11da177e4SLinus Torvalds /* 2151e7659SDavid Woodhouse * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is> 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 51da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 61da177e4SLinus Torvalds * Free Software Foundation; either version 2 of the License, or (at your 71da177e4SLinus Torvalds * option) any later version. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 101da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 111da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 121da177e4SLinus Torvalds * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 131da177e4SLinus Torvalds * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 141da177e4SLinus Torvalds * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 151da177e4SLinus Torvalds * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 161da177e4SLinus Torvalds * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 171da177e4SLinus Torvalds * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 181da177e4SLinus Torvalds * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License along 211da177e4SLinus Torvalds * with this program; if not, write to the Free Software Foundation, Inc., 221da177e4SLinus Torvalds * 675 Mass Ave, Cambridge, MA 02139, USA. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <linux/module.h> 261da177e4SLinus Torvalds #include <linux/types.h> 271da177e4SLinus Torvalds #include <linux/kernel.h> 281da177e4SLinus Torvalds #include <linux/init.h> 291da177e4SLinus Torvalds #include <asm/io.h> 301da177e4SLinus Torvalds #include <linux/mtd/mtd.h> 311da177e4SLinus Torvalds #include <linux/mtd/map.h> 321da177e4SLinus Torvalds #include <linux/mtd/partitions.h> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /* We split the flash chip up into four parts. 361da177e4SLinus Torvalds * 1: bootloader firts 128k (0x00000000 - 0x0001FFFF) size 0x020000 371da177e4SLinus Torvalds * 2: kernel 640k (0x00020000 - 0x000BFFFF) size 0x0A0000 381da177e4SLinus Torvalds * 3: compressed 1536k root ramdisk (0x000C0000 - 0x0023FFFF) size 0x180000 391da177e4SLinus Torvalds * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000 401da177e4SLinus Torvalds */ 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define FLASH_PHYS_ADDR 0x40000000 431da177e4SLinus Torvalds #define FLASH_SIZE 0x400000 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #define FLASH_PARTITION0_ADDR 0x00000000 461da177e4SLinus Torvalds #define FLASH_PARTITION0_SIZE 0x00020000 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #define FLASH_PARTITION1_ADDR 0x00020000 491da177e4SLinus Torvalds #define FLASH_PARTITION1_SIZE 0x000A0000 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #define FLASH_PARTITION2_ADDR 0x000C0000 521da177e4SLinus Torvalds #define FLASH_PARTITION2_SIZE 0x00180000 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds #define FLASH_PARTITION3_ADDR 0x00240000 551da177e4SLinus Torvalds #define FLASH_PARTITION3_SIZE 0x001C0000 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds struct map_info flagadm_map = { 591da177e4SLinus Torvalds .name = "FlagaDM flash device", 601da177e4SLinus Torvalds .size = FLASH_SIZE, 611da177e4SLinus Torvalds .bankwidth = 2, 621da177e4SLinus Torvalds }; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds struct mtd_partition flagadm_parts[] = { 651da177e4SLinus Torvalds { 661da177e4SLinus Torvalds .name = "Bootloader", 671da177e4SLinus Torvalds .offset = FLASH_PARTITION0_ADDR, 681da177e4SLinus Torvalds .size = FLASH_PARTITION0_SIZE 691da177e4SLinus Torvalds }, 701da177e4SLinus Torvalds { 711da177e4SLinus Torvalds .name = "Kernel image", 721da177e4SLinus Torvalds .offset = FLASH_PARTITION1_ADDR, 731da177e4SLinus Torvalds .size = FLASH_PARTITION1_SIZE 741da177e4SLinus Torvalds }, 751da177e4SLinus Torvalds { 761da177e4SLinus Torvalds .name = "Initial ramdisk image", 771da177e4SLinus Torvalds .offset = FLASH_PARTITION2_ADDR, 781da177e4SLinus Torvalds .size = FLASH_PARTITION2_SIZE 791da177e4SLinus Torvalds }, 801da177e4SLinus Torvalds { 8103a67a46SJan Engelhardt .name = "Persistent storage", 821da177e4SLinus Torvalds .offset = FLASH_PARTITION3_ADDR, 831da177e4SLinus Torvalds .size = FLASH_PARTITION3_SIZE 841da177e4SLinus Torvalds } 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 8787d10f3cSTobias Klauser #define PARTITION_COUNT ARRAY_SIZE(flagadm_parts) 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds static struct mtd_info *mymtd; 901da177e4SLinus Torvalds 912e257a2dSDmitri Vorobiev static int __init init_flagadm(void) 921da177e4SLinus Torvalds { 931da177e4SLinus Torvalds printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n", 941da177e4SLinus Torvalds FLASH_SIZE, FLASH_PHYS_ADDR); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds flagadm_map.phys = FLASH_PHYS_ADDR; 971da177e4SLinus Torvalds flagadm_map.virt = ioremap(FLASH_PHYS_ADDR, 981da177e4SLinus Torvalds FLASH_SIZE); 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds if (!flagadm_map.virt) { 1011da177e4SLinus Torvalds printk("Failed to ioremap\n"); 1021da177e4SLinus Torvalds return -EIO; 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds simple_map_init(&flagadm_map); 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds mymtd = do_map_probe("cfi_probe", &flagadm_map); 1081da177e4SLinus Torvalds if (mymtd) { 1091da177e4SLinus Torvalds mymtd->owner = THIS_MODULE; 1101da177e4SLinus Torvalds add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT); 1111da177e4SLinus Torvalds printk(KERN_NOTICE "FlagaDM flash device initialized\n"); 1121da177e4SLinus Torvalds return 0; 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds iounmap((void *)flagadm_map.virt); 1161da177e4SLinus Torvalds return -ENXIO; 1171da177e4SLinus Torvalds } 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds static void __exit cleanup_flagadm(void) 1201da177e4SLinus Torvalds { 1211da177e4SLinus Torvalds if (mymtd) { 1221da177e4SLinus Torvalds del_mtd_partitions(mymtd); 1231da177e4SLinus Torvalds map_destroy(mymtd); 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds if (flagadm_map.virt) { 1261da177e4SLinus Torvalds iounmap((void *)flagadm_map.virt); 1271da177e4SLinus Torvalds flagadm_map.virt = 0; 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds module_init(init_flagadm); 1321da177e4SLinus Torvalds module_exit(cleanup_flagadm); 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 136151e7659SDavid Woodhouse MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>"); 1371da177e4SLinus Torvalds MODULE_DESCRIPTION("MTD map driver for Flaga digital module"); 138