This source file includes following definitions.
- init_msp_flash
- cleanup_msp_flash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <linux/slab.h>
32 #include <linux/module.h>
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/mtd/mtd.h>
36 #include <linux/mtd/map.h>
37 #include <linux/mtd/partitions.h>
38
39 #include <asm/io.h>
40
41 #include <msp_prom.h>
42 #include <msp_regs.h>
43
44
45 static struct mtd_info **msp_flash;
46 static struct mtd_partition **msp_parts;
47 static struct map_info *msp_maps;
48 static int fcnt;
49
50 #define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n", __func__, __LINE__)
51
52 static int __init init_msp_flash(void)
53 {
54 int i, j, ret = -ENOMEM;
55 int offset, coff;
56 char *env;
57 int pcnt;
58 char flash_name[] = "flash0";
59 char part_name[] = "flash0_0";
60 unsigned addr, size;
61
62
63 if ((*DEV_ID_REG & DEV_ID_SINGLE_PC) &&
64 (*ELB_1PC_EN_REG & SINGLE_PCCARD)) {
65 printk(KERN_NOTICE "Single PC Card mode: no flash access\n");
66 return -ENXIO;
67 }
68
69
70 for (fcnt = 0; (env = prom_getenv(flash_name)); fcnt++)
71 flash_name[5] = '0' + fcnt + 1;
72
73 if (fcnt < 1)
74 return -ENXIO;
75
76 printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
77
78 msp_flash = kcalloc(fcnt, sizeof(*msp_flash), GFP_KERNEL);
79 if (!msp_flash)
80 return -ENOMEM;
81
82 msp_parts = kcalloc(fcnt, sizeof(*msp_parts), GFP_KERNEL);
83 if (!msp_parts)
84 goto free_msp_flash;
85
86 msp_maps = kcalloc(fcnt, sizeof(*msp_maps), GFP_KERNEL);
87 if (!msp_maps)
88 goto free_msp_parts;
89
90
91 for (i = 0; i < fcnt; i++) {
92
93 part_name[5] = '0' + i;
94 part_name[7] = '0';
95 for (pcnt = 0; (env = prom_getenv(part_name)); pcnt++)
96 part_name[7] = '0' + pcnt + 1;
97
98 if (pcnt == 0) {
99 printk(KERN_NOTICE "Skipping flash device %d "
100 "(no partitions defined)\n", i);
101 continue;
102 }
103
104 msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition),
105 GFP_KERNEL);
106 if (!msp_parts[i])
107 goto cleanup_loop;
108
109
110 flash_name[5] = '0' + i;
111 env = prom_getenv(flash_name);
112
113 if (sscanf(env, "%x:%x", &addr, &size) < 2) {
114 ret = -ENXIO;
115 kfree(msp_parts[i]);
116 goto cleanup_loop;
117 }
118 addr = CPHYSADDR(addr);
119
120 printk(KERN_NOTICE
121 "MSP flash device \"%s\": 0x%08x at 0x%08x\n",
122 flash_name, size, addr);
123
124 msp_maps[i].size = size;
125 msp_maps[i].phys = addr;
126
127
128
129
130
131 if (size > CONFIG_MSP_FLASH_MAP_LIMIT)
132 size = CONFIG_MSP_FLASH_MAP_LIMIT;
133
134 msp_maps[i].virt = ioremap(addr, size);
135 if (msp_maps[i].virt == NULL) {
136 ret = -ENXIO;
137 kfree(msp_parts[i]);
138 goto cleanup_loop;
139 }
140
141 msp_maps[i].bankwidth = 1;
142 msp_maps[i].name = kstrndup(flash_name, 7, GFP_KERNEL);
143 if (!msp_maps[i].name) {
144 iounmap(msp_maps[i].virt);
145 kfree(msp_parts[i]);
146 goto cleanup_loop;
147 }
148
149 for (j = 0; j < pcnt; j++) {
150 part_name[5] = '0' + i;
151 part_name[7] = '0' + j;
152
153 env = prom_getenv(part_name);
154
155 if (sscanf(env, "%x:%x:%n", &offset, &size,
156 &coff) < 2) {
157 ret = -ENXIO;
158 kfree(msp_maps[i].name);
159 iounmap(msp_maps[i].virt);
160 kfree(msp_parts[i]);
161 goto cleanup_loop;
162 }
163
164 msp_parts[i][j].size = size;
165 msp_parts[i][j].offset = offset;
166 msp_parts[i][j].name = env + coff;
167 }
168
169
170 simple_map_init(&msp_maps[i]);
171 msp_flash[i] = do_map_probe("cfi_probe", &msp_maps[i]);
172 if (msp_flash[i]) {
173 msp_flash[i]->owner = THIS_MODULE;
174 mtd_device_register(msp_flash[i], msp_parts[i], pcnt);
175 } else {
176 printk(KERN_ERR "map probe failed for flash\n");
177 ret = -ENXIO;
178 kfree(msp_maps[i].name);
179 iounmap(msp_maps[i].virt);
180 kfree(msp_parts[i]);
181 goto cleanup_loop;
182 }
183 }
184
185 return 0;
186
187 cleanup_loop:
188 while (i--) {
189 mtd_device_unregister(msp_flash[i]);
190 map_destroy(msp_flash[i]);
191 kfree(msp_maps[i].name);
192 iounmap(msp_maps[i].virt);
193 kfree(msp_parts[i]);
194 }
195 kfree(msp_maps);
196 free_msp_parts:
197 kfree(msp_parts);
198 free_msp_flash:
199 kfree(msp_flash);
200 return ret;
201 }
202
203 static void __exit cleanup_msp_flash(void)
204 {
205 int i;
206
207 for (i = 0; i < fcnt; i++) {
208 mtd_device_unregister(msp_flash[i]);
209 map_destroy(msp_flash[i]);
210 iounmap((void *)msp_maps[i].virt);
211
212
213 kfree(msp_maps[i].name);
214 kfree(msp_parts[i]);
215 }
216
217 kfree(msp_flash);
218 kfree(msp_parts);
219 kfree(msp_maps);
220 }
221
222 MODULE_AUTHOR("PMC-Sierra, Inc");
223 MODULE_DESCRIPTION("MTD map driver for PMC-Sierra MSP boards");
224 MODULE_LICENSE("GPL");
225
226 module_init(init_msp_flash);
227 module_exit(cleanup_msp_flash);