ar71xx: register the NAND controller device on the RB2011
authorGabor Juhos <juhosg@openwrt.org>
Thu, 13 Sep 2012 07:26:26 +0000 (07:26 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Thu, 13 Sep 2012 07:26:26 +0000 (07:26 +0000)
SVN-Revision: 33388

target/linux/ar71xx/files/arch/mips/ath79/mach-rb2011.c
target/linux/ar71xx/nand/config-default
target/linux/ar71xx/patches-3.3/613-RB2011-support.patch
target/linux/ar71xx/patches-3.3/614-MIPS-ath79-rb2011uas-2hnd-support.patch

index 4c7dc6dda9f3372f4e075fd5175e7624a6a4b5c9..ecdd7ea2e89f00a2968ffaf3b8a374b41e6dfe9d 100644 (file)
 #define pr_fmt(fmt) "rb2011: " fmt
 
 #include <linux/phy.h>
+#include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/ath9k_platform.h>
 #include <linux/ar8216_platform.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #include <linux/rle.h>
 #include <linux/routerboot.h>
+#include <linux/gpio.h>
 
 #include <asm/mach-ath79/ath79.h>
 #include <asm/mach-ath79/ar71xx_regs.h>
 #include "common.h"
 #include "dev-eth.h"
 #include "dev-m25p80.h"
+#include "dev-nfc.h"
 #include "dev-wmac.h"
 #include "machtypes.h"
 #include "routerboot.h"
 
+#define RB2011_GPIO_NAND_NCE   14
+
 #define RB_ROUTERBOOT_OFFSET   0x0000
 #define RB_ROUTERBOOT_SIZE     0xb000
 #define RB_HARD_CFG_OFFSET     0xb000
@@ -66,6 +72,25 @@ static struct mtd_partition rb2011_spi_partitions[] = {
        }
 };
 
+static struct mtd_partition rb2011_nand_partitions[] = {
+       {
+               .name   = "booter",
+               .offset = 0,
+               .size   = (256 * 1024),
+               .mask_flags = MTD_WRITEABLE,
+       },
+       {
+               .name   = "kernel",
+               .offset = (256 * 1024),
+               .size   = (4 * 1024 * 1024) - (256 * 1024),
+       },
+       {
+               .name   = "rootfs",
+               .offset = MTDPART_OFS_NXTBLK,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
 static struct flash_platform_data rb2011_spi_flash_data = {
        .parts          = rb2011_spi_partitions,
        .nr_parts       = ARRAY_SIZE(rb2011_spi_partitions),
@@ -151,9 +176,61 @@ free:
        kfree(art_buf);
 }
 
+static void rb2011_nand_select_chip(int chip_no)
+{
+       switch (chip_no) {
+       case 0:
+               gpio_set_value(RB2011_GPIO_NAND_NCE, 0);
+               break;
+       default:
+               gpio_set_value(RB2011_GPIO_NAND_NCE, 1);
+               break;
+       }
+       ndelay(500);
+}
+
+static struct nand_ecclayout rb2011_nand_ecclayout = {
+       .eccbytes       = 6,
+       .eccpos         = { 8, 9, 10, 13, 14, 15 },
+       .oobavail       = 9,
+       .oobfree        = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
+};
+
+static int rb2011_nand_scan_fixup(struct mtd_info *mtd)
+{
+       struct nand_chip *chip = mtd->priv;
+
+       if (mtd->writesize == 512) {
+               /*
+                * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
+                * will not be able to find the kernel that we load.
+                */
+               chip->ecc.layout = &rb2011_nand_ecclayout;
+       }
+
+       return 0;
+}
+
+static void __init rb2011_nand_init(void)
+{
+       ath79_nfc_set_scan_fixup(rb2011_nand_scan_fixup);
+       ath79_nfc_set_parts(rb2011_nand_partitions,
+                           ARRAY_SIZE(rb2011_nand_partitions));
+       ath79_nfc_set_select_chip(rb2011_nand_select_chip);
+       ath79_register_nfc();
+}
+
+static void __init rb2011_gpio_init(void)
+{
+       gpio_request_one(RB2011_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
+}
+
 static void __init rb2011_setup(void)
 {
+       rb2011_gpio_init();
+
        ath79_register_m25p80(&rb2011_spi_flash_data);
+       rb2011_nand_init();
 
        rb2011_gmac_setup();
 
index 5ba1486aef970e9033ed0e4e0070d10301ff6c7b..1015cf1fbf8dfb0fd33b926d3708e7b4b05c9ecf 100644 (file)
@@ -1,9 +1,11 @@
+CONFIG_ATH79_DEV_NFC=y
 CONFIG_CMDLINE="rootfstype=yaffs noinitrd"
 # CONFIG_JFFS2_CMODE_PRIORITY is not set
 # CONFIG_JFFS2_FS is not set
 CONFIG_MDIO_BITBANG=y
 CONFIG_MDIO_GPIO=y
 CONFIG_MTD_NAND=y
+CONFIG_MTD_NAND_AR934X=y
 CONFIG_MTD_NAND_ECC=y
 CONFIG_MTD_NAND_RB4XX=y
 CONFIG_MTD_NAND_RB750=y
index 656d5f8b59871e2ab01865d84a944f1ab4e87aef..f180fcf3357a0dd6636c76400501e24c92e5c4cb 100644 (file)
@@ -1,6 +1,6 @@
 --- a/arch/mips/ath79/Kconfig
 +++ b/arch/mips/ath79/Kconfig
-@@ -335,6 +335,11 @@ config ATH79_MACH_RB750
+@@ -335,6 +335,12 @@ config ATH79_MACH_RB750
        select ATH79_ROUTERBOOT
        select RLE_DECOMPRESS
  
@@ -8,6 +8,7 @@
 +      bool "MikroTik RouterBOARD 2011 support"
 +      select SOC_AR934x
 +      select ATH79_DEV_ETH
++      select ATH79_DEV_NFC
 +
  config ATH79_MACH_WNDR3700
        bool "NETGEAR WNDR3700 board support"
index 875d17c14a3d0c24d6c26ae89d38ab9fee1036cb..14b712c011e8036d003e20164c3fd0677843c4d1 100644 (file)
        ATH79_MACH_TEW_632BRP,          /* TRENDnet TEW-632BRP */
 --- a/arch/mips/ath79/Kconfig
 +++ b/arch/mips/ath79/Kconfig
-@@ -339,6 +339,8 @@ config ATH79_MACH_RB2011
-       bool "MikroTik RouterBOARD 2011 support"
+@@ -340,6 +340,8 @@ config ATH79_MACH_RB2011
        select SOC_AR934x
        select ATH79_DEV_ETH
+       select ATH79_DEV_NFC
 +      select ATH79_DEV_WMAC
 +      select ATH79_ROUTERBOOT