blob: 39f24fa37ebe9fff07c3f38087dbf6f04bedaaa8 [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>
Michal Simek337fc722011-02-14 11:40:09 +010032#include <linux/of_address.h>
Julie Zhu08d3c182009-09-21 16:08:19 -060033
34/**
Julie Zhu08d3c182009-09-21 16:08:19 -060035 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
37 * @portnum:Port number to which the device is attached.
38 *
39 * This function is used as a place to tell the user that the Xilinx USB host
40 * controller does support LS devices. And in an HS only configuration, it
41 * does not support FS devices either. It is hoped that this can help a
42 * confused user.
43 *
44 * There are cases when the host controller fails to enable the port due to,
45 * for example, insufficient power that can be supplied to the device from
46 * the USB bus. In those cases, the messages printed here are not helpful.
47 */
48static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
49{
50 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
51 if (hcd->has_tt) {
52 dev_warn(hcd->self.controller,
53 "Maybe you have connected a low speed device?\n");
54
55 dev_warn(hcd->self.controller,
56 "We do not support low speed devices\n");
57 } else {
58 dev_warn(hcd->self.controller,
59 "Maybe your device is not a high speed device?\n");
60 dev_warn(hcd->self.controller,
61 "The USB host controller does not support full speed "
62 "nor low speed devices\n");
63 dev_warn(hcd->self.controller,
64 "You can reconfigure the host controller to have "
65 "full speed support\n");
66 }
67
68 return 0;
69}
70
71
72static const struct hc_driver ehci_xilinx_of_hc_driver = {
73 .description = hcd_name,
74 .product_desc = "OF EHCI",
75 .hcd_priv_size = sizeof(struct ehci_hcd),
76
77 /*
78 * generic hardware linkage
79 */
80 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
82
83 /*
84 * basic lifecycle operations
85 */
Alan Stern1a49e2a2012-07-09 15:55:14 -040086 .reset = ehci_setup,
Julie Zhu08d3c182009-09-21 16:08:19 -060087 .start = ehci_run,
88 .stop = ehci_stop,
89 .shutdown = ehci_shutdown,
90
91 /*
92 * managing i/o requests and associated device resources
93 */
94 .urb_enqueue = ehci_urb_enqueue,
95 .urb_dequeue = ehci_urb_dequeue,
96 .endpoint_disable = ehci_endpoint_disable,
Paul Mundtb48d7f52010-11-30 17:57:02 +090097 .endpoint_reset = ehci_endpoint_reset,
Julie Zhu08d3c182009-09-21 16:08:19 -060098
99 /*
100 * scheduling support
101 */
102 .get_frame_number = ehci_get_frame,
103
104 /*
105 * root hub support
106 */
107 .hub_status_data = ehci_hub_status_data,
108 .hub_control = ehci_hub_control,
109#ifdef CONFIG_PM
110 .bus_suspend = ehci_bus_suspend,
111 .bus_resume = ehci_bus_resume,
112#endif
113 .relinquish_port = NULL,
114 .port_handed_over = ehci_xilinx_port_handed_over,
115
116 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
117};
118
119/**
120 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
Grant Likely2dc11582010-08-06 09:25:50 -0600121 * @op: pointer to the platform_device bound to the host controller
Julie Zhu08d3c182009-09-21 16:08:19 -0600122 *
123 * This function requests resources and sets up appropriate properties for the
124 * host controller. Because the Xilinx USB host controller can be configured
125 * as HS only or HS/FS only, it checks the configuration in the device tree
126 * entry, and sets an appropriate value for hcd->has_tt.
127 */
Grant Likelyd35fb642011-02-22 21:08:34 -0700128static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600129{
Grant Likelyffabc9a2010-06-02 13:35:02 -0600130 struct device_node *dn = op->dev.of_node;
Julie Zhu08d3c182009-09-21 16:08:19 -0600131 struct usb_hcd *hcd;
132 struct ehci_hcd *ehci;
133 struct resource res;
134 int irq;
135 int rv;
136 int *value;
137
138 if (usb_disabled())
139 return -ENODEV;
140
141 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
142
143 rv = of_address_to_resource(dn, 0, &res);
144 if (rv)
145 return rv;
146
147 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
148 "XILINX-OF USB");
149 if (!hcd)
150 return -ENOMEM;
151
152 hcd->rsrc_start = res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700153 hcd->rsrc_len = resource_size(&res);
Julie Zhu08d3c182009-09-21 16:08:19 -0600154
155 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800156 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600157 rv = -EBUSY;
158 goto err_rmr;
159 }
160
161 irq = irq_of_parse_and_map(dn, 0);
Michal Simek7f788ec2012-01-12 09:18:03 +0100162 if (!irq) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800163 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600164 rv = -EBUSY;
165 goto err_irq;
166 }
167
168 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
169 if (!hcd->regs) {
Joe Perchesf45ba772010-02-05 17:51:13 -0800170 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
Julie Zhu08d3c182009-09-21 16:08:19 -0600171 rv = -ENOMEM;
172 goto err_ioremap;
173 }
174
175 ehci = hcd_to_ehci(hcd);
176
177 /* This core always has big-endian register interface and uses
178 * big-endian memory descriptors.
179 */
180 ehci->big_endian_mmio = 1;
181 ehci->big_endian_desc = 1;
182
183 /* Check whether the FS support option is selected in the hardware.
184 */
185 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
186 if (value && (*value == 1)) {
187 ehci_dbg(ehci, "USB host controller supports FS devices\n");
188 hcd->has_tt = 1;
189 } else {
190 ehci_dbg(ehci,
191 "USB host controller is HS only\n");
192 hcd->has_tt = 0;
193 }
194
195 /* Debug registers are at the first 0x100 region
196 */
197 ehci->caps = hcd->regs + 0x100;
Julie Zhu08d3c182009-09-21 16:08:19 -0600198
199 rv = usb_add_hcd(hcd, irq, 0);
200 if (rv == 0)
201 return 0;
202
203 iounmap(hcd->regs);
204
205err_ioremap:
206err_irq:
207 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
208err_rmr:
209 usb_put_hcd(hcd);
210
211 return rv;
212}
213
214/**
215 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
Grant Likely2dc11582010-08-06 09:25:50 -0600216 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600217 *
218 * Remove the hcd structure, and release resources that has been requested
219 * during probe.
220 */
Grant Likely2dc11582010-08-06 09:25:50 -0600221static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600222{
223 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
224 dev_set_drvdata(&op->dev, NULL);
225
226 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
227
228 usb_remove_hcd(hcd);
229
230 iounmap(hcd->regs);
231 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
232
233 usb_put_hcd(hcd);
234
235 return 0;
236}
237
238/**
239 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
Grant Likely2dc11582010-08-06 09:25:50 -0600240 * @op: pointer to platform_device structure that is to be removed
Julie Zhu08d3c182009-09-21 16:08:19 -0600241 *
242 * Properly shutdown the hcd, call driver's shutdown routine.
243 */
Herton Ronaldo Krzesinski07828b12012-05-22 13:47:25 -0300244static void ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
Julie Zhu08d3c182009-09-21 16:08:19 -0600245{
246 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
247
248 if (hcd->driver->shutdown)
249 hcd->driver->shutdown(hcd);
Julie Zhu08d3c182009-09-21 16:08:19 -0600250}
251
252
Németh Mártonc4386ad2010-01-10 15:35:03 +0100253static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600254 {.compatible = "xlnx,xps-usb-host-1.00.a",},
255 {},
256};
257MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
258
Grant Likelyd35fb642011-02-22 21:08:34 -0700259static struct platform_driver ehci_hcd_xilinx_of_driver = {
Julie Zhu08d3c182009-09-21 16:08:19 -0600260 .probe = ehci_hcd_xilinx_of_probe,
261 .remove = ehci_hcd_xilinx_of_remove,
262 .shutdown = ehci_hcd_xilinx_of_shutdown,
Grant Likely40182942010-04-13 16:13:02 -0700263 .driver = {
264 .name = "xilinx-of-ehci",
265 .owner = THIS_MODULE,
266 .of_match_table = ehci_hcd_xilinx_of_match,
Julie Zhu08d3c182009-09-21 16:08:19 -0600267 },
268};