diff options
author | thl <thl@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2008-11-20 18:31:00 +0000 |
---|---|---|
committer | thl <thl@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2008-11-20 18:31:00 +0000 |
commit | 49b34728f956238c5fdbec568be0247fb8be95c6 (patch) | |
tree | c27e65457073e14fccdb143d901b02f5c64dd2ad /target/linux/ifxmips/files/drivers | |
parent | 54b8671bd25722d397706ab1ef82ffc1faed6d06 (diff) |
[ifxmips] some cleanups:
- fix CPUID detection
- update MTD map for checks and sysupgrade
- enable subtargets (Generic&NFS) for simpler development
- generic cleanups (e.g. from linux checkpatch.pl)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@13295 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/ifxmips/files/drivers')
-rw-r--r-- | target/linux/ifxmips/files/drivers/mtd/maps/ifxmips.c | 194 | ||||
-rw-r--r-- | target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c | 48 |
2 files changed, 140 insertions, 102 deletions
diff --git a/target/linux/ifxmips/files/drivers/mtd/maps/ifxmips.c b/target/linux/ifxmips/files/drivers/mtd/maps/ifxmips.c index b3692e72a0..aed241b983 100644 --- a/target/linux/ifxmips/files/drivers/mtd/maps/ifxmips.c +++ b/target/linux/ifxmips/files/drivers/mtd/maps/ifxmips.c @@ -3,7 +3,7 @@ * 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 @@ -20,7 +20,7 @@ #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> -#include <asm/io.h> +#include <linux/io.h> #include <linux/init.h> #include <linux/mtd/mtd.h> #include <linux/mtd/map.h> @@ -32,126 +32,143 @@ #include <linux/magic.h> #include <linux/platform_device.h> -static struct map_info -ifxmips_map = { - .name = "ifxmips_mtd", +#ifndef CONFIG_MTD_PARTITIONS +#error Please enable CONFIG_MTD_PARTITIONS +#endif + +static struct map_info ifxmips_map = { + .name = "ifx-nor", .bankwidth = 2, .size = 0x400000, }; -static map_word -ifxmips_read16(struct map_info * map, unsigned long adr) +static map_word ifxmips_read16(struct map_info *map, unsigned long adr) { unsigned long flags; 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; } -static void -ifxmips_write16(struct map_info *map, map_word d, unsigned long adr) +static void ifxmips_write16(struct map_info *map, map_word d, unsigned long adr) { 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); } -void -ifxmips_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) +void ifxmips_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) { unsigned char *p; unsigned char *to_8; unsigned long flags; spin_lock_irqsave(&ebu_lock, flags); from = (unsigned long)(from + map->virt); - p = (unsigned char*) from; - to_8 = (unsigned char*) to; - while(len--) + p = (unsigned char *) from; + to_8 = (unsigned char *) to; + while (len--) *to_8++ = *p++; spin_unlock_irqrestore(&ebu_lock, flags); } -void -ifxmips_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) +void ifxmips_copy_to(struct map_info *map, + unsigned long to, + const void *from, + ssize_t len) { - unsigned char *p = (unsigned char*)from; + unsigned char *p = (unsigned char *)from; unsigned char *to_8; unsigned long flags; spin_lock_irqsave(&ebu_lock, flags); to += (unsigned long) map->virt; - to_8 = (unsigned char*)to; - while(len--) + to_8 = (unsigned char *)to; + while (len--) *p++ = *to_8++; spin_unlock_irqrestore(&ebu_lock, flags); } -static struct mtd_partition -ifxmips_partitions[] = { +static struct mtd_partition ifxmips_partitions[] = { { - name:"uboot", - offset:0x00000000, - size:0x00020000, + .name = "uboot", + .offset = 0x00000000, + .size = 0x00020000, }, { - name:"uboot_env", - offset:0x00020000, - size:0x00010000, + .name = "uboot_env", + .offset = 0x00020000, + .size = 0x00010000, }, { - name:"kernel", - offset:0x00030000, - size:0x0, + .name = "kernel", + .offset = 0x00030000, + .size = 0x0, }, { - name:"rootfs", - offset:0x0, - size:0x0, + .name = "rootfs", + .offset = 0x0, + .size = 0x0, }, { - name:"board_config", - offset:0x0, - size:0x0, + .name = "board_config", + .offset = 0x0, + .size = 0x0, }, }; -int -find_uImage_size(unsigned long start_offset){ +static struct mtd_partition ifxmips_meta_partition = { + .name = "linux", + .offset = 0x00030000, + .size = 0x0, +}; + +static const char *part_probe_types[] = { "cmdlinepart", NULL }; + +int find_uImage_size(unsigned long start_offset) +{ + unsigned long magic; unsigned long temp; + ifxmips_copy_from(&ifxmips_map, &magic, start_offset, 4); + if (!(ntohl(magic) == 0x27051956)) { + printk(KERN_INFO "ifxmips_mtd: invalid magic (0x%08X) of kernel at 0x%08lx \n", ntohl(magic), start_offset); + return 0; + } 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){ +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) + if (memcmp(temp, "BRN-BOOT", 8) == 0) return 1; else return 0; } -int -detect_squashfs_partition(unsigned long start_offset){ +int detect_squashfs_partition(unsigned long start_offset) +{ unsigned long temp; ifxmips_copy_from(&ifxmips_map, &temp, start_offset, 4); - return (temp == SQUASHFS_MAGIC); + return temp == SQUASHFS_MAGIC; } -static int -ifxmips_mtd_probe(struct platform_device *dev) +static int ifxmips_mtd_probe(struct platform_device *dev) { struct mtd_info *ifxmips_mtd = NULL; struct mtd_partition *parts = NULL; unsigned long uimage_size; + int err, i; + int kernel_part = 2, rootfs_part = 3; + int num_parts = ARRAY_SIZE(ifxmips_partitions); ifxmips_w32(0x1d7ff, IFXMIPS_EBU_BUSCON0); @@ -163,51 +180,74 @@ ifxmips_mtd_probe(struct platform_device *dev) ifxmips_map.size = dev->resource->end - ifxmips_map.phys + 1; ifxmips_map.virt = ioremap_nocache(ifxmips_map.phys, ifxmips_map.size); - if(!ifxmips_map.virt) - { + if (!ifxmips_map.virt) { printk(KERN_WARNING "ifxmips_mtd: failed to ioremap!\n"); return -EIO; } ifxmips_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &ifxmips_map); - if(!ifxmips_mtd) - { + if (!ifxmips_mtd) { iounmap(ifxmips_map.virt); printk(KERN_WARNING "ifxmips_mtd: probing failed\n"); return -ENXIO; } ifxmips_mtd->owner = THIS_MODULE; - uimage_size = find_uImage_size(ifxmips_partitions[2].offset); - if(detect_squashfs_partition(ifxmips_partitions[2].offset + uimage_size)) - { - printk(KERN_INFO "ifxmips_mtd: found a squashfs following the uImage\n"); + err = parse_mtd_partitions(ifxmips_mtd, part_probe_types, &parts, 0); + if (err > 0) { + printk(KERN_INFO "ifxmips_mtd: found %d partitions from cmdline\n", err); + num_parts = err; + kernel_part = 0; + rootfs_part = 0; + for (i = 0; i < num_parts; i++) { + if (strcmp(parts[i].name, "kernel") == 0) + kernel_part = i; + if (strcmp(parts[i].name, "rootfs") == 0) + rootfs_part = i; + } } else { - uimage_size &= ~0xffff; - uimage_size += 0x10000; + parts = &ifxmips_partitions[0]; } - 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; - 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); + /* dynamic size detection only if rootfs-part follows kernel-part */ + if (kernel_part+1 == rootfs_part) { + uimage_size = find_uImage_size(parts[kernel_part].offset); + + if (detect_squashfs_partition(parts[kernel_part].offset + uimage_size)) { + printk(KERN_INFO "ifxmips_mtd: found a squashfs following the uImage\n"); + } else { + uimage_size &= ~0xffff; + uimage_size += 0x10000; + } + + parts[kernel_part].size = uimage_size; + parts[rootfs_part].offset = parts[kernel_part].offset + parts[kernel_part].size; + parts[rootfs_part].size = ((ifxmips_mtd->size >> 20) * 1024 * 1024) - parts[rootfs_part].offset; + + ifxmips_meta_partition.offset = parts[kernel_part].offset; + ifxmips_meta_partition.size = parts[kernel_part].size + parts[rootfs_part].size; } - printk(KERN_INFO "ifxmips_mtd: added ifxmips flash with %dMB\n", ifxmips_mtd->size >> 20); + if (err <= 0) { + if (ifxmips_has_brn_block()) { + parts[4].size -= ifxmips_mtd->erasesize; + parts[5].offset = ifxmips_mtd->size - ifxmips_mtd->erasesize; + parts[5].size = ifxmips_mtd->erasesize; + } else { + num_parts--; + } + } + + add_mtd_partitions(ifxmips_mtd, parts, num_parts); + add_mtd_partitions(ifxmips_mtd, &ifxmips_meta_partition, 1); + + printk(KERN_INFO "ifxmips_mtd: added %s flash with %dMB\n", + ifxmips_map.name, ifxmips_mtd->size >> 20); return 0; } -static struct -platform_driver ifxmips_mtd_driver = { +static struct platform_driver ifxmips_mtd_driver = { .probe = ifxmips_mtd_probe, .driver = { .name = "ifxmips_mtd", @@ -215,17 +255,15 @@ platform_driver ifxmips_mtd_driver = { }, }; -int __init -init_ifxmips_mtd(void) +int __init init_ifxmips_mtd(void) { int ret = platform_driver_register(&ifxmips_mtd_driver); - if(ret) + if (ret) printk(KERN_INFO "ifxmips_mtd: error registering platfom driver!"); return ret; } -static void __exit -cleanup_ifxmips_mtd(void) +static void __exit cleanup_ifxmips_mtd(void) { platform_driver_unregister(&ifxmips_mtd_driver); } diff --git a/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c b/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c index fe7f25ec2a..fafb5a52fe 100644 --- a/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c +++ b/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c @@ -14,7 +14,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * Copyright (C) 2005 Wu Qi Ming <Qi-Ming.Wu@infineon.com> - * Copyright (C) 2008 John Crispin <blogic@openwrt.org> + * Copyright (C) 2008 John Crispin <blogic@openwrt.org> */ #include <linux/kernel.h> @@ -22,7 +22,7 @@ #include <linux/errno.h> #include <linux/types.h> #include <linux/interrupt.h> -#include <asm/uaccess.h> +#include <linux/uaccess.h> #include <linux/in.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> @@ -32,9 +32,9 @@ #include <linux/mm.h> #include <linux/platform_device.h> #include <linux/ethtool.h> -#include <asm/checksum.h> #include <linux/init.h> -#include <asm/delay.h> +#include <linux/delay.h> +#include <asm/checksum.h> #include <asm/ifxmips/ifxmips.h> #include <asm/ifxmips/ifxmips_dma.h> #include <asm/ifxmips/ifxmips_pmu.h> @@ -83,9 +83,9 @@ ifxmips_ifxmips_mii_open(struct net_device *dev) struct dma_device_info* dma_dev = priv->dma_device; int i; - for(i = 0; i < dma_dev->max_rx_chan_num; i++) + for (i = 0; i < dma_dev->max_rx_chan_num; i++) { - if((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON) + if ((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON) (dma_dev->rx_chan[i])->open(dma_dev->rx_chan[i]); } netif_start_queue(dev); @@ -98,7 +98,7 @@ ifxmips_mii_release(struct net_device *dev){ struct dma_device_info* dma_dev = priv->dma_device; int i; - for(i = 0; i < dma_dev->max_rx_chan_num; i++) + for (i = 0; i < dma_dev->max_rx_chan_num; i++) dma_dev->rx_chan[i]->close(dma_dev->rx_chan[i]); netif_stop_queue(dev); return 0; @@ -114,7 +114,7 @@ ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev) len = dma_device_read(dma_dev, &buf, (void**)&skb); - if(len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) + if (len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) { printk(KERN_INFO "ifxmips_mii0: packet too large %d\n",len); goto ifxmips_mii_hw_receive_err_exit; @@ -122,13 +122,13 @@ ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev) /* remove CRC */ len -= 4; - if(skb == NULL) + if (skb == NULL) { printk(KERN_INFO "ifxmips_mii0: cannot restore pointer\n"); goto ifxmips_mii_hw_receive_err_exit; } - if(len > (skb->end - skb->tail)) + if (len > (skb->end - skb->tail)) { printk(KERN_INFO "ifxmips_mii0: BUG, len:%d end:%p tail:%p\n", (len+4), skb->end, skb->tail); @@ -145,9 +145,9 @@ ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev) return 0; ifxmips_mii_hw_receive_err_exit: - if(len == 0) + if (len == 0) { - if(skb) + if (skb) dev_kfree_skb_any(skb); priv->stats.rx_errors++; priv->stats.rx_dropped++; @@ -185,7 +185,7 @@ ifxmips_mii_tx(struct sk_buff *skb, struct net_device *dev) wmb(); - if(ifxmips_mii_hw_tx(data, len, dev) != len) + if (ifxmips_mii_hw_tx(data, len, dev) != len) { dev_kfree_skb_any(skb); priv->stats.tx_errors++; @@ -205,7 +205,7 @@ ifxmips_mii_tx_timeout(struct net_device *dev) struct ifxmips_mii_priv* priv = (struct ifxmips_mii_priv*)dev->priv; priv->stats.tx_errors++; - for(i = 0; i < priv->dma_device->max_tx_chan_num; i++) + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++) priv->dma_device->tx_chan[i]->disable_irq(priv->dma_device->tx_chan[i]); netif_wake_queue(dev); return; @@ -233,7 +233,7 @@ dma_intr_handler(struct dma_device_info* dma_dev, int status) break; case TRANSMIT_CPT_INT: - for(i = 0; i < dma_dev->max_tx_chan_num; i++) + for (i = 0; i < dma_dev->max_tx_chan_num; i++) dma_dev->tx_chan[i]->disable_irq(dma_dev->tx_chan[i]); netif_wake_queue(ifxmips_mii0_dev); @@ -250,7 +250,7 @@ ifxmips_etop_dma_buffer_alloc(int len, int *byte_offset, void **opt) struct sk_buff *skb = NULL; skb = dev_alloc_skb(ETHERNET_PACKET_DMA_BUFFER_SIZE); - if(skb == NULL) + if (skb == NULL) return NULL; buffer = (unsigned char*)(skb->data); @@ -266,7 +266,7 @@ ifxmips_etop_dma_buffer_free(unsigned char *dataptr, void *opt) { struct sk_buff *skb = NULL; - if(opt == NULL) + if (opt == NULL) { kfree(dataptr); } else { @@ -298,7 +298,7 @@ ifxmips_mii_dev_init(struct net_device *dev) memset(dev->priv, 0, sizeof(struct ifxmips_mii_priv)); priv = dev->priv; priv->dma_device = dma_device_reserve("PPE"); - if(!priv->dma_device){ + if (!priv->dma_device){ BUG(); return -ENODEV; } @@ -307,14 +307,14 @@ ifxmips_mii_dev_init(struct net_device *dev) priv->dma_device->intr_handler = &dma_intr_handler; priv->dma_device->max_rx_chan_num = 4; - for(i = 0; i < priv->dma_device->max_rx_chan_num; i++) + for (i = 0; i < priv->dma_device->max_rx_chan_num; i++) { priv->dma_device->rx_chan[i]->packet_size = ETHERNET_PACKET_DMA_BUFFER_SIZE; priv->dma_device->rx_chan[i]->control = IFXMIPS_DMA_CH_ON; } - for(i = 0; i < priv->dma_device->max_tx_chan_num; i++) - if(i == 0) + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++) + if (i == 0) priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_ON; else priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_OFF; @@ -322,7 +322,7 @@ ifxmips_mii_dev_init(struct net_device *dev) dma_device_register(priv->dma_device); printk(KERN_INFO "ifxmips_mii0: using mac="); - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { dev->dev_addr[i] = mac_addr[i]; printk("%02X%c", dev->dev_addr[i], (i == 5)?('\n'):(':')); @@ -336,9 +336,9 @@ ifxmips_mii_chip_init(int mode) ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_DMA); ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_PPE); - if(mode == REV_MII_MODE) + if (mode == REV_MII_MODE) ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG); - else if(mode == MII_MODE) + else if (mode == MII_MODE) ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG); ifxmips_w32(PPE32_PLEN_UNDER | PPE32_PLEN_OVER, IFXMIPS_PPE32_IG_PLEN_CTRL); ifxmips_w32(PPE32_CGEN, IFXMIPS_PPE32_ENET_MAC_CFG); |