2 * EHCI HCD (Host Controller Driver) for USB.
4 * Bus Glue for Xilinx EHCI core on the of_platform bus
6 * Copyright (c) 2009 Xilinx, Inc.
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>
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.
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
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.
28 #include <linux/signal.h>
31 #include <linux/of_platform.h>
32 #include <linux/of_address.h>
35 * 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.
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
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.
48 static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
50 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
52 dev_warn(hcd->self.controller,
53 "Maybe you have connected a low speed device?\n");
55 dev_warn(hcd->self.controller,
56 "We do not support low speed devices\n");
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");
72 static 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),
78 * generic hardware linkage
81 .flags = HCD_MEMORY | HCD_USB2,
84 * basic lifecycle operations
89 .shutdown = ehci_shutdown,
92 * managing i/o requests and associated device resources
94 .urb_enqueue = ehci_urb_enqueue,
95 .urb_dequeue = ehci_urb_dequeue,
96 .endpoint_disable = ehci_endpoint_disable,
97 .endpoint_reset = ehci_endpoint_reset,
102 .get_frame_number = ehci_get_frame,
107 .hub_status_data = ehci_hub_status_data,
108 .hub_control = ehci_hub_control,
110 .bus_suspend = ehci_bus_suspend,
111 .bus_resume = ehci_bus_resume,
113 .relinquish_port = NULL,
114 .port_handed_over = ehci_xilinx_port_handed_over,
116 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
120 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
121 * @op: pointer to the platform_device bound to the host controller
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.
128 static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
130 struct device_node *dn = op->dev.of_node;
132 struct ehci_hcd *ehci;
141 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
143 rv = of_address_to_resource(dn, 0, &res);
147 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
152 hcd->rsrc_start = res.start;
153 hcd->rsrc_len = resource_size(&res);
155 irq = irq_of_parse_and_map(dn, 0);
157 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
162 hcd->regs = devm_request_and_ioremap(&op->dev, &res);
164 pr_err("%s: devm_request_and_ioremap failed\n", __FILE__);
169 ehci = hcd_to_ehci(hcd);
171 /* This core always has big-endian register interface and uses
172 * big-endian memory descriptors.
174 ehci->big_endian_mmio = 1;
175 ehci->big_endian_desc = 1;
177 /* Check whether the FS support option is selected in the hardware.
179 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
180 if (value && (*value == 1)) {
181 ehci_dbg(ehci, "USB host controller supports FS devices\n");
185 "USB host controller is HS only\n");
189 /* Debug registers are at the first 0x100 region
191 ehci->caps = hcd->regs + 0x100;
193 rv = usb_add_hcd(hcd, irq, 0);
204 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
205 * @op: pointer to platform_device structure that is to be removed
207 * Remove the hcd structure, and release resources that has been requested
210 static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
212 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
213 dev_set_drvdata(&op->dev, NULL);
215 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
225 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
226 * @op: pointer to platform_device structure that is to be removed
228 * Properly shutdown the hcd, call driver's shutdown routine.
230 static void ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
232 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
234 if (hcd->driver->shutdown)
235 hcd->driver->shutdown(hcd);
239 static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
240 {.compatible = "xlnx,xps-usb-host-1.00.a",},
243 MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
245 static struct platform_driver ehci_hcd_xilinx_of_driver = {
246 .probe = ehci_hcd_xilinx_of_probe,
247 .remove = ehci_hcd_xilinx_of_remove,
248 .shutdown = ehci_hcd_xilinx_of_shutdown,
250 .name = "xilinx-of-ehci",
251 .owner = THIS_MODULE,
252 .of_match_table = ehci_hcd_xilinx_of_match,