source: trunk/target/linux/brcm47xx/patches-3.2/0018-mtd-bcm47xx-add-parallel-flash-driver.patch @ 29756

Last change on this file since 29756 was 29756, checked in by hauke, 4 years ago

brcm47xx: add support for kernel 3.2

File size: 6.9 KB
  • drivers/mtd/maps/Kconfig

    From 36f8b899174a445a98fe02ed8d1db177525f0c52 Mon Sep 17 00:00:00 2001
    From: Hauke Mehrtens <hauke@hauke-m.de>
    Date: Sun, 17 Jul 2011 14:55:18 +0200
    Subject: [PATCH 07/15] mtd: bcm47xx: add parallel flash driver
    
    
    Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
    ---
     drivers/mtd/maps/Kconfig          |    9 ++
     drivers/mtd/maps/Makefile         |    1 +
     drivers/mtd/maps/bcm47xx-pflash.c |  188 +++++++++++++++++++++++++++++++++++++
     3 files changed, 198 insertions(+), 0 deletions(-)
     create mode 100644 drivers/mtd/maps/bcm47xx-pflash.c
    
    a b config MTD_LANTIQ 
    257257        help 
    258258          Support for NOR flash attached to the Lantiq SoC's External Bus Unit. 
    259259 
     260config MTD_BCM47XX_PFLASH 
     261        tristate "bcm47xx parallel flash support" 
     262        default y 
     263        depends on BCM47XX 
     264        select MTD_PARTITIONS 
     265        select MTD_BCM47XX_PARTS 
     266        help 
     267          Support for bcm47xx parallel flash 
     268 
    260269config MTD_DILNETPC 
    261270        tristate "CFI Flash device mapped on DIL/Net PC" 
    262271        depends on X86 && MTD_CFI_INTELEXT && BROKEN 
  • drivers/mtd/maps/Makefile

    a b obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr 
    5858obj-$(CONFIG_MTD_BCM963XX)      += bcm963xx-flash.o 
    5959obj-$(CONFIG_MTD_LATCH_ADDR)    += latch-addr-flash.o 
    6060obj-$(CONFIG_MTD_LANTIQ)        += lantiq-flash.o 
     61obj-$(CONFIG_MTD_BCM47XX_PFLASH)+= bcm47xx-pflash.o 
  • new file drivers/mtd/maps/bcm47xx-pflash.c

    - +  
     1/* 
     2 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org> 
     3 *  Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org> 
     4 *  Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org) 
     5 * 
     6 *  original functions for finding root filesystem from Mike Baker 
     7 * 
     8 *  This program is free software; you can redistribute  it and/or modify it 
     9 *  under  the terms of  the GNU General  Public License as published by the 
     10 *  Free Software Foundation;  either version 2 of the  License, or (at your 
     11 *  option) any later version. 
     12 * 
     13 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED 
     14 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF 
     15 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN 
     16 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT, 
     17 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
     18 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF 
     19 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
     20 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT 
     21 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
     22 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * 
     24 *  You should have received a copy of the  GNU General Public License along 
     25 *  with this program; if not, write  to the Free Software Foundation, Inc., 
     26 *  675 Mass Ave, Cambridge, MA 02139, USA. 
     27 * 
     28 *  Copyright 2001-2003, Broadcom Corporation 
     29 *  All Rights Reserved. 
     30 * 
     31 *  THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY 
     32 *  KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM 
     33 *  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
     34 *  FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. 
     35 * 
     36 *  Flash mapping for BCM947XX boards 
     37 */ 
     38 
     39#define pr_fmt(fmt) "bcm47xx_pflash: " fmt 
     40#include <linux/init.h> 
     41#include <linux/module.h> 
     42#include <linux/types.h> 
     43#include <linux/kernel.h> 
     44#include <linux/sched.h> 
     45#include <linux/mtd/mtd.h> 
     46#include <linux/mtd/map.h> 
     47#include <linux/mtd/partitions.h> 
     48#include <linux/io.h> 
     49#include <asm/mach-bcm47xx/bcm47xx.h> 
     50#include <linux/platform_device.h> 
     51 
     52#define WINDOW_ADDR 0x1fc00000 
     53#define WINDOW_SIZE 0x400000 
     54#define BUSWIDTH 2 
     55 
     56static struct mtd_info *bcm47xx_mtd; 
     57 
     58static void bcm47xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 
     59{ 
     60        if (len == 1) { 
     61                memcpy_fromio(to, map->virt + from, len); 
     62        } else { 
     63                int i; 
     64                u16 *dest = (u16 *) to; 
     65                u16 *src  = (u16 *) (map->virt + from); 
     66                for (i = 0; i < (len / 2); i++) 
     67                        dest[i] = src[i]; 
     68                if (len & 1) 
     69                        *((u8 *)dest+len-1) = src[i] & 0xff; 
     70        } 
     71} 
     72 
     73static struct map_info bcm47xx_map = { 
     74        name: "Physically mapped flash", 
     75        size : WINDOW_SIZE, 
     76        bankwidth : BUSWIDTH, 
     77        phys : WINDOW_ADDR, 
     78}; 
     79 
     80static const char *probes[] = { "bcm47xx", NULL }; 
     81 
     82static int bcm47xx_mtd_probe(struct platform_device *pdev) 
     83{ 
     84#ifdef CONFIG_BCM47XX_SSB 
     85        struct ssb_chipcommon *ssb_cc; 
     86#endif 
     87#ifdef CONFIG_BCM47XX_BCMA 
     88        struct bcma_drv_cc *bcma_cc; 
     89#endif 
     90        int ret = 0; 
     91 
     92        switch (bcm47xx_bus_type) { 
     93#ifdef CONFIG_BCM47XX_SSB 
     94        case BCM47XX_BUS_TYPE_SSB: 
     95                ssb_cc = &bcm47xx_bus.ssb.chipco; 
     96                if (ssb_cc->flash_type != SSB_PFLASH) 
     97                        return -ENODEV; 
     98 
     99                bcm47xx_map.phys = ssb_cc->pflash.window; 
     100                bcm47xx_map.size = ssb_cc->pflash.window_size; 
     101                bcm47xx_map.bankwidth = ssb_cc->pflash.buswidth; 
     102                break; 
     103#endif 
     104#ifdef CONFIG_BCM47XX_BCMA 
     105        case BCM47XX_BUS_TYPE_BCMA: 
     106                bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc; 
     107                if (bcma_cc->flash_type != BCMA_PFLASH) 
     108                        return -ENODEV; 
     109 
     110                bcm47xx_map.phys = bcma_cc->pflash.window; 
     111                bcm47xx_map.size = bcma_cc->pflash.window_size; 
     112                bcm47xx_map.bankwidth = bcma_cc->pflash.buswidth; 
     113                break; 
     114#endif 
     115        } 
     116 
     117        pr_notice("flash init: 0x%08x 0x%08lx\n", bcm47xx_map.phys, bcm47xx_map.size); 
     118        bcm47xx_map.virt = ioremap_nocache(bcm47xx_map.phys, bcm47xx_map.size); 
     119 
     120        if (!bcm47xx_map.virt) { 
     121                pr_err("Failed to ioremap\n"); 
     122                return -EIO; 
     123        } 
     124 
     125        simple_map_init(&bcm47xx_map); 
     126        /* override copy_from routine */ 
     127        bcm47xx_map.copy_from = bcm47xx_map_copy_from; 
     128 
     129        bcm47xx_mtd = do_map_probe("cfi_probe", &bcm47xx_map); 
     130        if (!bcm47xx_mtd) { 
     131                pr_err("Failed to do_map_probe\n"); 
     132                ret = -ENXIO; 
     133                goto err_unmap; 
     134        } 
     135        bcm47xx_mtd->owner = THIS_MODULE; 
     136 
     137        pr_notice("Flash device: 0x%lx at 0x%x\n", bcm47xx_map.size, WINDOW_ADDR); 
     138 
     139        ret = mtd_device_parse_register(bcm47xx_mtd, probes, NULL, NULL, 0); 
     140 
     141        if (ret) { 
     142                pr_err("Flash: mtd_device_register failed\n"); 
     143                goto err_destroy; 
     144        } 
     145        return 0; 
     146 
     147err_destroy: 
     148        map_destroy(bcm47xx_mtd); 
     149err_unmap: 
     150        iounmap(bcm47xx_map.virt); 
     151        return ret; 
     152} 
     153 
     154static int __devexit bcm47xx_mtd_remove(struct platform_device *pdev) 
     155{ 
     156        mtd_device_unregister(bcm47xx_mtd); 
     157        map_destroy(bcm47xx_mtd); 
     158        iounmap(bcm47xx_map.virt); 
     159        return 0; 
     160} 
     161 
     162static struct platform_driver bcm47xx_mtd_driver = { 
     163        .remove = __devexit_p(bcm47xx_mtd_remove), 
     164        .driver = { 
     165                .name = "bcm47xx_pflash", 
     166                .owner = THIS_MODULE, 
     167        }, 
     168}; 
     169 
     170static int __init init_bcm47xx_mtd(void) 
     171{ 
     172        int ret = platform_driver_probe(&bcm47xx_mtd_driver, bcm47xx_mtd_probe); 
     173 
     174        if (ret) 
     175                pr_err("error registering platform driver: %i\n", ret); 
     176        return ret; 
     177} 
     178 
     179static void __exit exit_bcm47xx_mtd(void) 
     180{ 
     181        platform_driver_unregister(&bcm47xx_mtd_driver); 
     182} 
     183 
     184module_init(init_bcm47xx_mtd); 
     185module_exit(exit_bcm47xx_mtd); 
     186 
     187MODULE_LICENSE("GPL"); 
     188MODULE_DESCRIPTION("BCM47XX parallel flash driver"); 
Note: See TracBrowser for help on using the repository browser.