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.24 2005/11/07 11:14:26 gleixner 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>
16 #include <linux/slab.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/mtd/partitions.h>
23 #include <asm/hardware/dec21285.h>
24 #include <asm/mach-types.h>
27 static struct mtd_info
*dc21285_mtd
;
29 #ifdef CONFIG_ARCH_NETWINDER
31 * This is really ugly, but it seams to be the only
32 * realiable way to do it, as the cpld state machine
33 * is unpredictible. So we have a 25us penalty per
36 static void nw_en_write(void)
38 extern spinlock_t gpio_lock
;
42 * we want to write a bit pattern XXX1 to Xilinx to enable
43 * the write gate, which will be open for about the next 2ms.
45 spin_lock_irqsave(&gpio_lock
, flags
);
47 spin_unlock_irqrestore(&gpio_lock
, flags
);
50 * let the ISA bus to catch on...
55 #define nw_en_write() do { } while (0)
58 static map_word
dc21285_read8(struct map_info
*map
, unsigned long ofs
)
61 val
.x
[0] = *(uint8_t*)(map
->virt
+ ofs
);
65 static map_word
dc21285_read16(struct map_info
*map
, unsigned long ofs
)
68 val
.x
[0] = *(uint16_t*)(map
->virt
+ ofs
);
72 static map_word
dc21285_read32(struct map_info
*map
, unsigned long ofs
)
75 val
.x
[0] = *(uint32_t*)(map
->virt
+ ofs
);
79 static void dc21285_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
81 memcpy(to
, (void*)(map
->virt
+ from
), len
);
84 static void dc21285_write8(struct map_info
*map
, const map_word d
, unsigned long adr
)
86 if (machine_is_netwinder())
88 *CSR_ROMWRITEREG
= adr
& 3;
90 *(uint8_t*)(map
->virt
+ adr
) = d
.x
[0];
93 static void dc21285_write16(struct map_info
*map
, const map_word d
, unsigned long adr
)
95 if (machine_is_netwinder())
97 *CSR_ROMWRITEREG
= adr
& 3;
99 *(uint16_t*)(map
->virt
+ adr
) = d
.x
[0];
102 static void dc21285_write32(struct map_info
*map
, const map_word d
, unsigned long adr
)
104 if (machine_is_netwinder())
106 *(uint32_t*)(map
->virt
+ adr
) = d
.x
[0];
109 static void dc21285_copy_to_32(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
113 d
.x
[0] = *((uint32_t*)from
)++;
114 dc21285_write32(map
, d
, to
);
120 static void dc21285_copy_to_16(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
124 d
.x
[0] = *((uint16_t*)from
)++;
125 dc21285_write16(map
, d
, to
);
131 static void dc21285_copy_to_8(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
134 d
.x
[0] = *((uint8_t*)from
)++;
135 dc21285_write8(map
, d
, to
);
140 static struct map_info dc21285_map
= {
141 .name
= "DC21285 flash",
143 .size
= 16*1024*1024,
144 .copy_from
= dc21285_copy_from
,
148 /* Partition stuff */
149 #ifdef CONFIG_MTD_PARTITIONS
150 static struct mtd_partition
*dc21285_parts
;
151 static const char *probes
[] = { "RedBoot", "cmdlinepart", NULL
};
154 static int __init
init_dc21285(void)
157 #ifdef CONFIG_MTD_PARTITIONS
161 /* Determine bankwidth */
162 switch (*CSR_SA110_CNTL
& (3<<14)) {
163 case SA110_CNTL_ROMWIDTH_8
:
164 dc21285_map
.bankwidth
= 1;
165 dc21285_map
.read
= dc21285_read8
;
166 dc21285_map
.write
= dc21285_write8
;
167 dc21285_map
.copy_to
= dc21285_copy_to_8
;
169 case SA110_CNTL_ROMWIDTH_16
:
170 dc21285_map
.bankwidth
= 2;
171 dc21285_map
.read
= dc21285_read16
;
172 dc21285_map
.write
= dc21285_write16
;
173 dc21285_map
.copy_to
= dc21285_copy_to_16
;
175 case SA110_CNTL_ROMWIDTH_32
:
176 dc21285_map
.bankwidth
= 4;
177 dc21285_map
.read
= dc21285_read32
;
178 dc21285_map
.write
= dc21285_write32
;
179 dc21285_map
.copy_to
= dc21285_copy_to_32
;
182 printk (KERN_ERR
"DC21285 flash: undefined bankwidth\n");
185 printk (KERN_NOTICE
"DC21285 flash support (%d-bit bankwidth)\n",
186 dc21285_map
.bankwidth
*8);
188 /* Let's map the flash area */
189 dc21285_map
.virt
= ioremap(DC21285_FLASH
, 16*1024*1024);
190 if (!dc21285_map
.virt
) {
191 printk("Failed to ioremap\n");
195 if (machine_is_ebsa285()) {
196 dc21285_mtd
= do_map_probe("cfi_probe", &dc21285_map
);
198 dc21285_mtd
= do_map_probe("jedec_probe", &dc21285_map
);
202 iounmap(dc21285_map
.virt
);
206 dc21285_mtd
->owner
= THIS_MODULE
;
208 #ifdef CONFIG_MTD_PARTITIONS
209 nrparts
= parse_mtd_partitions(dc21285_mtd
, probes
, &dc21285_parts
, 0);
211 add_mtd_partitions(dc21285_mtd
, dc21285_parts
, nrparts
);
214 add_mtd_device(dc21285_mtd
);
216 if(machine_is_ebsa285()) {
218 * Flash timing is determined with bits 19-16 of the
219 * CSR_SA110_CNTL. The value is the number of wait cycles, or
220 * 0 for 16 cycles (the default). Cycles are 20 ns.
221 * Here we use 7 for 140 ns flash chips.
224 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x000f0000) | (7 << 16));
226 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x00f00000) | (7 << 20));
228 *CSR_SA110_CNTL
= ((*CSR_SA110_CNTL
& ~0x0f000000) | (7 << 24));
234 static void __exit
cleanup_dc21285(void)
236 #ifdef CONFIG_MTD_PARTITIONS
238 del_mtd_partitions(dc21285_mtd
);
239 kfree(dc21285_parts
);
242 del_mtd_device(dc21285_mtd
);
244 map_destroy(dc21285_mtd
);
245 iounmap(dc21285_map
.virt
);
248 module_init(init_dc21285
);
249 module_exit(cleanup_dc21285
);
252 MODULE_LICENSE("GPL");
253 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
254 MODULE_DESCRIPTION("MTD map driver for DC21285 boards");