OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / net / ethernet / stmicro / stmmac / stmmac_platform.c
blob3aad9810237c0dedb8c23f39324f2db646009f1a
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
13 more details.
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>
26 #include <linux/io.h>
27 #include "stmmac.h"
29 /**
30 * stmmac_pltfr_probe
31 * @pdev: platform device pointer
32 * Description: platform_device probe function. It allocates
33 * the necessary resources and invokes the main to init
34 * the net device, register the mdio bus etc.
36 static int stmmac_pltfr_probe(struct platform_device *pdev)
38 int ret = 0;
39 struct resource *res;
40 void __iomem *addr = NULL;
41 struct stmmac_priv *priv = NULL;
42 struct plat_stmmacenet_data *plat_dat;
44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
45 if (!res)
46 return -ENODEV;
48 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
49 pr_err("%s: ERROR: memory allocation failed"
50 "cannot get the I/O addr 0x%x\n",
51 __func__, (unsigned int)res->start);
52 return -EBUSY;
55 addr = ioremap(res->start, resource_size(res));
56 if (!addr) {
57 pr_err("%s: ERROR: memory mapping failed", __func__);
58 ret = -ENOMEM;
59 goto out_release_region;
61 plat_dat = pdev->dev.platform_data;
63 /* Custom initialisation (if needed)*/
64 if (plat_dat->init) {
65 ret = plat_dat->init(pdev);
66 if (unlikely(ret))
67 goto out_unmap;
70 priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
71 if (!priv) {
72 pr_err("%s: main driver probe failed", __func__);
73 goto out_unmap;
76 /* Get the MAC information */
77 priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
78 if (priv->dev->irq == -ENXIO) {
79 pr_err("%s: ERROR: MAC IRQ configuration "
80 "information not found\n", __func__);
81 ret = -ENXIO;
82 goto out_unmap;
86 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
87 * The external wake up irq can be passed through the platform code
88 * named as "eth_wake_irq"
90 * In case the wake up interrupt is not passed from the platform
91 * so the driver will continue to use the mac irq (ndev->irq)
93 priv->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
94 if (priv->wol_irq == -ENXIO)
95 priv->wol_irq = priv->dev->irq;
97 platform_set_drvdata(pdev, priv->dev);
99 pr_debug("STMMAC platform driver registration completed");
101 return 0;
103 out_unmap:
104 iounmap(addr);
105 platform_set_drvdata(pdev, NULL);
107 out_release_region:
108 release_mem_region(res->start, resource_size(res));
110 return ret;
114 * stmmac_pltfr_remove
115 * @pdev: platform device pointer
116 * Description: this function calls the main to free the net resources
117 * and calls the platforms hook and release the resources (e.g. mem).
119 static int stmmac_pltfr_remove(struct platform_device *pdev)
121 struct net_device *ndev = platform_get_drvdata(pdev);
122 struct stmmac_priv *priv = netdev_priv(ndev);
123 struct resource *res;
124 int ret = stmmac_dvr_remove(ndev);
126 if (priv->plat->exit)
127 priv->plat->exit(pdev);
129 if (priv->plat->exit)
130 priv->plat->exit(pdev);
132 platform_set_drvdata(pdev, NULL);
134 iounmap((void *)priv->ioaddr);
135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
136 release_mem_region(res->start, resource_size(res));
138 return ret;
141 #ifdef CONFIG_PM
142 static int stmmac_pltfr_suspend(struct device *dev)
144 struct net_device *ndev = dev_get_drvdata(dev);
146 return stmmac_suspend(ndev);
149 static int stmmac_pltfr_resume(struct device *dev)
151 struct net_device *ndev = dev_get_drvdata(dev);
153 return stmmac_resume(ndev);
156 int stmmac_pltfr_freeze(struct device *dev)
158 struct net_device *ndev = dev_get_drvdata(dev);
160 return stmmac_freeze(ndev);
163 int stmmac_pltfr_restore(struct device *dev)
165 struct net_device *ndev = dev_get_drvdata(dev);
167 return stmmac_restore(ndev);
170 static const struct dev_pm_ops stmmac_pltfr_pm_ops = {
171 .suspend = stmmac_pltfr_suspend,
172 .resume = stmmac_pltfr_resume,
173 .freeze = stmmac_pltfr_freeze,
174 .thaw = stmmac_pltfr_restore,
175 .restore = stmmac_pltfr_restore,
177 #else
178 static const struct dev_pm_ops stmmac_pltfr_pm_ops;
179 #endif /* CONFIG_PM */
181 static struct platform_driver stmmac_driver = {
182 .probe = stmmac_pltfr_probe,
183 .remove = stmmac_pltfr_remove,
184 .driver = {
185 .name = STMMAC_RESOURCE_NAME,
186 .owner = THIS_MODULE,
187 .pm = &stmmac_pltfr_pm_ops,
191 module_platform_driver(stmmac_driver);
193 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PLATFORM driver");
194 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
195 MODULE_LICENSE("GPL");