backport rtl8366 detection support from trunk
authorFelix Fietkau <nbd@openwrt.org>
Tue, 26 Jul 2011 16:24:35 +0000 (16:24 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 26 Jul 2011 16:24:35 +0000 (16:24 +0000)
SVN-Revision: 27785

target/linux/ar71xx/files/arch/mips/ar71xx/mach-dir-825-b1.c
target/linux/ar71xx/files/arch/mips/ar71xx/mach-tl-wr1043nd.c
target/linux/ar71xx/files/arch/mips/ar71xx/mach-wndr3700.c
target/linux/ar71xx/files/arch/mips/ar71xx/mach-wzr-hp-g300nh.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c
target/linux/generic-2.6/files/include/linux/rtl8366.h [new file with mode: 0644]
target/linux/generic-2.6/files/include/linux/rtl8366rb.h [deleted file]
target/linux/generic-2.6/files/include/linux/rtl8366s.h [deleted file]

index c1af09c27f7e446f666eaed6a18a5431eabfb66d..d9c16f70c916c9e70b11fe5c672694e461f6fc12 100644 (file)
@@ -14,7 +14,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/delay.h>
-#include <linux/rtl8366s.h>
+#include <linux/rtl8366.h>
 
 #include <asm/mach-ar71xx/ar71xx.h>
 
@@ -130,11 +130,11 @@ static struct gpio_button dir825b1_gpio_buttons[] __initdata = {
        }
 };
 
