targets: replace madwifi in profiles with ath5k, madwifi is unmaintained
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.0 / 0018-mtd-bcm47xx-add-parallel-flash-driver.patch
1 From fb261916ee9cd9eede57f6255ffd39e4145da48e 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 18/26] 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 | 198 +++++++++++++++++++++++++++++++++++++
12 3 files changed, 208 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,198 @@
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 <linux/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 + if (len & 1)
111 + *((u8 *)dest+len-1) = src[i] & 0xff;
112 + }
113 +}
114 +
115 +static struct map_info bcm47xx_map = {
116 + name: "Physically mapped flash",
117 + size : WINDOW_SIZE,
118 + bankwidth : BUSWIDTH,
119 + phys : WINDOW_ADDR,
120 +};
121 +
122 +static const char *probes[] = { "bcm47xx", NULL };
123 +
124 +static int bcm47xx_mtd_probe(struct platform_device *pdev)
125 +{
126 +#ifdef CONFIG_BCM47XX_SSB
127 + struct ssb_chipcommon *ssb_cc;
128 +#endif
129 +#ifdef CONFIG_BCM47XX_BCMA
130 + struct bcma_drv_cc *bcma_cc;
131 +#endif
132 + int ret = 0;
133 + struct mtd_partition *partitions = NULL;
134 + int num_partitions = 0;
135 +
136 + switch (bcm47xx_bus_type) {
137 +#ifdef CONFIG_BCM47XX_SSB
138 + case BCM47XX_BUS_TYPE_SSB:
139 + ssb_cc = &bcm47xx_bus.ssb.chipco;
140 + if (ssb_cc->flash_type != SSB_PFLASH)
141 + return -ENODEV;
142 +
143 + bcm47xx_map.phys = ssb_cc->pflash.window;
144 + bcm47xx_map.size = ssb_cc->pflash.window_size;
145 + bcm47xx_map.bankwidth = ssb_cc->pflash.buswidth;
146 + break;
147 +#endif
148 +#ifdef CONFIG_BCM47XX_BCMA
149 + case BCM47XX_BUS_TYPE_BCMA:
150 + bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc;
151 + if (bcma_cc->flash_type != BCMA_PFLASH)
152 + return -ENODEV;
153 +
154 + bcm47xx_map.phys = bcma_cc->pflash.window;
155 + bcm47xx_map.size = bcma_cc->pflash.window_size;
156 + bcm47xx_map.bankwidth = bcma_cc->pflash.buswidth;
157 + break;
158 +#endif
159 + }
160 +
161 + pr_notice("flash init: 0x%08x 0x%08lx\n", bcm47xx_map.phys, bcm47xx_map.size);
162 + bcm47xx_map.virt = ioremap_nocache(bcm47xx_map.phys, bcm47xx_map.size);
163 +
164 + if (!bcm47xx_map.virt) {
165 + pr_err("Failed to ioremap\n");
166 + return -EIO;
167 + }
168 +
169 + simple_map_init(&bcm47xx_map);
170 + /* override copy_from routine */
171 + bcm47xx_map.copy_from = bcm47xx_map_copy_from;
172 +
173 + bcm47xx_mtd = do_map_probe("cfi_probe", &bcm47xx_map);
174 + if (!bcm47xx_mtd) {
175 + pr_err("Failed to do_map_probe\n");
176 + ret = -ENXIO;
177 + goto err_unmap;
178 + }
179 + bcm47xx_mtd->owner = THIS_MODULE;
180 +
181 + pr_notice("Flash device: 0x%lx at 0x%x\n", bcm47xx_map.size, WINDOW_ADDR);
182 +
183 + num_partitions = parse_mtd_partitions(bcm47xx_mtd, probes, &partitions, 0);
184 + if (num_partitions < 0) {
185 + ret = num_partitions;
186 + goto err_unmap;
187 + }
188 +
189 + ret = mtd_device_register(bcm47xx_mtd, partitions, num_partitions);
190 +
191 +// ret = mtd_device_parse_register(bcm47xx_mtd, "bcm47xx", NULL, NULL, 0);
192 +
193 + if (ret) {
194 + pr_err("Flash: mtd_device_register failed\n");
195 + goto err_destroy;
196 + }
197 + return 0;
198 +
199 +err_destroy:
200 + map_destroy(bcm47xx_mtd);
201 +err_unmap:
202 + iounmap(bcm47xx_map.virt);
203 + return ret;
204 +}
205 +
206 +static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev)
207 +{
208 + mtd_device_unregister(bcm47xx_mtd);
209 + map_destroy(bcm47xx_mtd);
210 + iounmap(bcm47xx_map.virt);
211 + return 0;
212 +}
213 +
214 +static struct platform_driver bcm47xx_mtd_driver = {
215 + .remove = __devexit_p(bcm47xx_mtd_remove),
216 + .driver = {
217 + .name = "bcm47xx_pflash",
218 + .owner = THIS_MODULE,
219 + },
220 +};
221 +
222 +static int __init init_bcm47xx_mtd(void)
223 +{
224 + int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe);
225 +
226 + if (ret)
227 + pr_err("error registering platform driver: %i\n", ret);
228 + return ret;
229 +}
230 +
231 +static void __exit exit_bcm47xx_mtd(void)
232 +{
233 + platform_driver_unregister(&bcm47xx_mtd_driver);
234 +}
235 +
236 +module_init(init_bcm47xx_mtd);
237 +module_exit(exit_bcm47xx_mtd);
238 +
239 +MODULE_LICENSE("GPL");
240 +MODULE_DESCRIPTION("BCM47XX parallel flash driver");