Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 2 | /* |
| 3 | * USB HOST XHCI Controller stack |
| 4 | * |
| 5 | * Based on xHCI host controller driver in linux-kernel |
| 6 | * by Sarah Sharp. |
| 7 | * |
| 8 | * Copyright (C) 2008 Intel Corp. |
| 9 | * Author: Sarah Sharp |
| 10 | * |
| 11 | * Copyright (C) 2013 Samsung Electronics Co.Ltd |
| 12 | * Authors: Vivek Gautam <gautam.vivek@samsung.com> |
| 13 | * Vikas Sajjan <vikas.sajjan@samsung.com> |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * This file gives the xhci stack for usb3.0 looking into |
| 18 | * xhci specification Rev1.0 (5/21/10). |
| 19 | * The quirk devices support hasn't been given yet. |
| 20 | */ |
| 21 | |
| 22 | #include <common.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 23 | #include <cpu_func.h> |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 24 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 25 | #include <log.h> |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 26 | #include <asm/byteorder.h> |
| 27 | #include <usb.h> |
| 28 | #include <malloc.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <asm/cache.h> |
| 31 | #include <asm/unaligned.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 32 | #include <linux/bitops.h> |
Simon Glass | eb41d8a | 2020-05-10 11:40:08 -0600 | [diff] [blame] | 33 | #include <linux/bug.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 34 | #include <linux/delay.h> |
Masahiro Yamada | 5d97dff | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 35 | #include <linux/errno.h> |
Chunfeng Yun | a6837a0 | 2020-09-08 19:00:03 +0200 | [diff] [blame] | 36 | #include <linux/iopoll.h> |
Jean-Jacques Hiblot | 1708a12 | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 37 | #include <usb/xhci.h> |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 38 | |
| 39 | #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT |
| 40 | #define CONFIG_USB_MAX_CONTROLLER_COUNT 1 |
| 41 | #endif |
| 42 | |
| 43 | static struct descriptor { |
| 44 | struct usb_hub_descriptor hub; |
| 45 | struct usb_device_descriptor device; |
| 46 | struct usb_config_descriptor config; |
| 47 | struct usb_interface_descriptor interface; |
| 48 | struct usb_endpoint_descriptor endpoint; |
| 49 | struct usb_ss_ep_comp_descriptor ep_companion; |
| 50 | } __attribute__ ((packed)) descriptor = { |
| 51 | { |
| 52 | 0xc, /* bDescLength */ |
| 53 | 0x2a, /* bDescriptorType: hub descriptor */ |
| 54 | 2, /* bNrPorts -- runtime modified */ |
| 55 | cpu_to_le16(0x8), /* wHubCharacteristics */ |
| 56 | 10, /* bPwrOn2PwrGood */ |
| 57 | 0, /* bHubCntrCurrent */ |
Bin Meng | 337fc7e | 2017-07-19 21:50:00 +0800 | [diff] [blame] | 58 | { /* Device removable */ |
| 59 | } /* at most 7 ports! XXX */ |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 60 | }, |
| 61 | { |
| 62 | 0x12, /* bLength */ |
| 63 | 1, /* bDescriptorType: UDESC_DEVICE */ |
| 64 | cpu_to_le16(0x0300), /* bcdUSB: v3.0 */ |
| 65 | 9, /* bDeviceClass: UDCLASS_HUB */ |
| 66 | 0, /* bDeviceSubClass: UDSUBCLASS_HUB */ |
| 67 | 3, /* bDeviceProtocol: UDPROTO_SSHUBSTT */ |
| 68 | 9, /* bMaxPacketSize: 512 bytes 2^9 */ |
| 69 | 0x0000, /* idVendor */ |
| 70 | 0x0000, /* idProduct */ |
| 71 | cpu_to_le16(0x0100), /* bcdDevice */ |
| 72 | 1, /* iManufacturer */ |
| 73 | 2, /* iProduct */ |
| 74 | 0, /* iSerialNumber */ |
| 75 | 1 /* bNumConfigurations: 1 */ |
| 76 | }, |
| 77 | { |
| 78 | 0x9, |
| 79 | 2, /* bDescriptorType: UDESC_CONFIG */ |
| 80 | cpu_to_le16(0x1f), /* includes SS endpoint descriptor */ |
| 81 | 1, /* bNumInterface */ |
| 82 | 1, /* bConfigurationValue */ |
| 83 | 0, /* iConfiguration */ |
| 84 | 0x40, /* bmAttributes: UC_SELF_POWER */ |
| 85 | 0 /* bMaxPower */ |
| 86 | }, |
| 87 | { |
| 88 | 0x9, /* bLength */ |
| 89 | 4, /* bDescriptorType: UDESC_INTERFACE */ |
| 90 | 0, /* bInterfaceNumber */ |
| 91 | 0, /* bAlternateSetting */ |
| 92 | 1, /* bNumEndpoints */ |
| 93 | 9, /* bInterfaceClass: UICLASS_HUB */ |
| 94 | 0, /* bInterfaceSubClass: UISUBCLASS_HUB */ |
| 95 | 0, /* bInterfaceProtocol: UIPROTO_HSHUBSTT */ |
| 96 | 0 /* iInterface */ |
| 97 | }, |
| 98 | { |
| 99 | 0x7, /* bLength */ |
| 100 | 5, /* bDescriptorType: UDESC_ENDPOINT */ |
| 101 | 0x81, /* bEndpointAddress: IN endpoint 1 */ |
| 102 | 3, /* bmAttributes: UE_INTERRUPT */ |
| 103 | 8, /* wMaxPacketSize */ |
| 104 | 255 /* bInterval */ |
| 105 | }, |
| 106 | { |
| 107 | 0x06, /* ss_bLength */ |
| 108 | 0x30, /* ss_bDescriptorType: SS EP Companion */ |
| 109 | 0x00, /* ss_bMaxBurst: allows 1 TX between ACKs */ |
| 110 | /* ss_bmAttributes: 1 packet per service interval */ |
| 111 | 0x00, |
| 112 | /* ss_wBytesPerInterval: 15 bits for max 15 ports */ |
| 113 | cpu_to_le16(0x02), |
| 114 | }, |
| 115 | }; |
| 116 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 117 | #if !CONFIG_IS_ENABLED(DM_USB) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 118 | static struct xhci_ctrl xhcic[CONFIG_USB_MAX_CONTROLLER_COUNT]; |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 119 | #endif |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 120 | |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 121 | struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev) |
| 122 | { |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 123 | #if CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 124 | struct udevice *dev; |
| 125 | |
| 126 | /* Find the USB controller */ |
| 127 | for (dev = udev->dev; |
| 128 | device_get_uclass_id(dev) != UCLASS_USB; |
| 129 | dev = dev->parent) |
| 130 | ; |
| 131 | return dev_get_priv(dev); |
| 132 | #else |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 133 | return udev->controller; |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 134 | #endif |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 135 | } |
| 136 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 137 | /** |
| 138 | * Waits for as per specified amount of time |
| 139 | * for the "result" to match with "done" |
| 140 | * |
| 141 | * @param ptr pointer to the register to be read |
| 142 | * @param mask mask for the value read |
| 143 | * @param done value to be campared with result |
| 144 | * @param usec time to wait till |
| 145 | * @return 0 if handshake is success else < 0 on failure |
| 146 | */ |
Chunfeng Yun | a6837a0 | 2020-09-08 19:00:03 +0200 | [diff] [blame] | 147 | static int |
| 148 | handshake(uint32_t volatile *ptr, uint32_t mask, uint32_t done, int usec) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 149 | { |
| 150 | uint32_t result; |
Chunfeng Yun | a6837a0 | 2020-09-08 19:00:03 +0200 | [diff] [blame] | 151 | int ret; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 152 | |
Chunfeng Yun | a6837a0 | 2020-09-08 19:00:03 +0200 | [diff] [blame] | 153 | ret = readx_poll_sleep_timeout(xhci_readl, ptr, result, |
| 154 | (result & mask) == done || result == U32_MAX, |
| 155 | 1, usec); |
| 156 | if (result == U32_MAX) /* card removed */ |
| 157 | return -ENODEV; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 158 | |
Chunfeng Yun | a6837a0 | 2020-09-08 19:00:03 +0200 | [diff] [blame] | 159 | return ret; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Set the run bit and wait for the host to be running. |
| 164 | * |
| 165 | * @param hcor pointer to host controller operation registers |
| 166 | * @return status of the Handshake |
| 167 | */ |
| 168 | static int xhci_start(struct xhci_hcor *hcor) |
| 169 | { |
| 170 | u32 temp; |
| 171 | int ret; |
| 172 | |
| 173 | puts("Starting the controller\n"); |
| 174 | temp = xhci_readl(&hcor->or_usbcmd); |
| 175 | temp |= (CMD_RUN); |
| 176 | xhci_writel(&hcor->or_usbcmd, temp); |
| 177 | |
| 178 | /* |
| 179 | * Wait for the HCHalted Status bit to be 0 to indicate the host is |
| 180 | * running. |
| 181 | */ |
| 182 | ret = handshake(&hcor->or_usbsts, STS_HALT, 0, XHCI_MAX_HALT_USEC); |
| 183 | if (ret) |
| 184 | debug("Host took too long to start, " |
| 185 | "waited %u microseconds.\n", |
| 186 | XHCI_MAX_HALT_USEC); |
| 187 | return ret; |
| 188 | } |
| 189 | |
Nicolas Saenz Julienne | 0b80371 | 2020-06-29 18:37:25 +0200 | [diff] [blame] | 190 | #if CONFIG_IS_ENABLED(DM_USB) |
| 191 | /** |
| 192 | * Resets XHCI Hardware |
| 193 | * |
| 194 | * @param ctrl pointer to host controller |
| 195 | * @return 0 if OK, or a negative error code. |
| 196 | */ |
| 197 | static int xhci_reset_hw(struct xhci_ctrl *ctrl) |
| 198 | { |
| 199 | int ret; |
| 200 | |
| 201 | ret = reset_get_by_index(ctrl->dev, 0, &ctrl->reset); |
| 202 | if (ret && ret != -ENOENT && ret != -ENOTSUPP) { |
| 203 | dev_err(ctrl->dev, "failed to get reset\n"); |
| 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | if (reset_valid(&ctrl->reset)) { |
| 208 | ret = reset_assert(&ctrl->reset); |
| 209 | if (ret) |
| 210 | return ret; |
| 211 | |
| 212 | ret = reset_deassert(&ctrl->reset); |
| 213 | if (ret) |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | #endif |
| 220 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 221 | /** |
| 222 | * Resets the XHCI Controller |
| 223 | * |
| 224 | * @param hcor pointer to host controller operation registers |
| 225 | * @return -EBUSY if XHCI Controller is not halted else status of handshake |
| 226 | */ |
Masahiro Yamada | 121a4d1 | 2017-06-22 16:35:14 +0900 | [diff] [blame] | 227 | static int xhci_reset(struct xhci_hcor *hcor) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 228 | { |
| 229 | u32 cmd; |
| 230 | u32 state; |
| 231 | int ret; |
| 232 | |
| 233 | /* Halting the Host first */ |
Sergey Temerkhanov | a5ccda4 | 2015-08-17 15:38:07 +0300 | [diff] [blame] | 234 | debug("// Halt the HC: %p\n", hcor); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 235 | state = xhci_readl(&hcor->or_usbsts) & STS_HALT; |
| 236 | if (!state) { |
| 237 | cmd = xhci_readl(&hcor->or_usbcmd); |
| 238 | cmd &= ~CMD_RUN; |
| 239 | xhci_writel(&hcor->or_usbcmd, cmd); |
| 240 | } |
| 241 | |
| 242 | ret = handshake(&hcor->or_usbsts, |
| 243 | STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); |
| 244 | if (ret) { |
| 245 | printf("Host not halted after %u microseconds.\n", |
| 246 | XHCI_MAX_HALT_USEC); |
| 247 | return -EBUSY; |
| 248 | } |
| 249 | |
| 250 | debug("// Reset the HC\n"); |
| 251 | cmd = xhci_readl(&hcor->or_usbcmd); |
| 252 | cmd |= CMD_RESET; |
| 253 | xhci_writel(&hcor->or_usbcmd, cmd); |
| 254 | |
| 255 | ret = handshake(&hcor->or_usbcmd, CMD_RESET, 0, XHCI_MAX_RESET_USEC); |
| 256 | if (ret) |
| 257 | return ret; |
| 258 | |
| 259 | /* |
| 260 | * xHCI cannot write to any doorbells or operational registers other |
| 261 | * than status until the "Controller Not Ready" flag is cleared. |
| 262 | */ |
| 263 | return handshake(&hcor->or_usbsts, STS_CNR, 0, XHCI_MAX_RESET_USEC); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Used for passing endpoint bitmasks between the core and HCDs. |
| 268 | * Find the index for an endpoint given its descriptor. |
| 269 | * Use the return value to right shift 1 for the bitmask. |
| 270 | * |
| 271 | * Index = (epnum * 2) + direction - 1, |
| 272 | * where direction = 0 for OUT, 1 for IN. |
| 273 | * For control endpoints, the IN index is used (OUT index is unused), so |
| 274 | * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2) |
| 275 | * |
| 276 | * @param desc USB enpdoint Descriptor |
| 277 | * @return index of the Endpoint |
| 278 | */ |
| 279 | static unsigned int xhci_get_ep_index(struct usb_endpoint_descriptor *desc) |
| 280 | { |
| 281 | unsigned int index; |
| 282 | |
| 283 | if (usb_endpoint_xfer_control(desc)) |
| 284 | index = (unsigned int)(usb_endpoint_num(desc) * 2); |
| 285 | else |
| 286 | index = (unsigned int)((usb_endpoint_num(desc) * 2) - |
| 287 | (usb_endpoint_dir_in(desc) ? 0 : 1)); |
| 288 | |
| 289 | return index; |
| 290 | } |
| 291 | |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 292 | /* |
| 293 | * Convert bInterval expressed in microframes (in 1-255 range) to exponent of |
| 294 | * microframes, rounded down to nearest power of 2. |
| 295 | */ |
| 296 | static unsigned int xhci_microframes_to_exponent(unsigned int desc_interval, |
| 297 | unsigned int min_exponent, |
| 298 | unsigned int max_exponent) |
| 299 | { |
| 300 | unsigned int interval; |
| 301 | |
| 302 | interval = fls(desc_interval) - 1; |
| 303 | interval = clamp_val(interval, min_exponent, max_exponent); |
| 304 | if ((1 << interval) != desc_interval) |
| 305 | debug("rounding interval to %d microframes, "\ |
| 306 | "ep desc says %d microframes\n", |
| 307 | 1 << interval, desc_interval); |
| 308 | |
| 309 | return interval; |
| 310 | } |
| 311 | |
| 312 | static unsigned int xhci_parse_microframe_interval(struct usb_device *udev, |
| 313 | struct usb_endpoint_descriptor *endpt_desc) |
| 314 | { |
| 315 | if (endpt_desc->bInterval == 0) |
| 316 | return 0; |
| 317 | |
| 318 | return xhci_microframes_to_exponent(endpt_desc->bInterval, 0, 15); |
| 319 | } |
| 320 | |
| 321 | static unsigned int xhci_parse_frame_interval(struct usb_device *udev, |
| 322 | struct usb_endpoint_descriptor *endpt_desc) |
| 323 | { |
| 324 | return xhci_microframes_to_exponent(endpt_desc->bInterval * 8, 3, 10); |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * Convert interval expressed as 2^(bInterval - 1) == interval into |
| 329 | * straight exponent value 2^n == interval. |
| 330 | */ |
| 331 | static unsigned int xhci_parse_exponent_interval(struct usb_device *udev, |
| 332 | struct usb_endpoint_descriptor *endpt_desc) |
| 333 | { |
| 334 | unsigned int interval; |
| 335 | |
| 336 | interval = clamp_val(endpt_desc->bInterval, 1, 16) - 1; |
| 337 | if (interval != endpt_desc->bInterval - 1) |
| 338 | debug("ep %#x - rounding interval to %d %sframes\n", |
| 339 | endpt_desc->bEndpointAddress, 1 << interval, |
| 340 | udev->speed == USB_SPEED_FULL ? "" : "micro"); |
| 341 | |
| 342 | if (udev->speed == USB_SPEED_FULL) { |
| 343 | /* |
| 344 | * Full speed isoc endpoints specify interval in frames, |
| 345 | * not microframes. We are using microframes everywhere, |
| 346 | * so adjust accordingly. |
| 347 | */ |
| 348 | interval += 3; /* 1 frame = 2^3 uframes */ |
| 349 | } |
| 350 | |
| 351 | return interval; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Return the polling or NAK interval. |
| 356 | * |
| 357 | * The polling interval is expressed in "microframes". If xHCI's Interval field |
| 358 | * is set to N, it will service the endpoint every 2^(Interval)*125us. |
| 359 | * |
| 360 | * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval |
| 361 | * is set to 0. |
| 362 | */ |
| 363 | static unsigned int xhci_get_endpoint_interval(struct usb_device *udev, |
| 364 | struct usb_endpoint_descriptor *endpt_desc) |
| 365 | { |
| 366 | unsigned int interval = 0; |
| 367 | |
| 368 | switch (udev->speed) { |
| 369 | case USB_SPEED_HIGH: |
| 370 | /* Max NAK rate */ |
| 371 | if (usb_endpoint_xfer_control(endpt_desc) || |
| 372 | usb_endpoint_xfer_bulk(endpt_desc)) { |
| 373 | interval = xhci_parse_microframe_interval(udev, |
| 374 | endpt_desc); |
| 375 | break; |
| 376 | } |
| 377 | /* Fall through - SS and HS isoc/int have same decoding */ |
| 378 | |
| 379 | case USB_SPEED_SUPER: |
| 380 | if (usb_endpoint_xfer_int(endpt_desc) || |
| 381 | usb_endpoint_xfer_isoc(endpt_desc)) { |
| 382 | interval = xhci_parse_exponent_interval(udev, |
| 383 | endpt_desc); |
| 384 | } |
| 385 | break; |
| 386 | |
| 387 | case USB_SPEED_FULL: |
| 388 | if (usb_endpoint_xfer_isoc(endpt_desc)) { |
| 389 | interval = xhci_parse_exponent_interval(udev, |
| 390 | endpt_desc); |
| 391 | break; |
| 392 | } |
| 393 | /* |
| 394 | * Fall through for interrupt endpoint interval decoding |
| 395 | * since it uses the same rules as low speed interrupt |
| 396 | * endpoints. |
| 397 | */ |
| 398 | |
| 399 | case USB_SPEED_LOW: |
| 400 | if (usb_endpoint_xfer_int(endpt_desc) || |
| 401 | usb_endpoint_xfer_isoc(endpt_desc)) { |
| 402 | interval = xhci_parse_frame_interval(udev, endpt_desc); |
| 403 | } |
| 404 | break; |
| 405 | |
| 406 | default: |
| 407 | BUG(); |
| 408 | } |
| 409 | |
| 410 | return interval; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps. |
| 415 | * High speed endpoint descriptors can define "the number of additional |
| 416 | * transaction opportunities per microframe", but that goes in the Max Burst |
| 417 | * endpoint context field. |
| 418 | */ |
| 419 | static u32 xhci_get_endpoint_mult(struct usb_device *udev, |
| 420 | struct usb_endpoint_descriptor *endpt_desc, |
| 421 | struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc) |
| 422 | { |
| 423 | if (udev->speed < USB_SPEED_SUPER || |
| 424 | !usb_endpoint_xfer_isoc(endpt_desc)) |
| 425 | return 0; |
| 426 | |
| 427 | return ss_ep_comp_desc->bmAttributes; |
| 428 | } |
| 429 | |
Bin Meng | fa483b2 | 2017-09-18 06:40:48 -0700 | [diff] [blame] | 430 | static u32 xhci_get_endpoint_max_burst(struct usb_device *udev, |
| 431 | struct usb_endpoint_descriptor *endpt_desc, |
| 432 | struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc) |
| 433 | { |
| 434 | /* Super speed and Plus have max burst in ep companion desc */ |
| 435 | if (udev->speed >= USB_SPEED_SUPER) |
| 436 | return ss_ep_comp_desc->bMaxBurst; |
| 437 | |
| 438 | if (udev->speed == USB_SPEED_HIGH && |
| 439 | (usb_endpoint_xfer_isoc(endpt_desc) || |
| 440 | usb_endpoint_xfer_int(endpt_desc))) |
| 441 | return usb_endpoint_maxp_mult(endpt_desc) - 1; |
| 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 446 | /* |
| 447 | * Return the maximum endpoint service interval time (ESIT) payload. |
| 448 | * Basically, this is the maxpacket size, multiplied by the burst size |
| 449 | * and mult size. |
| 450 | */ |
| 451 | static u32 xhci_get_max_esit_payload(struct usb_device *udev, |
| 452 | struct usb_endpoint_descriptor *endpt_desc, |
| 453 | struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc) |
| 454 | { |
| 455 | int max_burst; |
| 456 | int max_packet; |
| 457 | |
| 458 | /* Only applies for interrupt or isochronous endpoints */ |
| 459 | if (usb_endpoint_xfer_control(endpt_desc) || |
| 460 | usb_endpoint_xfer_bulk(endpt_desc)) |
| 461 | return 0; |
| 462 | |
| 463 | /* SuperSpeed Isoc ep with less than 48k per esit */ |
| 464 | if (udev->speed >= USB_SPEED_SUPER) |
| 465 | return le16_to_cpu(ss_ep_comp_desc->wBytesPerInterval); |
| 466 | |
| 467 | max_packet = usb_endpoint_maxp(endpt_desc); |
| 468 | max_burst = usb_endpoint_maxp_mult(endpt_desc); |
| 469 | |
| 470 | /* A 0 in max burst means 1 transfer per ESIT */ |
| 471 | return max_packet * max_burst; |
| 472 | } |
| 473 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 474 | /** |
| 475 | * Issue a configure endpoint command or evaluate context command |
| 476 | * and wait for it to finish. |
| 477 | * |
| 478 | * @param udev pointer to the Device Data Structure |
| 479 | * @param ctx_change flag to indicate the Context has changed or NOT |
| 480 | * @return 0 on success, -1 on failure |
| 481 | */ |
| 482 | static int xhci_configure_endpoints(struct usb_device *udev, bool ctx_change) |
| 483 | { |
| 484 | struct xhci_container_ctx *in_ctx; |
| 485 | struct xhci_virt_device *virt_dev; |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 486 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 487 | union xhci_trb *event; |
| 488 | |
| 489 | virt_dev = ctrl->devs[udev->slot_id]; |
| 490 | in_ctx = virt_dev->in_ctx; |
| 491 | |
Sergey Temerkhanov | 421a5a0 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 492 | xhci_flush_cache((uintptr_t)in_ctx->bytes, in_ctx->size); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 493 | xhci_queue_command(ctrl, in_ctx->bytes, udev->slot_id, 0, |
| 494 | ctx_change ? TRB_EVAL_CONTEXT : TRB_CONFIG_EP); |
| 495 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
| 496 | BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) |
| 497 | != udev->slot_id); |
| 498 | |
| 499 | switch (GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))) { |
| 500 | case COMP_SUCCESS: |
| 501 | debug("Successful %s command\n", |
| 502 | ctx_change ? "Evaluate Context" : "Configure Endpoint"); |
| 503 | break; |
| 504 | default: |
| 505 | printf("ERROR: %s command returned completion code %d.\n", |
| 506 | ctx_change ? "Evaluate Context" : "Configure Endpoint", |
| 507 | GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))); |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | |
| 511 | xhci_acknowledge_event(ctrl); |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Configure the endpoint, programming the device contexts. |
| 518 | * |
| 519 | * @param udev pointer to the USB device structure |
| 520 | * @return returns the status of the xhci_configure_endpoints |
| 521 | */ |
| 522 | static int xhci_set_configuration(struct usb_device *udev) |
| 523 | { |
| 524 | struct xhci_container_ctx *in_ctx; |
| 525 | struct xhci_container_ctx *out_ctx; |
| 526 | struct xhci_input_control_ctx *ctrl_ctx; |
| 527 | struct xhci_slot_ctx *slot_ctx; |
| 528 | struct xhci_ep_ctx *ep_ctx[MAX_EP_CTX_NUM]; |
| 529 | int cur_ep; |
| 530 | int max_ep_flag = 0; |
| 531 | int ep_index; |
| 532 | unsigned int dir; |
| 533 | unsigned int ep_type; |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 534 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 535 | int num_of_ep; |
| 536 | int ep_flag = 0; |
| 537 | u64 trb_64 = 0; |
| 538 | int slot_id = udev->slot_id; |
| 539 | struct xhci_virt_device *virt_dev = ctrl->devs[slot_id]; |
| 540 | struct usb_interface *ifdesc; |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 541 | u32 max_esit_payload; |
| 542 | unsigned int interval; |
| 543 | unsigned int mult; |
Bin Meng | fa483b2 | 2017-09-18 06:40:48 -0700 | [diff] [blame] | 544 | unsigned int max_burst; |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 545 | unsigned int avg_trb_len; |
Bin Meng | ab2b727 | 2017-09-18 06:40:49 -0700 | [diff] [blame] | 546 | unsigned int err_count = 0; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 547 | |
| 548 | out_ctx = virt_dev->out_ctx; |
| 549 | in_ctx = virt_dev->in_ctx; |
| 550 | |
| 551 | num_of_ep = udev->config.if_desc[0].no_of_ep; |
| 552 | ifdesc = &udev->config.if_desc[0]; |
| 553 | |
| 554 | ctrl_ctx = xhci_get_input_control_ctx(in_ctx); |
Bin Meng | aab0db0 | 2017-07-19 21:49:56 +0800 | [diff] [blame] | 555 | /* Initialize the input context control */ |
| 556 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 557 | ctrl_ctx->drop_flags = 0; |
| 558 | |
| 559 | /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */ |
| 560 | for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) { |
| 561 | ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]); |
| 562 | ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1)); |
| 563 | if (max_ep_flag < ep_flag) |
| 564 | max_ep_flag = ep_flag; |
| 565 | } |
| 566 | |
Sergey Temerkhanov | 421a5a0 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 567 | xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 568 | |
| 569 | /* slot context */ |
| 570 | xhci_slot_copy(ctrl, in_ctx, out_ctx); |
| 571 | slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx); |
Bin Meng | e404066 | 2018-05-23 23:40:50 -0700 | [diff] [blame] | 572 | slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 573 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0); |
| 574 | |
| 575 | xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0); |
| 576 | |
| 577 | /* filling up ep contexts */ |
| 578 | for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) { |
| 579 | struct usb_endpoint_descriptor *endpt_desc = NULL; |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 580 | struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc = NULL; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 581 | |
| 582 | endpt_desc = &ifdesc->ep_desc[cur_ep]; |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 583 | ss_ep_comp_desc = &ifdesc->ss_ep_comp_desc[cur_ep]; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 584 | trb_64 = 0; |
| 585 | |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 586 | /* |
| 587 | * Get values to fill the endpoint context, mostly from ep |
| 588 | * descriptor. The average TRB buffer lengt for bulk endpoints |
| 589 | * is unclear as we have no clue on scatter gather list entry |
| 590 | * size. For Isoc and Int, set it to max available. |
| 591 | * See xHCI 1.1 spec 4.14.1.1 for details. |
| 592 | */ |
| 593 | max_esit_payload = xhci_get_max_esit_payload(udev, endpt_desc, |
| 594 | ss_ep_comp_desc); |
| 595 | interval = xhci_get_endpoint_interval(udev, endpt_desc); |
| 596 | mult = xhci_get_endpoint_mult(udev, endpt_desc, |
| 597 | ss_ep_comp_desc); |
Bin Meng | fa483b2 | 2017-09-18 06:40:48 -0700 | [diff] [blame] | 598 | max_burst = xhci_get_endpoint_max_burst(udev, endpt_desc, |
| 599 | ss_ep_comp_desc); |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 600 | avg_trb_len = max_esit_payload; |
| 601 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 602 | ep_index = xhci_get_ep_index(endpt_desc); |
| 603 | ep_ctx[ep_index] = xhci_get_ep_ctx(ctrl, in_ctx, ep_index); |
| 604 | |
| 605 | /* Allocate the ep rings */ |
| 606 | virt_dev->eps[ep_index].ring = xhci_ring_alloc(1, true); |
| 607 | if (!virt_dev->eps[ep_index].ring) |
| 608 | return -ENOMEM; |
| 609 | |
| 610 | /*NOTE: ep_desc[0] actually represents EP1 and so on */ |
| 611 | dir = (((endpt_desc->bEndpointAddress) & (0x80)) >> 7); |
| 612 | ep_type = (((endpt_desc->bmAttributes) & (0x3)) | (dir << 2)); |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 613 | |
| 614 | ep_ctx[ep_index]->ep_info = |
| 615 | cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | |
| 616 | EP_INTERVAL(interval) | EP_MULT(mult)); |
| 617 | |
Chunfeng Yun | 23a54cc | 2020-09-08 19:00:02 +0200 | [diff] [blame] | 618 | ep_ctx[ep_index]->ep_info2 = cpu_to_le32(EP_TYPE(ep_type)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 619 | ep_ctx[ep_index]->ep_info2 |= |
| 620 | cpu_to_le32(MAX_PACKET |
| 621 | (get_unaligned(&endpt_desc->wMaxPacketSize))); |
| 622 | |
Bin Meng | ab2b727 | 2017-09-18 06:40:49 -0700 | [diff] [blame] | 623 | /* Allow 3 retries for everything but isoc, set CErr = 3 */ |
| 624 | if (!usb_endpoint_xfer_isoc(endpt_desc)) |
| 625 | err_count = 3; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 626 | ep_ctx[ep_index]->ep_info2 |= |
Bin Meng | fa483b2 | 2017-09-18 06:40:48 -0700 | [diff] [blame] | 627 | cpu_to_le32(MAX_BURST(max_burst) | |
Bin Meng | ab2b727 | 2017-09-18 06:40:49 -0700 | [diff] [blame] | 628 | ERROR_COUNT(err_count)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 629 | |
Stefan Roese | b5152a6 | 2020-07-21 10:46:05 +0200 | [diff] [blame] | 630 | trb_64 = virt_to_phys(virt_dev->eps[ep_index].ring->enqueue); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 631 | ep_ctx[ep_index]->deq = cpu_to_le64(trb_64 | |
| 632 | virt_dev->eps[ep_index].ring->cycle_state); |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 633 | |
Bin Meng | fae3585 | 2017-09-18 06:40:50 -0700 | [diff] [blame] | 634 | /* |
| 635 | * xHCI spec 6.2.3: |
| 636 | * 'Average TRB Length' should be 8 for control endpoints. |
| 637 | */ |
| 638 | if (usb_endpoint_xfer_control(endpt_desc)) |
| 639 | avg_trb_len = 8; |
Bin Meng | f51966b | 2017-09-18 06:40:47 -0700 | [diff] [blame] | 640 | ep_ctx[ep_index]->tx_info = |
| 641 | cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | |
| 642 | EP_AVG_TRB_LENGTH(avg_trb_len)); |
Chunfeng Yun | 7410283 | 2020-05-02 11:35:18 +0200 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * The MediaTek xHCI defines some extra SW parameters which |
| 646 | * are put into reserved DWs in Slot and Endpoint Contexts |
| 647 | * for synchronous endpoints. |
| 648 | */ |
Chunfeng Yun | 7408205 | 2020-09-08 18:59:57 +0200 | [diff] [blame] | 649 | if (ctrl->quirks & XHCI_MTK_HOST) { |
Chunfeng Yun | 7410283 | 2020-05-02 11:35:18 +0200 | [diff] [blame] | 650 | ep_ctx[ep_index]->reserved[0] = |
| 651 | cpu_to_le32(EP_BPKTS(1) | EP_BBM(1)); |
| 652 | } |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | return xhci_configure_endpoints(udev, false); |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Issue an Address Device command (which will issue a SetAddress request to |
| 660 | * the device). |
| 661 | * |
| 662 | * @param udev pointer to the Device Data Structure |
| 663 | * @return 0 if successful else error code on failure |
| 664 | */ |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 665 | static int xhci_address_device(struct usb_device *udev, int root_portnr) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 666 | { |
| 667 | int ret = 0; |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 668 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 669 | struct xhci_slot_ctx *slot_ctx; |
| 670 | struct xhci_input_control_ctx *ctrl_ctx; |
| 671 | struct xhci_virt_device *virt_dev; |
| 672 | int slot_id = udev->slot_id; |
| 673 | union xhci_trb *event; |
| 674 | |
| 675 | virt_dev = ctrl->devs[slot_id]; |
| 676 | |
| 677 | /* |
| 678 | * This is the first Set Address since device plug-in |
| 679 | * so setting up the slot context. |
| 680 | */ |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 681 | debug("Setting up addressable devices %p\n", ctrl->dcbaa); |
Bin Meng | daec469 | 2017-07-19 21:51:14 +0800 | [diff] [blame] | 682 | xhci_setup_addressable_virt_dev(ctrl, udev, root_portnr); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 683 | |
| 684 | ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); |
| 685 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); |
| 686 | ctrl_ctx->drop_flags = 0; |
| 687 | |
| 688 | xhci_queue_command(ctrl, (void *)ctrl_ctx, slot_id, 0, TRB_ADDR_DEV); |
| 689 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
| 690 | BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) != slot_id); |
| 691 | |
| 692 | switch (GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))) { |
| 693 | case COMP_CTX_STATE: |
| 694 | case COMP_EBADSLT: |
| 695 | printf("Setup ERROR: address device command for slot %d.\n", |
| 696 | slot_id); |
| 697 | ret = -EINVAL; |
| 698 | break; |
| 699 | case COMP_TX_ERR: |
| 700 | puts("Device not responding to set address.\n"); |
| 701 | ret = -EPROTO; |
| 702 | break; |
| 703 | case COMP_DEV_ERR: |
| 704 | puts("ERROR: Incompatible device" |
| 705 | "for address device command.\n"); |
| 706 | ret = -ENODEV; |
| 707 | break; |
| 708 | case COMP_SUCCESS: |
| 709 | debug("Successful Address Device command\n"); |
| 710 | udev->status = 0; |
| 711 | break; |
| 712 | default: |
| 713 | printf("ERROR: unexpected command completion code 0x%x.\n", |
| 714 | GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))); |
| 715 | ret = -EINVAL; |
| 716 | break; |
| 717 | } |
| 718 | |
| 719 | xhci_acknowledge_event(ctrl); |
| 720 | |
| 721 | if (ret < 0) |
| 722 | /* |
| 723 | * TODO: Unsuccessful Address Device command shall leave the |
| 724 | * slot in default state. So, issue Disable Slot command now. |
| 725 | */ |
| 726 | return ret; |
| 727 | |
Sergey Temerkhanov | 421a5a0 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 728 | xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes, |
| 729 | virt_dev->out_ctx->size); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 730 | slot_ctx = xhci_get_slot_ctx(ctrl, virt_dev->out_ctx); |
| 731 | |
| 732 | debug("xHC internal address is: %d\n", |
| 733 | le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Issue Enable slot command to the controller to allocate |
| 740 | * device slot and assign the slot id. It fails if the xHC |
| 741 | * ran out of device slots, the Enable Slot command timed out, |
| 742 | * or allocating memory failed. |
| 743 | * |
| 744 | * @param udev pointer to the Device Data Structure |
| 745 | * @return Returns 0 on succes else return error code on failure |
| 746 | */ |
Masahiro Yamada | 121a4d1 | 2017-06-22 16:35:14 +0900 | [diff] [blame] | 747 | static int _xhci_alloc_device(struct usb_device *udev) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 748 | { |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 749 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 750 | union xhci_trb *event; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 751 | int ret; |
| 752 | |
| 753 | /* |
| 754 | * Root hub will be first device to be initailized. |
| 755 | * If this device is root-hub, don't do any xHC related |
| 756 | * stuff. |
| 757 | */ |
| 758 | if (ctrl->rootdev == 0) { |
| 759 | udev->speed = USB_SPEED_SUPER; |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | xhci_queue_command(ctrl, NULL, 0, 0, TRB_ENABLE_SLOT); |
| 764 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
| 765 | BUG_ON(GET_COMP_CODE(le32_to_cpu(event->event_cmd.status)) |
| 766 | != COMP_SUCCESS); |
| 767 | |
| 768 | udev->slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)); |
| 769 | |
| 770 | xhci_acknowledge_event(ctrl); |
| 771 | |
Simon Glass | 7e0c5ee | 2015-03-25 12:22:50 -0600 | [diff] [blame] | 772 | ret = xhci_alloc_virt_device(ctrl, udev->slot_id); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 773 | if (ret < 0) { |
| 774 | /* |
| 775 | * TODO: Unsuccessful Address Device command shall leave |
| 776 | * the slot in default. So, issue Disable Slot command now. |
| 777 | */ |
| 778 | puts("Could not allocate xHCI USB device data structures\n"); |
| 779 | return ret; |
| 780 | } |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 785 | #if !CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 786 | int usb_alloc_device(struct usb_device *udev) |
| 787 | { |
| 788 | return _xhci_alloc_device(udev); |
| 789 | } |
| 790 | #endif |
| 791 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 792 | /* |
| 793 | * Full speed devices may have a max packet size greater than 8 bytes, but the |
| 794 | * USB core doesn't know that until it reads the first 8 bytes of the |
| 795 | * descriptor. If the usb_device's max packet size changes after that point, |
| 796 | * we need to issue an evaluate context command and wait on it. |
| 797 | * |
| 798 | * @param udev pointer to the Device Data Structure |
| 799 | * @return returns the status of the xhci_configure_endpoints |
| 800 | */ |
| 801 | int xhci_check_maxpacket(struct usb_device *udev) |
| 802 | { |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 803 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 804 | unsigned int slot_id = udev->slot_id; |
| 805 | int ep_index = 0; /* control endpoint */ |
| 806 | struct xhci_container_ctx *in_ctx; |
| 807 | struct xhci_container_ctx *out_ctx; |
| 808 | struct xhci_input_control_ctx *ctrl_ctx; |
| 809 | struct xhci_ep_ctx *ep_ctx; |
| 810 | int max_packet_size; |
| 811 | int hw_max_packet_size; |
| 812 | int ret = 0; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 813 | |
| 814 | out_ctx = ctrl->devs[slot_id]->out_ctx; |
Sergey Temerkhanov | 421a5a0 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 815 | xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 816 | |
| 817 | ep_ctx = xhci_get_ep_ctx(ctrl, out_ctx, ep_index); |
| 818 | hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); |
Bin Meng | b5aa857 | 2017-09-18 06:40:44 -0700 | [diff] [blame] | 819 | max_packet_size = udev->epmaxpacketin[0]; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 820 | if (hw_max_packet_size != max_packet_size) { |
| 821 | debug("Max Packet Size for ep 0 changed.\n"); |
| 822 | debug("Max packet size in usb_device = %d\n", max_packet_size); |
| 823 | debug("Max packet size in xHCI HW = %d\n", hw_max_packet_size); |
| 824 | debug("Issuing evaluate context command.\n"); |
| 825 | |
| 826 | /* Set up the modified control endpoint 0 */ |
| 827 | xhci_endpoint_copy(ctrl, ctrl->devs[slot_id]->in_ctx, |
| 828 | ctrl->devs[slot_id]->out_ctx, ep_index); |
| 829 | in_ctx = ctrl->devs[slot_id]->in_ctx; |
| 830 | ep_ctx = xhci_get_ep_ctx(ctrl, in_ctx, ep_index); |
Chunfeng Yun | 23a54cc | 2020-09-08 19:00:02 +0200 | [diff] [blame] | 831 | ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET(MAX_PACKET_MASK)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 832 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); |
| 833 | |
| 834 | /* |
| 835 | * Set up the input context flags for the command |
| 836 | * FIXME: This won't work if a non-default control endpoint |
| 837 | * changes max packet sizes. |
| 838 | */ |
| 839 | ctrl_ctx = xhci_get_input_control_ctx(in_ctx); |
| 840 | ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); |
| 841 | ctrl_ctx->drop_flags = 0; |
| 842 | |
| 843 | ret = xhci_configure_endpoints(udev, true); |
| 844 | } |
| 845 | return ret; |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Clears the Change bits of the Port Status Register |
| 850 | * |
| 851 | * @param wValue request value |
| 852 | * @param wIndex request index |
| 853 | * @param addr address of posrt status register |
| 854 | * @param port_status state of port status register |
| 855 | * @return none |
| 856 | */ |
| 857 | static void xhci_clear_port_change_bit(u16 wValue, |
| 858 | u16 wIndex, volatile uint32_t *addr, u32 port_status) |
| 859 | { |
| 860 | char *port_change_bit; |
| 861 | u32 status; |
| 862 | |
| 863 | switch (wValue) { |
| 864 | case USB_PORT_FEAT_C_RESET: |
| 865 | status = PORT_RC; |
| 866 | port_change_bit = "reset"; |
| 867 | break; |
| 868 | case USB_PORT_FEAT_C_CONNECTION: |
| 869 | status = PORT_CSC; |
| 870 | port_change_bit = "connect"; |
| 871 | break; |
| 872 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 873 | status = PORT_OCC; |
| 874 | port_change_bit = "over-current"; |
| 875 | break; |
| 876 | case USB_PORT_FEAT_C_ENABLE: |
| 877 | status = PORT_PEC; |
| 878 | port_change_bit = "enable/disable"; |
| 879 | break; |
| 880 | case USB_PORT_FEAT_C_SUSPEND: |
| 881 | status = PORT_PLC; |
| 882 | port_change_bit = "suspend/resume"; |
| 883 | break; |
| 884 | default: |
| 885 | /* Should never happen */ |
| 886 | return; |
| 887 | } |
| 888 | |
| 889 | /* Change bits are all write 1 to clear */ |
| 890 | xhci_writel(addr, port_status | status); |
| 891 | |
| 892 | port_status = xhci_readl(addr); |
| 893 | debug("clear port %s change, actual port %d status = 0x%x\n", |
| 894 | port_change_bit, wIndex, port_status); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Save Read Only (RO) bits and save read/write bits where |
| 899 | * writing a 0 clears the bit and writing a 1 sets the bit (RWS). |
| 900 | * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect. |
| 901 | * |
| 902 | * @param state state of the Port Status and Control Regsiter |
| 903 | * @return a value that would result in the port being in the |
| 904 | * same state, if the value was written to the port |
| 905 | * status control register. |
| 906 | */ |
| 907 | static u32 xhci_port_state_to_neutral(u32 state) |
| 908 | { |
| 909 | /* Save read-only status and port state */ |
| 910 | return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS); |
| 911 | } |
| 912 | |
| 913 | /** |
| 914 | * Submits the Requests to the XHCI Host Controller |
| 915 | * |
| 916 | * @param udev pointer to the USB device structure |
| 917 | * @param pipe contains the DIR_IN or OUT , devnum |
| 918 | * @param buffer buffer to be read/written based on the request |
| 919 | * @return returns 0 if successful else -1 on failure |
| 920 | */ |
| 921 | static int xhci_submit_root(struct usb_device *udev, unsigned long pipe, |
| 922 | void *buffer, struct devrequest *req) |
| 923 | { |
| 924 | uint8_t tmpbuf[4]; |
| 925 | u16 typeReq; |
| 926 | void *srcptr = NULL; |
| 927 | int len, srclen; |
| 928 | uint32_t reg; |
| 929 | volatile uint32_t *status_reg; |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 930 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Bin Meng | 7274671 | 2017-07-19 21:50:03 +0800 | [diff] [blame] | 931 | struct xhci_hccr *hccr = ctrl->hccr; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 932 | struct xhci_hcor *hcor = ctrl->hcor; |
Bin Meng | 7274671 | 2017-07-19 21:50:03 +0800 | [diff] [blame] | 933 | int max_ports = HCS_MAX_PORTS(xhci_readl(&hccr->cr_hcsparams1)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 934 | |
Jeroen Hofstee | 25d1936 | 2014-06-12 00:31:27 +0200 | [diff] [blame] | 935 | if ((req->requesttype & USB_RT_PORT) && |
Bin Meng | 7274671 | 2017-07-19 21:50:03 +0800 | [diff] [blame] | 936 | le16_to_cpu(req->index) > max_ports) { |
| 937 | printf("The request port(%d) exceeds maximum port number\n", |
| 938 | le16_to_cpu(req->index) - 1); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 939 | return -EINVAL; |
| 940 | } |
| 941 | |
| 942 | status_reg = (volatile uint32_t *) |
| 943 | (&hcor->portregs[le16_to_cpu(req->index) - 1].or_portsc); |
| 944 | srclen = 0; |
| 945 | |
| 946 | typeReq = req->request | req->requesttype << 8; |
| 947 | |
| 948 | switch (typeReq) { |
| 949 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
| 950 | switch (le16_to_cpu(req->value) >> 8) { |
| 951 | case USB_DT_DEVICE: |
| 952 | debug("USB_DT_DEVICE request\n"); |
| 953 | srcptr = &descriptor.device; |
| 954 | srclen = 0x12; |
| 955 | break; |
| 956 | case USB_DT_CONFIG: |
| 957 | debug("USB_DT_CONFIG config\n"); |
| 958 | srcptr = &descriptor.config; |
| 959 | srclen = 0x19; |
| 960 | break; |
| 961 | case USB_DT_STRING: |
| 962 | debug("USB_DT_STRING config\n"); |
| 963 | switch (le16_to_cpu(req->value) & 0xff) { |
| 964 | case 0: /* Language */ |
| 965 | srcptr = "\4\3\11\4"; |
| 966 | srclen = 4; |
| 967 | break; |
| 968 | case 1: /* Vendor String */ |
Simon Glass | f161c17 | 2015-03-25 12:22:54 -0600 | [diff] [blame] | 969 | srcptr = "\16\3U\0-\0B\0o\0o\0t\0"; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 970 | srclen = 14; |
| 971 | break; |
| 972 | case 2: /* Product Name */ |
| 973 | srcptr = "\52\3X\0H\0C\0I\0 " |
| 974 | "\0H\0o\0s\0t\0 " |
| 975 | "\0C\0o\0n\0t\0r\0o\0l\0l\0e\0r\0"; |
| 976 | srclen = 42; |
| 977 | break; |
| 978 | default: |
| 979 | printf("unknown value DT_STRING %x\n", |
| 980 | le16_to_cpu(req->value)); |
| 981 | goto unknown; |
| 982 | } |
| 983 | break; |
| 984 | default: |
| 985 | printf("unknown value %x\n", le16_to_cpu(req->value)); |
| 986 | goto unknown; |
| 987 | } |
| 988 | break; |
| 989 | case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8): |
| 990 | switch (le16_to_cpu(req->value) >> 8) { |
| 991 | case USB_DT_HUB: |
Bin Meng | f342119 | 2017-07-19 21:49:58 +0800 | [diff] [blame] | 992 | case USB_DT_SS_HUB: |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 993 | debug("USB_DT_HUB config\n"); |
| 994 | srcptr = &descriptor.hub; |
| 995 | srclen = 0x8; |
| 996 | break; |
| 997 | default: |
| 998 | printf("unknown value %x\n", le16_to_cpu(req->value)); |
| 999 | goto unknown; |
| 1000 | } |
| 1001 | break; |
| 1002 | case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8): |
| 1003 | debug("USB_REQ_SET_ADDRESS\n"); |
| 1004 | ctrl->rootdev = le16_to_cpu(req->value); |
| 1005 | break; |
| 1006 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: |
| 1007 | /* Do nothing */ |
| 1008 | break; |
| 1009 | case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8): |
| 1010 | tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */ |
| 1011 | tmpbuf[1] = 0; |
| 1012 | srcptr = tmpbuf; |
| 1013 | srclen = 2; |
| 1014 | break; |
| 1015 | case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8): |
| 1016 | memset(tmpbuf, 0, 4); |
| 1017 | reg = xhci_readl(status_reg); |
| 1018 | if (reg & PORT_CONNECT) { |
| 1019 | tmpbuf[0] |= USB_PORT_STAT_CONNECTION; |
| 1020 | switch (reg & DEV_SPEED_MASK) { |
| 1021 | case XDEV_FS: |
| 1022 | debug("SPEED = FULLSPEED\n"); |
| 1023 | break; |
| 1024 | case XDEV_LS: |
| 1025 | debug("SPEED = LOWSPEED\n"); |
| 1026 | tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8; |
| 1027 | break; |
| 1028 | case XDEV_HS: |
| 1029 | debug("SPEED = HIGHSPEED\n"); |
| 1030 | tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; |
| 1031 | break; |
| 1032 | case XDEV_SS: |
| 1033 | debug("SPEED = SUPERSPEED\n"); |
| 1034 | tmpbuf[1] |= USB_PORT_STAT_SUPER_SPEED >> 8; |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
| 1038 | if (reg & PORT_PE) |
| 1039 | tmpbuf[0] |= USB_PORT_STAT_ENABLE; |
| 1040 | if ((reg & PORT_PLS_MASK) == XDEV_U3) |
| 1041 | tmpbuf[0] |= USB_PORT_STAT_SUSPEND; |
| 1042 | if (reg & PORT_OC) |
| 1043 | tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT; |
| 1044 | if (reg & PORT_RESET) |
| 1045 | tmpbuf[0] |= USB_PORT_STAT_RESET; |
| 1046 | if (reg & PORT_POWER) |
| 1047 | /* |
| 1048 | * XXX: This Port power bit (for USB 3.0 hub) |
| 1049 | * we are faking in USB 2.0 hub port status; |
| 1050 | * since there's a change in bit positions in |
| 1051 | * two: |
| 1052 | * USB 2.0 port status PP is at position[8] |
| 1053 | * USB 3.0 port status PP is at position[9] |
| 1054 | * So, we are still keeping it at position [8] |
| 1055 | */ |
| 1056 | tmpbuf[1] |= USB_PORT_STAT_POWER >> 8; |
| 1057 | if (reg & PORT_CSC) |
| 1058 | tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION; |
| 1059 | if (reg & PORT_PEC) |
| 1060 | tmpbuf[2] |= USB_PORT_STAT_C_ENABLE; |
| 1061 | if (reg & PORT_OCC) |
| 1062 | tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT; |
| 1063 | if (reg & PORT_RC) |
| 1064 | tmpbuf[2] |= USB_PORT_STAT_C_RESET; |
| 1065 | |
| 1066 | srcptr = tmpbuf; |
| 1067 | srclen = 4; |
| 1068 | break; |
| 1069 | case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
| 1070 | reg = xhci_readl(status_reg); |
| 1071 | reg = xhci_port_state_to_neutral(reg); |
| 1072 | switch (le16_to_cpu(req->value)) { |
| 1073 | case USB_PORT_FEAT_ENABLE: |
| 1074 | reg |= PORT_PE; |
| 1075 | xhci_writel(status_reg, reg); |
| 1076 | break; |
| 1077 | case USB_PORT_FEAT_POWER: |
| 1078 | reg |= PORT_POWER; |
| 1079 | xhci_writel(status_reg, reg); |
| 1080 | break; |
| 1081 | case USB_PORT_FEAT_RESET: |
| 1082 | reg |= PORT_RESET; |
| 1083 | xhci_writel(status_reg, reg); |
| 1084 | break; |
| 1085 | default: |
| 1086 | printf("unknown feature %x\n", le16_to_cpu(req->value)); |
| 1087 | goto unknown; |
| 1088 | } |
| 1089 | break; |
| 1090 | case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
| 1091 | reg = xhci_readl(status_reg); |
| 1092 | reg = xhci_port_state_to_neutral(reg); |
| 1093 | switch (le16_to_cpu(req->value)) { |
| 1094 | case USB_PORT_FEAT_ENABLE: |
| 1095 | reg &= ~PORT_PE; |
| 1096 | break; |
| 1097 | case USB_PORT_FEAT_POWER: |
| 1098 | reg &= ~PORT_POWER; |
| 1099 | break; |
| 1100 | case USB_PORT_FEAT_C_RESET: |
| 1101 | case USB_PORT_FEAT_C_CONNECTION: |
| 1102 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 1103 | case USB_PORT_FEAT_C_ENABLE: |
| 1104 | xhci_clear_port_change_bit((le16_to_cpu(req->value)), |
| 1105 | le16_to_cpu(req->index), |
| 1106 | status_reg, reg); |
| 1107 | break; |
| 1108 | default: |
| 1109 | printf("unknown feature %x\n", le16_to_cpu(req->value)); |
| 1110 | goto unknown; |
| 1111 | } |
| 1112 | xhci_writel(status_reg, reg); |
| 1113 | break; |
| 1114 | default: |
| 1115 | puts("Unknown request\n"); |
| 1116 | goto unknown; |
| 1117 | } |
| 1118 | |
| 1119 | debug("scrlen = %d\n req->length = %d\n", |
| 1120 | srclen, le16_to_cpu(req->length)); |
| 1121 | |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1122 | len = min(srclen, (int)le16_to_cpu(req->length)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1123 | |
| 1124 | if (srcptr != NULL && len > 0) |
| 1125 | memcpy(buffer, srcptr, len); |
| 1126 | else |
| 1127 | debug("Len is 0\n"); |
| 1128 | |
| 1129 | udev->act_len = len; |
| 1130 | udev->status = 0; |
| 1131 | |
| 1132 | return 0; |
| 1133 | |
| 1134 | unknown: |
| 1135 | udev->act_len = 0; |
| 1136 | udev->status = USB_ST_STALLED; |
| 1137 | |
| 1138 | return -ENODEV; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * Submits the INT request to XHCI Host cotroller |
| 1143 | * |
| 1144 | * @param udev pointer to the USB device |
| 1145 | * @param pipe contains the DIR_IN or OUT , devnum |
| 1146 | * @param buffer buffer to be read/written based on the request |
| 1147 | * @param length length of the buffer |
| 1148 | * @param interval interval of the interrupt |
| 1149 | * @return 0 |
| 1150 | */ |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1151 | static int _xhci_submit_int_msg(struct usb_device *udev, unsigned long pipe, |
Michal Suchanek | 3437121 | 2019-08-18 10:55:27 +0200 | [diff] [blame] | 1152 | void *buffer, int length, int interval, |
| 1153 | bool nonblock) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1154 | { |
Bin Meng | 1897d60 | 2017-09-18 06:40:41 -0700 | [diff] [blame] | 1155 | if (usb_pipetype(pipe) != PIPE_INTERRUPT) { |
| 1156 | printf("non-interrupt pipe (type=%lu)", usb_pipetype(pipe)); |
| 1157 | return -EINVAL; |
| 1158 | } |
| 1159 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1160 | /* |
Bin Meng | 1897d60 | 2017-09-18 06:40:41 -0700 | [diff] [blame] | 1161 | * xHCI uses normal TRBs for both bulk and interrupt. When the |
| 1162 | * interrupt endpoint is to be serviced, the xHC will consume |
| 1163 | * (at most) one TD. A TD (comprised of sg list entries) can |
| 1164 | * take several service intervals to transmit. |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1165 | */ |
Bin Meng | 1897d60 | 2017-09-18 06:40:41 -0700 | [diff] [blame] | 1166 | return xhci_bulk_tx(udev, pipe, length, buffer); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * submit the BULK type of request to the USB Device |
| 1171 | * |
| 1172 | * @param udev pointer to the USB device |
| 1173 | * @param pipe contains the DIR_IN or OUT , devnum |
| 1174 | * @param buffer buffer to be read/written based on the request |
| 1175 | * @param length length of the buffer |
| 1176 | * @return returns 0 if successful else -1 on failure |
| 1177 | */ |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1178 | static int _xhci_submit_bulk_msg(struct usb_device *udev, unsigned long pipe, |
| 1179 | void *buffer, int length) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1180 | { |
| 1181 | if (usb_pipetype(pipe) != PIPE_BULK) { |
| 1182 | printf("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); |
| 1183 | return -EINVAL; |
| 1184 | } |
| 1185 | |
| 1186 | return xhci_bulk_tx(udev, pipe, length, buffer); |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * submit the control type of request to the Root hub/Device based on the devnum |
| 1191 | * |
| 1192 | * @param udev pointer to the USB device |
| 1193 | * @param pipe contains the DIR_IN or OUT , devnum |
| 1194 | * @param buffer buffer to be read/written based on the request |
| 1195 | * @param length length of the buffer |
| 1196 | * @param setup Request type |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 1197 | * @param root_portnr Root port number that this device is on |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1198 | * @return returns 0 if successful else -1 on failure |
| 1199 | */ |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 1200 | static int _xhci_submit_control_msg(struct usb_device *udev, unsigned long pipe, |
| 1201 | void *buffer, int length, |
| 1202 | struct devrequest *setup, int root_portnr) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1203 | { |
Simon Glass | 7c1deec | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 1204 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1205 | int ret = 0; |
| 1206 | |
| 1207 | if (usb_pipetype(pipe) != PIPE_CONTROL) { |
| 1208 | printf("non-control pipe (type=%lu)", usb_pipetype(pipe)); |
| 1209 | return -EINVAL; |
| 1210 | } |
| 1211 | |
| 1212 | if (usb_pipedevice(pipe) == ctrl->rootdev) |
| 1213 | return xhci_submit_root(udev, pipe, buffer, setup); |
| 1214 | |
Ted Chen | 1b10888 | 2016-03-18 17:56:52 +1030 | [diff] [blame] | 1215 | if (setup->request == USB_REQ_SET_ADDRESS && |
| 1216 | (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD) |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 1217 | return xhci_address_device(udev, root_portnr); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1218 | |
Ted Chen | 1b10888 | 2016-03-18 17:56:52 +1030 | [diff] [blame] | 1219 | if (setup->request == USB_REQ_SET_CONFIGURATION && |
| 1220 | (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1221 | ret = xhci_set_configuration(udev); |
| 1222 | if (ret) { |
| 1223 | puts("Failed to configure xHCI endpoint\n"); |
| 1224 | return ret; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | return xhci_ctrl_tx(udev, pipe, setup, length, buffer); |
| 1229 | } |
| 1230 | |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1231 | static int xhci_lowlevel_init(struct xhci_ctrl *ctrl) |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1232 | { |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1233 | struct xhci_hccr *hccr; |
| 1234 | struct xhci_hcor *hcor; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1235 | uint32_t val; |
| 1236 | uint32_t val2; |
| 1237 | uint32_t reg; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1238 | |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1239 | hccr = ctrl->hccr; |
| 1240 | hcor = ctrl->hcor; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1241 | /* |
| 1242 | * Program the Number of Device Slots Enabled field in the CONFIG |
| 1243 | * register with the max value of slots the HC can handle. |
| 1244 | */ |
| 1245 | val = (xhci_readl(&hccr->cr_hcsparams1) & HCS_SLOTS_MASK); |
| 1246 | val2 = xhci_readl(&hcor->or_config); |
| 1247 | val |= (val2 & ~HCS_SLOTS_MASK); |
| 1248 | xhci_writel(&hcor->or_config, val); |
| 1249 | |
| 1250 | /* initializing xhci data structures */ |
| 1251 | if (xhci_mem_init(ctrl, hccr, hcor) < 0) |
| 1252 | return -ENOMEM; |
| 1253 | |
| 1254 | reg = xhci_readl(&hccr->cr_hcsparams1); |
Chunfeng Yun | 86d1fa1 | 2020-09-08 18:59:58 +0200 | [diff] [blame] | 1255 | descriptor.hub.bNbrPorts = HCS_MAX_PORTS(reg); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1256 | printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts); |
| 1257 | |
| 1258 | /* Port Indicators */ |
| 1259 | reg = xhci_readl(&hccr->cr_hccparams); |
| 1260 | if (HCS_INDICATOR(reg)) |
| 1261 | put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) |
| 1262 | | 0x80, &descriptor.hub.wHubCharacteristics); |
| 1263 | |
| 1264 | /* Port Power Control */ |
| 1265 | if (HCC_PPC(reg)) |
| 1266 | put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) |
| 1267 | | 0x01, &descriptor.hub.wHubCharacteristics); |
| 1268 | |
| 1269 | if (xhci_start(hcor)) { |
| 1270 | xhci_reset(hcor); |
| 1271 | return -ENODEV; |
| 1272 | } |
| 1273 | |
| 1274 | /* Zero'ing IRQ control register and IRQ pending register */ |
| 1275 | xhci_writel(&ctrl->ir_set->irq_control, 0x0); |
| 1276 | xhci_writel(&ctrl->ir_set->irq_pending, 0x0); |
| 1277 | |
| 1278 | reg = HC_VERSION(xhci_readl(&hccr->cr_capbase)); |
| 1279 | printf("USB XHCI %x.%02x\n", reg >> 8, reg & 0xff); |
Chunfeng Yun | 719d7d8 | 2020-09-08 18:59:55 +0200 | [diff] [blame] | 1280 | ctrl->hci_version = reg; |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1281 | |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static int xhci_lowlevel_stop(struct xhci_ctrl *ctrl) |
| 1286 | { |
| 1287 | u32 temp; |
| 1288 | |
| 1289 | xhci_reset(ctrl->hcor); |
| 1290 | |
| 1291 | debug("// Disabling event ring interrupts\n"); |
| 1292 | temp = xhci_readl(&ctrl->hcor->or_usbsts); |
| 1293 | xhci_writel(&ctrl->hcor->or_usbsts, temp & ~STS_EINT); |
| 1294 | temp = xhci_readl(&ctrl->ir_set->irq_pending); |
| 1295 | xhci_writel(&ctrl->ir_set->irq_pending, ER_IRQ_DISABLE(temp)); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1296 | |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 1300 | #if !CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | 5dd75e3 | 2015-03-25 12:22:51 -0600 | [diff] [blame] | 1301 | int submit_control_msg(struct usb_device *udev, unsigned long pipe, |
| 1302 | void *buffer, int length, struct devrequest *setup) |
| 1303 | { |
| 1304 | struct usb_device *hop = udev; |
| 1305 | |
| 1306 | if (hop->parent) |
| 1307 | while (hop->parent->parent) |
| 1308 | hop = hop->parent; |
| 1309 | |
| 1310 | return _xhci_submit_control_msg(udev, pipe, buffer, length, setup, |
| 1311 | hop->portnr); |
| 1312 | } |
| 1313 | |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1314 | int submit_bulk_msg(struct usb_device *udev, unsigned long pipe, void *buffer, |
| 1315 | int length) |
| 1316 | { |
| 1317 | return _xhci_submit_bulk_msg(udev, pipe, buffer, length); |
| 1318 | } |
| 1319 | |
| 1320 | int submit_int_msg(struct usb_device *udev, unsigned long pipe, void *buffer, |
Michal Suchanek | 3437121 | 2019-08-18 10:55:27 +0200 | [diff] [blame] | 1321 | int length, int interval, bool nonblock) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1322 | { |
Michal Suchanek | 3437121 | 2019-08-18 10:55:27 +0200 | [diff] [blame] | 1323 | return _xhci_submit_int_msg(udev, pipe, buffer, length, interval, |
| 1324 | nonblock); |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1325 | } |
| 1326 | |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1327 | /** |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1328 | * Intialises the XHCI host controller |
| 1329 | * and allocates the necessary data structures |
| 1330 | * |
| 1331 | * @param index index to the host controller data structure |
| 1332 | * @return pointer to the intialised controller |
| 1333 | */ |
| 1334 | int usb_lowlevel_init(int index, enum usb_init_type init, void **controller) |
| 1335 | { |
| 1336 | struct xhci_hccr *hccr; |
| 1337 | struct xhci_hcor *hcor; |
| 1338 | struct xhci_ctrl *ctrl; |
| 1339 | int ret; |
| 1340 | |
Sergey Temerkhanov | a5ccda4 | 2015-08-17 15:38:07 +0300 | [diff] [blame] | 1341 | *controller = NULL; |
| 1342 | |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1343 | if (xhci_hcd_init(index, &hccr, (struct xhci_hcor **)&hcor) != 0) |
| 1344 | return -ENODEV; |
| 1345 | |
| 1346 | if (xhci_reset(hcor) != 0) |
| 1347 | return -ENODEV; |
| 1348 | |
| 1349 | ctrl = &xhcic[index]; |
| 1350 | |
| 1351 | ctrl->hccr = hccr; |
| 1352 | ctrl->hcor = hcor; |
| 1353 | |
| 1354 | ret = xhci_lowlevel_init(ctrl); |
| 1355 | |
Sergey Temerkhanov | a5ccda4 | 2015-08-17 15:38:07 +0300 | [diff] [blame] | 1356 | if (ret) { |
| 1357 | ctrl->hccr = NULL; |
| 1358 | ctrl->hcor = NULL; |
| 1359 | } else { |
| 1360 | *controller = &xhcic[index]; |
| 1361 | } |
Simon Glass | 779d126 | 2015-03-25 12:22:52 -0600 | [diff] [blame] | 1362 | |
| 1363 | return ret; |
| 1364 | } |
| 1365 | |
| 1366 | /** |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1367 | * Stops the XHCI host controller |
| 1368 | * and cleans up all the related data structures |
| 1369 | * |
| 1370 | * @param index index to the host controller data structure |
| 1371 | * @return none |
| 1372 | */ |
| 1373 | int usb_lowlevel_stop(int index) |
| 1374 | { |
| 1375 | struct xhci_ctrl *ctrl = (xhcic + index); |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1376 | |
Sergey Temerkhanov | a5ccda4 | 2015-08-17 15:38:07 +0300 | [diff] [blame] | 1377 | if (ctrl->hcor) { |
| 1378 | xhci_lowlevel_stop(ctrl); |
| 1379 | xhci_hcd_stop(index); |
| 1380 | xhci_cleanup(ctrl); |
| 1381 | } |
Vivek Gautam | 5853e13 | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1382 | |
| 1383 | return 0; |
| 1384 | } |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 1385 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1386 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 1387 | #if CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1388 | |
| 1389 | static int xhci_submit_control_msg(struct udevice *dev, struct usb_device *udev, |
| 1390 | unsigned long pipe, void *buffer, int length, |
| 1391 | struct devrequest *setup) |
| 1392 | { |
| 1393 | struct usb_device *uhop; |
| 1394 | struct udevice *hub; |
| 1395 | int root_portnr = 0; |
| 1396 | |
| 1397 | debug("%s: dev='%s', udev=%p, udev->dev='%s', portnr=%d\n", __func__, |
| 1398 | dev->name, udev, udev->dev->name, udev->portnr); |
| 1399 | hub = udev->dev; |
| 1400 | if (device_get_uclass_id(hub) == UCLASS_USB_HUB) { |
| 1401 | /* Figure out our port number on the root hub */ |
Bin Meng | 46c1d49 | 2017-07-19 21:51:11 +0800 | [diff] [blame] | 1402 | if (usb_hub_is_root_hub(hub)) { |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1403 | root_portnr = udev->portnr; |
| 1404 | } else { |
Bin Meng | 46c1d49 | 2017-07-19 21:51:11 +0800 | [diff] [blame] | 1405 | while (!usb_hub_is_root_hub(hub->parent)) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1406 | hub = hub->parent; |
Simon Glass | bcbe3d1 | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 1407 | uhop = dev_get_parent_priv(hub); |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1408 | root_portnr = uhop->portnr; |
| 1409 | } |
| 1410 | } |
| 1411 | /* |
| 1412 | struct usb_device *hop = udev; |
| 1413 | |
| 1414 | if (hop->parent) |
| 1415 | while (hop->parent->parent) |
| 1416 | hop = hop->parent; |
| 1417 | */ |
| 1418 | return _xhci_submit_control_msg(udev, pipe, buffer, length, setup, |
| 1419 | root_portnr); |
| 1420 | } |
| 1421 | |
| 1422 | static int xhci_submit_bulk_msg(struct udevice *dev, struct usb_device *udev, |
| 1423 | unsigned long pipe, void *buffer, int length) |
| 1424 | { |
| 1425 | debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); |
| 1426 | return _xhci_submit_bulk_msg(udev, pipe, buffer, length); |
| 1427 | } |
| 1428 | |
| 1429 | static int xhci_submit_int_msg(struct udevice *dev, struct usb_device *udev, |
| 1430 | unsigned long pipe, void *buffer, int length, |
Michal Suchanek | 3437121 | 2019-08-18 10:55:27 +0200 | [diff] [blame] | 1431 | int interval, bool nonblock) |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1432 | { |
| 1433 | debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); |
Michal Suchanek | 3437121 | 2019-08-18 10:55:27 +0200 | [diff] [blame] | 1434 | return _xhci_submit_int_msg(udev, pipe, buffer, length, interval, |
| 1435 | nonblock); |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | static int xhci_alloc_device(struct udevice *dev, struct usb_device *udev) |
| 1439 | { |
| 1440 | debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); |
| 1441 | return _xhci_alloc_device(udev); |
| 1442 | } |
| 1443 | |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1444 | static int xhci_update_hub_device(struct udevice *dev, struct usb_device *udev) |
| 1445 | { |
| 1446 | struct xhci_ctrl *ctrl = dev_get_priv(dev); |
| 1447 | struct usb_hub_device *hub = dev_get_uclass_priv(udev->dev); |
| 1448 | struct xhci_virt_device *virt_dev; |
| 1449 | struct xhci_input_control_ctx *ctrl_ctx; |
| 1450 | struct xhci_container_ctx *out_ctx; |
| 1451 | struct xhci_container_ctx *in_ctx; |
| 1452 | struct xhci_slot_ctx *slot_ctx; |
| 1453 | int slot_id = udev->slot_id; |
| 1454 | unsigned think_time; |
| 1455 | |
| 1456 | debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); |
| 1457 | |
| 1458 | /* Ignore root hubs */ |
| 1459 | if (usb_hub_is_root_hub(udev->dev)) |
| 1460 | return 0; |
| 1461 | |
| 1462 | virt_dev = ctrl->devs[slot_id]; |
| 1463 | BUG_ON(!virt_dev); |
| 1464 | |
| 1465 | out_ctx = virt_dev->out_ctx; |
| 1466 | in_ctx = virt_dev->in_ctx; |
| 1467 | |
| 1468 | ctrl_ctx = xhci_get_input_control_ctx(in_ctx); |
| 1469 | /* Initialize the input context control */ |
Bin Meng | 793c819 | 2018-05-23 23:40:47 -0700 | [diff] [blame] | 1470 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1471 | ctrl_ctx->drop_flags = 0; |
| 1472 | |
| 1473 | xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); |
| 1474 | |
| 1475 | /* slot context */ |
| 1476 | xhci_slot_copy(ctrl, in_ctx, out_ctx); |
| 1477 | slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx); |
| 1478 | |
| 1479 | /* Update hub related fields */ |
| 1480 | slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); |
Bin Meng | eaaefb0 | 2018-05-23 23:40:49 -0700 | [diff] [blame] | 1481 | /* |
| 1482 | * refer to section 6.2.2: MTT should be 0 for full speed hub, |
| 1483 | * but it may be already set to 1 when setup an xHCI virtual |
| 1484 | * device, so clear it anyway. |
| 1485 | */ |
| 1486 | if (hub->tt.multi) |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1487 | slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); |
Bin Meng | eaaefb0 | 2018-05-23 23:40:49 -0700 | [diff] [blame] | 1488 | else if (udev->speed == USB_SPEED_FULL) |
| 1489 | slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1490 | slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(udev->maxchild)); |
| 1491 | /* |
| 1492 | * Set TT think time - convert from ns to FS bit times. |
| 1493 | * Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns |
| 1494 | * |
| 1495 | * 0 = 8 FS bit times, 1 = 16 FS bit times, |
| 1496 | * 2 = 24 FS bit times, 3 = 32 FS bit times. |
| 1497 | * |
| 1498 | * This field shall be 0 if the device is not a high-spped hub. |
| 1499 | */ |
| 1500 | think_time = hub->tt.think_time; |
| 1501 | if (think_time != 0) |
| 1502 | think_time = (think_time / 666) - 1; |
| 1503 | if (udev->speed == USB_SPEED_HIGH) |
| 1504 | slot_ctx->tt_info |= cpu_to_le32(TT_THINK_TIME(think_time)); |
Bin Meng | ae751b0 | 2018-05-23 23:40:48 -0700 | [diff] [blame] | 1505 | slot_ctx->dev_state = 0; |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1506 | |
| 1507 | return xhci_configure_endpoints(udev, false); |
| 1508 | } |
| 1509 | |
Bin Meng | 022ceac | 2017-09-07 06:13:18 -0700 | [diff] [blame] | 1510 | static int xhci_get_max_xfer_size(struct udevice *dev, size_t *size) |
| 1511 | { |
| 1512 | /* |
| 1513 | * xHCD allocates one segment which includes 64 TRBs for each endpoint |
| 1514 | * and the last TRB in this segment is configured as a link TRB to form |
| 1515 | * a TRB ring. Each TRB can transfer up to 64K bytes, however data |
| 1516 | * buffers referenced by transfer TRBs shall not span 64KB boundaries. |
| 1517 | * Hence the maximum number of TRBs we can use in one transfer is 62. |
| 1518 | */ |
| 1519 | *size = (TRBS_PER_SEGMENT - 2) * TRB_MAX_BUFF_SIZE; |
| 1520 | |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1524 | int xhci_register(struct udevice *dev, struct xhci_hccr *hccr, |
| 1525 | struct xhci_hcor *hcor) |
| 1526 | { |
| 1527 | struct xhci_ctrl *ctrl = dev_get_priv(dev); |
| 1528 | struct usb_bus_priv *priv = dev_get_uclass_priv(dev); |
| 1529 | int ret; |
| 1530 | |
| 1531 | debug("%s: dev='%s', ctrl=%p, hccr=%p, hcor=%p\n", __func__, dev->name, |
| 1532 | ctrl, hccr, hcor); |
| 1533 | |
| 1534 | ctrl->dev = dev; |
| 1535 | |
Nicolas Saenz Julienne | 0b80371 | 2020-06-29 18:37:25 +0200 | [diff] [blame] | 1536 | ret = xhci_reset_hw(ctrl); |
| 1537 | if (ret) |
| 1538 | goto err; |
| 1539 | |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1540 | /* |
| 1541 | * XHCI needs to issue a Address device command to setup |
| 1542 | * proper device context structures, before it can interact |
| 1543 | * with the device. So a get_descriptor will fail before any |
| 1544 | * of that is done for XHCI unlike EHCI. |
| 1545 | */ |
| 1546 | priv->desc_before_addr = false; |
| 1547 | |
| 1548 | ret = xhci_reset(hcor); |
| 1549 | if (ret) |
| 1550 | goto err; |
| 1551 | |
| 1552 | ctrl->hccr = hccr; |
| 1553 | ctrl->hcor = hcor; |
| 1554 | ret = xhci_lowlevel_init(ctrl); |
| 1555 | if (ret) |
| 1556 | goto err; |
| 1557 | |
| 1558 | return 0; |
| 1559 | err: |
| 1560 | free(ctrl); |
| 1561 | debug("%s: failed, ret=%d\n", __func__, ret); |
| 1562 | return ret; |
| 1563 | } |
| 1564 | |
| 1565 | int xhci_deregister(struct udevice *dev) |
| 1566 | { |
| 1567 | struct xhci_ctrl *ctrl = dev_get_priv(dev); |
| 1568 | |
| 1569 | xhci_lowlevel_stop(ctrl); |
| 1570 | xhci_cleanup(ctrl); |
| 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | struct dm_usb_ops xhci_usb_ops = { |
| 1576 | .control = xhci_submit_control_msg, |
| 1577 | .bulk = xhci_submit_bulk_msg, |
| 1578 | .interrupt = xhci_submit_int_msg, |
| 1579 | .alloc_device = xhci_alloc_device, |
Bin Meng | d228ca3 | 2017-07-19 21:51:19 +0800 | [diff] [blame] | 1580 | .update_hub_device = xhci_update_hub_device, |
Bin Meng | 022ceac | 2017-09-07 06:13:18 -0700 | [diff] [blame] | 1581 | .get_max_xfer_size = xhci_get_max_xfer_size, |
Simon Glass | a5762fe | 2015-03-25 12:22:53 -0600 | [diff] [blame] | 1582 | }; |
| 1583 | |
| 1584 | #endif |