Skip to contentSkip to conversation

stmmac: dwmac-sti refactor+cleanup

PATCH Superseded Joachim Eastwood 3 participants 15 messages Oct 30, 2016 – Nov 4, 2016

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover stmmac: dwmac-sti refactor+cleanup

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Note that this patch set has only been test compiled and no functional change is intended.

Joachim Eastwood (7):
stmmac: dwmac-sti: remove useless of_node check
stmmac: dwmac-sti: remove clk NULL checks
stmmac: dwmac-sti: add PM ops and resume function
stmmac: dwmac-sti: move st,gmac_en parsing to sti_dwmac_parse_data
stmmac: dwmac-sti: move clk_prepare_enable out of init and add error handling
stmmac: dwmac-sti: clean up and rename sti_dwmac_init
stmmac: dwmac-sti: remove unused priv dev member

 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 86 ++++++++++++++++---------
 1 file changed, 57 insertions(+), 29 deletions(-)
Signature · 1 line
2.10.1
#1 lore raw

PATCH 1/7 stmmac: dwmac-sti: remove useless of_node check

Since dwmac-sti is a DT only driver checking for OF node is not necessary.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +0 -3
index 58c05ac..075ed42 100644
@@ -270,9 +270,6 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
 	struct regmap *regmap;
 	int err;
 
-	if (!np)
-		return -EINVAL;
-
 	/* clk selection from extra syscfg register */
 	dwmac->clk_sel_reg = -ENXIO;
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-clkconf");
Signature · 1 line
2.10.1
#2 lore raw

PATCH 2/7 stmmac: dwmac-sti: remove clk NULL checks

In reply to Joachim Eastwood

Since sti_dwmac_parse_data() sets dwmac->clk to NULL if not clock was provided in DT and NULL is a valid clock there is no need to check for NULL before using this clock.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +4 -6
index 075ed42..f009bf4 100644
@@ -191,7 +191,7 @@ static void stih4xx_fix_retime_src(void *priv, u32 spd)
 		}
 	}
 
-	if (src == TX_RETIME_SRC_CLKGEN && dwmac->clk && freq)
+	if (src == TX_RETIME_SRC_CLKGEN && freq)
 		clk_set_rate(dwmac->clk, freq);
 
 	regmap_update_bits(dwmac->regmap, reg, STIH4XX_RETIME_SRC_MASK,
@@ -222,7 +222,7 @@ static void stid127_fix_retime_src(void *priv, u32 spd)
 			freq = DWMAC_2_5MHZ;
 	}
 
-	if (dwmac->clk && freq)
+	if (freq)
 		clk_set_rate(dwmac->clk, freq);
 
 	regmap_update_bits(dwmac->regmap, reg, STID127_RETIME_SRC_MASK, val);
@@ -238,8 +238,7 @@ static int sti_dwmac_init(struct platform_device *pdev, void *priv)
 	u32 reg = dwmac->ctrl_reg;
 	u32 val;
 
-	if (dwmac->clk)
-		clk_prepare_enable(dwmac->clk);
+	clk_prepare_enable(dwmac->clk);
 
 	if (of_property_read_bool(np, "st,gmac_en"))
 		regmap_update_bits(regmap, reg, EN_MASK, EN);
@@ -258,8 +257,7 @@ static void sti_dwmac_exit(struct platform_device *pdev, void *priv)
 {
 	struct sti_dwmac *dwmac = priv;
 
-	if (dwmac->clk)
-		clk_disable_unprepare(dwmac->clk);
+	clk_disable_unprepare(dwmac->clk);
 }
 static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
 				struct platform_device *pdev)
Signature · 1 line
2.10.1
#3 lore raw

PATCH 3/7 stmmac: dwmac-sti: add PM ops and resume function

In reply to Joachim Eastwood

Implement PM callbacks and driver remove in the driver instead of relying on the init/exit hooks in stmmac_platform. This gives the driver more flexibility in how the code is organized.

Eventually the init/exit callbacks will be deprecated in favor of the standard PM callbacks and driver remove function.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 46 +++++++++++++++++++------
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +36 -10
index f009bf4..09dd2be 100644
@@ -253,12 +253,6 @@ static int sti_dwmac_init(struct platform_device *pdev, void *priv)
 	return 0;
 }
 
-static void sti_dwmac_exit(struct platform_device *pdev, void *priv)
-{
-	struct sti_dwmac *dwmac = priv;
-
-	clk_disable_unprepare(dwmac->clk);
-}
 static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
 				struct platform_device *pdev)
 {
@@ -352,8 +346,6 @@ static int sti_dwmac_probe(struct platform_device *pdev)
 	dwmac->fix_retime_src = data->fix_retime_src;
 
 	plat_dat->bsp_priv = dwmac;
-	plat_dat->init = sti_dwmac_init;
-	plat_dat->exit = sti_dwmac_exit;
 	plat_dat->fix_mac_speed = data->fix_retime_src;
 
 	ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
@@ -363,6 +355,40 @@ static int sti_dwmac_probe(struct platform_device *pdev)
 	return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 }
 
