Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Map for flash chips on Wind River PowerQUICC II SBC82xx board. |
| 3 | * |
| 4 | * Copyright (C) 2004 Red Hat, Inc. |
| 5 | * |
| 6 | * Author: David Woodhouse <dwmw2@infradead.org> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <linux/mtd/mtd.h> |
| 17 | #include <linux/mtd/map.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/mtd/partitions.h> |
| 19 | |
| 20 | #include <asm/immap_cpm2.h> |
| 21 | |
| 22 | static struct mtd_info *sbcmtd[3]; |
| 23 | static struct mtd_partition *sbcmtd_parts[3]; |
| 24 | |
| 25 | struct map_info sbc82xx_flash_map[3] = { |
| 26 | {.name = "Boot flash"}, |
| 27 | {.name = "Alternate boot flash"}, |
| 28 | {.name = "User flash"} |
| 29 | }; |
| 30 | |
| 31 | static struct mtd_partition smallflash_parts[] = { |
| 32 | { |
| 33 | .name = "space", |
| 34 | .size = 0x100000, |
| 35 | .offset = 0, |
| 36 | }, { |
| 37 | .name = "bootloader", |
| 38 | .size = MTDPART_SIZ_FULL, |
| 39 | .offset = MTDPART_OFS_APPEND, |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | static struct mtd_partition bigflash_parts[] = { |
| 44 | { |
| 45 | .name = "bootloader", |
| 46 | .size = 0x00100000, |
| 47 | .offset = 0, |
| 48 | }, { |
| 49 | .name = "file system", |
| 50 | .size = 0x01f00000, |
| 51 | .offset = MTDPART_OFS_APPEND, |
| 52 | }, { |
| 53 | .name = "boot config", |
| 54 | .size = 0x00100000, |
| 55 | .offset = MTDPART_OFS_APPEND, |
| 56 | }, { |
| 57 | .name = "space", |
| 58 | .size = 0x01f00000, |
| 59 | .offset = MTDPART_OFS_APPEND, |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL}; |
| 64 | |
| 65 | #define init_sbc82xx_one_flash(map, br, or) \ |
| 66 | do { \ |
| 67 | (map).phys = (br & 1) ? (br & 0xffff8000) : 0; \ |
| 68 | (map).size = (br & 1) ? (~(or & 0xffff8000) + 1) : 0; \ |
| 69 | switch (br & 0x00001800) { \ |
| 70 | case 0x00000000: \ |
| 71 | case 0x00000800: (map).bankwidth = 1; break; \ |
| 72 | case 0x00001000: (map).bankwidth = 2; break; \ |
| 73 | case 0x00001800: (map).bankwidth = 4; break; \ |
| 74 | } \ |
| 75 | } while (0); |
| 76 | |
Dmitri Vorobiev | 8d24032 | 2008-11-25 02:55:11 +0200 | [diff] [blame] | 77 | static int __init init_sbc82xx_flash(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl; |
| 80 | int bigflash; |
| 81 | int i; |
| 82 | |
| 83 | #ifdef CONFIG_SBC8560 |
| 84 | mc = ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t)); |
| 85 | #else |
| 86 | mc = &cpm2_immr->im_memctl; |
| 87 | #endif |
| 88 | |
| 89 | bigflash = 1; |
| 90 | if ((mc->memc_br0 & 0x00001800) == 0x00001800) |
| 91 | bigflash = 0; |
| 92 | |
| 93 | init_sbc82xx_one_flash(sbc82xx_flash_map[0], mc->memc_br0, mc->memc_or0); |
| 94 | init_sbc82xx_one_flash(sbc82xx_flash_map[1], mc->memc_br6, mc->memc_or6); |
| 95 | init_sbc82xx_one_flash(sbc82xx_flash_map[2], mc->memc_br1, mc->memc_or1); |
| 96 | |
| 97 | #ifdef CONFIG_SBC8560 |
| 98 | iounmap((void *) mc); |
| 99 | #endif |
| 100 | |
| 101 | for (i=0; i<3; i++) { |
| 102 | int8_t flashcs[3] = { 0, 6, 1 }; |
| 103 | int nr_parts; |
| 104 | |
| 105 | printk(KERN_NOTICE "PowerQUICC II %s (%ld MiB on CS%d", |
| 106 | sbc82xx_flash_map[i].name, |
| 107 | (sbc82xx_flash_map[i].size >> 20), |
| 108 | flashcs[i]); |
| 109 | if (!sbc82xx_flash_map[i].phys) { |
| 110 | /* We know it can't be at zero. */ |
| 111 | printk("): disabled by bootloader.\n"); |
| 112 | continue; |
| 113 | } |
| 114 | printk(" at %08lx)\n", sbc82xx_flash_map[i].phys); |
| 115 | |
| 116 | sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys, sbc82xx_flash_map[i].size); |
| 117 | |
| 118 | if (!sbc82xx_flash_map[i].virt) { |
| 119 | printk("Failed to ioremap\n"); |
| 120 | continue; |
| 121 | } |
| 122 | |
| 123 | simple_map_init(&sbc82xx_flash_map[i]); |
| 124 | |
| 125 | sbcmtd[i] = do_map_probe("cfi_probe", &sbc82xx_flash_map[i]); |
| 126 | |
| 127 | if (!sbcmtd[i]) |
| 128 | continue; |
| 129 | |
| 130 | sbcmtd[i]->owner = THIS_MODULE; |
| 131 | |
| 132 | nr_parts = parse_mtd_partitions(sbcmtd[i], part_probes, |
| 133 | &sbcmtd_parts[i], 0); |
| 134 | if (nr_parts > 0) { |
| 135 | add_mtd_partitions (sbcmtd[i], sbcmtd_parts[i], nr_parts); |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | /* No partitioning detected. Use default */ |
| 140 | if (i == 2) { |
| 141 | add_mtd_device(sbcmtd[i]); |
| 142 | } else if (i == bigflash) { |
| 143 | add_mtd_partitions (sbcmtd[i], bigflash_parts, ARRAY_SIZE(bigflash_parts)); |
| 144 | } else { |
| 145 | add_mtd_partitions (sbcmtd[i], smallflash_parts, ARRAY_SIZE(smallflash_parts)); |
| 146 | } |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static void __exit cleanup_sbc82xx_flash(void) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | for (i=0; i<3; i++) { |
| 156 | if (!sbcmtd[i]) |
| 157 | continue; |
| 158 | |
| 159 | if (i<2 || sbcmtd_parts[i]) |
| 160 | del_mtd_partitions(sbcmtd[i]); |
| 161 | else |
| 162 | del_mtd_device(sbcmtd[i]); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | kfree(sbcmtd_parts[i]); |
| 165 | map_destroy(sbcmtd[i]); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | iounmap((void *)sbc82xx_flash_map[i].virt); |
| 168 | sbc82xx_flash_map[i].virt = 0; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | module_init(init_sbc82xx_flash); |
| 173 | module_exit(cleanup_sbc82xx_flash); |
| 174 | |
| 175 | |
| 176 | MODULE_LICENSE("GPL"); |
| 177 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |
| 178 | MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II"); |