2 * Flash memory access on Alchemy Db1xxx boards
4 * $Id: db1x00-flash.c,v 1.3 2004/07/14 17:45:40 dwmw2 Exp $
6 * (C) 2003 Pete Popov <ppopov@pacbell.net>
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>
21 #include <asm/au1000.h>
22 #include <asm/db1x00.h>
25 #define DBG(x...) printk(x)
30 static unsigned long window_addr;
31 static unsigned long window_size;
32 static unsigned long flash_size;
34 static BCSR * const bcsr = (BCSR *)0xAE000000;
35 static unsigned char flash_bankwidth = 4;
38 * The Db1x boards support different flash densities. We setup
39 * the mtd_partition structures below for default of 64Mbit
40 * flash densities, and override the partitions sizes, if
41 * necessary, after we check the board status register.
44 #ifdef DB1X00_BOTH_BANKS
45 /* both banks will be used. Combine the first bank and the first
46 * part of the second bank together into a single jffs/jffs2
49 static struct mtd_partition db1x00_partitions[] = {
57 .offset = MTDPART_OFS_APPEND,
58 .mask_flags = MTD_WRITEABLE
61 .size = (0x300000-0x40000), /* last 256KB is env */
62 .offset = MTDPART_OFS_APPEND,
65 #elif defined(DB1X00_BOOT_ONLY)
66 static struct mtd_partition db1x00_partitions[] = {
74 .offset = MTDPART_OFS_APPEND,
75 .mask_flags = MTD_WRITEABLE
78 .size = (0x300000-0x40000), /* last 256KB is env */
79 .offset = MTDPART_OFS_APPEND,
82 #elif defined(DB1X00_USER_ONLY)
83 static struct mtd_partition db1x00_partitions[] = {
90 .size = MTDPART_SIZ_FULL,
91 .offset = MTDPART_OFS_APPEND,
95 #error MTD_DB1X00 define combo error /* should never happen */
97 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
99 #define NAME "Db1x00 Linux Flash"
101 static struct map_info db1xxx_mtd_map = {
105 static struct mtd_partition *parsed_parts;
106 static struct mtd_info *db1xxx_mtd;
109 * Probe the flash density and setup window address and size
110 * based on user CONFIG options. There are times when we don't
111 * want the MTD driver to be probing the boot or user flash,
112 * so having the option to enable only one bank is important.
114 int setup_flash_params(void)
116 switch ((bcsr->status >> 14) & 0x3) {
117 case 0: /* 64Mbit devices */
118 flash_size = 0x800000; /* 8MB per part */
119 #if defined(DB1X00_BOTH_BANKS)
120 window_addr = 0x1E000000;
121 window_size = 0x2000000;
122 #elif defined(DB1X00_BOOT_ONLY)
123 window_addr = 0x1F000000;
124 window_size = 0x1000000;
125 #else /* USER ONLY */
126 window_addr = 0x1E000000;
127 window_size = 0x1000000;
131 /* 128 Mbit devices */
132 flash_size = 0x1000000; /* 16MB per part */
133 #if defined(DB1X00_BOTH_BANKS)
134 window_addr = 0x1C000000;
135 window_size = 0x4000000;
136 /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
137 db1x00_partitions[0].size = 0x3C00000;
138 #elif defined(DB1X00_BOOT_ONLY)
139 window_addr = 0x1E000000;
140 window_size = 0x2000000;
141 /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
142 db1x00_partitions[0].size = 0x1C00000;
143 #else /* USER ONLY */
144 window_addr = 0x1C000000;
145 window_size = 0x2000000;
146 /* USERFS from 0x1C00 0000 to 0x1DE00000 */
147 db1x00_partitions[0].size = 0x1DE0000;
151 /* 256 Mbit devices */
152 flash_size = 0x4000000; /* 64MB per part */
153 #if defined(DB1X00_BOTH_BANKS)
155 #elif defined(DB1X00_BOOT_ONLY)
156 /* Boot ROM flash bank only; no user bank */
157 window_addr = 0x1C000000;
158 window_size = 0x4000000;
159 /* USERFS from 0x1C00 0000 to 0x1FC00000 */
160 db1x00_partitions[0].size = 0x3C00000;
161 #else /* USER ONLY */
168 db1xxx_mtd_map.size = window_size;
169 db1xxx_mtd_map.bankwidth = flash_bankwidth;
170 db1xxx_mtd_map.phys = window_addr;
171 db1xxx_mtd_map.bankwidth = flash_bankwidth;
175 int __init db1x00_mtd_init(void)
177 struct mtd_partition *parts;
180 if (setup_flash_params())
184 * Static partition definition selection
186 parts = db1x00_partitions;
187 nb_parts = NB_OF(db1x00_partitions);
190 * Now let's probe for the actual flash. Do it here since
191 * specific machine settings might have been set above.
193 printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n",
194 db1xxx_mtd_map.bankwidth*8);
195 db1xxx_mtd_map.virt = (unsigned long)ioremap(window_addr, window_size);
196 db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map);
197 if (!db1xxx_mtd) return -ENXIO;
198 db1xxx_mtd->owner = THIS_MODULE;
200 add_mtd_partitions(db1xxx_mtd, parts, nb_parts);
204 static void __exit db1x00_mtd_cleanup(void)
207 del_mtd_partitions(db1xxx_mtd);
208 map_destroy(db1xxx_mtd);
214 module_init(db1x00_mtd_init);
215 module_exit(db1x00_mtd_cleanup);
217 MODULE_AUTHOR("Pete Popov");
218 MODULE_DESCRIPTION("Db1x00 mtd map driver");
219 MODULE_LICENSE("GPL");