+static int sti_dwmac_remove(struct platform_device *pdev)
+{
+	struct sti_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
+	int ret = stmmac_dvr_remove(&pdev->dev);
+
+	clk_disable_unprepare(dwmac->clk);
+
+	return ret;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int sti_dwmac_suspend(struct device *dev)
+{
+	struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
+	int ret = stmmac_suspend(dev);
+
+	clk_disable_unprepare(dwmac->clk);
+
+	return ret;
+}
+
+static int sti_dwmac_resume(struct device *dev)
+{
+	struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
+	struct platform_device *pdev = to_platform_device(dev);
+
+	sti_dwmac_init(pdev, dwmac);
+
+	return stmmac_resume(dev);
+}
+#endif /* CONFIG_PM_SLEEP */
+
+SIMPLE_DEV_PM_OPS(sti_dwmac_pm_ops, sti_dwmac_suspend, sti_dwmac_resume);
+
 static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
 	.fix_retime_src = stih4xx_fix_retime_src,
 };
@@ -382,10 +408,10 @@ MODULE_DEVICE_TABLE(of, sti_dwmac_match);
 
 static struct platform_driver sti_dwmac_driver = {
 	.probe  = sti_dwmac_probe,
-	.remove = stmmac_pltfr_remove,
+	.remove = sti_dwmac_remove,
 	.driver = {
 		.name           = "sti-dwmac",
-		.pm		= &stmmac_pltfr_pm_ops,
+		.pm		= &sti_dwmac_pm_ops,
 		.of_match_table = sti_dwmac_match,
 	},
 };
Signature · 1 line
2.10.1
#5 lore raw

PATCH 4/7 stmmac: dwmac-sti: move st,gmac_en parsing to sti_dwmac_parse_data

In reply to Joachim Eastwood

The sti_dwmac_init() function is called both from probe and resume. Since DT properties doesn't change between suspend/resume cycles move parsing of this parameter into sti_dwmac_parse_data() where it belongs.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +3 -3
index 09dd2be..e814b68 100644
@@ -128,6 +128,7 @@ struct sti_dwmac {
 	int clk_sel_reg;	/* GMAC ext clk selection register */
 	struct device *dev;
 	struct regmap *regmap;
+	bool gmac_en;
 	u32 speed;
 	void (*fix_retime_src)(void *priv, unsigned int speed);
 };
@@ -233,14 +234,12 @@ static int sti_dwmac_init(struct platform_device *pdev, void *priv)
 	struct sti_dwmac *dwmac = priv;
 	struct regmap *regmap = dwmac->regmap;
 	int iface = dwmac->interface;
-	struct device *dev = dwmac->dev;
-	struct device_node *np = dev->of_node;
 	u32 reg = dwmac->ctrl_reg;
 	u32 val;
 
 	clk_prepare_enable(dwmac->clk);
 
-	if (of_property_read_bool(np, "st,gmac_en"))
+	if (dwmac->gmac_en)
 		regmap_update_bits(regmap, reg, EN_MASK, EN);
 
 	regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK, phy_intf_sels[iface]);
@@ -281,6 +280,7 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
 	dwmac->dev = dev;
 	dwmac->interface = of_get_phy_mode(np);
 	dwmac->regmap = regmap;
+	dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en");
 	dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk");
 	dwmac->tx_retime_src = TX_RETIME_SRC_NA;
 	dwmac->speed = SPEED_100;
Signature · 1 line
2.10.1
#6 lore raw

PATCH 5/7 stmmac: dwmac-sti: move clk_prepare_enable out of init and add error handling

In reply to Joachim Eastwood

Add clock error handling to probe and in the process move clock enabling out of sti_dwmac_init() to make this easier.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +15 -4
index e814b68..aa75a27 100644
@@ -237,8 +237,6 @@ static int sti_dwmac_init(struct platform_device *pdev, void *priv)
 	u32 reg = dwmac->ctrl_reg;
 	u32 val;
 
-	clk_prepare_enable(dwmac->clk);
-
 	if (dwmac->gmac_en)
 		regmap_update_bits(regmap, reg, EN_MASK, EN);
 
@@ -348,11 +346,23 @@ static int sti_dwmac_probe(struct platform_device *pdev)
 	plat_dat->bsp_priv = dwmac;
 	plat_dat->fix_mac_speed = data->fix_retime_src;
 
-	ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
+	ret = clk_prepare_enable(dwmac->clk);
 	if (ret)
 		return ret;
 
