[adm5120] make use the chip_fixup function of the plat_nand driver
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / boards / mikrotik.c
index 855ec3a..48a7272 100644 (file)
  *    Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  *    The original Mikrotik code seems not to have a license.
  *
- *  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., 51 Franklin Street, Fifth Floor,
- *  Boston, MA  02110-1301, USA.
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
  *
  */
 
@@ -42,7 +31,9 @@
 #include <adm5120_nand.h>
 #include <adm5120_board.h>
 #include <adm5120_platform.h>
-#include <adm5120_cf.h>
+#include <adm5120_info.h>
+
+#include <prom/routerboot.h>
 
 #define RB1XX_NAND_CHIP_DELAY  25
 
@@ -117,6 +108,33 @@ static struct resource rb150_nand_resource[] = {
        },
 };
 
+static struct resource rb153_cf_resources[] = {
+       {
+               .name   = "cf_membase",
+               .start  = ADM5120_EXTIO1_BASE,
+               .end    = ADM5120_EXTIO1_BASE + ADM5120_EXTIO1_SIZE-1 ,
+               .flags  = IORESOURCE_MEM
+       }, {
+               .name   = "cf_irq",
+               .start  = ADM5120_IRQ_GPIO4,
+               .end    = ADM5120_IRQ_GPIO4,
+               .flags  = IORESOURCE_IRQ
+       }
+};
+
+static struct platform_device rb153_cf_device = {
+       .name           = "pata-rb153-cf",
+       .id             = -1,
+       .resource       = rb153_cf_resources,
+       .num_resources  = ARRAY_SIZE(rb153_cf_resources),
+};
+
+static struct platform_device *rb153_devices[] __initdata = {
+       &adm5120_flash0_device,
+       &adm5120_nand_device,
+       &rb153_cf_device,
+};
+
 #if 0
 /*
  * RB1xx boards have bad network performance with the default VLAN matrixes.
@@ -180,41 +198,29 @@ static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 }
 
 /*--------------------------------------------------------------------------*/
-static struct resource cf_slot0_res[] = {
-        {
-                .name = "cf_membase",
-               .start = ADM5120_EXTIO0_BASE, 
-               .end = ADM5120_EXTIO0_BASE + ADM5120_MPMC_SIZE-1 ,
-                .flags = IORESOURCE_MEM
-        }, {
-                .name = "cf_irq",
-                .start = ADM5120_IRQ_GPIO4, /* 5 */
-                .end = ADM5120_IRQ_GPIO4,
-                .flags = IORESOURCE_IRQ
-        }
-};
 
-static struct cf_device cf_slot0_data = {
-        .gpio_pin = 4
-};
+static void __init rb1xx_mac_setup(void)
+{
+       int i, j;
 
-static struct platform_device cf_slot0 = {
-        .id = 0,
-        .name = "rb153-cf",
-        .dev.platform_data = &cf_slot0_data,
-        .resource = cf_slot0_res,
-        .num_resources = ARRAY_SIZE(cf_slot0_res),
-};
+       if (!rb_hs.mac_base)
+               return;
 
-static struct platform_device *rb153_devices[] __initdata = {
-        &adm5120_flash0_device,
-        &adm5120_nand_device,
-       &cf_slot0,
-};
+       for (i = 0; i < 6; i++) {
+               for (j = 0; j < 5; j++)
+                       adm5120_eth_macs[i][j] = rb_hs.mac_base[j];
+               adm5120_eth_macs[i][5] = rb_hs.mac_base[5]+i;
+       }
+}
 
-static void __init rb1xx_mac_setup(void)
+static int rb1xx_nand_fixup(struct mtd_info *mtd)
 {
-       /* TODO */
+       struct nand_chip *chip = mtd->priv;
+
+       if (mtd->writesize == 512)
+               chip->ecc.layout = &rb1xx_nand_ecclayout;
+
+       return 0;
 }
 
 static void __init rb1xx_flash_setup(void)
@@ -227,9 +233,10 @@ static void __init rb1xx_flash_setup(void)
        adm5120_nand_data.chip.nr_chips = 1;
        adm5120_nand_data.chip.nr_partitions = ARRAY_SIZE(rb1xx_nand_parts);
        adm5120_nand_data.chip.partitions = rb1xx_nand_parts;
-       adm5120_nand_data.chip.ecclayout = &rb1xx_nand_ecclayout;
        adm5120_nand_data.chip.chip_delay = RB1XX_NAND_CHIP_DELAY;
        adm5120_nand_data.chip.options = NAND_NO_AUTOINCR;
