Lines Matching +full:interrupt +full:- +full:endpoint
5 * SPDX-License-Identifier: Apache-2.0
56 /* FIXME: The actual MPS depends on endpoint type and bus speed. */
59 /* Number of SETUP back-to-back packets */
75 * USB endpoint private structure.
82 usb_dc_ep_callback cb;/* Endpoint callback function */
104 const struct pinctrl_dev_config *const pcfg = config->pcfg; in usb_dw_init_pinctrl()
189 "0x%x", base->gotgctl, base->gotgint, base->gahbcfg); in usb_dw_reg_dump()
191 base->gusbcfg, base->gintsts, base->gintmsk); in usb_dw_reg_dump()
193 base->dcfg, base->dctl, base->dsts); in usb_dw_reg_dump()
195 base->diepmsk, base->doepmsk, base->daint); in usb_dw_reg_dump()
197 base->daintmsk, base->ghwcfg1, base->ghwcfg2); in usb_dw_reg_dump()
199 base->ghwcfg3, base->ghwcfg4); in usb_dw_reg_dump()
203 "0x%x", i, base->in_ep[i].diepctl, in usb_dw_reg_dump()
204 base->in_ep[i].diepint); in usb_dw_reg_dump()
206 "0x%x", base->in_ep[i].dieptsiz, in usb_dw_reg_dump()
207 base->in_ep[i].diepdma, in usb_dw_reg_dump()
208 base->out_ep[i].doepctl); in usb_dw_reg_dump()
210 "0x%x", base->out_ep[i].doepint, in usb_dw_reg_dump()
211 base->out_ep[i].doeptsiz, in usb_dw_reg_dump()
212 base->out_ep[i].doepdma); in usb_dw_reg_dump()
257 while (!(base->grstctl & USB_DWC2_GRSTCTL_AHBIDLE)) { in usb_dw_reset()
262 base->grstctl); in usb_dw_reset()
263 return -EIO; in usb_dw_reset()
269 base->grstctl |= USB_DWC2_GRSTCTL_CSFTRST; in usb_dw_reset()
274 base->grstctl); in usb_dw_reset()
275 return -EIO; in usb_dw_reset()
278 } while (base->grstctl & USB_DWC2_GRSTCTL_CSFTRST); in usb_dw_reset()
290 return (base->ghwcfg2 >> 10) & 0xf; in usb_dw_num_dev_eps()
298 base->grstctl = (fnum << 6) | (1<<5); in usb_dw_flush_tx_fifo()
299 while (base->grstctl & (1<<5)) { in usb_dw_flush_tx_fifo()
307 return base->in_ep[ep].dtxfsts & USB_DWC2_DTXFSTS_INEPTXFSPCAVAIL_MASK; in usb_dw_tx_fifo_avail()
310 /* Choose a FIFO number for an IN endpoint */
315 volatile uint32_t *reg = &base->in_ep[ep_idx].diepctl; in usb_dw_set_fifo()
318 int ded_fifo = !!(base->ghwcfg4 & USB_DWC2_GHWCFG4_DEDFIFOMODE); in usb_dw_set_fifo()
321 /* No support for shared-FIFO mode yet, existing in usb_dw_set_fifo()
324 return -ENOTSUP; in usb_dw_set_fifo()
327 /* In dedicated-FIFO mode, all IN endpoints must have a unique in usb_dw_set_fifo()
335 * for the endpoint. This just picks the next available one. in usb_dw_set_fifo()
340 return -EINVAL; in usb_dw_set_fifo()
343 reg = &base->in_ep[ep_idx].diepctl; in usb_dw_set_fifo()
369 p_depctl = &base->out_ep[ep_idx].doepctl; in usb_dw_ep_set()
372 p_depctl = &base->in_ep[ep_idx].diepctl; in usb_dw_ep_set()
398 return -EINVAL; in usb_dw_ep_set()
405 return -EINVAL; in usb_dw_ep_set()
411 /* Set endpoint type */ in usb_dw_ep_set()
428 return -EINVAL; in usb_dw_ep_set()
431 /* sets the Endpoint Data PID to DATA0 */ in usb_dw_ep_set()
452 /* Set max RX size to EP mps so we get an interrupt in usb_dw_prep_rx()
456 base->out_ep[ep_idx].doeptsiz = in usb_dw_prep_rx()
462 base->out_ep[ep_idx].doepctl |= USB_DWC2_DEPCTL_CNAK; in usb_dw_prep_rx()
465 base->out_ep[ep_idx].doepctl |= USB_DWC2_DEPCTL_EPENA; in usb_dw_prep_rx()
495 base->in_ep[ep_idx].dtxfsts); in usb_dw_tx()
497 return -EAGAIN; in usb_dw_tx()
500 /* For now tx-fifo sizes are not configured (cf usb_dw_set_fifo). Here in usb_dw_tx()
504 avail_space -= avail_space % ep_mps; in usb_dw_tx()
529 LOG_WRN("USB IN EP%d len too big (%d->%d)", ep_idx, in usb_dw_tx()
543 LOG_WRN("USB IN EP%d pkt count too big (%d->%d)", in usb_dw_tx()
554 base->in_ep[ep_idx].dieptsiz = in usb_dw_tx()
558 base->in_ep[ep_idx].diepctl |= (USB_DWC2_DEPCTL_EPENA | in usb_dw_tx()
564 * USB 1.1/2.0 Device Subsystem-AHB/VCI Databook": "During FIFO in usb_dw_tx()
608 base->gusbcfg |= USB_DWC2_GUSBCFG_FORCEDEVMODE; in usb_dw_init()
612 /* set the PHY interface to be 16-bit UTMI */ in usb_dw_init()
613 base->gusbcfg = (base->gusbcfg & ~USB_DWC2_GUSBCFG_PHYIF_16_BIT) | in usb_dw_init()
617 base->dcfg |= USB_DWC2_DCFG_DEVSPD_USBHS20; in usb_dw_init()
620 base->dcfg |= USB_DWC2_DCFG_DEVSPD_USBFS1148; in usb_dw_init()
625 base->out_ep[ep].doepctl = USB_DWC2_DEPCTL_SNAK; in usb_dw_init()
629 base->gintmsk = USB_DWC2_GINTSTS_OEPINT | in usb_dw_init()
636 /* Enable global interrupt */ in usb_dw_init()
637 base->gahbcfg |= USB_DWC2_GAHBCFG_GLBINTRMASK; in usb_dw_init()
639 /* Call vendor-specific function to enable peripheral */ in usb_dw_init()
648 base->dctl &= ~USB_DWC2_DCTL_SFTDISCON; in usb_dw_init()
667 base->dcfg &= ~USB_DWC2_DCFG_DEVADDR_MASK; in usb_dw_handle_reset()
670 base->doepmsk = 0U; in usb_dw_handle_reset()
671 base->gintmsk |= USB_DWC2_GINTSTS_RXFLVL; in usb_dw_handle_reset()
672 base->diepmsk |= USB_DWC2_DIEPINT_XFERCOMPL; in usb_dw_handle_reset()
680 speed = (base->dsts & ~USB_DWC2_DSTS_ENUMSPD_MASK) >> in usb_dw_handle_enum_done()
696 uint32_t grxstsp = base->grxstsp; in usb_dw_int_rx_flvl_handler()
747 if (base->daint & USB_DWC2_DAINT_INEPINT(ep_idx)) { in usb_dw_int_iep_handler()
748 /* Read IN EP interrupt status */ in usb_dw_int_iep_handler()
749 ep_int_status = base->in_ep[ep_idx].diepint & in usb_dw_int_iep_handler()
750 base->diepmsk; in usb_dw_int_iep_handler()
753 base->in_ep[ep_idx].diepint = ep_int_status; in usb_dw_int_iep_handler()
755 LOG_DBG("USB IN EP%u interrupt status: 0x%x", in usb_dw_int_iep_handler()
769 /* Clear interrupt. */ in usb_dw_int_iep_handler()
770 base->gintsts = USB_DWC2_GINTSTS_IEPINT; in usb_dw_int_iep_handler()
780 if (base->daint & USB_DWC2_DAINT_OUTEPINT(ep_idx)) { in usb_dw_int_oep_handler()
781 /* Read OUT EP interrupt status */ in usb_dw_int_oep_handler()
782 ep_int_status = base->out_ep[ep_idx].doepint & in usb_dw_int_oep_handler()
783 base->doepmsk; in usb_dw_int_oep_handler()
786 base->out_ep[ep_idx].doepint = ep_int_status; in usb_dw_int_oep_handler()
788 LOG_DBG("USB OUT EP%u interrupt status: 0x%x\n", in usb_dw_int_oep_handler()
793 /* Clear interrupt. */ in usb_dw_int_oep_handler()
794 base->gintsts = USB_DWC2_GINTSTS_OEPINT; in usb_dw_int_oep_handler()
804 /* Read interrupt status */ in usb_dw_isr_handler()
805 while ((int_status = (base->gintsts & base->gintmsk))) { in usb_dw_isr_handler()
810 /* Clear interrupt. */ in usb_dw_isr_handler()
811 base->gintsts = USB_DWC2_GINTSTS_USBRST; in usb_dw_isr_handler()
818 /* Clear interrupt. */ in usb_dw_isr_handler()
819 base->gintsts = USB_DWC2_GINTSTS_ENUMDONE; in usb_dw_isr_handler()
826 /* Clear interrupt. */ in usb_dw_isr_handler()
827 base->gintsts = USB_DWC2_GINTSTS_USBSUSP; in usb_dw_isr_handler()
835 /* Clear interrupt. */ in usb_dw_isr_handler()
836 base->gintsts = USB_DWC2_GINTSTS_WKUPINT; in usb_dw_isr_handler()
849 /* IN EP interrupt */ in usb_dw_isr_handler()
854 /* No OUT interrupt expected in FIFO mode, in usb_dw_isr_handler()
855 * just clear interrupt in usb_dw_isr_handler()
887 /* Connect and enable USB interrupt */ in usb_dc_attach()
906 base->dctl |= USB_DWC2_DCTL_SFTDISCON; in usb_dc_detach()
930 return -EINVAL; in usb_dc_set_address()
933 base->dcfg &= ~USB_DWC2_DCFG_DEVADDR_MASK; in usb_dc_set_address()
934 base->dcfg |= addr << USB_DWC2_DCFG_DEVADDR_POS; in usb_dc_set_address()
941 uint8_t ep_idx = USB_EP_GET_IDX(cfg->ep_addr); in usb_dc_ep_check_cap()
943 LOG_DBG("ep %x, mps %d, type %d", cfg->ep_addr, cfg->ep_mps, in usb_dc_ep_check_cap()
944 cfg->ep_type); in usb_dc_ep_check_cap()
946 if ((cfg->ep_type == USB_DC_EP_CONTROL) && ep_idx) { in usb_dc_ep_check_cap()
947 LOG_ERR("invalid endpoint configuration"); in usb_dc_ep_check_cap()
948 return -1; in usb_dc_ep_check_cap()
951 if (cfg->ep_mps > DW_USB_MAX_PACKET_SIZE) { in usb_dc_ep_check_cap()
953 return -1; in usb_dc_ep_check_cap()
956 if (USB_EP_DIR_IS_OUT(cfg->ep_addr) && ep_idx >= USB_DW_OUT_EP_NUM) { in usb_dc_ep_check_cap()
957 LOG_WRN("OUT endpoint address out of range"); in usb_dc_ep_check_cap()
958 return -1; in usb_dc_ep_check_cap()
961 if (USB_EP_DIR_IS_IN(cfg->ep_addr) && ep_idx >= USB_DW_IN_EP_NUM) { in usb_dc_ep_check_cap()
962 LOG_WRN("IN endpoint address out of range"); in usb_dc_ep_check_cap()
963 return -1; in usb_dc_ep_check_cap()
974 return -EINVAL; in usb_dc_ep_configure()
977 ep = ep_cfg->ep_addr; in usb_dc_ep_configure()
980 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_configure()
981 return -EINVAL; in usb_dc_ep_configure()
984 usb_dw_ep_set(ep, ep_cfg->ep_mps, ep_cfg->ep_type); in usb_dc_ep_configure()
995 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_set_stall()
996 return -EINVAL; in usb_dc_ep_set_stall()
1000 base->out_ep[ep_idx].doepctl |= USB_DWC2_DEPCTL_STALL; in usb_dc_ep_set_stall()
1002 base->in_ep[ep_idx].diepctl |= USB_DWC2_DEPCTL_STALL; in usb_dc_ep_set_stall()
1014 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_clear_stall()
1015 return -EINVAL; in usb_dc_ep_clear_stall()
1020 return -EINVAL; in usb_dc_ep_clear_stall()
1024 base->out_ep[ep_idx].doepctl &= ~USB_DWC2_DEPCTL_STALL; in usb_dc_ep_clear_stall()
1026 base->in_ep[ep_idx].diepctl &= ~USB_DWC2_DEPCTL_STALL; in usb_dc_ep_clear_stall()
1039 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_halt()
1040 return -EINVAL; in usb_dc_ep_halt()
1048 p_depctl = &base->out_ep[ep_idx].doepctl; in usb_dc_ep_halt()
1050 p_depctl = &base->in_ep[ep_idx].diepctl; in usb_dc_ep_halt()
1053 /* Set STALL and disable endpoint if enabled */ in usb_dc_ep_halt()
1070 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_is_stalled()
1071 return -EINVAL; in usb_dc_ep_is_stalled()
1075 return -EINVAL; in usb_dc_ep_is_stalled()
1080 if (base->out_ep[ep_idx].doepctl & USB_DWC2_DEPCTL_STALL) { in usb_dc_ep_is_stalled()
1084 if (base->in_ep[ep_idx].diepctl & USB_DWC2_DEPCTL_STALL) { in usb_dc_ep_is_stalled()
1098 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_enable()
1099 return -EINVAL; in usb_dc_ep_enable()
1104 base->daintmsk |= USB_DWC2_DAINT_OUTEPINT(ep_idx); in usb_dc_ep_enable()
1106 base->daintmsk |= USB_DWC2_DAINT_INEPINT(ep_idx); in usb_dc_ep_enable()
1111 base->out_ep[ep_idx].doepctl |= USB_DWC2_DEPCTL_USBACTEP; in usb_dc_ep_enable()
1114 base->in_ep[ep_idx].diepctl |= USB_DWC2_DEPCTL_USBACTEP; in usb_dc_ep_enable()
1133 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_disable()
1134 return -EINVAL; in usb_dc_ep_disable()
1139 base->daintmsk &= ~USB_DWC2_DAINT_OUTEPINT(ep_idx); in usb_dc_ep_disable()
1140 base->doepmsk &= ~USB_DWC2_DOEPINT_SETUP; in usb_dc_ep_disable()
1142 base->daintmsk &= ~USB_DWC2_DAINT_INEPINT(ep_idx); in usb_dc_ep_disable()
1143 base->diepmsk &= ~USB_DWC2_DIEPINT_XFERCOMPL; in usb_dc_ep_disable()
1144 base->gintmsk &= ~USB_DWC2_GINTSTS_RXFLVL; in usb_dc_ep_disable()
1147 /* De-activate, disable and set NAK for Ep */ in usb_dc_ep_disable()
1149 base->out_ep[ep_idx].doepctl &= in usb_dc_ep_disable()
1155 base->in_ep[ep_idx].diepctl &= in usb_dc_ep_disable()
1172 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_flush()
1173 return -EINVAL; in usb_dc_ep_flush()
1178 return -EINVAL; in usb_dc_ep_flush()
1181 /* Each endpoint has dedicated Tx FIFO */ in usb_dc_ep_flush()
1182 base->grstctl |= ep_idx << USB_DWC2_GRSTCTL_TXFNUM_POS; in usb_dc_ep_flush()
1183 base->grstctl |= USB_DWC2_GRSTCTL_TXFFLSH; in usb_dc_ep_flush()
1190 return -EIO; in usb_dc_ep_flush()
1193 } while (base->grstctl & USB_DWC2_GRSTCTL_TXFFLSH); in usb_dc_ep_flush()
1204 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_write()
1205 return -EINVAL; in usb_dc_ep_write()
1210 return -EINVAL; in usb_dc_ep_write()
1215 return -EINVAL; in usb_dc_ep_write()
1238 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_read_wait()
1239 return -EINVAL; in usb_dc_ep_read_wait()
1244 LOG_ERR("Wrong endpoint direction"); in usb_dc_ep_read_wait()
1245 return -EINVAL; in usb_dc_ep_read_wait()
1251 return -EINVAL; in usb_dc_ep_read_wait()
1256 LOG_ERR("Not enabled endpoint"); in usb_dc_ep_read_wait()
1257 return -EINVAL; in usb_dc_ep_read_wait()
1283 /* Data in the FIFOs is always stored per 32-bit words */ in usb_dc_ep_read_wait()
1297 usb_dw_ctrl.out_ep_ctrl[ep_idx].data_len -= bytes_to_copy; in usb_dc_ep_read_wait()
1312 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_read_continue()
1313 return -EINVAL; in usb_dc_ep_read_continue()
1318 LOG_ERR("Wrong endpoint direction"); in usb_dc_ep_read_continue()
1319 return -EINVAL; in usb_dc_ep_read_continue()
1333 return -EINVAL; in usb_dc_ep_read()
1344 return -EINVAL; in usb_dc_ep_read()
1355 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_set_callback()
1356 return -EINVAL; in usb_dc_ep_set_callback()
1378 LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep); in usb_dc_ep_mps()
1379 return -EINVAL; in usb_dc_ep_mps()