kernel: add reset control support to rtl8366 driver
authorJohn Crispin <john@phrozen.org>
Wed, 23 May 2018 22:23:16 +0000 (00:23 +0200)
committerJohn Crispin <john@phrozen.org>
Thu, 24 May 2018 13:43:39 +0000 (15:43 +0200)
Signed-off-by: John Crispin <john@phrozen.org>
target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr1043nd.c
target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic/files/include/linux/rtl8366.h

index 61aeb52d02bbb7c9ae24388dcf796e34038cad25..4e4b85d7365eaa4d0ecd4ca277f3898354ce8cee 100644 (file)
@@ -83,7 +83,7 @@ static struct gpio_keys_button tl_wr1043nd_gpio_keys[] __initdata = {
        }
 };
 
-static void tl_wr1043nd_rtl8366rb_hw_reset(bool active)
+static void tl_wr1043nd_rtl8366rb_hw_reset(struct rtl8366_smi *smi, bool active)
 {
        if (active)
                ath79_device_reset_set(AR71XX_RESET_GE0_PHY);
@@ -110,7 +110,7 @@ static void __init tl_wr1043nd_setup(void)
        u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
        u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
 
-       tl_wr1043nd_rtl8366rb_hw_reset(true);
+       tl_wr1043nd_rtl8366rb_hw_reset(NULL, true);
 
        ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
        ath79_eth0_data.mii_bus_dev = &tl_wr1043nd_rtl8366rb_device.dev;
index c21ad9425de596908aeea750c4b97bf0a38baf07..00ad68e0bc5eb6236b419571d44b61e5f0b70f14 100644 (file)
@@ -319,9 +319,9 @@ EXPORT_SYMBOL_GPL(rtl8366_smi_rmwr);
 static int rtl8366_reset(struct rtl8366_smi *smi)
 {
        if (smi->hw_reset) {
-               smi->hw_reset(true);
+               smi->hw_reset(smi, true);
                msleep(RTL8366_SMI_HW_STOP_DELAY);
-               smi->hw_reset(false);
+               smi->hw_reset(smi, false);
                msleep(RTL8366_SMI_HW_START_DELAY);
                return 0;
        }
@@ -1300,7 +1300,7 @@ static int __rtl8366_smi_init(struct rtl8366_smi *smi, const char *name)
 
        /* start the switch */
        if (smi->hw_reset) {
-               smi->hw_reset(false);
+               smi->hw_reset(smi, false);
                msleep(RTL8366_SMI_HW_START_DELAY);
        }
 
@@ -1315,7 +1315,7 @@ static int __rtl8366_smi_init(struct rtl8366_smi *smi, const char *name)
 static void __rtl8366_smi_cleanup(struct rtl8366_smi *smi)
 {
        if (smi->hw_reset)
-               smi->hw_reset(true);
+               smi->hw_reset(smi, true);
 
        gpio_free(smi->gpio_sck);
        gpio_free(smi->gpio_sda);
@@ -1425,6 +1425,14 @@ void rtl8366_smi_cleanup(struct rtl8366_smi *smi)
 EXPORT_SYMBOL_GPL(rtl8366_smi_cleanup);
 
 #ifdef CONFIG_OF
+static void rtl8366_smi_reset(struct rtl8366_smi *smi, bool active)
+{
+       if (active)
+               reset_control_assert(smi->reset);
+       else
+               reset_control_deassert(smi->reset);
+}
+
 int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
 {
        int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0);
@@ -1437,6 +1445,9 @@ int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
 
        smi->gpio_sda = sda;
        smi->gpio_sck = sck;
+       smi->reset = devm_reset_control_get(&pdev->dev, "switch");
+       if (!IS_ERR(smi->reset))
+               smi->hw_reset = rtl8366_smi_reset;
 
        return 0;
 }
index 4bb9e9a66eea93426f7f60c71b76b051e9774d8c..e5f34bf9cfdc0ae603ec9627592ff32bbc77a610 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/phy.h>
 #include <linux/switch.h>
 #include <linux/platform_device.h>
+#include <linux/reset.h>
 
 struct rtl8366_smi_ops;
 struct rtl8366_vlan_ops;
@@ -33,7 +34,7 @@ struct rtl8366_smi {
        struct device           *parent;
        unsigned int            gpio_sda;
        unsigned int            gpio_sck;
-       void                    (*hw_reset)(bool active);
+       void                    (*hw_reset)(struct rtl8366_smi *smi, bool active);
        unsigned int            clk_delay;      /* ns */
        u8                      cmd_read;
        u8                      cmd_write;
@@ -54,6 +55,9 @@ struct rtl8366_smi {
        int                     vlan4k_enabled;
 
        char                    buf[4096];
+
+       struct reset_control    *reset;
+
 #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
        struct dentry           *debugfs_root;
        u16                     dbg_reg;
index 78daed22057540c785c071398f1ee9a073478aa1..e3ce8f5361eb57cb566129f635633572f7c916ee 100644 (file)
@@ -15,6 +15,8 @@
 #define RTL8366S_DRIVER_NAME   "rtl8366s"
 #define RTL8366RB_DRIVER_NAME  "rtl8366rb"
 
+struct rtl8366_smi;
+
 enum rtl8366_type {
        RTL8366_TYPE_UNKNOWN,
        RTL8366_TYPE_S,
@@ -29,7 +31,7 @@ struct rtl8366_initval {
 struct rtl8366_platform_data {
        unsigned        gpio_sda;
        unsigned        gpio_sck;
-       void            (*hw_reset)(bool active);
+       void            (*hw_reset)(struct rtl8366_smi *smi, bool active);
 
        unsigned        num_initvals;
        struct rtl8366_initval *initvals;