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