Skip to content

Commit 2c1bcaf

Browse files
committed
Merge branch 'stmmac-cleanup'
Joachim Eastwood says: ==================== stmmac clean up for 4.3 part1 This patch set continues the conversion of the dwmac glue layers to more proper platform drivers. The first part of the patch set cleans up stmmac_platform a bit. Refactors code from the common probe function and exports two functions that will be used in the dwmac-* drivers. Second part converts two simple dwmac-* drivers to have their own probe function and use the exported functions. This brings us closer to point where stmmac_platform is only a library of common functions for the dwmac-* drivers to use. The plan next is: * add probe functions to the rest of the dwmac-* drivers * move probe function in stmmac_platform to dwmac-generic * remove struct stmmac_of_data and let those drivers that actually need match data handle it themselves * clean up include/linux/stmmac.h Note that this patch set has only been tested on lpc18xx so testing on other platforms is greatly appreciated. Previous parts can be found here: http://www.spinics.net/lists/netdev/msg328997.html http://www.spinics.net/lists/netdev/msg329932.html ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 7781e5d + f4c190e commit 2c1bcaf

File tree

6 files changed

+126
-114
lines changed

6 files changed

+126
-114
lines changed

Documentation/networking/stmmac.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ struct plat_stmmacenet_data {
139139
void (*free)(struct platform_device *pdev, void *priv);
140140
int (*init)(struct platform_device *pdev, void *priv);
141141
void (*exit)(struct platform_device *pdev, void *priv);
142-
void *custom_cfg;
143-
void *custom_data;
144142
void *bsp_priv;
145143
};
146144

@@ -186,8 +184,6 @@ Where:
186184
which will be stored in bsp_priv, and then passed to init and
187185
exit callbacks. init/exit callbacks should not use or modify
188186
platform data.
189-
o custom_cfg/custom_data: this is a custom configuration that can be passed
190-
while initializing the resources.
191187
o bsp_priv: another private pointer.
192188

193189
For MDIO bus The we have:

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

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,66 +25,53 @@
2525
# define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
2626
# define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
2727

