2007-12-21 00:29:45 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Liu Peng Infineon IFAP DC COM CPE
|
2008-06-23 23:31:34 +03:00
|
|
|
* Copyright (C) 2008 John Crispin <blogic@openwrt.org>
|
2007-12-21 00:29:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/map.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
|
|
|
#include <linux/mtd/cfi.h>
|
2007-12-22 16:27:29 +02:00
|
|
|
#include <asm/ifxmips/ifxmips.h>
|
2008-07-06 02:06:07 +03:00
|
|
|
#include <asm/ifxmips/ifxmips_prom.h>
|
2008-06-28 20:28:31 +03:00
|
|
|
#include <asm/ifxmips/ifxmips_ebu.h>
|
2007-12-21 00:29:45 +02:00
|
|
|
#include <linux/magic.h>
|
2007-12-25 15:26:41 +02:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2007-12-21 00:29:45 +02:00
|
|
|
static struct map_info
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_map = {
|
2008-06-23 23:31:34 +03:00
|
|
|
.name = "ifxmips_mtd",
|
2007-12-21 00:29:45 +02:00
|
|
|
.bankwidth = 2,
|
|
|
|
.size = 0x400000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static map_word
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_read16(struct map_info * map, unsigned long adr)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-06-28 20:28:31 +03:00
|
|
|
unsigned long flags;
|
2007-12-21 00:29:45 +02:00
|
|
|
map_word temp;
|
2008-06-28 20:28:31 +03:00
|
|
|
spin_lock_irqsave(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
adr ^= 2;
|
2008-06-29 03:42:45 +03:00
|
|
|
temp.x[0] = *((__u16*)(map->virt + adr));
|
2008-06-28 20:28:31 +03:00
|
|
|
spin_unlock_irqrestore(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_write16(struct map_info *map, map_word d, unsigned long adr)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-06-28 20:28:31 +03:00
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
adr ^= 2;
|
2008-06-29 03:42:45 +03:00
|
|
|
*((__u16*)(map->virt + adr)) = d.x[0];
|
2008-06-28 20:28:31 +03:00
|
|
|
spin_unlock_irqrestore(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-06-23 23:31:34 +03:00
|
|
|
unsigned char *p;
|
|
|
|
unsigned char *to_8;
|
2008-06-28 20:28:31 +03:00
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&ebu_lock, flags);
|
2008-06-23 23:31:34 +03:00
|
|
|
from = (unsigned long)(from + map->virt);
|
|
|
|
p = (unsigned char*) from;
|
|
|
|
to_8 = (unsigned char*) to;
|
|
|
|
while(len--)
|
2007-12-21 00:29:45 +02:00
|
|
|
*to_8++ = *p++;
|
2008-06-29 03:42:45 +03:00
|
|
|
spin_unlock_irqrestore(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-06-23 23:31:34 +03:00
|
|
|
unsigned char *p = (unsigned char*)from;
|
|
|
|
unsigned char *to_8;
|
2008-06-28 20:28:31 +03:00
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
to += (unsigned long) map->virt;
|
2008-06-23 23:31:34 +03:00
|
|
|
to_8 = (unsigned char*)to;
|
2008-06-29 03:42:45 +03:00
|
|
|
while(len--)
|
2007-12-21 00:29:45 +02:00
|
|
|
*p++ = *to_8++;
|
2008-06-28 20:28:31 +03:00
|
|
|
spin_unlock_irqrestore(&ebu_lock, flags);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mtd_partition
|
2008-07-06 02:06:07 +03:00
|
|
|
ifxmips_partitions[] = {
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2008-07-06 02:06:07 +03:00
|
|
|
name:"uboot",
|
2007-12-21 00:29:45 +02:00
|
|
|
offset:0x00000000,
|
|
|
|
size:0x00020000,
|
|
|
|
},
|
|
|
|
{
|
2008-07-06 02:06:07 +03:00
|
|
|
name:"uboot_env",
|
2007-12-21 00:29:45 +02:00
|
|
|
offset:0x00020000,
|
|
|
|
size:0x00010000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name:"kernel",
|
|
|
|
offset:0x00030000,
|
|
|
|
size:0x0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name:"rootfs",
|
|
|
|
offset:0x0,
|
|
|
|
size:0x0,
|
|
|
|
},
|
2008-07-06 02:06:07 +03:00
|
|
|
{
|
|
|
|
name:"board_config",
|
|
|
|
offset:0x0,
|
|
|
|
size:0x0,
|
|
|
|
},
|
2007-12-21 00:29:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2008-06-23 23:31:34 +03:00
|
|
|
find_uImage_size(unsigned long start_offset){
|
2007-12-21 00:29:45 +02:00
|
|
|
unsigned long temp;
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_copy_from(&ifxmips_map, &temp, start_offset + 12, 4);
|
2008-06-23 23:31:34 +03:00
|
|
|
printk(KERN_INFO "ifxmips_mtd: kernel size is %ld \n", temp + 0x40);
|
2007-12-21 00:29:45 +02:00
|
|
|
return temp + 0x40;
|
|
|
|
}
|
|
|
|
|
2008-07-06 02:06:07 +03:00
|
|
|
int
|
|
|
|
find_brn_block(unsigned long start_offset){
|
|
|
|
unsigned char temp[9];
|
|
|
|
ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 8);
|
|
|
|
temp[8] = '\0';
|
|
|
|
printk(KERN_INFO "data in brn block %s\n", temp);
|
|
|
|
if(memcmp(temp, "BRN-BOOT", 8) == 0)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-21 00:29:45 +02:00
|
|
|
int
|
2008-06-23 23:31:34 +03:00
|
|
|
detect_squashfs_partition(unsigned long start_offset){
|
2007-12-21 00:29:45 +02:00
|
|
|
unsigned long temp;
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 4);
|
2007-12-21 00:29:45 +02:00
|
|
|
return (temp == SQUASHFS_MAGIC);
|
|
|
|
}
|
|
|
|
|
2007-12-25 15:26:41 +02:00
|
|
|
static int
|
2008-06-23 23:31:34 +03:00
|
|
|
ifxmips_mtd_probe(struct platform_device *dev)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2007-12-25 15:26:41 +02:00
|
|
|
struct mtd_info *ifxmips_mtd = NULL;
|
2007-12-21 00:29:45 +02:00
|
|
|
struct mtd_partition *parts = NULL;
|
|
|
|
unsigned long uimage_size;
|
|
|
|
|
2008-06-07 19:04:31 +03:00
|
|
|
ifxmips_w32(0x1d7ff, IFXMIPS_EBU_BUSCON0);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_map.read = ifxmips_read16;
|
|
|
|
ifxmips_map.write = ifxmips_write16;
|
|
|
|
ifxmips_map.copy_from = ifxmips_copy_from;
|
|
|
|
ifxmips_map.copy_to = ifxmips_copy_to;
|
2008-06-29 03:42:45 +03:00
|
|
|
ifxmips_map.phys = dev->resource->start;
|
|
|
|
ifxmips_map.size = dev->resource->end - ifxmips_map.phys + 1;
|
|
|
|
ifxmips_map.virt = ioremap_nocache(ifxmips_map.phys, ifxmips_map.size);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-23 23:31:34 +03:00
|
|
|
if(!ifxmips_map.virt)
|
|
|
|
{
|
|
|
|
printk(KERN_WARNING "ifxmips_mtd: failed to ioremap!\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &ifxmips_map);
|
2008-06-23 23:31:34 +03:00
|
|
|
if(!ifxmips_mtd)
|
|
|
|
{
|
2007-12-25 15:26:41 +02:00
|
|
|
iounmap(ifxmips_map.virt);
|
2008-06-23 23:31:34 +03:00
|
|
|
printk(KERN_WARNING "ifxmips_mtd: probing failed\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_mtd->owner = THIS_MODULE;
|
|
|
|
uimage_size = find_uImage_size(ifxmips_partitions[2].offset);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-23 23:31:34 +03:00
|
|
|
if(detect_squashfs_partition(ifxmips_partitions[2].offset + uimage_size))
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "ifxmips_mtd: found a squashfs following the uImage\n");
|
2007-12-21 00:29:45 +02:00
|
|
|
} else {
|
|
|
|
uimage_size &= ~0xffff;
|
|
|
|
uimage_size += 0x10000;
|
|
|
|
}
|
|
|
|
|
2008-07-06 02:06:07 +03:00
|
|
|
parts = &ifxmips_partitions[0];
|
2007-12-25 15:26:41 +02:00
|
|
|
ifxmips_partitions[2].size = uimage_size;
|
|
|
|
ifxmips_partitions[3].offset = ifxmips_partitions[2].offset + ifxmips_partitions[2].size;
|
|
|
|
ifxmips_partitions[3].size = ((ifxmips_mtd->size >> 20) * 1024 * 1024) - ifxmips_partitions[3].offset;
|
2008-07-06 02:06:07 +03:00
|
|
|
if(ifxmips_has_brn_block())
|
|
|
|
{
|
|
|
|
ifxmips_partitions[3].size -= ifxmips_mtd->erasesize;
|
|
|
|
ifxmips_partitions[4].offset = ifxmips_mtd->size - ifxmips_mtd->erasesize;
|
|
|
|
ifxmips_partitions[4].size = ifxmips_mtd->erasesize;
|
|
|
|
add_mtd_partitions(ifxmips_mtd, parts, 5);
|
|
|
|
} else {
|
|
|
|
add_mtd_partitions(ifxmips_mtd, parts, 4);
|
|
|
|
}
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-23 23:31:34 +03:00
|
|
|
printk(KERN_INFO "ifxmips_mtd: added ifxmips flash with %dMB\n", ifxmips_mtd->size >> 20);
|
2007-12-21 00:29:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-22 22:01:14 +03:00
|
|
|
static struct
|
|
|
|
platform_driver ifxmips_mtd_driver = {
|
|
|
|
.probe = ifxmips_mtd_probe,
|
|
|
|
.driver = {
|
2008-06-23 23:31:34 +03:00
|
|
|
.name = "ifxmips_mtd",
|
2008-06-22 22:01:14 +03:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
2007-12-25 15:26:41 +02:00
|
|
|
|
|
|
|
int __init
|
2008-06-23 23:31:34 +03:00
|
|
|
init_ifxmips_mtd(void)
|
2007-12-25 15:26:41 +02:00
|
|
|
{
|
2008-06-22 22:01:14 +03:00
|
|
|
int ret = platform_driver_register(&ifxmips_mtd_driver);
|
2008-06-23 23:31:34 +03:00
|
|
|
if(ret)
|
|
|
|
printk(KERN_INFO "ifxmips_mtd: error registering platfom driver!");
|
2008-06-22 22:01:14 +03:00
|
|
|
return ret;
|
2007-12-25 15:26:41 +02:00
|
|
|
}
|
|
|
|
|
2008-06-29 03:42:45 +03:00
|
|
|
static void __exit
|
2008-06-23 23:31:34 +03:00
|
|
|
cleanup_ifxmips_mtd(void)
|
2007-12-21 00:29:45 +02:00
|
|
|
{
|
2007-12-25 15:26:41 +02:00
|
|
|
platform_driver_unregister(&ifxmips_mtd_driver);
|
2007-12-21 00:29:45 +02:00
|
|
|
}
|
|
|
|
|
2008-06-23 23:31:34 +03:00
|
|
|
module_init(init_ifxmips_mtd);
|
|
|
|
module_exit(cleanup_ifxmips_mtd);
|
2007-12-21 00:29:45 +02:00
|
|
|
|
2008-06-23 23:31:34 +03:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
|
|
|
|
MODULE_DESCRIPTION("MTD map driver for IFXMIPS boards");
|