blob: f54480850bb89eba4c44bad91d4ad01f9f8d3bf0 [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
Thierry Reding148e1132013-01-21 11:09:22 +010028#include <linux/err.h>
Julie Zhu08d3c182009-09-21 16:08:19 -060029#include <linux/signal.h>
30
31#include <linux/of.h>
32#include <linux/of_platform.h>
Michal Simek337fc722011-02-14 11:40:09 +010033#include <linux/of_address.h>
Chen Gang13d79f22014-09-03 23:50:31 +080034#include <linux/of_irq.h>
Julie Zhu08d3c182009-09-21 16:08:19 -060035
36/**
Julie Zhu08d3c182009-09-21 16:08:19 -060037 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
38 * @hcd: Pointer to the usb_hcd device to which the host controller bound
39 * @portnum:Port number to which the device is attached.
40 *
41 * This function is used as a place to tell the user that the Xilinx USB host
42 * controller does support LS devices. And in an HS only configuration, it
43 * does not support FS devices either. It is hoped that this can help a
44 * confused user.
45 *
46 * There are cases when the host controller fails to enable the port due to,
47 * for example, insufficient power that can be supplied to the device from
48 * the USB bus. In those cases, the messages printed here are not helpful.
49 */
50static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
51{
52 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
53 if (hcd->has_tt) {
54 dev_warn(hcd->self.controller,
55 "Maybe you have connected a low speed device?\n");
56
57 dev_warn(hcd->self.controller,
58 "We do not support low speed devices\n");
59 } else {
60 dev_warn(hcd->self.controller,
61 "Maybe your device is not a high speed device?\n");
62 dev_warn(hcd->self.controller,
63 "The USB host controller does not support full speed "
64 "nor low speed devices\n");
65 dev_warn(hcd->self.controller,
66 "You can reconfigure the host controller to have "
67 "full speed support\n");
68 }
69
70 return 0;
71}
72
73
74static const struct hc_driver ehci_xilinx_of_hc_driver = {
75 .description = hcd_name,
76 .product_desc = "OF EHCI",
77 .hcd_priv_size = sizeof(struct ehci_hcd),
78
79 /*
80 * generic hardware linkage
81 */
82 .irq = ehci_irq,
Greg Kroah-Hartmanc04ee4b2013-09-23 13:32:51 -070083 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
Julie Zhu08d3c182009-09-21 16:08:19 -060084
85 /*
86 * basic lifecycle operations
87 */
Alan Stern1a49e2a2012-07-09 15:55:14 -040088 .reset = ehci_setup,
Julie Zhu08d3c182009-09-21 16:08:19 -060089 .start = ehci_run,
90 .stop = ehci_stop,
91 .shutdown = ehci_shutdown,
92
93 /*
94 * managing i/o requests and associated device resources
95 */
96 .urb_enqueue = ehci_urb_enqueue,
97 .urb_dequeue = ehci_urb_dequeue,
98 .endpoint_disable = ehci_endpoint_disable,
Paul Mundtb48d7f52010-11-30 17:57:02 +090099 .endpoint_reset = ehci_endpoint_reset,
Julie Zhu08d3c182009-09-21 16:08:19 -0600100
101 /*
102 * scheduling support
103 */
104 .get_frame_number = ehci_get_frame,
105
106 /*
107 * root hub support
108 */
109 .hub_status_data = ehci_hub_status_data,
110 .hub_control = ehci_hub_control,
111#ifdef CONFIG_PM
112 .bus_suspend = ehci_bus_suspend,
113 .bus_resume = ehci_bus_resume,
114#endif
115 .relinquish_port = NULL,
116 .port_handed_over = ehci_xilinx_port_handed_over,
117
118 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
119};
120
121/**
122 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
Grant Likely2dc11582010-08-06 09:25:50 -0600123 * @op: pointer to the platform_device bound to the host controller
Julie Zhu08d3c182009-09-21 16:08:19 -0600124 *
125 * This function requests resources and sets up appropriate properties for the
126 * host controller. Because the Xilinx USB host controller can be configured
127 * as HS only or HS/FS only, it checks the configuration in the device tree
128 * entry, and sets an appropriate value for hcd->has_tt.
129 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500130static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600131{
Grant Likelyffabc9a2010-06-02 13:35:02 -0600132 struct device_node *dn = op->dev.of_node;
Julie Zhu08d3c182009-09-21 16:08:19 -0600133 struct usb_hcd *hcd;
134 struct ehci_hcd *ehci;
135 struct resource res;
136 int irq;
137 int rv;
138 int *value;
139
140 if (usb_disabled())
141 return -ENODEV;
142
143 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
144
145 rv = of_address_to_resource(dn, 0, &res);
146 if (rv)
147 return rv;
148
149 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
150 "XILINX-OF USB");
151 if (!hcd)
152 return -ENOMEM;
153
154 hcd->rsrc_start = res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700155 hcd->rsrc_len = resource_size(&res);
Julie Zhu08d3c182009-09-21 16:08:19 -0600156
Julie Zhu08d3c182009-09-21 16:08:19 -0600157 irq = irq_of_parse_and_map(dn, 0);
Michal Simek7f788ec2012-01-12 09:18:03 +0100158 if (!irq) {
Jingoo Hana74cf5c2013-12-10 21:24:24 +0900159 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
160 __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600161 rv = -EBUSY;
162 goto err_irq;
163 }
164
Thierry Reding148e1132013-01-21 11:09:22 +0100165 hcd->regs = devm_ioremap_resource(&op->dev, &res);
166 if (IS_ERR(hcd->regs)) {
167 rv = PTR_ERR(hcd->regs);
Julia Lawall6df471e2012-07-30 16:43:39 +0200168 goto err_irq;
Julie Zhu08d3c182009-09-21 16:08:19 -0600169 }
170
171 ehci = hcd_to_ehci(hcd);
172
173 /* This core always has big-endian register interface and uses
174 * big-endian memory descriptors.
175 */
176 ehci->big_endian_mmio = 1;
177 ehci->big_endian_desc = 1;
178
179 /* Check whether the FS support option is selected in the hardware.
180 */
181 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
182 if (value && (*value == 1)) {
183 ehci_dbg(ehci, "USB host controller supports FS devices\n");
184 hcd->has_tt = 1;
185 } else {
186 ehci_dbg(ehci,
187 "USB host controller is HS only\n");
188 hcd->has_tt = 0;
189 }
190
191 /* Debug registers are at the first 0x100 region
192 */
193 ehci->caps = hcd->regs + 0x100;
Julie Zhu08d3c182009-09-21 16:08:19 -0600194
195 rv = usb_add_hcd(hcd, irq, 0);
Peter Chen3c9740a2013-11-05 10:46:02 +0800196 if (rv == 0) {
197 device_wakeup_enable(hcd->self.controller);
Julie Zhu08d3c182009-09-21 16:08:19 -0600198 return 0;
Peter Chen3c9740a2013-11-05 10:46:02 +0800199 }
Julie Zhu08d3c182009-09-21 16:08:19 -0600200
Julie Zhu08d3c182009-09-21 16:08:19 -0600201err_irq:
Julie Zhu08d3c182009-09-21 16:08:19 -0600202 usb_put_hcd(hcd);
203
204 return rv;
205}
206
207/**
208 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
Grant Likely2dc11582010-08-06 09:25:50 -0600209 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600210 *
211 * Remove the hcd structure, and release resources that has been requested
212 * during probe.
213 */
Grant Likely2dc11582010-08-06 09:25:50 -0600214static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600215{
Jingoo Han477527b2013-05-23 19:18:39 +0900216 struct usb_hcd *hcd = platform_get_drvdata(op);
Julie Zhu08d3c182009-09-21 16:08:19 -0600217
218 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
219
220 usb_remove_hcd(hcd);
221
Julie Zhu08d3c182009-09-21 16:08:19 -0600222 usb_put_hcd(hcd);
223
224 return 0;
225}
226
Németh Mártonc4386ad2010-01-10 15:35:03 +0100227static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600228 {.compatible = "xlnx,xps-usb-host-1.00.a",},
229 {},
230};
231MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
232
Grant Likelyd35fb642011-02-22 21:08:34 -0700233static struct platform_driver ehci_hcd_xilinx_of_driver = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600234 .probe = ehci_hcd_xilinx_of_probe,
235 .remove = ehci_hcd_xilinx_of_remove,
Roger Quadrosaaf6b522013-07-22 15:04:50 +0300236 .shutdown = usb_hcd_platform_shutdown,
Grant Likely40182942010-04-13 16:13:02 -0700237 .driver = {
238 .name = "xilinx-of-ehci",
Grant Likely40182942010-04-13 16:13:02 -0700239 .of_match_table = ehci_hcd_xilinx_of_match,
Julie Zhu08d3c182009-09-21 16:08:19 -0600240 },
241};