blob: 886b05678de98b83c4b6f4a4441e3b5a550ad538 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0+
Julie Zhu08d3c182009-09-21 16:08:19 -06002/*
3 * EHCI HCD (Host Controller Driver) for USB.
4 *
5 * Bus Glue for Xilinx EHCI core on the of_platform bus
6 *
7 * Copyright (c) 2009 Xilinx, Inc.
8 *
9 * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
10 * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
11 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28
Thierry Reding148e1132013-01-21 11:09:22 +010029#include <linux/err.h>
Julie Zhu08d3c182009-09-21 16:08:19 -060030#include <linux/signal.h>
31
32#include <linux/of.h>
33#include <linux/of_platform.h>
Michal Simek337fc722011-02-14 11:40:09 +010034#include <linux/of_address.h>
Chen Gang13d79f22014-09-03 23:50:31 +080035#include <linux/of_irq.h>
Julie Zhu08d3c182009-09-21 16:08:19 -060036
37/**
Julie Zhu08d3c182009-09-21 16:08:19 -060038 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
39 * @hcd: Pointer to the usb_hcd device to which the host controller bound
40 * @portnum:Port number to which the device is attached.
41 *
42 * This function is used as a place to tell the user that the Xilinx USB host
43 * controller does support LS devices. And in an HS only configuration, it
44 * does not support FS devices either. It is hoped that this can help a
45 * confused user.
46 *
47 * There are cases when the host controller fails to enable the port due to,
48 * for example, insufficient power that can be supplied to the device from
49 * the USB bus. In those cases, the messages printed here are not helpful.
50 */
51static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
52{
53 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
54 if (hcd->has_tt) {
55 dev_warn(hcd->self.controller,
56 "Maybe you have connected a low speed device?\n");
57
58 dev_warn(hcd->self.controller,
59 "We do not support low speed devices\n");
60 } else {
61 dev_warn(hcd->self.controller,
62 "Maybe your device is not a high speed device?\n");
63 dev_warn(hcd->self.controller,
64 "The USB host controller does not support full speed "
65 "nor low speed devices\n");
66 dev_warn(hcd->self.controller,
67 "You can reconfigure the host controller to have "
68 "full speed support\n");
69 }
70
71 return 0;
72}
73
74
75static const struct hc_driver ehci_xilinx_of_hc_driver = {
76 .description = hcd_name,
77 .product_desc = "OF EHCI",
78 .hcd_priv_size = sizeof(struct ehci_hcd),
79
80 /*
81 * generic hardware linkage
82 */
83 .irq = ehci_irq,
Greg Kroah-Hartmanc04ee4b2013-09-23 13:32:51 -070084 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
Julie Zhu08d3c182009-09-21 16:08:19 -060085
86 /*
87 * basic lifecycle operations
88 */
Alan Stern1a49e2a2012-07-09 15:55:14 -040089 .reset = ehci_setup,
Julie Zhu08d3c182009-09-21 16:08:19 -060090 .start = ehci_run,
91 .stop = ehci_stop,
92 .shutdown = ehci_shutdown,
93
94 /*
95 * managing i/o requests and associated device resources
96 */
97 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
Paul Mundtb48d7f52010-11-30 17:57:02 +0900100 .endpoint_reset = ehci_endpoint_reset,
Julie Zhu08d3c182009-09-21 16:08:19 -0600101
102 /*
103 * scheduling support
104 */
105 .get_frame_number = ehci_get_frame,
106
107 /*
108 * root hub support
109 */
110 .hub_status_data = ehci_hub_status_data,
111 .hub_control = ehci_hub_control,
112#ifdef CONFIG_PM
113 .bus_suspend = ehci_bus_suspend,
114 .bus_resume = ehci_bus_resume,
115#endif
116 .relinquish_port = NULL,
117 .port_handed_over = ehci_xilinx_port_handed_over,
118
119 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
120};
121
122/**
123 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
Grant Likely2dc11582010-08-06 09:25:50 -0600124 * @op: pointer to the platform_device bound to the host controller
Julie Zhu08d3c182009-09-21 16:08:19 -0600125 *
126 * This function requests resources and sets up appropriate properties for the
127 * host controller. Because the Xilinx USB host controller can be configured
128 * as HS only or HS/FS only, it checks the configuration in the device tree
129 * entry, and sets an appropriate value for hcd->has_tt.
130 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500131static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600132{
Grant Likelyffabc9a2010-06-02 13:35:02 -0600133 struct device_node *dn = op->dev.of_node;
Julie Zhu08d3c182009-09-21 16:08:19 -0600134 struct usb_hcd *hcd;
135 struct ehci_hcd *ehci;
136 struct resource res;
137 int irq;
138 int rv;
139 int *value;
140
141 if (usb_disabled())
142 return -ENODEV;
143
144 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
145
146 rv = of_address_to_resource(dn, 0, &res);
147 if (rv)
148 return rv;
149
150 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
151 "XILINX-OF USB");
152 if (!hcd)
153 return -ENOMEM;
154
155 hcd->rsrc_start = res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700156 hcd->rsrc_len = resource_size(&res);
Julie Zhu08d3c182009-09-21 16:08:19 -0600157
Julie Zhu08d3c182009-09-21 16:08:19 -0600158 irq = irq_of_parse_and_map(dn, 0);
Michal Simek7f788ec2012-01-12 09:18:03 +0100159 if (!irq) {
Jingoo Hana74cf5c2013-12-10 21:24:24 +0900160 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
161 __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600162 rv = -EBUSY;
163 goto err_irq;
164 }
165
Thierry Reding148e1132013-01-21 11:09:22 +0100166 hcd->regs = devm_ioremap_resource(&op->dev, &res);
167 if (IS_ERR(hcd->regs)) {
168 rv = PTR_ERR(hcd->regs);
Julia Lawall6df471e2012-07-30 16:43:39 +0200169 goto err_irq;
Julie Zhu08d3c182009-09-21 16:08:19 -0600170 }
171
172 ehci = hcd_to_ehci(hcd);
173
174 /* This core always has big-endian register interface and uses
175 * big-endian memory descriptors.
176 */
177 ehci->big_endian_mmio = 1;
178 ehci->big_endian_desc = 1;
179
180 /* Check whether the FS support option is selected in the hardware.
181 */
182 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
183 if (value && (*value == 1)) {
184 ehci_dbg(ehci, "USB host controller supports FS devices\n");
185 hcd->has_tt = 1;
186 } else {
187 ehci_dbg(ehci,
188 "USB host controller is HS only\n");
189 hcd->has_tt = 0;
190 }
191
192 /* Debug registers are at the first 0x100 region
193 */
194 ehci->caps = hcd->regs + 0x100;
Julie Zhu08d3c182009-09-21 16:08:19 -0600195
196 rv = usb_add_hcd(hcd, irq, 0);
Peter Chen3c9740a2013-11-05 10:46:02 +0800197 if (rv == 0) {
198 device_wakeup_enable(hcd->self.controller);
Julie Zhu08d3c182009-09-21 16:08:19 -0600199 return 0;
Peter Chen3c9740a2013-11-05 10:46:02 +0800200 }
Julie Zhu08d3c182009-09-21 16:08:19 -0600201
Julie Zhu08d3c182009-09-21 16:08:19 -0600202err_irq:
Julie Zhu08d3c182009-09-21 16:08:19 -0600203 usb_put_hcd(hcd);
204
205 return rv;
206}
207
208/**
209 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
Grant Likely2dc11582010-08-06 09:25:50 -0600210 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600211 *
212 * Remove the hcd structure, and release resources that has been requested
213 * during probe.
214 */
Grant Likely2dc11582010-08-06 09:25:50 -0600215static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600216{
Jingoo Han477527b2013-05-23 19:18:39 +0900217 struct usb_hcd *hcd = platform_get_drvdata(op);
Julie Zhu08d3c182009-09-21 16:08:19 -0600218
219 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
220
221 usb_remove_hcd(hcd);
222
Julie Zhu08d3c182009-09-21 16:08:19 -0600223 usb_put_hcd(hcd);
224
225 return 0;
226}
227
Németh Mártonc4386ad2010-01-10 15:35:03 +0100228static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600229 {.compatible = "xlnx,xps-usb-host-1.00.a",},
230 {},
231};
232MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
233
Grant Likelyd35fb642011-02-22 21:08:34 -0700234static struct platform_driver ehci_hcd_xilinx_of_driver = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600235 .probe = ehci_hcd_xilinx_of_probe,
236 .remove = ehci_hcd_xilinx_of_remove,
Roger Quadrosaaf6b522013-07-22 15:04:50 +0300237 .shutdown = usb_hcd_platform_shutdown,
Grant Likely40182942010-04-13 16:13:02 -0700238 .driver = {
239 .name = "xilinx-of-ehci",
Grant Likely40182942010-04-13 16:13:02 -0700240 .of_match_table = ehci_hcd_xilinx_of_match,
Julie Zhu08d3c182009-09-21 16:08:19 -0600241 },
242};