-	return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
+	ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
+	if (ret)
+		goto disable_clk;
+
+	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
+	if (ret)
+		goto disable_clk;
+
+	return 0;
+
+disable_clk:
+	clk_disable_unprepare(dwmac->clk);
+	return ret;
 }
 
 static int sti_dwmac_remove(struct platform_device *pdev)
@@ -381,6 +391,7 @@ static int sti_dwmac_resume(struct device *dev)
 	struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
 	struct platform_device *pdev = to_platform_device(dev);
 
+	clk_prepare_enable(dwmac->clk);
 	sti_dwmac_init(pdev, dwmac);
 
 	return stmmac_resume(dev);
Signature · 1 line
2.10.1
#7 lore raw

PATCH 6/7 stmmac: dwmac-sti: clean up and rename sti_dwmac_init

In reply to Joachim Eastwood

Rename sti_dwmac_init to sti_dwmac_set_phy_mode which is a better description for what it really does.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +4 -6
index aa75a27..0af3faa 100644
@@ -229,9 +229,8 @@ static void stid127_fix_retime_src(void *priv, u32 spd)
 	regmap_update_bits(dwmac->regmap, reg, STID127_RETIME_SRC_MASK, val);
 }
 
-static int sti_dwmac_init(struct platform_device *pdev, void *priv)
+static int sti_dwmac_set_phy_mode(struct sti_dwmac *dwmac)
 {
-	struct sti_dwmac *dwmac = priv;
 	struct regmap *regmap = dwmac->regmap;
 	int iface = dwmac->interface;
 	u32 reg = dwmac->ctrl_reg;
@@ -245,7 +244,7 @@ static int sti_dwmac_init(struct platform_device *pdev, void *priv)
 	val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
 	regmap_update_bits(regmap, reg, ENMII_MASK, val);
 
-	dwmac->fix_retime_src(priv, dwmac->speed);
+	dwmac->fix_retime_src(dwmac, dwmac->speed);
 
 	return 0;
 }
@@ -350,7 +349,7 @@ static int sti_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
+	ret = sti_dwmac_set_phy_mode(dwmac);
 	if (ret)
 		goto disable_clk;
 
@@ -389,10 +388,9 @@ static int sti_dwmac_suspend(struct device *dev)
 static int sti_dwmac_resume(struct device *dev)
 {
 	struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
-	struct platform_device *pdev = to_platform_device(dev);
 
 	clk_prepare_enable(dwmac->clk);
-	sti_dwmac_init(pdev, dwmac);
+	sti_dwmac_set_phy_mode(dwmac);
 
 	return stmmac_resume(dev);
 }
Signature · 1 line
2.10.1
#8 lore raw

PATCH 7/7 stmmac: dwmac-sti: remove unused priv dev member

In reply to Joachim Eastwood

The dev member of struct sti_dwmac is not used anywhere in the driver so lets just remove it.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +0 -2
index 0af3faa..f51fb16 100644
@@ -126,7 +126,6 @@ struct sti_dwmac {
 	struct clk *clk;	/* PHY clock */
 	u32 ctrl_reg;		/* GMAC glue-logic control register */
 	int clk_sel_reg;	/* GMAC ext clk selection register */
-	struct device *dev;
 	struct regmap *regmap;
 	bool gmac_en;
 	u32 speed;
@@ -274,7 +273,6 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
 		return err;
 	}
 
-	dwmac->dev = dev;
 	dwmac->interface = of_get_phy_mode(np);
 	dwmac->regmap = regmap;
 	dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en");
Signature · 1 line
2.10.1
maintainer
#9 lore raw
In reply to Joachim Eastwood

From: Joachim Eastwood <[email protected]>
Date: Sun, 30 Oct 2016 21:05:00 +0100

Quoted 10 lines

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Note that this patch set has only been test compiled and no functional change is intended.

I would really like to see some review and testing before applying this series.

maintainer
#10 lore raw

From: David Miller <[email protected]>
Date: Mon, 31 Oct 2016 15:47:26 -0400 (EDT)

Quoted 11 lines

From: Joachim Eastwood <[email protected]>
Date: Sun, 30 Oct 2016 21:05:00 +0100

Quoted 8 lines

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Quoted 5 lines
Quoted 2 lines

Note that this patch set has only been test compiled and no functional change is intended.

I would really like to see some review and testing before applying this series.

Ping?

#11 lore raw

Hi,

Quoted 14 lines · David Miller

From: David Miller <[email protected]>
Date: Mon, 31 Oct 2016 15:47:26 -0400 (EDT)

Quoted 11 lines

From: Joachim Eastwood <[email protected]>
Date: Sun, 30 Oct 2016 21:05:00 +0100

Quoted 8 lines

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Note that this patch set has only been test compiled and no functional change is intended.

I would really like to see some review and testing before applying this series.

