2 * Flash memory access on Alchemy Db1550 board
4 * $Id: db1550-flash.c,v 1.7 2004/11/04 13:24:14 gleixner Exp $
6 * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c:
7 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.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>
24 #define DBG(x...) printk(x)
29 static unsigned long window_addr
;
30 static unsigned long window_size
;
33 static struct map_info db1550_map
= {
34 .name
= "Db1550 flash",
37 static unsigned char flash_bankwidth
= 4;
40 * Support only 64MB NOR Flash parts
43 #if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
44 #define DB1550_BOTH_BANKS
45 #elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER)
46 #define DB1550_BOOT_ONLY
47 #elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
48 #define DB1550_USER_ONLY
51 #ifdef DB1550_BOTH_BANKS
52 /* both banks will be used. Combine the first bank and the first
53 * part of the second bank together into a single jffs/jffs2
56 static struct mtd_partition db1550_partitions
[] = {
57 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
58 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
59 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
63 .size
= (0x1FC00000 - 0x18000000),
68 .offset
= MTDPART_OFS_APPEND
,
69 .mask_flags
= MTD_WRITEABLE
72 .size
= (0x300000 - 0x40000), /* last 256KB is yamon env */
73 .offset
= MTDPART_OFS_APPEND
,
76 #elif defined(DB1550_BOOT_ONLY)
77 static struct mtd_partition db1550_partitions
[] = {
78 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
79 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
88 .offset
= MTDPART_OFS_APPEND
,
89 .mask_flags
= MTD_WRITEABLE
92 .size
= (0x300000-0x40000), /* last 256KB is yamon env */
93 .offset
= MTDPART_OFS_APPEND
,
96 #elif defined(DB1550_USER_ONLY)
97 static struct mtd_partition db1550_partitions
[] = {
98 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
99 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
103 .size
= (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
106 .name
= "raw kernel",
107 .size
= MTDPART_SIZ_FULL
,
108 .offset
= MTDPART_OFS_APPEND
,
112 #error MTD_DB1550 define combo error /* should never happen */
115 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
117 static struct mtd_info
*mymtd
;
120 * Probe the flash density and setup window address and size
121 * based on user CONFIG options. There are times when we don't
122 * want the MTD driver to be probing the boot or user flash,
123 * so having the option to enable only one bank is important.
125 int setup_flash_params(void)
127 #if defined(DB1550_BOTH_BANKS)
128 window_addr
= 0x18000000;
129 window_size
= 0x8000000;
130 #elif defined(DB1550_BOOT_ONLY)
131 window_addr
= 0x1C000000;
132 window_size
= 0x4000000;
133 #else /* USER ONLY */
134 window_addr
= 0x18000000;
135 window_size
= 0x4000000;
140 int __init
db1550_mtd_init(void)
142 struct mtd_partition
*parts
;
145 /* Default flash bankwidth */
146 db1550_map
.bankwidth
= flash_bankwidth
;
148 if (setup_flash_params())
152 * Static partition definition selection
154 parts
= db1550_partitions
;
155 nb_parts
= NB_OF(db1550_partitions
);
156 db1550_map
.size
= window_size
;
159 * Now let's probe for the actual flash. Do it here since
160 * specific machine settings might have been set above.
162 printk(KERN_NOTICE
"Db1550 flash: probing %d-bit flash bus\n",
163 db1550_map
.bankwidth
*8);
164 db1550_map
.virt
= ioremap(window_addr
, window_size
);
165 mymtd
= do_map_probe("cfi_probe", &db1550_map
);
166 if (!mymtd
) return -ENXIO
;
167 mymtd
->owner
= THIS_MODULE
;
169 add_mtd_partitions(mymtd
, parts
, nb_parts
);
173 static void __exit
db1550_mtd_cleanup(void)
176 del_mtd_partitions(mymtd
);
178 iounmap((void *) db1550_map
.virt
);
182 module_init(db1550_mtd_init
);
183 module_exit(db1550_mtd_cleanup
);
185 MODULE_AUTHOR("Embedded Edge, LLC");
186 MODULE_DESCRIPTION("Db1550 mtd map driver");
187 MODULE_LICENSE("GPL");