ar71xx: register USB port for RB2011U* devices
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rb2011.c
index fd39ec618cd282840a68c556c05486a5031de318..9b0145875bd52cbfe379912efb24f8addbcaf794 100644 (file)
 #include "dev-eth.h"
 #include "dev-m25p80.h"
 #include "dev-nfc.h"
+#include "dev-usb.h"
 #include "dev-wmac.h"
 #include "machtypes.h"
 #include "routerboot.h"
 
 #define RB2011_GPIO_NAND_NCE   14
+#define RB2011_GPIO_SFP_LOS    21
 
 #define RB_ROUTERBOOT_OFFSET   0x0000
 #define RB_ROUTERBOOT_MIN_SIZE 0xb000
@@ -119,6 +121,17 @@ static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg = {
        .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
 };
 
+static struct ar8327_pad_cfg rb2011_ar8327_pad6_cfg;
+static struct ar8327_sgmii_cfg rb2011_ar8327_sgmii_cfg;
+
+static struct ar8327_led_cfg rb2011_ar8327_led_cfg = {
+       .led_ctrl0 = 0x0000c731,
+       .led_ctrl1 = 0x00000000,
+       .led_ctrl2 = 0x00000000,
+       .led_ctrl3 = 0x0030c300,
+       .open_drain = false,
+};
+
 static struct ar8327_platform_data rb2011_ar8327_data = {
        .pad0_cfg = &rb2011_ar8327_pad0_cfg,
        .port0_cfg = {
@@ -127,7 +140,8 @@ static struct ar8327_platform_data rb2011_ar8327_data = {
                .duplex = 1,
                .txpause = 1,
                .rxpause = 1,
-       }
+       },
+       .led_cfg = &rb2011_ar8327_led_cfg,
 };
 
 static struct mdio_board_info rb2011_mdio0_info[] = {
@@ -222,6 +236,35 @@ static void __init rb2011_nand_init(void)
        ath79_register_nfc();
 }
 
+static int rb2011_get_port_link(unsigned port)
+{
+       if (port != 6)
+               return -EINVAL;
+
+       /* The Loss of signal line is active low */
+       return !gpio_get_value(RB2011_GPIO_SFP_LOS);
+}
+
+static void __init rb2011_sfp_init(void)
+{
+       gpio_request_one(RB2011_GPIO_SFP_LOS, GPIOF_IN, "SFP LOS");
+
+       rb2011_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
+
+       rb2011_ar8327_data.pad6_cfg = &rb2011_ar8327_pad6_cfg;
+
+       rb2011_ar8327_sgmii_cfg.sgmii_ctrl = 0xc70167d0;
+       rb2011_ar8327_sgmii_cfg.serdes_aen = true;
+
+       rb2011_ar8327_data.sgmii_cfg = &rb2011_ar8327_sgmii_cfg;
+
+       rb2011_ar8327_data.port6_cfg.force_link = 1;
+       rb2011_ar8327_data.port6_cfg.speed = AR8327_PORT_SPEED_1000;
+       rb2011_ar8327_data.port6_cfg.duplex = 1;
+
+       rb2011_ar8327_data.get_port_link = rb2011_get_port_link;
+}
+
 static void __init rb2011_setup(void)
 {
        rb2011_init_partitions();
@@ -262,6 +305,9 @@ MIPS_MACHINE(ATH79_MACH_RB_2011L, "2011L", "MikroTik RouterBOARD 2011L",
 static void __init rb2011us_setup(void)
 {
        rb2011_setup();
+       rb2011_sfp_init();
+
+       ath79_register_usb();
 }
 
 MIPS_MACHINE(ATH79_MACH_RB_2011US, "2011US", "MikroTik RouterBOARD 2011UAS",
@@ -270,7 +316,10 @@ MIPS_MACHINE(ATH79_MACH_RB_2011US, "2011US", "MikroTik RouterBOARD 2011UAS",
 static void __init rb2011g_setup(void)
 {
        rb2011_setup();
+       rb2011_sfp_init();
        rb2011_wlan_init();
+
+       ath79_register_usb();
 }
 
 MIPS_MACHINE(ATH79_MACH_RB_2011G, "2011G", "MikroTik RouterBOARD 2011UAS-2HnD",