1/* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */ 2/* 3 * xHCI host controller driver PCI Bus Glue. 4 * 5 * Copyright (C) 2008 Intel Corp. 6 * 7 * Author: Sarah Sharp 8 * Some code borrowed from the Linux EHCI driver. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License version 2 as 12 * published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 * for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software Foundation, 21 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 */ 23 24#include <linux/pci.h> 25 26#include "xhci.h" 27 28/* Device for a quirk */ 29#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 30#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 31 32static const char hcd_name[] = "xhci_hcd"; 33 34/* called after powerup, by probe or system-pm "wakeup" */ 35static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) 36{ 37 /* 38 * TODO: Implement finding debug ports later. 39 * TODO: see if there are any quirks that need to be added to handle 40 * new extended capabilities. 41 */ 42 43 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */ 44 if (!pci_set_mwi(pdev)) 45 xhci_dbg(xhci, "MWI active\n"); 46 47 xhci_dbg(xhci, "Finished xhci_pci_reinit\n"); 48 return 0; 49} 50 51/* called during probe() after chip reset completes */ 52static int xhci_pci_setup(struct usb_hcd *hcd) 53{ 54 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 55 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 56 int retval; 57 u32 temp; 58 59#ifdef CONFIG_BCM47XX 60 hcd->self.sg_tablesize = (TRBS_PER_SEGMENT - 2) / 2; 61#else 62 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 63#endif 64 65 xhci->cap_regs = hcd->regs; 66 xhci->op_regs = hcd->regs + 67 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); 68 xhci->run_regs = hcd->regs + 69 (xhci_readl(xhci, &xhci->cap_regs->run_regs_off) & RTSOFF_MASK); 70 /* Cache read-only capability registers */ 71 xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); 72 xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); 73 xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); 74 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); 75 xhci->hci_version = HC_VERSION(xhci->hcc_params); 76 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 77 xhci_print_registers(xhci); 78 79 /* Look for vendor-specific quirks */ 80 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && 81 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && 82 pdev->revision == 0x0) { 83 xhci->quirks |= XHCI_RESET_EP_QUIRK; 84 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure" 85 " endpoint cmd after reset endpoint\n"); 86 } 87 if (pdev->vendor == PCI_VENDOR_ID_NEC) 88 xhci->quirks |= XHCI_NEC_HOST; 89 90 /* Make sure the HC is halted. */ 91 retval = xhci_halt(xhci); 92 if (retval) 93 return retval; 94 95 xhci_dbg(xhci, "Resetting HCD\n"); 96 /* Reset the internal HC memory state and registers. */ 97 retval = xhci_reset(xhci); 98 if (retval) 99 return retval; 100 xhci_dbg(xhci, "Reset complete\n"); 101 102 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 103 if (HCC_64BIT_ADDR(temp)) { 104 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); 105 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); 106 } else { 107 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); 108 } 109 110 xhci_dbg(xhci, "Calling HCD init\n"); 111 /* Initialize HCD and host controller data structures. */ 112 retval = xhci_init(hcd); 113 if (retval) 114 return retval; 115 xhci_dbg(xhci, "Called HCD init\n"); 116 117 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); 118 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); 119 120 /* Find any debug ports */ 121 return xhci_pci_reinit(xhci, pdev); 122} 123 124static const struct hc_driver xhci_pci_hc_driver = { 125 .description = hcd_name, 126 .product_desc = "xHCI Host Controller", 127 .hcd_priv_size = sizeof(struct xhci_hcd), 128 129 /* 130 * generic hardware linkage 131 */ 132 .irq = xhci_irq, 133 .flags = HCD_MEMORY | HCD_USB3, 134 135 /* 136 * basic lifecycle operations 137 */ 138 .reset = xhci_pci_setup, 139 .start = xhci_run, 140 /* suspend and resume implemented later */ 141 .stop = xhci_stop, 142 .shutdown = xhci_shutdown, 143 144 /* 145 * managing i/o requests and associated device resources 146 */ 147 .urb_enqueue = xhci_urb_enqueue, 148 .urb_dequeue = xhci_urb_dequeue, 149 .alloc_dev = xhci_alloc_dev, 150 .free_dev = xhci_free_dev, 151 .alloc_streams = xhci_alloc_streams, 152 .free_streams = xhci_free_streams, 153 .add_endpoint = xhci_add_endpoint, 154 .drop_endpoint = xhci_drop_endpoint, 155 .endpoint_reset = xhci_endpoint_reset, 156 .check_bandwidth = xhci_check_bandwidth, 157 .reset_bandwidth = xhci_reset_bandwidth, 158 .address_device = xhci_address_device, 159 .update_hub_device = xhci_update_hub_device, 160 .reset_device = xhci_reset_device, 161 162 /* 163 * scheduling support 164 */ 165 .get_frame_number = xhci_get_frame, 166 167 /* Root hub support */ 168 .hub_control = xhci_hub_control, 169 .hub_status_data = xhci_hub_status_data, 170}; 171 172/*-------------------------------------------------------------------------*/ 173 174/* PCI driver selection metadata; PCI hotplugging uses this */ 175static const struct pci_device_id pci_ids[] = { { 176 /* handle any USB 3.0 xHCI controller */ 177 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), 178 .driver_data = (unsigned long) &xhci_pci_hc_driver, 179 }, 180 { /* end: all zeroes */ } 181}; 182MODULE_DEVICE_TABLE(pci, pci_ids); 183 184/* pci driver glue; this is a "new style" PCI driver module */ 185static struct pci_driver xhci_pci_driver = { 186 .name = (char *) hcd_name, 187 .id_table = pci_ids, 188 189 .probe = usb_hcd_pci_probe, 190 .remove = usb_hcd_pci_remove, 191 /* suspend and resume implemented later */ 192 193 .shutdown = usb_hcd_pci_shutdown, 194}; 195 196int xhci_register_pci(void) 197{ 198 return pci_register_driver(&xhci_pci_driver); 199} 200 201void xhci_unregister_pci(void) 202{ 203 pci_unregister_driver(&xhci_pci_driver); 204} 205