Move files and patches to files-2.6.23 and patches-2.6.23
[openwrt.git] / target / linux / ifxmips / files / drivers / mtd / maps / ifxmips.c
index 808904a..b3692e7 100644 (file)
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/cfi.h>
 #include <asm/ifxmips/ifxmips.h>
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/cfi.h>
 #include <asm/ifxmips/ifxmips.h>
+#include <asm/ifxmips/ifxmips_prom.h>
 #include <asm/ifxmips/ifxmips_ebu.h>
 #include <linux/magic.h>
 #include <linux/platform_device.h>
 
 #include <asm/ifxmips/ifxmips_ebu.h>
 #include <linux/magic.h>
 #include <linux/platform_device.h>
 
-
 static struct map_info
 ifxmips_map = {
        .name = "ifxmips_mtd",
 static struct map_info
 ifxmips_map = {
        .name = "ifxmips_mtd",
@@ -46,7 +46,7 @@ ifxmips_read16(struct map_info * map, unsigned long adr)
        map_word temp;
        spin_lock_irqsave(&ebu_lock, flags);
        adr ^= 2;
        map_word temp;
        spin_lock_irqsave(&ebu_lock, flags);
        adr ^= 2;
-       temp.x[0] = *((__u16 *) (map->virt + adr));
+       temp.x[0] = *((__u16*)(map->virt + adr));
        spin_unlock_irqrestore(&ebu_lock, flags);
        return temp;
 }
        spin_unlock_irqrestore(&ebu_lock, flags);
        return temp;
 }
@@ -57,7 +57,7 @@ ifxmips_write16(struct map_info *map, map_word d, unsigned long adr)
        unsigned long flags;
        spin_lock_irqsave(&ebu_lock, flags);
        adr ^= 2;
        unsigned long flags;
        spin_lock_irqsave(&ebu_lock, flags);
        adr ^= 2;
-       *((__u16 *) (map->virt + adr)) = d.x[0];
+       *((__u16*)(map->virt + adr)) = d.x[0];
        spin_unlock_irqrestore(&ebu_lock, flags);
 }
 
        spin_unlock_irqrestore(&ebu_lock, flags);
 }
 
@@ -73,7 +73,7 @@ ifxmips_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t le
        to_8 = (unsigned char*) to;
        while(len--)
                *to_8++ = *p++;
        to_8 = (unsigned char*) to;
        while(len--)
                *to_8++ = *p++;
-               spin_unlock_irqrestore(&ebu_lock, flags);
+       spin_unlock_irqrestore(&ebu_lock, flags);
 }
 
 void
 }
 
 void
@@ -85,21 +85,20 @@ ifxmips_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_
        spin_lock_irqsave(&ebu_lock, flags);
        to += (unsigned long) map->virt;
        to_8 = (unsigned char*)to;
        spin_lock_irqsave(&ebu_lock, flags);
        to += (unsigned long) map->virt;
        to_8 = (unsigned char*)to;
-       while(len--){
+       while(len--)
                *p++ = *to_8++;
                *p++ = *to_8++;
-       }
        spin_unlock_irqrestore(&ebu_lock, flags);
 }
 
 static struct mtd_partition
        spin_unlock_irqrestore(&ebu_lock, flags);
 }
 
 static struct mtd_partition
