blob: 6e6c23bdb4842ea6fa92ce4751375a64e1c55dab [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 */
21#include <linux/platform_device.h>
22#include <linux/usb/ehci_pdriver.h>
23
24static int ehci_platform_reset(struct usb_hcd *hcd)
25{
26 struct platform_device *pdev = to_platform_device(hcd->self.controller);
27 struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
28 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
29 int retval;
30
31 hcd->has_tt = pdata->has_tt;
32 ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
33 ehci->big_endian_desc = pdata->big_endian_desc;
34 ehci->big_endian_mmio = pdata->big_endian_mmio;
35
36 ehci->caps = hcd->regs + pdata->caps_offset;
37 retval = ehci_setup(hcd);
38 if (retval)
39 return retval;
40
Florian Fainelli45348742012-10-08 15:11:21 +020041 if (pdata->no_io_watchdog)
42 ehci->need_io_watchdog = 0;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010043 return 0;
44}
45
46static const struct hc_driver ehci_platform_hc_driver = {
47 .description = hcd_name,
48 .product_desc = "Generic Platform EHCI Controller",
49 .hcd_priv_size = sizeof(struct ehci_hcd),
50
51 .irq = ehci_irq,
52 .flags = HCD_MEMORY | HCD_USB2,
53
54 .reset = ehci_platform_reset,
55 .start = ehci_run,
56 .stop = ehci_stop,
57 .shutdown = ehci_shutdown,
58
59 .urb_enqueue = ehci_urb_enqueue,
60 .urb_dequeue = ehci_urb_dequeue,
61 .endpoint_disable = ehci_endpoint_disable,
62 .endpoint_reset = ehci_endpoint_reset,
63
64 .get_frame_number = ehci_get_frame,
65
66 .hub_status_data = ehci_hub_status_data,
67 .hub_control = ehci_hub_control,
68#if defined(CONFIG_PM)
69 .bus_suspend = ehci_bus_suspend,
70 .bus_resume = ehci_bus_resume,
71#endif
72 .relinquish_port = ehci_relinquish_port,
73 .port_handed_over = ehci_port_handed_over,
74
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010075 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
76};
77
78static int __devinit ehci_platform_probe(struct platform_device *dev)
79{
80 struct usb_hcd *hcd;
81 struct resource *res_mem;
Kuninori Morimoto86e4cb32012-08-06 18:06:53 -070082 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010083 int irq;
84 int err = -ENOMEM;
85
Kuninori Morimoto86e4cb32012-08-06 18:06:53 -070086 if (!pdata) {
87 WARN_ON(1);
88 return -ENODEV;
89 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010090
91 if (usb_disabled())
92 return -ENODEV;
93
94 irq = platform_get_irq(dev, 0);
95 if (irq < 0) {
Florian Fainelli2350cb02012-10-08 15:11:41 +020096 dev_err(&dev->dev, "no irq provided");
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010097 return irq;
98 }
99 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
100 if (!res_mem) {
Florian Fainelli5c9b2b22012-10-08 15:11:43 +0200101 dev_err(&dev->dev, "no memory resource provided");
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100102 return -ENXIO;
103 }
104
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700105 if (pdata->power_on) {
106 err = pdata->power_on(dev);
107 if (err < 0)
108 return err;
109 }
110
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100111 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
112 dev_name(&dev->dev));
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700113 if (!hcd) {
114 err = -ENOMEM;
115 goto err_power;
116 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100117
118 hcd->rsrc_start = res_mem->start;
119 hcd->rsrc_len = resource_size(res_mem);
120
Florian Fainelli61ff2742012-10-08 15:11:45 +0200121 hcd->regs = devm_request_and_ioremap(&dev->dev, res_mem);
Julia Lawallec03ad82012-08-14 08:47:38 +0200122 if (!hcd->regs) {
123 err = -ENOMEM;
Florian Fainelli61ff2742012-10-08 15:11:45 +0200124 goto err_put_hcd;
Julia Lawallec03ad82012-08-14 08:47:38 +0200125 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100126 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
127 if (err)
Florian Fainelli61ff2742012-10-08 15:11:45 +0200128 goto err_put_hcd;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100129
130 platform_set_drvdata(dev, hcd);
131
132 return err;
133
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100134err_put_hcd:
135 usb_put_hcd(hcd);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700136err_power:
137 if (pdata->power_off)
138 pdata->power_off(dev);
139
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100140 return err;
141}
142
143static int __devexit ehci_platform_remove(struct platform_device *dev)
144{
145 struct usb_hcd *hcd = platform_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700146 struct usb_ehci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100147
148 usb_remove_hcd(hcd);
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100149 usb_put_hcd(hcd);
150 platform_set_drvdata(dev, NULL);
151
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700152 if (pdata->power_off)
153 pdata->power_off(dev);
154
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100155 return 0;
156}
157
158#ifdef CONFIG_PM
159
160static int ehci_platform_suspend(struct device *dev)
161{
162 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700163 struct usb_ehci_pdata *pdata = dev->platform_data;
164 struct platform_device *pdev =
165 container_of(dev, struct platform_device, dev);
Alan Sternc5cf9212012-06-28 11:19:02 -0400166 bool do_wakeup = device_may_wakeup(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700167 int ret;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100168
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700169 ret = ehci_suspend(hcd, do_wakeup);
170
171 if (pdata->power_suspend)
172 pdata->power_suspend(pdev);
173
174 return ret;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100175}
176
177static int ehci_platform_resume(struct device *dev)
178{
179 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimoto04216be2012-08-06 18:08:39 -0700180 struct usb_ehci_pdata *pdata = dev->platform_data;
181 struct platform_device *pdev =
182 container_of(dev, struct platform_device, dev);
183
184 if (pdata->power_on) {
185 int err = pdata->power_on(pdev);
186 if (err < 0)
187 return err;
188 }
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100189
Alan Sternc5cf9212012-06-28 11:19:02 -0400190 ehci_resume(hcd, false);
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +0100191 return 0;
192}
193
194#else /* !CONFIG_PM */
195#define ehci_platform_suspend NULL
196#define ehci_platform_resume NULL
197#endif /* CONFIG_PM */
198
199static const struct platform_device_id ehci_platform_table[] = {
200 { "ehci-platform", 0 },
201 { }
202};
203MODULE_DEVICE_TABLE(platform, ehci_platform_table);
204
205static const struct dev_pm_ops ehci_platform_pm_ops = {
206 .suspend = ehci_platform_suspend,
207 .resume = ehci_platform_resume,
208};
209
210static struct platform_driver ehci_platform_driver = {
211 .id_table = ehci_platform_table,
212 .probe = ehci_platform_probe,
213 .remove = __devexit_p(ehci_platform_remove),
214 .shutdown = usb_hcd_platform_shutdown,
215 .driver = {
216 .owner = THIS_MODULE,
217 .name = "ehci-platform",
218 .pm = &ehci_platform_pm_ops,
219 }
220};