Ping?

Adding some more ST people.

Could anyone with a stih407 platform please give these patches a try?

The series can found at https://github.com/manabian/linux-lpc.git in the net-sti-dwmac branch (based on net-next). Alternatively they can also be picked from netdev's patchwork.

regards,
Joachim Eastwood

#4 lore raw

Re: [net-next PATCH 3/7] stmmac: dwmac-sti: add PM ops and resume function

In reply to Joachim Eastwood
Quoted 24 lines · Joachim Eastwood

Implement PM callbacks and driver remove in the driver instead of relying on the init/exit hooks in stmmac_platform. This gives the driver more flexibility in how the code is organized.

Eventually the init/exit callbacks will be deprecated in favor of the standard PM callbacks and driver remove function.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 46 +++++++++++++++++++------
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +13 -0
+#ifdef CONFIG_PM_SLEEP
+static int sti_dwmac_suspend(struct device *dev)
+{
+       struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
+       int ret = stmmac_suspend(dev);
+
+       clk_disable_unprepare(dwmac->clk);
+
+       return ret;
+}
+
+static int sti_dwmac_resume(struct device *dev)
+{

drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c static int sti_dwmac_probe(struct platform_device *pdev) · line 390

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +10 -0
+       struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
+       struct platform_device *pdev = to_platform_device(dev);
+
+       sti_dwmac_init(pdev, dwmac);
+
+       return stmmac_resume(dev);
+}
+#endif /* CONFIG_PM_SLEEP */
+
+SIMPLE_DEV_PM_OPS(sti_dwmac_pm_ops, sti_dwmac_suspend, sti_dwmac_resume);

Just noticed that I am missing a 'static' here.

As this not critical for testing I'll resend the patch set after I (hopefully) get some response from someone with the hw that can do a test.

regards,
Joachim Eastwood

#12 lore raw
In reply to Joachim Eastwood

Hello Joachim

thx for this series, I will review them and test the changes on my board asap ... I let you known.

Peppe

Quoted 23 lines · Joachim Eastwood

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Note that this patch set has only been test compiled and no functional change is intended.

Joachim Eastwood (7):
stmmac: dwmac-sti: remove useless of_node check
stmmac: dwmac-sti: remove clk NULL checks
stmmac: dwmac-sti: add PM ops and resume function
stmmac: dwmac-sti: move st,gmac_en parsing to sti_dwmac_parse_data
stmmac: dwmac-sti: move clk_prepare_enable out of init and add error handling
stmmac: dwmac-sti: clean up and rename sti_dwmac_init
stmmac: dwmac-sti: remove unused priv dev member

 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 86 ++++++++++++++++---------
 1 file changed, 57 insertions(+), 29 deletions(-)
#13 lore raw
In reply to Joachim Eastwood

Hello Joachim.

I have tested the patches on STiH390 with GMAC4 and the driver is ok.

So you can add my Acked-by/Tested-by in the V2.

I just ask you, when rename the sti_dwmac_init in sti_dwmac_set_phy_mode to use another name: sti_dwmac_set_mode could be good, IMO.

In fact, this function is not strictly related to the PHY and the system config registers could touch different MAC/MII settings.

Regards
Peppe

Quoted 23 lines · Joachim Eastwood

This patch set aims to remove the init/exit callbacks from the dwmac-sti driver and instead use standard PM callbacks. Doing this will also allow us to cleanup the driver.

Eventually the init/exit callbacks will be deprecated and removed from all drivers dwmac-* except for dwmac-generic. Drivers will be refactored to use standard PM and remove callbacks.

Note that this patch set has only been test compiled and no functional change is intended.

Joachim Eastwood (7):
stmmac: dwmac-sti: remove useless of_node check
stmmac: dwmac-sti: remove clk NULL checks
stmmac: dwmac-sti: add PM ops and resume function
stmmac: dwmac-sti: move st,gmac_en parsing to sti_dwmac_parse_data
stmmac: dwmac-sti: move clk_prepare_enable out of init and add error handling
stmmac: dwmac-sti: clean up and rename sti_dwmac_init
stmmac: dwmac-sti: remove unused priv dev member

 drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 86 ++++++++++++++++---------
 1 file changed, 57 insertions(+), 29 deletions(-)
#14 lore raw

Hi Giuseppe,

Quoted 5 lines · Giuseppe CAVALLARO

Hello Joachim.

I have tested the patches on STiH390 with GMAC4 and the driver is ok.

So you can add my Acked-by/Tested-by in the V2.

Thanks! I'll send a V2 later today or tomorrow.

Quoted 2 lines

I just ask you, when rename the sti_dwmac_init in sti_dwmac_set_phy_mode to use another name: sti_dwmac_set_mode could be good, IMO.

Sure thing.

regards,
Joachim Eastwood