2 * Flash memory access on Alchemy Db1550 board
4 * $Id: db1550-flash.c,v 1.3 2004/07/14 17:45:40 dwmw2 Exp $
6 * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c:
7 * (C) 2003 Pete Popov <pete_popov@yahoo.com>
11 #include <linux/config.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/mtd/partitions.h>
22 #include <asm/au1000.h>
25 #define DBG(x...) printk(x)
30 static unsigned long window_addr;
31 static unsigned long window_size;
34 static struct map_info db1550_map = {
35 .name = "Db1550 flash",
38 static unsigned char flash_bankwidth = 4;
41 * Support only 64MB NOR Flash parts
44 #if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
45 #define DB1550_BOTH_BANKS
46 #elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER)
47 #define DB1550_BOOT_ONLY
48 #elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
49 #define DB1550_USER_ONLY
52 #ifdef DB1550_BOTH_BANKS
53 /* both banks will be used. Combine the first bank and the first
54 * part of the second bank together into a single jffs/jffs2
57 static struct mtd_partition db1550_partitions[] = {
58 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
59 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
60 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
64 .size = (0x1FC00000 - 0x18000000),
69 .offset = MTDPART_OFS_APPEND,
70 .mask_flags = MTD_WRITEABLE
73 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
74 .offset = MTDPART_OFS_APPEND,
77 #elif defined(DB1550_BOOT_ONLY)
78 static struct mtd_partition db1550_partitions[] = {
79 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
80 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
89 .offset = MTDPART_OFS_APPEND,
90 .mask_flags = MTD_WRITEABLE
93 .size = (0x300000-0x40000), /* last 256KB is yamon env */
94 .offset = MTDPART_OFS_APPEND,
97 #elif defined(DB1550_USER_ONLY)
98 static struct mtd_partition db1550_partitions[] = {
99 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
100 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
104 .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
107 .name = "raw kernel",
108 .size = MTDPART_SIZ_FULL,
109 .offset = MTDPART_OFS_APPEND,
113 #error MTD_DB1550 define combo error /* should never happen */
116 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
118 static struct mtd_info *mymtd;
121 * Probe the flash density and setup window address and size
122 * based on user CONFIG options. There are times when we don't
123 * want the MTD driver to be probing the boot or user flash,
124 * so having the option to enable only one bank is important.
126 int setup_flash_params(void)
128 #if defined(DB1550_BOTH_BANKS)
129 window_addr = 0x18000000;
130 window_size = 0x8000000;
131 #elif defined(DB1550_BOOT_ONLY)
132 window_addr = 0x1C000000;
133 window_size = 0x4000000;
134 #else /* USER ONLY */
135 window_addr = 0x1E000000;
136 window_size = 0x4000000;
141 int __init db1550_mtd_init(void)
143 struct mtd_partition *parts;
146 /* Default flash bankwidth */
147 db1550_map.bankwidth = flash_bankwidth;
149 if (setup_flash_params())
153 * Static partition definition selection
155 parts = db1550_partitions;
156 nb_parts = NB_OF(db1550_partitions);
157 db1550_map.size = window_size;
160 * Now let's probe for the actual flash. Do it here since
161 * specific machine settings might have been set above.
163 printk(KERN_NOTICE "Pb1550 flash: probing %d-bit flash bus\n",
164 db1550_map.bankwidth*8);
166 (unsigned long)ioremap(window_addr, window_size);
167 mymtd = do_map_probe("cfi_probe", &db1550_map);
168 if (!mymtd) return -ENXIO;
169 mymtd->owner = THIS_MODULE;
171 add_mtd_partitions(mymtd, parts, nb_parts);
175 static void __exit db1550_mtd_cleanup(void)
178 del_mtd_partitions(mymtd);
183 module_init(db1550_mtd_init);
184 module_exit(db1550_mtd_cleanup);
186 MODULE_AUTHOR("Embedded Edge, LLC");
187 MODULE_DESCRIPTION("Db1550 mtd map driver");
188 MODULE_LICENSE("GPL");