2 * Flash memory access on Alchemy Db1xxx boards
4 * $Id: db1x00-flash.c,v 1.6 2004/11/04 13:24:14 gleixner Exp $
6 * (C) 2003 Pete Popov <ppopov@embeddedalley.com>
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
23 #define DBG(x...) printk(x)
28 /* MTD CONFIG OPTIONS */
29 #if defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
30 #define DB1X00_BOTH_BANKS
31 #elif defined(CONFIG_MTD_DB1X00_BOOT) && !defined(CONFIG_MTD_DB1X00_USER)
32 #define DB1X00_BOOT_ONLY
33 #elif !defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
34 #define DB1X00_USER_ONLY
37 static unsigned long window_addr
;
38 static unsigned long window_size
;
39 static unsigned long flash_size
;
41 static unsigned short *bcsr
= (unsigned short *)0xAE000000;
42 static unsigned char flash_bankwidth
= 4;
45 * The Db1x boards support different flash densities. We setup
46 * the mtd_partition structures below for default of 64Mbit
47 * flash densities, and override the partitions sizes, if
48 * necessary, after we check the board status register.
51 #ifdef DB1X00_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 db1x00_partitions
[] = {
64 .offset
= MTDPART_OFS_APPEND
,
65 .mask_flags
= MTD_WRITEABLE
68 .size
= (0x300000-0x40000), /* last 256KB is env */
69 .offset
= MTDPART_OFS_APPEND
,
72 #elif defined(DB1X00_BOOT_ONLY)
73 static struct mtd_partition db1x00_partitions
[] = {
81 .offset
= MTDPART_OFS_APPEND
,
82 .mask_flags
= MTD_WRITEABLE
85 .size
= (0x300000-0x40000), /* last 256KB is env */
86 .offset
= MTDPART_OFS_APPEND
,
89 #elif defined(DB1X00_USER_ONLY)
90 static struct mtd_partition db1x00_partitions
[] = {
97 .size
= MTDPART_SIZ_FULL
,
98 .offset
= MTDPART_OFS_APPEND
,
102 #error MTD_DB1X00 define combo error /* should never happen */
104 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
106 #define NAME "Db1x00 Linux Flash"
108 static struct map_info db1xxx_mtd_map
= {
112 static struct mtd_partition
*parsed_parts
;
113 static struct mtd_info
*db1xxx_mtd
;
116 * Probe the flash density and setup window address and size
117 * based on user CONFIG options. There are times when we don't
118 * want the MTD driver to be probing the boot or user flash,
119 * so having the option to enable only one bank is important.
121 int setup_flash_params(void)
123 switch ((bcsr
[2] >> 14) & 0x3) {
124 case 0: /* 64Mbit devices */
125 flash_size
= 0x800000; /* 8MB per part */
126 #if defined(DB1X00_BOTH_BANKS)
127 window_addr
= 0x1E000000;
128 window_size
= 0x2000000;
129 #elif defined(DB1X00_BOOT_ONLY)
130 window_addr
= 0x1F000000;
131 window_size
= 0x1000000;
132 #else /* USER ONLY */
133 window_addr
= 0x1E000000;
134 window_size
= 0x1000000;
138 /* 128 Mbit devices */
139 flash_size
= 0x1000000; /* 16MB per part */
140 #if defined(DB1X00_BOTH_BANKS)
141 window_addr
= 0x1C000000;
142 window_size
= 0x4000000;
143 /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
144 db1x00_partitions
[0].size
= 0x3C00000;
145 #elif defined(DB1X00_BOOT_ONLY)
146 window_addr
= 0x1E000000;
147 window_size
= 0x2000000;
148 /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
149 db1x00_partitions
[0].size
= 0x1C00000;
150 #else /* USER ONLY */
151 window_addr
= 0x1C000000;
152 window_size
= 0x2000000;
153 /* USERFS from 0x1C00 0000 to 0x1DE00000 */
154 db1x00_partitions
[0].size
= 0x1DE0000;
158 /* 256 Mbit devices */
159 flash_size
= 0x4000000; /* 64MB per part */
160 #if defined(DB1X00_BOTH_BANKS)
162 #elif defined(DB1X00_BOOT_ONLY)
163 /* Boot ROM flash bank only; no user bank */
164 window_addr
= 0x1C000000;
165 window_size
= 0x4000000;
166 /* USERFS from 0x1C00 0000 to 0x1FC00000 */
167 db1x00_partitions
[0].size
= 0x3C00000;
168 #else /* USER ONLY */
175 db1xxx_mtd_map
.size
= window_size
;
176 db1xxx_mtd_map
.bankwidth
= flash_bankwidth
;
177 db1xxx_mtd_map
.phys
= window_addr
;
178 db1xxx_mtd_map
.bankwidth
= flash_bankwidth
;
182 int __init
db1x00_mtd_init(void)
184 struct mtd_partition
*parts
;
187 if (setup_flash_params())
191 * Static partition definition selection
193 parts
= db1x00_partitions
;
194 nb_parts
= NB_OF(db1x00_partitions
);
197 * Now let's probe for the actual flash. Do it here since
198 * specific machine settings might have been set above.
200 printk(KERN_NOTICE
"Db1xxx flash: probing %d-bit flash bus\n",
201 db1xxx_mtd_map
.bankwidth
*8);
202 db1xxx_mtd_map
.virt
= ioremap(window_addr
, window_size
);
203 db1xxx_mtd
= do_map_probe("cfi_probe", &db1xxx_mtd_map
);
204 if (!db1xxx_mtd
) return -ENXIO
;
205 db1xxx_mtd
->owner
= THIS_MODULE
;
207 add_mtd_partitions(db1xxx_mtd
, parts
, nb_parts
);
211 static void __exit
db1x00_mtd_cleanup(void)
214 del_mtd_partitions(db1xxx_mtd
);
215 map_destroy(db1xxx_mtd
);
221 module_init(db1x00_mtd_init
);
222 module_exit(db1x00_mtd_cleanup
);
224 MODULE_AUTHOR("Pete Popov");
225 MODULE_DESCRIPTION("Db1x00 mtd map driver");
226 MODULE_LICENSE("GPL");