blob: cb27f855074c279a65ce23a53cc2615ff9417d55 [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.
4 * $Id: map_rom.c,v 1.23 2005/01/05 18:05:12 dwmw2 Exp $
5 */
6
7#include <linux/module.h>
8#include <linux/types.h>
9#include <linux/kernel.h>
10#include <asm/io.h>
11#include <asm/byteorder.h>
12#include <linux/errno.h>
13#include <linux/slab.h>
14#include <linux/init.h>
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/map.h>
17#include <linux/mtd/compatmac.h>
18
19static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
20static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
21static void maprom_nop (struct mtd_info *);
22static struct mtd_info *map_rom_probe(struct map_info *map);
23
24static struct mtd_chip_driver maprom_chipdrv = {
25 .probe = map_rom_probe,
26 .name = "map_rom",
27 .module = THIS_MODULE
28};
29
30static struct mtd_info *map_rom_probe(struct map_info *map)
31{
32 struct mtd_info *mtd;
33
Burman Yan95b93a02006-11-15 21:10:29 +020034 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 if (!mtd)
36 return NULL;
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 map->fldrv = &maprom_chipdrv;
39 mtd->priv = map;
40 mtd->name = map->name;
David Woodhouse21c8db92006-06-14 21:39:48 +010041 mtd->type = MTD_ROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 mtd->size = map->size;
43 mtd->read = maprom_read;
44 mtd->write = maprom_write;
45 mtd->sync = maprom_nop;
46 mtd->flags = MTD_CAP_ROM;
Joern Engele369d622006-05-30 14:25:17 +020047 mtd->erasesize = map->size;
Artem B. Bityutskiy17ffc7b2006-06-22 18:15:48 +040048 mtd->writesize = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 __module_get(THIS_MODULE);
51 return mtd;
52}
53
54
55static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
56{
57 struct map_info *map = mtd->priv;
58
59 map_copy_from(map, buf, from, len);
60 *retlen = len;
61 return 0;
62}
63
64static void maprom_nop(struct mtd_info *mtd)
65{
66 /* Nothing to see here */
67}
68
69static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
70{
71 printk(KERN_NOTICE "maprom_write called\n");
72 return -EIO;
73}
74
75static int __init map_rom_init(void)
76{
77 register_mtd_chip_driver(&maprom_chipdrv);
78 return 0;
79}
80
81static void __exit map_rom_exit(void)
82{
83 unregister_mtd_chip_driver(&maprom_chipdrv);
84}
85
86module_init(map_rom_init);
87module_exit(map_rom_exit);
88
89MODULE_LICENSE("GPL");
90MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
91MODULE_DESCRIPTION("MTD chip driver for ROM chips");