xref: /openbmc/linux/drivers/mtd/chips/map_rom.c (revision 9ac8d3fb)
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 
23 static struct mtd_chip_driver maprom_chipdrv = {
24 	.probe	= map_rom_probe,
25 	.name	= "map_rom",
26 	.module	= THIS_MODULE
27 };
28 
29 static struct mtd_info *map_rom_probe(struct map_info *map)
30 {
31 	struct mtd_info *mtd;
32 
33 	mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
34 	if (!mtd)
35 		return NULL;
36 
37 	map->fldrv = &maprom_chipdrv;
38 	mtd->priv = map;
39 	mtd->name = map->name;
40 	mtd->type = MTD_ROM;
41 	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;
46 	mtd->erasesize = map->size;
47 	mtd->writesize = 1;
48 
49 	__module_get(THIS_MODULE);
50 	return mtd;
51 }
52 
53 
54 static 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 
63 static void maprom_nop(struct mtd_info *mtd)
64 {
65 	/* Nothing to see here */
66 }
67 
68 static 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 
74 static int __init map_rom_init(void)
75 {
76 	register_mtd_chip_driver(&maprom_chipdrv);
77 	return 0;
78 }
79 
80 static void __exit map_rom_exit(void)
81 {
82 	unregister_mtd_chip_driver(&maprom_chipdrv);
83 }
84 
85 module_init(map_rom_init);
86 module_exit(map_rom_exit);
87 
88 MODULE_LICENSE("GPL");
89 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
90 MODULE_DESCRIPTION("MTD chip driver for ROM chips");
91