aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/stmicro
diff options
context:
space:
mode:
authorStefan Roese <sr@denx.de>2012-03-13 00:56:37 -0400
committerDavid S. Miller <davem@davemloft.net>2012-03-17 01:48:53 -0400
commit6a228452d11eaf1f1577261540ec0903a2af7f61 (patch)
tree9e08f1ba22948df7f09c0f2f6d4d6c7fa3d55871 /drivers/net/ethernet/stmicro
parent06d6c1087605b38342eb20e74b0cacb8b71f5086 (diff)
stmmac: Add device-tree support
This patch adds support to configure the STMMAC ethernet driver via device-tree instead of platform_data. Currently, only the properties needed on SPEAr600 are provided. All other properties should be added once needed on other platforms. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/stmicro')
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 3aad9810237..116529a366b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -24,8 +24,48 @@
24 24
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/of.h>
28#include <linux/of_net.h>
27#include "stmmac.h" 29#include "stmmac.h"
28 30
31#ifdef CONFIG_OF
32static int __devinit stmmac_probe_config_dt(struct platform_device *pdev,
33 struct plat_stmmacenet_data *plat,
34 const char **mac)
35{
36 struct device_node *np = pdev->dev.of_node;
37
38 if (!np)
39 return -ENODEV;
40
41 *mac = of_get_mac_address(np);
42 plat->interface = of_get_phy_mode(np);
43 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
44 sizeof(struct stmmac_mdio_bus_data),
45 GFP_KERNEL);
46
47 /*
48 * Currently only the properties needed on SPEAr600
49 * are provided. All other properties should be added
50 * once needed on other platforms.
51 */
52 if (of_device_is_compatible(np, "st,spear600-gmac")) {
53 plat->pbl = 8;
54 plat->has_gmac = 1;
55 plat->pmt = 1;
56 }
57
58 return 0;
59}
60#else
61static int __devinit stmmac_probe_config_dt(struct platform_device *pdev,
62 struct plat_stmmacenet_data *plat,
63 const char **mac)
64{
65 return -ENOSYS;
66}
67#endif /* CONFIG_OF */
68
29/** 69/**
30 * stmmac_pltfr_probe 70 * stmmac_pltfr_probe
31 * @pdev: platform device pointer 71 * @pdev: platform device pointer
@@ -39,7 +79,8 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
39 struct resource *res; 79 struct resource *res;
40 void __iomem *addr = NULL; 80 void __iomem *addr = NULL;
41 struct stmmac_priv *priv = NULL; 81 struct stmmac_priv *priv = NULL;
42 struct plat_stmmacenet_data *plat_dat; 82 struct plat_stmmacenet_data *plat_dat = NULL;
83 const char *mac = NULL;
43 84
44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 85 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
45 if (!res) 86 if (!res)
@@ -58,7 +99,25 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
58 ret = -ENOMEM; 99 ret = -ENOMEM;
59 goto out_release_region; 100 goto out_release_region;
60 } 101 }
61 plat_dat = pdev->dev.platform_data; 102
103 if (pdev->dev.of_node) {
104 plat_dat = devm_kzalloc(&pdev->dev,
105 sizeof(struct plat_stmmacenet_data),
106 GFP_KERNEL);
107 if (!plat_dat) {
108 pr_err("%s: ERROR: no memory", __func__);
109 ret = -ENOMEM;
110 goto out_unmap;
111 }
112
113 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
114 if (ret) {
115 pr_err("%s: main dt probe failed", __func__);
116 goto out_unmap;
117 }
118 } else {
119 plat_dat = pdev->dev.platform_data;
120 }
62 121
63 /* Custom initialisation (if needed)*/ 122 /* Custom initialisation (if needed)*/
64 if (plat_dat->init) { 123 if (plat_dat->init) {
@@ -73,6 +132,10 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
73 goto out_unmap; 132 goto out_unmap;
74 } 133 }
75 134
135 /* Get MAC address if available (DT) */
136 if (mac)
137 memcpy(priv->dev->dev_addr, mac, ETH_ALEN);
138
76 /* Get the MAC information */ 139 /* Get the MAC information */
77 priv->dev->irq = platform_get_irq_byname(pdev, "macirq"); 140 priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
78 if (priv->dev->irq == -ENXIO) { 141 if (priv->dev->irq == -ENXIO) {
@@ -178,6 +241,12 @@ static const struct dev_pm_ops stmmac_pltfr_pm_ops = {
178static const struct dev_pm_ops stmmac_pltfr_pm_ops; 241static const struct dev_pm_ops stmmac_pltfr_pm_ops;
179#endif /* CONFIG_PM */ 242#endif /* CONFIG_PM */
180 243
244static const struct of_device_id stmmac_dt_ids[] = {
245 { .compatible = "st,spear600-gmac", },
246 { /* sentinel */ }
247};
248MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
249
181static struct platform_driver stmmac_driver = { 250static struct platform_driver stmmac_driver = {
182 .probe = stmmac_pltfr_probe, 251 .probe = stmmac_pltfr_probe,
183 .remove = stmmac_pltfr_remove, 252 .remove = stmmac_pltfr_remove,
@@ -185,6 +254,7 @@ static struct platform_driver stmmac_driver = {
185 .name = STMMAC_RESOURCE_NAME, 254 .name = STMMAC_RESOURCE_NAME,
186 .owner = THIS_MODULE, 255 .owner = THIS_MODULE,
187 .pm = &stmmac_pltfr_pm_ops, 256 .pm = &stmmac_pltfr_pm_ops,
257 .of_match_table = of_match_ptr(stmmac_dt_ids),
188 }, 258 },
189}; 259};
190 260