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
 
   9 #include <linux/module.h>
 
  10 #include <linux/types.h>
 
  11 #include <linux/kernel.h>
 
  12 #include <linux/spinlock.h>
 
  13 #include <linux/init.h>
 
  14 #include <linux/slab.h>
 
  16 #include <asm/mach-types.h>
 
  17 #include <asm/system.h>
 
  18 #include <asm/errno.h>
 
  20 #include <linux/mtd/mtd.h>
 
  21 #include <linux/mtd/map.h>
 
  22 #include <linux/mtd/partitions.h>
 
  23 #ifdef CONFIG_MTD_CONCAT
 
  24 #include <linux/mtd/concat.h>
 
  27 #include <mach/hardware.h>
 
  28 #include <mach/h3600.h>
 
  32 #ifndef CONFIG_IPAQ_HANDHELD
 
  33 #error This is for iPAQ Handhelds only
 
  35 #ifdef CONFIG_SA1100_JORNADA56X
 
  37 static void jornada56x_set_vpp(struct map_info *map, int vpp)
 
  48 #ifdef CONFIG_SA1100_JORNADA720
 
  50 static void jornada720_set_vpp(struct map_info *map, int vpp)
 
  61 #define MAX_IPAQ_CS 2           /* Number of CS we are going to test */
 
  63 #define IPAQ_MAP_INIT(X) \
 
  65                 name:           "IPAQ flash " X, \
 
  69 static struct map_info ipaq_map[MAX_IPAQ_CS] = {
 
  70         IPAQ_MAP_INIT("bank 1"),
 
  71         IPAQ_MAP_INIT("bank 2")
 
  74 static struct mtd_info *my_sub_mtd[MAX_IPAQ_CS] = {
 
  80  * Here are partition information for all known IPAQ-based devices.
 
  81  * See include/linux/mtd/partitions.h for definition of the mtd_partition
 
  84  * The *_max_flash_size is the maximum possible mapped flash size which
 
  85  * is not necessarily the actual flash size.  It must be no more than
 
  86  * the value specified in the "struct map_desc *_io_desc" mapping
 
  87  * definition for the corresponding machine.
 
  89  * Please keep these in alphabetical order, and formatted as per existing
 
  93 #ifdef CONFIG_IPAQ_HANDHELD
 
  94 static unsigned long h3xxx_max_flash_size = 0x04000000;
 
  95 static struct mtd_partition h3xxx_partitions[] = {
 
  97                 name:           "H3XXX boot firmware",
 
 105                 mask_flags:     MTD_WRITEABLE,  /* force read-only */
 
 109                 name:           "H3XXX root jffs2",
 
 111                 size:           0x2000000 - 2*0x40000, /* Warning, this is fixed later */
 
 114                 size:           0x2000000 - 0x40000 - 0x80000, /* Warning, this is fixed later */
 
 121                 offset:         0x2000000 - 0x40000, /* Warning, this is fixed later */
 
 122                 mask_flags:     MTD_WRITEABLE,  /* force read-only */
 
 126 #ifndef CONFIG_MTD_CONCAT
 
 127 static struct mtd_partition h3xxx_partitions_bank2[] = {
 
 128         /* this is used only on 2 CS machines when concat is not present */
 
 130                 name:           "second H3XXX root jffs2",
 
 131                 size:           0x1000000 - 0x40000, /* Warning, this is fixed later */
 
 135                 name:           "second asset",
 
 137                 offset:         0x1000000 - 0x40000, /* Warning, this is fixed later */
 
 138                 mask_flags:     MTD_WRITEABLE,  /* force read-only */
 
 143 static DEFINE_SPINLOCK(ipaq_vpp_lock);
 
 145 static void h3xxx_set_vpp(struct map_info *map, int vpp)
 
 149         spin_lock(&ipaq_vpp_lock);
 
 155                 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 1);
 
 157                 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 0);
 
 158         spin_unlock(&ipaq_vpp_lock);
 
 163 #if defined(CONFIG_SA1100_JORNADA56X) || defined(CONFIG_SA1100_JORNADA720)
 
 164 static unsigned long jornada_max_flash_size = 0x02000000;
 
 165 static struct mtd_partition jornada_partitions[] = {
 
 167                 name:           "Jornada boot firmware",
 
 170                 mask_flags:     MTD_WRITEABLE,  /* force read-only */
 
 172                 name:           "Jornada root jffs2",
 
 173                 size:           MTDPART_SIZ_FULL,
 
 180 static struct mtd_partition *parsed_parts;
 
 181 static struct mtd_info *mymtd;
 
 183 static unsigned long cs_phys[] = {
 
 184 #ifdef CONFIG_ARCH_SA1100
 
 201 static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
 
 203 static int __init h1900_special_case(void);
 
 205 static int __init ipaq_mtd_init(void)
 
 207         struct mtd_partition *parts = NULL;
 
 209         int parsed_nr_parts = 0;
 
 210         const char *part_type;
 
 211         int i; /* used when we have >1 flash chips */
 
 212         unsigned long tot_flashsize = 0; /* used when we have >1 flash chips */
 
 214         /* Default flash bankwidth */
 
 215         // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
 
 217         if (machine_is_h1900())
 
 219                 /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */
 
 220                 return h1900_special_case();
 
 223         if (machine_is_h3100() || machine_is_h1900())
 
 224                 for(i=0; i<MAX_IPAQ_CS; i++)
 
 225                         ipaq_map[i].bankwidth = 2;
 
 227                 for(i=0; i<MAX_IPAQ_CS; i++)
 
 228                         ipaq_map[i].bankwidth = 4;
 
 231          * Static partition definition selection
 
 233         part_type = "static";
 
 235         simple_map_init(&ipaq_map[0]);
 
 236         simple_map_init(&ipaq_map[1]);
 
 238 #ifdef CONFIG_IPAQ_HANDHELD
 
 239         if (machine_is_ipaq()) {
 
 240                 parts = h3xxx_partitions;
 
 241                 nb_parts = ARRAY_SIZE(h3xxx_partitions);
 
 242                 for(i=0; i<MAX_IPAQ_CS; i++) {
 
 243                         ipaq_map[i].size = h3xxx_max_flash_size;
 
 244                         ipaq_map[i].set_vpp = h3xxx_set_vpp;
 
 245                         ipaq_map[i].phys = cs_phys[i];
 
 246                         ipaq_map[i].virt = ioremap(cs_phys[i], 0x04000000);
 
 247                         if (machine_is_h3100 () || machine_is_h1900())
 
 248                                 ipaq_map[i].bankwidth = 2;
 
 250                 if (machine_is_h3600()) {
 
 251                         /* No asset partition here */
 
 252                         h3xxx_partitions[1].size += 0x40000;
 
 257 #ifdef CONFIG_ARCH_H5400
 
 258         if (machine_is_h5400()) {
 
 259                 ipaq_map[0].size = 0x02000000;
 
 260                 ipaq_map[1].size = 0x02000000;
 
 261                 ipaq_map[1].phys = 0x02000000;
 
 262                 ipaq_map[1].virt = ipaq_map[0].virt + 0x02000000;
 
 265 #ifdef CONFIG_ARCH_H1900
 
 266         if (machine_is_h1900()) {
 
 267                 ipaq_map[0].size = 0x00400000;
 
 268                 ipaq_map[1].size = 0x02000000;
 
 269                 ipaq_map[1].phys = 0x00080000;
 
 270                 ipaq_map[1].virt = ipaq_map[0].virt + 0x00080000;
 
 274 #ifdef CONFIG_SA1100_JORNADA56X
 
 275         if (machine_is_jornada56x()) {
 
 276                 parts = jornada_partitions;
 
 277                 nb_parts = ARRAY_SIZE(jornada_partitions);
 
 278                 ipaq_map[0].size = jornada_max_flash_size;
 
 279                 ipaq_map[0].set_vpp = jornada56x_set_vpp;
 
 280                 ipaq_map[0].virt = (__u32)ioremap(0x0, 0x04000000);
 
 283 #ifdef CONFIG_SA1100_JORNADA720
 
 284         if (machine_is_jornada720()) {
 
 285                 parts = jornada_partitions;
 
 286                 nb_parts = ARRAY_SIZE(jornada_partitions);
 
 287                 ipaq_map[0].size = jornada_max_flash_size;
 
 288                 ipaq_map[0].set_vpp = jornada720_set_vpp;
 
 293         if (machine_is_ipaq()) { /* for iPAQs only */
 
 294                 for(i=0; i<MAX_IPAQ_CS; i++) {
 
 295                         printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with CFI.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
 
 296                         my_sub_mtd[i] = do_map_probe("cfi_probe", &ipaq_map[i]);
 
 297                         if (!my_sub_mtd[i]) {
 
 298                                 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
 
 299                                 my_sub_mtd[i] = do_map_probe("jedec_probe", &ipaq_map[i]);
 
 301                         if (!my_sub_mtd[i]) {
 
 302                                 printk(KERN_NOTICE "iPAQ flash: failed to find flash.\n");
 
 308                                 printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size);
 
 310                         /* do we really need this debugging? --joshua 20030703 */
 
 311                         // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]);
 
 312                         my_sub_mtd[i]->owner = THIS_MODULE;
 
 313                         tot_flashsize += my_sub_mtd[i]->size;
 
 315 #ifdef CONFIG_MTD_CONCAT
 
 316                 /* fix the asset location */
 
 318                 h3xxx_partitions[1].size = tot_flashsize - 0x40000 - 0x80000 /* extra big boot block */;
 
 320                 h3xxx_partitions[1].size = tot_flashsize - 2 * 0x40000;
 
 322                 h3xxx_partitions[2].offset = tot_flashsize - 0x40000;
 
 323                 /* and concat the devices */
 
 324                 mymtd = mtd_concat_create(&my_sub_mtd[0], i,
 
 327                         printk("Cannot create iPAQ concat device\n");
 
 331                 mymtd = my_sub_mtd[0];
 
 334                  *In the very near future, command line partition parsing
 
 335                  * will use the device name as 'mtd-id' instead of a value
 
 336                  * passed to the parse_cmdline_partitions() routine. Since
 
 337                  * the bootldr says 'ipaq', make sure it continues to work.
 
 339                 mymtd->name = "ipaq";
 
 341                 if ((machine_is_h3600())) {
 
 343                         h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x80000;
 
 345                         h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000;
 
 350                         h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000 - 0x80000; /* extra big boot block */
 
 352                         h3xxx_partitions[1].size = my_sub_mtd[0]->size - 2*0x40000;
 
 354                         h3xxx_partitions[2].offset = my_sub_mtd[0]->size - 0x40000;
 
 359                         h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x80000;
 
 361                         h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x40000;
 
 363                         h3xxx_partitions_bank2[1].offset = my_sub_mtd[1]->size - 0x40000;
 
 369                  * Now let's probe for the actual flash.  Do it here since
 
 370                  * specific machine settings might have been set above.
 
 372                 printk(KERN_NOTICE "IPAQ flash: probing %d-bit flash bus, window=%lx\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
 
 373                 mymtd = do_map_probe("cfi_probe", &ipaq_map[0]);
 
 376                 mymtd->owner = THIS_MODULE;
 
 381          * Dynamic partition selection stuff (might override the static ones)
 
 384          i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0);
 
 387                  nb_parts = parsed_nr_parts = i;
 
 388                  parts = parsed_parts;
 
 389                  part_type = "dynamic";
 
 393                  printk(KERN_NOTICE "IPAQ flash: no partition info available, registering whole flash at once\n");
 
 394                  add_mtd_device(mymtd);
 
 395 #ifndef CONFIG_MTD_CONCAT
 
 397                          add_mtd_device(my_sub_mtd[1]);
 
 400                  printk(KERN_NOTICE "Using %s partition definition\n", part_type);
 
 401                  add_mtd_partitions(mymtd, parts, nb_parts);
 
 402 #ifndef CONFIG_MTD_CONCAT
 
 404                          add_mtd_partitions(my_sub_mtd[1], h3xxx_partitions_bank2, ARRAY_SIZE(h3xxx_partitions_bank2));
 
 411 static void __exit ipaq_mtd_cleanup(void)
 
 416                 del_mtd_partitions(mymtd);
 
 417 #ifndef CONFIG_MTD_CONCAT
 
 419                         del_mtd_partitions(my_sub_mtd[1]);
 
 422 #ifdef CONFIG_MTD_CONCAT
 
 423                 for(i=0; i<MAX_IPAQ_CS; i++)
 
 425                         for(i=1; i<MAX_IPAQ_CS; i++)
 
 429                                         map_destroy(my_sub_mtd[i]);
 
 435 static int __init h1900_special_case(void)
 
 437         /* The iPAQ h1900 is a special case - it has weird ROM. */
 
 438         simple_map_init(&ipaq_map[0]);
 
 439         ipaq_map[0].size = 0x80000;
 
 440         ipaq_map[0].set_vpp = h3xxx_set_vpp;
 
 441         ipaq_map[0].phys = 0x0;
 
 442         ipaq_map[0].virt = ioremap(0x0, 0x04000000);
 
 443         ipaq_map[0].bankwidth = 2;
 
 445         printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
 
 446         mymtd = do_map_probe("jedec_probe", &ipaq_map[0]);
 
 449         add_mtd_device(mymtd);
 
 450         printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n");
 
 455 module_init(ipaq_mtd_init);
 
 456 module_exit(ipaq_mtd_cleanup);
 
 458 MODULE_AUTHOR("Jamey Hicks");
 
 459 MODULE_DESCRIPTION("IPAQ CFI map driver");
 
 460 MODULE_LICENSE("MIT");