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>
14
#include <linux/mtd/mtd.h>
15
#include <linux/mtd/map.h>
17
static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
18
static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
19
static void maprom_nop (struct mtd_info *);
20
static struct mtd_info *map_rom_probe(struct map_info *map);
21
static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);
22
static unsigned long maprom_unmapped_area(struct mtd_info *, unsigned long,
23
unsigned long, unsigned long);
25
static struct mtd_chip_driver maprom_chipdrv = {
26
.probe = map_rom_probe,
31
static struct mtd_info *map_rom_probe(struct map_info *map)
35
mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
39
map->fldrv = &maprom_chipdrv;
41
mtd->name = map->name;
43
mtd->size = map->size;
44
mtd->get_unmapped_area = maprom_unmapped_area;
45
mtd->read = maprom_read;
46
mtd->write = maprom_write;
47
mtd->sync = maprom_nop;
48
mtd->erase = maprom_erase;
49
mtd->flags = MTD_CAP_ROM;
50
mtd->erasesize = map->size;
53
__module_get(THIS_MODULE);
59
* Allow NOMMU mmap() to directly map the device (if not NULL)
60
* - return the address to which the offset maps
61
* - return -ENOSYS to indicate refusal to do the mapping
63
static unsigned long maprom_unmapped_area(struct mtd_info *mtd,
68
struct map_info *map = mtd->priv;
69
return (unsigned long) map->virt + offset;
72
static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
74
struct map_info *map = mtd->priv;
76
map_copy_from(map, buf, from, len);
81
static void maprom_nop(struct mtd_info *mtd)
83
/* Nothing to see here */
86
static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
88
printk(KERN_NOTICE "maprom_write called\n");
92
static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
94
/* We do our best 8) */
98
static int __init map_rom_init(void)
100
register_mtd_chip_driver(&maprom_chipdrv);
104
static void __exit map_rom_exit(void)
106
unregister_mtd_chip_driver(&maprom_chipdrv);
109
module_init(map_rom_init);
110
module_exit(map_rom_exit);
112
MODULE_LICENSE("GPL");
113
MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
114
MODULE_DESCRIPTION("MTD chip driver for ROM chips");