blob: 17c1b1142e38b21c5a1eb3de81063e7d0b7be0e4 [file] [log] [blame]
Julie Zhu08d3c182009-09-21 16:08:19 -06001/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for Xilinx EHCI core on the of_platform bus
5 *
6 * Copyright (c) 2009 Xilinx, Inc.
7 *
8 * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
9 * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
10 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/signal.h>
29
30#include <linux/of.h>
31#include <linux/of_platform.h>
32
33/**
34 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
35 * @hcd: Pointer to the usb_hcd device to which the host controller bound
36 *
37 * called during probe() after chip reset completes.
38 */
39static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
40{
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
43
44 retval = ehci_halt(ehci);
45 if (retval)
46 return retval;
47
48 retval = ehci_init(hcd);
49 if (retval)
50 return retval;
51
52 ehci->sbrn = 0x20;
53
54 return ehci_reset(ehci);
55}
56
57/**
58 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
59 * @hcd: Pointer to the usb_hcd device to which the host controller bound
60 * @portnum:Port number to which the device is attached.
61 *
62 * This function is used as a place to tell the user that the Xilinx USB host
63 * controller does support LS devices. And in an HS only configuration, it
64 * does not support FS devices either. It is hoped that this can help a
65 * confused user.
66 *
67 * There are cases when the host controller fails to enable the port due to,
68 * for example, insufficient power that can be supplied to the device from
69 * the USB bus. In those cases, the messages printed here are not helpful.
70 */
71static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
72{
73 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
74 if (hcd->has_tt) {
75 dev_warn(hcd->self.controller,
76 "Maybe you have connected a low speed device?\n");
77
78 dev_warn(hcd->self.controller,
79 "We do not support low speed devices\n");
80 } else {
81 dev_warn(hcd->self.controller,
82 "Maybe your device is not a high speed device?\n");
83 dev_warn(hcd->self.controller,
84 "The USB host controller does not support full speed "
85 "nor low speed devices\n");
86 dev_warn(hcd->self.controller,
87 "You can reconfigure the host controller to have "
88 "full speed support\n");
89 }
90
91 return 0;
92}
93
94
95static const struct hc_driver ehci_xilinx_of_hc_driver = {
96 .description = hcd_name,
97 .product_desc = "OF EHCI",
98 .hcd_priv_size = sizeof(struct ehci_hcd),
99
100 /*
101 * generic hardware linkage
102 */
103 .irq = ehci_irq,
104 .flags = HCD_MEMORY | HCD_USB2,
105
106 /*
107 * basic lifecycle operations
108 */
109 .reset = ehci_xilinx_of_setup,
110 .start = ehci_run,
111 .stop = ehci_stop,
112 .shutdown = ehci_shutdown,
113
114 /*
115 * managing i/o requests and associated device resources
116 */
117 .urb_enqueue = ehci_urb_enqueue,
118 .urb_dequeue = ehci_urb_dequeue,
119 .endpoint_disable = ehci_endpoint_disable,
Paul Mundtb48d7f52010-11-30 17:57:02 +0900120 .endpoint_reset = ehci_endpoint_reset,
Julie Zhu08d3c182009-09-21 16:08:19 -0600121
122 /*
123 * scheduling support
124 */
125 .get_frame_number = ehci_get_frame,
126
127 /*
128 * root hub support
129 */
130 .hub_status_data = ehci_hub_status_data,
131 .hub_control = ehci_hub_control,
132#ifdef CONFIG_PM
133 .bus_suspend = ehci_bus_suspend,
134 .bus_resume = ehci_bus_resume,
135#endif
136 .relinquish_port = NULL,
137 .port_handed_over = ehci_xilinx_port_handed_over,
138
139 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
140};
141
142/**
143 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
Grant Likely2dc11582010-08-06 09:25:50 -0600144 * @op: pointer to the platform_device bound to the host controller
Julie Zhu08d3c182009-09-21 16:08:19 -0600145 *
146 * This function requests resources and sets up appropriate properties for the
147 * host controller. Because the Xilinx USB host controller can be configured
148 * as HS only or HS/FS only, it checks the configuration in the device tree
149 * entry, and sets an appropriate value for hcd->has_tt.
150 */
Grant Likelyd35fb642011-02-22 21:08:34 -0700151static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600152{
Grant Likelyffabc9a2010-06-02 13:35:02 -0600153 struct device_node *dn = op->dev.of_node;
Julie Zhu08d3c182009-09-21 16:08:19 -0600154 struct usb_hcd *hcd;
155 struct ehci_hcd *ehci;
156 struct resource res;
157 int irq;
158 int rv;
159 int *value;
160
161 if (usb_disabled())
162 return -ENODEV;
163
164 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
165
166 rv = of_address_to_resource(dn, 0, &res);
167 if (rv)
168 return rv;
169
170 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
171 "XILINX-OF USB");
172 if (!hcd)
173 return -ENOMEM;
174
175 hcd->rsrc_start = res.start;
176 hcd->rsrc_len = res.end - res.start + 1;
177
178 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800179 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600180 rv = -EBUSY;
181 goto err_rmr;
182 }
183
184 irq = irq_of_parse_and_map(dn, 0);
185 if (irq == NO_IRQ) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800186 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600187 rv = -EBUSY;
188 goto err_irq;
189 }
190
191 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
192 if (!hcd->regs) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800193 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600194 rv = -ENOMEM;
195 goto err_ioremap;
196 }
197
198 ehci = hcd_to_ehci(hcd);
199
200 /* This core always has big-endian register interface and uses
201 * big-endian memory descriptors.
202 */
203 ehci->big_endian_mmio = 1;
204 ehci->big_endian_desc = 1;
205
206 /* Check whether the FS support option is selected in the hardware.
207 */
208 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
209 if (value && (*value == 1)) {
210 ehci_dbg(ehci, "USB host controller supports FS devices\n");
211 hcd->has_tt = 1;
212 } else {
213 ehci_dbg(ehci,
214 "USB host controller is HS only\n");
215 hcd->has_tt = 0;
216 }
217
218 /* Debug registers are at the first 0x100 region
219 */
220 ehci->caps = hcd->regs + 0x100;
221 ehci->regs = hcd->regs + 0x100 +
222 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
223
224 /* cache this readonly data; minimize chip reads */
225 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
226
227 rv = usb_add_hcd(hcd, irq, 0);
228 if (rv == 0)
229 return 0;
230
231 iounmap(hcd->regs);
232
233err_ioremap:
234err_irq:
235 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236err_rmr:
237 usb_put_hcd(hcd);
238
239 return rv;
240}
241
242/**
243 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
Grant Likely2dc11582010-08-06 09:25:50 -0600244 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600245 *
246 * Remove the hcd structure, and release resources that has been requested
247 * during probe.
248 */
Grant Likely2dc11582010-08-06 09:25:50 -0600249static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600250{
251 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
252 dev_set_drvdata(&op->dev, NULL);
253
254 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
255
256 usb_remove_hcd(hcd);
257
258 iounmap(hcd->regs);
259 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
260
261 usb_put_hcd(hcd);
262
263 return 0;
264}
265
266/**
267 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
Grant Likely2dc11582010-08-06 09:25:50 -0600268 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600269 *
270 * Properly shutdown the hcd, call driver's shutdown routine.
271 */
Grant Likely2dc11582010-08-06 09:25:50 -0600272static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600273{
274 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
275
276 if (hcd->driver->shutdown)
277 hcd->driver->shutdown(hcd);
278
279 return 0;
280}
281
282
Németh Mártonc4386ad2010-01-10 15:35:03 +0100283static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600284 {.compatible = "xlnx,xps-usb-host-1.00.a",},
285 {},
286};
287MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
288
Grant Likelyd35fb642011-02-22 21:08:34 -0700289static struct platform_driver ehci_hcd_xilinx_of_driver = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600290 .probe = ehci_hcd_xilinx_of_probe,
291 .remove = ehci_hcd_xilinx_of_remove,
292 .shutdown = ehci_hcd_xilinx_of_shutdown,
Grant Likely40182942010-04-13 16:13:02 -0700293 .driver = {
294 .name = "xilinx-of-ehci",
295 .owner = THIS_MODULE,
296 .of_match_table = ehci_hcd_xilinx_of_match,
Julie Zhu08d3c182009-09-21 16:08:19 -0600297 },
298};