xhci: rework cycle bit checking for new dequeue pointers
[deliverable/linux.git] / drivers / usb / host / ehci-xilinx-of.c
CommitLineData
08d3c18e
JZ
1/*
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
148e1134 28#include <linux/err.h>
08d3c18e
JZ
29#include <linux/signal.h>
30
31#include <linux/of.h>
32#include <linux/of_platform.h>
337fc720 33#include <linux/of_address.h>
08d3c18e 34
08d3c18e
JZ
35/**
36 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
37 * @hcd: Pointer to the usb_hcd device to which the host controller bound
38 * @portnum:Port number to which the device is attached.
39 *
40 * This function is used as a place to tell the user that the Xilinx USB host
41 * controller does support LS devices. And in an HS only configuration, it
42 * does not support FS devices either. It is hoped that this can help a
43 * confused user.
44 *
45 * There are cases when the host controller fails to enable the port due to,
46 * for example, insufficient power that can be supplied to the device from
47 * the USB bus. In those cases, the messages printed here are not helpful.
48 */
49static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
50{
51 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
52 if (hcd->has_tt) {
53 dev_warn(hcd->self.controller,
54 "Maybe you have connected a low speed device?\n");
55
56 dev_warn(hcd->self.controller,
57 "We do not support low speed devices\n");
58 } else {
59 dev_warn(hcd->self.controller,
60 "Maybe your device is not a high speed device?\n");
61 dev_warn(hcd->self.controller,
62 "The USB host controller does not support full speed "
63 "nor low speed devices\n");
64 dev_warn(hcd->self.controller,
65 "You can reconfigure the host controller to have "
66 "full speed support\n");
67 }
68
69 return 0;
70}
71
72
73static const struct hc_driver ehci_xilinx_of_hc_driver = {
74 .description = hcd_name,
75 .product_desc = "OF EHCI",
76 .hcd_priv_size = sizeof(struct ehci_hcd),
77
78 /*
79 * generic hardware linkage
80 */
81 .irq = ehci_irq,
c04ee4b1 82 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
08d3c18e
JZ
83
84 /*
85 * basic lifecycle operations
86 */
1a49e2ac 87 .reset = ehci_setup,
08d3c18e
JZ
88 .start = ehci_run,
89 .stop = ehci_stop,
90 .shutdown = ehci_shutdown,
91
92 /*
93 * managing i/o requests and associated device resources
94 */
95 .urb_enqueue = ehci_urb_enqueue,
96 .urb_dequeue = ehci_urb_dequeue,
97 .endpoint_disable = ehci_endpoint_disable,
b48d7f50 98 .endpoint_reset = ehci_endpoint_reset,
08d3c18e
JZ
99
100 /*
101 * scheduling support
102 */
103 .get_frame_number = ehci_get_frame,
104
105 /*
106 * root hub support
107 */
108 .hub_status_data = ehci_hub_status_data,
109 .hub_control = ehci_hub_control,
110#ifdef CONFIG_PM
111 .bus_suspend = ehci_bus_suspend,
112 .bus_resume = ehci_bus_resume,
113#endif
114 .relinquish_port = NULL,
115 .port_handed_over = ehci_xilinx_port_handed_over,
116
117 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
118};
119
120/**
121 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
2dc11581 122 * @op: pointer to the platform_device bound to the host controller
08d3c18e
JZ
123 *
124 * This function requests resources and sets up appropriate properties for the
125 * host controller. Because the Xilinx USB host controller can be configured
126 * as HS only or HS/FS only, it checks the configuration in the device tree
127 * entry, and sets an appropriate value for hcd->has_tt.
128 */
41ac7b3a 129static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
08d3c18e 130{
ffabc9a6 131 struct device_node *dn = op->dev.of_node;
08d3c18e
JZ
132 struct usb_hcd *hcd;
133 struct ehci_hcd *ehci;
134 struct resource res;
135 int irq;
136 int rv;
137 int *value;
138
139 if (usb_disabled())
140 return -ENODEV;
141
142 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
143
144 rv = of_address_to_resource(dn, 0, &res);
145 if (rv)
146 return rv;
147
148 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
149 "XILINX-OF USB");
150 if (!hcd)
151 return -ENOMEM;
152
153 hcd->rsrc_start = res.start;
28f65c11 154 hcd->rsrc_len = resource_size(&res);
08d3c18e 155
08d3c18e 156 irq = irq_of_parse_and_map(dn, 0);
7f788ec0 157 if (!irq) {
a74cf5cc
JH
158 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
159 __FILE__);
08d3c18e
JZ
160 rv = -EBUSY;
161 goto err_irq;
162 }
163
148e1134
TR
164 hcd->regs = devm_ioremap_resource(&op->dev, &res);
165 if (IS_ERR(hcd->regs)) {
166 rv = PTR_ERR(hcd->regs);
6df471ea 167 goto err_irq;
08d3c18e
JZ
168 }
169
170 ehci = hcd_to_ehci(hcd);
171
172 /* This core always has big-endian register interface and uses
173 * big-endian memory descriptors.
174 */
175 ehci->big_endian_mmio = 1;
176 ehci->big_endian_desc = 1;
177
178 /* Check whether the FS support option is selected in the hardware.
179 */
180 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
181 if (value && (*value == 1)) {
182 ehci_dbg(ehci, "USB host controller supports FS devices\n");
183 hcd->has_tt = 1;
184 } else {
185 ehci_dbg(ehci,
186 "USB host controller is HS only\n");
187 hcd->has_tt = 0;
188 }
189
190 /* Debug registers are at the first 0x100 region
191 */
192 ehci->caps = hcd->regs + 0x100;
08d3c18e
JZ
193
194 rv = usb_add_hcd(hcd, irq, 0);
3c9740a1
PC
195 if (rv == 0) {
196 device_wakeup_enable(hcd->self.controller);
08d3c18e 197 return 0;
3c9740a1 198 }
08d3c18e 199
08d3c18e 200err_irq:
08d3c18e
JZ
201 usb_put_hcd(hcd);
202
203 return rv;
204}
205
206/**
207 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
2dc11581 208 * @op: pointer to platform_device structure that is to be removed
08d3c18e
JZ
209 *
210 * Remove the hcd structure, and release resources that has been requested
211 * during probe.
212 */
2dc11581 213static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
08d3c18e 214{
477527ba 215 struct usb_hcd *hcd = platform_get_drvdata(op);
08d3c18e
JZ
216
217 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
218
219 usb_remove_hcd(hcd);
220
08d3c18e
JZ
221 usb_put_hcd(hcd);
222
223 return 0;
224}
225
c4386ad0 226static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
08d3c18e
JZ
227 {.compatible = "xlnx,xps-usb-host-1.00.a",},
228 {},
229};
230MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
231
d35fb641 232static struct platform_driver ehci_hcd_xilinx_of_driver = {
08d3c18e
JZ
233 .probe = ehci_hcd_xilinx_of_probe,
234 .remove = ehci_hcd_xilinx_of_remove,
aaf6b52d 235 .shutdown = usb_hcd_platform_shutdown,
4018294b
GL
236 .driver = {
237 .name = "xilinx-of-ehci",
238 .owner = THIS_MODULE,
239 .of_match_table = ehci_hcd_xilinx_of_match,
08d3c18e
JZ
240 },
241};
This page took 0.294313 seconds and 5 git commands to generate.