blob: f97fe3a4d81cf4e7e76d0983854e20b5eff2f86f [file] [log] [blame]
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +01001/*
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 */
Alan Stern99f91932012-11-01 11:13:08 -040021#include <linux/kernel.h>
22#include <linux/module.h>
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010023#include <linux/platform_device.h>
Alan Stern99f91932012-11-01 11:13:08 -040024#include <linux/usb.h>
25#include <linux/usb/hcd.h>
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010026#include <linux/usb/ehci_pdriver.h>
27
Alan Stern99f91932012-11-01 11:13:08 -040028#include "ehci.h"
29
30#define DRIVER_DESC "EHCI generic platform driver"
31
32static const char hcd_name[] = "ehci-platform";
33
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010034static int ehci_platform_reset(struct usb_hcd *hcd)
35{
36 struct platform_device *pdev = to_platform_device(hcd->self.controller);
37 struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
38 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
39 int retval;
40
41 hcd->has_tt = pdata->has_tt;
42 ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
43 ehci->big_endian_desc = pdata->big_endian_desc;
44 ehci->big_endian_mmio = pdata->big_endian_mmio;
45
46 ehci->caps = hcd->regs + pdata->caps_offset;
47 retval = ehci_setup(hcd);
48 if (retval)
49 return retval;
50
Florian Fainelli45348742012-10-08 15:11:21 +020051 if (pdata->no_io_watchdog)
52 ehci->need_io_watchdog = 0;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010053 return 0;
54}
55
Alan Stern99f91932012-11-01 11:13:08 -040056static struct hc_driver __read_mostly ehci_platform_hc_driver;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010057
Alan Stern99f91932012-11-01 11:13:08 -040058static const struct ehci_driver_overrides platform_overrides = {
59 .product_desc = "Generic Platform EHCI controller",
60 .reset = ehci_platform_reset,
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010061};
62
63static int __devinit ehci_platform_probe(struct platform_device *dev)
64{
65 struct usb_hcd *hcd;
66 struct resource *res_mem;
Kuninori Morimoto86e4cb32012-08-06 18:06:53 -070067 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010068 int irq;
69 int err = -ENOMEM;
70
Kuninori Morimoto86e4cb32012-08-06 18:06:53 -070071 if (!pdata) {
72 WARN_ON(1);
73 return -ENODEV;
74 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010075
76 if (usb_disabled())
77 return -ENODEV;
78
79 irq = platform_get_irq(dev, 0);
80 if (irq < 0) {
Florian Fainelli2350cb02012-10-08 15:11:41 +020081 dev_err(&dev->dev, "no irq provided");
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010082 return irq;
83 }
84 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
85 if (!res_mem) {
Florian Fainelli5c9b2b22012-10-08 15:11:43 +020086 dev_err(&dev->dev, "no memory resource provided");
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010087 return -ENXIO;
88 }
89
Kuninori Morimoto04216be2012-08-06 18:08:39 -070090 if (pdata->power_on) {
91 err = pdata->power_on(dev);
92 if (err < 0)
93 return err;
94 }
95
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010096 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
97 dev_name(&dev->dev));
Kuninori Morimoto04216be2012-08-06 18:08:39 -070098 if (!hcd) {
99 err = -ENOMEM;
100 goto err_power;
101 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100102
103 hcd->rsrc_start = res_mem->start;
104 hcd->rsrc_len = resource_size(res_mem);
105
Florian Fainelli61ff2742012-10-08 15:11:45 +0200106 hcd->regs = devm_request_and_ioremap(&dev->dev, res_mem);
Julia Lawallec03ad82012-08-14 08:47:38 +0200107 if (!hcd->regs) {
108 err = -ENOMEM;
Florian Fainelli61ff2742012-10-08 15:11:45 +0200109 goto err_put_hcd;
Julia Lawallec03ad82012-08-14 08:47:38 +0200110 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100111 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
112 if (err)
Florian Fainelli61ff2742012-10-08 15:11:45 +0200113 goto err_put_hcd;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100114
115 platform_set_drvdata(dev, hcd);
116
117 return err;
118
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100119err_put_hcd:
120 usb_put_hcd(hcd);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700121err_power:
122 if (pdata->power_off)
123 pdata->power_off(dev);
124
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100125 return err;
126}
127
128static int __devexit ehci_platform_remove(struct platform_device *dev)
129{
130 struct usb_hcd *hcd = platform_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700131 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100132
133 usb_remove_hcd(hcd);
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100134 usb_put_hcd(hcd);
135 platform_set_drvdata(dev, NULL);
136
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700137 if (pdata->power_off)
138 pdata->power_off(dev);
139
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100140 return 0;
141}
142
143#ifdef CONFIG_PM
144
145static int ehci_platform_suspend(struct device *dev)
146{
147 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700148 struct usb_ehci_pdata *pdata = dev->platform_data;
149 struct platform_device *pdev =
150 container_of(dev, struct platform_device, dev);
Alan Sternc5cf9212012-06-28 11:19:02 -0400151 bool do_wakeup = device_may_wakeup(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700152 int ret;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100153
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700154 ret = ehci_suspend(hcd, do_wakeup);
155
156 if (pdata->power_suspend)
157 pdata->power_suspend(pdev);
158
159 return ret;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100160}
161
162static int ehci_platform_resume(struct device *dev)
163{
164 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700165 struct usb_ehci_pdata *pdata = dev->platform_data;
166 struct platform_device *pdev =
167 container_of(dev, struct platform_device, dev);
168
169 if (pdata->power_on) {
170 int err = pdata->power_on(pdev);
171 if (err < 0)
172 return err;
173 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100174
Alan Sternc5cf9212012-06-28 11:19:02 -0400175 ehci_resume(hcd, false);
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100176 return 0;
177}
178
179#else /* !CONFIG_PM */
180#define ehci_platform_suspend NULL
181#define ehci_platform_resume NULL
182#endif /* CONFIG_PM */
183
184static const struct platform_device_id ehci_platform_table[] = {
185 { "ehci-platform", 0 },
186 { }
187};
188MODULE_DEVICE_TABLE(platform, ehci_platform_table);
189
190static const struct dev_pm_ops ehci_platform_pm_ops = {
191 .suspend = ehci_platform_suspend,
192 .resume = ehci_platform_resume,
193};
194
195static struct platform_driver ehci_platform_driver = {
196 .id_table = ehci_platform_table,
197 .probe = ehci_platform_probe,
198 .remove = __devexit_p(ehci_platform_remove),
199 .shutdown = usb_hcd_platform_shutdown,
200 .driver = {
201 .owner = THIS_MODULE,
202 .name = "ehci-platform",
203 .pm = &ehci_platform_pm_ops,
204 }
205};
Alan Stern99f91932012-11-01 11:13:08 -0400206
207static int __init ehci_platform_init(void)
208{
209 if (usb_disabled())
210 return -ENODEV;
211
212 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
213
214 ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
215 return platform_driver_register(&ehci_platform_driver);
216}
217module_init(ehci_platform_init);
218
219static void __exit ehci_platform_cleanup(void)
220{
221 platform_driver_unregister(&ehci_platform_driver);
222}
223module_exit(ehci_platform_cleanup);
224
225MODULE_DESCRIPTION(DRIVER_DESC);
226MODULE_AUTHOR("Hauke Mehrtens");
227MODULE_AUTHOR("Alan Stern");
228MODULE_LICENSE("GPL");