Skip to content

Commit 94edc86

Browse files
committed
Merge branch 'dwmac-sti-refactor-cleanup'
Joachim Eastwood says: ==================== 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. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9811d1e + cb42d4b commit 94edc86

File tree

1 file changed

+58
-29
lines changed

1 file changed

+58
-29
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ struct sti_dwmac {
126126
struct clk *clk; /* PHY clock */
127127
u32 ctrl_reg; /* GMAC glue-logic control register */
128128
int clk_sel_reg; /* GMAC ext clk selection register */
129-
struct device *dev;
130129
struct regmap *regmap;
130+
bool gmac_en;
131131
u32 speed;
132132
void (*fix_retime_src)(void *priv, unsigned int speed);
133133
};
@@ -191,7 +191,7 @@ static void stih4xx_fix_retime_src(void *priv, u32 spd)
191191
}
192192
}
193193

194-
if (src == TX_RETIME_SRC_CLKGEN && dwmac->clk && freq)
194+
if (src == TX_RETIME_SRC_CLKGEN && freq)
195195
clk_set_rate(dwmac->clk, freq);
196196

197197
regmap_update_bits(dwmac->regmap, reg, STIH4XX_RETIME_SRC_MASK,
@@ -222,45 +222,32 @@ static void stid127_fix_retime_src(void *priv, u32 spd)
222222
freq = DWMAC_2_5MHZ;
223223
}
224224

225-
if (dwmac->clk && freq)
225+
if (freq)
226226
clk_set_rate(dwmac->clk, freq);
227227

228228
regmap_update_bits(dwmac->regmap, reg, STID127_RETIME_SRC_MASK, val);
229229
}
230230

231-
static int sti_dwmac_init(struct platform_device *pdev, void *priv)
231+
static int sti_dwmac_set_mode(struct sti_dwmac *dwmac)
232232
{
233-
struct sti_dwmac *dwmac = priv;
234233
struct regmap *regmap = dwmac->regmap;
235234
int iface = dwmac->interface;
236-
struct device *dev = dwmac->dev;
237-
struct device_node *np = dev->of_node;
238235
u32 reg = dwmac->ctrl_reg;
239236
u32 val;
240237

241-
if (dwmac->clk)
242-
clk_prepare_enable(dwmac->clk);
243-
244-
if (of_property_read_bool(np, "st,gmac_en"))
238+
if (dwmac->gmac_en)
245239
regmap_update_bits(regmap, reg, EN_MASK, EN);
246240

247241
regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK, phy_intf_sels[iface]);
248242

249243
val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
250244
regmap_update_bits(regmap, reg, ENMII_MASK, val);
251245

252-
dwmac->fix_retime_src(priv, dwmac->speed);
246+
dwmac->fix_retime_src(dwmac, dwmac->speed);
253247

254248
return 0;
255249
}
256250

257-
static void sti_dwmac_exit(struct platform_device *pdev, void *priv)
258-
{
259-
struct sti_dwmac *dwmac = priv;
260-
261-
if (dwmac->clk)
262-
clk_disable_unprepare(dwmac->clk);
263-
}
264251
static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
265252
struct platform_device *pdev)
266253
{
@@ -270,9 +257,6 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
270257
struct regmap *regmap;
271258
int err;
272259

273-
if (!np)
274-
return -EINVAL;
275-
276260
/* clk selection from extra syscfg register */
277261
dwmac->clk_sel_reg = -ENXIO;
278262
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-clkconf");
@@ -289,9 +273,9 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
289273
return err;
290274
}
291275

292-
dwmac->dev = dev;
293276
dwmac->interface = of_get_phy_mode(np);
294277
dwmac->regmap = regmap;
278+
dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en");
295279
dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk");
296280
dwmac->tx_retime_src = TX_RETIME_SRC_NA;
297281
dwmac->speed = SPEED_100;
@@ -357,17 +341,62 @@ static int sti_dwmac_probe(struct platform_device *pdev)
357341
dwmac->fix_retime_src = data->fix_retime_src;
358342

359343
plat_dat->bsp_priv = dwmac;
360-
plat_dat->init = sti_dwmac_init;
361-
plat_dat->exit = sti_dwmac_exit;
362344
plat_dat->fix_mac_speed = data->fix_retime_src;
363345

364-
ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
346+
ret = clk_prepare_enable(dwmac->clk);
365347
if (ret)
366348
return ret;
367349

368-
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
350+
ret = sti_dwmac_set_mode(dwmac);
351+
if (ret)
352+
goto disable_clk;
353+
354+
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
355+
if (ret)
356+
goto disable_clk;
357+
358+
return 0;
359+
360+
disable_clk:
361+
clk_disable_unprepare(dwmac->clk);
362+
return ret;
369363
}
370364

365+
static int sti_dwmac_remove(struct platform_device *pdev)
366+
{
367+
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
368+
int ret = stmmac_dvr_remove(&pdev->dev);
369+
370+
clk_disable_unprepare(dwmac->clk);
371+
372+
return ret;
373+
}
374+
375+
#ifdef CONFIG_PM_SLEEP
376+
static int sti_dwmac_suspend(struct device *dev)
377+
{
378+
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
379+
int ret = stmmac_suspend(dev);
380+
381+
clk_disable_unprepare(dwmac->clk);
382+
383+
return ret;
384+
}
385+
386+
static int sti_dwmac_resume(struct device *dev)
387+
{
388+
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
389+
390+
clk_prepare_enable(dwmac->clk);
391+
sti_dwmac_set_mode(dwmac);
392+
393+
return stmmac_resume(dev);
394+
}
395+
#endif /* CONFIG_PM_SLEEP */
396+
397+
static SIMPLE_DEV_PM_OPS(sti_dwmac_pm_ops, sti_dwmac_suspend,
398+
sti_dwmac_resume);
399+
371400
static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
372401
.fix_retime_src = stih4xx_fix_retime_src,
373402
};
@@ -387,10 +416,10 @@ MODULE_DEVICE_TABLE(of, sti_dwmac_match);
387416

388417
static struct platform_driver sti_dwmac_driver = {
389418
.probe = sti_dwmac_probe,
390-
.remove = stmmac_pltfr_remove,
419+
.remove = sti_dwmac_remove,
391420
.driver = {
392421
.name = "sti-dwmac",
393-
.pm = &stmmac_pltfr_pm_ops,
422+
.pm = &sti_dwmac_pm_ops,
394423
.of_match_table = sti_dwmac_match,
395424
},
396425
};

0 commit comments

Comments
 (0)