2 * Common code to handle map devices which are simple ROM
3 * (C) 2000 Red Hat. GPL'd.
4 * $Id: map_rom.c,v 1.21 2004/07/12 14:06:01 dwmw2 Exp $
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
11 #include <asm/byteorder.h>
12 #include <linux/errno.h>
13 #include <linux/slab.h>
14 #include <linux/init.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/compatmac.h>
19 static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
20 static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
21 static void maprom_nop (struct mtd_info *);
22 struct mtd_info *map_rom_probe(struct map_info *map);
24 static struct mtd_chip_driver maprom_chipdrv = {
25 .probe = map_rom_probe,
30 struct mtd_info *map_rom_probe(struct map_info *map)
34 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
38 memset(mtd, 0, sizeof(*mtd));
40 map->fldrv = &maprom_chipdrv;
42 mtd->name = map->name;
44 mtd->size = map->size;
45 mtd->read = maprom_read;
46 mtd->write = maprom_write;
47 mtd->sync = maprom_nop;
48 mtd->flags = MTD_CAP_ROM;
49 mtd->erasesize = 131072;
50 while(mtd->size & (mtd->erasesize - 1))
53 __module_get(THIS_MODULE);
58 static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
60 struct map_info *map = (struct map_info *)mtd->priv;
62 map_copy_from(map, buf, from, len);
67 static void maprom_nop(struct mtd_info *mtd)
69 /* Nothing to see here */
72 static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
74 printk(KERN_NOTICE "maprom_write called\n");
78 int __init map_rom_init(void)
80 register_mtd_chip_driver(&maprom_chipdrv);
84 static void __exit map_rom_exit(void)
86 unregister_mtd_chip_driver(&maprom_chipdrv);
89 module_init(map_rom_init);
90 module_exit(map_rom_exit);
92 MODULE_LICENSE("GPL");
93 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
94 MODULE_DESCRIPTION("MTD chip driver for ROM chips");