+
+       adm5120_nand_data.chip.chip_fixup = &rb1xx_nand_fixup;
 }
 
 static void __init rb1xx_setup(void)
@@ -268,11 +275,19 @@ static void __init rb150_setup(void)
        rb1xx_mac_setup();
 }
 
+static void __init rb153_setup(void)
+{
+       /* enable CSX1:INTX1 on GPIO[3:4] for the CF slot */
+       adm5120_gpio_csx1_enable();
+       /* enable the wait state pin GPIO[0] for external I/O control */
+       adm5120_gpio_ew_enable();
+
+       rb1xx_setup();
+}
+
 /*--------------------------------------------------------------------------*/
 
-static struct adm5120_board rb111_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_111,
-       .name           = "Mikrotik RouterBOARD 111",
+ADM5120_BOARD_START(RB_111, "Mikrotik RouterBOARD 111")
        .board_setup    = rb1xx_setup,
        .eth_num_ports  = 1,
        .eth_vlans      = rb11x_vlans,
@@ -280,11 +295,9 @@ static struct adm5120_board rb111_board __initdata = {
        .devices        = rb1xx_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb112_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_112,
-       .name           = "Mikrotik RouterBOARD 112",
+ADM5120_BOARD_START(RB_112, "Mikrotik RouterBOARD 112")
        .board_setup    = rb1xx_setup,
        .eth_num_ports  = 1,
        .eth_vlans      = rb11x_vlans,
@@ -292,11 +305,9 @@ static struct adm5120_board rb112_board __initdata = {
        .devices        = rb1xx_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb133_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_133,
-       .name           = "Mikrotik RouterBOARD 133",
+ADM5120_BOARD_START(RB_133, "Mikrotik RouterBOARD 133")
        .board_setup    = rb1xx_setup,
        .eth_num_ports  = 3,
        .eth_vlans      = rb133_vlans,
@@ -304,11 +315,9 @@ static struct adm5120_board rb133_board __initdata = {
        .devices        = rb1xx_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb133c_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_133C,
-       .name           = "Mikrotik RouterBOARD 133C",
+ADM5120_BOARD_START(RB_133C, "Mikrotik RouterBOARD 133C")
        .board_setup    = rb1xx_setup,
        .eth_num_ports  = 1,
        .eth_vlans      = rb133c_vlans,
@@ -316,33 +325,27 @@ static struct adm5120_board rb133c_board __initdata = {
        .devices        = rb1xx_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb150_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_150,
-       .name           = "Mikrotik RouterBOARD 150",
+ADM5120_BOARD_START(RB_150, "Mikrotik RouterBOARD 150")
        .board_setup    = rb150_setup,
        .eth_num_ports  = 5,
        .eth_vlans      = rb15x_vlans,
        .num_devices    = ARRAY_SIZE(rb1xx_devices),
        .devices        = rb1xx_devices,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb153_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_153,
-       .name           = "Mikrotik RouterBOARD 153",
-       .board_setup    = rb1xx_setup,
+ADM5120_BOARD_START(RB_153, "Mikrotik RouterBOARD 153")
+       .board_setup    = rb153_setup,
        .eth_num_ports  = 5,
        .eth_vlans      = rb15x_vlans,
        .num_devices    = ARRAY_SIZE(rb153_devices),
        .devices        = rb153_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
+ADM5120_BOARD_END
 
-static struct adm5120_board rb192_board __initdata = {
-       .mach_type      = MACH_ADM5120_RB_192,
-       .name           = "Mikrotik RouterBOARD 192",
+ADM5120_BOARD_START(RB_192, "Mikrotik RouterBOARD 192")
        .board_setup    = rb1xx_setup,
        .eth_num_ports  = 5,
        .eth_vlans      = rb192_vlans,
@@ -350,18 +353,4 @@ static struct adm5120_board rb192_board __initdata = {
        .devices        = rb1xx_devices,
        .pci_nr_irqs    = ARRAY_SIZE(rb1xx_pci_irqs),
        .pci_irq_map    = rb1xx_pci_irqs,
-};
-
-static int __init register_boards(void)
-{
-       adm5120_board_register(&rb111_board);
-       adm5120_board_register(&rb112_board);
-       adm5120_board_register(&rb133_board);
-       adm5120_board_register(&rb133c_board);
-       adm5120_board_register(&rb150_board);
-       adm5120_board_register(&rb153_board);
-       adm5120_board_register(&rb192_board);
-       return 0;
-}
-
-pure_initcall(register_boards);
+ADM5120_BOARD_END