2 * Driver for DANUBE flashmap
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Copyright (C) 2004 Liu Peng Infineon IFAP DC COM CPE
19 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/map.h>
30 #include <linux/mtd/partitions.h>
31 #include <linux/mtd/cfi.h>
32 #include <asm/danube/danube.h>
33 #include <linux/magic.h>
35 static struct map_info
37 .name = "DANUBE_FLASH",
43 danube_read16 (struct map_info * map, unsigned long adr)
48 temp.x[0] = *((__u16 *) (map->virt + adr));
54 danube_write16 (struct map_info *map, map_word d, unsigned long adr)
57 *((__u16 *) (map->virt + adr)) = d.x[0];
61 danube_copy_from (struct map_info *map, void *to, unsigned long from, ssize_t len)
66 from = (unsigned long) (from + map->virt);
75 danube_copy_to (struct map_info *map, unsigned long to, const void *from, ssize_t len)
80 to += (unsigned long) map->virt;
87 static struct mtd_partition
88 danube_partitions[4] = {
111 #define DANUBE_FLASH_START 0x10000000
112 #define DANUBE_FLASH_MAX 0x2000000
115 find_uImage_size (unsigned long start_offset){
118 danube_copy_from(&danube_map, &temp, start_offset + 12, 4);
119 printk("kernel size is %ld \n", temp + 0x40);
124 detect_squashfs_partition (unsigned long start_offset){
127 danube_copy_from(&danube_map, &temp, start_offset, 4);
129 return (temp == SQUASHFS_MAGIC);
133 init_danube_mtd (void)
135 struct mtd_info *danube_mtd = NULL;
136 struct mtd_partition *parts = NULL;
137 unsigned long uimage_size;
139 writel(0x1d7ff, DANUBE_EBU_BUSCON0);
141 danube_map.read = danube_read16;
142 danube_map.write = danube_write16;
143 danube_map.copy_from = danube_copy_from;
144 danube_map.copy_to = danube_copy_to;
146 danube_map.phys = DANUBE_FLASH_START;
147 danube_map.virt = ioremap_nocache(DANUBE_FLASH_START, DANUBE_FLASH_MAX);
148 danube_map.size = DANUBE_FLASH_MAX;
149 if (!danube_map.virt) {
150 printk(KERN_WARNING "Failed to ioremap!\n");
154 danube_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &danube_map);
156 iounmap(danube_map.virt);
157 printk("probing failed\n");
161 danube_mtd->owner = THIS_MODULE;
163 uimage_size = find_uImage_size(danube_partitions[2].offset);
165 if(detect_squashfs_partition(danube_partitions[2].offset + uimage_size)){
166 printk("Found a squashfs following the uImage\n");
168 uimage_size &= ~0xffff;
169 uimage_size += 0x10000;
172 danube_partitions[2].size = uimage_size;
173 danube_partitions[3].offset = danube_partitions[2].offset + danube_partitions[2].size;
174 danube_partitions[3].size = ((danube_mtd->size >> 20) * 1024 * 1024) - danube_partitions[3].offset;
176 parts = &danube_partitions[0];
177 add_mtd_partitions(danube_mtd, parts, 4);
179 printk("Added danube flash with %dMB\n", danube_mtd->size >> 20);
185 cleanup_danube_mtd (void)
189 module_init (init_danube_mtd);
190 module_exit (cleanup_danube_mtd);
192 MODULE_LICENSE ("GPL");
193 MODULE_AUTHOR ("John Crispin <blogic@openwrt.org>");
194 MODULE_DESCRIPTION ("MTD map driver for DANUBE boards");