613dc8914caf8dcb691de9f77574196ad077cee2
[openwrt.git] / target / linux / brcm47xx / patches-3.2 / 0018-mtd-bcm47xx-add-parallel-flash-driver.patch
1 From 36f8b899174a445a98fe02ed8d1db177525f0c52 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 07/15] 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 | 188 +++++++++++++++++++++++++++++++++++++
12 3 files changed, 198 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 @@ -257,6 +257,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 @@ -58,3 +58,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,188 @@
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 +
134 + switch (bcm47xx_bus_type) {
135 +#ifdef CONFIG_BCM47XX_SSB
136 + case BCM47XX_BUS_TYPE_SSB:
137 + ssb_cc = &bcm47xx_bus.ssb.chipco;
138 + if (ssb_cc->flash_type != SSB_PFLASH)
139 + return -ENODEV;
140 +
141 + bcm47xx_map.phys = ssb_cc->pflash.window;
142 + bcm47xx_map.size = ssb_cc->pflash.window_size;
143 + bcm47xx_map.bankwidth = ssb_cc->pflash.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->pflash.window;
153 + bcm47xx_map.size = bcma_cc->pflash.window_size;
154 + bcm47xx_map.bankwidth = bcma_cc->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 + ret = mtd_device_parse_register(bcm47xx_mtd, probes, NULL, NULL, 0);
182 +
183 + if (ret) {
184 + pr_err("Flash: mtd_device_register failed\n");
185 + goto err_destroy;
186 + }
187 + return 0;
188 +
189 +err_destroy:
190 + map_destroy(bcm47xx_mtd);
191 +err_unmap:
192 + iounmap(bcm47xx_map.virt);
193 + return ret;
194 +}
195 +
196 +static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev)
197 +{
198 + mtd_device_unregister(bcm47xx_mtd);
199 + map_destroy(bcm47xx_mtd);
200 + iounmap(bcm47xx_map.virt);
201 + return 0;
202 +}
203 +
204 +static struct platform_driver bcm47xx_mtd_driver = {
205 + .remove = __devexit_p(bcm47xx_mtd_remove),
206 + .driver = {
207 + .name = "bcm47xx_pflash",
208 + .owner = THIS_MODULE,
209 + },
210 +};
211 +
212 +static int __init init_bcm47xx_mtd(void)
213 +{
214 + int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe);
215 +
216 + if (ret)
217 + pr_err("error registering platform driver: %i\n", ret);
218 + return ret;
219 +}
220 +
221 +static void __exit exit_bcm47xx_mtd(void)
222 +{
223 + platform_driver_unregister(&bcm47xx_mtd_driver);
224 +}
225 +
226 +module_init(init_bcm47xx_mtd);
227 +module_exit(exit_bcm47xx_mtd);
228 +
229 +MODULE_LICENSE("GPL");
230 +MODULE_DESCRIPTION("BCM47XX parallel flash driver");
This page took 0.065703 seconds and 3 git commands to generate.