28-
struct lpc18xx_dwmac_priv_data {
28+
static int lpc18xx_dwmac_probe(struct platform_device *pdev)
29+
{
30+
struct plat_stmmacenet_data *plat_dat;
31+
struct stmmac_resources stmmac_res;
2932
struct regmap *reg;
30-
int interface;
31-
};
33+
u8 ethmode;
34+
int ret;
3235

33-
static void *lpc18xx_dwmac_setup(struct platform_device *pdev)
34-
{
35-
struct lpc18xx_dwmac_priv_data *dwmac;
36+
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
37+
if (ret)
38+
return ret;
3639

37-
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
38-
if (!dwmac)
39-
return ERR_PTR(-ENOMEM);
40+
plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
41+
if (IS_ERR(plat_dat))
42+
return PTR_ERR(plat_dat);
4043

41-
dwmac->interface = of_get_phy_mode(pdev->dev.of_node);
42-
if (dwmac->interface < 0)
43-
return ERR_PTR(dwmac->interface);
44+
plat_dat->has_gmac = true;
4445

45-
dwmac->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
46-
if (IS_ERR(dwmac->reg)) {
47-
dev_err(&pdev->dev, "Syscon lookup failed\n");
48-
return dwmac->reg;
46+
reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
47+
if (IS_ERR(reg)) {
48+
dev_err(&pdev->dev, "syscon lookup failed\n");
49+
return PTR_ERR(reg);
4950
}
5051

51-
return dwmac;
52-
}
53-
54-
static int lpc18xx_dwmac_init(struct platform_device *pdev, void *priv)
55-
{
56-
struct lpc18xx_dwmac_priv_data *dwmac = priv;
57-
u8 ethmode;
58-
59-
if (dwmac->interface == PHY_INTERFACE_MODE_MII) {
52+
if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
6053
ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
61-
} else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
54+
} else if (plat_dat->interface == PHY_INTERFACE_MODE_RMII) {
6255
ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
6356
} else {
6457
dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
6558
return -EINVAL;
6659
}
6760

68-
regmap_update_bits(dwmac->reg, LPC18XX_CREG_CREG6,
61+
regmap_update_bits(reg, LPC18XX_CREG_CREG6,
6962
LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
7063

71-
return 0;
64+
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
7265
}
7366

74-
static const struct stmmac_of_data lpc18xx_dwmac_data = {
75-
.has_gmac = 1,
76-
.setup = lpc18xx_dwmac_setup,
77-
.init = lpc18xx_dwmac_init,
78-
};
79-
8067
static const struct of_device_id lpc18xx_dwmac_match[] = {
81-
{ .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
68+
{ .compatible = "nxp,lpc1850-dwmac" },
8269
{ }
8370
};
8471
MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
8572

8673
static struct platform_driver lpc18xx_dwmac_driver = {
87-
.probe = stmmac_pltfr_probe,
74+
.probe = lpc18xx_dwmac_probe,
8875
.remove = stmmac_pltfr_remove,
8976
.driver = {
9077
.name = "lpc18xx-dwmac",

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,45 @@ static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed)
4747
writel(val, dwmac->reg);
4848
}
4949

50-
static void *meson6_dwmac_setup(struct platform_device *pdev)
50+
static int meson6_dwmac_probe(struct platform_device *pdev)
5151
{
52+
struct plat_stmmacenet_data *plat_dat;
53+
struct stmmac_resources stmmac_res;
5254
struct meson_dwmac *dwmac;
5355
struct resource *res;
56+
int ret;
57+
58+
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
59+
if (ret)
60+
return ret;
61+
62+
plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
63+
if (IS_ERR(plat_dat))
64+
return PTR_ERR(plat_dat);
5465

5566
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
5667
if (!dwmac)
57-
return ERR_PTR(-ENOMEM);
68+
return -ENOMEM;
5869

5970
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
6071
dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
6172
if (IS_ERR(dwmac->reg))
62-
return ERR_CAST(dwmac->reg);
73+
return PTR_ERR(dwmac->reg);
6374

64-
return dwmac;
65-
}
75+
plat_dat->bsp_priv = dwmac;
76+
plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
6677

67-
static const struct stmmac_of_data meson6_dwmac_data = {
68-
.setup = meson6_dwmac_setup,
69-
.fix_mac_speed = meson6_dwmac_fix_mac_speed,
70-
};
78+
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
79+
}
7180

7281
static const struct of_device_id meson6_dwmac_match[] = {
73-
{ .compatible = "amlogic,meson6-dwmac", .data = &meson6_dwmac_data},
82+
{ .compatible = "amlogic,meson6-dwmac" },
7483
{ }
7584
};
7685
MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
7786

7887
static struct platform_driver meson6_dwmac_driver = {
79-
.probe = stmmac_pltfr_probe,
88+
.probe = meson6_dwmac_probe,
8089
.remove = stmmac_pltfr_remove,
8190
.driver = {
8291
.name = "meson6-dwmac",

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

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,20 @@ static int dwmac1000_validate_ucast_entries(int ucast_entries)
104104
* this function is to read the driver parameters from device-tree and
105105
* set some private fields that will be used by the main at runtime.
106106
*/
107-
static int stmmac_probe_config_dt(struct platform_device *pdev,
108-
struct plat_stmmacenet_data *plat,
109-
const char **mac)
107+
struct plat_stmmacenet_data *
108+
stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
110109
{
111110
struct device_node *np = pdev->dev.of_node;
111+
struct plat_stmmacenet_data *plat;
112+
const struct stmmac_of_data *data;
112113
struct stmmac_dma_cfg *dma_cfg;
113-
const struct of_device_id *device;
114-
struct device *dev = &pdev->dev;
115114

116-
device = of_match_device(dev->driver->of_match_table, dev);
117-
if (device->data) {
118-
const struct stmmac_of_data *data = device->data;
115+
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
116+
if (!plat)
117+
return ERR_PTR(-ENOMEM);
118+
119+
data = of_device_get_match_data(&pdev->dev);
120+
if (data) {
119121
plat->has_gmac = data->has_gmac;
120122
plat->enh_desc = data->enh_desc;
121123
plat->tx_coe = data->tx_coe;
@@ -151,7 +153,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
151153
/* If phy-handle is not specified, check if we have a fixed-phy */
152154
if (!plat->phy_node && of_phy_is_fixed_link(np)) {
153155
if ((of_phy_register_fixed_link(np) < 0))
154-
return -ENODEV;
156+
return ERR_PTR(-ENODEV);
155157

156158
plat->phy_node = of_node_get(np);
157159
}
@@ -182,6 +184,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
182184
*/
183185
plat->maxmtu = JUMBO_LEN;
184186

187+
/* Set default value for multicast hash bins */
188+
plat->multicast_filter_bins = HASH_TABLE_SIZE;
189+
190+
/* Set default value for unicast filter entries */
191+
plat->unicast_filter_entries = 1;
192+
185193
/*
186194
* Currently only the properties needed on SPEAr600
187195
* are provided. All other properties should be added
@@ -222,7 +230,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
222230
GFP_KERNEL);
223231
if (!dma_cfg) {
224232
of_node_put(np);
225-
return -ENOMEM;
233+
return ERR_PTR(-ENOMEM);
226234
}
227235
plat->dma_cfg = dma_cfg;
228236
of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
@@ -240,44 +248,34 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
240248
pr_warn("force_sf_dma_mode is ignored if force_thresh_dma_mode is set.");
241249
}
242250

243-
return 0;
251+
return plat;
244252
}
245253
#else
246-
static int stmmac_probe_config_dt(struct platform_device *pdev,
247-
struct plat_stmmacenet_data *plat,
248-
const char **mac)
254+
struct plat_stmmacenet_data *
255+
stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
249256
{
250-
return -ENOSYS;
257+
return ERR_PTR(-ENOSYS);
251258
}
252259
#endif /* CONFIG_OF */
260+
EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
253261

254-
/**
255-
* stmmac_pltfr_probe - platform driver probe.
256-
* @pdev: platform device pointer
257-
* Description: platform_device probe function. It is to allocate
258-
* the necessary platform resources, invoke custom helper (if required) and
259-
* invoke the main probe function.
260-
*/
261-
int stmmac_pltfr_probe(struct platform_device *pdev)
262+
int stmmac_get_platform_resources(struct platform_device *pdev,
263+
struct stmmac_resources *stmmac_res)
262264
{
263-
struct stmmac_resources stmmac_res;
264-
int ret = 0;
265265
struct resource *res;
266-
struct device *dev = &pdev->dev;
267-
struct plat_stmmacenet_data *plat_dat = NULL;
268266

269-
memset(&stmmac_res, 0, sizeof(stmmac_res));
267+
memset(stmmac_res, 0, sizeof(*stmmac_res));
270268

271269
/* Get IRQ information early to have an ability to ask for deferred
272270
* probe if needed before we went too far with resource allocation.
273271
*/
274-
stmmac_res.irq = platform_get_irq_byname(pdev, "macirq");
275-
if (stmmac_res.irq < 0) {
276-
if (stmmac_res.irq != -EPROBE_DEFER) {
277-
dev_err(dev,
272+
stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
273+
if (stmmac_res->irq < 0) {
274+
if (stmmac_res->irq != -EPROBE_DEFER) {
275+
dev_err(&pdev->dev,
278276
"MAC IRQ configuration information not found\n");
279277
}
280-
return stmmac_res.irq;
278+
return stmmac_res->irq;
281279
}
282280

283281
/* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
@@ -287,45 +285,61 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
287285
* In case the wake up interrupt is not passed from the platform
288286
* so the driver will continue to use the mac irq (ndev->irq)
289287
*/
290-
stmmac_res.wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
291-
if (stmmac_res.wol_irq < 0) {
292-
if (stmmac_res.wol_irq == -EPROBE_DEFER)
288+
stmmac_res->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
289+
if (stmmac_res->wol_irq < 0) {
290+
if (stmmac_res->wol_irq == -EPROBE_DEFER)
293291
return -EPROBE_DEFER;
294-
stmmac_res.wol_irq = stmmac_res.irq;
292+
stmmac_res->wol_irq = stmmac_res->irq;
295293
}
296294

297-
stmmac_res.lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
298-
if (stmmac_res.lpi_irq == -EPROBE_DEFER)
295+
stmmac_res->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
296+
if (stmmac_res->lpi_irq == -EPROBE_DEFER)
299297
return -EPROBE_DEFER;
300298

301299
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
302-
stmmac_res.addr = devm_ioremap_resource(dev, res);
303-
if (IS_ERR(stmmac_res.addr))
304-
return PTR_ERR(stmmac_res.addr);
305-
306-
plat_dat = dev_get_platdata(&pdev->dev);
307-
308-
if (!plat_dat)
309-
plat_dat = devm_kzalloc(&pdev->dev,
310-
sizeof(struct plat_stmmacenet_data),
311-
GFP_KERNEL);
312-
if (!plat_dat) {
313-
pr_err("%s: ERROR: no memory", __func__);
314-
return -ENOMEM;
315-
}
300+
stmmac_res->addr = devm_ioremap_resource(&pdev->dev, res);
301+
if (IS_ERR(stmmac_res->addr))
302+
return PTR_ERR(stmmac_res->addr);
316303

317-
/* Set default value for multicast hash bins */
318-
plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
304+
return 0;
305+
}
306+
EXPORT_SYMBOL_GPL(stmmac_get_platform_resources);
319307

320-
/* Set default value for unicast filter entries */
321-
plat_dat->unicast_filter_entries = 1;
308+
/**
309+
* stmmac_pltfr_probe - platform driver probe.
310+
* @pdev: platform device pointer
311+
* Description: platform_device probe function. It is to allocate
312+
* the necessary platform resources, invoke custom helper (if required) and
313+
* invoke the main probe function.
314+
*/
315+
int stmmac_pltfr_probe(struct platform_device *pdev)
316+
{
317+
struct plat_stmmacenet_data *plat_dat;
318+
struct stmmac_resources stmmac_res;
319+
int ret;
320+
321+
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
322+
if (ret)
323+
return ret;
322324

323325
if (pdev->dev.of_node) {
324-
ret = stmmac_probe_config_dt(pdev, plat_dat, &stmmac_res.mac);
325-
if (ret) {
326-
pr_err("%s: main dt probe failed", __func__);
327-
return ret;
326+
plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
327+
if (IS_ERR(plat_dat)) {
328+
dev_err(&pdev->dev, "dt configuration failed\n");
329+
return PTR_ERR(plat_dat);
330+
}
331+
} else {
332+
plat_dat = dev_get_platdata(&pdev->dev);
333+
if (!plat_dat) {
334+
dev_err(&pdev->dev, "no platform data provided\n");
335+
return -EINVAL;
328336
}
337+
338+
/* Set default value for multicast hash bins */
339+
plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
340+
341+
/* Set default value for unicast filter entries */
342+
plat_dat->unicast_filter_entries = 1;
329343
}
330344

331345
/* Custom setup (if needed) */

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#ifndef __STMMAC_PLATFORM_H__
2020
#define __STMMAC_PLATFORM_H__
2121

22+
#include "stmmac.h"
23+
24+
struct plat_stmmacenet_data *
25+
stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
26+
27+
int stmmac_get_platform_resources(struct platform_device *pdev,
28+
struct stmmac_resources *stmmac_res);
29+
2230
int stmmac_pltfr_probe(struct platform_device *pdev);
2331
int stmmac_pltfr_remove(struct platform_device *pdev);
2432
extern const struct dev_pm_ops stmmac_pltfr_pm_ops;

include/linux/stmmac.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ struct plat_stmmacenet_data {
123123
void (*free)(struct platform_device *pdev, void *priv);
124124
int (*init)(struct platform_device *pdev, void *priv);
125125
void (*exit)(struct platform_device *pdev, void *priv);
126-
void *custom_cfg;
127-
void *custom_data;
128126
void *bsp_priv;
129127
};
130128

0 commit comments

Comments
 (0)