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>
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
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
= {
35 static struct mtd_partition m520x_romfs
[] = {
41 static struct mtd_info
*flash_mtdinfo
;
42 struct map_info m520x_flash_map
= {
43 .name
= "Am29BDD160G 2.5v flash device (2MB)",
45 .bankwidth
= BANKWIDTH
47 static struct mtd_partition m520x_partitions
[] = {
49 .name
= "dBUG (256K)",
54 .name
= "User FS (1792K)",
60 /****************************************************************************
62 * Find the MTD device with the given name
64 ****************************************************************************/
66 static struct mtd_info
67 *get_mtd_named(char *name
)
72 for (i
= 0; i
< MAX_MTD_DEVICES
; i
++) {
73 mtd
= get_mtd_device(NULL
, i
);
76 if (strcmp(mtd
->name
, name
) == 0)
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
);
97 m520x_probe(int type
, unsigned long addr
, int size
, int bankwidth
)
99 static struct mtd_info
*mymtd
;
100 struct map_info
*map_ptr
;
103 map_ptr
= &m520x_ram_map
;
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
);
121 mymtd
= do_map_probe("map_ram", map_ptr
);
123 mymtd
= do_map_probe("cfi_probe", map_ptr
);
126 iounmap((void *)map_ptr
->map_priv_1
);
130 mymtd
->owner
= THIS_MODULE
;
131 mymtd
->point
= m520x_point
;
132 mymtd
->priv
= map_ptr
;
136 add_mtd_partitions(mymtd
, m520x_romfs
, NB_OF(m520x_romfs
));
138 flash_mtdinfo
= mymtd
;
139 add_mtd_partitions(mymtd
, m520x_partitions
,
140 sizeof(m520x_partitions
) / sizeof(struct mtd_partition
));
147 * Initialize the mtd devices
150 int __init
init_m520x(void)
153 struct mtd_info
*mtd
;
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");
168 unsigned long start_area
;
169 unsigned char *sp
, *ep
;
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){
180 while (sp
< ep
&& strncmp(sp
,"-rom1fs-",8) != 0)
183 start_area
= (unsigned long) sp
;
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");
195 mtd
= get_mtd_named("Romfs");
197 ROOT_DEV
= MKDEV(MTD_BLOCK_MAJOR
, mtd
->index
);
200 printk("%s: Failed to make root filesystem\n", __FUNCTION__
);
202 mtd
= get_mtd_named("User FS (1792K)");
204 blk_register_region(MKDEV(MTD_BLOCK_MAJOR
, mtd
->index
), MAX_MTD_DEVICES
,
205 THIS_MODULE
, m520x_probe
, NULL
, NULL
);
208 printk("%s: Failed to flash filesystem\n", __FUNCTION__
);
213 static void __exit
cleanup_m520x(void)
216 del_mtd_partitions(flash_mtdinfo
);
217 map_destroy(flash_mtdinfo
);
218 flash_mtdinfo
= NULL
;
221 del_mtd_partitions(ram_mtdinfo
);
222 map_destroy(ram_mtdinfo
);
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");