Lines Matching refs:ep_state
119 struct smartbond_ep_state ep_state[2][4]; member
123 #define EP0_OUT_STATE(data) (&data->ep_state[0][0])
124 #define EP0_IN_STATE(data) (&data->ep_state[1][0])
241 return (ep_idx < config->num_of_eps) ? &data->ep_state[ep_dir][ep_idx] : NULL; in usb_dc_get_ep_state()
249 return ep_idx < config->num_of_eps ? &data->ep_state[0][ep_idx] : NULL; in usb_dc_get_ep_out_state()
257 return ep_idx < config->num_of_eps ? &data->ep_state[1][ep_idx] : NULL; in usb_dc_get_ep_in_state()
271 static void fill_tx_fifo(struct smartbond_ep_state *ep_state) in fill_tx_fifo() argument
275 struct smartbond_ep_reg_set *regs = ep_state->regs; in fill_tx_fifo()
276 struct net_buf *buf = ep_state->buf; in fill_tx_fifo()
277 const struct udc_ep_config *const ep_cfg = &ep_state->config; in fill_tx_fifo()
283 if (remaining > mps - ep_state->last_packet_size) { in fill_tx_fifo()
284 remaining = mps - ep_state->last_packet_size; in fill_tx_fifo()
293 ep_state->last_packet_size++; in fill_tx_fifo()
324 static bool try_allocate_dma(struct usb_smartbond_data *data, struct smartbond_ep_state *ep_state) in try_allocate_dma() argument
326 struct udc_ep_config *const ep_cfg = &ep_state->config; in try_allocate_dma()
331 if (atomic_ptr_cas(&data->dma_ep[dir_ix], NULL, ep_state)) { in try_allocate_dma()
358 static void start_rx_packet(struct usb_smartbond_data *data, struct smartbond_ep_state *ep_state) in start_rx_packet() argument
360 struct udc_ep_config *const ep_cfg = &ep_state->config; in start_rx_packet()
363 struct smartbond_ep_reg_set *regs = ep_state->regs; in start_rx_packet()
364 struct net_buf *buf = ep_state->buf; in start_rx_packet()
371 ep_state->last_packet_size = 0; in start_rx_packet()
374 if (try_allocate_dma(data, ep_state)) { in start_rx_packet()
410 static void start_tx_packet(struct usb_smartbond_data *data, struct smartbond_ep_state *ep_state) in start_tx_packet() argument
413 struct smartbond_ep_reg_set *regs = ep_state->regs; in start_tx_packet()
414 struct udc_ep_config *const ep_cfg = &ep_state->config; in start_tx_packet()
415 struct net_buf *buf = ep_state->buf; in start_tx_packet()
424 ep_state->last_packet_size = 0; in start_tx_packet()
434 (uint32_t)(buf->data) >= CONFIG_SRAM_BASE_ADDRESS && try_allocate_dma(data, ep_state)) { in start_tx_packet()
437 fill_tx_fifo(ep_state); in start_tx_packet()
453 static uint16_t read_rx_fifo(struct smartbond_ep_state *ep_state, uint8_t *dst, in read_rx_fifo() argument
456 struct smartbond_ep_reg_set *regs = ep_state->regs; in read_rx_fifo()
457 struct udc_ep_config *const ep_cfg = &ep_state->config; in read_rx_fifo()
459 uint16_t remaining = mps - ep_state->last_packet_size; in read_rx_fifo()
470 ep_state->last_packet_size += receive_this_time; in read_rx_fifo()
532 struct smartbond_ep_state *ep_state = (struct smartbond_ep_state *)(ep_cfg); in udc_smartbond_ep_abort() local
537 if (data->dma_ep[0] == ep_state) { in udc_smartbond_ep_abort()
540 } else if (data->dma_ep[1] == ep_state) { in udc_smartbond_ep_abort()
546 ep_state->regs->rxc |= USB_USB_RXC0_REG_USB_FLUSH_Msk; in udc_smartbond_ep_abort()
547 ep_state->regs->rxc &= ~USB_USB_RXC0_REG_USB_FLUSH_Msk; in udc_smartbond_ep_abort()
549 ep_state->regs->txc |= USB_USB_TXC0_REG_USB_FLUSH_Msk; in udc_smartbond_ep_abort()
550 ep_state->regs->txc &= ~USB_USB_TXC0_REG_USB_FLUSH_Msk; in udc_smartbond_ep_abort()
557 struct smartbond_ep_state *ep_state = usb_dc_get_ep_in_state(data, USB_EP_GET_IDX(ep)); in udc_smartbond_ep_tx() local
561 (ep_state->regs->epc_in & USB_USB_EPC1_REG_USB_STALL_Msk) != 0) { in udc_smartbond_ep_tx()
569 ep_state->buf = buf; in udc_smartbond_ep_tx()
570 ep_state->last_packet_size = 0; in udc_smartbond_ep_tx()
572 start_tx_packet(data, ep_state); in udc_smartbond_ep_tx()
583 struct smartbond_ep_state *ep_state = usb_dc_get_ep_out_state(data, USB_EP_GET_IDX(ep)); in udc_smartbond_ep_rx() local
595 ep_state->last_packet_size = 0; in udc_smartbond_ep_rx()
596 ep_state->buf = buf; in udc_smartbond_ep_rx()
598 start_rx_packet(data, ep_state); in udc_smartbond_ep_rx()
666 struct smartbond_ep_state *ep_state; in udc_smartbond_ep_enable() local
674 ep_state = (struct smartbond_ep_state *)(ep_cfg); in udc_smartbond_ep_enable()
676 ep_state->regs->txc &= ~USB_USB_TXC0_REG_USB_IGN_IN_Msk; in udc_smartbond_ep_enable()
678 ep_state->regs->epc_in |= USB_USB_EPC1_REG_USB_EP_EN_Msk | in udc_smartbond_ep_enable()
685 ep_state->regs->rxc &= ~USB_USB_RXC0_REG_USB_IGN_OUT_Msk; in udc_smartbond_ep_enable()
687 ep_state->regs->rxc &= ~USB_USB_RXC0_REG_USB_IGN_SETUP_Msk; in udc_smartbond_ep_enable()
689 ep_state->regs->epc_out = USB_USB_EPC2_REG_USB_EP_EN_Msk | in udc_smartbond_ep_enable()
704 struct smartbond_ep_state *ep_state; in udc_smartbond_ep_disable() local
708 ep_state = usb_dc_get_ep_state(data, ep); in udc_smartbond_ep_disable()
710 ep_state->regs->txc = in udc_smartbond_ep_disable()
713 ep_state->regs->rxc = in udc_smartbond_ep_disable()
722 struct smartbond_ep_state *ep_state = (struct smartbond_ep_state *)(ep_cfg); in udc_smartbond_ep_set_halt() local
741 ep_state->regs->rxc |= USB_USB_RXC0_REG_USB_RX_EN_Msk; in udc_smartbond_ep_set_halt()
742 ep_state->regs->epc_in |= USB_USB_EPC0_REG_USB_STALL_Msk; in udc_smartbond_ep_set_halt()
744 ep_state->regs->epc_out = USB_USB_EPC1_REG_USB_STALL_Msk; in udc_smartbond_ep_set_halt()
745 ep_state->regs->rxc = USB_USB_RXC1_REG_USB_RX_EN_Msk; in udc_smartbond_ep_set_halt()
747 ep_state->regs->epc_in |= USB_USB_EPC1_REG_USB_STALL_Msk; in udc_smartbond_ep_set_halt()
748 ep_state->regs->txc = in udc_smartbond_ep_set_halt()
758 struct smartbond_ep_state *ep_state = (struct smartbond_ep_state *)(ep_cfg); in udc_smartbond_ep_clear_halt() local
770 ep_state->regs->epc_out &= ~USB_USB_EPC1_REG_USB_STALL_Msk; in udc_smartbond_ep_clear_halt()
773 ep_state->regs->epc_in &= ~USB_USB_EPC1_REG_USB_STALL_Msk; in udc_smartbond_ep_clear_halt()
850 if (data->ep_state[0][0].buf != NULL) { in check_reset_end()
918 struct smartbond_ep_state *ep_state = usb_dc_get_ep_out_state(data, ep_idx); in handle_epx_rx_ev() local
920 struct smartbond_ep_reg_set *regs = ep_state->regs; in handle_epx_rx_ev()
921 struct udc_ep_config *const ep_cfg = &ep_state->config; in handle_epx_rx_ev()
922 struct net_buf *buf = ep_state->buf; in handle_epx_rx_ev()
929 ep_state->last_packet_size = 0; in handle_epx_rx_ev()
930 if (data->dma_ep[0] == ep_state) { in handle_epx_rx_ev()
941 if (data->dma_ep[0] == ep_state) { in handle_epx_rx_ev()
951 ep_state->last_packet_size = rx_dma_status.total_copied; in handle_epx_rx_ev()
959 if (ep_state->last_packet_size == in handle_epx_rx_ev()
961 ep_state->last_packet_size++; in handle_epx_rx_ev()
973 fifo_bytes = read_rx_fifo(ep_state, in handle_epx_rx_ev()
974 net_buf_tail(buf) + ep_state->last_packet_size, in handle_epx_rx_ev()
979 if (!ep_state->iso && in handle_epx_rx_ev()
983 ep_state->last_packet_size = 0; in handle_epx_rx_ev()
986 start_rx_packet(data, ep_state); in handle_epx_rx_ev()
990 net_buf_add(buf, ep_state->last_packet_size); in handle_epx_rx_ev()
993 ep_state->last_packet_size < udc_mps_ep_size(ep_cfg) || in handle_epx_rx_ev()
994 ep_state->iso) { in handle_epx_rx_ev()
1004 start_rx_packet(data, ep_state); in handle_epx_rx_ev()
1025 static void handle_epx_tx_ev(struct usb_smartbond_data *data, struct smartbond_ep_state *ep_state) in handle_epx_tx_ev() argument
1029 struct smartbond_ep_reg_set *regs = ep_state->regs; in handle_epx_tx_ev()
1030 struct udc_ep_config *const ep_cfg = &ep_state->config; in handle_epx_tx_ev()
1031 struct net_buf *buf = ep_state->buf; in handle_epx_tx_ev()
1037 if (data->dma_ep[1] == ep_state) { in handle_epx_tx_ev()
1047 ep_state->last_packet_size = tx_dma_status.total_copied + 1; in handle_epx_tx_ev()
1054 net_buf_pull(buf, ep_state->last_packet_size); in handle_epx_tx_ev()
1055 ep_state->last_packet_size = 0; in handle_epx_tx_ev()
1088 start_tx_packet(data, ep_state); in handle_epx_tx_ev()
1193 data->ep_state[1][i].buf = NULL; in handle_bus_reset()
1194 data->ep_state[1][i].config.stat.busy = 0; in handle_bus_reset()
1230 struct smartbond_ep_state *ep_state; in handle_alt_ev() local
1242 if (data->ep_state[0][0].buf != NULL) { in handle_alt_ev()
1249 ep_state = usb_dc_get_ep_out_state(data, ep_idx); in handle_alt_ev()
1250 if (!ep_state->config.stat.halted) { in handle_alt_ev()
1251 start_rx_packet(data, ep_state); in handle_alt_ev()
1317 if (data->ep_state[0][0].buf != NULL) { in udc_smartbond_isr()
1434 struct smartbond_ep_state *ep_state = EP0_OUT_STATE(data); in usbd_ctrl_feed_dout() local
1435 struct udc_ep_config *const ep_cfg = &ep_state->config; in usbd_ctrl_feed_dout()
1444 ep_state->buf = buf; in usbd_ctrl_feed_dout()
1445 start_rx_packet(data, ep_state); in usbd_ctrl_feed_dout()
1648 data->ep_state[0][i].config.caps.out = 1; in udc_smartbond_init()
1650 data->ep_state[0][i].config.caps.control = 1; in udc_smartbond_init()
1651 data->ep_state[0][i].config.caps.mps = 8; in udc_smartbond_init()
1653 data->ep_state[0][i].config.caps.bulk = 1; in udc_smartbond_init()
1654 data->ep_state[0][i].config.caps.interrupt = 1; in udc_smartbond_init()
1655 data->ep_state[0][i].config.caps.iso = 1; in udc_smartbond_init()
1656 data->ep_state[0][i].config.caps.mps = mps; in udc_smartbond_init()
1658 data->ep_state[0][i].config.addr = USB_EP_DIR_OUT | i; in udc_smartbond_init()
1659 err = udc_register_ep(dev, &data->ep_state[0][i].config); in udc_smartbond_init()
1664 data->ep_state[0][i].regs = reg_set + i; in udc_smartbond_init()
1668 data->ep_state[1][i].config.caps.in = 1; in udc_smartbond_init()
1670 data->ep_state[1][i].config.caps.control = 1; in udc_smartbond_init()
1671 data->ep_state[1][i].config.caps.mps = 8; in udc_smartbond_init()
1673 data->ep_state[1][i].config.caps.bulk = 1; in udc_smartbond_init()
1674 data->ep_state[1][i].config.caps.interrupt = 1; in udc_smartbond_init()
1675 data->ep_state[1][i].config.caps.iso = 1; in udc_smartbond_init()
1676 data->ep_state[1][i].config.caps.mps = mps; in udc_smartbond_init()
1679 data->ep_state[1][i].config.addr = USB_EP_DIR_IN | i; in udc_smartbond_init()
1680 err = udc_register_ep(dev, &data->ep_state[1][i].config); in udc_smartbond_init()
1685 data->ep_state[1][i].regs = reg_set + i; in udc_smartbond_init()