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