ar71xx: enable sysupgrade on the AP96 and DB120 boards
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.0 / 0015-mtd-bcm47xx-add-parallel-flash-driver.patch
1 From 941c7a12af5d985c9dabc6813db3b75908bd619c Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 17 Jul 2011 14:55:18 +0200
4 Subject: [PATCH 15/22] mtd: bcm47xx: add parallel flash driver
5
6
7 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
8 ---
9 drivers/mtd/maps/Kconfig | 9 ++
10 drivers/mtd/maps/Makefile | 1 +
11 drivers/mtd/maps/bcm47xx-pflash.c | 196 +++++++++++++++++++++++++++++++++++++
12 3 files changed, 206 insertions(+), 0 deletions(-)
13 create mode 100644 drivers/mtd/maps/bcm47xx-pflash.c
14
15 --- a/drivers/mtd/maps/Kconfig
16 +++ b/drivers/mtd/maps/Kconfig
17 @@ -264,6 +264,15 @@ config MTD_LANTIQ
18 help
19 Support for NOR flash attached to the Lantiq SoC's External Bus Unit.
20
21 +config MTD_BCM47XX_PFLASH
22 + tristate "bcm47xx parallel flash support"
23 + default y
24 + depends on BCM47XX
25 + select MTD_PARTITIONS
26 + select MTD_BCM47XX_PARTS
27 + help
28 + Support for bcm47xx parallel flash
29 +
30 config MTD_DILNETPC
31 tristate "CFI Flash device mapped on DIL/Net PC"
32 depends on X86 && MTD_CFI_INTELEXT && BROKEN
33 --- a/drivers/mtd/maps/Makefile
34 +++ b/drivers/mtd/maps/Makefile
35 @@ -60,3 +60,4 @@ obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr
36 obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
37 obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o
38 obj-$(CONFIG_MTD_LANTIQ) += lantiq-flash.o
39 +obj-$(CONFIG_MTD_BCM47XX_PFLASH)+= bcm47xx-pflash.o
40 --- /dev/null
41 +++ b/drivers/mtd/maps/bcm47xx-pflash.c
42 @@ -0,0 +1,196 @@
43 +/*
44 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
45 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
46 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
47 + *
48 + * original functions for finding root filesystem from Mike Baker
49 + *
50 + * This program is free software; you can redistribute it and/or modify it
51 + * under the terms of the GNU General Public License as published by the
52 + * Free Software Foundation; either version 2 of the License, or (at your
53 + * option) any later version.
54 + *
55 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
56 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
57 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
58 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
59 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
60 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
61 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
62 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
64 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 + *
66 + * You should have received a copy of the GNU General Public License along
67 + * with this program; if not, write to the Free Software Foundation, Inc.,
68 + * 675 Mass Ave, Cambridge, MA 02139, USA.
69 + *
70 + * Copyright 2001-2003, Broadcom Corporation
71 + * All Rights Reserved.
72 + *
73 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
74 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
75 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
76 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
77 + *
78 + * Flash mapping for BCM947XX boards
79 + */
80 +
81 +#define pr_fmt(fmt) "bcm47xx_pflash: " fmt
82 +#include <linux/init.h>
83 +#include <linux/module.h>
84 +#include <linux/types.h>
85 +#include <linux/kernel.h>
86 +#include <linux/sched.h>
87 +#include <linux/mtd/mtd.h>
88 +#include <linux/mtd/map.h>
89 +#include <linux/mtd/partitions.h>
90 +#include <asm/io.h>
91 +#include <asm/mach-bcm47xx/bcm47xx.h>
92 +#include <linux/platform_device.h>
93 +
94 +#define WINDOW_ADDR 0x1fc00000
95 +#define WINDOW_SIZE 0x400000
96 +#define BUSWIDTH 2
97 +
98 +static struct mtd_info *bcm47xx_mtd;
99 +
100 +static void bcm47xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
101 +{
102 + if (len==1) {
103 + memcpy_fromio(to, map->virt + from, len);
104 + } else {
105 + int i;
106 + u16 *dest = (u16 *) to;
107 + u16 *src = (u16 *) (map->virt + from);
108 + for (i = 0; i < (len / 2); i++) {
109 + dest[i] = src[i];
110 + }
111 + if (len & 1)
112 + *((u8 *)dest+len-1) = src[i] & 0xff;
113 + }
114 +}
115 +
116 +static struct map_info bcm47xx_map = {
117 + name: "Physically mapped flash",
118 + size: WINDOW_SIZE,
119 + bankwidth: BUSWIDTH,
120 + phys: WINDOW_ADDR,
121 +};
122 +
123 +static const char *probes[] = { "bcm47xx", NULL };
124 +
125 +static int bcm47xx_mtd_probe(struct platform_device *pdev)
126 +{
127 +#ifdef CONFIG_BCM47XX_SSB
128 + struct ssb_mipscore *mcore_ssb;
129 +#endif
130 +#ifdef CONFIG_BCM47XX_BCMA
131 + struct bcma_drv_cc *bcma_cc;
132 +#endif
133 + int ret = 0;
134 + struct mtd_partition *partitions = NULL;
135 + int num_partitions = 0;
136 +
137 + switch (bcm47xx_active_bus_type) {
138 +#ifdef CONFIG_BCM47XX_SSB
139 + case BCM47XX_BUS_TYPE_SSB:
140 + mcore_ssb = &bcm47xx_bus.ssb.mipscore;
141 + bcm47xx_map.phys = mcore_ssb->flash_window;
142 + bcm47xx_map.size = mcore_ssb->flash_window_size;
143 + bcm47xx_map.bankwidth = mcore_ssb->flash_buswidth;
144 + break;
145 +#endif
146 +#ifdef CONFIG_BCM47XX_BCMA
147 + case BCM47XX_BUS_TYPE_BCMA:
148 + bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc;
149 + if (bcma_cc->flash_type != BCMA_PFLASH)
150 + return -ENODEV;
151 +
152 + bcm47xx_map.phys = bcma_cc->flash.pflash.window;
153 + bcm47xx_map.size = bcma_cc->flash.pflash.window_size;
154 + bcm47xx_map.bankwidth = bcma_cc->flash.pflash.buswidth;
155 + break;
156 +#endif
157 + }
158 +
159 + pr_notice("flash init: 0x%08x 0x%08lx\n", bcm47xx_map.phys, bcm47xx_map.size);
160 + bcm47xx_map.virt = ioremap_nocache(bcm47xx_map.phys, bcm47xx_map.size);
161 +
162 + if (!bcm47xx_map.virt) {
163 + pr_err("Failed to ioremap\n");
164 + return -EIO;
165 + }
166 +
167 + simple_map_init(&bcm47xx_map);
168 + /* override copy_from routine */
169 + bcm47xx_map.copy_from = bcm47xx_map_copy_from;
170 +
171 + bcm47xx_mtd = do_map_probe("cfi_probe", &bcm47xx_map);
172 + if (!bcm47xx_mtd) {
173 + pr_err("Failed to do_map_probe\n");
174 + ret = -ENXIO;
175 + goto err_unmap;
176 + }
177 + bcm47xx_mtd->owner = THIS_MODULE;
178 +
179 + pr_notice("Flash device: 0x%lx at 0x%x\n", bcm47xx_map.size, WINDOW_ADDR);
180 +
181 + num_partitions = parse_mtd_partitions(bcm47xx_mtd, probes, &partitions, 0);
182 + if (num_partitions < 0) {
183 + ret = num_partitions;
184 + goto err_unmap;
185 + }
186 +
187 + ret = mtd_device_register(bcm47xx_mtd, partitions, num_partitions);
188 +
189 +// ret = mtd_device_parse_register(bcm47xx_mtd, "bcm47xx", NULL, NULL, 0);
190 +
191 + if (ret) {
192 + pr_err("Flash: mtd_device_register failed\n");
193 + goto err_destroy;
194 + }
195 + return 0;
196 +
197 +err_destroy:
198 + map_destroy(bcm47xx_mtd);
199 +err_unmap:
200 + iounmap(bcm47xx_map.virt);
201 + return ret;
202 +}
203 +
204 +static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev)
205 +{
206 + mtd_device_unregister(bcm47xx_mtd);
207 + map_destroy(bcm47xx_mtd);
208 + iounmap(bcm47xx_map.virt);
209 + return 0;
210 +}
211 +
212 +static struct platform_driver bcm47xx_mtd_driver = {
213 + .remove = __devexit_p(bcm47xx_mtd_remove),
214 + .driver = {
215 + .name = "bcm47xx_pflash",
216 + .owner = THIS_MODULE,
217 + },
218 +};
219 +
220 +static int __init init_bcm47xx_mtd(void)
221 +{
222 + int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe);
223 +
224 + if (ret)
225 + pr_err("error registering platform driver: %i\n", ret);
226 + return ret;
227 +}
228 +
229 +static void __exit exit_bcm47xx_mtd(void)
230 +{
231 + platform_driver_unregister(&bcm47xx_mtd_driver);
232 +}
233 +
234 +module_init(init_bcm47xx_mtd);
235 +module_exit(exit_bcm47xx_mtd);
236 +
237 +MODULE_LICENSE("GPL");
238 +MODULE_DESCRIPTION("BCM47XX parallel flash driver");