diff options
Diffstat (limited to 'drivers/mtd/chips/map_ram.c')
-rw-r--r-- | drivers/mtd/chips/map_ram.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c new file mode 100644 index 000000000000..bd2e876a814b --- /dev/null +++ b/drivers/mtd/chips/map_ram.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * Common code to handle map devices which are simple RAM | ||
3 | * (C) 2000 Red Hat. GPL'd. | ||
4 | * $Id: map_ram.c,v 1.22 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 | |||
19 | |||
20 | static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); | ||
21 | static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *); | ||
22 | static int mapram_erase (struct mtd_info *, struct erase_info *); | ||
23 | static void mapram_nop (struct mtd_info *); | ||
24 | static struct mtd_info *map_ram_probe(struct map_info *map); | ||
25 | |||
26 | |||
27 | static struct mtd_chip_driver mapram_chipdrv = { | ||
28 | .probe = map_ram_probe, | ||
29 | .name = "map_ram", | ||
30 | .module = THIS_MODULE | ||
31 | }; | ||
32 | |||
33 | static struct mtd_info *map_ram_probe(struct map_info *map) | ||
34 | { | ||
35 | struct mtd_info *mtd; | ||
36 | |||
37 | /* Check the first byte is RAM */ | ||
38 | #if 0 | ||
39 | map_write8(map, 0x55, 0); | ||
40 | if (map_read8(map, 0) != 0x55) | ||
41 | return NULL; | ||
42 | |||
43 | map_write8(map, 0xAA, 0); | ||
44 | if (map_read8(map, 0) != 0xAA) | ||
45 | return NULL; | ||
46 | |||
47 | /* Check the last byte is RAM */ | ||
48 | map_write8(map, 0x55, map->size-1); | ||
49 | if (map_read8(map, map->size-1) != 0x55) | ||
50 | return NULL; | ||
51 | |||
52 | map_write8(map, 0xAA, map->size-1); | ||
53 | if (map_read8(map, map->size-1) != 0xAA) | ||
54 | return NULL; | ||
55 | #endif | ||
56 | /* OK. It seems to be RAM. */ | ||
57 | |||
58 | mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); | ||
59 | if (!mtd) | ||
60 | return NULL; | ||
61 | |||
62 | memset(mtd, 0, sizeof(*mtd)); | ||
63 | |||
64 | map->fldrv = &mapram_chipdrv; | ||
65 | mtd->priv = map; | ||
66 | mtd->name = map->name; | ||
67 | mtd->type = MTD_RAM; | ||
68 | mtd->size = map->size; | ||
69 | mtd->erase = mapram_erase; | ||
70 | mtd->read = mapram_read; | ||
71 | mtd->write = mapram_write; | ||
72 | mtd->sync = mapram_nop; | ||
73 | mtd->flags = MTD_CAP_RAM | MTD_VOLATILE; | ||
74 | |||
75 | mtd->erasesize = PAGE_SIZE; | ||
76 | while(mtd->size & (mtd->erasesize - 1)) | ||
77 | mtd->erasesize >>= 1; | ||
78 | |||
79 | __module_get(THIS_MODULE); | ||
80 | return mtd; | ||
81 | } | ||
82 | |||
83 | |||
84 | static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) | ||
85 | { | ||
86 | struct map_info *map = mtd->priv; | ||
87 | |||
88 | map_copy_from(map, buf, from, len); | ||
89 | *retlen = len; | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static int mapram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) | ||
94 | { | ||
95 | struct map_info *map = mtd->priv; | ||
96 | |||
97 | map_copy_to(map, to, buf, len); | ||
98 | *retlen = len; | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr) | ||
103 | { | ||
104 | /* Yeah, it's inefficient. Who cares? It's faster than a _real_ | ||
105 | flash erase. */ | ||
106 | struct map_info *map = mtd->priv; | ||
107 | map_word allff; | ||
108 | unsigned long i; | ||
109 | |||
110 | allff = map_word_ff(map); | ||
111 | |||
112 | for (i=0; i<instr->len; i += map_bankwidth(map)) | ||
113 | map_write(map, allff, instr->addr + i); | ||
114 | |||
115 | instr->state = MTD_ERASE_DONE; | ||
116 | |||
117 | mtd_erase_callback(instr); | ||
118 | |||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static void mapram_nop(struct mtd_info *mtd) | ||
123 | { | ||
124 | /* Nothing to see here */ | ||
125 | } | ||
126 | |||
127 | static int __init map_ram_init(void) | ||
128 | { | ||
129 | register_mtd_chip_driver(&mapram_chipdrv); | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | static void __exit map_ram_exit(void) | ||
134 | { | ||
135 | unregister_mtd_chip_driver(&mapram_chipdrv); | ||
136 | } | ||
137 | |||
138 | module_init(map_ram_init); | ||
139 | module_exit(map_ram_exit); | ||
140 | |||
141 | MODULE_LICENSE("GPL"); | ||
142 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
143 | MODULE_DESCRIPTION("MTD chip driver for RAM chips"); | ||