blob: b4ed8161191846e95a65fd973ff20f4c3b5b4aa6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
David Woodhouse151e7652006-05-14 01:51:54 +01002 * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 firts 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
Thomas Gleixner69f34c92005-11-07 11:15:40 +000043#define FLASH_SIZE 0x400000
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
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
58struct map_info flagadm_map = {
59 .name = "FlagaDM flash device",
60 .size = FLASH_SIZE,
61 .bankwidth = 2,
62};
63
64struct 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 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000080 {
Jan Engelhardt03a67a42006-11-30 05:32:19 +010081 .name = "Persistent storage",
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .offset = FLASH_PARTITION3_ADDR,
83 .size = FLASH_PARTITION3_SIZE
84 }
85};
86
Tobias Klauser87d10f32006-03-31 02:29:45 -080087#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89static struct mtd_info *mymtd;
90
Dmitri Vorobiev2e257a2d2008-11-25 02:54:54 +020091static int __init init_flagadm(void)
Thomas Gleixner69f34c92005-11-07 11:15:40 +000092{
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
94 FLASH_SIZE, FLASH_PHYS_ADDR);
Thomas Gleixner69f34c92005-11-07 11:15:40 +000095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 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 add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT);
111 printk(KERN_NOTICE "FlagaDM flash device initialized\n");
112 return 0;
113 }
114
115 iounmap((void *)flagadm_map.virt);
116 return -ENXIO;
117}
118
119static void __exit cleanup_flagadm(void)
120{
121 if (mymtd) {
122 del_mtd_partitions(mymtd);
123 map_destroy(mymtd);
124 }
125 if (flagadm_map.virt) {
126 iounmap((void *)flagadm_map.virt);
127 flagadm_map.virt = 0;
128 }
129}
130
131module_init(init_flagadm);
132module_exit(cleanup_flagadm);
133
134
135MODULE_LICENSE("GPL");
David Woodhouse151e7652006-05-14 01:51:54 +0100136MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137MODULE_DESCRIPTION("MTD map driver for Flaga digital module");