Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 2 | /* |
| 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> |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 12 | */ |
| 13 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 14 | #include <linux/err.h> |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 15 | #include <linux/signal.h> |
| 16 | |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/of_platform.h> |
Michal Simek | 337fc72 | 2011-02-14 11:40:09 +0100 | [diff] [blame] | 19 | #include <linux/of_address.h> |
Chen Gang | 13d79f2 | 2014-09-03 23:50:31 +0800 | [diff] [blame] | 20 | #include <linux/of_irq.h> |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 21 | |
| 22 | /** |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 23 | * ehci_xilinx_port_handed_over - hand the port out if failed to enable it |
| 24 | * @hcd: Pointer to the usb_hcd device to which the host controller bound |
| 25 | * @portnum:Port number to which the device is attached. |
| 26 | * |
| 27 | * This function is used as a place to tell the user that the Xilinx USB host |
| 28 | * controller does support LS devices. And in an HS only configuration, it |
| 29 | * does not support FS devices either. It is hoped that this can help a |
| 30 | * confused user. |
| 31 | * |
| 32 | * There are cases when the host controller fails to enable the port due to, |
| 33 | * for example, insufficient power that can be supplied to the device from |
| 34 | * the USB bus. In those cases, the messages printed here are not helpful. |
| 35 | */ |
| 36 | static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum) |
| 37 | { |
| 38 | dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum); |
| 39 | if (hcd->has_tt) { |
| 40 | dev_warn(hcd->self.controller, |
| 41 | "Maybe you have connected a low speed device?\n"); |
| 42 | |
| 43 | dev_warn(hcd->self.controller, |
| 44 | "We do not support low speed devices\n"); |
| 45 | } else { |
| 46 | dev_warn(hcd->self.controller, |
| 47 | "Maybe your device is not a high speed device?\n"); |
| 48 | dev_warn(hcd->self.controller, |
| 49 | "The USB host controller does not support full speed " |
| 50 | "nor low speed devices\n"); |
| 51 | dev_warn(hcd->self.controller, |
| 52 | "You can reconfigure the host controller to have " |
| 53 | "full speed support\n"); |
| 54 | } |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | static const struct hc_driver ehci_xilinx_of_hc_driver = { |
| 61 | .description = hcd_name, |
| 62 | .product_desc = "OF EHCI", |
| 63 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 64 | |
| 65 | /* |
| 66 | * generic hardware linkage |
| 67 | */ |
| 68 | .irq = ehci_irq, |
Christoph Hellwig | 7b81cb6 | 2019-08-16 08:24:32 +0200 | [diff] [blame] | 69 | .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * basic lifecycle operations |
| 73 | */ |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 74 | .reset = ehci_setup, |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 75 | .start = ehci_run, |
| 76 | .stop = ehci_stop, |
| 77 | .shutdown = ehci_shutdown, |
| 78 | |
| 79 | /* |
| 80 | * managing i/o requests and associated device resources |
| 81 | */ |
| 82 | .urb_enqueue = ehci_urb_enqueue, |
| 83 | .urb_dequeue = ehci_urb_dequeue, |
| 84 | .endpoint_disable = ehci_endpoint_disable, |
Paul Mundt | b48d7f5 | 2010-11-30 17:57:02 +0900 | [diff] [blame] | 85 | .endpoint_reset = ehci_endpoint_reset, |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * scheduling support |
| 89 | */ |
| 90 | .get_frame_number = ehci_get_frame, |
| 91 | |
| 92 | /* |
| 93 | * root hub support |
| 94 | */ |
| 95 | .hub_status_data = ehci_hub_status_data, |
| 96 | .hub_control = ehci_hub_control, |
| 97 | #ifdef CONFIG_PM |
| 98 | .bus_suspend = ehci_bus_suspend, |
| 99 | .bus_resume = ehci_bus_resume, |
| 100 | #endif |
| 101 | .relinquish_port = NULL, |
| 102 | .port_handed_over = ehci_xilinx_port_handed_over, |
| 103 | |
| 104 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 109 | * @op: pointer to the platform_device bound to the host controller |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 110 | * |
| 111 | * This function requests resources and sets up appropriate properties for the |
| 112 | * host controller. Because the Xilinx USB host controller can be configured |
| 113 | * as HS only or HS/FS only, it checks the configuration in the device tree |
| 114 | * entry, and sets an appropriate value for hcd->has_tt. |
| 115 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 116 | static int ehci_hcd_xilinx_of_probe(struct platform_device *op) |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 117 | { |
Grant Likely | ffabc9a | 2010-06-02 13:35:02 -0600 | [diff] [blame] | 118 | struct device_node *dn = op->dev.of_node; |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 119 | struct usb_hcd *hcd; |
| 120 | struct ehci_hcd *ehci; |
| 121 | struct resource res; |
| 122 | int irq; |
| 123 | int rv; |
| 124 | int *value; |
| 125 | |
| 126 | if (usb_disabled()) |
| 127 | return -ENODEV; |
| 128 | |
| 129 | dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n"); |
| 130 | |
| 131 | rv = of_address_to_resource(dn, 0, &res); |
| 132 | if (rv) |
| 133 | return rv; |
| 134 | |
| 135 | hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev, |
| 136 | "XILINX-OF USB"); |
| 137 | if (!hcd) |
| 138 | return -ENOMEM; |
| 139 | |
| 140 | hcd->rsrc_start = res.start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 141 | hcd->rsrc_len = resource_size(&res); |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 142 | |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 143 | irq = irq_of_parse_and_map(dn, 0); |
Michal Simek | 7f788ec | 2012-01-12 09:18:03 +0100 | [diff] [blame] | 144 | if (!irq) { |
Jingoo Han | a74cf5c | 2013-12-10 21:24:24 +0900 | [diff] [blame] | 145 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
| 146 | __FILE__); |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 147 | rv = -EBUSY; |
| 148 | goto err_irq; |
| 149 | } |
| 150 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 151 | hcd->regs = devm_ioremap_resource(&op->dev, &res); |
| 152 | if (IS_ERR(hcd->regs)) { |
| 153 | rv = PTR_ERR(hcd->regs); |
Julia Lawall | 6df471e | 2012-07-30 16:43:39 +0200 | [diff] [blame] | 154 | goto err_irq; |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | ehci = hcd_to_ehci(hcd); |
| 158 | |
| 159 | /* This core always has big-endian register interface and uses |
| 160 | * big-endian memory descriptors. |
| 161 | */ |
| 162 | ehci->big_endian_mmio = 1; |
| 163 | ehci->big_endian_desc = 1; |
| 164 | |
| 165 | /* Check whether the FS support option is selected in the hardware. |
| 166 | */ |
| 167 | value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL); |
| 168 | if (value && (*value == 1)) { |
| 169 | ehci_dbg(ehci, "USB host controller supports FS devices\n"); |
| 170 | hcd->has_tt = 1; |
| 171 | } else { |
| 172 | ehci_dbg(ehci, |
| 173 | "USB host controller is HS only\n"); |
| 174 | hcd->has_tt = 0; |
| 175 | } |
| 176 | |
| 177 | /* Debug registers are at the first 0x100 region |
| 178 | */ |
| 179 | ehci->caps = hcd->regs + 0x100; |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 180 | |
| 181 | rv = usb_add_hcd(hcd, irq, 0); |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 182 | if (rv == 0) { |
| 183 | device_wakeup_enable(hcd->self.controller); |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 184 | return 0; |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 185 | } |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 186 | |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 187 | err_irq: |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 188 | usb_put_hcd(hcd); |
| 189 | |
| 190 | return rv; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 195 | * @op: pointer to platform_device structure that is to be removed |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 196 | * |
| 197 | * Remove the hcd structure, and release resources that has been requested |
| 198 | * during probe. |
| 199 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 200 | static int ehci_hcd_xilinx_of_remove(struct platform_device *op) |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 201 | { |
Jingoo Han | 477527b | 2013-05-23 19:18:39 +0900 | [diff] [blame] | 202 | struct usb_hcd *hcd = platform_get_drvdata(op); |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 203 | |
| 204 | dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n"); |
| 205 | |
| 206 | usb_remove_hcd(hcd); |
| 207 | |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 208 | usb_put_hcd(hcd); |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
Németh Márton | c4386ad | 2010-01-10 15:35:03 +0100 | [diff] [blame] | 213 | static const struct of_device_id ehci_hcd_xilinx_of_match[] = { |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 214 | {.compatible = "xlnx,xps-usb-host-1.00.a",}, |
| 215 | {}, |
| 216 | }; |
| 217 | MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match); |
| 218 | |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 219 | static struct platform_driver ehci_hcd_xilinx_of_driver = { |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 220 | .probe = ehci_hcd_xilinx_of_probe, |
| 221 | .remove = ehci_hcd_xilinx_of_remove, |
Roger Quadros | aaf6b52 | 2013-07-22 15:04:50 +0300 | [diff] [blame] | 222 | .shutdown = usb_hcd_platform_shutdown, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 223 | .driver = { |
| 224 | .name = "xilinx-of-ehci", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 225 | .of_match_table = ehci_hcd_xilinx_of_match, |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 226 | }, |
| 227 | }; |