]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: stmmac: pass struct device to init()/exit() methods
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Wed, 19 Nov 2025 10:03:50 +0000 (10:03 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 21 Nov 2025 01:54:07 +0000 (17:54 -0800)
As struct plat_stmmacenet_data is not platform_device specific, pass
a struct device into the init() and exit() methods to allow them to
become independent of the underlying device.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Acked-by: Chen-Yu Tsai <wens@kernel.org>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/E1vLf2U-0000000FMN2-0SLg@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
12 files changed:
drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c
drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
include/linux/stmmac.h

index 84072c8ed741c626813611c57a7762fa31bc82e7..5e0fc31762d9d8cc218b9b36c22d56fa7e288349 100644 (file)
@@ -34,7 +34,7 @@ static void gmac_write_reg(struct anarion_gmac *gmac, uint8_t reg, uint32_t val)
        writel(val, gmac->ctl_block + reg);
 }
 
-static int anarion_gmac_init(struct platform_device *pdev, void *priv)
+static int anarion_gmac_init(struct device *dev, void *priv)
 {
        uint32_t sw_config;
        struct anarion_gmac *gmac = priv;
@@ -52,7 +52,7 @@ static int anarion_gmac_init(struct platform_device *pdev, void *priv)
        return 0;
 }
 
-static void anarion_gmac_exit(struct platform_device *pdev, void *priv)
+static void anarion_gmac_exit(struct device *dev, void *priv)
 {
        struct anarion_gmac *gmac = priv;
 
index 1dcf2037001ef938ba3a8de8a548dfe5a1907357..bcb8e000e720b78f5a0aaf3fc067aa7d4e7ac475 100644 (file)
@@ -58,14 +58,14 @@ static int eic7700_clks_config(void *priv, bool enabled)
        return ret;
 }
 
-static int eic7700_dwmac_init(struct platform_device *pdev, void *priv)
+static int eic7700_dwmac_init(struct device *dev, void *priv)
 {
        struct eic7700_qos_priv *dwc = priv;
 
        return eic7700_clks_config(dwc, true);
 }
 
