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/config.h>
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/spinlock.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
19 #include <asm/mach-types.h>
20 #include <asm/system.h>
21 #include <asm/errno.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/partitions.h>
26 #ifdef CONFIG_MTD_CONCAT
27 #include <linux/mtd/concat.h>
30 #include <asm/hardware.h>
31 #include <asm/arch-sa1100/h3600.h>
35 #ifndef CONFIG_IPAQ_HANDHELD
36 #error This is for iPAQ Handhelds only
38 #ifdef CONFIG_SA1100_JORNADA56X
40 static void jornada56x_set_vpp(struct map_info
*map
, int vpp
)
51 #ifdef CONFIG_SA1100_JORNADA720
53 static void jornada720_set_vpp(struct map_info
*map
, int vpp
)
64 #define MAX_IPAQ_CS 2 /* Number of CS we are going to test */
66 #define IPAQ_MAP_INIT(X) \
68 name: "IPAQ flash " X, \
72 static struct map_info ipaq_map
[MAX_IPAQ_CS
] = {
73 IPAQ_MAP_INIT("bank 1"),
74 IPAQ_MAP_INIT("bank 2")
77 static struct mtd_info
*my_sub_mtd
[MAX_IPAQ_CS
] = {
83 * Here are partition information for all known IPAQ-based devices.
84 * See include/linux/mtd/partitions.h for definition of the mtd_partition
87 * The *_max_flash_size is the maximum possible mapped flash size which
88 * is not necessarily the actual flash size. It must be no more than
89 * the value specified in the "struct map_desc *_io_desc" mapping
90 * definition for the corresponding machine.
92 * Please keep these in alphabetical order, and formatted as per existing
96 #ifdef CONFIG_IPAQ_HANDHELD
97 static unsigned long h3xxx_max_flash_size
= 0x04000000;
98 static struct mtd_partition h3xxx_partitions
[] = {
100 name
: "H3XXX boot firmware",
108 mask_flags
: MTD_WRITEABLE
, /* force read-only */
112 name
: "H3XXX root jffs2",
114 size
: 0x2000000 - 2*0x40000, /* Warning, this is fixed later */
117 size
: 0x2000000 - 0x40000 - 0x80000, /* Warning, this is fixed later */
124 offset
: 0x2000000 - 0x40000, /* Warning, this is fixed later */
125 mask_flags
: MTD_WRITEABLE
, /* force read-only */
129 #ifndef CONFIG_MTD_CONCAT
130 static struct mtd_partition h3xxx_partitions_bank2
[] = {
131 /* this is used only on 2 CS machines when concat is not present */
133 name
: "second H3XXX root jffs2",
134 size
: 0x1000000 - 0x40000, /* Warning, this is fixed later */
138 name
: "second asset",
140 offset
: 0x1000000 - 0x40000, /* Warning, this is fixed later */
141 mask_flags
: MTD_WRITEABLE
, /* force read-only */
146 static DEFINE_SPINLOCK(ipaq_vpp_lock
);
148 static void h3xxx_set_vpp(struct map_info
*map
, int vpp
)
152 spin_lock(&ipaq_vpp_lock
);
158 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON
, 1);
160 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON
, 0);
161 spin_unlock(&ipaq_vpp_lock
);
166 #if defined(CONFIG_SA1100_JORNADA56X) || defined(CONFIG_SA1100_JORNADA720)
167 static unsigned long jornada_max_flash_size
= 0x02000000;
168 static struct mtd_partition jornada_partitions
[] = {
170 name
: "Jornada boot firmware",
173 mask_flags
: MTD_WRITEABLE
, /* force read-only */
175 name
: "Jornada root jffs2",
176 size
: MTDPART_SIZ_FULL
,
183 static struct mtd_partition
*parsed_parts
;
184 static struct mtd_info
*mymtd
;
186 static unsigned long cs_phys
[] = {
187 #ifdef CONFIG_ARCH_SA1100
204 static const char *part_probes
[] = { "cmdlinepart", "RedBoot", NULL
};
206 static int __init
h1900_special_case(void);
208 int __init
ipaq_mtd_init(void)
210 struct mtd_partition
*parts
= NULL
;
212 int parsed_nr_parts
= 0;
213 const char *part_type
;
214 int i
; /* used when we have >1 flash chips */
215 unsigned long tot_flashsize
= 0; /* used when we have >1 flash chips */
217 /* Default flash bankwidth */
218 // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
220 if (machine_is_h1900())
222 /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */
223 return h1900_special_case();
226 if (machine_is_h3100() || machine_is_h1900())
227 for(i
=0; i
<MAX_IPAQ_CS
; i
++)
228 ipaq_map
[i
].bankwidth
= 2;
230 for(i
=0; i
<MAX_IPAQ_CS
; i
++)
231 ipaq_map
[i
].bankwidth
= 4;
234 * Static partition definition selection
236 part_type
= "static";
238 simple_map_init(&ipaq_map
[0]);
239 simple_map_init(&ipaq_map
[1]);
241 #ifdef CONFIG_IPAQ_HANDHELD
242 if (machine_is_ipaq()) {
243 parts
= h3xxx_partitions
;
244 nb_parts
= ARRAY_SIZE(h3xxx_partitions
);
245 for(i
=0; i
<MAX_IPAQ_CS
; i
++) {
246 ipaq_map
[i
].size
= h3xxx_max_flash_size
;
247 ipaq_map
[i
].set_vpp
= h3xxx_set_vpp
;
248 ipaq_map
[i
].phys
= cs_phys
[i
];
249 ipaq_map
[i
].virt
= ioremap(cs_phys
[i
], 0x04000000);
250 if (machine_is_h3100 () || machine_is_h1900())
251 ipaq_map
[i
].bankwidth
= 2;
253 if (machine_is_h3600()) {
254 /* No asset partition here */
255 h3xxx_partitions
[1].size
+= 0x40000;
260 #ifdef CONFIG_ARCH_H5400
261 if (machine_is_h5400()) {
262 ipaq_map
[0].size
= 0x02000000;
263 ipaq_map
[1].size
= 0x02000000;
264 ipaq_map
[1].phys
= 0x02000000;
265 ipaq_map
[1].virt
= ipaq_map
[0].virt
+ 0x02000000;
268 #ifdef CONFIG_ARCH_H1900
269 if (machine_is_h1900()) {
270 ipaq_map
[0].size
= 0x00400000;
271 ipaq_map
[1].size
= 0x02000000;
272 ipaq_map
[1].phys
= 0x00080000;
273 ipaq_map
[1].virt
= ipaq_map
[0].virt
+ 0x00080000;
277 #ifdef CONFIG_SA1100_JORNADA56X
278 if (machine_is_jornada56x()) {
279 parts
= jornada_partitions
;
280 nb_parts
= ARRAY_SIZE(jornada_partitions
);
281 ipaq_map
[0].size
= jornada_max_flash_size
;
282 ipaq_map
[0].set_vpp
= jornada56x_set_vpp
;
283 ipaq_map
[0].virt
= (__u32
)ioremap(0x0, 0x04000000);
286 #ifdef CONFIG_SA1100_JORNADA720
287 if (machine_is_jornada720()) {
288 parts
= jornada_partitions
;
289 nb_parts
= ARRAY_SIZE(jornada_partitions
);
290 ipaq_map
[0].size
= jornada_max_flash_size
;
291 ipaq_map
[0].set_vpp
= jornada720_set_vpp
;
296 if (machine_is_ipaq()) { /* for iPAQs only */
297 for(i
=0; i
<MAX_IPAQ_CS
; i
++) {
298 printk(KERN_NOTICE
"iPAQ flash: probing %d-bit flash bus, window=%lx with CFI.\n", ipaq_map
[i
].bankwidth
*8, ipaq_map
[i
].virt
);
299 my_sub_mtd
[i
] = do_map_probe("cfi_probe", &ipaq_map
[i
]);
300 if (!my_sub_mtd
[i
]) {
301 printk(KERN_NOTICE
"iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map
[i
].bankwidth
*8, ipaq_map
[i
].virt
);
302 my_sub_mtd
[i
] = do_map_probe("jedec_probe", &ipaq_map
[i
]);
304 if (!my_sub_mtd
[i
]) {
305 printk(KERN_NOTICE
"iPAQ flash: failed to find flash.\n");
311 printk(KERN_NOTICE
"iPAQ flash: found %d bytes\n", my_sub_mtd
[i
]->size
);
313 /* do we really need this debugging? --joshua 20030703 */
314 // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]);
315 my_sub_mtd
[i
]->owner
= THIS_MODULE
;
316 tot_flashsize
+= my_sub_mtd
[i
]->size
;
318 #ifdef CONFIG_MTD_CONCAT
319 /* fix the asset location */
321 h3xxx_partitions
[1].size
= tot_flashsize
- 0x40000 - 0x80000 /* extra big boot block */;
323 h3xxx_partitions
[1].size
= tot_flashsize
- 2 * 0x40000;
325 h3xxx_partitions
[2].offset
= tot_flashsize
- 0x40000;
326 /* and concat the devices */
327 mymtd
= mtd_concat_create(&my_sub_mtd
[0], i
,
330 printk("Cannot create iPAQ concat device\n");
334 mymtd
= my_sub_mtd
[0];
337 *In the very near future, command line partition parsing
338 * will use the device name as 'mtd-id' instead of a value
339 * passed to the parse_cmdline_partitions() routine. Since
340 * the bootldr says 'ipaq', make sure it continues to work.
342 mymtd
->name
= "ipaq";
344 if ((machine_is_h3600())) {
346 h3xxx_partitions
[1].size
= my_sub_mtd
[0]->size
- 0x80000;
348 h3xxx_partitions
[1].size
= my_sub_mtd
[0]->size
- 0x40000;
353 h3xxx_partitions
[1].size
= my_sub_mtd
[0]->size
- 0x40000 - 0x80000; /* extra big boot block */
355 h3xxx_partitions
[1].size
= my_sub_mtd
[0]->size
- 2*0x40000;
357 h3xxx_partitions
[2].offset
= my_sub_mtd
[0]->size
- 0x40000;
362 h3xxx_partitions_bank2
[0].size
= my_sub_mtd
[1]->size
- 0x80000;
364 h3xxx_partitions_bank2
[0].size
= my_sub_mtd
[1]->size
- 0x40000;
366 h3xxx_partitions_bank2
[1].offset
= my_sub_mtd
[1]->size
- 0x40000;
372 * Now let's probe for the actual flash. Do it here since
373 * specific machine settings might have been set above.
375 printk(KERN_NOTICE
"IPAQ flash: probing %d-bit flash bus, window=%lx\n", ipaq_map
[0].bankwidth
*8, ipaq_map
[0].virt
);
376 mymtd
= do_map_probe("cfi_probe", &ipaq_map
[0]);
379 mymtd
->owner
= THIS_MODULE
;
384 * Dynamic partition selection stuff (might override the static ones)
387 i
= parse_mtd_partitions(mymtd
, part_probes
, &parsed_parts
, 0);
390 nb_parts
= parsed_nr_parts
= i
;
391 parts
= parsed_parts
;
392 part_type
= "dynamic";
396 printk(KERN_NOTICE
"IPAQ flash: no partition info available, registering whole flash at once\n");
397 add_mtd_device(mymtd
);
398 #ifndef CONFIG_MTD_CONCAT
400 add_mtd_device(my_sub_mtd
[1]);
403 printk(KERN_NOTICE
"Using %s partition definition\n", part_type
);
404 add_mtd_partitions(mymtd
, parts
, nb_parts
);
405 #ifndef CONFIG_MTD_CONCAT
407 add_mtd_partitions(my_sub_mtd
[1], h3xxx_partitions_bank2
, ARRAY_SIZE(h3xxx_partitions_bank2
));
414 static void __exit
ipaq_mtd_cleanup(void)
419 del_mtd_partitions(mymtd
);
420 #ifndef CONFIG_MTD_CONCAT
422 del_mtd_partitions(my_sub_mtd
[1]);
425 #ifdef CONFIG_MTD_CONCAT
426 for(i
=0; i
<MAX_IPAQ_CS
; i
++)
428 for(i
=1; i
<MAX_IPAQ_CS
; i
++)
432 map_destroy(my_sub_mtd
[i
]);
438 static int __init
h1900_special_case(void)
440 /* The iPAQ h1900 is a special case - it has weird ROM. */
441 simple_map_init(&ipaq_map
[0]);
442 ipaq_map
[0].size
= 0x80000;
443 ipaq_map
[0].set_vpp
= h3xxx_set_vpp
;
444 ipaq_map
[0].phys
= 0x0;
445 ipaq_map
[0].virt
= ioremap(0x0, 0x04000000);
446 ipaq_map
[0].bankwidth
= 2;
448 printk(KERN_NOTICE
"iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map
[0].bankwidth
*8, ipaq_map
[0].virt
);
449 mymtd
= do_map_probe("jedec_probe", &ipaq_map
[0]);
452 add_mtd_device(mymtd
);
453 printk(KERN_NOTICE
"iPAQ flash: registered h1910 flash\n");
458 module_init(ipaq_mtd_init
);
459 module_exit(ipaq_mtd_cleanup
);
461 MODULE_AUTHOR("Jamey Hicks");
462 MODULE_DESCRIPTION("IPAQ CFI map driver");
463 MODULE_LICENSE("MIT");