Blame view

drivers/mtd/chips/map_rom.c 2.08 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  /*
   * Common code to handle map devices which are simple ROM
   * (C) 2000 Red Hat. GPL'd.
   * $Id: map_rom.c,v 1.23 2005/01/05 18:05:12 dwmw2 Exp $
   */
  
  #include <linux/module.h>
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <asm/io.h>
  #include <asm/byteorder.h>
  #include <linux/errno.h>
  #include <linux/slab.h>
  #include <linux/init.h>
  #include <linux/mtd/mtd.h>
  #include <linux/mtd/map.h>
  #include <linux/mtd/compatmac.h>
  
  static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  static void maprom_nop (struct mtd_info *);
  static struct mtd_info *map_rom_probe(struct map_info *map);
  
  static struct mtd_chip_driver maprom_chipdrv = {
  	.probe	= map_rom_probe,
  	.name	= "map_rom",
  	.module	= THIS_MODULE
  };
  
  static struct mtd_info *map_rom_probe(struct map_info *map)
  {
  	struct mtd_info *mtd;
95b93a0cd   Burman Yan   [MTD] replace kma...
33
  	mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
  	if (!mtd)
  		return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
  	map->fldrv = &maprom_chipdrv;
  	mtd->priv = map;
  	mtd->name = map->name;
21c8db9ef   David Woodhouse   [MTD] Restore MTD...
39
  	mtd->type = MTD_ROM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
  	mtd->size = map->size;
  	mtd->read = maprom_read;
  	mtd->write = maprom_write;
  	mtd->sync = maprom_nop;
  	mtd->flags = MTD_CAP_ROM;
e369d62e9   Joern Engel   [MTD] replace MTD...
45
  	mtd->erasesize = map->size;
17ffc7ba6   Artem B. Bityutskiy   [MTD] Initialize ...
46
  	mtd->writesize = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  
  	__module_get(THIS_MODULE);
  	return mtd;
  }
  
  
  static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  {
  	struct map_info *map = mtd->priv;
  
  	map_copy_from(map, buf, from, len);
  	*retlen = len;
  	return 0;
  }
  
  static void maprom_nop(struct mtd_info *mtd)
  {
  	/* Nothing to see here */
  }
  
  static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  {
  	printk(KERN_NOTICE "maprom_write called
  ");
  	return -EIO;
  }
  
  static int __init map_rom_init(void)
  {
  	register_mtd_chip_driver(&maprom_chipdrv);
  	return 0;
  }
  
  static void __exit map_rom_exit(void)
  {
  	unregister_mtd_chip_driver(&maprom_chipdrv);
  }
  
  module_init(map_rom_init);
  module_exit(map_rom_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  MODULE_DESCRIPTION("MTD chip driver for ROM chips");