4 * Map driver for the Mainstone developer platform.
6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc.
9 * 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.
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/map.h>
21 #include <linux/mtd/partitions.h>
23 #include <asm/hardware.h>
24 #include <asm/arch/pxa-regs.h>
25 #include <asm/arch/mainstone.h>
28 #define ROM_ADDR 0x00000000
29 #define FLASH_ADDR 0x04000000
31 #define WINDOW_SIZE 0x04000000
33 static void mainstone_map_inval_cache(struct map_info *map, unsigned long from,
36 consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
39 static struct map_info mainstone_maps[2] = { {
42 .inval_cache = mainstone_map_inval_cache,
46 .inval_cache = mainstone_map_inval_cache,
49 static struct mtd_partition mainstone_partitions[] = {
54 .mask_flags = MTD_WRITEABLE /* force read-only */
61 .size = MTDPART_SIZ_FULL,
66 static struct mtd_info *mymtds[2];
67 static struct mtd_partition *parsed_parts[2];
68 static int nr_parsed_parts[2];
70 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
72 static int __init init_mainstone(void)
74 int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */
77 mainstone_maps[0].bankwidth = (BOOT_DEF & 1) ? 2 : 4;
78 mainstone_maps[1].bankwidth = 4;
80 /* Compensate for SW7 which swaps the flash banks */
81 mainstone_maps[SW7].name = "processor flash";
82 mainstone_maps[SW7 ^ 1].name = "main board flash";
84 printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
85 mainstone_maps[0].name);
87 for (i = 0; i < 2; i++) {
88 mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys,
90 if (!mainstone_maps[i].virt) {
91 printk(KERN_WARNING "Failed to ioremap %s\n",
92 mainstone_maps[i].name);
97 mainstone_maps[i].cached =
98 ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE);
99 if (!mainstone_maps[i].cached)
100 printk(KERN_WARNING "Failed to ioremap cached %s\n",
101 mainstone_maps[i].name);
102 simple_map_init(&mainstone_maps[i]);
105 "Probing %s at physical address 0x%08lx"
106 " (%d-bit bankwidth)\n",
107 mainstone_maps[i].name, mainstone_maps[i].phys,
108 mainstone_maps[i].bankwidth * 8);
110 mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]);
113 iounmap((void *)mainstone_maps[i].virt);
114 if (mainstone_maps[i].cached)
115 iounmap(mainstone_maps[i].cached);
120 mymtds[i]->owner = THIS_MODULE;
122 ret = parse_mtd_partitions(mymtds[i], probes,
123 &parsed_parts[i], 0);
126 nr_parsed_parts[i] = ret;
129 if (!mymtds[0] && !mymtds[1])
132 for (i = 0; i < 2; i++) {
134 printk(KERN_WARNING "%s is absent. Skipping\n",
135 mainstone_maps[i].name);
136 } else if (nr_parsed_parts[i]) {
137 add_mtd_partitions(mymtds[i], parsed_parts[i],
140 printk("Using static partitions on %s\n",
141 mainstone_maps[i].name);
142 add_mtd_partitions(mymtds[i], mainstone_partitions,
143 ARRAY_SIZE(mainstone_partitions));
145 printk("Registering %s as whole device\n",
146 mainstone_maps[i].name);
147 add_mtd_device(mymtds[i]);
153 static void __exit cleanup_mainstone(void)
156 for (i = 0; i < 2; i++) {
160 if (nr_parsed_parts[i] || !i)
161 del_mtd_partitions(mymtds[i]);
163 del_mtd_device(mymtds[i]);
165 map_destroy(mymtds[i]);
166 iounmap((void *)mainstone_maps[i].virt);
167 if (mainstone_maps[i].cached)
168 iounmap(mainstone_maps[i].cached);
169 kfree(parsed_parts[i]);
173 module_init(init_mainstone);
174 module_exit(cleanup_mainstone);
176 MODULE_LICENSE("GPL");
177 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
178 MODULE_DESCRIPTION("MTD map driver for Intel Mainstone");