-ifxmips_partitions[4] = {
+ifxmips_partitions[] = {
        {
        {
-               name:"U-Boot",
+               name:"uboot",
                offset:0x00000000,
                size:0x00020000,
        },
        {
                offset:0x00000000,
                size:0x00020000,
        },
        {
-               name:"U-Boot-Env",
+               name:"uboot_env",
                offset:0x00020000,
                size:0x00010000,
        },
                offset:0x00020000,
                size:0x00010000,
        },
@@ -113,23 +112,37 @@ ifxmips_partitions[4] = {
                offset:0x0,
                size:0x0,
        },
                offset:0x0,
                size:0x0,
        },
+       {
+               name:"board_config",
+               offset:0x0,
+               size:0x0,
+       },
 };
 
 int
 find_uImage_size(unsigned long start_offset){
        unsigned long temp;
 };
 
 int
 find_uImage_size(unsigned long start_offset){
        unsigned long temp;
-
        ifxmips_copy_from(&ifxmips_map, &temp, start_offset + 12, 4);
        printk(KERN_INFO "ifxmips_mtd: kernel size is %ld \n", temp + 0x40);
        return temp + 0x40;
 }
 
        ifxmips_copy_from(&ifxmips_map, &temp, start_offset + 12, 4);
        printk(KERN_INFO "ifxmips_mtd: kernel size is %ld \n", temp + 0x40);
        return temp + 0x40;
 }
 
+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;
+}
+
 int
 detect_squashfs_partition(unsigned long start_offset){
        unsigned long temp;
 int
 detect_squashfs_partition(unsigned long start_offset){
        unsigned long temp;
-
        ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 4);
        ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 4);
-
        return (temp == SQUASHFS_MAGIC);
 }
 
        return (temp == SQUASHFS_MAGIC);
 }
 
@@ -146,10 +159,10 @@ ifxmips_mtd_probe(struct platform_device *dev)
        ifxmips_map.write = ifxmips_write16;
        ifxmips_map.copy_from = ifxmips_copy_from;
        ifxmips_map.copy_to = ifxmips_copy_to;
        ifxmips_map.write = ifxmips_write16;
        ifxmips_map.copy_from = ifxmips_copy_from;
        ifxmips_map.copy_to = ifxmips_copy_to;
+       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);
 
 
-       ifxmips_map.phys = IFXMIPS_FLASH_START;
-       ifxmips_map.virt = ioremap_nocache(IFXMIPS_FLASH_START, IFXMIPS_FLASH_MAX);
-       ifxmips_map.size = IFXMIPS_FLASH_MAX;
        if(!ifxmips_map.virt)
        {
                printk(KERN_WARNING "ifxmips_mtd: failed to ioremap!\n");
        if(!ifxmips_map.virt)
        {
                printk(KERN_WARNING "ifxmips_mtd: failed to ioremap!\n");
@@ -165,7 +178,6 @@ ifxmips_mtd_probe(struct platform_device *dev)
        }
 
        ifxmips_mtd->owner = THIS_MODULE;
        }
 
        ifxmips_mtd->owner = THIS_MODULE;
-
        uimage_size = find_uImage_size(ifxmips_partitions[2].offset);
 
        if(detect_squashfs_partition(ifxmips_partitions[2].offset + uimage_size))
        uimage_size = find_uImage_size(ifxmips_partitions[2].offset);
 
        if(detect_squashfs_partition(ifxmips_partitions[2].offset + uimage_size))
@@ -176,12 +188,19 @@ ifxmips_mtd_probe(struct platform_device *dev)
                uimage_size += 0x10000;
        }
 
                uimage_size += 0x10000;
        }
 
+       parts = &ifxmips_partitions[0];
        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;
        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;
-
-       parts = &ifxmips_partitions[0];
-       add_mtd_partitions(ifxmips_mtd, parts, 4);
+       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);
+       }
 
        printk(KERN_INFO "ifxmips_mtd: added ifxmips flash with %dMB\n", ifxmips_mtd->size >> 20);
        return 0;
 
        printk(KERN_INFO "ifxmips_mtd: added ifxmips flash with %dMB\n", ifxmips_mtd->size >> 20);
        return 0;
@@ -205,8 +224,7 @@ init_ifxmips_mtd(void)
        return ret;
 }
 
        return ret;
 }
 
-static void
-__exit
+static void __exit
 cleanup_ifxmips_mtd(void)
 {
        platform_driver_unregister(&ifxmips_mtd_driver);
 cleanup_ifxmips_mtd(void)
 {
        platform_driver_unregister(&ifxmips_mtd_driver);
This page took 0.027558 seconds and 4 git commands to generate.