Linux 4.9.137
[linux/fpc-iii.git] / drivers / mtd / maps / cfi_flagadm.c
blobd504b3d1791da8ef70076d2b936c6afba7cc863c
1 /*
2 * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
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.
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.
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.
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>
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
42 #define FLASH_PHYS_ADDR 0x40000000
43 #define FLASH_SIZE 0x400000
45 #define FLASH_PARTITION0_ADDR 0x00000000
46 #define FLASH_PARTITION0_SIZE 0x00020000
48 #define FLASH_PARTITION1_ADDR 0x00020000
49 #define FLASH_PARTITION1_SIZE 0x000A0000
51 #define FLASH_PARTITION2_ADDR 0x000C0000
52 #define FLASH_PARTITION2_SIZE 0x00180000
54 #define FLASH_PARTITION3_ADDR 0x00240000
55 #define FLASH_PARTITION3_SIZE 0x001C0000
58 static struct map_info flagadm_map = {
59 .name = "FlagaDM flash device",
60 .size = FLASH_SIZE,
61 .bankwidth = 2,
64 static struct mtd_partition flagadm_parts[] = {
66 .name = "Bootloader",
67 .offset = FLASH_PARTITION0_ADDR,
68 .size = FLASH_PARTITION0_SIZE
71 .name = "Kernel image",
72 .offset = FLASH_PARTITION1_ADDR,
73 .size = FLASH_PARTITION1_SIZE
76 .name = "Initial ramdisk image",
77 .offset = FLASH_PARTITION2_ADDR,
78 .size = FLASH_PARTITION2_SIZE
81 .name = "Persistent storage",
82 .offset = FLASH_PARTITION3_ADDR,
83 .size = FLASH_PARTITION3_SIZE
87 #define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
89 static struct mtd_info *mymtd;
91 static int __init init_flagadm(void)
93 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
94 FLASH_SIZE, FLASH_PHYS_ADDR);
96 flagadm_map.phys = FLASH_PHYS_ADDR;
97 flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
98 FLASH_SIZE);
100 if (!flagadm_map.virt) {
101 printk("Failed to ioremap\n");
102 return -EIO;
105 simple_map_init(&flagadm_map);
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;
115 iounmap((void __iomem *)flagadm_map.virt);
116 return -ENXIO;
119 static void __exit cleanup_flagadm(void)
121 if (mymtd) {
122 mtd_device_unregister(mymtd);
123 map_destroy(mymtd);
125 if (flagadm_map.virt) {
126 iounmap((void __iomem *)flagadm_map.virt);
127 flagadm_map.virt = NULL;
131 module_init(init_flagadm);
132 module_exit(cleanup_flagadm);
135 MODULE_LICENSE("GPL");
136 MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
137 MODULE_DESCRIPTION("MTD map driver for Flaga digital module");