blob: 92b5d883d7b0e4f8b4ad978a6fac2a9c44c2bfc4 [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 *
Thomas Gleixner69f34c92005-11-07 11:15:40 +00004 * $Id: cfi_flagadm.c,v 1.15 2005/11/07 11:14:26 gleixner Exp $
5 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * 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 <linux/init.h>
31#include <asm/io.h>
32#include <linux/mtd/mtd.h>
33#include <linux/mtd/map.h>
34#include <linux/mtd/partitions.h>
35
36
37/* We split the flash chip up into four parts.
38 * 1: bootloader firts 128k (0x00000000 - 0x0001FFFF) size 0x020000
39 * 2: kernel 640k (0x00020000 - 0x000BFFFF) size 0x0A0000
40 * 3: compressed 1536k root ramdisk (0x000C0000 - 0x0023FFFF) size 0x180000
41 * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000
42 */
43
44#define FLASH_PHYS_ADDR 0x40000000
Thomas Gleixner69f34c92005-11-07 11:15:40 +000045#define FLASH_SIZE 0x400000
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#define FLASH_PARTITION0_ADDR 0x00000000
48#define FLASH_PARTITION0_SIZE 0x00020000
49
50#define FLASH_PARTITION1_ADDR 0x00020000
51#define FLASH_PARTITION1_SIZE 0x000A0000
52
53#define FLASH_PARTITION2_ADDR 0x000C0000
54#define FLASH_PARTITION2_SIZE 0x00180000
55
56#define FLASH_PARTITION3_ADDR 0x00240000
57#define FLASH_PARTITION3_SIZE 0x001C0000
58
59
60struct map_info flagadm_map = {
61 .name = "FlagaDM flash device",
62 .size = FLASH_SIZE,
63 .bankwidth = 2,
64};
65
66struct mtd_partition flagadm_parts[] = {
67 {
68 .name = "Bootloader",
69 .offset = FLASH_PARTITION0_ADDR,
70 .size = FLASH_PARTITION0_SIZE
71 },
72 {
73 .name = "Kernel image",
74 .offset = FLASH_PARTITION1_ADDR,
75 .size = FLASH_PARTITION1_SIZE
76 },
77 {
78 .name = "Initial ramdisk image",
79 .offset = FLASH_PARTITION2_ADDR,
80 .size = FLASH_PARTITION2_SIZE
81 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .name = "Persistant storage",
84 .offset = FLASH_PARTITION3_ADDR,
85 .size = FLASH_PARTITION3_SIZE
86 }
87};
88
Tobias Klauser87d10f32006-03-31 02:29:45 -080089#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91static struct mtd_info *mymtd;
92
93int __init init_flagadm(void)
Thomas Gleixner69f34c92005-11-07 11:15:40 +000094{
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
96 FLASH_SIZE, FLASH_PHYS_ADDR);
Thomas Gleixner69f34c92005-11-07 11:15:40 +000097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 flagadm_map.phys = FLASH_PHYS_ADDR;
99 flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
100 FLASH_SIZE);
101
102 if (!flagadm_map.virt) {
103 printk("Failed to ioremap\n");
104 return -EIO;
105 }
106
107 simple_map_init(&flagadm_map);
108
109 mymtd = do_map_probe("cfi_probe", &flagadm_map);
110 if (mymtd) {
111 mymtd->owner = THIS_MODULE;
112 add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT);
113 printk(KERN_NOTICE "FlagaDM flash device initialized\n");
114 return 0;
115 }
116
117 iounmap((void *)flagadm_map.virt);
118 return -ENXIO;
119}
120
121static void __exit cleanup_flagadm(void)
122{
123 if (mymtd) {
124 del_mtd_partitions(mymtd);
125 map_destroy(mymtd);
126 }
127 if (flagadm_map.virt) {
128 iounmap((void *)flagadm_map.virt);
129 flagadm_map.virt = 0;
130 }
131}
132
133module_init(init_flagadm);
134module_exit(cleanup_flagadm);
135
136
137MODULE_LICENSE("GPL");
David Woodhouse151e7652006-05-14 01:51:54 +0100138MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139MODULE_DESCRIPTION("MTD map driver for Flaga digital module");