sunxi: driver refresh for 3.13 - update gmac / mmc / usb / ahci drivers to follow...
[openwrt/openwrt.git] / target / linux / sunxi / patches-3.13 / 153-6-stmmac-use-drvdata-callback-with-compat-strings.patch
1 From 022066f50f53000679d31eb407693085f37b3f14 Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 17 Jan 2014 21:24:46 +0800
4 Subject: [PATCH] net: stmmac: Use driver data and callbacks tied with
5 compatible strings
6
7 The stmmac driver core allows passing feature flags and callbacks via
8 platform data. Add a similar stmmac_of_data to pass flags and callbacks
9 tied to compatible strings. This allows us to extend stmmac with glue
10 layers for different SoCs.
11
12 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 44 +++++++++++++++++-----
16 include/linux/stmmac.h | 18 +++++++++
17 2 files changed, 52 insertions(+), 10 deletions(-)
18
19 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
20 index 82110f1..bf119db 100644
21 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
22 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
23 @@ -26,8 +26,20 @@
24 #include <linux/io.h>
25 #include <linux/of.h>
26 #include <linux/of_net.h>
27 +#include <linux/of_device.h>
28 #include "stmmac.h"
29
30 +static const struct of_device_id stmmac_dt_ids[] = {
31 + /* SoC specific glue layers should come before generic bindings */
32 + { .compatible = "st,spear600-gmac"},
33 + { .compatible = "snps,dwmac-3.610"},
34 + { .compatible = "snps,dwmac-3.70a"},
35 + { .compatible = "snps,dwmac-3.710"},
36 + { .compatible = "snps,dwmac"},
37 + { /* sentinel */ }
38 +};
39 +MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
40 +
41 #ifdef CONFIG_OF
42 static int stmmac_probe_config_dt(struct platform_device *pdev,
43 struct plat_stmmacenet_data *plat,
44 @@ -35,10 +47,32 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
45 {
46 struct device_node *np = pdev->dev.of_node;
47 struct stmmac_dma_cfg *dma_cfg;
48 + const struct of_device_id *device;
49
50 if (!np)
51 return -ENODEV;
52
53 + device = of_match_device(stmmac_dt_ids, &pdev->dev);
54 + if (!device)
55 + return -ENODEV;
56 +
57 + if (device->data) {
58 + const struct stmmac_of_data *data = device->data;
59 + plat->has_gmac = data->has_gmac;
60 + plat->enh_desc = data->enh_desc;
61 + plat->tx_coe = data->tx_coe;
62 + plat->rx_coe = data->rx_coe;
63 + plat->bugged_jumbo = data->bugged_jumbo;
64 + plat->pmt = data->pmt;
65 + plat->riwt_off = data->riwt_off;
66 + plat->fix_mac_speed = data->fix_mac_speed;
67 + plat->bus_setup = data->bus_setup;
68 + plat->setup = data->setup;
69 + plat->free = data->free;
70 + plat->init = data->init;
71 + plat->exit = data->exit;
72 + }
73 +
74 *mac = of_get_mac_address(np);
75 plat->interface = of_get_phy_mode(np);
76
77 @@ -259,16 +293,6 @@ static int stmmac_pltfr_resume(struct device *dev)
78 static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
79 stmmac_pltfr_suspend, stmmac_pltfr_resume);
80
81 -static const struct of_device_id stmmac_dt_ids[] = {
82 - { .compatible = "st,spear600-gmac"},
83 - { .compatible = "snps,dwmac-3.610"},
84 - { .compatible = "snps,dwmac-3.70a"},
85 - { .compatible = "snps,dwmac-3.710"},
86 - { .compatible = "snps,dwmac"},
87 - { /* sentinel */ }
88 -};
89 -MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
90 -
91 struct platform_driver stmmac_pltfr_driver = {
92 .probe = stmmac_pltfr_probe,
93 .remove = stmmac_pltfr_remove,
94 diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
95 index 0a5a7ac..1367974 100644
96 --- a/include/linux/stmmac.h
97 +++ b/include/linux/stmmac.h
98 @@ -121,4 +121,22 @@ struct plat_stmmacenet_data {
99 void *custom_data;
100 void *bsp_priv;
101 };
102 +
103 +/* of_data for SoC glue layer device tree bindings */
104 +
105 +struct stmmac_of_data {
106 + int has_gmac;
107 + int enh_desc;
108 + int tx_coe;
109 + int rx_coe;
110 + int bugged_jumbo;
111 + int pmt;
112 + int riwt_off;
113 + void (*fix_mac_speed)(void *priv, unsigned int speed);
114 + void (*bus_setup)(void __iomem *ioaddr);
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);
119 +};
120 #endif
121 --
122 1.8.5.5
123