stmmac: dwmac-sti refactor+cleanup
Subsystems (4)
v2 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.
Changes since v2:
- add missing static to sti_dwmac_pm_ops
- s/sti_dwmac_set_phy_mode/sti_dwmac_set_mode
- acked/tested by Giuseppe
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 | 87 ++++++++++++++++--------- 1 file changed, 58 insertions(+), 29 deletions(-)
Signature · 1 line
2.10.2
PATCH v2 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
@@ -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.2
PATCH v2 2/7 stmmac: dwmac-sti: remove clk NULL checks
In reply to Joachim EastwoodSince 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
@@ -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.2
PATCH v2 3/7 stmmac: dwmac-sti: add PM ops and resume function
In reply to Joachim EastwoodImplement 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 | 47 +++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +37 -10
@@ -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,41 @@ 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 */ + +static 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 +409,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.2
PATCH v2 4/7 stmmac: dwmac-sti: move st,gmac_en parsing to sti_dwmac_parse_data
In reply to Joachim EastwoodThe 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
@@ -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.2
PATCH v2 5/7 stmmac: dwmac-sti: move clk_prepare_enable out of init and add error handling
In reply to Joachim EastwoodAdd 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
@@ -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.2
PATCH v2 6/7 stmmac: dwmac-sti: clean up and rename sti_dwmac_init
In reply to Joachim EastwoodRename sti_dwmac_init to sti_dwmac_set_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
@@ -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_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_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_mode (dwmac);return stmmac_resume (dev); }
Signature · 1 line
2.10.2
PATCH v2 7/7 stmmac: dwmac-sti: remove unused priv dev member
In reply to Joachim EastwoodThe 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
@@ -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.2
David Miller
maintainerFrom: Joachim Eastwood <[email protected]>
Date: Fri, 4 Nov 2016 18:54:04 +0100
Quoted 4 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.
Quoted 8 lines
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.
Changes since v2:
- add missing static tosti_dwmac_pm_ops
- s/sti_dwmac_set_phy_mode/sti_dwmac_set_mode
- acked/tested by Giuseppe
Series applied, thanks.