Lines Matching refs:ep_state

166 	struct smartbond_ep_state ep_state[2][4];  member
324 return (ep_idx < EP_MAX) ? &dev_state.ep_state[ep_dir][ep_idx] : NULL; in usb_dc_get_ep_state()
332 &dev_state.ep_state[0][ep_idx] : NULL; in usb_dc_get_ep_out_state()
340 &dev_state.ep_state[1][ep_idx] : NULL; in usb_dc_get_ep_in_state()
364 static void fill_tx_fifo(struct smartbond_ep_state *ep_state) in fill_tx_fifo() argument
368 uint8_t ep_idx = USB_EP_GET_IDX(ep_state->ep_addr); in fill_tx_fifo()
369 struct smartbond_ep_reg_set *regs = ep_state->regs; in fill_tx_fifo()
371 src = &ep_state->buffer[ep_state->transferred]; in fill_tx_fifo()
372 remaining = ep_state->total_len - ep_state->transferred; in fill_tx_fifo()
373 if (remaining > ep_state->mps - ep_state->last_packet_size) { in fill_tx_fifo()
374 remaining = ep_state->mps - ep_state->last_packet_size; in fill_tx_fifo()
384 ep_state->last_packet_size++; in fill_tx_fifo()
409 static bool try_allocate_dma(struct smartbond_ep_state *ep_state, uint8_t dir) in try_allocate_dma() argument
411 uint8_t ep_idx = USB_EP_GET_IDX(ep_state->ep_addr); in try_allocate_dma()
414 if (atomic_ptr_cas(&dev_state.dma_ep[dir_ix], NULL, ep_state)) { in try_allocate_dma()
441 static void start_rx_packet(struct smartbond_ep_state *ep_state) in start_rx_packet() argument
443 uint8_t ep_idx = USB_EP_GET_IDX(ep_state->ep_addr); in start_rx_packet()
444 struct smartbond_ep_reg_set *regs = ep_state->regs; in start_rx_packet()
446 LOG_DBG("%02x", ep_state->ep_addr); in start_rx_packet()
448 ep_state->last_packet_size = 0; in start_rx_packet()
449 ep_state->transferred = 0; in start_rx_packet()
450 ep_state->total_len = 0; in start_rx_packet()
452 if (ep_state->mps > DMA_MIN_TRANSFER_SIZE) { in start_rx_packet()
453 if (try_allocate_dma(ep_state, USB_EP_DIR_OUT)) { in start_rx_packet()
455 ep_state->buffer, in start_rx_packet()
456 ep_state->mps); in start_rx_packet()
457 } else if (ep_state->mps > EP_FIFO_SIZE) { in start_rx_packet()
490 static void start_tx_packet(struct smartbond_ep_state *ep_state) in start_tx_packet() argument
492 struct smartbond_ep_reg_set *regs = ep_state->regs; in start_tx_packet()
493 uint16_t remaining = ep_state->total_len - ep_state->transferred; in start_tx_packet()
494 uint16_t size = MIN(remaining, ep_state->mps); in start_tx_packet()
496 LOG_DBG("%02x %d/%d", ep_state->ep_addr, size, remaining); in start_tx_packet()
498 ep_state->last_packet_size = 0; in start_tx_packet()
502 if (ep_state->data1) { in start_tx_packet()
506 if (ep_state->ep_addr != EP0_IN && in start_tx_packet()
508 (uint32_t)(ep_state->buffer) >= CONFIG_SRAM_BASE_ADDRESS && in start_tx_packet()
509 try_allocate_dma(ep_state, USB_EP_DIR_IN)) { in start_tx_packet()
514 start_tx_dma(ep_state->buffer + ep_state->transferred, in start_tx_packet()
518 fill_tx_fifo(ep_state); in start_tx_packet()
524 static uint16_t read_rx_fifo(struct smartbond_ep_state *ep_state, in read_rx_fifo() argument
527 struct smartbond_ep_reg_set *regs = ep_state->regs; in read_rx_fifo()
528 uint16_t remaining = ep_state->mps - ep_state->last_packet_size; in read_rx_fifo()
530 uint8_t *buf = ep_state->buffer + ep_state->last_packet_size; in read_rx_fifo()
540 ep_state->last_packet_size += receive_this_time; in read_rx_fifo()
636 struct smartbond_ep_state *ep_state = usb_dc_get_ep_out_state(ep_idx); in handle_epx_rx_ev() local
637 struct smartbond_ep_reg_set *regs = ep_state->regs; in handle_epx_rx_ev()
644 ep_state->last_packet_size = 0; in handle_epx_rx_ev()
645 if (dev_state.dma_ep[0] == ep_state) { in handle_epx_rx_ev()
656 if (dev_state.dma_ep[0] == ep_state) { in handle_epx_rx_ev()
665 ep_state->last_packet_size = rx_dma_status.total_copied; in handle_epx_rx_ev()
673 if (ep_state->last_packet_size == in handle_epx_rx_ev()
675 ep_state->last_packet_size++; in handle_epx_rx_ev()
687 fifo_bytes = read_rx_fifo(ep_state, fifo_bytes); in handle_epx_rx_ev()
691 if (!ep_state->iso && in handle_epx_rx_ev()
693 ep_state->data1) { in handle_epx_rx_ev()
696 ep_state->last_packet_size = 0; in handle_epx_rx_ev()
698 start_rx_packet(ep_state); in handle_epx_rx_ev()
700 ep_state->data1 ^= 1; in handle_epx_rx_ev()
701 atomic_clear(&ep_state->busy); in handle_epx_rx_ev()
723 static void handle_epx_tx_ev(struct smartbond_ep_state *ep_state) in handle_epx_tx_ev() argument
726 struct smartbond_ep_reg_set *regs = ep_state->regs; in handle_epx_tx_ev()
731 if (dev_state.dma_ep[1] == ep_state) { in handle_epx_tx_ev()
740 ep_state->last_packet_size = tx_dma_status.total_copied + 1; in handle_epx_tx_ev()
747 ep_state->transferred += ep_state->last_packet_size; in handle_epx_tx_ev()
748 ep_state->last_packet_size = 0; in handle_epx_tx_ev()
749 ep_state->data1 ^= 1; in handle_epx_tx_ev()
751 if (ep_state->transferred == ep_state->total_len) { in handle_epx_tx_ev()
752 atomic_clear(&ep_state->busy); in handle_epx_tx_ev()
753 ep_state->cb(ep_state->ep_addr, USB_DC_EP_DATA_IN); in handle_epx_tx_ev()
767 LOG_DBG("EP 0x%02x FIFO underrun\n", ep_state->ep_addr); in handle_epx_tx_ev()
770 start_tx_packet(ep_state); in handle_epx_tx_ev()
806 if (dev_state.ep_state[0][0].buffer != NULL) { in check_reset_end()
831 dev_state.ep_state[1][i].buffer = NULL; in handle_bus_reset()
832 dev_state.ep_state[1][i].transferred = 0; in handle_bus_reset()
833 dev_state.ep_state[1][i].total_len = 0; in handle_bus_reset()
834 atomic_clear(&dev_state.ep_state[1][i].busy); in handle_bus_reset()
870 struct smartbond_ep_state *ep_state; in handle_alt_ev() local
883 if (dev_state.ep_state[0][0].buffer != NULL) { in handle_alt_ev()
891 ep_state = usb_dc_get_ep_out_state(ep_num); in handle_alt_ev()
892 if (ep_state->enabled) { in handle_alt_ev()
893 start_rx_packet(ep_state); in handle_alt_ev()
1022 if (dev_state.ep_state[0][0].buffer != NULL) { in usb_dc_smartbond_isr()
1044 dev_state.ep_state[0][i].cb(dev_state.ep_state[0][i].ep_addr, in usb_dc_smartbond_isr()
1142 dev_state.ep_state[0][i].regs = reg_sets[i]; in usb_init()
1143 dev_state.ep_state[0][i].ep_addr = i | USB_EP_DIR_OUT; in usb_init()
1144 dev_state.ep_state[0][i].buffer = ep_out_bufs[i]; in usb_init()
1145 dev_state.ep_state[1][i].regs = reg_sets[i]; in usb_init()
1146 dev_state.ep_state[1][i].ep_addr = i | USB_EP_DIR_IN; in usb_init()
1150 dev_state.ep_state[0][0].mps = EP0_FIFO_SIZE; in usb_init()
1151 dev_state.ep_state[1][0].mps = EP0_FIFO_SIZE; in usb_init()
1169 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_disable() local
1173 if (ep_state == NULL) { in usb_dc_ep_disable()
1178 ep_state->enabled = 0; in usb_dc_ep_disable()
1179 if (ep_state->ep_addr == EP0_IN) { in usb_dc_ep_disable()
1181 } else if (ep_state->ep_addr == EP0_OUT) { in usb_dc_ep_disable()
1185 ep_state->regs->epc_out &= ~USB_USB_EPC2_REG_USB_EP_EN_Msk; in usb_dc_ep_disable()
1187 ep_state->regs->epc_in &= ~USB_USB_EPC1_REG_USB_EP_EN_Msk; in usb_dc_ep_disable()
1195 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_mps() local
1197 if (ep_state == NULL) { in usb_dc_ep_mps()
1202 return ep_state->mps; in usb_dc_ep_mps()
1207 struct smartbond_ep_state *ep_state = usb_dc_get_ep_out_state(ep); in usb_dc_ep_read_continue() local
1209 if (ep_state == NULL) { in usb_dc_ep_read_continue()
1219 if (ep_state->transferred >= ep_state->last_packet_size) { in usb_dc_ep_read_continue()
1220 start_rx_packet(ep_state); in usb_dc_ep_read_continue()
1229 struct smartbond_ep_state *ep_state = usb_dc_get_ep_out_state(ep); in usb_dc_ep_read_wait() local
1232 if (ep_state == NULL) { in usb_dc_ep_read_wait()
1239 read_count = ep_state->last_packet_size - ep_state->transferred; in usb_dc_ep_read_wait()
1247 memcpy(data, ep_state->buffer + ep_state->transferred, read_count); in usb_dc_ep_read_wait()
1248 ep_state->transferred += read_count; in usb_dc_ep_read_wait()
1301 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_set_callback() local
1305 if (ep_state == NULL) { in usb_dc_ep_set_callback()
1310 ep_state->cb = cb; in usb_dc_ep_set_callback()
1364 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_clear_stall() local
1369 if (ep_state == NULL) { in usb_dc_ep_clear_stall()
1373 regs = ep_state->regs; in usb_dc_ep_clear_stall()
1378 ep_state->stall = false; in usb_dc_ep_clear_stall()
1379 ep_state->data1 = 0; in usb_dc_ep_clear_stall()
1395 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_enable() local
1399 if (ep_state == NULL) { in usb_dc_ep_enable()
1406 if (ep_state->ep_addr == EP0_IN) { in usb_dc_ep_enable()
1408 } else if (ep_state->ep_addr == EP0_OUT) { in usb_dc_ep_enable()
1412 ep_state->last_packet_size = 0; in usb_dc_ep_enable()
1413 ep_state->transferred = 0; in usb_dc_ep_enable()
1414 ep_state->total_len = 0; in usb_dc_ep_enable()
1418 ep_state->regs->epc_out |= USB_USB_EPC1_REG_USB_EP_EN_Msk; in usb_dc_ep_enable()
1420 if (ep_state->busy) { in usb_dc_ep_enable()
1424 start_rx_packet(ep_state); in usb_dc_ep_enable()
1428 ep_state->regs->epc_in |= USB_USB_EPC2_REG_USB_EP_EN_Msk; in usb_dc_ep_enable()
1430 ep_state->enabled = 1; in usb_dc_ep_enable()
1437 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep_cfg->ep_addr); in usb_dc_ep_configure() local
1442 if (ep_state == NULL) { in usb_dc_ep_configure()
1448 ep_state->iso = ep_cfg->ep_type == USB_DC_EP_ISOCHRONOUS; in usb_dc_ep_configure()
1449 iso_mask = (ep_state->iso ? USB_USB_EPC2_REG_USB_ISO_Msk : 0); in usb_dc_ep_configure()
1452 ep_state->mps = EP0_FIFO_SIZE; in usb_dc_ep_configure()
1454 ep_state->mps = ep_cfg->ep_mps; in usb_dc_ep_configure()
1457 ep_state->data1 = 0; in usb_dc_ep_configure()
1464 ep_state->regs->epc_out = ep_idx | iso_mask; in usb_dc_ep_configure()
1466 ep_state->regs->epc_in = ep_idx | iso_mask; in usb_dc_ep_configure()
1493 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_write() local
1495 if (ep_state == NULL) { in usb_dc_ep_write()
1501 if (!atomic_cas(&ep_state->busy, 0, 1)) { in usb_dc_ep_write()
1506 ep_state->buffer = (uint8_t *)data; in usb_dc_ep_write()
1507 ep_state->transferred = 0; in usb_dc_ep_write()
1508 ep_state->total_len = data_len; in usb_dc_ep_write()
1509 ep_state->last_packet_size = 0; in usb_dc_ep_write()
1522 start_tx_packet(ep_state); in usb_dc_ep_write()
1535 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_set_stall() local
1544 if (ep_state == NULL) { in usb_dc_ep_set_stall()
1549 regs = ep_state->regs; in usb_dc_ep_set_stall()
1550 ep_state->stall = 1; in usb_dc_ep_set_stall()
1576 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_is_stalled() local
1582 if (NULL == ep_state || NULL == stalled) { in usb_dc_ep_is_stalled()
1586 *stalled = ep_state->stall; in usb_dc_ep_is_stalled()
1598 struct smartbond_ep_state *ep_state = usb_dc_get_ep_state(ep); in usb_dc_ep_flush() local
1600 if (ep_state == NULL) { in usb_dc_ep_flush()