MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / mtd / maps / m520x.c
blob86ca368a387fc45fdd960ab6c84566053eec35f9
1 /*
3 * Normal mappings of chips in physical memory.
5 * Copyright (C) 2005, Freescale Semiconductor (Matt.Waddel@freescale.com)
6 * Copyright (C) 2005, Intec Automation Inc. (mike@steroidmicros.com)
7 * Copyright (C) 2001-2002, David McCullough <davidm@snapgear.com>
9 * Based on snapgear-uc.c
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <asm/io.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/kdev_t.h>
20 #include <linux/ioport.h>
21 #include <linux/devfs_fs_kernel.h>
23 extern dev_t ROOT_DEV;
25 #define WINDOW_ADDR 0x00000000
26 #define WINDOW_SIZE 0x00200000
27 #define BANKWIDTH 2
29 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
31 static struct mtd_info *ram_mtdinfo;
32 static struct map_info m520x_ram_map = {
33 .name = "RAM",
35 static struct mtd_partition m520x_romfs[] = {
37 .name = "Romfs"
41 static struct mtd_info *flash_mtdinfo;
42 struct map_info m520x_flash_map = {
43 .name = "Am29BDD160G 2.5v flash device (2MB)",
44 .size = WINDOW_SIZE,
45 .bankwidth = BANKWIDTH
47 static struct mtd_partition m520x_partitions[] = {
49 .name = "dBUG (256K)",
50 .size = 0x40000,
51 .offset = 0x00000
54 .name = "User FS (1792K)",
55 .size = 0x1C0000,
56 .offset = 0x40000
60 /****************************************************************************
62 * Find the MTD device with the given name
64 ****************************************************************************/
66 static struct mtd_info
67 *get_mtd_named(char *name)
69 int i;
70 struct mtd_info *mtd;
72 for (i = 0; i < MAX_MTD_DEVICES; i++) {
73 mtd = get_mtd_device(NULL, i);
75 if (mtd) {
76 if (strcmp(mtd->name, name) == 0)
77 return(mtd);
78 put_mtd_device(mtd);
81 return(NULL);
85 static int
86 m520x_point(struct mtd_info *mtd, loff_t from, size_t len,
87 size_t *retlen, u_char **mtdbuf)
89 struct map_info *map = (struct map_info *) mtd->priv;
90 *mtdbuf = (u_char *) (map->map_priv_1 + (int)from);
91 *retlen = len;
92 return(0);
96 static int __init
97 m520x_probe(int type, unsigned long addr, int size, int bankwidth)
99 static struct mtd_info *mymtd;
100 struct map_info *map_ptr;
102 if (type)
103 map_ptr = &m520x_ram_map;
104 else
105 map_ptr = &m520x_flash_map;
107 map_ptr->bankwidth = bankwidth;
108 map_ptr->map_priv_2 = addr;
109 map_ptr->phys = addr;
110 map_ptr->size = size;
112 printk(KERN_NOTICE "m520xevb %s probe(0x%lx,%x,%x): %lx at %lx\n",
113 type ? "ram":"flash", addr, size, bankwidth,
114 map_ptr->size, map_ptr->map_priv_2);
116 map_ptr->virt = (unsigned long)
117 ioremap_nocache(map_ptr->map_priv_2, map_ptr->size);
119 simple_map_init(map_ptr);
120 if (type)
121 mymtd = do_map_probe("map_ram", map_ptr);
122 else
123 mymtd = do_map_probe("cfi_probe", map_ptr);
125 if (!mymtd) {
126 iounmap((void *)map_ptr->map_priv_1);
127 return -ENXIO;
130 mymtd->owner = THIS_MODULE;
131 mymtd->point = m520x_point;
132 mymtd->priv = map_ptr;
134 if (type) {
135 ram_mtdinfo = mymtd;
136 add_mtd_partitions(mymtd, m520x_romfs, NB_OF(m520x_romfs));
137 } else {
138 flash_mtdinfo = mymtd;
139 add_mtd_partitions(mymtd, m520x_partitions,
140 sizeof(m520x_partitions) / sizeof(struct mtd_partition));
142 return(0);
147 * Initialize the mtd devices
150 int __init init_m520x(void)
152 int rc = -1;
153 struct mtd_info *mtd;
154 extern char _ebss;
156 rc = m520x_probe( 0, WINDOW_ADDR, WINDOW_SIZE, BANKWIDTH);
158 /* Map in the filesystem from RAM last so that, if the filesystem
159 * is not in RAM for some reason we do not change the minor/major
160 * for the flash devices
162 #ifndef CONFIG_ROMFS_FROM_ROM
163 if (0 != m520x_probe( 1, (unsigned long)&_ebss,
164 PAGE_ALIGN(*(unsigned long *)(&_ebss + 8)), 4))
165 printk("Failed to probe RAM filesystem\n");
166 #else
168 unsigned long start_area;
169 unsigned char *sp, *ep;
170 size_t len;
172 start_area = (unsigned long) &_ebss;
174 /* If romfs is in flash use it to boot */
175 if (strncmp((char *) start_area, "-rom1fs-", 8) != 0) {
176 mtd = get_mtd_named("Image");
177 if (mtd && mtd->point) {
178 if ((*mtd->point)(mtd, 0, mtd->size, &len, &sp) == 0){
179 ep = sp + len;
180 while (sp < ep && strncmp(sp,"-rom1fs-",8) != 0)
181 sp++;
182 if (sp < ep)
183 start_area = (unsigned long) sp;
186 if (mtd)
187 put_mtd_device(mtd);
189 if (0 != m520x_probe(1, start_area,
190 PAGE_ALIGN(*(unsigned long *)(start_area + 8)), 4))
191 printk("Failed to probe RAM filesystem\n");
193 #endif
195 mtd = get_mtd_named("Romfs");
196 if (mtd) {
197 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
198 put_mtd_device(mtd);
199 } else
200 printk("%s: Failed to make root filesystem\n", __FUNCTION__);
202 mtd = get_mtd_named("User FS (1792K)");
203 if (mtd) {
204 blk_register_region(MKDEV(MTD_BLOCK_MAJOR, mtd->index), MAX_MTD_DEVICES,
205 THIS_MODULE, m520x_probe, NULL, NULL);
206 put_mtd_device(mtd);
207 } else
208 printk("%s: Failed to flash filesystem\n", __FUNCTION__);
210 return(rc);
213 static void __exit cleanup_m520x(void)
215 if (flash_mtdinfo) {
216 del_mtd_partitions(flash_mtdinfo);
217 map_destroy(flash_mtdinfo);
218 flash_mtdinfo = NULL;
220 if (ram_mtdinfo) {
221 del_mtd_partitions(ram_mtdinfo);
222 map_destroy(ram_mtdinfo);
223 ram_mtdinfo = NULL;
225 if (m520x_ram_map.map_priv_1) {
226 iounmap((void *)m520x_ram_map.map_priv_1);
227 m520x_ram_map.map_priv_1 = 0;
229 if (m520x_flash_map.map_priv_1) {
230 iounmap((void *)m520x_flash_map.map_priv_1);
231 m520x_flash_map.map_priv_1 = 0;
236 module_init(init_m520x);
237 module_exit(cleanup_m520x);
239 MODULE_LICENSE("GPL");
240 MODULE_AUTHOR("<Matt.Waddel@freescale.com>");
241 MODULE_DESCRIPTION("MTD map for M520xEVB");