aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/maps
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/maps')
-rw-r--r--drivers/mtd/maps/Kconfig9
-rw-r--r--drivers/mtd/maps/Makefile1
-rw-r--r--drivers/mtd/maps/bcm963xx-flash.c271
-rw-r--r--drivers/mtd/maps/gpio-addr-flash.c10
-rw-r--r--drivers/mtd/maps/pcmciamtd.c4
-rw-r--r--drivers/mtd/maps/physmap_of.c20
6 files changed, 299 insertions, 16 deletions
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 962212628f6e..a0dd7bba9481 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -251,6 +251,15 @@ config MTD_NETtel
251 help 251 help
252 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 252 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
253 253
254config MTD_BCM963XX
255 tristate "Map driver for Broadcom BCM963xx boards"
256 depends on BCM63XX
257 select MTD_MAP_BANK_WIDTH_2
258 select MTD_CFI_I1
259 help
260 Support for parsing CFE image tag and creating MTD partitions on
261 Broadcom BCM63xx boards.
262
254config MTD_DILNETPC 263config MTD_DILNETPC
255 tristate "CFI Flash device mapped on DIL/Net PC" 264 tristate "CFI Flash device mapped on DIL/Net PC"
256 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN 265 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index f216bb573713..c7869c7a6b18 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -58,3 +58,4 @@ obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o
58obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o 58obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o
59obj-$(CONFIG_MTD_VMU) += vmu-flash.o 59obj-$(CONFIG_MTD_VMU) += vmu-flash.o
60obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o 60obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o
61obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c
new file mode 100644
index 000000000000..d175c120ee84
--- /dev/null
+++ b/drivers/mtd/maps/bcm963xx-flash.c
@@ -0,0 +1,271 @@
1/*
2 * Copyright © 2006-2008 Florian Fainelli <florian@openwrt.org>
3 * Mike Albon <malbon@openwrt.org>
4 * Copyright © 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/slab.h>
24#include <linux/mtd/map.h>
25#include <linux/mtd/mtd.h>
26#include <linux/mtd/partitions.h>
27#include <linux/vmalloc.h>
28#include <linux/platform_device.h>
29#include <linux/io.h>
30
31#include <asm/mach-bcm63xx/bcm963xx_tag.h>
32
33#define BCM63XX_BUSWIDTH 2 /* Buswidth */
34#define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
35
36#define PFX KBUILD_MODNAME ": "
37
38static struct mtd_partition *parsed_parts;
39
40static struct mtd_info *bcm963xx_mtd_info;
41
42static struct map_info bcm963xx_map = {
43 .name = "bcm963xx",
44 .bankwidth = BCM63XX_BUSWIDTH,
45};
46
47static int parse_cfe_partitions(struct mtd_info *master,
48 struct mtd_partition **pparts)
49{
50 /* CFE, NVRAM and global Linux are always present */
51 int nrparts = 3, curpart = 0;
52 struct bcm_tag *buf;
53 struct mtd_partition *parts;
54 int ret;
55 size_t retlen;
56 unsigned int rootfsaddr, kerneladdr, spareaddr;
57 unsigned int rootfslen, kernellen, sparelen, totallen;
58 int namelen = 0;
59 int i;
60 char *boardid;
61 char *tagversion;
62
63 /* Allocate memory for buffer */
64 buf = vmalloc(sizeof(struct bcm_tag));
65 if (!buf)
66 return -ENOMEM;
67
68 /* Get the tag */
69 ret = master->read(master, master->erasesize, sizeof(struct bcm_tag),
70 &retlen, (void *)buf);
71 if (retlen != sizeof(struct bcm_tag)) {
72 vfree(buf);
73 return -EIO;
74 }
75
76 sscanf(buf->kernel_address, "%u", &kerneladdr);
77 sscanf(buf->kernel_length, "%u", &kernellen);
78 sscanf(buf->total_length, "%u", &totallen);
79 tagversion = &(buf->tag_version[0]);
80 boardid = &(buf->board_id[0]);
81
82 printk(KERN_INFO PFX "CFE boot tag found with version %s "
83 "and board type %s\n", tagversion, boardid);
84
85 kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
86 rootfsaddr = kerneladdr + kernellen;
87 spareaddr = roundup(totallen, master->erasesize) + master->erasesize;
88 sparelen = master->size - spareaddr - master->erasesize;
89 rootfslen = spareaddr - rootfsaddr;
90
91 /* Determine number of partitions */
92 namelen = 8;
93 if (rootfslen > 0) {
94 nrparts++;
95 namelen += 6;
96 };
97 if (kernellen > 0) {
98 nrparts++;
99 namelen += 6;
100 };
101
102 /* Ask kernel for more memory */
103 parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL);
104 if (!parts) {
105 vfree(buf);
106 return -ENOMEM;
107 };
108
109 /* Start building partition list */
110 parts[curpart].name = "CFE";
111 parts[curpart].offset = 0;
112 parts[curpart].size = master->erasesize;
113 curpart++;
114
115 if (kernellen > 0) {
116 parts[curpart].name = "kernel";
117 parts[curpart].offset = kerneladdr;
118 parts[curpart].size = kernellen;
119 curpart++;
120 };
121
122 if (rootfslen > 0) {
123 parts[curpart].name = "rootfs";
124 parts[curpart].offset = rootfsaddr;
125 parts[curpart].size = rootfslen;
126 if (sparelen > 0)
127 parts[curpart].size += sparelen;
128 curpart++;
129 };
130
131 parts[curpart].name = "nvram";
132 parts[curpart].offset = master->size - master->erasesize;
133 parts[curpart].size = master->erasesize;
134
135 /* Global partition "linux" to make easy firmware upgrade */
136 curpart++;
137 parts[curpart].name = "linux";
138 parts[curpart].offset = parts[0].size;
139 parts[curpart].size = master->size - parts[0].size - parts[3].size;
140
141 for (i = 0; i < nrparts; i++)
142 printk(KERN_INFO PFX "Partition %d is %s offset %lx and "
143 "length %lx\n", i, parts[i].name,
144 (long unsigned int)(parts[i].offset),
145 (long unsigned int)(parts[i].size));
146
147 printk(KERN_INFO PFX "Spare partition is %x offset and length %x\n",
148 spareaddr, sparelen);
149 *pparts = parts;
150 vfree(buf);
151
152 return nrparts;
153};
154
155static int bcm963xx_detect_cfe(struct mtd_info *master)
156{
157 int idoffset = 0x4e0;
158 static char idstring[8] = "CFE1CFE1";
159 char buf[9];
160 int ret;
161 size_t retlen;
162
163 ret = master->read(master, idoffset, 8, &retlen, (void *)buf);
164 buf[retlen] = 0;
165 printk(KERN_INFO PFX "Read Signature value of %s\n", buf);
166
167 return strncmp(idstring, buf, 8);
168}
169
170static int bcm963xx_probe(struct platform_device *pdev)
171{
172 int err = 0;
173 int parsed_nr_parts = 0;
174 char *part_type;
175 struct resource *r;
176
177 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
178 if (!r) {
179 dev_err(&pdev->dev, "no resource supplied\n");
180 return -ENODEV;
181 }
182
183 bcm963xx_map.phys = r->start;
184 bcm963xx_map.size = resource_size(r);
185 bcm963xx_map.virt = ioremap(r->start, resource_size(r));
186 if (!bcm963xx_map.virt) {
187 dev_err(&pdev->dev, "failed to ioremap\n");
188 return -EIO;
189 }
190
191 dev_info(&pdev->dev, "0x%08lx at 0x%08x\n",
192 bcm963xx_map.size, bcm963xx_map.phys);
193
194 simple_map_init(&bcm963xx_map);
195
196 bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
197 if (!bcm963xx_mtd_info) {
198 dev_err(&pdev->dev, "failed to probe using CFI\n");
199 err = -EIO;
200 goto err_probe;
201 }
202
203 bcm963xx_mtd_info->owner = THIS_MODULE;
204
205 /* This is mutually exclusive */
206 if (bcm963xx_detect_cfe(bcm963xx_mtd_info) == 0) {
207 dev_info(&pdev->dev, "CFE bootloader detected\n");
208 if (parsed_nr_parts == 0) {
209 int ret = parse_cfe_partitions(bcm963xx_mtd_info,
210 &parsed_parts);
211 if (ret > 0) {
212 part_type = "CFE";
213 parsed_nr_parts = ret;
214 }
215 }
216 } else {
217 dev_info(&pdev->dev, "unsupported bootloader\n");
218 err = -ENODEV;
219 goto err_probe;
220 }
221
222 return add_mtd_partitions(bcm963xx_mtd_info, parsed_parts,
223 parsed_nr_parts);
224
225err_probe:
226 iounmap(bcm963xx_map.virt);
227 return err;
228}
229
230static int bcm963xx_remove(struct platform_device *pdev)
231{
232 if (bcm963xx_mtd_info) {
233 del_mtd_partitions(bcm963xx_mtd_info);
234 map_destroy(bcm963xx_mtd_info);
235 }
236
237 if (bcm963xx_map.virt) {
238 iounmap(bcm963xx_map.virt);
239 bcm963xx_map.virt = 0;
240 }
241
242 return 0;
243}
244
245static struct platform_driver bcm63xx_mtd_dev = {
246 .probe = bcm963xx_probe,
247 .remove = bcm963xx_remove,
248 .driver = {
249 .name = "bcm963xx-flash",
250 .owner = THIS_MODULE,
251 },
252};
253
254static int __init bcm963xx_mtd_init(void)
255{
256 return platform_driver_register(&bcm63xx_mtd_dev);
257}
258
259static void __exit bcm963xx_mtd_exit(void)
260{
261 platform_driver_unregister(&bcm63xx_mtd_dev);
262}
263
264module_init(bcm963xx_mtd_init);
265module_exit(bcm963xx_mtd_exit);
266
267MODULE_LICENSE("GPL");
268MODULE_DESCRIPTION("Broadcom BCM63xx MTD driver for CFE and RedBoot");
269MODULE_AUTHOR("Daniel Dickinson <openwrt@cshore.neomailbox.net>");
270MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
271MODULE_AUTHOR("Mike Albon <malbon@openwrt.org>");
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index 32e89d773b4e..af5707a80205 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -208,10 +208,14 @@ static int __devinit gpio_flash_probe(struct platform_device *pdev)
208 if (!state) 208 if (!state)
209 return -ENOMEM; 209 return -ENOMEM;
210 210
211 /*
212 * We cast start/end to known types in the boards file, so cast
213 * away their pointer types here to the known types (gpios->xxx).
214 */
211 state->gpio_count = gpios->end; 215 state->gpio_count = gpios->end;
212 state->gpio_addrs = (void *)gpios->start; 216 state->gpio_addrs = (void *)(unsigned long)gpios->start;
213 state->gpio_values = (void *)(state + 1); 217 state->gpio_values = (void *)(state + 1);
214 state->win_size = memory->end - memory->start + 1; 218 state->win_size = resource_size(memory);
215 memset(state->gpio_values, 0xff, arr_size); 219 memset(state->gpio_values, 0xff, arr_size);
216 220
217 state->map.name = DRIVER_NAME; 221 state->map.name = DRIVER_NAME;
@@ -221,7 +225,7 @@ static int __devinit gpio_flash_probe(struct platform_device *pdev)
221 state->map.copy_to = gf_copy_to; 225 state->map.copy_to = gf_copy_to;
222 state->map.bankwidth = pdata->width; 226 state->map.bankwidth = pdata->width;
223 state->map.size = state->win_size * (1 << state->gpio_count); 227 state->map.size = state->win_size * (1 << state->gpio_count);
224 state->map.virt = (void __iomem *)memory->start; 228 state->map.virt = ioremap_nocache(memory->start, state->map.size);
225 state->map.phys = NO_XIP; 229 state->map.phys = NO_XIP;
226 state->map.map_priv_1 = (unsigned long)state; 230 state->map.map_priv_1 = (unsigned long)state;
227 231
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 57a1acfe22c4..917022948399 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -640,10 +640,6 @@ static int pcmciamtd_config(struct pcmcia_device *link)
640 } 640 }
641 dev_info(&dev->p_dev->dev, "mtd%d: %s\n", mtd->index, mtd->name); 641 dev_info(&dev->p_dev->dev, "mtd%d: %s\n", mtd->index, mtd->name);
642 return 0; 642 return 0;
643
644 dev_err(&dev->p_dev->dev, "CS Error, exiting\n");
645 pcmciamtd_release(link);
646 return -ENODEV;
647} 643}
648 644
649 645
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index ec3edf6e68b4..9861814aa027 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -50,7 +50,7 @@ static int parse_obsolete_partitions(struct platform_device *dev,
50{ 50{
51 int i, plen, nr_parts; 51 int i, plen, nr_parts;
52 const struct { 52 const struct {
53 u32 offset, len; 53 __be32 offset, len;
54 } *part; 54 } *part;
55 const char *names; 55 const char *names;
56 56
@@ -69,9 +69,9 @@ static int parse_obsolete_partitions(struct platform_device *dev,
69 names = of_get_property(dp, "partition-names", &plen); 69 names = of_get_property(dp, "partition-names", &plen);
70 70
71 for (i = 0; i < nr_parts; i++) { 71 for (i = 0; i < nr_parts; i++) {
72 info->parts[i].offset = part->offset; 72 info->parts[i].offset = be32_to_cpu(part->offset);
73 info->parts[i].size = part->len & ~1; 73 info->parts[i].size = be32_to_cpu(part->len) & ~1;
74 if (part->len & 1) /* bit 0 set signifies read only partition */ 74 if (be32_to_cpu(part->len) & 1) /* bit 0 set signifies read only partition */
75 info->parts[i].mask_flags = MTD_WRITEABLE; 75 info->parts[i].mask_flags = MTD_WRITEABLE;
76 76
77 if (names && (plen > 0)) { 77 if (names && (plen > 0)) {
@@ -226,11 +226,11 @@ static int __devinit of_flash_probe(struct platform_device *dev,
226 struct resource res; 226 struct resource res;
227 struct of_flash *info; 227 struct of_flash *info;
228 const char *probe_type = match->data; 228 const char *probe_type = match->data;
229 const u32 *width; 229 const __be32 *width;
230 int err; 230 int err;
231 int i; 231 int i;
232 int count; 232 int count;
233 const u32 *p; 233 const __be32 *p;
234 int reg_tuple_size; 234 int reg_tuple_size;
235 struct mtd_info **mtd_list = NULL; 235 struct mtd_info **mtd_list = NULL;
236 resource_size_t res_size; 236 resource_size_t res_size;
@@ -267,9 +267,11 @@ static int __devinit of_flash_probe(struct platform_device *dev,
267 for (i = 0; i < count; i++) { 267 for (i = 0; i < count; i++) {
268 err = -ENXIO; 268 err = -ENXIO;
269 if (of_address_to_resource(dp, i, &res)) { 269 if (of_address_to_resource(dp, i, &res)) {
270 dev_err(&dev->dev, "Can't get IO address from device" 270 /*
271 " tree\n"); 271 * Continue with next register tuple if this
272 goto err_out; 272 * one is not mappable
273 */
274 continue;
273 } 275 }
274 276
275 dev_dbg(&dev->dev, "of_flash device: %.8llx-%.8llx\n", 277 dev_dbg(&dev->dev, "of_flash device: %.8llx-%.8llx\n",