1 Index: linux-2.6.30.8/drivers/mtd/maps/Makefile
2 ===================================================================
3 --- linux-2.6.30.8.orig/drivers/mtd/maps/Makefile 2009-09-24 17:28:02.000000000 +0200
4 +++ linux-2.6.30.8/drivers/mtd/maps/Makefile 2009-10-19 21:31:32.000000000 +0200
6 obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o
7 obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o
8 obj-$(CONFIG_MTD_VMU) += vmu-flash.o
9 +obj-$(CONFIG_MTD_IFXMIPS) += ifxmips.o
10 Index: linux-2.6.30.8/drivers/mtd/maps/ifxmips.c
11 ===================================================================
12 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13 +++ linux-2.6.30.8/drivers/mtd/maps/ifxmips.c 2009-10-19 21:40:44.000000000 +0200
16 + * This program is free software; you can redistribute it and/or modify
17 + * it under the terms of the GNU General Public License as published by
18 + * the Free Software Foundation; either version 2 of the License, or
19 + * (at your option) any later version.
21 + * This program is distributed in the hope that it will be useful,
22 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 + * GNU General Public License for more details.
26 + * You should have received a copy of the GNU General Public License
27 + * along with this program; if not, write to the Free Software
28 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 + * Copyright (C) 2004 Liu Peng Infineon IFAP DC COM CPE
31 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
34 +#include <linux/module.h>
35 +#include <linux/types.h>
36 +#include <linux/kernel.h>
37 +#include <linux/io.h>
38 +#include <linux/init.h>
39 +#include <linux/mtd/mtd.h>
40 +#include <linux/mtd/map.h>
41 +#include <linux/mtd/partitions.h>
42 +#include <linux/mtd/cfi.h>
43 +#include <linux/magic.h>
44 +#include <linux/platform_device.h>
47 +#include <ifxmips_prom.h>
48 +#include <ifxmips_ebu.h>
50 +#ifndef CONFIG_MTD_PARTITIONS
51 +#error Please enable CONFIG_MTD_PARTITIONS
54 +static struct map_info ifxmips_map = {
60 +static map_word ifxmips_read16(struct map_info *map, unsigned long adr)
62 + unsigned long flags;
64 + spin_lock_irqsave(&ebu_lock, flags);
66 + temp.x[0] = *((__u16 *)(map->virt + adr));
67 + spin_unlock_irqrestore(&ebu_lock, flags);
71 +static void ifxmips_write16(struct map_info *map, map_word d, unsigned long adr)
73 + unsigned long flags;
74 + spin_lock_irqsave(&ebu_lock, flags);
76 + *((__u16 *)(map->virt + adr)) = d.x[0];
77 + spin_unlock_irqrestore(&ebu_lock, flags);
80 +void ifxmips_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
83 + unsigned char *to_8;
84 + unsigned long flags;
85 + spin_lock_irqsave(&ebu_lock, flags);
86 + from = (unsigned long)(from + map->virt);
87 + p = (unsigned char *) from;
88 + to_8 = (unsigned char *) to;
91 + spin_unlock_irqrestore(&ebu_lock, flags);
94 +void ifxmips_copy_to(struct map_info *map,
99 + unsigned char *p = (unsigned char *)from;
100 + unsigned char *to_8;
101 + unsigned long flags;
102 + spin_lock_irqsave(&ebu_lock, flags);
103 + to += (unsigned long) map->virt;
104 + to_8 = (unsigned char *)to;
107 + spin_unlock_irqrestore(&ebu_lock, flags);
110 +static struct mtd_partition ifxmips_partitions[] = {
113 + .offset = 0x00000000,
114 + .size = 0x00020000,
117 + .name = "uboot_env",
118 + .offset = 0x00020000,
119 + .size = 0x00010000,
123 + .offset = 0x00030000,
132 + .name = "board_config",
138 +static struct mtd_partition ifxmips_meta_partition = {
140 + .offset = 0x00030000,
144 +static const char *part_probe_types[] = { "cmdlinepart", NULL };
146 +int find_uImage_size(unsigned long start_offset)
148 + unsigned long magic;
149 + unsigned long temp;
150 + ifxmips_copy_from(&ifxmips_map, &magic, start_offset, 4);
151 + if (le32_to_cpu(magic) != 0x56190527) {
152 + printk(KERN_INFO "ifxmips_mtd: invalid magic (0x%08X) of kernel at 0x%08lx \n", le32_to_cpu(magic), start_offset);
155 + ifxmips_copy_from(&ifxmips_map, &temp, start_offset + 12, 4);
156 + printk(KERN_INFO "ifxmips_mtd: kernel size is %ld \n", temp + 0x40);
157 + return temp + 0x40;
160 +int find_brn_block(unsigned long start_offset)
162 + unsigned char temp[9];
163 + ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 8);
165 + printk(KERN_INFO "data in brn block %s\n", temp);
166 + if (memcmp(temp, "BRN-BOOT", 8) == 0)
172 +int detect_squashfs_partition(unsigned long start_offset)
174 + unsigned long temp;
175 + ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 4);
176 + return le32_to_cpu(temp) == SQUASHFS_MAGIC;
179 +static int ifxmips_mtd_probe(struct platform_device *dev)
181 + struct mtd_info *ifxmips_mtd = NULL;
182 + struct mtd_partition *parts = NULL;
183 + unsigned long uimage_size;
185 + int kernel_part = 2, rootfs_part = 3;
186 + int num_parts = ARRAY_SIZE(ifxmips_partitions);
188 + ifxmips_w32(0x1d7ff, IFXMIPS_EBU_BUSCON0);
190 + ifxmips_map.read = ifxmips_read16;
191 + ifxmips_map.write = ifxmips_write16;
192 + ifxmips_map.copy_from = ifxmips_copy_from;
193 + ifxmips_map.copy_to = ifxmips_copy_to;
194 + ifxmips_map.phys = dev->resource->start;
195 + ifxmips_map.size = dev->resource->end - ifxmips_map.phys + 1;
196 + ifxmips_map.virt = ioremap_nocache(ifxmips_map.phys, ifxmips_map.size);
198 + if (!ifxmips_map.virt) {
199 + printk(KERN_WARNING "ifxmips_mtd: failed to ioremap!\n");
203 + ifxmips_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &ifxmips_map);
204 + if (!ifxmips_mtd) {
205 + iounmap(ifxmips_map.virt);
206 + printk(KERN_WARNING "ifxmips_mtd: probing failed\n");
210 + ifxmips_mtd->owner = THIS_MODULE;
212 + err = parse_mtd_partitions(ifxmips_mtd, part_probe_types, &parts, 0);
214 + printk(KERN_INFO "ifxmips_mtd: found %d partitions from cmdline\n", err);
218 + for (i = 0; i < num_parts; i++) {
219 + if (strcmp(parts[i].name, "kernel") == 0)
221 + if (strcmp(parts[i].name, "rootfs") == 0)
225 + parts = &ifxmips_partitions[0];
228 + /* dynamic size detection only if rootfs-part follows kernel-part */
229 + if (kernel_part+1 == rootfs_part) {
230 + uimage_size = find_uImage_size(parts[kernel_part].offset);
232 + if (detect_squashfs_partition(parts[kernel_part].offset + uimage_size)) {
233 + printk(KERN_INFO "ifxmips_mtd: found a squashfs following the uImage\n");
235 + uimage_size &= ~0xffff;
236 + uimage_size += 0x10000;
239 + parts[kernel_part].size = uimage_size;
240 + parts[rootfs_part].offset = parts[kernel_part].offset + parts[kernel_part].size;
241 + parts[rootfs_part].size = ((ifxmips_mtd->size >> 20) * 1024 * 1024) - parts[rootfs_part].offset;
243 + ifxmips_meta_partition.offset = parts[kernel_part].offset;
244 + ifxmips_meta_partition.size = parts[kernel_part].size + parts[rootfs_part].size;
248 + if (ifxmips_has_brn_block()) {
249 + parts[3].size -= ifxmips_mtd->erasesize;
250 + parts[4].offset = ifxmips_mtd->size - ifxmips_mtd->erasesize;
251 + parts[4].size = ifxmips_mtd->erasesize;
257 + add_mtd_partitions(ifxmips_mtd, parts, num_parts);
258 + add_mtd_partitions(ifxmips_mtd, &ifxmips_meta_partition, 1);
260 + printk(KERN_INFO "ifxmips_mtd: added %s flash with %dMB\n",
261 + ifxmips_map.name, ((int)ifxmips_mtd->size) >> 20);
265 +static struct platform_driver ifxmips_mtd_driver = {
266 + .probe = ifxmips_mtd_probe,
268 + .name = "ifxmips_mtd",
269 + .owner = THIS_MODULE,
273 +int __init init_ifxmips_mtd(void)
275 + int ret = platform_driver_register(&ifxmips_mtd_driver);
277 + printk(KERN_INFO "ifxmips_mtd: error registering platfom driver!");
281 +static void __exit cleanup_ifxmips_mtd(void)
283 + platform_driver_unregister(&ifxmips_mtd_driver);
286 +module_init(init_ifxmips_mtd);
287 +module_exit(cleanup_ifxmips_mtd);
289 +MODULE_LICENSE("GPL");
290 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
291 +MODULE_DESCRIPTION("MTD map driver for IFXMIPS boards");