2 * Flash memory access on iPAQ Handhelds (either SA1100 or PXA250 based)
4 * (C) 2000 Nicolas Pitre <nico@cam.org>
5 * (C) 2002 Hewlett-Packard Company <jamey.hicks@hp.com>
6 * (C) 2003 Christian Pellegrin <chri@ascensit.com>, <chri@infis.univ.ts.it>: concatenation of multiple flashes
8 * $Id: ipaq-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/spinlock.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
18 #include <asm/mach-types.h>
19 #include <asm/system.h>
20 #include <asm/errno.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/map.h>
24 #include <linux/mtd/partitions.h>
25 #ifdef CONFIG_MTD_CONCAT
26 #include <linux/mtd/concat.h>
29 #include <asm/hardware.h>
30 #include <asm/arch-sa1100/h3600.h>
34 #ifndef CONFIG_IPAQ_HANDHELD
35 #error This is for iPAQ Handhelds only
37 #ifdef CONFIG_SA1100_JORNADA56X
39 static void jornada56x_set_vpp(struct map_info *map, int vpp)
50 #ifdef CONFIG_SA1100_JORNADA720
52 static void jornada720_set_vpp(struct map_info *map, int vpp)
63 #define MAX_IPAQ_CS 2 /* Number of CS we are going to test */
65 #define IPAQ_MAP_INIT(X) \
67 name: "IPAQ flash " X, \
71 static struct map_info ipaq_map[MAX_IPAQ_CS] = {
72 IPAQ_MAP_INIT("bank 1"),
73 IPAQ_MAP_INIT("bank 2")
76 static struct mtd_info *my_sub_mtd[MAX_IPAQ_CS] = {
82 * Here are partition information for all known IPAQ-based devices.
83 * See include/linux/mtd/partitions.h for definition of the mtd_partition
86 * The *_max_flash_size is the maximum possible mapped flash size which
87 * is not necessarily the actual flash size. It must be no more than
88 * the value specified in the "struct map_desc *_io_desc" mapping
89 * definition for the corresponding machine.
91 * Please keep these in alphabetical order, and formatted as per existing
95 #ifdef CONFIG_IPAQ_HANDHELD
96 static unsigned long h3xxx_max_flash_size = 0x04000000;
97 static struct mtd_partition h3xxx_partitions[] = {
99 name: "H3XXX boot firmware",
107 mask_flags: MTD_WRITEABLE, /* force read-only */
111 name: "H3XXX root jffs2",
113 size: 0x2000000 - 2*0x40000, /* Warning, this is fixed later */
116 size: 0x2000000 - 0x40000 - 0x80000, /* Warning, this is fixed later */
123 offset: 0x2000000 - 0x40000, /* Warning, this is fixed later */
124 mask_flags: MTD_WRITEABLE, /* force read-only */
128 #ifndef CONFIG_MTD_CONCAT
129 static struct mtd_partition h3xxx_partitions_bank2[] = {
130 /* this is used only on 2 CS machines when concat is not present */
132 name: "second H3XXX root jffs2",
133 size: 0x1000000 - 0x40000, /* Warning, this is fixed later */
137 name: "second asset",
139 offset: 0x1000000 - 0x40000, /* Warning, this is fixed later */
140 mask_flags: MTD_WRITEABLE, /* force read-only */
145 static DEFINE_SPINLOCK(ipaq_vpp_lock);
147 static void h3xxx_set_vpp(struct map_info *map, int vpp)
151 spin_lock(&ipaq_vpp_lock);
157 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 1);
159 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 0);
160 spin_unlock(&ipaq_vpp_lock);
165 #if defined(CONFIG_SA1100_JORNADA56X) || defined(CONFIG_SA1100_JORNADA720)
166 static unsigned long jornada_max_flash_size = 0x02000000;
167 static struct mtd_partition jornada_partitions[] = {
169 name: "Jornada boot firmware",
172 mask_flags: MTD_WRITEABLE, /* force read-only */
174 name: "Jornada root jffs2",
175 size: MTDPART_SIZ_FULL,
182 static struct mtd_partition *parsed_parts;
183 static struct mtd_info *mymtd;
185 static unsigned long cs_phys[] = {
186 #ifdef CONFIG_ARCH_SA1100
203 static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
205 static int __init h1900_special_case(void);
207 int __init ipaq_mtd_init(void)
209 struct mtd_partition *parts = NULL;
211 int parsed_nr_parts = 0;
212 const char *part_type;
213 int i; /* used when we have >1 flash chips */
214 unsigned long tot_flashsize = 0; /* used when we have >1 flash chips */
216 /* Default flash bankwidth */
217 // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
219 if (machine_is_h1900())
221 /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */
222 return h1900_special_case();
225 if (machine_is_h3100() || machine_is_h1900())
226 for(i=0; i<MAX_IPAQ_CS; i++)
227 ipaq_map[i].bankwidth = 2;
229 for(i=0; i<MAX_IPAQ_CS; i++)
230 ipaq_map[i].bankwidth = 4;
233 * Static partition definition selection
235 part_type = "static";
237 simple_map_init(&ipaq_map[0]);
238 simple_map_init(&ipaq_map[1]);
240 #ifdef CONFIG_IPAQ_HANDHELD
241 if (machine_is_ipaq()) {
242 parts = h3xxx_partitions;
243 nb_parts = ARRAY_SIZE(h3xxx_partitions);
244 for(i=0; i<MAX_IPAQ_CS; i++) {
245 ipaq_map[i].size = h3xxx_max_flash_size;
246 ipaq_map[i].set_vpp = h3xxx_set_vpp;
247 ipaq_map[i].phys = cs_phys[i];
248 ipaq_map[i].virt = ioremap(cs_phys[i], 0x04000000);
249 if (machine_is_h3100 () || machine_is_h1900())
250 ipaq_map[i].bankwidth = 2;
252 if (machine_is_h3600()) {
253 /* No asset partition here */
254 h3xxx_partitions[1].size += 0x40000;
259 #ifdef CONFIG_ARCH_H5400
260 if (machine_is_h5400()) {
261 ipaq_map[0].size = 0x02000000;
262 ipaq_map[1].size = 0x02000000;
263 ipaq_map[1].phys = 0x02000000;
264 ipaq_map[1].virt = ipaq_map[0].virt + 0x02000000;
267 #ifdef CONFIG_ARCH_H1900
268 if (machine_is_h1900()) {
269 ipaq_map[0].size = 0x00400000;
270 ipaq_map[1].size = 0x02000000;
271 ipaq_map[1].phys = 0x00080000;
272 ipaq_map[1].virt = ipaq_map[0].virt + 0x00080000;
276 #ifdef CONFIG_SA1100_JORNADA56X
277 if (machine_is_jornada56x()) {
278 parts = jornada_partitions;
279 nb_parts = ARRAY_SIZE(jornada_partitions);
280 ipaq_map[0].size = jornada_max_flash_size;
281 ipaq_map[0].set_vpp = jornada56x_set_vpp;
282 ipaq_map[0].virt = (__u32)ioremap(0x0, 0x04000000);
285 #ifdef CONFIG_SA1100_JORNADA720
286 if (machine_is_jornada720()) {
287 parts = jornada_partitions;
288 nb_parts = ARRAY_SIZE(jornada_partitions);
289 ipaq_map[0].size = jornada_max_flash_size;
290 ipaq_map[0].set_vpp = jornada720_set_vpp;
295 if (machine_is_ipaq()) { /* for iPAQs only */
296 for(i=0; i<MAX_IPAQ_CS; i++) {
297 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with CFI.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
298 my_sub_mtd[i] = do_map_probe("cfi_probe", &ipaq_map[i]);
299 if (!my_sub_mtd[i]) {
300 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
301 my_sub_mtd[i] = do_map_probe("jedec_probe", &ipaq_map[i]);
303 if (!my_sub_mtd[i]) {
304 printk(KERN_NOTICE "iPAQ flash: failed to find flash.\n");
310 printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size);
312 /* do we really need this debugging? --joshua 20030703 */
313 // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]);
314 my_sub_mtd[i]->owner = THIS_MODULE;
315 tot_flashsize += my_sub_mtd[i]->size;
317 #ifdef CONFIG_MTD_CONCAT
318 /* fix the asset location */
320 h3xxx_partitions[1].size = tot_flashsize - 0x40000 - 0x80000 /* extra big boot block */;
322 h3xxx_partitions[1].size = tot_flashsize - 2 * 0x40000;
324 h3xxx_partitions[2].offset = tot_flashsize - 0x40000;
325 /* and concat the devices */
326 mymtd = mtd_concat_create(&my_sub_mtd[0], i,
329 printk("Cannot create iPAQ concat device\n");
333 mymtd = my_sub_mtd[0];
336 *In the very near future, command line partition parsing
337 * will use the device name as 'mtd-id' instead of a value
338 * passed to the parse_cmdline_partitions() routine. Since
339 * the bootldr says 'ipaq', make sure it continues to work.
341 mymtd->name = "ipaq";
343 if ((machine_is_h3600())) {
345 h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x80000;
347 h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000;
352 h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000 - 0x80000; /* extra big boot block */
354 h3xxx_partitions[1].size = my_sub_mtd[0]->size - 2*0x40000;
356 h3xxx_partitions[2].offset = my_sub_mtd[0]->size - 0x40000;
361 h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x80000;
363 h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x40000;
365 h3xxx_partitions_bank2[1].offset = my_sub_mtd[1]->size - 0x40000;
371 * Now let's probe for the actual flash. Do it here since
372 * specific machine settings might have been set above.
374 printk(KERN_NOTICE "IPAQ flash: probing %d-bit flash bus, window=%lx\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
375 mymtd = do_map_probe("cfi_probe", &ipaq_map[0]);
378 mymtd->owner = THIS_MODULE;
383 * Dynamic partition selection stuff (might override the static ones)
386 i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0);
389 nb_parts = parsed_nr_parts = i;
390 parts = parsed_parts;
391 part_type = "dynamic";
395 printk(KERN_NOTICE "IPAQ flash: no partition info available, registering whole flash at once\n");
396 add_mtd_device(mymtd);
397 #ifndef CONFIG_MTD_CONCAT
399 add_mtd_device(my_sub_mtd[1]);
402 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
403 add_mtd_partitions(mymtd, parts, nb_parts);
404 #ifndef CONFIG_MTD_CONCAT
406 add_mtd_partitions(my_sub_mtd[1], h3xxx_partitions_bank2, ARRAY_SIZE(h3xxx_partitions_bank2));
413 static void __exit ipaq_mtd_cleanup(void)
418 del_mtd_partitions(mymtd);
419 #ifndef CONFIG_MTD_CONCAT
421 del_mtd_partitions(my_sub_mtd[1]);
424 #ifdef CONFIG_MTD_CONCAT
425 for(i=0; i<MAX_IPAQ_CS; i++)
427 for(i=1; i<MAX_IPAQ_CS; i++)
431 map_destroy(my_sub_mtd[i]);
437 static int __init h1900_special_case(void)
439 /* The iPAQ h1900 is a special case - it has weird ROM. */
440 simple_map_init(&ipaq_map[0]);
441 ipaq_map[0].size = 0x80000;
442 ipaq_map[0].set_vpp = h3xxx_set_vpp;
443 ipaq_map[0].phys = 0x0;
444 ipaq_map[0].virt = ioremap(0x0, 0x04000000);
445 ipaq_map[0].bankwidth = 2;
447 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
448 mymtd = do_map_probe("jedec_probe", &ipaq_map[0]);
451 add_mtd_device(mymtd);
452 printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n");
457 module_init(ipaq_mtd_init);
458 module_exit(ipaq_mtd_cleanup);
460 MODULE_AUTHOR("Jamey Hicks");
461 MODULE_DESCRIPTION("IPAQ CFI map driver");
462 MODULE_LICENSE("MIT");