aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/xhci-pci.c')
-rw-r--r--drivers/usb/host/xhci-pci.c124
1 files changed, 114 insertions, 10 deletions
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index bb668a894ab9..ceea9f33491c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -50,13 +50,45 @@ static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
50/* called during probe() after chip reset completes */ 50/* called during probe() after chip reset completes */
51static int xhci_pci_setup(struct usb_hcd *hcd) 51static int xhci_pci_setup(struct usb_hcd *hcd)
52{ 52{
53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 53 struct xhci_hcd *xhci;
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 55 int retval;
56 u32 temp; 56 u32 temp;
57 57
58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
59 59
60 if (usb_hcd_is_primary_hcd(hcd)) {
61 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
62 if (!xhci)
63 return -ENOMEM;
64 *((struct xhci_hcd **) hcd->hcd_priv) = xhci;
65 xhci->main_hcd = hcd;
66 /* Mark the first roothub as being USB 2.0.
67 * The xHCI driver will register the USB 3.0 roothub.
68 */
69 hcd->speed = HCD_USB2;
70 hcd->self.root_hub->speed = USB_SPEED_HIGH;
71 /*
72 * USB 2.0 roothub under xHCI has an integrated TT,
73 * (rate matching hub) as opposed to having an OHCI/UHCI
74 * companion controller.
75 */
76 hcd->has_tt = 1;
77 } else {
78 /* xHCI private pointer was set in xhci_pci_probe for the second
79 * registered roothub.
80 */
81 xhci = hcd_to_xhci(hcd);
82 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
83 if (HCC_64BIT_ADDR(temp)) {
84 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
85 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
86 } else {
87 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
88 }
89 return 0;
90 }
91
60 xhci->cap_regs = hcd->regs; 92 xhci->cap_regs = hcd->regs;
61 xhci->op_regs = hcd->regs + 93 xhci->op_regs = hcd->regs +
62 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); 94 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase));
@@ -85,13 +117,13 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
85 /* Make sure the HC is halted. */ 117 /* Make sure the HC is halted. */
86 retval = xhci_halt(xhci); 118 retval = xhci_halt(xhci);
87 if (retval) 119 if (retval)
88 return retval; 120 goto error;
89 121
90 xhci_dbg(xhci, "Resetting HCD\n"); 122 xhci_dbg(xhci, "Resetting HCD\n");
91 /* Reset the internal HC memory state and registers. */ 123 /* Reset the internal HC memory state and registers. */
92 retval = xhci_reset(xhci); 124 retval = xhci_reset(xhci);
93 if (retval) 125 if (retval)
94 return retval; 126 goto error;
95 xhci_dbg(xhci, "Reset complete\n"); 127 xhci_dbg(xhci, "Reset complete\n");
96 128
97 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 129 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
@@ -106,14 +138,85 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
106 /* Initialize HCD and host controller data structures. */ 138 /* Initialize HCD and host controller data structures. */
107 retval = xhci_init(hcd); 139 retval = xhci_init(hcd);
108 if (retval) 140 if (retval)
109 return retval; 141 goto error;
110 xhci_dbg(xhci, "Called HCD init\n"); 142 xhci_dbg(xhci, "Called HCD init\n");
111 143
112 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); 144 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
113 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); 145 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
114 146
115 /* Find any debug ports */ 147 /* Find any debug ports */
116 return xhci_pci_reinit(xhci, pdev); 148 retval = xhci_pci_reinit(xhci, pdev);
149 if (!retval)
150 return retval;
151
152error:
153 kfree(xhci);
154 return retval;
155}
156
157/*
158 * We need to register our own PCI probe function (instead of the USB core's
159 * function) in order to create a second roothub under xHCI.
160 */
161static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
162{
163 int retval;
164 struct xhci_hcd *xhci;
165 struct hc_driver *driver;
166 struct usb_hcd *hcd;
167
168 driver = (struct hc_driver *)id->driver_data;
169 /* Register the USB 2.0 roothub.
170 * FIXME: USB core must know to register the USB 2.0 roothub first.
171 * This is sort of silly, because we could just set the HCD driver flags
172 * to say USB 2.0, but I'm not sure what the implications would be in
173 * the other parts of the HCD code.
174 */
175 retval = usb_hcd_pci_probe(dev, id);
176
177 if (retval)
178 return retval;
179
180 /* USB 2.0 roothub is stored in the PCI device now. */
181 hcd = dev_get_drvdata(&dev->dev);
182 xhci = hcd_to_xhci(hcd);
183 xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
184 pci_name(dev), hcd);
185 if (!xhci->shared_hcd) {
186 retval = -ENOMEM;
187 goto dealloc_usb2_hcd;
188 }
189
190 /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset)
191 * is called by usb_add_hcd().
192 */
193 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
194
195 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
196 IRQF_DISABLED | IRQF_SHARED);
197 if (retval)
198 goto put_usb3_hcd;
199 /* Roothub already marked as USB 3.0 speed */
200 return 0;
201
202put_usb3_hcd:
203 usb_put_hcd(xhci->shared_hcd);
204dealloc_usb2_hcd:
205 usb_hcd_pci_remove(dev);
206 return retval;
207}
208
209static void xhci_pci_remove(struct pci_dev *dev)
210{
211 struct xhci_hcd *xhci;
212
213 xhci = hcd_to_xhci(pci_get_drvdata(dev));
214 if (xhci->shared_hcd) {
215 usb_remove_hcd(xhci->shared_hcd);
216 usb_put_hcd(xhci->shared_hcd);
217 }
218 usb_hcd_pci_remove(dev);
219 kfree(xhci);
117} 220}
118 221
119#ifdef CONFIG_PM 222#ifdef CONFIG_PM
@@ -122,7 +225,8 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
122 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 225 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
123 int retval = 0; 226 int retval = 0;
124 227
125 if (hcd->state != HC_STATE_SUSPENDED) 228 if (hcd->state != HC_STATE_SUSPENDED ||
229 xhci->shared_hcd->state != HC_STATE_SUSPENDED)
126 return -EINVAL; 230 return -EINVAL;
127 231
128 retval = xhci_suspend(xhci); 232 retval = xhci_suspend(xhci);
@@ -143,13 +247,13 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
143static const struct hc_driver xhci_pci_hc_driver = { 247static const struct hc_driver xhci_pci_hc_driver = {
144 .description = hcd_name, 248 .description = hcd_name,
145 .product_desc = "xHCI Host Controller", 249 .product_desc = "xHCI Host Controller",
146 .hcd_priv_size = sizeof(struct xhci_hcd), 250 .hcd_priv_size = sizeof(struct xhci_hcd *),
147 251
148 /* 252 /*
149 * generic hardware linkage 253 * generic hardware linkage
150 */ 254 */
151 .irq = xhci_irq, 255 .irq = xhci_irq,
152 .flags = HCD_MEMORY | HCD_USB3, 256 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
153 257
154 /* 258 /*
155 * basic lifecycle operations 259 * basic lifecycle operations
@@ -210,8 +314,8 @@ static struct pci_driver xhci_pci_driver = {
210 .name = (char *) hcd_name, 314 .name = (char *) hcd_name,
211 .id_table = pci_ids, 315 .id_table = pci_ids,
212 316
213 .probe = usb_hcd_pci_probe, 317 .probe = xhci_pci_probe,
214 .remove = usb_hcd_pci_remove, 318 .remove = xhci_pci_remove,
215 /* suspend and resume implemented later */ 319 /* suspend and resume implemented later */
216 320
217 .shutdown = usb_hcd_pci_shutdown, 321 .shutdown = usb_hcd_pci_shutdown,