iwlwifi: don't include iwl-dev.h from iwl-devtrace.h
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / mtd / maps / pmcmsp-flash.c
CommitLineData
68aa0fa8
MSJ
1/*
2 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
3 * Config with both CFI and JEDEC device support.
4 *
5 * Basically physmap.c with the addition of partitions and
6 * an array of mapping info to accomodate more than one flash type per board.
7 *
8 * Copyright 2005-2007 PMC-Sierra, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/kernel.h>
34#include <linux/mtd/mtd.h>
35#include <linux/mtd/map.h>
36#include <linux/mtd/partitions.h>
37
38#include <asm/io.h>
39
40#include <msp_prom.h>
41#include <msp_regs.h>
42
43
44static struct mtd_info **msp_flash;
45static struct mtd_partition **msp_parts;
46static struct map_info *msp_maps;
47static int fcnt;
48
cb53b3b9 49#define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n", __func__, __LINE__)
68aa0fa8 50
6127cfcd 51static int __init init_msp_flash(void)
68aa0fa8 52{
2c78c443 53 int i, j, ret = -ENOMEM;
68aa0fa8
MSJ
54 int offset, coff;
55 char *env;
56 int pcnt;
57 char flash_name[] = "flash0";
58 char part_name[] = "flash0_0";
59 unsigned addr, size;
60
61 /* If ELB is disabled by "ful-mux" mode, we can't get at flash */
62 if ((*DEV_ID_REG & DEV_ID_SINGLE_PC) &&
63 (*ELB_1PC_EN_REG & SINGLE_PCCARD)) {
64 printk(KERN_NOTICE "Single PC Card mode: no flash access\n");
65 return -ENXIO;
66 }
67
68 /* examine the prom environment for flash devices */
69 for (fcnt = 0; (env = prom_getenv(flash_name)); fcnt++)
70 flash_name[5] = '0' + fcnt + 1;
71
72 if (fcnt < 1)
73 return -ENXIO;
74
75 printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
4fb4caa6
MK
76
77 msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
2c78c443
RK
78 if (!msp_flash)
79 return -ENOMEM;
80
4fb4caa6 81 msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
2c78c443
RK
82 if (!msp_parts)
83 goto free_msp_flash;
84
4fb4caa6 85 msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL);
2c78c443
RK
86 if (!msp_maps)
87 goto free_msp_parts;
68aa0fa8
MSJ
88
89 /* loop over the flash devices, initializing each */
90 for (i = 0; i < fcnt; i++) {
91 /* examine the prom environment for flash partititions */
92 part_name[5] = '0' + i;
93 part_name[7] = '0';
94 for (pcnt = 0; (env = prom_getenv(part_name)); pcnt++)
95 part_name[7] = '0' + pcnt + 1;
96
97 if (pcnt == 0) {
98 printk(KERN_NOTICE "Skipping flash device %d "
99 "(no partitions defined)\n", i);
100 continue;
101 }
102
4fb4caa6
MK
103 msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition),
104 GFP_KERNEL);
2c78c443
RK
105 if (!msp_parts[i])
106 goto cleanup_loop;
68aa0fa8
MSJ
107
108 /* now initialize the devices proper */
109 flash_name[5] = '0' + i;
110 env = prom_getenv(flash_name);
111
2c78c443
RK
112 if (sscanf(env, "%x:%x", &addr, &size) < 2) {
113 ret = -ENXIO;
114 kfree(msp_parts[i]);
115 goto cleanup_loop;
116 }
68aa0fa8
MSJ
117 addr = CPHYSADDR(addr);
118
119 printk(KERN_NOTICE
120 "MSP flash device \"%s\": 0x%08x at 0x%08x\n",
121 flash_name, size, addr);
122 /* This must matchs the actual size of the flash chip */
123 msp_maps[i].size = size;
124 msp_maps[i].phys = addr;
125
126 /*
127 * Platforms have a specific limit of the size of memory
128 * which may be mapped for flash:
129 */
130 if (size > CONFIG_MSP_FLASH_MAP_LIMIT)
131 size = CONFIG_MSP_FLASH_MAP_LIMIT;
2c78c443 132
68aa0fa8 133 msp_maps[i].virt = ioremap(addr, size);
2c78c443
RK
134 if (msp_maps[i].virt == NULL) {
135 ret = -ENXIO;
136 kfree(msp_parts[i]);
137 goto cleanup_loop;
138 }
139
68aa0fa8 140 msp_maps[i].bankwidth = 1;
2c78c443
RK
141 msp_maps[i].name = kmalloc(7, GFP_KERNEL);
142 if (!msp_maps[i].name) {
143 iounmap(msp_maps[i].virt);
144 kfree(msp_parts[i]);
145 goto cleanup_loop;
146 }
68aa0fa8 147
2c78c443 148 msp_maps[i].name = strncpy(msp_maps[i].name, flash_name, 7);
68aa0fa8
MSJ
149
150 for (j = 0; j < pcnt; j++) {
151 part_name[5] = '0' + i;
152 part_name[7] = '0' + j;
153
154 env = prom_getenv(part_name);
155
2c78c443
RK
156 if (sscanf(env, "%x:%x:%n", &offset, &size,
157 &coff) < 2) {
158 ret = -ENXIO;
159 kfree(msp_maps[i].name);
160 iounmap(msp_maps[i].virt);
161 kfree(msp_parts[i]);
162 goto cleanup_loop;
163 }
68aa0fa8
MSJ
164
165 msp_parts[i][j].size = size;
166 msp_parts[i][j].offset = offset;
167 msp_parts[i][j].name = env + coff;
168 }
169
170 /* now probe and add the device */
171 simple_map_init(&msp_maps[i]);
172 msp_flash[i] = do_map_probe("cfi_probe", &msp_maps[i]);
173 if (msp_flash[i]) {
174 msp_flash[i]->owner = THIS_MODULE;
175 add_mtd_partitions(msp_flash[i], msp_parts[i], pcnt);
176 } else {
177 printk(KERN_ERR "map probe failed for flash\n");
2c78c443
RK
178 ret = -ENXIO;
179 kfree(msp_maps[i].name);
180 iounmap(msp_maps[i].virt);
181 kfree(msp_parts[i]);
182 goto cleanup_loop;
68aa0fa8
MSJ
183 }
184 }
185
186 return 0;
2c78c443
RK
187
188cleanup_loop:
189 while (i--) {
190 del_mtd_partitions(msp_flash[i]);
191 map_destroy(msp_flash[i]);
192 kfree(msp_maps[i].name);
193 iounmap(msp_maps[i].virt);
194 kfree(msp_parts[i]);
195 }
196 kfree(msp_maps);
197free_msp_parts:
198 kfree(msp_parts);
199free_msp_flash:
200 kfree(msp_flash);
201 return ret;
68aa0fa8
MSJ
202}
203
204static void __exit cleanup_msp_flash(void)
205{
206 int i;
207
2c78c443 208 for (i = 0; i < fcnt; i++) {
68aa0fa8
MSJ
209 del_mtd_partitions(msp_flash[i]);
210 map_destroy(msp_flash[i]);
211 iounmap((void *)msp_maps[i].virt);
212
213 /* free the memory */
214 kfree(msp_maps[i].name);
215 kfree(msp_parts[i]);
216 }
217
218 kfree(msp_flash);
219 kfree(msp_parts);
220 kfree(msp_maps);
221}
222
223MODULE_AUTHOR("PMC-Sierra, Inc");
224MODULE_DESCRIPTION("MTD map driver for PMC-Sierra MSP boards");
225MODULE_LICENSE("GPL");
226
227module_init(init_msp_flash);
228module_exit(cleanup_msp_flash);