Skip to content

Commit f396cb0

Browse files
manabiandavem330
authored andcommitted
stmmac: introduce stmmac_get_platform_resources()
Refactor all code that deals with platform resources into it's own get function. This function will later be used in the probe function in dwmac-* drivers. Signed-off-by: Joachim Eastwood <manabian@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4ed2d8f commit f396cb0

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -262,33 +262,23 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
262262
}
263263
#endif /* CONFIG_OF */
264264

265-
/**
266-
* stmmac_pltfr_probe - platform driver probe.
267-
* @pdev: platform device pointer
268-
* Description: platform_device probe function. It is to allocate
269-
* the necessary platform resources, invoke custom helper (if required) and
270-
* invoke the main probe function.
271-
*/
272-
int stmmac_pltfr_probe(struct platform_device *pdev)
265+
static int stmmac_get_platform_resources(struct platform_device *pdev,
266+
struct stmmac_resources *stmmac_res)
273267
{
274-
struct stmmac_resources stmmac_res;
275-
int ret = 0;
276268
struct resource *res;
277-
struct device *dev = &pdev->dev;
278-
struct plat_stmmacenet_data *plat_dat = NULL;
279269

280-
memset(&stmmac_res, 0, sizeof(stmmac_res));
270+
memset(stmmac_res, 0, sizeof(*stmmac_res));
281271

282272
/* Get IRQ information early to have an ability to ask for deferred
283273
* probe if needed before we went too far with resource allocation.
284274
*/
285-
stmmac_res.irq = platform_get_irq_byname(pdev, "macirq");
286-
if (stmmac_res.irq < 0) {
287-
if (stmmac_res.irq != -EPROBE_DEFER) {
288-
dev_err(dev,
275+
stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
276+
if (stmmac_res->irq < 0) {
277+
if (stmmac_res->irq != -EPROBE_DEFER) {
278+
dev_err(&pdev->dev,
289279
"MAC IRQ configuration information not found\n");
290280
}
291-
return stmmac_res.irq;
281+
return stmmac_res->irq;
292282
}
293283

294284
/* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
@@ -298,21 +288,41 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
298288
* In case the wake up interrupt is not passed from the platform
299289
* so the driver will continue to use the mac irq (ndev->irq)
300290
*/
301-
stmmac_res.wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
302-
if (stmmac_res.wol_irq < 0) {
303-
if (stmmac_res.wol_irq == -EPROBE_DEFER)
291+
stmmac_res->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
292+
if (stmmac_res->wol_irq < 0) {
293+
if (stmmac_res->wol_irq == -EPROBE_DEFER)
304294
return -EPROBE_DEFER;
305-
stmmac_res.wol_irq = stmmac_res.irq;
295+
stmmac_res->wol_irq = stmmac_res->irq;
306296
}
307297

308-
stmmac_res.lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
309-
if (stmmac_res.lpi_irq == -EPROBE_DEFER)
298+
stmmac_res->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
299+
if (stmmac_res->lpi_irq == -EPROBE_DEFER)
310300
return -EPROBE_DEFER;
311301

312302
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
313-
stmmac_res.addr = devm_ioremap_resource(dev, res);
314-
if (IS_ERR(stmmac_res.addr))
315-
return PTR_ERR(stmmac_res.addr);
303+
stmmac_res->addr = devm_ioremap_resource(&pdev->dev, res);
304+
if (IS_ERR(stmmac_res->addr))
305+
return PTR_ERR(stmmac_res->addr);
306+
307+
return 0;
308+
}
309+
310+
/**
311+
* stmmac_pltfr_probe - platform driver probe.
312+
* @pdev: platform device pointer
313+
* Description: platform_device probe function. It is to allocate
314+
* the necessary platform resources, invoke custom helper (if required) and
315+
* invoke the main probe function.
316+
*/
317+
int stmmac_pltfr_probe(struct platform_device *pdev)
318+
{
319+
struct plat_stmmacenet_data *plat_dat;
320+
struct stmmac_resources stmmac_res;
321+
int ret;
322+
323+
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
324+
if (ret)
325+
return ret;
316326

317327
if (pdev->dev.of_node) {
318328
ret = stmmac_probe_config_dt(pdev, &plat_dat, &stmmac_res.mac);

0 commit comments

Comments
 (0)