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
7 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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
15 --- a/drivers/mtd/maps/Kconfig
16 +++ b/drivers/mtd/maps/Kconfig
17 @@ -257,6 +257,15 @@ config MTD_LANTIQ
19 Support for NOR flash attached to the Lantiq SoC's External Bus Unit.
21 +config MTD_BCM47XX_PFLASH
22 + tristate "bcm47xx parallel flash support"
25 + select MTD_PARTITIONS
26 + select MTD_BCM47XX_PARTS
28 + Support for bcm47xx parallel flash
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
41 +++ b/drivers/mtd/maps/bcm47xx-pflash.c
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)
48 + * original functions for finding root filesystem from Mike Baker
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.
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.
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.
70 + * Copyright 2001-2003, Broadcom Corporation
71 + * All Rights Reserved.
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.
78 + * Flash mapping for BCM947XX boards
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>
94 +#define WINDOW_ADDR 0x1fc00000
95 +#define WINDOW_SIZE 0x400000
98 +static struct mtd_info *bcm47xx_mtd;
100 +static void bcm47xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
103 + memcpy_fromio(to, map->virt + from, len);
106 + u16 *dest = (u16 *) to;
107 + u16 *src = (u16 *) (map->virt + from);
108 + for (i = 0; i < (len / 2); i++)
111 + *((u8 *)dest+len-1) = src[i] & 0xff;
115 +static struct map_info bcm47xx_map = {
116 + name: "Physically mapped flash",
117 + size : WINDOW_SIZE,
118 + bankwidth : BUSWIDTH,
119 + phys : WINDOW_ADDR,
122 +static const char *probes[] = { "bcm47xx", NULL };
124 +static int bcm47xx_mtd_probe(struct platform_device *pdev)
126 +#ifdef CONFIG_BCM47XX_SSB
127 + struct ssb_chipcommon *ssb_cc;
129 +#ifdef CONFIG_BCM47XX_BCMA
130 + struct bcma_drv_cc *bcma_cc;
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)
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;
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)
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;
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);
162 + if (!bcm47xx_map.virt) {
163 + pr_err("Failed to ioremap\n");
167 + simple_map_init(&bcm47xx_map);
168 + /* override copy_from routine */
169 + bcm47xx_map.copy_from = bcm47xx_map_copy_from;
171 + bcm47xx_mtd = do_map_probe("cfi_probe", &bcm47xx_map);
172 + if (!bcm47xx_mtd) {
173 + pr_err("Failed to do_map_probe\n");
177 + bcm47xx_mtd->owner = THIS_MODULE;
179 + pr_notice("Flash device: 0x%lx at 0x%x\n", bcm47xx_map.size, WINDOW_ADDR);
181 + ret = mtd_device_parse_register(bcm47xx_mtd, probes, NULL, NULL, 0);
184 + pr_err("Flash: mtd_device_register failed\n");
190 + map_destroy(bcm47xx_mtd);
192 + iounmap(bcm47xx_map.virt);
196 +static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev)
198 + mtd_device_unregister(bcm47xx_mtd);
199 + map_destroy(bcm47xx_mtd);
200 + iounmap(bcm47xx_map.virt);
204 +static struct platform_driver bcm47xx_mtd_driver = {
205 + .remove = __devexit_p(bcm47xx_mtd_remove),
207 + .name = "bcm47xx_pflash",
208 + .owner = THIS_MODULE,
212 +static int __init init_bcm47xx_mtd(void)
214 + int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe);
217 + pr_err("error registering platform driver: %i\n", ret);
221 +static void __exit exit_bcm47xx_mtd(void)
223 + platform_driver_unregister(&bcm47xx_mtd_driver);
226 +module_init(init_bcm47xx_mtd);
227 +module_exit(exit_bcm47xx_mtd);
229 +MODULE_LICENSE("GPL");
230 +MODULE_DESCRIPTION("BCM47XX parallel flash driver");