mm: fix assertion
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mtd / chips / map_ram.c
blob072dd8abf33a726620bd0f9299c3005632ce4ee4
1 /*
2 * Common code to handle map devices which are simple RAM
3 * (C) 2000 Red Hat. GPL'd.
4 */
6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <asm/io.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>
16 #include <linux/mtd/compatmac.h>
19 static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
20 static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
21 static int mapram_erase (struct mtd_info *, struct erase_info *);
22 static void mapram_nop (struct mtd_info *);
23 static struct mtd_info *map_ram_probe(struct map_info *map);
26 static struct mtd_chip_driver mapram_chipdrv = {
27 .probe = map_ram_probe,
28 .name = "map_ram",
29 .module = THIS_MODULE
32 static struct mtd_info *map_ram_probe(struct map_info *map)
34 struct mtd_info *mtd;
36 /* Check the first byte is RAM */
37 #if 0
38 map_write8(map, 0x55, 0);
39 if (map_read8(map, 0) != 0x55)
40 return NULL;
42 map_write8(map, 0xAA, 0);
43 if (map_read8(map, 0) != 0xAA)
44 return NULL;
46 /* Check the last byte is RAM */
47 map_write8(map, 0x55, map->size-1);
48 if (map_read8(map, map->size-1) != 0x55)
49 return NULL;
51 map_write8(map, 0xAA, map->size-1);
52 if (map_read8(map, map->size-1) != 0xAA)
53 return NULL;
54 #endif
55 /* OK. It seems to be RAM. */
57 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
58 if (!mtd)
59 return NULL;
61 map->fldrv = &mapram_chipdrv;
62 mtd->priv = map;
63 mtd->name = map->name;
64 mtd->type = MTD_RAM;
65 mtd->size = map->size;
66 mtd->erase = mapram_erase;
67 mtd->read = mapram_read;
68 mtd->write = mapram_write;
69 mtd->sync = mapram_nop;
70 mtd->flags = MTD_CAP_RAM;
71 mtd->writesize = 1;
73 mtd->erasesize = PAGE_SIZE;
74 while(mtd->size & (mtd->erasesize - 1))
75 mtd->erasesize >>= 1;
77 __module_get(THIS_MODULE);
78 return mtd;
82 static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
84 struct map_info *map = mtd->priv;
86 map_copy_from(map, buf, from, len);
87 *retlen = len;
88 return 0;
91 static int mapram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
93 struct map_info *map = mtd->priv;
95 map_copy_to(map, to, buf, len);
96 *retlen = len;
97 return 0;
100 static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr)
102 /* Yeah, it's inefficient. Who cares? It's faster than a _real_
103 flash erase. */
104 struct map_info *map = mtd->priv;
105 map_word allff;
106 unsigned long i;
108 allff = map_word_ff(map);
110 for (i=0; i<instr->len; i += map_bankwidth(map))
111 map_write(map, allff, instr->addr + i);
113 instr->state = MTD_ERASE_DONE;
115 mtd_erase_callback(instr);
117 return 0;
120 static void mapram_nop(struct mtd_info *mtd)
122 /* Nothing to see here */
125 static int __init map_ram_init(void)
127 register_mtd_chip_driver(&mapram_chipdrv);
128 return 0;
131 static void __exit map_ram_exit(void)
133 unregister_mtd_chip_driver(&mapram_chipdrv);
136 module_init(map_ram_init);
137 module_exit(map_ram_exit);
139 MODULE_LICENSE("GPL");
140 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
141 MODULE_DESCRIPTION("MTD chip driver for RAM chips");