1 /*
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.10 2000/12/10 01:39:13 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/malloc.h>
14
15 #include <linux/mtd/map.h>
16
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
21 static const char im_name[] = "map_rom_probe";
22
23 /* This routine is made available to other mtd code via
24 * inter_module_register. It must only be accessed through
25 * inter_module_get which will bump the use count of this module. The
26 * addresses passed back in mtd are valid as long as the use count of
27 * this module is non-zero, i.e. between inter_module_get and
28 * inter_module_put. Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
29 */
30
31 struct mtd_info *map_rom_probe(struct map_info *map)
32 {
33 struct mtd_info *mtd;
34
35 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
36 if (!mtd)
37 return NULL;
38
39 memset(mtd, 0, sizeof(*mtd));
40
41 map->im_name = im_name;
42 map->fldrv_destroy = maprom_nop;
43 mtd->priv = map;
44 mtd->name = map->name;
45 mtd->type = MTD_ROM;
46 mtd->size = map->size;
47 mtd->read = maprom_read;
48 mtd->write = maprom_write;
49 mtd->sync = maprom_nop;
50 mtd->flags = MTD_CAP_ROM;
51 mtd->erasesize = 131072;
52
53 return mtd;
54 }
55
56
57 static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
58 {
59 struct map_info *map = (struct map_info *)mtd->priv;
60
61 map->copy_from(map, buf, from, len);
62 *retlen = len;
63 return 0;
64 }
65
66 static void maprom_nop(struct mtd_info *mtd)
67 {
68 /* Nothing to see here */
69 }
70
71 static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
72 {
73 printk(KERN_NOTICE "maprom_write called\n");
74 return -EIO;
75 }
76
77 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
78 #define map_rom_init init_module
79 #define map_rom_exit cleanup_module
80 #endif
81
82 static int __init map_rom_init(void)
83 {
84 inter_module_register(im_name, THIS_MODULE, &map_rom_probe);
85 return 0;
86 }
87
88 static void __exit map_rom_exit(void)
89 {
90 inter_module_unregister(im_name);
91 }
92
93 module_init(map_rom_init);
94 module_exit(map_rom_exit);
95
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.