]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mtd/maps/wr_sbc82xx_flash.c
Merge branch 'setns'
[karo-tx-linux.git] / drivers / mtd / maps / wr_sbc82xx_flash.c
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 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
77 static int __init init_sbc82xx_flash(void)
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                         mtd_device_register(sbcmtd[i], sbcmtd_parts[i],
136                                             nr_parts);
137                         continue;
138                 }
139
140                 /* No partitioning detected. Use default */
141                 if (i == 2) {
142                         mtd_device_register(sbcmtd[i], NULL, 0);
143                 } else if (i == bigflash) {
144                         mtd_device_register(sbcmtd[i], bigflash_parts,
145                                             ARRAY_SIZE(bigflash_parts));
146                 } else {
147                         mtd_device_register(sbcmtd[i], smallflash_parts,
148                                             ARRAY_SIZE(smallflash_parts));
149                 }
150         }
151         return 0;
152 }
153
154 static void __exit cleanup_sbc82xx_flash(void)
155 {
156         int i;
157
158         for (i=0; i<3; i++) {
159                 if (!sbcmtd[i])
160                         continue;
161
162                 if (i<2 || sbcmtd_parts[i])
163                         mtd_device_unregister(sbcmtd[i]);
164                 else
165                         mtd_device_unregister(sbcmtd[i]);
166
167                 kfree(sbcmtd_parts[i]);
168                 map_destroy(sbcmtd[i]);
169
170                 iounmap((void *)sbc82xx_flash_map[i].virt);
171                 sbc82xx_flash_map[i].virt = 0;
172         }
173 }
174
175 module_init(init_sbc82xx_flash);
176 module_exit(cleanup_sbc82xx_flash);
177
178
179 MODULE_LICENSE("GPL");
180 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
181 MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");