2 * Flash memory access on Alchemy Pb1550 board
4 * $Id: pb1550-flash.c,v 1.6 2004/11/04 13:24:15 gleixner Exp $
6 * (C) 2004 Embedded Edge, LLC, based on pb1550-flash.c:
7 * (C) 2003 Pete Popov <ppopov@pacbell.net>
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>
23 #include <asm/pb1550.h>
26 #define DBG(x...) printk(x)
31 static unsigned long window_addr
;
32 static unsigned long window_size
;
35 static struct map_info pb1550_map
= {
36 .name
= "Pb1550 flash",
39 static unsigned char flash_bankwidth
= 4;
42 * Support only 64MB NOR Flash parts
45 #ifdef PB1550_BOTH_BANKS
46 /* both banks will be used. Combine the first bank and the first
47 * part of the second bank together into a single jffs/jffs2
50 static struct mtd_partition pb1550_partitions
[] = {
51 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
52 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
53 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
57 .size
= (0x1FC00000 - 0x18000000),
62 .offset
= MTDPART_OFS_APPEND
,
63 .mask_flags
= MTD_WRITEABLE
66 .size
= (0x300000 - 0x40000), /* last 256KB is yamon env */
67 .offset
= MTDPART_OFS_APPEND
,
70 #elif defined(PB1550_BOOT_ONLY)
71 static struct mtd_partition pb1550_partitions
[] = {
72 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
73 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
82 .offset
= MTDPART_OFS_APPEND
,
83 .mask_flags
= MTD_WRITEABLE
86 .size
= (0x300000-0x40000), /* last 256KB is yamon env */
87 .offset
= MTDPART_OFS_APPEND
,
90 #elif defined(PB1550_USER_ONLY)
91 static struct mtd_partition pb1550_partitions
[] = {
92 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
93 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
97 .size
= (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
100 .name
= "raw kernel",
101 .size
= MTDPART_SIZ_FULL
,
102 .offset
= MTDPART_OFS_APPEND
,
106 #error MTD_PB1550 define combo error /* should never happen */
109 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
111 static struct mtd_info
*mymtd
;
114 * Probe the flash density and setup window address and size
115 * based on user CONFIG options. There are times when we don't
116 * want the MTD driver to be probing the boot or user flash,
117 * so having the option to enable only one bank is important.
119 int setup_flash_params(void)
122 boot_swapboot
= (au_readl(MEM_STSTAT
) & (0x7<<1)) |
123 ((bcsr
->status
>> 6) & 0x1);
124 printk("Pb1550 MTD: boot:swap %d\n", boot_swapboot
);
126 switch (boot_swapboot
) {
127 case 0: /* 512Mbit devices, both enabled */
131 #if defined(PB1550_BOTH_BANKS)
132 window_addr
= 0x18000000;
133 window_size
= 0x8000000;
134 #elif defined(PB1550_BOOT_ONLY)
135 window_addr
= 0x1C000000;
136 window_size
= 0x4000000;
137 #else /* USER ONLY */
138 window_addr
= 0x1E000000;
139 window_size
= 0x4000000;
146 /* 64 MB Boot NOR Flash is disabled */
147 /* and the start address is moved to 0x0C00000 */
148 window_addr
= 0x0C000000;
149 window_size
= 0x4000000;
151 printk("Pb1550 MTD: unsupported boot:swap setting\n");
157 int __init
pb1550_mtd_init(void)
159 struct mtd_partition
*parts
;
162 /* Default flash bankwidth */
163 pb1550_map
.bankwidth
= flash_bankwidth
;
165 if (setup_flash_params())
169 * Static partition definition selection
171 parts
= pb1550_partitions
;
172 nb_parts
= NB_OF(pb1550_partitions
);
173 pb1550_map
.size
= window_size
;
176 * Now let's probe for the actual flash. Do it here since
177 * specific machine settings might have been set above.
179 printk(KERN_NOTICE
"Pb1550 flash: probing %d-bit flash bus\n",
180 pb1550_map
.bankwidth
*8);
181 pb1550_map
.virt
= ioremap(window_addr
, window_size
);
182 mymtd
= do_map_probe("cfi_probe", &pb1550_map
);
183 if (!mymtd
) return -ENXIO
;
184 mymtd
->owner
= THIS_MODULE
;
186 add_mtd_partitions(mymtd
, parts
, nb_parts
);
190 static void __exit
pb1550_mtd_cleanup(void)
193 del_mtd_partitions(mymtd
);
198 module_init(pb1550_mtd_init
);
199 module_exit(pb1550_mtd_cleanup
);
201 MODULE_AUTHOR("Embedded Edge, LLC");
202 MODULE_DESCRIPTION("Pb1550 mtd map driver");
203 MODULE_LICENSE("GPL");