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
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 | 198 +++++++++++++++++++++++++++++++++++++
12 3 files changed, 208 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 @@ -264,6 +264,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 @@ -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
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;
133 + struct mtd_partition *partitions = NULL;
134 + int num_partitions = 0;
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)
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;
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)
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;
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);
164 + if (!bcm47xx_map.virt) {
165 + pr_err("Failed to ioremap\n");
169 + simple_map_init(&bcm47xx_map);
170 + /* override copy_from routine */
171 + bcm47xx_map.copy_from = bcm47xx_map_copy_from;
173 + bcm47xx_mtd = do_map_probe("cfi_probe", &bcm47xx_map);
174 + if (!bcm47xx_mtd) {
175 + pr_err("Failed to do_map_probe\n");
179 + bcm47xx_mtd->owner = THIS_MODULE;
181 + pr_notice("Flash device: 0x%lx at 0x%x\n", bcm47xx_map.size, WINDOW_ADDR);
183 + num_partitions = parse_mtd_partitions(bcm47xx_mtd, probes, &partitions, 0);
184 + if (num_partitions < 0) {
185 + ret = num_partitions;
189 + ret = mtd_device_register(bcm47xx_mtd, partitions, num_partitions);
191 +// ret = mtd_device_parse_register(bcm47xx_mtd, "bcm47xx", NULL, NULL, 0);
194 + pr_err("Flash: mtd_device_register failed\n");
200 + map_destroy(bcm47xx_mtd);
202 + iounmap(bcm47xx_map.virt);
206 +static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev)
208 + mtd_device_unregister(bcm47xx_mtd);
209 + map_destroy(bcm47xx_mtd);
210 + iounmap(bcm47xx_map.virt);
214 +static struct platform_driver bcm47xx_mtd_driver = {
215 + .remove = __devexit_p(bcm47xx_mtd_remove),
217 + .name = "bcm47xx_pflash",
218 + .owner = THIS_MODULE,
222 +static int __init init_bcm47xx_mtd(void)
224 + int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe);
227 + pr_err("error registering platform driver: %i\n", ret);
231 +static void __exit exit_bcm47xx_mtd(void)
233 + platform_driver_unregister(&bcm47xx_mtd_driver);
236 +module_init(init_bcm47xx_mtd);
237 +module_exit(exit_bcm47xx_mtd);
239 +MODULE_LICENSE("GPL");
240 +MODULE_DESCRIPTION("BCM47XX parallel flash driver");