-static struct rtl8366s_initval dir825b1_rtl8366s_initvals[] = {
+static struct rtl8366_initval dir825b1_rtl8366s_initvals[] = {
        { .reg = 0x06, .val = 0x0108 },
 };
 
-static struct rtl8366s_platform_data dir825b1_rtl8366s_data = {
+static struct rtl8366_platform_data dir825b1_rtl8366s_data = {
        .gpio_sda       = DIR825B1_GPIO_RTL8366_SDA,
        .gpio_sck       = DIR825B1_GPIO_RTL8366_SCK,
        .num_initvals   = ARRAY_SIZE(dir825b1_rtl8366s_initvals),
index 3b7b764c227060559499c730e244f89f2d413f9d..7642d0423b2844bd5a5ee1c7e0677d70117ae57f 100644 (file)
@@ -11,7 +11,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/platform_device.h>
-#include <linux/rtl8366rb.h>
+#include <linux/rtl8366.h>
 #include <asm/mach-ar71xx/ar71xx.h>
 
 #include "machtype.h"
@@ -108,7 +108,7 @@ static struct gpio_button tl_wr1043nd_gpio_buttons[] __initdata = {
        }
 };
 
-static struct rtl8366rb_platform_data tl_wr1043nd_rtl8366rb_data = {
+static struct rtl8366_platform_data tl_wr1043nd_rtl8366rb_data = {
        .gpio_sda        = TL_WR1043ND_GPIO_RTL8366_SDA,
        .gpio_sck        = TL_WR1043ND_GPIO_RTL8366_SCK,
 };
index 68839505eef5ab5af6425599bddb66810a0bb58a..7d66d22f473a6c99eee75796072abf53844a0e41 100644 (file)
@@ -13,7 +13,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/delay.h>
-#include <linux/rtl8366s.h>
+#include <linux/rtl8366.h>
 
 #include <asm/mach-ar71xx/ar71xx.h>
 
@@ -201,7 +201,7 @@ static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
        }
 };
 
-static struct rtl8366s_platform_data wndr3700_rtl8366s_data = {
+static struct rtl8366_platform_data wndr3700_rtl8366s_data = {
        .gpio_sda        = WNDR3700_GPIO_RTL8366_SDA,
        .gpio_sck        = WNDR3700_GPIO_RTL8366_SCK,
 };
index b52cc601fccb1f4fd8630008c6efc879402f1faf..8ba0ee39b14bcd43ae28a0ddcff645478d77ccf7 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/nxp_74hc153.h>
-#include <linux/rtl8366s.h>
+#include <linux/rtl8366.h>
 
 #include <asm/mips_machine.h>
 #include <asm/mach-ar71xx/ar71xx.h>
@@ -212,7 +212,7 @@ static struct platform_device wzrhpg300nh_74hc153_device = {
        }
 };
 
-static struct rtl8366s_platform_data wzrhpg300nh_rtl8366s_data = {
+static struct rtl8366_platform_data wzrhpg300nh_rtl8366_data = {
        .gpio_sda        = WZRHPG300NH_GPIO_RTL8366_SDA,
        .gpio_sck        = WZRHPG300NH_GPIO_RTL8366_SCK,
 };
@@ -221,24 +221,44 @@ static struct platform_device wzrhpg300nh_rtl8366s_device = {
        .name           = RTL8366S_DRIVER_NAME,
        .id             = -1,
        .dev = {
-               .platform_data  = &wzrhpg300nh_rtl8366s_data,
+               .platform_data  = &wzrhpg300nh_rtl8366_data,
+       }
+};
+
+static struct platform_device wzrhpg301nh_rtl8366rb_device = {
+       .name           = RTL8366RB_DRIVER_NAME,
+       .id             = -1,
+       .dev = {
+               .platform_data  = &wzrhpg300nh_rtl8366_data,
        }
 };
 
 static void __init wzrhpg300nh_setup(void)
 {
        u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
+       bool hasrtl8366rb = false;
 
        ar71xx_set_mac_base(eeprom + WZRHPG300NH_MAC_OFFSET);
 
-       ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
-       ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
+       if (rtl8366_smi_detect(&wzrhpg300nh_rtl8366_data) == RTL8366_TYPE_RB)
+               hasrtl8366rb = true;
+
+       if (hasrtl8366rb) {
+               ar71xx_eth0_pll_data.pll_1000 = 0x1f000000;
+               ar71xx_eth0_data.mii_bus_dev = &wzrhpg301nh_rtl8366rb_device.dev;
+               ar71xx_eth1_pll_data.pll_1000 = 0x100;
+               ar71xx_eth1_data.mii_bus_dev = &wzrhpg301nh_rtl8366rb_device.dev;
+       } else {
+               ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
+               ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
+               ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
+               ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
+       }
+
        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
        ar71xx_eth0_data.speed = SPEED_1000;
        ar71xx_eth0_data.duplex = DUPLEX_FULL;
 
-       ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
-       ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
        ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
        ar71xx_eth1_data.phy_mask = 0x10;
 
index 28e1a8505d4fd490c54f9bee8b0850538bd11561..281c4536707b39f5d2fe34511b50a3d8e3ac6f8a 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/spinlock.h>
 #include <linux/skbuff.h>
+#include <linux/rtl8366.h>
 
 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
 #include <linux/debugfs.h>
@@ -1160,27 +1161,86 @@ struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent)
 }
 EXPORT_SYMBOL_GPL(rtl8366_smi_alloc);
 
-int rtl8366_smi_init(struct rtl8366_smi *smi)
+static int __rtl8366_smi_init(struct rtl8366_smi *smi, const char *name)
 {
        int err;
 
-       if (!smi->ops)
-               return -EINVAL;
-
-       err = gpio_request(smi->gpio_sda, dev_name(smi->parent));
+       err = gpio_request(smi->gpio_sda, name);
        if (err) {
-               dev_err(smi->parent, "gpio_request failed for %u, err=%d\n",
+               printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n",
                        smi->gpio_sda, err);
                goto err_out;
        }
 
-       err = gpio_request(smi->gpio_sck, dev_name(smi->parent));
+       err = gpio_request(smi->gpio_sck, name);
        if (err) {
-               dev_err(smi->parent, "gpio_request failed for %u, err=%d\n",
+               printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n",
                        smi->gpio_sck, err);
                goto err_free_sda;
        }
 
+       spin_lock_init(&smi->lock);
+       return 0;
+
+ err_free_sda:
+       gpio_free(smi->gpio_sda);
+ err_out:
+       return err;
+}
+
+static void __rtl8366_smi_cleanup(struct rtl8366_smi *smi)
+{
+       gpio_free(smi->gpio_sck);
+       gpio_free(smi->gpio_sda);
+}
+
+enum rtl8366_type rtl8366_smi_detect(struct rtl8366_platform_data *pdata)
+{
+       static struct rtl8366_smi smi;
+       enum rtl8366_type type = RTL8366_TYPE_UNKNOWN;
+       u32 reg = 0;
+
+       memset(&smi, 0, sizeof(smi));
+       smi.gpio_sda = pdata->gpio_sda;
+       smi.gpio_sck = pdata->gpio_sck;
+
+       if (__rtl8366_smi_init(&smi, "rtl8366"))
+               goto out;
+
+       if (rtl8366_smi_read_reg(&smi, 0x5c, &reg))
+               goto cleanup;
+
+       switch(reg) {
+       case 0x6027:
+               printk("Found an RTL8366S switch\n");
+               type = RTL8366_TYPE_S;
+               break;
+       case 0x5937:
+               printk("Found an RTL8366RB switch\n");
+               type = RTL8366_TYPE_RB;
+               break;
+       default:
+               printk("Found an Unknown RTL8366 switch (id=0x%04x)\n", reg);
+               break;
+       }
+
+cleanup:
+       __rtl8366_smi_cleanup(&smi);
+out:
+       return type;
+}
+
+int rtl8366_smi_init(struct rtl8366_smi *smi)
+{
+       int err;
+
+       if (!smi->ops)
+               return -EINVAL;
+
+       err = __rtl8366_smi_init(smi, dev_name(smi->parent));
+       if (err)
+               goto err_out;
+
        spin_lock_init(&smi->lock);
 
        dev_info(smi->parent, "using GPIO pins %u (SDA) and %u (SCK)\n",
@@ -1218,9 +1278,7 @@ int rtl8366_smi_init(struct rtl8366_smi *smi)
        return 0;
 
  err_free_sck:
-       gpio_free(smi->gpio_sck);
- err_free_sda:
-       gpio_free(smi->gpio_sda);
+       __rtl8366_smi_cleanup(smi);
  err_out:
        return err;
 }
index 90c37ad1f2e9df8b89d3f6b3aa2e4874138e1dd1..c813800a10ca666622a2fbea3250d611dd6ea558 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
-#include <linux/rtl8366rb.h>
+#include <linux/rtl8366.h>
 
 #include "rtl8366_smi.h"
 
@@ -1231,7 +1231,7 @@ static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
 static int __devinit rtl8366rb_probe(struct platform_device *pdev)
 {
        static int rtl8366_smi_version_printed;
-       struct rtl8366rb_platform_data *pdata;
+       struct rtl8366_platform_data *pdata;
        struct rtl8366_smi *smi;
        int err;
 
index 7e72164131b6c99fb59f23c790df5423a3e7f177..374b7b9c221bd91df84f9c2d4559ceb109c5c52e 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
-#include <linux/rtl8366s.h>
+#include <linux/rtl8366.h>
 
 #include "rtl8366_smi.h"
 
@@ -251,7 +251,7 @@ static int rtl8366s_reset_chip(struct rtl8366_smi *smi)
 
 static int rtl8366s_hw_init(struct rtl8366_smi *smi)
 {
-       struct rtl8366s_platform_data *pdata;
+       struct rtl8366_platform_data *pdata;
        int err;
 
        pdata = smi->parent->platform_data;
@@ -1060,7 +1060,7 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
 static int __devinit rtl8366s_probe(struct platform_device *pdev)
 {
        static int rtl8366_smi_version_printed;
-       struct rtl8366s_platform_data *pdata;
+       struct rtl8366_platform_data *pdata;
        struct rtl8366_smi *smi;
        int err;
 
diff --git a/target/linux/generic-2.6/files/include/linux/rtl8366.h b/target/linux/generic-2.6/files/include/linux/rtl8366.h
new file mode 100644 (file)
index 0000000..22ce614
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Platform data definition for the Realtek RTL8366RB/S ethernet switch driver
+ *
+ * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * 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.
+ */
+
+#ifndef _RTL8366_H
+#define _RTL8366_H
+
+#define RTL8366_DRIVER_NAME    "rtl8366"
+#define RTL8366S_DRIVER_NAME   "rtl8366s"
+#define RTL8366RB_DRIVER_NAME  "rtl8366rb"
+
+enum rtl8366_type {
+       RTL8366_TYPE_UNKNOWN,
+       RTL8366_TYPE_S,
+       RTL8366_TYPE_RB,
+};
+
+struct rtl8366_initval {
+       unsigned        reg;
+       u16             val;
+};
+
+struct rtl8366_platform_data {
+       unsigned        gpio_sda;
+       unsigned        gpio_sck;
+       unsigned        num_initvals;
+       struct rtl8366_initval *initvals;
+};
+
+enum rtl8366_type rtl8366_smi_detect(struct rtl8366_platform_data *pdata);
+
+#endif /*  _RTL8366_H */
diff --git a/target/linux/generic-2.6/files/include/linux/rtl8366rb.h b/target/linux/generic-2.6/files/include/linux/rtl8366rb.h
deleted file mode 100644 (file)
index 053e2ec..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Platform data definition for the Realtek RTL8366S ethernet switch driver
- *
- * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
- *
- * 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.
- */
-
-#ifndef _RTL8366RB_H
-#define _RTL8366RB_H
-
-#define RTL8366RB_DRIVER_NAME  "rtl8366rb"
-
-struct rtl8366rb_platform_data {
-       unsigned        gpio_sda;
-       unsigned        gpio_sck;
-};
-
-#endif /*  _RTL8366RB_SMI_H */
diff --git a/target/linux/generic-2.6/files/include/linux/rtl8366s.h b/target/linux/generic-2.6/files/include/linux/rtl8366s.h
deleted file mode 100644 (file)
index 7d5daa4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Platform data definition for the Realtek RTL8366S ethernet switch driver
- *
- * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
- *
- * 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.
- */
-
-#ifndef _RTL8366S_H
-#define _RTL8366S_H
-
-#define RTL8366S_DRIVER_NAME   "rtl8366s"
-
-struct rtl8366s_initval {
-       unsigned        reg;
-       u16             val;
-};
-
-struct rtl8366s_platform_data {
-       unsigned        gpio_sda;
-       unsigned        gpio_sck;
-       unsigned        num_initvals;
-       struct rtl8366s_initval *initvals;
-};
-
-#endif /*  _RTL8366_SMI_H */