2 * Driver for IFXMIPS 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>
26 #include <linux/init.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/map.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/mtd/cfi.h>
31 #include <asm/ifxmips/ifxmips.h>
32 #include <linux/magic.h>
33 #include <linux/platform_device.h>
35 #define DRVNAME "ifxmips_mtd"
37 static struct map_info
45 ifxmips_read16 (struct map_info
* map
, unsigned long adr
)
50 temp
.x
[0] = *((__u16
*) (map
->virt
+ adr
));
56 ifxmips_write16 (struct map_info
*map
, map_word d
, unsigned long adr
)
59 *((__u16
*) (map
->virt
+ adr
)) = d
.x
[0];
63 ifxmips_copy_from (struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
68 from
= (unsigned long) (from
+ map
->virt
);
77 ifxmips_copy_to (struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
82 to
+= (unsigned long) map
->virt
;
89 static struct mtd_partition
90 ifxmips_partitions
[4] = {
114 find_uImage_size (unsigned long start_offset
){
117 ifxmips_copy_from(&ifxmips_map
, &temp
, start_offset
+ 12, 4);
118 printk(KERN_INFO DRVNAME
": kernel size is %ld \n", temp
+ 0x40);
123 detect_squashfs_partition (unsigned long start_offset
){
126 ifxmips_copy_from(&ifxmips_map
, &temp
, start_offset
, 4);
128 return (temp
== SQUASHFS_MAGIC
);
132 ifxmips_mtd_probe (void)
134 struct mtd_info
*ifxmips_mtd
= NULL
;
135 struct mtd_partition
*parts
= NULL
;
136 unsigned long uimage_size
;
138 writel(0x1d7ff, IFXMIPS_EBU_BUSCON0
);
140 ifxmips_map
.read
= ifxmips_read16
;
141 ifxmips_map
.write
= ifxmips_write16
;
142 ifxmips_map
.copy_from
= ifxmips_copy_from
;
143 ifxmips_map
.copy_to
= ifxmips_copy_to
;
145 ifxmips_map
.phys
= IFXMIPS_FLASH_START
;
146 ifxmips_map
.virt
= ioremap_nocache(IFXMIPS_FLASH_START
, IFXMIPS_FLASH_MAX
);
147 ifxmips_map
.size
= IFXMIPS_FLASH_MAX
;
148 if (!ifxmips_map
.virt
) {
149 printk(KERN_WARNING DRVNAME
": failed to ioremap!\n");
153 ifxmips_mtd
= (struct mtd_info
*) do_map_probe("cfi_probe", &ifxmips_map
);
155 iounmap(ifxmips_map
.virt
);
156 printk(KERN_WARNING DRVNAME
": probing failed\n");
160 ifxmips_mtd
->owner
= THIS_MODULE
;
162 uimage_size
= find_uImage_size(ifxmips_partitions
[2].offset
);
164 if(detect_squashfs_partition(ifxmips_partitions
[2].offset
+ uimage_size
)){
165 printk(KERN_INFO DRVNAME
": found a squashfs following the uImage\n");
167 uimage_size
&= ~0xffff;
168 uimage_size
+= 0x10000;
171 ifxmips_partitions
[2].size
= uimage_size
;
172 ifxmips_partitions
[3].offset
= ifxmips_partitions
[2].offset
+ ifxmips_partitions
[2].size
;
173 ifxmips_partitions
[3].size
= ((ifxmips_mtd
->size
>> 20) * 1024 * 1024) - ifxmips_partitions
[3].offset
;
175 parts
= &ifxmips_partitions
[0];
176 add_mtd_partitions(ifxmips_mtd
, parts
, 4);
178 printk(KERN_INFO DRVNAME
": added ifxmips flash with %dMB\n", ifxmips_mtd
->size
>> 20);
183 platform_driver ifxmips_mtd_driver
= {
184 .probe
= ifxmips_mtd_probe
,
187 .owner
= THIS_MODULE
,
192 init_ifxmips_mtd (void)
194 int ret
= platform_driver_register(&ifxmips_mtd_driver
);
196 printk(KERN_INFO DRVNAME
": error registering platfom driver!");
203 cleanup_ifxmips_mtd (void)
205 platform_driver_unregister(&ifxmips_mtd_driver
);
208 module_init (init_ifxmips_mtd
);
209 module_exit (cleanup_ifxmips_mtd
);
211 MODULE_LICENSE ("GPL");
212 MODULE_AUTHOR ("John Crispin <blogic@openwrt.org>");
213 MODULE_DESCRIPTION ("MTD map driver for IFXMIPS boards");