1 /*
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>
18 #include <linux/mtd/partitions.h>
19
20 #include <asm/immap_cpm2.h>
21
22 static struct mtd_info *sbcmtd[3];
23
24 struct map_info sbc82xx_flash_map[3] = {
25 {.name = "Boot flash"},
26 {.name = "Alternate boot flash"},
27 {.name = "User flash"}
28 };
29
30 static struct mtd_partition smallflash_parts[] = {
31 {
32 .name = "space",
33 .size = 0x100000,
34 .offset = 0,
35 }, {
36 .name = "bootloader",
37 .size = MTDPART_SIZ_FULL,
38 .offset = MTDPART_OFS_APPEND,
39 }
40 };
41
42 static struct mtd_partition bigflash_parts[] = {
43 {
44 .name = "bootloader",
45 .size = 0x00100000,
46 .offset = 0,
47 }, {
48 .name = "file system",
49 .size = 0x01f00000,
50 .offset = MTDPART_OFS_APPEND,
51 }, {
52 .name = "boot config",
53 .size = 0x00100000,
54 .offset = MTDPART_OFS_APPEND,
55 }, {
56 .name = "space",
57 .size = 0x01f00000,
58 .offset = MTDPART_OFS_APPEND,
59 }
60 };
61
62 static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
63
64 #define init_sbc82xx_one_flash(map, br, or) \
65 do { \
66 (map).phys = (br & 1) ? (br & 0xffff8000) : 0; \
67 (map).size = (br & 1) ? (~(or & 0xffff8000) + 1) : 0; \
68 switch (br & 0x00001800) { \
69 case 0x00000000: \
70 case 0x00000800: (map).bankwidth = 1; break; \
71 case 0x00001000: (map).bankwidth = 2; break; \
72 case 0x00001800: (map).bankwidth = 4; break; \
73 } \
74 } while (0);
75
init_sbc82xx_flash(void)76 static int __init init_sbc82xx_flash(void)
77 {
78 volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
79 int bigflash;
80 int i;
81
82 #ifdef CONFIG_SBC8560
83 mc = ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t));
84 #else
85 mc = &cpm2_immr->im_memctl;
86 #endif
87
88 bigflash = 1;
89 if ((mc->memc_br0 & 0x00001800) == 0x00001800)
90 bigflash = 0;
91
92 init_sbc82xx_one_flash(sbc82xx_flash_map[0], mc->memc_br0, mc->memc_or0);
93 init_sbc82xx_one_flash(sbc82xx_flash_map[1], mc->memc_br6, mc->memc_or6);
94 init_sbc82xx_one_flash(sbc82xx_flash_map[2], mc->memc_br1, mc->memc_or1);
95
96 #ifdef CONFIG_SBC8560
97 iounmap((void *) mc);
98 #endif
99
100 for (i=0; i<3; i++) {
101 int8_t flashcs[3] = { 0, 6, 1 };
102 int nr_parts;
103 struct mtd_partition *defparts;
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,
117 sbc82xx_flash_map[i].size);
118
119 if (!sbc82xx_flash_map[i].virt) {
120 printk("Failed to ioremap\n");
121 continue;
122 }
123
124 simple_map_init(&sbc82xx_flash_map[i]);
125
126 sbcmtd[i] = do_map_probe("cfi_probe", &sbc82xx_flash_map[i]);
127
128 if (!sbcmtd[i])
129 continue;
130
131 sbcmtd[i]->owner = THIS_MODULE;
132
133 /* No partitioning detected. Use default */
134 if (i == 2) {
135 defparts = NULL;
136 nr_parts = 0;
137 } else if (i == bigflash) {
138 defparts = bigflash_parts;
139 nr_parts = ARRAY_SIZE(bigflash_parts);
140 } else {
141 defparts = smallflash_parts;
142 nr_parts = ARRAY_SIZE(smallflash_parts);
143 }
144
145 mtd_device_parse_register(sbcmtd[i], part_probes, NULL,
146 defparts, nr_parts);
147 }
148 return 0;
149 }
150
cleanup_sbc82xx_flash(void)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 mtd_device_unregister(sbcmtd[i]);
160
161 map_destroy(sbcmtd[i]);
162
163 iounmap((void *)sbc82xx_flash_map[i].virt);
164 sbc82xx_flash_map[i].virt = 0;
165 }
166 }
167
168 module_init(init_sbc82xx_flash);
169 module_exit(cleanup_sbc82xx_flash);
170
171
172 MODULE_LICENSE("GPL");
173 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
174 MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");
175