brcmfmac: remove use of unconditional access of struct wireless_dev::netdev
[deliverable/linux.git] / drivers / usb / host / ehci-platform.c
CommitLineData
7a7a4a59
HM
1/*
2 * Generic platform ehci driver
3 *
4 * Copyright 2007 Steven Brown <sbrown@cortland.com>
5 * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
6 *
7 * Derived from the ohci-ssb driver
8 * Copyright 2007 Michael Buesch <m@bues.ch>
9 *
10 * Derived from the EHCI-PCI driver
11 * Copyright (c) 2000-2004 by David Brownell
12 *
13 * Derived from the ohci-pci driver
14 * Copyright 1999 Roman Weissgaerber
15 * Copyright 2000-2002 David Brownell
16 * Copyright 1999 Linus Torvalds
17 * Copyright 1999 Gregory P. Smith
18 *
19 * Licensed under the GNU/GPL. See COPYING for details.
20 */
148e1134 21#include <linux/err.h>
99f91934 22#include <linux/kernel.h>
d1bb67a7
AS
23#include <linux/hrtimer.h>
24#include <linux/io.h>
99f91934 25#include <linux/module.h>
7a7a4a59 26#include <linux/platform_device.h>
99f91934
AS
27#include <linux/usb.h>
28#include <linux/usb/hcd.h>
7a7a4a59
HM
29#include <linux/usb/ehci_pdriver.h>
30
99f91934
AS
31#include "ehci.h"
32
33#define DRIVER_DESC "EHCI generic platform driver"
34
35static const char hcd_name[] = "ehci-platform";
36
7a7a4a59
HM
37static int ehci_platform_reset(struct usb_hcd *hcd)
38{
39 struct platform_device *pdev = to_platform_device(hcd->self.controller);
40 struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
43
44 hcd->has_tt = pdata->has_tt;
45 ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
46 ehci->big_endian_desc = pdata->big_endian_desc;
47 ehci->big_endian_mmio = pdata->big_endian_mmio;
48
49 ehci->caps = hcd->regs + pdata->caps_offset;
50 retval = ehci_setup(hcd);
51 if (retval)
52 return retval;
53
4534874a
FF
54 if (pdata->no_io_watchdog)
55 ehci->need_io_watchdog = 0;
7a7a4a59
HM
56 return 0;
57}
58
99f91934 59static struct hc_driver __read_mostly ehci_platform_hc_driver;
7a7a4a59 60
1b36810e 61static const struct ehci_driver_overrides platform_overrides __initdata = {
99f91934 62 .reset = ehci_platform_reset,
7a7a4a59
HM
63};
64
41ac7b3a 65static int ehci_platform_probe(struct platform_device *dev)
7a7a4a59
HM
66{
67 struct usb_hcd *hcd;
68 struct resource *res_mem;
86e4cb35 69 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
7a7a4a59
HM
70 int irq;
71 int err = -ENOMEM;
72
86e4cb35
KM
73 if (!pdata) {
74 WARN_ON(1);
75 return -ENODEV;
76 }
7a7a4a59
HM
77
78 if (usb_disabled())
79 return -ENODEV;
80
81 irq = platform_get_irq(dev, 0);
82 if (irq < 0) {
2350cb0c 83 dev_err(&dev->dev, "no irq provided");
7a7a4a59
HM
84 return irq;
85 }
86 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
87 if (!res_mem) {
5c9b2b28 88 dev_err(&dev->dev, "no memory resource provided");
7a7a4a59
HM
89 return -ENXIO;
90 }
91
04216bed
KM
92 if (pdata->power_on) {
93 err = pdata->power_on(dev);
94 if (err < 0)
95 return err;
96 }
97
7a7a4a59
HM
98 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
99 dev_name(&dev->dev));
04216bed
KM
100 if (!hcd) {
101 err = -ENOMEM;
102 goto err_power;
103 }
7a7a4a59
HM
104
105 hcd->rsrc_start = res_mem->start;
106 hcd->rsrc_len = resource_size(res_mem);
107
148e1134
TR
108 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
109 if (IS_ERR(hcd->regs)) {
110 err = PTR_ERR(hcd->regs);
61ff2745 111 goto err_put_hcd;
ec03ad85 112 }
7a7a4a59
HM
113 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
114 if (err)
61ff2745 115 goto err_put_hcd;
7a7a4a59
HM
116
117 platform_set_drvdata(dev, hcd);
118
119 return err;
120
7a7a4a59
HM
121err_put_hcd:
122 usb_put_hcd(hcd);
04216bed
KM
123err_power:
124 if (pdata->power_off)
125 pdata->power_off(dev);
126
7a7a4a59
HM
127 return err;
128}
129
fb4e98ab 130static int ehci_platform_remove(struct platform_device *dev)
7a7a4a59
HM
131{
132 struct usb_hcd *hcd = platform_get_drvdata(dev);
04216bed 133 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
7a7a4a59
HM
134
135 usb_remove_hcd(hcd);
7a7a4a59
HM
136 usb_put_hcd(hcd);
137 platform_set_drvdata(dev, NULL);
138
04216bed
KM
139 if (pdata->power_off)
140 pdata->power_off(dev);
141
7a7a4a59
HM
142 return 0;
143}
144
145#ifdef CONFIG_PM
146
147static int ehci_platform_suspend(struct device *dev)
148{
149 struct usb_hcd *hcd = dev_get_drvdata(dev);
04216bed
KM
150 struct usb_ehci_pdata *pdata = dev->platform_data;
151 struct platform_device *pdev =
152 container_of(dev, struct platform_device, dev);
c5cf9212 153 bool do_wakeup = device_may_wakeup(dev);
04216bed
KM
154 int ret;
155
156 ret = ehci_suspend(hcd, do_wakeup);
7a7a4a59 157
04216bed
KM
158 if (pdata->power_suspend)
159 pdata->power_suspend(pdev);
160
161 return ret;
7a7a4a59
HM
162}
163
164static int ehci_platform_resume(struct device *dev)
165{
166 struct usb_hcd *hcd = dev_get_drvdata(dev);
04216bed
KM
167 struct usb_ehci_pdata *pdata = dev->platform_data;
168 struct platform_device *pdev =
169 container_of(dev, struct platform_device, dev);
170
171 if (pdata->power_on) {
172 int err = pdata->power_on(pdev);
173 if (err < 0)
174 return err;
175 }
7a7a4a59 176
c5cf9212 177 ehci_resume(hcd, false);
7a7a4a59
HM
178 return 0;
179}
180
181#else /* !CONFIG_PM */
182#define ehci_platform_suspend NULL
183#define ehci_platform_resume NULL
184#endif /* CONFIG_PM */
185
186static const struct platform_device_id ehci_platform_table[] = {
187 { "ehci-platform", 0 },
188 { }
189};
190MODULE_DEVICE_TABLE(platform, ehci_platform_table);
191
192static const struct dev_pm_ops ehci_platform_pm_ops = {
193 .suspend = ehci_platform_suspend,
194 .resume = ehci_platform_resume,
195};
196
197static struct platform_driver ehci_platform_driver = {
198 .id_table = ehci_platform_table,
199 .probe = ehci_platform_probe,
7690417d 200 .remove = ehci_platform_remove,
7a7a4a59
HM
201 .shutdown = usb_hcd_platform_shutdown,
202 .driver = {
203 .owner = THIS_MODULE,
204 .name = "ehci-platform",
205 .pm = &ehci_platform_pm_ops,
206 }
207};
99f91934
AS
208
209static int __init ehci_platform_init(void)
210{
211 if (usb_disabled())
212 return -ENODEV;
213
214 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
215
216 ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
217 return platform_driver_register(&ehci_platform_driver);
218}
219module_init(ehci_platform_init);
220
221static void __exit ehci_platform_cleanup(void)
222{
223 platform_driver_unregister(&ehci_platform_driver);
224}
225module_exit(ehci_platform_cleanup);
226
227MODULE_DESCRIPTION(DRIVER_DESC);
228MODULE_AUTHOR("Hauke Mehrtens");
229MODULE_AUTHOR("Alan Stern");
230MODULE_LICENSE("GPL");
This page took 0.10094 seconds and 5 git commands to generate.