blob: 07a232af670d9fd2d7177331d515f93fb7be5d34 [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;
Shimrit Malichicf9a8e92012-10-30 16:06:55 +020033 ehci->pool_64_bit_align = pdata->pool_64_bit_align;
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +010034 ehci->big_endian_desc = pdata->big_endian_desc;
35 ehci->big_endian_mmio = pdata->big_endian_mmio;
36
37 ehci->caps = hcd->regs + pdata->caps_offset;
38 retval = ehci_setup(hcd);
39 if (retval)
40 return retval;
41
42 if (pdata->port_power_on)
43 ehci_port_power(ehci, 1);
44 if (pdata->port_power_off)
45 ehci_port_power(ehci, 0);
46
47 return 0;
48}
49
50static const struct hc_driver ehci_platform_hc_driver = {
51 .description = hcd_name,
52 .product_desc = "Generic Platform EHCI Controller",
53 .hcd_priv_size = sizeof(struct ehci_hcd),
54
55 .irq = ehci_irq,
56 .flags = HCD_MEMORY | HCD_USB2,
57
58 .reset = ehci_platform_reset,
59 .start = ehci_run,
60 .stop = ehci_stop,
61 .shutdown = ehci_shutdown,
62
63 .urb_enqueue = ehci_urb_enqueue,
64 .urb_dequeue = ehci_urb_dequeue,
65 .endpoint_disable = ehci_endpoint_disable,
66 .endpoint_reset = ehci_endpoint_reset,
67
68 .get_frame_number = ehci_get_frame,
69
70 .hub_status_data = ehci_hub_status_data,
71 .hub_control = ehci_hub_control,
72#if defined(CONFIG_PM)
73 .bus_suspend = ehci_bus_suspend,
74 .bus_resume = ehci_bus_resume,
75#endif
76 .relinquish_port = ehci_relinquish_port,
77 .port_handed_over = ehci_port_handed_over,
78
79 .update_device = ehci_update_device,
80
81 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
82};
83
84static int __devinit ehci_platform_probe(struct platform_device *dev)
85{
86 struct usb_hcd *hcd;
87 struct resource *res_mem;
88 int irq;
89 int err = -ENOMEM;
90
91 BUG_ON(!dev->dev.platform_data);
92
93 if (usb_disabled())
94 return -ENODEV;
95
96 irq = platform_get_irq(dev, 0);
97 if (irq < 0) {
98 pr_err("no irq provieded");
99 return irq;
100 }
101 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
102 if (!res_mem) {
103 pr_err("no memory recourse provieded");
104 return -ENXIO;
105 }
106
107 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
108 dev_name(&dev->dev));
109 if (!hcd)
110 return -ENOMEM;
111
112 hcd->rsrc_start = res_mem->start;
113 hcd->rsrc_len = resource_size(res_mem);
114
115 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
116 pr_err("controller already in use");
117 err = -EBUSY;
118 goto err_put_hcd;
119 }
120
121 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
122 if (!hcd->regs)
123 goto err_release_region;
124 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
125 if (err)
126 goto err_iounmap;
127
128 platform_set_drvdata(dev, hcd);
129
130 return err;
131
132err_iounmap:
133 iounmap(hcd->regs);
134err_release_region:
135 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
136err_put_hcd:
137 usb_put_hcd(hcd);
138 return err;
139}
140
141static int __devexit ehci_platform_remove(struct platform_device *dev)
142{
143 struct usb_hcd *hcd = platform_get_drvdata(dev);
144
145 usb_remove_hcd(hcd);
146 iounmap(hcd->regs);
147 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
148 usb_put_hcd(hcd);
149 platform_set_drvdata(dev, NULL);
150
151 return 0;
152}
153
154#ifdef CONFIG_PM
155
156static int ehci_platform_suspend(struct device *dev)
157{
158 struct usb_hcd *hcd = dev_get_drvdata(dev);
159 bool wakeup = device_may_wakeup(dev);
160
161 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
162 return 0;
163}
164
165static int ehci_platform_resume(struct device *dev)
166{
167 struct usb_hcd *hcd = dev_get_drvdata(dev);
168
169 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
170 return 0;
171}
172
173#else /* !CONFIG_PM */
174#define ehci_platform_suspend NULL
175#define ehci_platform_resume NULL
176#endif /* CONFIG_PM */
177
178static const struct platform_device_id ehci_platform_table[] = {
179 { "ehci-platform", 0 },
180 { }
181};
182MODULE_DEVICE_TABLE(platform, ehci_platform_table);
183
184static const struct dev_pm_ops ehci_platform_pm_ops = {
185 .suspend = ehci_platform_suspend,
186 .resume = ehci_platform_resume,
187};
188
189static struct platform_driver ehci_platform_driver = {
190 .id_table = ehci_platform_table,
191 .probe = ehci_platform_probe,
192 .remove = __devexit_p(ehci_platform_remove),
193 .shutdown = usb_hcd_platform_shutdown,
194 .driver = {
195 .owner = THIS_MODULE,
196 .name = "ehci-platform",
197 .pm = &ehci_platform_pm_ops,
198 }
199};