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 plat->bus_id = of_alias_get_id(np, "ethernet");
49 of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr);
51 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
52 sizeof(struct stmmac_mdio_bus_data),
56 * Currently only the properties needed on SPEAr600
57 * are provided. All other properties should be added
58 * once needed on other platforms.
60 if (of_device_is_compatible(np, "st,spear600-gmac") ||
61 of_device_is_compatible(np, "snps,dwmac-3.70a") ||
62 of_device_is_compatible(np, "snps,dwmac")) {
67 if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
68 of_device_is_compatible(np, "snps,dwmac-3.710")) {
70 plat->bugged_jumbo = 1;
71 plat->force_sf_dma_mode = 1;
74 dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL);
78 plat->dma_cfg = dma_cfg;
79 of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
80 dma_cfg->fixed_burst = of_property_read_bool(np, "snps,fixed-burst");
81 dma_cfg->mixed_burst = of_property_read_bool(np, "snps,mixed-burst");
82 plat->force_thresh_dma_mode = of_property_read_bool(np, "snps,force_thresh_dma_mode");
83 if (plat->force_thresh_dma_mode) {
84 plat->force_sf_dma_mode = 0;
85 pr_warn("force_sf_dma_mode is ignored if force_thresh_dma_mode is set.");
91 static int stmmac_probe_config_dt(struct platform_device *pdev,
92 struct plat_stmmacenet_data *plat,
97 #endif /* CONFIG_OF */
101 * @pdev: platform device pointer
102 * Description: platform_device probe function. It allocates
103 * the necessary resources and invokes the main to init
104 * the net device, register the mdio bus etc.
106 static int stmmac_pltfr_probe(struct platform_device *pdev)
109 struct resource *res;
110 struct device *dev = &pdev->dev;
111 void __iomem *addr = NULL;
112 struct stmmac_priv *priv = NULL;
113 struct plat_stmmacenet_data *plat_dat = NULL;
114 const char *mac = NULL;
116 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
117 addr = devm_ioremap_resource(dev, res);
119 return PTR_ERR(addr);
121 plat_dat = pdev->dev.platform_data;
122 if (pdev->dev.of_node) {
124 plat_dat = devm_kzalloc(&pdev->dev,
125 sizeof(struct plat_stmmacenet_data),
128 pr_err("%s: ERROR: no memory", __func__);
132 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
134 pr_err("%s: main dt probe failed", __func__);
139 /* Custom initialisation (if needed)*/
140 if (plat_dat->init) {
141 ret = plat_dat->init(pdev);
146 priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
148 pr_err("%s: main driver probe failed", __func__);
152 /* Get MAC address if available (DT) */
154 memcpy(priv->dev->dev_addr, mac, ETH_ALEN);
156 /* Get the MAC information */
157 priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
158 if (priv->dev->irq == -ENXIO) {
159 pr_err("%s: ERROR: MAC IRQ configuration "
160 "information not found\n", __func__);
165 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
166 * The external wake up irq can be passed through the platform code
167 * named as "eth_wake_irq"
169 * In case the wake up interrupt is not passed from the platform
170 * so the driver will continue to use the mac irq (ndev->irq)
172 priv->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
173 if (priv->wol_irq == -ENXIO)
174 priv->wol_irq = priv->dev->irq;
176 priv->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
178 platform_set_drvdata(pdev, priv->dev);
180 pr_debug("STMMAC platform driver registration completed");
186 * stmmac_pltfr_remove
187 * @pdev: platform device pointer
188 * Description: this function calls the main to free the net resources
189 * and calls the platforms hook and release the resources (e.g. mem).
191 static int stmmac_pltfr_remove(struct platform_device *pdev)
193 struct net_device *ndev = platform_get_drvdata(pdev);
194 struct stmmac_priv *priv = netdev_priv(ndev);
195 int ret = stmmac_dvr_remove(ndev);
197 if (priv->plat->exit)
198 priv->plat->exit(pdev);
204 static int stmmac_pltfr_suspend(struct device *dev)
206 struct net_device *ndev = dev_get_drvdata(dev);
208 return stmmac_suspend(ndev);
211 static int stmmac_pltfr_resume(struct device *dev)
213 struct net_device *ndev = dev_get_drvdata(dev);
215 return stmmac_resume(ndev);
218 int stmmac_pltfr_freeze(struct device *dev)
221 struct plat_stmmacenet_data *plat_dat = dev_get_platdata(dev);
222 struct net_device *ndev = dev_get_drvdata(dev);
223 struct platform_device *pdev = to_platform_device(dev);
225 ret = stmmac_freeze(ndev);
227 plat_dat->exit(pdev);
232 int stmmac_pltfr_restore(struct device *dev)
234 struct plat_stmmacenet_data *plat_dat = dev_get_platdata(dev);
235 struct net_device *ndev = dev_get_drvdata(dev);
236 struct platform_device *pdev = to_platform_device(dev);
239 plat_dat->init(pdev);
241 return stmmac_restore(ndev);
244 static const struct dev_pm_ops stmmac_pltfr_pm_ops = {
245 .suspend = stmmac_pltfr_suspend,
246 .resume = stmmac_pltfr_resume,
247 .freeze = stmmac_pltfr_freeze,
248 .thaw = stmmac_pltfr_restore,
249 .restore = stmmac_pltfr_restore,
252 static const struct dev_pm_ops stmmac_pltfr_pm_ops;
253 #endif /* CONFIG_PM */
255 static const struct of_device_id stmmac_dt_ids[] = {
256 { .compatible = "st,spear600-gmac"},
257 { .compatible = "snps,dwmac-3.610"},
258 { .compatible = "snps,dwmac-3.70a"},
259 { .compatible = "snps,dwmac-3.710"},
260 { .compatible = "snps,dwmac"},
263 MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
265 struct platform_driver stmmac_pltfr_driver = {
266 .probe = stmmac_pltfr_probe,
267 .remove = stmmac_pltfr_remove,
269 .name = STMMAC_RESOURCE_NAME,
270 .owner = THIS_MODULE,
271 .pm = &stmmac_pltfr_pm_ops,
272 .of_match_table = of_match_ptr(stmmac_dt_ids),
276 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PLATFORM driver");
277 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
278 MODULE_LICENSE("GPL");