Lines Matching +full:dev +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0
2 /*-
3 * Copyright (c) 2007-2008, Juniper Networks, Inc.
50 2, /* bNrPorts -- runtime modified */
115 return dev_get_priv(usb_get_bus(udev->dev)); in ehci_get_ctrl()
117 return udev->controller; in ehci_get_ctrl()
121 static int ehci_get_port_speed(struct ehci_ctrl *ctrl, uint32_t reg) in ehci_get_port_speed() argument
126 static void ehci_set_usbmode(struct ehci_ctrl *ctrl) in ehci_set_usbmode() argument
131 reg_ptr = (uint32_t *)((u8 *)&ctrl->hcor->or_usbcmd + USBMODE); in ehci_set_usbmode()
142 static void ehci_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, in ehci_powerup_fixup() argument
148 static uint32_t *ehci_get_portsc_register(struct ehci_ctrl *ctrl, int port) in ehci_get_portsc_register() argument
150 int max_ports = HCS_N_PORTS(ehci_readl(&ctrl->hccr->cr_hcsparams)); in ehci_get_portsc_register()
159 return (uint32_t *)&ctrl->hcor->or_portsc[port]; in ehci_get_portsc_register()
169 return -1; in handshake()
173 usec--; in handshake()
175 return -1; in handshake()
178 static int ehci_reset(struct ehci_ctrl *ctrl) in ehci_reset() argument
183 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_reset()
185 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_reset()
186 ret = handshake((uint32_t *)&ctrl->hcor->or_usbcmd, in ehci_reset()
194 ctrl->ops.set_usb_mode(ctrl); in ehci_reset()
197 cmd = ehci_readl(&ctrl->hcor->or_txfilltuning); in ehci_reset()
200 ehci_writel(&ctrl->hcor->or_txfilltuning, cmd); in ehci_reset()
206 static int ehci_shutdown(struct ehci_ctrl *ctrl) in ehci_shutdown() argument
210 int max_ports = HCS_N_PORTS(ehci_readl(&ctrl->hccr->cr_hcsparams)); in ehci_shutdown()
212 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_shutdown()
217 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_shutdown()
218 ret = handshake(&ctrl->hcor->or_usbsts, STS_ASS | STS_PSS, 0, in ehci_shutdown()
223 reg = ehci_readl(&ctrl->hcor->or_portsc[i]); in ehci_shutdown()
225 ehci_writel(&ctrl->hcor->or_portsc[i], reg); in ehci_shutdown()
229 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_shutdown()
230 ret = handshake(&ctrl->hcor->or_usbsts, STS_HALT, STS_HALT, in ehci_shutdown()
247 debug("EHCI-HCD: Misaligned buffer address (%p)\n", buf); in ehci_td_buffer()
253 td->qt_buffer[idx] = cpu_to_hc32(virt_to_phys((void *)addr)); in ehci_td_buffer()
254 td->qt_buffer_hi[idx] = 0; in ehci_td_buffer()
255 next = (addr + EHCI_PAGE_SIZE) & ~(EHCI_PAGE_SIZE - 1); in ehci_td_buffer()
256 delta = next - addr; in ehci_td_buffer()
259 sz -= delta; in ehci_td_buffer()
266 return -1; in ehci_td_buffer()
290 if (udev->speed != USB_SPEED_LOW && udev->speed != USB_SPEED_FULL) in ehci_update_endpt2_dev_n_port()
295 qh->qh_endpt2 |= cpu_to_hc32(QH_ENDPT2_PORTNUM(portnr) | in ehci_update_endpt2_dev_n_port()
300 ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, in ehci_submit_async() argument
315 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev); in ehci_submit_async() local
317 debug("dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\n", dev, pipe, in ehci_submit_async()
321 req->request, req->request, in ehci_submit_async()
322 req->requesttype, req->requesttype, in ehci_submit_async()
323 le16_to_cpu(req->value), le16_to_cpu(req->value), in ehci_submit_async()
324 le16_to_cpu(req->index)); in ehci_submit_async()
338 * page (not considering the cache-line alignment issues), while the in ehci_submit_async()
339 * following buffers must be page-aligned. There is no alignment in ehci_submit_async()
364 * data buffer of each transfer will be page-unaligned. in ehci_submit_async()
366 if ((unsigned long)buffer & (PKT_ALIGN - 1)) in ehci_submit_async()
367 xfr_sz--; in ehci_submit_async()
379 * Threshold value based on the worst-case total size of the allocated qTDs for in ehci_submit_async()
380 * a mass-storage transfer of 65535 blocks of 512 bytes. in ehci_submit_async()
388 return -1; in ehci_submit_async()
394 toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); in ehci_submit_async()
397 * Setup QH (3.6 in ehci-r10.pdf) in ehci_submit_async()
399 * qh_link ................. 03-00 H in ehci_submit_async()
400 * qh_endpt1 ............... 07-04 H in ehci_submit_async()
401 * qh_endpt2 ............... 0B-08 H in ehci_submit_async()
402 * - qh_curtd in ehci_submit_async()
403 * qh_overlay.qt_next ...... 13-10 H in ehci_submit_async()
404 * - qh_overlay.qt_altnext in ehci_submit_async()
406 qh->qh_link = cpu_to_hc32(virt_to_phys(&ctrl->qh_list) | QH_LINK_TYPE_QH); in ehci_submit_async()
407 c = (dev->speed != USB_SPEED_HIGH) && !usb_pipeendpoint(pipe); in ehci_submit_async()
408 maxpacket = usb_maxpacket(dev, pipe); in ehci_submit_async()
416 if (!ctrl->has_fsl_erratum_a005275) in ehci_submit_async()
417 endpt |= QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)); in ehci_submit_async()
421 qh->qh_endpt1 = cpu_to_hc32(endpt); in ehci_submit_async()
423 qh->qh_endpt2 = cpu_to_hc32(endpt); in ehci_submit_async()
424 ehci_update_endpt2_dev_n_port(dev, qh); in ehci_submit_async()
425 qh->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_submit_async()
426 qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_submit_async()
428 tdp = &qh->qh_overlay.qt_next; in ehci_submit_async()
431 * Setup request qTD (3.5 in ehci-r10.pdf) in ehci_submit_async()
433 * qt_next ................ 03-00 H in ehci_submit_async()
434 * qt_altnext ............. 07-04 H in ehci_submit_async()
435 * qt_token ............... 0B-08 H in ehci_submit_async()
467 * However, if the input buffer is not page-aligned, the in ehci_submit_async()
471 xfr_bytes -= (unsigned long)buf_ptr & (EHCI_PAGE_SIZE - 1); in ehci_submit_async()
476 xfr_bytes &= ~(PKT_ALIGN - 1); in ehci_submit_async()
484 * Setup request qTD (3.5 in ehci-r10.pdf) in ehci_submit_async()
486 * qt_next ................ 03-00 H in ehci_submit_async()
487 * qt_altnext ............. 07-04 H in ehci_submit_async()
488 * qt_token ............... 0B-08 H in ehci_submit_async()
520 left_length -= xfr_bytes; in ehci_submit_async()
526 * Setup request qTD (3.5 in ehci-r10.pdf) in ehci_submit_async()
528 * qt_next ................ 03-00 H in ehci_submit_async()
529 * qt_altnext ............. 07-04 H in ehci_submit_async()
530 * qt_token ............... 0B-08 H in ehci_submit_async()
545 ctrl->qh_list.qh_link = cpu_to_hc32(virt_to_phys(qh) | QH_LINK_TYPE_QH); in ehci_submit_async()
548 flush_dcache_range((unsigned long)&ctrl->qh_list, in ehci_submit_async()
549 ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1)); in ehci_submit_async()
555 ehci_writel(&ctrl->hcor->or_asynclistaddr, virt_to_phys(&ctrl->qh_list)); in ehci_submit_async()
557 usbsts = ehci_readl(&ctrl->hcor->or_usbsts); in ehci_submit_async()
558 ehci_writel(&ctrl->hcor->or_usbsts, (usbsts & 0x3f)); in ehci_submit_async()
561 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_submit_async()
563 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_submit_async()
565 ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, STS_ASS, in ehci_submit_async()
574 vtd = &qtd[qtd_counter - 1]; in ehci_submit_async()
578 invalidate_dcache_range((unsigned long)&ctrl->qh_list, in ehci_submit_async()
579 ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1)); in ehci_submit_async()
585 token = hc32_to_cpu(vtd->qt_token); in ehci_submit_async()
606 printf("EHCI timed out on TD - token=%#x\n", token); in ehci_submit_async()
609 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_submit_async()
611 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_submit_async()
613 ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, 0, in ehci_submit_async()
620 token = hc32_to_cpu(qh->qh_overlay.qt_token); in ehci_submit_async()
627 usb_settoggle(dev, usb_pipeendpoint(pipe), in ehci_submit_async()
629 dev->status = 0; in ehci_submit_async()
632 dev->status = USB_ST_STALLED; in ehci_submit_async()
636 dev->status = USB_ST_BUF_ERR; in ehci_submit_async()
640 dev->status = USB_ST_BABBLE_DET; in ehci_submit_async()
643 dev->status = USB_ST_CRC_ERR; in ehci_submit_async()
645 dev->status |= USB_ST_STALLED; in ehci_submit_async()
648 dev->act_len = length - QT_TOKEN_GET_TOTALBYTES(token); in ehci_submit_async()
650 dev->act_len = 0; in ehci_submit_async()
652 debug("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\n", in ehci_submit_async()
653 dev->devnum, ehci_readl(&ctrl->hcor->or_usbsts), in ehci_submit_async()
654 ehci_readl(&ctrl->hcor->or_portsc[0]), in ehci_submit_async()
655 ehci_readl(&ctrl->hcor->or_portsc[1])); in ehci_submit_async()
660 return (dev->status != USB_ST_NOT_PROC) ? 0 : -1; in ehci_submit_async()
664 return -1; in ehci_submit_async()
667 static int ehci_submit_root(struct usb_device *dev, unsigned long pipe, in ehci_submit_root() argument
676 int port = le16_to_cpu(req->index) & 0xff; in ehci_submit_root()
677 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev); in ehci_submit_root() local
682 req->request, req->request, in ehci_submit_root()
683 req->requesttype, req->requesttype, in ehci_submit_root()
684 le16_to_cpu(req->value), le16_to_cpu(req->index)); in ehci_submit_root()
686 typeReq = req->request | req->requesttype << 8; in ehci_submit_root()
692 status_reg = ctrl->ops.get_portsc_register(ctrl, port - 1); in ehci_submit_root()
694 return -1; in ehci_submit_root()
703 switch (le16_to_cpu(req->value) >> 8) { in ehci_submit_root()
718 switch (le16_to_cpu(req->value) & 0xff) { in ehci_submit_root()
724 srcptr = "\16\3u\0-\0b\0o\0o\0t\0"; in ehci_submit_root()
735 le16_to_cpu(req->value)); in ehci_submit_root()
740 debug("unknown value %x\n", le16_to_cpu(req->value)); in ehci_submit_root()
745 switch (le16_to_cpu(req->value) >> 8) { in ehci_submit_root()
752 debug("unknown value %x\n", le16_to_cpu(req->value)); in ehci_submit_root()
758 ctrl->rootdev = le16_to_cpu(req->value); in ehci_submit_root()
787 switch (ctrl->ops.get_port_speed(ctrl, reg)) { in ehci_submit_root()
808 if (ctrl->portreset & (1 << port)) in ehci_submit_root()
817 switch (le16_to_cpu(req->value)) { in ehci_submit_root()
823 if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams))) { in ehci_submit_root()
833 debug("port %d low speed --> companion\n", in ehci_submit_root()
834 port - 1); in ehci_submit_root()
837 return -ENXIO; in ehci_submit_root()
842 if (ctrl->has_fsl_erratum_a005275) in ehci_submit_root()
853 ctrl->ops.powerup_fixup(ctrl, status_reg, ®); in ehci_submit_root()
867 debug("port %d full speed --> companion\n", port - 1); in ehci_submit_root()
871 return -ENXIO; in ehci_submit_root()
873 ctrl->portreset |= 1 << port; in ehci_submit_root()
877 port - 1); in ehci_submit_root()
882 ehci_shutdown(ctrl); in ehci_submit_root()
884 reg |= ((le16_to_cpu(req->index) >> 8) & 0xf) << 16; in ehci_submit_root()
888 debug("unknown feature %x\n", le16_to_cpu(req->value)); in ehci_submit_root()
892 (void) ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_submit_root()
897 switch (le16_to_cpu(req->value)) { in ehci_submit_root()
905 if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams))) in ehci_submit_root()
915 ctrl->portreset &= ~(1 << port); in ehci_submit_root()
918 debug("unknown feature %x\n", le16_to_cpu(req->value)); in ehci_submit_root()
923 (void) ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_submit_root()
931 len = min3(srclen, (int)le16_to_cpu(req->length), length); in ehci_submit_root()
937 dev->act_len = len; in ehci_submit_root()
938 dev->status = 0; in ehci_submit_root()
943 req->requesttype, req->request, le16_to_cpu(req->value), in ehci_submit_root()
944 le16_to_cpu(req->index), le16_to_cpu(req->length)); in ehci_submit_root()
946 dev->act_len = 0; in ehci_submit_root()
947 dev->status = USB_ST_STALLED; in ehci_submit_root()
948 return -1; in ehci_submit_root()
958 static void ehci_setup_ops(struct ehci_ctrl *ctrl, const struct ehci_ops *ops) in ehci_setup_ops() argument
961 ctrl->ops = default_ehci_ops; in ehci_setup_ops()
963 ctrl->ops = *ops; in ehci_setup_ops()
964 if (!ctrl->ops.set_usb_mode) in ehci_setup_ops()
965 ctrl->ops.set_usb_mode = ehci_set_usbmode; in ehci_setup_ops()
966 if (!ctrl->ops.get_port_speed) in ehci_setup_ops()
967 ctrl->ops.get_port_speed = ehci_get_port_speed; in ehci_setup_ops()
968 if (!ctrl->ops.powerup_fixup) in ehci_setup_ops()
969 ctrl->ops.powerup_fixup = ehci_powerup_fixup; in ehci_setup_ops()
970 if (!ctrl->ops.get_portsc_register) in ehci_setup_ops()
971 ctrl->ops.get_portsc_register = in ehci_setup_ops()
979 struct ehci_ctrl *ctrl = &ehcic[index]; in ehci_set_controller_priv() local
981 ctrl->priv = priv; in ehci_set_controller_priv()
982 ehci_setup_ops(ctrl, ops); in ehci_set_controller_priv()
991 static int ehci_common_init(struct ehci_ctrl *ctrl, uint tweaks) in ehci_common_init() argument
999 /* Set the high address word (aka segment) for 64-bit controller */ in ehci_common_init()
1000 if (ehci_readl(&ctrl->hccr->cr_hccparams) & 1) in ehci_common_init()
1001 ehci_writel(&ctrl->hcor->or_ctrldssegment, 0); in ehci_common_init()
1003 qh_list = &ctrl->qh_list; in ehci_common_init()
1007 qh_list->qh_link = cpu_to_hc32(virt_to_phys(qh_list) | QH_LINK_TYPE_QH); in ehci_common_init()
1008 qh_list->qh_endpt1 = cpu_to_hc32(QH_ENDPT1_H(1) | in ehci_common_init()
1010 qh_list->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_common_init()
1011 qh_list->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_common_init()
1012 qh_list->qh_overlay.qt_token = in ehci_common_init()
1019 ehci_writel(&ctrl->hcor->or_asynclistaddr, virt_to_phys(qh_list)); in ehci_common_init()
1025 ctrl->periodic_schedules = 0; in ehci_common_init()
1026 periodic = &ctrl->periodic_queue; in ehci_common_init()
1028 periodic->qh_link = cpu_to_hc32(QH_LINK_TERMINATE); in ehci_common_init()
1029 periodic->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_common_init()
1030 periodic->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); in ehci_common_init()
1036 * Step 2: Setup frame-list: Every microframe, USB tries the same list. in ehci_common_init()
1042 * S-mask and C-mask. in ehci_common_init()
1044 if (ctrl->periodic_list == NULL) in ehci_common_init()
1045 ctrl->periodic_list = memalign(4096, 1024 * 4); in ehci_common_init()
1047 if (!ctrl->periodic_list) in ehci_common_init()
1048 return -ENOMEM; in ehci_common_init()
1050 ctrl->periodic_list[i] = cpu_to_hc32((unsigned long)periodic in ehci_common_init()
1054 flush_dcache_range((unsigned long)ctrl->periodic_list, in ehci_common_init()
1055 ALIGN_END_ADDR(uint32_t, ctrl->periodic_list, in ehci_common_init()
1059 ehci_writel(&ctrl->hcor->or_periodiclistbase, in ehci_common_init()
1060 (unsigned long)ctrl->periodic_list); in ehci_common_init()
1062 reg = ehci_readl(&ctrl->hccr->cr_hcsparams); in ehci_common_init()
1075 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_common_init()
1082 ehci_writel(&ctrl->hcor->or_usbcmd, cmd); in ehci_common_init()
1086 cmd = ehci_readl(&ctrl->hcor->or_configflag); in ehci_common_init()
1088 ehci_writel(&ctrl->hcor->or_configflag, cmd); in ehci_common_init()
1092 cmd = ehci_readl(&ctrl->hcor->or_usbcmd); in ehci_common_init()
1094 reg = HC_VERSION(ehci_readl(&ctrl->hccr->cr_capbase)); in ehci_common_init()
1109 struct ehci_ctrl *ctrl = &ehcic[index]; in usb_lowlevel_init() local
1117 ctrl->ops = default_ehci_ops; in usb_lowlevel_init()
1119 rc = ehci_hcd_init(index, init, &ctrl->hccr, &ctrl->hcor); in usb_lowlevel_init()
1122 if (!ctrl->hccr || !ctrl->hcor) in usb_lowlevel_init()
1123 return -1; in usb_lowlevel_init()
1128 if (ehci_reset(ctrl)) in usb_lowlevel_init()
1129 return -1; in usb_lowlevel_init()
1132 rc = ehci_hcd_init(index, init, &ctrl->hccr, &ctrl->hcor); in usb_lowlevel_init()
1139 rc = ehci_common_init(ctrl, tweaks); in usb_lowlevel_init()
1143 ctrl->rootdev = 0; in usb_lowlevel_init()
1150 static int _ehci_submit_bulk_msg(struct usb_device *dev, unsigned long pipe, in _ehci_submit_bulk_msg() argument
1155 debug("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); in _ehci_submit_bulk_msg()
1156 return -1; in _ehci_submit_bulk_msg()
1158 return ehci_submit_async(dev, pipe, buffer, length, NULL); in _ehci_submit_bulk_msg()
1161 static int _ehci_submit_control_msg(struct usb_device *dev, unsigned long pipe, in _ehci_submit_control_msg() argument
1165 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev); in _ehci_submit_control_msg() local
1168 debug("non-control pipe (type=%lu)", usb_pipetype(pipe)); in _ehci_submit_control_msg()
1169 return -1; in _ehci_submit_control_msg()
1172 if (usb_pipedevice(pipe) == ctrl->rootdev) { in _ehci_submit_control_msg()
1173 if (!ctrl->rootdev) in _ehci_submit_control_msg()
1174 dev->speed = USB_SPEED_HIGH; in _ehci_submit_control_msg()
1175 return ehci_submit_root(dev, pipe, buffer, length, setup); in _ehci_submit_control_msg()
1177 return ehci_submit_async(dev, pipe, buffer, length, setup); in _ehci_submit_control_msg()
1189 #define NEXT_QH(qh) (struct QH *)((unsigned long)hc32_to_cpu((qh)->qh_link) & ~0x1f)
1192 enable_periodic(struct ehci_ctrl *ctrl) in enable_periodic() argument
1195 struct ehci_hcor *hcor = ctrl->hcor; in enable_periodic()
1198 cmd = ehci_readl(&hcor->or_usbcmd); in enable_periodic()
1200 ehci_writel(&hcor->or_usbcmd, cmd); in enable_periodic()
1202 ret = handshake((uint32_t *)&hcor->or_usbsts, in enable_periodic()
1206 return -ETIMEDOUT; in enable_periodic()
1213 disable_periodic(struct ehci_ctrl *ctrl) in disable_periodic() argument
1216 struct ehci_hcor *hcor = ctrl->hcor; in disable_periodic()
1219 cmd = ehci_readl(&hcor->or_usbcmd); in disable_periodic()
1221 ehci_writel(&hcor->or_usbcmd, cmd); in disable_periodic()
1223 ret = handshake((uint32_t *)&hcor->or_usbsts, in disable_periodic()
1227 return -ETIMEDOUT; in disable_periodic()
1232 static struct int_queue *_ehci_create_int_queue(struct usb_device *dev, in _ehci_create_int_queue() argument
1236 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev); in _ehci_create_int_queue() local
1251 if (elementsize > usb_maxpacket(dev, pipe)) { in _ehci_create_int_queue()
1259 debug("non-interrupt pipe (type=%lu)", usb_pipetype(pipe)); in _ehci_create_int_queue()
1263 /* limit to 4 full pages worth of data - in _ehci_create_int_queue()
1277 result->elementsize = elementsize; in _ehci_create_int_queue()
1278 result->pipe = pipe; in _ehci_create_int_queue()
1279 result->first = memalign(USB_DMA_MINALIGN, in _ehci_create_int_queue()
1281 if (!result->first) { in _ehci_create_int_queue()
1285 result->current = result->first; in _ehci_create_int_queue()
1286 result->last = result->first + queuesize - 1; in _ehci_create_int_queue()
1287 result->tds = memalign(USB_DMA_MINALIGN, in _ehci_create_int_queue()
1289 if (!result->tds) { in _ehci_create_int_queue()
1293 memset(result->first, 0, sizeof(struct QH) * queuesize); in _ehci_create_int_queue()
1294 memset(result->tds, 0, sizeof(struct qTD) * queuesize); in _ehci_create_int_queue()
1296 toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); in _ehci_create_int_queue()
1299 struct QH *qh = result->first + i; in _ehci_create_int_queue()
1300 struct qTD *td = result->tds + i; in _ehci_create_int_queue()
1301 void **buf = &qh->buffer; in _ehci_create_int_queue()
1303 qh->qh_link = cpu_to_hc32((unsigned long)(qh+1) | QH_LINK_TYPE_QH); in _ehci_create_int_queue()
1304 if (i == queuesize - 1) in _ehci_create_int_queue()
1305 qh->qh_link = cpu_to_hc32(QH_LINK_TERMINATE); in _ehci_create_int_queue()
1307 qh->qh_overlay.qt_next = cpu_to_hc32((unsigned long)td); in _ehci_create_int_queue()
1308 qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); in _ehci_create_int_queue()
1309 qh->qh_endpt1 = in _ehci_create_int_queue()
1311 (usb_maxpacket(dev, pipe) << 16) | /* MPS */ in _ehci_create_int_queue()
1313 QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) | in _ehci_create_int_queue()
1316 qh->qh_endpt2 = cpu_to_hc32((1 << 30) | /* 1 Tx per mframe */ in _ehci_create_int_queue()
1317 (1 << 0)); /* S-mask: microframe 0 */ in _ehci_create_int_queue()
1318 if (dev->speed == USB_SPEED_LOW || in _ehci_create_int_queue()
1319 dev->speed == USB_SPEED_FULL) { in _ehci_create_int_queue()
1320 /* C-mask: microframes 2-4 */ in _ehci_create_int_queue()
1321 qh->qh_endpt2 |= cpu_to_hc32((0x1c << 8)); in _ehci_create_int_queue()
1323 ehci_update_endpt2_dev_n_port(dev, qh); in _ehci_create_int_queue()
1325 td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); in _ehci_create_int_queue()
1326 td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); in _ehci_create_int_queue()
1329 td->qt_token = cpu_to_hc32( in _ehci_create_int_queue()
1334 td->qt_buffer[0] = in _ehci_create_int_queue()
1336 td->qt_buffer[1] = in _ehci_create_int_queue()
1337 cpu_to_hc32((td->qt_buffer[0] + 0x1000) & ~0xfff); in _ehci_create_int_queue()
1338 td->qt_buffer[2] = in _ehci_create_int_queue()
1339 cpu_to_hc32((td->qt_buffer[0] + 0x2000) & ~0xfff); in _ehci_create_int_queue()
1340 td->qt_buffer[3] = in _ehci_create_int_queue()
1341 cpu_to_hc32((td->qt_buffer[0] + 0x3000) & ~0xfff); in _ehci_create_int_queue()
1342 td->qt_buffer[4] = in _ehci_create_int_queue()
1343 cpu_to_hc32((td->qt_buffer[0] + 0x4000) & ~0xfff); in _ehci_create_int_queue()
1352 flush_dcache_range((unsigned long)result->first, in _ehci_create_int_queue()
1353 ALIGN_END_ADDR(struct QH, result->first, in _ehci_create_int_queue()
1355 flush_dcache_range((unsigned long)result->tds, in _ehci_create_int_queue()
1356 ALIGN_END_ADDR(struct qTD, result->tds, in _ehci_create_int_queue()
1359 if (ctrl->periodic_schedules > 0) { in _ehci_create_int_queue()
1360 if (disable_periodic(ctrl) < 0) { in _ehci_create_int_queue()
1367 struct QH *list = &ctrl->periodic_queue; in _ehci_create_int_queue()
1368 result->last->qh_link = list->qh_link; in _ehci_create_int_queue()
1369 list->qh_link = cpu_to_hc32((unsigned long)result->first | QH_LINK_TYPE_QH); in _ehci_create_int_queue()
1371 flush_dcache_range((unsigned long)result->last, in _ehci_create_int_queue()
1372 ALIGN_END_ADDR(struct QH, result->last, 1)); in _ehci_create_int_queue()
1376 if (enable_periodic(ctrl) < 0) { in _ehci_create_int_queue()
1380 ctrl->periodic_schedules++; in _ehci_create_int_queue()
1385 if (result->tds) in _ehci_create_int_queue()
1386 free(result->tds); in _ehci_create_int_queue()
1388 if (result->first) in _ehci_create_int_queue()
1389 free(result->first); in _ehci_create_int_queue()
1396 static void *_ehci_poll_int_queue(struct usb_device *dev, in _ehci_poll_int_queue() argument
1399 struct QH *cur = queue->current; in _ehci_poll_int_queue()
1402 unsigned long pipe = queue->pipe; in _ehci_poll_int_queue()
1410 cur_td = &queue->tds[queue->current - queue->first]; in _ehci_poll_int_queue()
1413 token = hc32_to_cpu(cur_td->qt_token); in _ehci_poll_int_queue()
1420 usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), toggle); in _ehci_poll_int_queue()
1422 if (!(cur->qh_link & QH_LINK_TERMINATE)) in _ehci_poll_int_queue()
1423 queue->current++; in _ehci_poll_int_queue()
1425 queue->current = NULL; in _ehci_poll_int_queue()
1427 invalidate_dcache_range((unsigned long)cur->buffer, in _ehci_poll_int_queue()
1428 ALIGN_END_ADDR(char, cur->buffer, in _ehci_poll_int_queue()
1429 queue->elementsize)); in _ehci_poll_int_queue()
1432 token, cur, queue->first); in _ehci_poll_int_queue()
1433 return cur->buffer; in _ehci_poll_int_queue()
1437 static int _ehci_destroy_int_queue(struct usb_device *dev, in _ehci_destroy_int_queue() argument
1440 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev); in _ehci_destroy_int_queue() local
1441 int result = -1; in _ehci_destroy_int_queue()
1444 if (disable_periodic(ctrl) < 0) { in _ehci_destroy_int_queue()
1448 ctrl->periodic_schedules--; in _ehci_destroy_int_queue()
1450 struct QH *cur = &ctrl->periodic_queue; in _ehci_destroy_int_queue()
1452 while (!(cur->qh_link & cpu_to_hc32(QH_LINK_TERMINATE))) { in _ehci_destroy_int_queue()
1453 debug("considering %p, with qh_link %x\n", cur, cur->qh_link); in _ehci_destroy_int_queue()
1454 if (NEXT_QH(cur) == queue->first) { in _ehci_destroy_int_queue()
1456 cur->qh_link = queue->last->qh_link; in _ehci_destroy_int_queue()
1465 result = -1; in _ehci_destroy_int_queue()
1470 if (ctrl->periodic_schedules > 0) { in _ehci_destroy_int_queue()
1471 result = enable_periodic(ctrl); in _ehci_destroy_int_queue()
1477 free(queue->tds); in _ehci_destroy_int_queue()
1478 free(queue->first); in _ehci_destroy_int_queue()
1484 static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe, in _ehci_submit_int_msg() argument
1492 debug("dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d", in _ehci_submit_int_msg()
1493 dev, pipe, buffer, length, interval); in _ehci_submit_int_msg()
1495 queue = _ehci_create_int_queue(dev, pipe, 1, length, buffer, interval); in _ehci_submit_int_msg()
1497 return -1; in _ehci_submit_int_msg()
1500 while ((backbuffer = _ehci_poll_int_queue(dev, queue)) == NULL) in _ehci_submit_int_msg()
1503 result = -ETIMEDOUT; in _ehci_submit_int_msg()
1510 return -EINVAL; in _ehci_submit_int_msg()
1513 ret = _ehci_destroy_int_queue(dev, queue); in _ehci_submit_int_msg()
1522 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, in submit_bulk_msg() argument
1525 return _ehci_submit_bulk_msg(dev, pipe, buffer, length); in submit_bulk_msg()
1528 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, in submit_control_msg() argument
1531 return _ehci_submit_control_msg(dev, pipe, buffer, length, setup); in submit_control_msg()
1534 int submit_int_msg(struct usb_device *dev, unsigned long pipe, in submit_int_msg() argument
1537 return _ehci_submit_int_msg(dev, pipe, buffer, length, interval); in submit_int_msg()
1540 struct int_queue *create_int_queue(struct usb_device *dev, in create_int_queue() argument
1544 return _ehci_create_int_queue(dev, pipe, queuesize, elementsize, in create_int_queue()
1548 void *poll_int_queue(struct usb_device *dev, struct int_queue *queue) in poll_int_queue() argument
1550 return _ehci_poll_int_queue(dev, queue); in poll_int_queue()
1553 int destroy_int_queue(struct usb_device *dev, struct int_queue *queue) in destroy_int_queue() argument
1555 return _ehci_destroy_int_queue(dev, queue); in destroy_int_queue()
1560 static int ehci_submit_control_msg(struct udevice *dev, struct usb_device *udev, in ehci_submit_control_msg() argument
1564 debug("%s: dev='%s', udev=%p, udev->dev='%s', portnr=%d\n", __func__, in ehci_submit_control_msg()
1565 dev->name, udev, udev->dev->name, udev->portnr); in ehci_submit_control_msg()
1570 static int ehci_submit_bulk_msg(struct udevice *dev, struct usb_device *udev, in ehci_submit_bulk_msg() argument
1573 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in ehci_submit_bulk_msg()
1577 static int ehci_submit_int_msg(struct udevice *dev, struct usb_device *udev, in ehci_submit_int_msg() argument
1581 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in ehci_submit_int_msg()
1585 static struct int_queue *ehci_create_int_queue(struct udevice *dev, in ehci_create_int_queue() argument
1589 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in ehci_create_int_queue()
1594 static void *ehci_poll_int_queue(struct udevice *dev, struct usb_device *udev, in ehci_poll_int_queue() argument
1597 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in ehci_poll_int_queue()
1601 static int ehci_destroy_int_queue(struct udevice *dev, struct usb_device *udev, in ehci_destroy_int_queue() argument
1604 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in ehci_destroy_int_queue()
1608 static int ehci_get_max_xfer_size(struct udevice *dev, size_t *size) in ehci_get_max_xfer_size() argument
1619 int ehci_register(struct udevice *dev, struct ehci_hccr *hccr, in ehci_register() argument
1623 struct usb_bus_priv *priv = dev_get_uclass_priv(dev); in ehci_register()
1624 struct ehci_ctrl *ctrl = dev_get_priv(dev); in ehci_register() local
1625 int ret = -1; in ehci_register()
1627 debug("%s: dev='%s', ctrl=%p, hccr=%p, hcor=%p, init=%d\n", __func__, in ehci_register()
1628 dev->name, ctrl, hccr, hcor, init); in ehci_register()
1630 if (!ctrl || !hccr || !hcor) in ehci_register()
1633 priv->desc_before_addr = true; in ehci_register()
1635 ehci_setup_ops(ctrl, ops); in ehci_register()
1636 ctrl->hccr = hccr; in ehci_register()
1637 ctrl->hcor = hcor; in ehci_register()
1638 ctrl->priv = ctrl; in ehci_register()
1640 ctrl->init = init; in ehci_register()
1641 if (ctrl->init == USB_INIT_DEVICE) in ehci_register()
1644 ret = ehci_reset(ctrl); in ehci_register()
1648 if (ctrl->ops.init_after_reset) { in ehci_register()
1649 ret = ctrl->ops.init_after_reset(ctrl); in ehci_register()
1654 ret = ehci_common_init(ctrl, tweaks); in ehci_register()
1660 free(ctrl); in ehci_register()
1665 int ehci_deregister(struct udevice *dev) in ehci_deregister() argument
1667 struct ehci_ctrl *ctrl = dev_get_priv(dev); in ehci_deregister() local
1669 if (ctrl->init == USB_INIT_DEVICE) in ehci_deregister()
1672 ehci_shutdown(ctrl); in ehci_deregister()
1690 int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index) in ehci_setup_phy() argument
1697 ret = generic_phy_get_by_index(dev, index, phy); in ehci_setup_phy()
1699 if (ret != -ENOENT) { in ehci_setup_phy()
1700 dev_err(dev, "failed to get usb phy\n"); in ehci_setup_phy()
1706 dev_err(dev, "failed to init usb phy\n"); in ehci_setup_phy()
1712 dev_err(dev, "failed to power on usb phy\n"); in ehci_setup_phy()
1720 int ehci_shutdown_phy(struct udevice *dev, struct phy *phy) in ehci_shutdown_phy() argument
1730 dev_err(dev, "failed to power off usb phy\n"); in ehci_shutdown_phy()
1736 dev_err(dev, "failed to power off usb phy\n"); in ehci_shutdown_phy()
1744 int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index) in ehci_setup_phy() argument
1749 int ehci_shutdown_phy(struct udevice *dev, struct phy *phy) in ehci_shutdown_phy() argument