First Support on Ginger and OMAP TI
[linux-ginger.git] / drivers / mtd / maps / wr_sbc82xx_flash.c
blob933a2b6598b46fe44f1935afe3f55ed49f35f521
1 /*
2 * Map for flash chips on Wind River PowerQUICC II SBC82xx board.
4 * Copyright (C) 2004 Red Hat, Inc.
6 * Author: David Woodhouse <dwmw2@infradead.org>
8 */
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>
18 #include <linux/mtd/partitions.h>
20 #include <asm/immap_cpm2.h>
22 static struct mtd_info *sbcmtd[3];
23 static struct mtd_partition *sbcmtd_parts[3];
25 struct map_info sbc82xx_flash_map[3] = {
26 {.name = "Boot flash"},
27 {.name = "Alternate boot flash"},
28 {.name = "User flash"}
31 static struct mtd_partition smallflash_parts[] = {
33 .name = "space",
34 .size = 0x100000,
35 .offset = 0,
36 }, {
37 .name = "bootloader",
38 .size = MTDPART_SIZ_FULL,
39 .offset = MTDPART_OFS_APPEND,
43 static struct mtd_partition bigflash_parts[] = {
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,
63 static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
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);
77 static int __init init_sbc82xx_flash(void)
79 volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
80 int bigflash;
81 int i;
83 #ifdef CONFIG_SBC8560
84 mc = ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t));
85 #else
86 mc = &cpm2_immr->im_memctl;
87 #endif
89 bigflash = 1;
90 if ((mc->memc_br0 & 0x00001800) == 0x00001800)
91 bigflash = 0;
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);
97 #ifdef CONFIG_SBC8560
98 iounmap((void *) mc);
99 #endif
101 for (i=0; i<3; i++) {
102 int8_t flashcs[3] = { 0, 6, 1 };
103 int nr_parts;
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;
114 printk(" at %08lx)\n", sbc82xx_flash_map[i].phys);
116 sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys, sbc82xx_flash_map[i].size);
118 if (!sbc82xx_flash_map[i].virt) {
119 printk("Failed to ioremap\n");
120 continue;
123 simple_map_init(&sbc82xx_flash_map[i]);
125 sbcmtd[i] = do_map_probe("cfi_probe", &sbc82xx_flash_map[i]);
127 if (!sbcmtd[i])
128 continue;
130 sbcmtd[i]->owner = THIS_MODULE;
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;
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));
148 return 0;
151 static void __exit cleanup_sbc82xx_flash(void)
153 int i;
155 for (i=0; i<3; i++) {
156 if (!sbcmtd[i])
157 continue;
159 if (i<2 || sbcmtd_parts[i])
160 del_mtd_partitions(sbcmtd[i]);
161 else
162 del_mtd_device(sbcmtd[i]);
164 kfree(sbcmtd_parts[i]);
165 map_destroy(sbcmtd[i]);
167 iounmap((void *)sbc82xx_flash_map[i].virt);
168 sbc82xx_flash_map[i].virt = 0;
172 module_init(init_sbc82xx_flash);
173 module_exit(cleanup_sbc82xx_flash);
176 MODULE_LICENSE("GPL");
177 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
178 MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");