cfi_flagadm.c (3990B)
1/* 2 * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is> 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License as published by the 6 * Free Software Foundation; either version 2 of the License, or (at your 7 * option) any later version. 8 * 9 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 10 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 12 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 13 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 14 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 15 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 16 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 17 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 18 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 * 20 * You should have received a copy of the GNU General Public License along 21 * with this program; if not, write to the Free Software Foundation, Inc., 22 * 675 Mass Ave, Cambridge, MA 02139, USA. 23 */ 24 25#include <linux/module.h> 26#include <linux/types.h> 27#include <linux/kernel.h> 28#include <linux/init.h> 29#include <asm/io.h> 30#include <linux/mtd/mtd.h> 31#include <linux/mtd/map.h> 32#include <linux/mtd/partitions.h> 33 34 35/* We split the flash chip up into four parts. 36 * 1: bootloader first 128k (0x00000000 - 0x0001FFFF) size 0x020000 37 * 2: kernel 640k (0x00020000 - 0x000BFFFF) size 0x0A0000 38 * 3: compressed 1536k root ramdisk (0x000C0000 - 0x0023FFFF) size 0x180000 39 * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000 40 */ 41 42#define FLASH_PHYS_ADDR 0x40000000 43#define FLASH_SIZE 0x400000 44 45#define FLASH_PARTITION0_ADDR 0x00000000 46#define FLASH_PARTITION0_SIZE 0x00020000 47 48#define FLASH_PARTITION1_ADDR 0x00020000 49#define FLASH_PARTITION1_SIZE 0x000A0000 50 51#define FLASH_PARTITION2_ADDR 0x000C0000 52#define FLASH_PARTITION2_SIZE 0x00180000 53 54#define FLASH_PARTITION3_ADDR 0x00240000 55#define FLASH_PARTITION3_SIZE 0x001C0000 56 57 58static struct map_info flagadm_map = { 59 .name = "FlagaDM flash device", 60 .size = FLASH_SIZE, 61 .bankwidth = 2, 62}; 63 64static const struct mtd_partition flagadm_parts[] = { 65 { 66 .name = "Bootloader", 67 .offset = FLASH_PARTITION0_ADDR, 68 .size = FLASH_PARTITION0_SIZE 69 }, 70 { 71 .name = "Kernel image", 72 .offset = FLASH_PARTITION1_ADDR, 73 .size = FLASH_PARTITION1_SIZE 74 }, 75 { 76 .name = "Initial ramdisk image", 77 .offset = FLASH_PARTITION2_ADDR, 78 .size = FLASH_PARTITION2_SIZE 79 }, 80 { 81 .name = "Persistent storage", 82 .offset = FLASH_PARTITION3_ADDR, 83 .size = FLASH_PARTITION3_SIZE 84 } 85}; 86 87#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts) 88 89static struct mtd_info *mymtd; 90 91static int __init init_flagadm(void) 92{ 93 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n", 94 FLASH_SIZE, FLASH_PHYS_ADDR); 95 96 flagadm_map.phys = FLASH_PHYS_ADDR; 97 flagadm_map.virt = ioremap(FLASH_PHYS_ADDR, 98 FLASH_SIZE); 99 100 if (!flagadm_map.virt) { 101 printk("Failed to ioremap\n"); 102 return -EIO; 103 } 104 105 simple_map_init(&flagadm_map); 106 107 mymtd = do_map_probe("cfi_probe", &flagadm_map); 108 if (mymtd) { 109 mymtd->owner = THIS_MODULE; 110 mtd_device_register(mymtd, flagadm_parts, PARTITION_COUNT); 111 printk(KERN_NOTICE "FlagaDM flash device initialized\n"); 112 return 0; 113 } 114 115 iounmap((void __iomem *)flagadm_map.virt); 116 return -ENXIO; 117} 118 119static void __exit cleanup_flagadm(void) 120{ 121 if (mymtd) { 122 mtd_device_unregister(mymtd); 123 map_destroy(mymtd); 124 } 125 if (flagadm_map.virt) { 126 iounmap((void __iomem *)flagadm_map.virt); 127 flagadm_map.virt = NULL; 128 } 129} 130 131module_init(init_flagadm); 132module_exit(cleanup_flagadm); 133 134 135MODULE_LICENSE("GPL"); 136MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>"); 137MODULE_DESCRIPTION("MTD map driver for Flaga digital module");