1 From 938dfdaa3c0f92e9a490d324f3bce43bbaef7632 Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 17 Jan 2014 21:24:42 +0800
4 Subject: [PATCH] net: stmmac: Allocate and pass soc/board specific data to
7 The current .init and .exit callbacks requires access to driver
8 private data structures. This is not a good seperation and abstraction.
10 Instead, we add a new .setup callback for allocating private data, and
11 pass the returned pointer to the other callbacks.
13 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 Documentation/networking/stmmac.txt | 12 ++++++++----
17 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 18 ++++++++++++++----
18 include/linux/stmmac.h | 6 ++++--
19 3 files changed, 26 insertions(+), 10 deletions(-)
21 diff --git a/Documentation/networking/stmmac.txt b/Documentation/networking/stmmac.txt
22 index cdd916d..2090895 100644
23 --- a/Documentation/networking/stmmac.txt
24 +++ b/Documentation/networking/stmmac.txt
25 @@ -127,8 +127,9 @@ struct plat_stmmacenet_data {
27 void (*fix_mac_speed)(void *priv, unsigned int speed);
28 void (*bus_setup)(void __iomem *ioaddr);
29 - int (*init)(struct platform_device *pdev);
30 - void (*exit)(struct platform_device *pdev);
31 + void *(*setup)(struct platform_device *pdev);
32 + int (*init)(struct platform_device *pdev, void *priv);
33 + void (*exit)(struct platform_device *pdev, void *priv);
37 @@ -169,10 +170,13 @@ Where:
38 o bus_setup: perform HW setup of the bus. For example, on some ST platforms
39 this field is used to configure the AMBA bridge to generate more
40 efficient STBus traffic.
41 - o init/exit: callbacks used for calling a custom initialization;
42 + o setup/init/exit: callbacks used for calling a custom initialization;
43 this is sometime necessary on some platforms (e.g. ST boxes)
44 where the HW needs to have set some PIO lines or system cfg
46 + registers. setup should return a pointer to private data,
47 + which will be stored in bsp_priv, and then passed to init and
48 + exit callbacks. init/exit callbacks should not use or modify
50 o custom_cfg/custom_data: this is a custom configuration that can be passed
51 while initializing the resources.
52 o bsp_priv: another private pointer.
53 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
54 index cc6b89a7..704a5e0 100644
55 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
56 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
57 @@ -144,9 +144,16 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
61 + /* Custom setup (if needed) */
62 + if (plat_dat->setup) {
63 + plat_dat->bsp_priv = plat_dat->setup(pdev);
64 + if (IS_ERR(plat_dat->bsp_priv))
65 + return PTR_ERR(plat_dat->bsp_priv);
68 /* Custom initialisation (if needed)*/
70 - ret = plat_dat->init(pdev);
71 + ret = plat_dat->init(pdev, plat_dat->bsp_priv);
75 @@ -203,7 +210,10 @@ static int stmmac_pltfr_remove(struct platform_device *pdev)
76 int ret = stmmac_dvr_remove(ndev);
79 - priv->plat->exit(pdev);
80 + priv->plat->exit(pdev, priv->plat->bsp_priv);
82 + if (priv->plat->free)
83 + priv->plat->free(pdev, priv->plat->bsp_priv);
87 @@ -218,7 +228,7 @@ static int stmmac_pltfr_suspend(struct device *dev)
89 ret = stmmac_suspend(ndev);
91 - priv->plat->exit(pdev);
92 + priv->plat->exit(pdev, priv->plat->bsp_priv);
96 @@ -230,7 +240,7 @@ static int stmmac_pltfr_resume(struct device *dev)
97 struct platform_device *pdev = to_platform_device(dev);
100 - priv->plat->init(pdev);
101 + priv->plat->init(pdev, priv->plat->bsp_priv);
103 return stmmac_resume(ndev);
105 diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
106 index 33ace71..0a5a7ac 100644
107 --- a/include/linux/stmmac.h
108 +++ b/include/linux/stmmac.h
109 @@ -113,8 +113,10 @@ struct plat_stmmacenet_data {
111 void (*fix_mac_speed)(void *priv, unsigned int speed);
112 void (*bus_setup)(void __iomem *ioaddr);
113 - int (*init)(struct platform_device *pdev);
114 - void (*exit)(struct platform_device *pdev);
115 + void *(*setup)(struct platform_device *pdev);
116 + void (*free)(struct platform_device *pdev, void *priv);
117 + int (*init)(struct platform_device *pdev, void *priv);
118 + void (*exit)(struct platform_device *pdev, void *priv);