]> Pileus Git - ~andy/linux/commitdiff
net: stmmac: Allocate and pass soc/board specific data to callbacks
authorChen-Yu Tsai <wens@csie.org>
Fri, 17 Jan 2014 13:24:42 +0000 (21:24 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Jan 2014 04:02:02 +0000 (20:02 -0800)
The current .init and .exit callbacks requires access to driver
private data structures. This is not a good seperation and abstraction.

Instead, we add a new .setup callback for allocating private data, and
pass the returned pointer to the other callbacks.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Documentation/networking/stmmac.txt
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
include/linux/stmmac.h

index cdd916da838d44317974161311d1f81e2db2c233..2090895b08d42636a6bc9a4c4bfffacc04b6c94d 100644 (file)
@@ -127,8 +127,9 @@ struct plat_stmmacenet_data {
        int riwt_off;
        void (*fix_mac_speed)(void *priv, unsigned int speed);
        void (*bus_setup)(void __iomem *ioaddr);
-       int (*init)(struct platform_device *pdev);
-       void (*exit)(struct platform_device *pdev);
+       void *(*setup)(struct platform_device *pdev);
+       int (*init)(struct platform_device *pdev, void *priv);
+       void (*exit)(struct platform_device *pdev, void *priv);
        void *custom_cfg;
        void *custom_data;
        void *bsp_priv;
@@ -169,10 +170,13 @@ Where:
  o bus_setup: perform HW setup of the bus. For example, on some ST platforms
             this field is used to configure the AMBA  bridge to generate more
             efficient STBus traffic.
- o init/exit: callbacks used for calling a custom initialization;
+ o setup/init/exit: callbacks used for calling a custom initialization;
             this is sometime necessary on some platforms (e.g. ST boxes)
             where the HW needs to have set some PIO lines or system cfg
-            registers.
+            registers. setup should return a pointer to private data,
+            which will be stored in bsp_priv, and then passed to init and
+            exit callbacks. init/exit callbacks should not use or modify
+            platform data.
  o custom_cfg/custom_data: this is a custom configuration that can be passed
                           while initializing the resources.
  o bsp_priv: another private pointer.
index cc6b89a75f994538a800c67034d7ed26121eaf7a..704a5e0069c071653b78d32274b2be28f25b1785 100644 (file)
@@ -144,9 +144,16 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
                }
        }
 
+       /* Custom setup (if needed) */
+       if (plat_dat->setup) {
+               plat_dat->bsp_priv = plat_dat->setup(pdev);
+               if (IS_ERR(plat_dat->bsp_priv))
+                       return PTR_ERR(plat_dat->bsp_priv);
+       }
+
        /* Custom initialisation (if needed)*/
        if (plat_dat->init) {
-               ret = plat_dat->init(pdev);
+               ret = plat_dat->init(pdev, plat_dat->bsp_priv);
                if (unlikely(ret))
                        return ret;
        }
@@ -203,7 +210,10 @@ static int stmmac_pltfr_remove(struct platform_device *pdev)
        int ret = stmmac_dvr_remove(ndev);
 
        if (priv->plat->exit)
-               priv->plat->exit(pdev);
+               priv->plat->exit(pdev, priv->plat->bsp_priv);
+
+       if (priv->plat->free)
+               priv->plat->free(pdev, priv->plat->bsp_priv);
 
        return ret;
 }
@@ -218,7 +228,7 @@ static int stmmac_pltfr_suspend(struct device *dev)
 
        ret = stmmac_suspend(ndev);
        if (priv->plat->exit)
-               priv->plat->exit(pdev);
+               priv->plat->exit(pdev, priv->plat->bsp_priv);
 
        return ret;
 }
@@ -230,7 +240,7 @@ static int stmmac_pltfr_resume(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
 
        if (priv->plat->init)
-               priv->plat->init(pdev);
+               priv->plat->init(pdev, priv->plat->bsp_priv);
 
        return stmmac_resume(ndev);
 }
index 33ace712e7e818e7409732d77d9ea4583b7a78ad..0a5a7aca562e2d70f84f45752425684ab964da0a 100644 (file)
@@ -113,8 +113,10 @@ struct plat_stmmacenet_data {
        int max_speed;
        void (*fix_mac_speed)(void *priv, unsigned int speed);
        void (*bus_setup)(void __iomem *ioaddr);
-       int (*init)(struct platform_device *pdev);
-       void (*exit)(struct platform_device *pdev);
+       void *(*setup)(struct platform_device *pdev);
+       void (*free)(struct platform_device *pdev, void *priv);
+       int (*init)(struct platform_device *pdev, void *priv);
+       void (*exit)(struct platform_device *pdev, void *priv);
        void *custom_cfg;
        void *custom_data;
        void *bsp_priv;