• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/mtd/chips/
1/*
2 * Common code to handle map devices which are simple RAM
3 * (C) 2000 Red Hat. GPL'd.
4 */
5
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
17
18static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
19static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
20static int mapram_erase (struct mtd_info *, struct erase_info *);
21static void mapram_nop (struct mtd_info *);
22static struct mtd_info *map_ram_probe(struct map_info *map);
23static unsigned long mapram_unmapped_area(struct mtd_info *, unsigned long,
24					  unsigned long, unsigned long);
25
26
27static struct mtd_chip_driver mapram_chipdrv = {
28	.probe	= map_ram_probe,
29	.name	= "map_ram",
30	.module	= THIS_MODULE
31};
32
33static 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	/* OK. It seems to be RAM. */
39
40	mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
41	if (!mtd)
42		return NULL;
43
44	map->fldrv = &mapram_chipdrv;
45	mtd->priv = map;
46	mtd->name = map->name;
47	mtd->type = MTD_RAM;
48	mtd->size = map->size;
49	mtd->erase = mapram_erase;
50	mtd->get_unmapped_area = mapram_unmapped_area;
51	mtd->read = mapram_read;
52	mtd->write = mapram_write;
53	mtd->sync = mapram_nop;
54	mtd->flags = MTD_CAP_RAM;
55	mtd->writesize = 1;
56
57	mtd->erasesize = PAGE_SIZE;
58 	while(mtd->size & (mtd->erasesize - 1))
59		mtd->erasesize >>= 1;
60
61	__module_get(THIS_MODULE);
62	return mtd;
63}
64
65
66/*
67 * Allow NOMMU mmap() to directly map the device (if not NULL)
68 * - return the address to which the offset maps
69 * - return -ENOSYS to indicate refusal to do the mapping
70 */
71static unsigned long mapram_unmapped_area(struct mtd_info *mtd,
72					  unsigned long len,
73					  unsigned long offset,
74					  unsigned long flags)
75{
76	struct map_info *map = mtd->priv;
77	return (unsigned long) map->virt + offset;
78}
79
80static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
81{
82	struct map_info *map = mtd->priv;
83
84	map_copy_from(map, buf, from, len);
85	*retlen = len;
86	return 0;
87}
88
89static int mapram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
90{
91	struct map_info *map = mtd->priv;
92
93	map_copy_to(map, to, buf, len);
94	*retlen = len;
95	return 0;
96}
97
98static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr)
99{
100	/* Yeah, it's inefficient. Who cares? It's faster than a _real_
101	   flash erase. */
102	struct map_info *map = mtd->priv;
103	map_word allff;
104	unsigned long i;
105
106	allff = map_word_ff(map);
107
108	for (i=0; i<instr->len; i += map_bankwidth(map))
109		map_write(map, allff, instr->addr + i);
110
111	instr->state = MTD_ERASE_DONE;
112
113	mtd_erase_callback(instr);
114
115	return 0;
116}
117
118static void mapram_nop(struct mtd_info *mtd)
119{
120	/* Nothing to see here */
121}
122
123static int __init map_ram_init(void)
124{
125	register_mtd_chip_driver(&mapram_chipdrv);
126	return 0;
127}
128
129static void __exit map_ram_exit(void)
130{
131	unregister_mtd_chip_driver(&mapram_chipdrv);
132}
133
134module_init(map_ram_init);
135module_exit(map_ram_exit);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
139MODULE_DESCRIPTION("MTD chip driver for RAM chips");
140