2 * MTD map driver for flash on the DC21285 (the StrongARM-110 companion chip)
4 * (C) 2000 Nicolas Pitre <nico@cam.org>
8 * $Id: dc21285.c,v 1.22 2004/11/01 13:39:21 rmk Exp $
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/mtd/partitions.h>
22 #include <asm/hardware/dec21285.h>
23 #include <asm/mach-types.h>
26 static struct mtd_info
*dc21285_mtd
;
28 #ifdef CONFIG_ARCH_NETWINDER
30 * This is really ugly, but it seams to be the only
31 * realiable way to do it, as the cpld state machine
32 * is unpredictible. So we have a 25us penalty per
35 static void nw_en_write(void)
37 extern spinlock_t gpio_lock
;
41 * we want to write a bit pattern XXX1 to Xilinx to enable
42 * the write gate, which will be open for about the next 2ms.
44 spin_lock_irqsave(&gpio_lock
, flags
);
46 spin_unlock_irqrestore(&gpio_lock
, flags
);
49 * let the ISA bus to catch on...
54 #define nw_en_write() do { } while (0)
57 static map_word
dc21285_read8(struct map_info
*map
, unsigned long ofs
)
60 val
.x
[0] = *(uint8_t*)(map
->virt
+ ofs
);
64 static map_word
dc21285_read16(struct map_info
*map
, unsigned long ofs
)
67 val
.x
[0] = *(uint16_t*)(map
->virt
+ ofs
);
71 static map_word
dc21285_read32(struct map_info
*map
, unsigned long ofs
)
74 val
.x
[0] = *(uint32_t*)(map
->virt
+ ofs
);
78 static void dc21285_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
80 memcpy(to
, (void*)(map
->virt
+ from
), len
);
83 static void dc21285_write8(struct map_info
*map
, const map_word d
, unsigned long adr
)
85 if (machine_is_netwinder())
87 *CSR_ROMWRITEREG
= adr
& 3;
89 *(uint8_t*)(map
->virt
+ adr
) = d
.x
[0];
92 static void dc21285_write16(struct map_info
*map
, const map_word d
, unsigned long adr
)
94 if (machine_is_netwinder())
96 *CSR_ROMWRITEREG
= adr
& 3;
98 *(uint16_t*)(map
->virt
+ adr
) = d
.x
[0];
101 static void dc21285_write32(struct map_info
*map
, const map_word d
, unsigned long adr
)
103 if (machine_is_netwinder())
105 *(uint32_t*)(map
->virt
+ adr
) = d
.x
[0];
108 static void dc21285_copy_to_32(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
112 d
.x
[0] = *((uint32_t*)from
)++;
113 dc21285_write32(map
, d
, to
);
119 static void dc21285_copy_to_16(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
123 d
.x
[0] = *((uint16_t*)from
)++;
124 dc21285_write16(map
, d
, to
);
130 static void dc21285_copy_to_8(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
133 d
.x
[0] = *((uint8_t*)from
)++;
134 dc21285_write8(map
, d
, to
);
139 static struct map_info dc21285_map
= {
140 .name
= "DC21285 flash",
142 .size
= 16*1024*1024,
143 .copy_from
= dc21285_copy_from
,
147 /* Partition stuff */
148 #ifdef CONFIG_MTD_PARTITIONS
149 static struct mtd_partition
*dc21285_parts
;
150 static const char *probes
[] = { "RedBoot", "cmdlinepart", NULL
};
153 static int __init
init_dc21285(void)
156 #ifdef CONFIG_MTD_PARTITIONS
160 /* Determine bankwidth */
161 switch (*CSR_SA110_CNTL
& (3<<14)) {
162 case SA110_CNTL_ROMWIDTH_8
:
163 dc21285_map
.bankwidth
= 1;
164 dc21285_map
.read
= dc21285_read8
;
165 dc21285_map
.write
= dc21285_write8
;
166 dc21285_map
.copy_to
= dc21285_copy_to_8
;
168 case SA110_CNTL_ROMWIDTH_16
:
169 dc21285_map
.bankwidth
= 2;
170 dc21285_map
.read
= dc21285_read16
;
171 dc21285_map
.write
= dc21285_write16
;
172 dc21285_map
.copy_to
= dc21285_copy_to_16
;
174 case SA110_CNTL_ROMWIDTH_32
:
175 dc21285_map
.bankwidth
= 4;
176 dc21285_map
.read
= dc21285_read32
;
177 dc21285_map
.write
= dc21285_write32
;
178 dc21285_map
.copy_to
= dc21285_copy_to_32
;
181 printk (KERN_ERR
"DC21285 flash: undefined bankwidth\n");
184 printk (KERN_NOTICE
"DC21285 flash support (%d-bit bankwidth)\n",
185 dc21285_map
.bankwidth
*8);
187 /* Let's map the flash area */
188 dc21285_map
.virt
= ioremap(DC21285_FLASH
, 16*1024*1024);
189 if (!dc21285_map
.virt
) {
190 printk("Failed to ioremap\n");
194 if (machine_is_ebsa285()) {
195 dc21285_mtd
= do_map_probe("cfi_probe", &dc21285_map
);
197 dc21285_mtd
= do_map_probe("jedec_probe", &dc21285_map
);
201 iounmap(dc21285_map
.virt
);
205 dc21285_mtd
->owner
= THIS_MODULE
;
207 #ifdef CONFIG_MTD_PARTITIONS
208 nrparts
= parse_mtd_partitions(dc21285_mtd
, probes
, &dc21285_parts
, 0);
210 add_mtd_partitions(dc21285_mtd
, dc21285_parts
, nrparts
);
213 add_mtd_device(dc21285_mtd
);
215 if(machine_is_ebsa285()) {
217 * Flash timing is determined with bits 19-16 of the
218 * CSR_SA110_CNTL. The value is the number of wait cycles, or
219 * 0 for 16 cycles (the default). Cycles are 20 ns.
220 * Here we use 7 for 140 ns flash chips.
223 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x000f0000) | (7 << 16));
225 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x00f00000) | (7 << 20));
227 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x0f000000) | (7 << 24));
233 static void __exit
cleanup_dc21285(void)
235 #ifdef CONFIG_MTD_PARTITIONS
237 del_mtd_partitions(dc21285_mtd
);
238 kfree(dc21285_parts
);
241 del_mtd_device(dc21285_mtd
);
243 map_destroy(dc21285_mtd
);
244 iounmap(dc21285_map
.virt
);
247 module_init(init_dc21285
);
248 module_exit(cleanup_dc21285
);
251 MODULE_LICENSE("GPL");
252 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
253 MODULE_DESCRIPTION("MTD map driver for DC21285 boards");