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