-static void eic7700_dwmac_exit(struct platform_device *pdev, void *priv)
+static void eic7700_dwmac_exit(struct device *dev, void *priv)
 {
        struct eic7700_qos_priv *dwc = priv;
 
index 894ee66f5c9bc1b27a9c03521672f87f46b1bec7..de9aba756aacb529bf0e623c43e8543f72c2f81e 100644 (file)
@@ -48,7 +48,7 @@ struct ls1x_dwmac {
 struct ls1x_data {
        int (*setup)(struct platform_device *pdev,
                     struct plat_stmmacenet_data *plat_dat);
-       int (*init)(struct platform_device *pdev, void *bsp_priv);
+       int (*init)(struct device *dev, void *bsp_priv);
 };
 
 static int ls1b_dwmac_setup(struct platform_device *pdev,
@@ -79,7 +79,7 @@ static int ls1b_dwmac_setup(struct platform_device *pdev,
        return 0;
 }
 
-static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+static int ls1b_dwmac_syscon_init(struct device *dev, void *priv)
 {
        struct ls1x_dwmac *dwmac = priv;
        struct plat_stmmacenet_data *plat = dwmac->plat_dat;
@@ -98,7 +98,7 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
                                           GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
                        break;
                default:
-                       dev_err(&pdev->dev, "Unsupported PHY mode %u\n",
+                       dev_err(dev, "Unsupported PHY mode %u\n",
                                plat->phy_interface);
                        return -EOPNOTSUPP;
                }
@@ -122,7 +122,7 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
                                           GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
                        break;
                default:
-                       dev_err(&pdev->dev, "Unsupported PHY mode %u\n",
+                       dev_err(dev, "Unsupported PHY mode %u\n",
                                plat->phy_interface);
                        return -EOPNOTSUPP;
                }
@@ -133,7 +133,7 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
        return 0;
 }
 
-static int ls1c_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+static int ls1c_dwmac_syscon_init(struct device *dev, void *priv)
 {
        struct ls1x_dwmac *dwmac = priv;
        struct plat_stmmacenet_data *plat = dwmac->plat_dat;
@@ -143,7 +143,7 @@ static int ls1c_dwmac_syscon_init(struct platform_device *pdev, void *priv)
        phy_intf_sel = stmmac_get_phy_intf_sel(plat->phy_interface);
        if (phy_intf_sel != PHY_INTF_SEL_GMII_MII &&
            phy_intf_sel != PHY_INTF_SEL_RMII) {
-               dev_err(&pdev->dev, "Unsupported PHY-mode %u\n",
+               dev_err(dev, "Unsupported PHY-mode %u\n",
                        plat->phy_interface);
                return -EOPNOTSUPP;
        }
index bc7bb975803ca08f71f97c2f4bea5d367a89a83b..be7f5eb2cdcf3e41c52db7bc8ff376a263afa58c 100644 (file)
@@ -91,7 +91,7 @@ static struct phylink_pcs *renesas_gmac_select_pcs(struct stmmac_priv *priv,
        return priv->hw->phylink_pcs;
 }
 
-static int renesas_gbeth_init(struct platform_device *pdev, void *priv)
+static int renesas_gbeth_init(struct device *dev, void *priv)
 {
        struct plat_stmmacenet_data *plat_dat;
        struct renesas_gbeth *gbeth = priv;
@@ -113,7 +113,7 @@ static int renesas_gbeth_init(struct platform_device *pdev, void *priv)
        return ret;
 }
 
-static void renesas_gbeth_exit(struct platform_device *pdev, void *priv)
+static void renesas_gbeth_exit(struct device *dev, void *priv)
 {
        struct plat_stmmacenet_data *plat_dat;
        struct renesas_gbeth *gbeth = priv;
index 2b7ad64bfdf7433db47a3e4546d42ec1b9f4733c..5a485ee98fa721e3b77d9fed19ab741e4b226924 100644 (file)
@@ -47,7 +47,7 @@ static int s32_gmac_write_phy_intf_select(struct s32_priv_data *gmac)
        return 0;
 }
 
-static int s32_gmac_init(struct platform_device *pdev, void *priv)
+static int s32_gmac_init(struct device *dev, void *priv)
 {
        struct s32_priv_data *gmac = priv;
        int ret;
@@ -55,31 +55,31 @@ static int s32_gmac_init(struct platform_device *pdev, void *priv)
        /* Set initial TX interface clock */
        ret = clk_prepare_enable(gmac->tx_clk);
        if (ret) {
-               dev_err(&pdev->dev, "Can't enable tx clock\n");
+               dev_err(dev, "Can't enable tx clock\n");
                return ret;
        }
        ret = clk_set_rate(gmac->tx_clk, GMAC_INTF_RATE_125M);
        if (ret) {
-               dev_err(&pdev->dev, "Can't set tx clock\n");
+               dev_err(dev, "Can't set tx clock\n");
                goto err_tx_disable;
        }
 
        /* Set initial RX interface clock */
        ret = clk_prepare_enable(gmac->rx_clk);
        if (ret) {
-               dev_err(&pdev->dev, "Can't enable rx clock\n");
+               dev_err(dev, "Can't enable rx clock\n");
                goto err_tx_disable;
        }
        ret = clk_set_rate(gmac->rx_clk, GMAC_INTF_RATE_125M);
        if (ret) {
-               dev_err(&pdev->dev, "Can't set rx clock\n");
+               dev_err(dev, "Can't set rx clock\n");
                goto err_txrx_disable;
        }
 
        /* Set interface mode */
        ret = s32_gmac_write_phy_intf_select(gmac);
        if (ret) {
-               dev_err(&pdev->dev, "Can't set PHY interface mode\n");
+               dev_err(dev, "Can't set PHY interface mode\n");
                goto err_txrx_disable;
        }
 
@@ -92,7 +92,7 @@ err_tx_disable:
        return ret;
 }
 
-static void s32_gmac_exit(struct platform_device *pdev, void *priv)
+static void s32_gmac_exit(struct device *dev, void *priv)
 {
        struct s32_priv_data *gmac = priv;
 
index 49d651948e2bd41faeecaebb37121aef757a66a7..a2b52d2c4eb6f6cc45f4e628dcd2a78db529b6a9 100644 (file)
@@ -551,7 +551,7 @@ static struct phylink_pcs *socfpga_dwmac_select_pcs(struct stmmac_priv *priv,
        return priv->hw->phylink_pcs;
 }
 
-static int socfpga_dwmac_init(struct platform_device *pdev, void *bsp_priv)
+static int socfpga_dwmac_init(struct device *dev, void *bsp_priv)
 {
        struct socfpga_dwmac *dwmac = bsp_priv;
 
index b0509ab6b31cadadc7a303faff4f1322a9bb08bd..f50547b67fbc87a1c5550dd17b266a13aed3d0f8 100644 (file)
@@ -229,14 +229,14 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
        return 0;
 }
 
-static int sti_dwmac_init(struct platform_device *pdev, void *bsp_priv)
+static int sti_dwmac_init(struct device *dev, void *bsp_priv)
 {
        struct sti_dwmac *dwmac = bsp_priv;
 
        return clk_prepare_enable(dwmac->clk);
 }
 
-static void sti_dwmac_exit(struct platform_device *pdev, void *bsp_priv)
+static void sti_dwmac_exit(struct device *dev, void *bsp_priv)
 {
        struct sti_dwmac *dwmac = bsp_priv;
 
index 7434d4bbb52609049598a5de5aec28c355645a5b..8aa496ac85cce5bc3e2bcec5ceb880ada79e472c 100644 (file)
@@ -571,16 +571,16 @@ static const struct stmmac_dma_ops sun8i_dwmac_dma_ops = {
 
 static int sun8i_dwmac_power_internal_phy(struct stmmac_priv *priv);
 
-static int sun8i_dwmac_init(struct platform_device *pdev, void *priv)
+static int sun8i_dwmac_init(struct device *dev, void *priv)
 {
-       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct net_device *ndev = dev_get_drvdata(dev);
        struct sunxi_priv_data *gmac = priv;
        int ret;
 
        if (gmac->regulator) {
                ret = regulator_enable(gmac->regulator);
                if (ret) {
-                       dev_err(&pdev->dev, "Fail to enable regulator\n");
+                       dev_err(dev, "Fail to enable regulator\n");
                        return ret;
                }
        }
@@ -1005,7 +1005,7 @@ static void sun8i_dwmac_unset_syscon(struct sunxi_priv_data *gmac)
                                   (H3_EPHY_SHUTDOWN | H3_EPHY_SELECT));
 }
 
-static void sun8i_dwmac_exit(struct platform_device *pdev, void *priv)
+static void sun8i_dwmac_exit(struct device *dev, void *priv)
 {
        struct sunxi_priv_data *gmac = priv;
 
@@ -1265,7 +1265,7 @@ static void sun8i_dwmac_shutdown(struct platform_device *pdev)
        struct stmmac_priv *priv = netdev_priv(ndev);
        struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
 
-       sun8i_dwmac_exit(pdev, gmac);
+       sun8i_dwmac_exit(&pdev->dev, gmac);
 }
 
 static const struct of_device_id sun8i_dwmac_match[] = {
index 7f560d78209d1677a414b7873173f24ecf4bd1cf..52593ba3a3a317e3d99f943e1ef654808b824f74 100644 (file)
@@ -27,7 +27,7 @@ struct sunxi_priv_data {
 #define SUN7I_GMAC_GMII_RGMII_RATE     125000000
 #define SUN7I_GMAC_MII_RATE            25000000
 
-static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
+static int sun7i_gmac_init(struct device *dev, void *priv)
 {
        struct sunxi_priv_data *gmac = priv;
        int ret = 0;
@@ -58,7 +58,7 @@ static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
        return ret;
 }
 
-static void sun7i_gmac_exit(struct platform_device *pdev, void *priv)
+static void sun7i_gmac_exit(struct device *dev, void *priv)
 {
        struct sunxi_priv_data *gmac = priv;
 
index a3378046b061e9a06aac25d796161200c4574bbf..e291028ba56e818196dde2ebe239a8e4d2d3710e 100644 (file)
@@ -186,7 +186,7 @@ static int thead_dwmac_enable_clk(struct plat_stmmacenet_data *plat)
        return 0;
 }
 
-static int thead_dwmac_init(struct platform_device *pdev, void *priv)
+static int thead_dwmac_init(struct device *dev, void *priv)
 {
        struct thead_dwmac *dwmac = priv;
        unsigned int reg;
index 1fefa6c55db1c5bcb2d769ab6de355f660f99105..feccb8a3e7e861c6ba6261b8ba7285191c0ad256 100644 (file)
@@ -747,40 +747,40 @@ EXPORT_SYMBOL_GPL(stmmac_get_platform_resources);
 
 /**
  * stmmac_pltfr_init
- * @pdev: pointer to the platform device
+ * @dev: pointer to the device structure
  * @plat: driver data platform structure
  * Description: Call the platform's init callback (if any) and propagate
  * the return value.
  */
-static int stmmac_pltfr_init(struct platform_device *pdev,
+static int stmmac_pltfr_init(struct device *dev,
                             struct plat_stmmacenet_data *plat)
 {
        int ret = 0;
 
        if (plat->init)
-               ret = plat->init(pdev, plat->bsp_priv);
+               ret = plat->init(dev, plat->bsp_priv);
 
        return ret;
 }
 
 /**
  * stmmac_pltfr_exit
- * @pdev: pointer to the platform device
+ * @dev: pointer to the device structure
  * @plat: driver data platform structure
  * Description: Call the platform's exit callback (if any).
  */
-static void stmmac_pltfr_exit(struct platform_device *pdev,
+static void stmmac_pltfr_exit(struct device *dev,
                              struct plat_stmmacenet_data *plat)
 {
        if (plat->exit)
-               plat->exit(pdev, plat->bsp_priv);
+               plat->exit(dev, plat->bsp_priv);
 }
 
 static int stmmac_plat_suspend(struct device *dev, void *bsp_priv)
 {
        struct stmmac_priv *priv = netdev_priv(dev_get_drvdata(dev));
 
-       stmmac_pltfr_exit(to_platform_device(dev), priv->plat);
+       stmmac_pltfr_exit(dev, priv->plat);
 
        return 0;
 }
@@ -789,7 +789,7 @@ static int stmmac_plat_resume(struct device *dev, void *bsp_priv)
 {
        struct stmmac_priv *priv = netdev_priv(dev_get_drvdata(dev));
 
-       return stmmac_pltfr_init(to_platform_device(dev), priv->plat);
+       return stmmac_pltfr_init(dev, priv->plat);
 }
 
 /**
@@ -804,6 +804,7 @@ int stmmac_pltfr_probe(struct platform_device *pdev,
                       struct plat_stmmacenet_data *plat,
                       struct stmmac_resources *res)
 {
+       struct device *dev = &pdev->dev;
        int ret;
 
        if (!plat->suspend && plat->exit)
@@ -811,13 +812,13 @@ int stmmac_pltfr_probe(struct platform_device *pdev,
        if (!plat->resume && plat->init)
                plat->resume = stmmac_plat_resume;
 
-       ret = stmmac_pltfr_init(pdev, plat);
+       ret = stmmac_pltfr_init(dev, plat);
        if (ret)
                return ret;
 
-       ret = stmmac_dvr_probe(&pdev->dev, plat, res);
+       ret = stmmac_dvr_probe(dev, plat, res);
        if (ret) {
-               stmmac_pltfr_exit(pdev, plat);
+               stmmac_pltfr_exit(dev, plat);
                return ret;
        }
 
@@ -866,9 +867,10 @@ void stmmac_pltfr_remove(struct platform_device *pdev)
        struct net_device *ndev = platform_get_drvdata(pdev);
        struct stmmac_priv *priv = netdev_priv(ndev);
        struct plat_stmmacenet_data *plat = priv->plat;
+       struct device *dev = &pdev->dev;
 
-       stmmac_dvr_remove(&pdev->dev);
-       stmmac_pltfr_exit(pdev, plat);
+       stmmac_dvr_remove(dev);
+       stmmac_pltfr_exit(dev, plat);
 }
 EXPORT_SYMBOL_GPL(stmmac_pltfr_remove);
 
index 4f70a6551e68c8a3014789f4e66d9e1db3210c44..673b068fdadf4e2420574dcb44d280985121b56a 100644 (file)
@@ -264,8 +264,8 @@ struct plat_stmmacenet_data {
                          unsigned int mode,
                          phy_interface_t interface);
        void (*ptp_clk_freq_config)(struct stmmac_priv *priv);
-       int (*init)(struct platform_device *pdev, void *priv);
-       void (*exit)(struct platform_device *pdev, void *priv);
+       int (*init)(struct device *dev, void *priv);
+       void (*exit)(struct device *dev, void *priv);
        int (*suspend)(struct device *dev, void *priv);
        int (*resume)(struct device *dev, void *priv);
        int (*mac_setup)(void *priv, struct mac_device_info *mac);