stmmac: introduce stmmac_get_platform_resources()
authorJoachim Eastwood <manabian@gmail.com>
Thu, 16 Jul 2015 22:26:07 +0000 (00:26 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Jul 2015 03:45:56 +0000 (20:45 -0700)
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>
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

index 6e6ef859f58ad86f3c5a29e600750f2418ccfb68..94962d75b99ac0170b1570dbebf9cf7aeb04ed27 100644 (file)
@@ -262,33 +262,23 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
 }
 #endif /* CONFIG_OF */
 
-/**
- * stmmac_pltfr_probe - platform driver probe.
- * @pdev: platform device pointer
- * Description: platform_device probe function. It is to allocate
- * the necessary platform resources, invoke custom helper (if required) and
- * invoke the main probe function.
- */
-int stmmac_pltfr_probe(struct platform_device *pdev)
+static int stmmac_get_platform_resources(struct platform_device *pdev,
+                                        struct stmmac_resources *stmmac_res)
 {
-       struct stmmac_resources stmmac_res;
-       int ret = 0;
        struct resource *res;
-       struct device *dev = &pdev->dev;
-       struct plat_stmmacenet_data *plat_dat = NULL;
 
-       memset(&stmmac_res, 0, sizeof(stmmac_res));
+       memset(stmmac_res, 0, sizeof(*stmmac_res));
 
        /* Get IRQ information early to have an ability to ask for deferred
         * probe if needed before we went too far with resource allocation.
         */
-       stmmac_res.irq = platform_get_irq_byname(pdev, "macirq");
-       if (stmmac_res.irq < 0) {
-               if (stmmac_res.irq != -EPROBE_DEFER) {
-                       dev_err(dev,
+       stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
+       if (stmmac_res->irq < 0) {
+               if (stmmac_res->irq != -EPROBE_DEFER) {
+                       dev_err(&pdev->dev,
                                "MAC IRQ configuration information not found\n");
                }
-               return stmmac_res.irq;
+               return stmmac_res->irq;
        }
 
        /* 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)
         * In case the wake up interrupt is not passed from the platform
         * so the driver will continue to use the mac irq (ndev->irq)
         */
-       stmmac_res.wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
-       if (stmmac_res.wol_irq < 0) {
-               if (stmmac_res.wol_irq == -EPROBE_DEFER)
+       stmmac_res->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
+       if (stmmac_res->wol_irq < 0) {
+               if (stmmac_res->wol_irq == -EPROBE_DEFER)
                        return -EPROBE_DEFER;
-               stmmac_res.wol_irq = stmmac_res.irq;
+               stmmac_res->wol_irq = stmmac_res->irq;
        }
 
-       stmmac_res.lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
-       if (stmmac_res.lpi_irq == -EPROBE_DEFER)
+       stmmac_res->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
+       if (stmmac_res->lpi_irq == -EPROBE_DEFER)
                return -EPROBE_DEFER;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       stmmac_res.addr = devm_ioremap_resource(dev, res);
-       if (IS_ERR(stmmac_res.addr))
-               return PTR_ERR(stmmac_res.addr);
+       stmmac_res->addr = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(stmmac_res->addr))
+               return PTR_ERR(stmmac_res->addr);
+
+       return 0;
+}
+
+/**
+ * stmmac_pltfr_probe - platform driver probe.
+ * @pdev: platform device pointer
+ * Description: platform_device probe function. It is to allocate
+ * the necessary platform resources, invoke custom helper (if required) and
+ * invoke the main probe function.
+ */
+int stmmac_pltfr_probe(struct platform_device *pdev)
+{
+       struct plat_stmmacenet_data *plat_dat;
+       struct stmmac_resources stmmac_res;
+       int ret;
+
+       ret = stmmac_get_platform_resources(pdev, &stmmac_res);
+       if (ret)
+               return ret;
 
        if (pdev->dev.of_node) {
                ret = stmmac_probe_config_dt(pdev, &plat_dat, &stmmac_res.mac);