2 * Common code to handle map devices which are simple RAM
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>
18 static int mapram_read (struct mtd_info
*, loff_t
, size_t, size_t *, u_char
*);
19 static int mapram_write (struct mtd_info
*, loff_t
, size_t, size_t *, const u_char
*);
20 static int mapram_erase (struct mtd_info
*, struct erase_info
*);
21 static void mapram_nop (struct mtd_info
*);
22 static struct mtd_info
*map_ram_probe(struct map_info
*map
);
23 static int mapram_point (struct mtd_info
*mtd
, loff_t from
, size_t len
,
24 size_t *retlen
, void **virt
, resource_size_t
*phys
);
25 static int mapram_unpoint(struct mtd_info
*mtd
, loff_t from
, size_t len
);
28 static struct mtd_chip_driver mapram_chipdrv
= {
29 .probe
= map_ram_probe
,
34 static struct mtd_info
*map_ram_probe(struct map_info
*map
)
38 /* Check the first byte is RAM */
40 map_write8(map
, 0x55, 0);
41 if (map_read8(map
, 0) != 0x55)
44 map_write8(map
, 0xAA, 0);
45 if (map_read8(map
, 0) != 0xAA)
48 /* Check the last byte is RAM */
49 map_write8(map
, 0x55, map
->size
-1);
50 if (map_read8(map
, map
->size
-1) != 0x55)
53 map_write8(map
, 0xAA, map
->size
-1);
54 if (map_read8(map
, map
->size
-1) != 0xAA)
57 /* OK. It seems to be RAM. */
59 mtd
= kzalloc(sizeof(*mtd
), GFP_KERNEL
);
63 map
->fldrv
= &mapram_chipdrv
;
65 mtd
->name
= map
->name
;
67 mtd
->size
= map
->size
;
68 mtd
->_erase
= mapram_erase
;
69 mtd
->_read
= mapram_read
;
70 mtd
->_write
= mapram_write
;
71 mtd
->_panic_write
= mapram_write
;
72 mtd
->_point
= mapram_point
;
73 mtd
->_sync
= mapram_nop
;
74 mtd
->_unpoint
= mapram_unpoint
;
75 mtd
->flags
= MTD_CAP_RAM
;
78 mtd
->erasesize
= PAGE_SIZE
;
79 while(mtd
->size
& (mtd
->erasesize
- 1))
82 __module_get(THIS_MODULE
);
86 static int mapram_point(struct mtd_info
*mtd
, loff_t from
, size_t len
,
87 size_t *retlen
, void **virt
, resource_size_t
*phys
)
89 struct map_info
*map
= mtd
->priv
;
93 *virt
= map
->virt
+ from
;
95 *phys
= map
->phys
+ from
;
100 static int mapram_unpoint(struct mtd_info
*mtd
, loff_t from
, size_t len
)
105 static int mapram_read (struct mtd_info
*mtd
, loff_t from
, size_t len
, size_t *retlen
, u_char
*buf
)
107 struct map_info
*map
= mtd
->priv
;
109 map_copy_from(map
, buf
, from
, len
);
114 static int mapram_write (struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
116 struct map_info
*map
= mtd
->priv
;
118 map_copy_to(map
, to
, buf
, len
);
123 static int mapram_erase (struct mtd_info
*mtd
, struct erase_info
*instr
)
125 /* Yeah, it's inefficient. Who cares? It's faster than a _real_
127 struct map_info
*map
= mtd
->priv
;
131 allff
= map_word_ff(map
);
132 for (i
=0; i
<instr
->len
; i
+= map_bankwidth(map
))
133 map_write(map
, allff
, instr
->addr
+ i
);
137 static void mapram_nop(struct mtd_info
*mtd
)
139 /* Nothing to see here */
142 static int __init
map_ram_init(void)
144 register_mtd_chip_driver(&mapram_chipdrv
);
148 static void __exit
map_ram_exit(void)
150 unregister_mtd_chip_driver(&mapram_chipdrv
);
153 module_init(map_ram_init
);
154 module_exit(map_ram_exit
);
156 MODULE_LICENSE("GPL");
157 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
158 MODULE_DESCRIPTION("MTD chip driver for RAM chips");