1 /*******************************************************************************
2 This contains the functions to handle the platform driver.
4 Copyright (C) 2007-2011 STMicroelectronics Ltd
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23 *******************************************************************************/
25 #include <linux/platform_device.h>
28 #include <linux/of_net.h>
32 static int stmmac_probe_config_dt(struct platform_device *pdev,
33 struct plat_stmmacenet_data *plat,
36 struct device_node *np = pdev->dev.of_node;
37 struct stmmac_dma_cfg *dma_cfg;
42 *mac = of_get_mac_address(np);
43 plat->interface = of_get_phy_mode(np);
45 /* Get max speed of operation from device tree */
46 if (of_property_read_u32(np, "max-speed", &plat->max_speed))
49 plat->bus_id = of_alias_get_id(np, "ethernet");
53 /* Default to phy auto-detection */
56 /* "snps,phy-addr" is not a standard property. Mark it as deprecated
57 * and warn of its use. Remove this when phy node support is added.
59 if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
60 dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
62 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
63 sizeof(struct stmmac_mdio_bus_data),
66 plat->force_sf_dma_mode = of_property_read_bool(np, "snps,force_sf_dma_mode");
69 * Currently only the properties needed on SPEAr600
70 * are provided. All other properties should be added
71 * once needed on other platforms.
73 if (of_device_is_compatible(np, "st,spear600-gmac") ||
74 of_device_is_compatible(np, "snps,dwmac-3.70a") ||
75 of_device_is_compatible(np, "snps,dwmac")) {
80 if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
81 of_device_is_compatible(np, "snps,dwmac-3.710")) {
83 plat->bugged_jumbo = 1;
84 plat->force_sf_dma_mode = 1;
87 if (of_find_property(np, "snps,pbl", NULL)) {
88 dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg),
92 plat->dma_cfg = dma_cfg;
93 of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
94 dma_cfg->fixed_burst =
95 of_property_read_bool(np, "snps,fixed-burst");
96 dma_cfg->mixed_burst =
97 of_property_read_bool(np, "snps,mixed-burst");
99 plat->force_thresh_dma_mode = of_property_read_bool(np, "snps,force_thresh_dma_mode");
100 if (plat->force_thresh_dma_mode) {
101 plat->force_sf_dma_mode = 0;
102 pr_warn("force_sf_dma_mode is ignored if force_thresh_dma_mode is set.");
108 static int stmmac_probe_config_dt(struct platform_device *pdev,
109 struct plat_stmmacenet_data *plat,
114 #endif /* CONFIG_OF */
118 * @pdev: platform device pointer
119 * Description: platform_device probe function. It allocates
120 * the necessary resources and invokes the main to init
121 * the net device, register the mdio bus etc.
123 static int stmmac_pltfr_probe(struct platform_device *pdev)
126 struct resource *res;
127 struct device *dev = &pdev->dev;
128 void __iomem *addr = NULL;
129 struct stmmac_priv *priv = NULL;
130 struct plat_stmmacenet_data *plat_dat = NULL;
131 const char *mac = NULL;
133 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
134 addr = devm_ioremap_resource(dev, res);
136 return PTR_ERR(addr);
138 plat_dat = dev_get_platdata(&pdev->dev);
139 if (pdev->dev.of_node) {
141 plat_dat = devm_kzalloc(&pdev->dev,
142 sizeof(struct plat_stmmacenet_data),
145 pr_err("%s: ERROR: no memory", __func__);
149 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
151 pr_err("%s: main dt probe failed", __func__);
156 /* Custom setup (if needed) */
157 if (plat_dat->setup) {
158 plat_dat->bsp_priv = plat_dat->setup(pdev);
159 if (IS_ERR(plat_dat->bsp_priv))
160 return PTR_ERR(plat_dat->bsp_priv);
163 /* Custom initialisation (if needed)*/
164 if (plat_dat->init) {
165 ret = plat_dat->init(pdev, plat_dat->bsp_priv);
170 priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
172 pr_err("%s: main driver probe failed", __func__);
173 return PTR_ERR(priv);
176 /* Get MAC address if available (DT) */
178 memcpy(priv->dev->dev_addr, mac, ETH_ALEN);
180 /* Get the MAC information */
181 priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
182 if (priv->dev->irq == -ENXIO) {
183 pr_err("%s: ERROR: MAC IRQ configuration "
184 "information not found\n", __func__);
189 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
190 * The external wake up irq can be passed through the platform code
191 * named as "eth_wake_irq"
193 * In case the wake up interrupt is not passed from the platform
194 * so the driver will continue to use the mac irq (ndev->irq)
196 priv->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
197 if (priv->wol_irq == -ENXIO)
198 priv->wol_irq = priv->dev->irq;
200 priv->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
202 platform_set_drvdata(pdev, priv->dev);
204 pr_debug("STMMAC platform driver registration completed");
210 * stmmac_pltfr_remove
211 * @pdev: platform device pointer
212 * Description: this function calls the main to free the net resources
213 * and calls the platforms hook and release the resources (e.g. mem).
215 static int stmmac_pltfr_remove(struct platform_device *pdev)
217 struct net_device *ndev = platform_get_drvdata(pdev);
218 struct stmmac_priv *priv = netdev_priv(ndev);
219 int ret = stmmac_dvr_remove(ndev);
221 if (priv->plat->exit)
222 priv->plat->exit(pdev, priv->plat->bsp_priv);
224 if (priv->plat->free)
225 priv->plat->free(pdev, priv->plat->bsp_priv);
231 static int stmmac_pltfr_suspend(struct device *dev)
234 struct net_device *ndev = dev_get_drvdata(dev);
235 struct stmmac_priv *priv = netdev_priv(ndev);
236 struct platform_device *pdev = to_platform_device(dev);
238 ret = stmmac_suspend(ndev);
239 if (priv->plat->exit)
240 priv->plat->exit(pdev, priv->plat->bsp_priv);
245 static int stmmac_pltfr_resume(struct device *dev)
247 struct net_device *ndev = dev_get_drvdata(dev);
248 struct stmmac_priv *priv = netdev_priv(ndev);
249 struct platform_device *pdev = to_platform_device(dev);
251 if (priv->plat->init)
252 priv->plat->init(pdev, priv->plat->bsp_priv);
254 return stmmac_resume(ndev);
257 #endif /* CONFIG_PM */
259 static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
260 stmmac_pltfr_suspend, stmmac_pltfr_resume);
262 static const struct of_device_id stmmac_dt_ids[] = {
263 { .compatible = "st,spear600-gmac"},
264 { .compatible = "snps,dwmac-3.610"},
265 { .compatible = "snps,dwmac-3.70a"},
266 { .compatible = "snps,dwmac-3.710"},
267 { .compatible = "snps,dwmac"},
270 MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
272 struct platform_driver stmmac_pltfr_driver = {
273 .probe = stmmac_pltfr_probe,
274 .remove = stmmac_pltfr_remove,
276 .name = STMMAC_RESOURCE_NAME,
277 .owner = THIS_MODULE,
278 .pm = &stmmac_pltfr_pm_ops,
279 .of_match_table = of_match_ptr(stmmac_dt_ids),
283 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PLATFORM driver");
284 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
285 MODULE_LICENSE("GPL");