2 * Common code to handle map devices which are simple ROM
3 * (C) 2000 Red Hat. GPL'd.
6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/kernel.h>
10 #include <asm/byteorder.h>
11 #include <linux/errno.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
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 static int maprom_point (struct mtd_info
*mtd
, loff_t from
, size_t len
,
24 size_t *retlen
, void **virt
, resource_size_t
*phys
);
25 static int maprom_unpoint(struct mtd_info
*mtd
, loff_t from
, size_t len
);
28 static struct mtd_chip_driver maprom_chipdrv
= {
29 .probe
= map_rom_probe
,
34 static unsigned int default_erasesize(struct map_info
*map
)
36 const __be32
*erase_size
= NULL
;
38 erase_size
= of_get_property(map
->device_node
, "erase-size", NULL
);
40 return !erase_size
? map
->size
: be32_to_cpu(*erase_size
);
43 static struct mtd_info
*map_rom_probe(struct map_info
*map
)
47 mtd
= kzalloc(sizeof(*mtd
), GFP_KERNEL
);
51 map
->fldrv
= &maprom_chipdrv
;
53 mtd
->name
= map
->name
;
55 mtd
->size
= map
->size
;
56 mtd
->_point
= maprom_point
;
57 mtd
->_unpoint
= maprom_unpoint
;
58 mtd
->_read
= maprom_read
;
59 mtd
->_write
= maprom_write
;
60 mtd
->_sync
= maprom_nop
;
61 mtd
->_erase
= maprom_erase
;
62 mtd
->flags
= MTD_CAP_ROM
;
63 mtd
->erasesize
= default_erasesize(map
);
65 mtd
->writebufsize
= 1;
67 __module_get(THIS_MODULE
);
72 static int maprom_point(struct mtd_info
*mtd
, loff_t from
, size_t len
,
73 size_t *retlen
, void **virt
, resource_size_t
*phys
)
75 struct map_info
*map
= mtd
->priv
;
79 *virt
= map
->virt
+ from
;
81 *phys
= map
->phys
+ from
;
86 static int maprom_unpoint(struct mtd_info
*mtd
, loff_t from
, size_t len
)
91 static int maprom_read (struct mtd_info
*mtd
, loff_t from
, size_t len
, size_t *retlen
, u_char
*buf
)
93 struct map_info
*map
= mtd
->priv
;
95 map_copy_from(map
, buf
, from
, len
);
100 static void maprom_nop(struct mtd_info
*mtd
)
102 /* Nothing to see here */
105 static int maprom_write (struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
110 static int maprom_erase (struct mtd_info
*mtd
, struct erase_info
*info
)
112 /* We do our best 8) */
116 static int __init
map_rom_init(void)
118 register_mtd_chip_driver(&maprom_chipdrv
);
122 static void __exit
map_rom_exit(void)
124 unregister_mtd_chip_driver(&maprom_chipdrv
);
127 module_init(map_rom_init
);
128 module_exit(map_rom_exit
);
130 MODULE_LICENSE("GPL");
131 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
132 MODULE_DESCRIPTION("MTD chip driver for ROM chips");