2 * MTD map driver for flash on the DC21285 (the StrongARM-110 companion chip)
4 * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
8 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/partitions.h>
20 #include <asm/hardware/dec21285.h>
21 #include <asm/mach-types.h>
24 static struct mtd_info
*dc21285_mtd
;
26 #ifdef CONFIG_ARCH_NETWINDER
28 * This is really ugly, but it seams to be the only
29 * realiable way to do it, as the cpld state machine
30 * is unpredictible. So we have a 25us penalty per
33 static void nw_en_write(void)
38 * we want to write a bit pattern XXX1 to Xilinx to enable
39 * the write gate, which will be open for about the next 2ms.
41 spin_lock_irqsave(&nw_gpio_lock
, flags
);
42 nw_cpld_modify(CPLD_FLASH_WR_ENABLE
, CPLD_FLASH_WR_ENABLE
);
43 spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
46 * let the ISA bus to catch on...
51 #define nw_en_write() do { } while (0)
54 static map_word
dc21285_read8(struct map_info
*map
, unsigned long ofs
)
57 val
.x
[0] = *(uint8_t*)(map
->virt
+ ofs
);
61 static map_word
dc21285_read16(struct map_info
*map
, unsigned long ofs
)
64 val
.x
[0] = *(uint16_t*)(map
->virt
+ ofs
);
68 static map_word
dc21285_read32(struct map_info
*map
, unsigned long ofs
)
71 val
.x
[0] = *(uint32_t*)(map
->virt
+ ofs
);
75 static void dc21285_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
77 memcpy(to
, (void*)(map
->virt
+ from
), len
);
80 static void dc21285_write8(struct map_info
*map
, const map_word d
, unsigned long adr
)
82 if (machine_is_netwinder())
84 *CSR_ROMWRITEREG
= adr
& 3;
86 *(uint8_t*)(map
->virt
+ adr
) = d
.x
[0];
89 static void dc21285_write16(struct map_info
*map
, const map_word d
, unsigned long adr
)
91 if (machine_is_netwinder())
93 *CSR_ROMWRITEREG
= adr
& 3;
95 *(uint16_t*)(map
->virt
+ adr
) = d
.x
[0];
98 static void dc21285_write32(struct map_info
*map
, const map_word d
, unsigned long adr
)
100 if (machine_is_netwinder())
102 *(uint32_t*)(map
->virt
+ adr
) = d
.x
[0];
105 static void dc21285_copy_to_32(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
109 d
.x
[0] = *((uint32_t*)from
);
110 dc21285_write32(map
, d
, to
);
117 static void dc21285_copy_to_16(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
121 d
.x
[0] = *((uint16_t*)from
);
122 dc21285_write16(map
, d
, to
);
129 static void dc21285_copy_to_8(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
132 d
.x
[0] = *((uint8_t*)from
);
133 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
,
146 /* Partition stuff */
147 static const char * const probes
[] = { "RedBoot", "cmdlinepart", NULL
};
149 static int __init
init_dc21285(void)
151 /* Determine bankwidth */
152 switch (*CSR_SA110_CNTL
& (3<<14)) {
153 case SA110_CNTL_ROMWIDTH_8
:
154 dc21285_map
.bankwidth
= 1;
155 dc21285_map
.read
= dc21285_read8
;
156 dc21285_map
.write
= dc21285_write8
;
157 dc21285_map
.copy_to
= dc21285_copy_to_8
;
159 case SA110_CNTL_ROMWIDTH_16
:
160 dc21285_map
.bankwidth
= 2;
161 dc21285_map
.read
= dc21285_read16
;
162 dc21285_map
.write
= dc21285_write16
;
163 dc21285_map
.copy_to
= dc21285_copy_to_16
;
165 case SA110_CNTL_ROMWIDTH_32
:
166 dc21285_map
.bankwidth
= 4;
167 dc21285_map
.read
= dc21285_read32
;
168 dc21285_map
.write
= dc21285_write32
;
169 dc21285_map
.copy_to
= dc21285_copy_to_32
;
172 printk (KERN_ERR
"DC21285 flash: undefined bankwidth\n");
175 printk (KERN_NOTICE
"DC21285 flash support (%d-bit bankwidth)\n",
176 dc21285_map
.bankwidth
*8);
178 /* Let's map the flash area */
179 dc21285_map
.virt
= ioremap(DC21285_FLASH
, 16*1024*1024);
180 if (!dc21285_map
.virt
) {
181 printk("Failed to ioremap\n");
185 if (machine_is_ebsa285()) {
186 dc21285_mtd
= do_map_probe("cfi_probe", &dc21285_map
);
188 dc21285_mtd
= do_map_probe("jedec_probe", &dc21285_map
);
192 iounmap(dc21285_map
.virt
);
196 dc21285_mtd
->owner
= THIS_MODULE
;
198 mtd_device_parse_register(dc21285_mtd
, probes
, NULL
, NULL
, 0);
200 if(machine_is_ebsa285()) {
202 * Flash timing is determined with bits 19-16 of the
203 * CSR_SA110_CNTL. The value is the number of wait cycles, or
204 * 0 for 16 cycles (the default). Cycles are 20 ns.
205 * Here we use 7 for 140 ns flash chips.
208 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x000f0000) | (7 << 16));
210 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x00f00000) | (7 << 20));
212 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x0f000000) | (7 << 24));
218 static void __exit
cleanup_dc21285(void)
220 mtd_device_unregister(dc21285_mtd
);
221 map_destroy(dc21285_mtd
);
222 iounmap(dc21285_map
.virt
);
225 module_init(init_dc21285
);
226 module_exit(cleanup_dc21285
);
229 MODULE_LICENSE("GPL");
230 MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
231 MODULE_DESCRIPTION("MTD map driver for DC21285 boards");