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