mediatek: rtl8367s: modernize gpio API
authorRosen Penev <[email protected]>
Thu, 18 Sep 2025 23:15:02 +0000 (16:15 -0700)
committerHauke Mehrtens <[email protected]>
Sat, 29 Nov 2025 20:08:39 +0000 (21:08 +0100)
Upstream is strongly considering removing of_gpio.h. As of this commit,
3 upstream drivers remain with actual usage.

Get ahead of upstream and use the GPIOD API before the OF one goes away.

Rework to remove mediatek,reset-pin in favor of the standard
reset-gpios.

Fix wrong high GPIO.

Signed-off-by: Rosen Penev <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/20088
Signed-off-by: Hauke Mehrtens <[email protected]>
target/linux/mediatek/dts/mt7622-buffalo-wsr-2533dhp2.dts
target/linux/mediatek/dts/mt7622-elecom-wrc-2533gent.dts
target/linux/mediatek/dts/mt7622-totolink-a8000ru.dts
target/linux/mediatek/files/drivers/net/phy/rtk/rtl8367s_mdio.c

index d016e4d328d7bebd43033e8f058f22ddda67776c..5211f2d8e5f54732ab2fb190826a8065cc3bfe21 100644 (file)
@@ -22,7 +22,7 @@
                compatible = "mediatek,rtk-gsw";
                mediatek,ethsys = <&ethsys>;
                mediatek,mdio = <&mdio>;
-               mediatek,reset-pin = <&pio 54 GPIO_ACTIVE_HIGH>;
+               reset-gpios = <&pio 54 GPIO_ACTIVE_LOW>;
        };
 };
 
index fa98310a0aca58c916a157627be77e05f475eac1..bddbd8219d819decd15f4c037d600ff9a064eb56 100644 (file)
                compatible = "mediatek,rtk-gsw";
                mediatek,ethsys = <&ethsys>;
                mediatek,mdio = <&mdio>;
-               mediatek,reset-pin = <&pio 54 0>;
+               reset-gpios = <&pio 54 GPIO_ACTIVE_LOW>;
                status = "okay";
        };
 };
index 5ec07128baaa7620b61e1543cf98934096276d25..5eaa2797c1bcb25169fea6a3fa6e0dbb128aab40 100644 (file)
@@ -95,7 +95,7 @@
                compatible = "mediatek,rtk-gsw";
                mediatek,ethsys = <&ethsys>;
                mediatek,mdio = <&mdio>;
-               mediatek,reset-pin = <&pio 54 0>;
+               reset-gpios = <&pio 54 GPIO_ACTIVE_LOW>;
                status = "okay";
        };
 };
index 2f9dc0da6bc1398e1c5ef7a91798f47962905a0a..537e226a19369c5be9231200ec7585d66beea302 100644 (file)
@@ -16,9 +16,9 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/of_mdio.h>
 #include <linux/of_platform.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 
 
@@ -31,7 +31,7 @@
 struct rtk_gsw {
        struct device           *dev;
        struct mii_bus          *bus;
-       int reset_pin;
+       struct gpio_desc        *reset_gpiod;
 };
 
 static struct rtk_gsw *_gsw;
@@ -67,14 +67,14 @@ static int rtl8367s_hw_reset(void)
 {
        struct rtk_gsw *gsw = _gsw;
 
-       if (gsw->reset_pin < 0)
+       if (!gsw->reset_gpiod)
                return 0;
 
-       gpio_direction_output(gsw->reset_pin, 0);
+       gpiod_set_value_cansleep(gsw->reset_gpiod, 1);
 
        usleep_range(1000, 1100);
 
-       gpio_set_value(gsw->reset_pin, 1);
+       gpiod_set_value_cansleep(gsw->reset_gpiod, 0);
 
        mdelay(500);
 
@@ -221,7 +221,6 @@ static int rtk_gsw_probe(struct platform_device *pdev)
        struct mii_bus *mdio_bus;
        struct rtk_gsw *gsw;
        const char *pm;
-       int ret;
 
        mdio = of_parse_phandle(np, "mediatek,mdio", 0);
 
@@ -242,12 +241,9 @@ static int rtk_gsw_probe(struct platform_device *pdev)
 
        gsw->bus = mdio_bus;
 
-       gsw->reset_pin = of_get_named_gpio(np, "mediatek,reset-pin", 0);
-       if (gsw->reset_pin >= 0) {
-               ret = devm_gpio_request(gsw->dev, gsw->reset_pin, "mediatek,reset-pin");
-               if (ret)
-                       printk("fail to devm_gpio_request\n");
-       }
+       gsw->reset_gpiod = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(gsw->reset_gpiod))
+               return dev_err_probe(&pdev->dev, PTR_ERR(gsw->reset_gpiod), "Failed to reset gpio");
 
        _gsw = gsw;