blob: 821d0ed6bae3970453a38d2e40bb0bb802930b1d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Common code to handle map devices which are simple ROM
3 * (C) 2000 Red Hat. GPL'd.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
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
18static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
19static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
20static void maprom_nop (struct mtd_info *);
21static struct mtd_info *map_rom_probe(struct map_info *map);
22
23static struct mtd_chip_driver maprom_chipdrv = {
24 .probe = map_rom_probe,
25 .name = "map_rom",
26 .module = THIS_MODULE
27};
28
29static struct mtd_info *map_rom_probe(struct map_info *map)
30{
31 struct mtd_info *mtd;
32
Burman Yan95b93a02006-11-15 21:10:29 +020033 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 if (!mtd)
35 return NULL;
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 map->fldrv = &maprom_chipdrv;
38 mtd->priv = map;
39 mtd->name = map->name;
David Woodhouse21c8db92006-06-14 21:39:48 +010040 mtd->type = MTD_ROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 mtd->size = map->size;
42 mtd->read = maprom_read;
43 mtd->write = maprom_write;
44 mtd->sync = maprom_nop;
45 mtd->flags = MTD_CAP_ROM;
Joern Engele369d622006-05-30 14:25:17 +020046 mtd->erasesize = map->size;
Artem B. Bityutskiy17ffc7b2006-06-22 18:15:48 +040047 mtd->writesize = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 __module_get(THIS_MODULE);
50 return mtd;
51}
52
53
54static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
55{
56 struct map_info *map = mtd->priv;
57
58 map_copy_from(map, buf, from, len);
59 *retlen = len;
60 return 0;
61}
62
63static void maprom_nop(struct mtd_info *mtd)
64{
65 /* Nothing to see here */
66}
67
68static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
69{
70 printk(KERN_NOTICE "maprom_write called\n");
71 return -EIO;
72}
73
74static int __init map_rom_init(void)
75{
76 register_mtd_chip_driver(&maprom_chipdrv);
77 return 0;
78}
79
80static void __exit map_rom_exit(void)
81{
82 unregister_mtd_chip_driver(&maprom_chipdrv);
83}
84
85module_init(map_rom_init);
86module_exit(map_rom_exit);
87
88MODULE_LICENSE("GPL");
89MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
90MODULE_DESCRIPTION("MTD chip driver for ROM chips");