linux-old/drivers/mtd/maps/cfi_flagadm.c
<<
>>
Prefs
   1/*
   2 *  Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
   3 *
   4 *  $Id: cfi_flagadm.c,v 1.7 2001/10/02 15:05:13 dwmw2 Exp $
   5 *  
   6 *  This program is free software; you can redistribute  it and/or modify it
   7 *  under  the terms of  the GNU General  Public License as published by the
   8 *  Free Software Foundation;  either version 2 of the  License, or (at your
   9 *  option) any later version.
  10 *
  11 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
  12 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
  13 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
  14 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
  15 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
  17 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
  19 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21 *
  22 *  You should have received a copy of the  GNU General Public License along
  23 *  with this program; if not, write  to the Free Software Foundation, Inc.,
  24 *  675 Mass Ave, Cambridge, MA 02139, USA.
  25 */
  26
  27#include <linux/module.h>
  28#include <linux/types.h>
  29#include <linux/kernel.h>
  30#include <asm/io.h>
  31#include <linux/mtd/mtd.h>
  32#include <linux/mtd/map.h>
  33#include <linux/mtd/partitions.h>
  34
  35
  36/* We split the flash chip up into four parts.
  37 * 1: bootloader firts 128k                     (0x00000000 - 0x0001FFFF) size 0x020000
  38 * 2: kernel 640k                                       (0x00020000 - 0x000BFFFF) size 0x0A0000
  39 * 3: compressed 1536k root ramdisk     (0x000C0000 - 0x0023FFFF) size 0x180000
  40 * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000
  41 */
  42
  43#define FLASH_PHYS_ADDR 0x40000000
  44#define FLASH_SIZE 0x400000  
  45
  46#define FLASH_PARTITION0_ADDR 0x00000000
  47#define FLASH_PARTITION0_SIZE 0x00020000
  48
  49#define FLASH_PARTITION1_ADDR 0x00020000
  50#define FLASH_PARTITION1_SIZE 0x000A0000
  51
  52#define FLASH_PARTITION2_ADDR 0x000C0000
  53#define FLASH_PARTITION2_SIZE 0x00180000
  54
  55#define FLASH_PARTITION3_ADDR 0x00240000
  56#define FLASH_PARTITION3_SIZE 0x001C0000
  57
  58__u8 flagadm_read8(struct map_info *map, unsigned long ofs)
  59{
  60        return __raw_readb(map->map_priv_1 + ofs);
  61}
  62
  63__u16 flagadm_read16(struct map_info *map, unsigned long ofs)
  64{
  65        return __raw_readw(map->map_priv_1 + ofs);
  66}
  67
  68__u32 flagadm_read32(struct map_info *map, unsigned long ofs)
  69{
  70        return __raw_readl(map->map_priv_1 + ofs);
  71}
  72
  73void flagadm_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  74{
  75        memcpy_fromio(to, map->map_priv_1 + from, len);
  76}
  77
  78void flagadm_write8(struct map_info *map, __u8 d, unsigned long adr)
  79{
  80        __raw_writeb(d, map->map_priv_1 + adr);
  81        mb();
  82}
  83
  84void flagadm_write16(struct map_info *map, __u16 d, unsigned long adr)
  85{
  86        __raw_writew(d, map->map_priv_1 + adr);
  87        mb();
  88}
  89
  90void flagadm_write32(struct map_info *map, __u32 d, unsigned long adr)
  91{
  92        __raw_writel(d, map->map_priv_1 + adr);
  93        mb();
  94}
  95
  96void flagadm_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  97{
  98        memcpy_toio(map->map_priv_1 + to, from, len);
  99}
 100
 101struct map_info flagadm_map = {
 102                name: "FlagaDM flash device",
 103                size: FLASH_SIZE,
 104                buswidth: 2,
 105                read8: flagadm_read8,
 106                read16: flagadm_read16,
 107                read32: flagadm_read32,
 108                copy_from: flagadm_copy_from,
 109                write8: flagadm_write8,
 110                write16: flagadm_write16,
 111                write32: flagadm_write32,
 112                copy_to: flagadm_copy_to
 113};
 114
 115struct mtd_partition flagadm_parts[] = {
 116        {
 117                name    : "Bootloader",
 118                offset  : FLASH_PARTITION0_ADDR,
 119                size    : FLASH_PARTITION0_SIZE
 120        },
 121        {
 122                name    : "Kernel image",
 123                offset  : FLASH_PARTITION1_ADDR,
 124                size    : FLASH_PARTITION1_SIZE
 125        },
 126        {
 127                name    : "Initial ramdisk image",
 128                offset  : FLASH_PARTITION2_ADDR,
 129                size    : FLASH_PARTITION2_SIZE
 130        },
 131        {       
 132                name    : "Persistant storage",
 133                offset  : FLASH_PARTITION3_ADDR,
 134                size    : FLASH_PARTITION3_SIZE
 135        }
 136};
 137
 138#define PARTITION_COUNT (sizeof(flagadm_parts)/sizeof(struct mtd_partition))
 139
 140static struct mtd_info *mymtd;
 141
 142int __init init_flagadm(void)
 143{       
 144        printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
 145                        FLASH_SIZE, FLASH_PHYS_ADDR);
 146        
 147        flagadm_map.map_priv_1 = (unsigned long)ioremap(FLASH_PHYS_ADDR,
 148                                        FLASH_SIZE);
 149
 150        if (!flagadm_map.map_priv_1) {
 151                printk("Failed to ioremap\n");
 152                return -EIO;
 153        }
 154        mymtd = do_map_probe("cfi_probe", &flagadm_map);
 155        if (mymtd) {
 156                mymtd->module = THIS_MODULE;
 157                add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT);
 158                printk(KERN_NOTICE "FlagaDM flash device initialized\n");
 159                return 0;
 160        }
 161
 162        iounmap((void *)flagadm_map.map_priv_1);
 163        return -ENXIO;
 164}
 165
 166static void __exit cleanup_flagadm(void)
 167{
 168        if (mymtd) {
 169                del_mtd_partitions(mymtd);
 170                map_destroy(mymtd);
 171        }
 172        if (flagadm_map.map_priv_1) {
 173                iounmap((void *)flagadm_map.map_priv_1);
 174                flagadm_map.map_priv_1 = 0;
 175        }
 176}
 177
 178module_init(init_flagadm);
 179module_exit(cleanup_flagadm);
 180
 181
 182MODULE_LICENSE("GPL");
 183MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
 184MODULE_DESCRIPTION("MTD map driver for Flaga digital module");
 185