blob: 1aa0447c5e66a2430ec9dd42bf5b86fba8549f16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +00002 * $Id: lubbock-flash.c,v 1.21 2005/11/07 11:14:27 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Map driver for the Lubbock developer platform.
5 *
6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc.
Thomas Gleixner69f34c92005-11-07 11:15:40 +00008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080018#include <linux/slab.h>
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/dma-mapping.h>
21#include <linux/mtd/mtd.h>
22#include <linux/mtd/map.h>
23#include <linux/mtd/partitions.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io.h>
26#include <asm/hardware.h>
27#include <asm/arch/pxa-regs.h>
28#include <asm/arch/lubbock.h>
29
30
31#define ROM_ADDR 0x00000000
32#define FLASH_ADDR 0x04000000
33
34#define WINDOW_SIZE 64*1024*1024
35
36static void lubbock_map_inval_cache(struct map_info *map, unsigned long from, ssize_t len)
37{
38 consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
39}
40
41static struct map_info lubbock_maps[2] = { {
42 .size = WINDOW_SIZE,
43 .phys = 0x00000000,
44 .inval_cache = lubbock_map_inval_cache,
45}, {
46 .size = WINDOW_SIZE,
47 .phys = 0x04000000,
48 .inval_cache = lubbock_map_inval_cache,
49} };
50
51static struct mtd_partition lubbock_partitions[] = {
52 {
53 .name = "Bootloader",
54 .size = 0x00040000,
55 .offset = 0,
56 .mask_flags = MTD_WRITEABLE /* force read-only */
57 },{
58 .name = "Kernel",
59 .size = 0x00100000,
60 .offset = 0x00040000,
61 },{
62 .name = "Filesystem",
63 .size = MTDPART_SIZ_FULL,
64 .offset = 0x00140000
65 }
66};
67
68static struct mtd_info *mymtds[2];
69static struct mtd_partition *parsed_parts[2];
70static int nr_parsed_parts[2];
71
72static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
73
74static int __init init_lubbock(void)
75{
76 int flashboot = (LUB_CONF_SWITCHES & 1);
77 int ret = 0, i;
78
Thomas Gleixner69f34c92005-11-07 11:15:40 +000079 lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth =
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 (BOOT_DEF & 1) ? 2 : 4;
81
82 /* Compensate for the nROMBT switch which swaps the flash banks */
83 printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
84 flashboot?"Flash":"ROM", flashboot);
85
86 lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
87 lubbock_maps[flashboot].name = "Lubbock Boot ROM";
88
89 for (i = 0; i < 2; i++) {
90 lubbock_maps[i].virt = ioremap(lubbock_maps[i].phys, WINDOW_SIZE);
91 if (!lubbock_maps[i].virt) {
92 printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
93 if (!ret)
94 ret = -ENOMEM;
95 continue;
96 }
97 lubbock_maps[i].cached = ioremap_cached(lubbock_maps[i].phys, WINDOW_SIZE);
98 if (!lubbock_maps[i].cached)
99 printk(KERN_WARNING "Failed to ioremap cached %s\n", lubbock_maps[i].name);
100 simple_map_init(&lubbock_maps[i]);
101
102 printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n",
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000103 lubbock_maps[i].name, lubbock_maps[i].phys,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 lubbock_maps[i].bankwidth * 8);
105
106 mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (!mymtds[i]) {
109 iounmap((void *)lubbock_maps[i].virt);
110 if (lubbock_maps[i].cached)
111 iounmap(lubbock_maps[i].cached);
112 if (!ret)
113 ret = -EIO;
114 continue;
115 }
116 mymtds[i]->owner = THIS_MODULE;
117
118 ret = parse_mtd_partitions(mymtds[i], probes,
119 &parsed_parts[i], 0);
120
121 if (ret > 0)
122 nr_parsed_parts[i] = ret;
123 }
124
125 if (!mymtds[0] && !mymtds[1])
126 return ret;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 for (i = 0; i < 2; i++) {
129 if (!mymtds[i]) {
130 printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
131 } else if (nr_parsed_parts[i]) {
132 add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
133 } else if (!i) {
134 printk("Using static partitions on %s\n", lubbock_maps[i].name);
135 add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions));
136 } else {
137 printk("Registering %s as whole device\n", lubbock_maps[i].name);
138 add_mtd_device(mymtds[i]);
139 }
140 }
141 return 0;
142}
143
144static void __exit cleanup_lubbock(void)
145{
146 int i;
147 for (i = 0; i < 2; i++) {
148 if (!mymtds[i])
149 continue;
150
151 if (nr_parsed_parts[i] || !i)
152 del_mtd_partitions(mymtds[i]);
153 else
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000154 del_mtd_device(mymtds[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 map_destroy(mymtds[i]);
157 iounmap((void *)lubbock_maps[i].virt);
158 if (lubbock_maps[i].cached)
159 iounmap(lubbock_maps[i].cached);
160
Jesper Juhlfa671642005-11-07 01:01:27 -0800161 kfree(parsed_parts[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163}
164
165module_init(init_lubbock);
166module_exit(cleanup_lubbock);
167
168MODULE_LICENSE("GPL");
169MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
170MODULE_DESCRIPTION("MTD map driver for Intel Lubbock");