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 28 #include <linux/signal.h> 29 30 #include <linux/of.h> 31 #include <linux/of_platform.h> 32 33 /** 34 * ehci_xilinx_of_setup - Initialize the device for ehci_reset() 35 * @hcd: Pointer to the usb_hcd device to which the host controller bound 36 * 37 * called during probe() after chip reset completes. 38 */ 39 static int ehci_xilinx_of_setup(struct usb_hcd *hcd) 40 { 41 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 42 int retval; 43 44 retval = ehci_halt(ehci); 45 if (retval) 46 return retval; 47 48 retval = ehci_init(hcd); 49 if (retval) 50 return retval; 51 52 ehci->sbrn = 0x20; 53 54 return ehci_reset(ehci); 55 } 56 57 /** 58 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it 59 * @hcd: Pointer to the usb_hcd device to which the host controller bound 60 * @portnum:Port number to which the device is attached. 61 * 62 * This function is used as a place to tell the user that the Xilinx USB host 63 * controller does support LS devices. And in an HS only configuration, it 64 * does not support FS devices either. It is hoped that this can help a 65 * confused user. 66 * 67 * There are cases when the host controller fails to enable the port due to, 68 * for example, insufficient power that can be supplied to the device from 69 * the USB bus. In those cases, the messages printed here are not helpful. 70 */ 71 static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum) 72 { 73 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum); 74 if (hcd->has_tt) { 75 dev_warn(hcd->self.controller, 76 "Maybe you have connected a low speed device?\n"); 77 78 dev_warn(hcd->self.controller, 79 "We do not support low speed devices\n"); 80 } else { 81 dev_warn(hcd->self.controller, 82 "Maybe your device is not a high speed device?\n"); 83 dev_warn(hcd->self.controller, 84 "The USB host controller does not support full speed " 85 "nor low speed devices\n"); 86 dev_warn(hcd->self.controller, 87 "You can reconfigure the host controller to have " 88 "full speed support\n"); 89 } 90 91 return 0; 92 } 93 94 95 static const struct hc_driver ehci_xilinx_of_hc_driver = { 96 .description = hcd_name, 97 .product_desc = "OF EHCI", 98 .hcd_priv_size = sizeof(struct ehci_hcd), 99 100 /* 101 * generic hardware linkage 102 */ 103 .irq = ehci_irq, 104 .flags = HCD_MEMORY | HCD_USB2, 105 106 /* 107 * basic lifecycle operations 108 */ 109 .reset = ehci_xilinx_of_setup, 110 .start = ehci_run, 111 .stop = ehci_stop, 112 .shutdown = ehci_shutdown, 113 114 /* 115 * managing i/o requests and associated device resources 116 */ 117 .urb_enqueue = ehci_urb_enqueue, 118 .urb_dequeue = ehci_urb_dequeue, 119 .endpoint_disable = ehci_endpoint_disable, 120 .endpoint_reset = ehci_endpoint_reset, 121 122 /* 123 * scheduling support 124 */ 125 .get_frame_number = ehci_get_frame, 126 127 /* 128 * root hub support 129 */ 130 .hub_status_data = ehci_hub_status_data, 131 .hub_control = ehci_hub_control, 132 #ifdef CONFIG_PM 133 .bus_suspend = ehci_bus_suspend, 134 .bus_resume = ehci_bus_resume, 135 #endif 136 .relinquish_port = NULL, 137 .port_handed_over = ehci_xilinx_port_handed_over, 138 139 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 140 }; 141 142 /** 143 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller 144 * @op: pointer to the platform_device bound to the host controller 145 * @match: pointer to of_device_id structure, not used 146 * 147 * This function requests resources and sets up appropriate properties for the 148 * host controller. Because the Xilinx USB host controller can be configured 149 * as HS only or HS/FS only, it checks the configuration in the device tree 150 * entry, and sets an appropriate value for hcd->has_tt. 151 */ 152 static int __devinit 153 ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *match) 154 { 155 struct device_node *dn = op->dev.of_node; 156 struct usb_hcd *hcd; 157 struct ehci_hcd *ehci; 158 struct resource res; 159 int irq; 160 int rv; 161 int *value; 162 163 if (usb_disabled()) 164 return -ENODEV; 165 166 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n"); 167 168 rv = of_address_to_resource(dn, 0, &res); 169 if (rv) 170 return rv; 171 172 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev, 173 "XILINX-OF USB"); 174 if (!hcd) 175 return -ENOMEM; 176 177 hcd->rsrc_start = res.start; 178 hcd->rsrc_len = res.end - res.start + 1; 179 180 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 181 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__); 182 rv = -EBUSY; 183 goto err_rmr; 184 } 185 186 irq = irq_of_parse_and_map(dn, 0); 187 if (irq == NO_IRQ) { 188 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); 189 rv = -EBUSY; 190 goto err_irq; 191 } 192 193 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 194 if (!hcd->regs) { 195 printk(KERN_ERR "%s: ioremap failed\n", __FILE__); 196 rv = -ENOMEM; 197 goto err_ioremap; 198 } 199 200 ehci = hcd_to_ehci(hcd); 201 202 /* This core always has big-endian register interface and uses 203 * big-endian memory descriptors. 204 */ 205 ehci->big_endian_mmio = 1; 206 ehci->big_endian_desc = 1; 207 208 /* Check whether the FS support option is selected in the hardware. 209 */ 210 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL); 211 if (value && (*value == 1)) { 212 ehci_dbg(ehci, "USB host controller supports FS devices\n"); 213 hcd->has_tt = 1; 214 } else { 215 ehci_dbg(ehci, 216 "USB host controller is HS only\n"); 217 hcd->has_tt = 0; 218 } 219 220 /* Debug registers are at the first 0x100 region 221 */ 222 ehci->caps = hcd->regs + 0x100; 223 ehci->regs = hcd->regs + 0x100 + 224 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 225 226 /* cache this readonly data; minimize chip reads */ 227 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 228 229 rv = usb_add_hcd(hcd, irq, 0); 230 if (rv == 0) 231 return 0; 232 233 iounmap(hcd->regs); 234 235 err_ioremap: 236 err_irq: 237 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 238 err_rmr: 239 usb_put_hcd(hcd); 240 241 return rv; 242 } 243 244 /** 245 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources 246 * @op: pointer to platform_device structure that is to be removed 247 * 248 * Remove the hcd structure, and release resources that has been requested 249 * during probe. 250 */ 251 static int ehci_hcd_xilinx_of_remove(struct platform_device *op) 252 { 253 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 254 dev_set_drvdata(&op->dev, NULL); 255 256 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n"); 257 258 usb_remove_hcd(hcd); 259 260 iounmap(hcd->regs); 261 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 262 263 usb_put_hcd(hcd); 264 265 return 0; 266 } 267 268 /** 269 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd 270 * @op: pointer to platform_device structure that is to be removed 271 * 272 * Properly shutdown the hcd, call driver's shutdown routine. 273 */ 274 static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op) 275 { 276 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 277 278 if (hcd->driver->shutdown) 279 hcd->driver->shutdown(hcd); 280 281 return 0; 282 } 283 284 285 static const struct of_device_id ehci_hcd_xilinx_of_match[] = { 286 {.compatible = "xlnx,xps-usb-host-1.00.a",}, 287 {}, 288 }; 289 MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match); 290 291 static struct of_platform_driver ehci_hcd_xilinx_of_driver = { 292 .probe = ehci_hcd_xilinx_of_probe, 293 .remove = ehci_hcd_xilinx_of_remove, 294 .shutdown = ehci_hcd_xilinx_of_shutdown, 295 .driver = { 296 .name = "xilinx-of-ehci", 297 .owner = THIS_MODULE, 298 .of_match_table = ehci_hcd_xilinx_of_match, 299 }, 300 }; 301