Lines Matching +full:vbus +full:- +full:detect

4  * SPDX-License-Identifier: Apache-2.0
36 /* Needed for pico-sdk */
113 if (*ep_state->buf_ctl & USB_BUF_CTRL_AVAIL) { in udc_rpi_start_xfer()
119 return -ENOMEM; in udc_rpi_start_xfer()
124 memcpy(ep_state->buf, data, len); in udc_rpi_start_xfer()
127 ep_state->read_offset = 0; in udc_rpi_start_xfer()
130 LOG_DBG("xfer ep %d len %d pid: %d", ep, len, ep_state->next_pid); in udc_rpi_start_xfer()
131 val |= ep_state->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID; in udc_rpi_start_xfer()
133 ep_state->next_pid ^= 1u; in udc_rpi_start_xfer()
134 *ep_state->buf_ctl = val; in udc_rpi_start_xfer()
142 *ep_state->buf_ctl = val | USB_BUF_CTRL_AVAIL; in udc_rpi_start_xfer()
150 * - BUFF_STATUS
151 * - BUFF_CPU_SHOULD_HANDLE
152 * - EP_ABOR
153 * - EP_ABORT_DONE
154 * - EP_STATUS_STALL_NAK
167 if (*ep_state->buf_ctl & USB_BUF_CTRL_AVAIL) { in udc_rpi_cancel_endpoint()
172 hw_set_alias(usb_hw)->abort = mask; in udc_rpi_cancel_endpoint()
173 while ((usb_hw->abort_done & mask) != mask) { in udc_rpi_cancel_endpoint()
177 *ep_state->buf_ctl &= ~USB_BUF_CTRL_AVAIL; in udc_rpi_cancel_endpoint()
180 hw_clear_alias(usb_hw)->abort = mask; in udc_rpi_cancel_endpoint()
184 k_sem_give(&ep_state->write_sem); in udc_rpi_cancel_endpoint()
205 if (*ep_state->buf_ctl & USB_BUF_CTRL_AVAIL) { in udc_rpi_handle_setup()
221 udc_rpi_get_ep_state(USB_CONTROL_EP_IN)->next_pid = 1; in udc_rpi_handle_setup()
222 udc_rpi_get_ep_state(USB_CONTROL_EP_OUT)->next_pid = 1; in udc_rpi_handle_setup()
235 uint32_t status = usb_hw->buf_status; in udc_rpi_handle_buff_status()
243 hw_clear_alias(usb_hw)->buf_status = bit; in udc_rpi_handle_buff_status()
254 usb_hw->dev_addr_ctrl = state.addr; in udc_rpi_handle_buff_status()
258 k_sem_give(&ep_state->write_sem); in udc_rpi_handle_buff_status()
301 uint32_t status = usb_hw->ints; in udc_rpi_isr()
318 * this may seem a little counter-intuitive, because setup irqs in udc_rpi_isr()
331 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_SETUP_REC_BITS; in udc_rpi_isr()
336 LOG_DBG("buf %u ep %u", *udc_rpi_get_ep_state(0x81)->buf_ctl, in udc_rpi_isr()
337 *udc_rpi_get_ep_state(0x81)->ep_ctl); in udc_rpi_isr()
339 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_CONNECTED_BITS; in udc_rpi_isr()
343 msg.type = usb_hw->sie_status & USB_SIE_STATUS_CONNECTED_BITS ? in udc_rpi_isr()
347 /* VBUS detection does not always detect the detach. in udc_rpi_isr()
348 * Check on disconnect if VBUS is still attached in udc_rpi_isr()
351 (usb_hw->sie_status & USB_SIE_STATUS_VBUS_DETECTED_BITS) == 0) { in udc_rpi_isr()
352 LOG_DBG("Disconnected. Disabling pull-up"); in udc_rpi_isr()
353 hw_clear_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS; in udc_rpi_isr()
361 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_VBUS_DETECTED_BITS; in udc_rpi_isr()
364 if (usb_hw->sie_status & USB_SIE_STATUS_VBUS_DETECTED_BITS) { in udc_rpi_isr()
365 LOG_DBG("VBUS attached. Enabling pull-up"); in udc_rpi_isr()
366 hw_set_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS; in udc_rpi_isr()
368 LOG_DBG("VBUS detached. Disabling pull-up"); in udc_rpi_isr()
369 hw_clear_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS; in udc_rpi_isr()
377 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_BUS_RESET_BITS; in udc_rpi_isr()
378 usb_hw->dev_addr_ctrl = 0; in udc_rpi_isr()
397 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_SUSPENDED_BITS; in udc_rpi_isr()
403 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_RESUME_BITS; in udc_rpi_isr()
409 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_DATA_SEQ_ERROR_BITS; in udc_rpi_isr()
415 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_RX_TIMEOUT_BITS; in udc_rpi_isr()
421 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_RX_OVERFLOW_BITS; in udc_rpi_isr()
427 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_BIT_STUFF_ERROR_BITS; in udc_rpi_isr()
433 hw_clear_alias(usb_hw)->sie_status = USB_SIE_STATUS_CRC_ERROR_BITS; in udc_rpi_isr()
444 state.out_ep_state[i].buf_ctl = &usb_dpram->ep_buf_ctrl[i].out; in udc_rpi_init_endpoint()
445 state.in_ep_state[i].buf_ctl = &usb_dpram->ep_buf_ctrl[i].in; in udc_rpi_init_endpoint()
448 state.out_ep_state[i].ep_ctl = &usb_dpram->ep_ctrl[i - 1].out; in udc_rpi_init_endpoint()
449 state.in_ep_state[i].ep_ctl = &usb_dpram->ep_ctrl[i - 1].in; in udc_rpi_init_endpoint()
452 &usb_dpram->epx_data[((i - 1) * 2 + 1) * DATA_BUFFER_SIZE]; in udc_rpi_init_endpoint()
453 state.in_ep_state[i].buf = &usb_dpram->epx_data[((i - 1) * 2) * DATA_BUFFER_SIZE]; in udc_rpi_init_endpoint()
455 state.out_ep_state[i].buf = &usb_dpram->ep0_buf_a[0]; in udc_rpi_init_endpoint()
456 state.in_ep_state[i].buf = &usb_dpram->ep0_buf_a[0]; in udc_rpi_init_endpoint()
484 usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS; in udc_rpi_init()
487 /* Force VBUS detect so the device thinks it is plugged into a host */ in udc_rpi_init()
488 usb_hw->pwr = in udc_rpi_init()
493 usb_hw->main_ctrl = USB_MAIN_CTRL_CONTROLLER_EN_BITS; in udc_rpi_init()
496 usb_hw->sie_ctrl = USB_SIE_CTRL_EP0_INT_1BUF_BITS; in udc_rpi_init()
501 usb_hw->inte = USB_INTS_BUFF_STATUS_BITS | USB_INTS_BUS_RESET_BITS | in udc_rpi_init()
517 /* Self powered devices must enable the pull up only if vbus is detected. in udc_rpi_init()
518 * If the pull-up is not enabled here, this will be handled by the USB_INTS_VBUS_DETECT in udc_rpi_init()
521 if (usb_hw->sie_status & USB_SIE_STATUS_VBUS_DETECTED_BITS) { in udc_rpi_init()
522 LOG_DBG("Enabling pull-up"); in udc_rpi_init()
524 hw_set_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS; in udc_rpi_init()
544 return -EINVAL; in usb_dc_ep_set_callback()
547 ep_state->cb = cb; in usb_dc_ep_set_callback()
575 return -EINVAL; in usb_dc_ep_start_read()
589 uint8_t ep_idx = USB_EP_GET_IDX(cfg->ep_addr); in usb_dc_ep_check_cap()
592 cfg->ep_addr, cfg->ep_mps, cfg->ep_type); in usb_dc_ep_check_cap()
594 if ((cfg->ep_type == USB_DC_EP_CONTROL) && ep_idx) { in usb_dc_ep_check_cap()
596 return -1; in usb_dc_ep_check_cap()
599 if (ep_idx > (USB_NUM_BIDIR_ENDPOINTS - 1)) { in usb_dc_ep_check_cap()
601 return -1; in usb_dc_ep_check_cap()
609 uint8_t ep = ep_cfg->ep_addr; in usb_dc_ep_configure()
613 return -EINVAL; in usb_dc_ep_configure()
617 ep_cfg->ep_addr, ep_state->mps, in usb_dc_ep_configure()
618 ep_cfg->ep_mps, ep_cfg->ep_type); in usb_dc_ep_configure()
620 ep_state->mps = ep_cfg->ep_mps; in usb_dc_ep_configure()
621 ep_state->type = ep_cfg->ep_type; in usb_dc_ep_configure()
633 return -EINVAL; in usb_dc_ep_set_stall()
636 hw_set_alias(usb_hw)->ep_stall_arm = USB_EP_DIR_IS_OUT(ep) ? in usb_dc_ep_set_stall()
641 *ep_state->buf_ctl = USB_BUF_CTRL_STALL; in usb_dc_ep_set_stall()
643 /* Un-arm EP0_OUT endpoint, to make sure next setup packet starts clean */ in usb_dc_ep_set_stall()
647 ep_state->halted = 1U; in usb_dc_ep_set_stall()
660 return -EINVAL; in usb_dc_ep_clear_stall()
664 val = *ep_state->buf_ctl; in usb_dc_ep_clear_stall()
667 *ep_state->buf_ctl = val; in usb_dc_ep_clear_stall()
669 ep_state->halted = 0U; in usb_dc_ep_clear_stall()
670 ep_state->read_offset = 0U; in usb_dc_ep_clear_stall()
683 return -EINVAL; in usb_dc_ep_is_stalled()
686 *stalled = ep_state->halted; in usb_dc_ep_is_stalled()
693 /* TODO: Bits 0-5 are ignored by the controller so make sure these are 0 */ in usb_dc_ep_rpi_pico_buffer_offset()
702 return -EINVAL; in usb_dc_ep_enable()
705 LOG_DBG("ep 0x%02x (id: %d) -> type %d", ep, USB_EP_GET_IDX(ep), ep_state->type); in usb_dc_ep_enable()
708 *ep_state->buf_ctl = USB_BUF_CTRL_DATA0_PID; in usb_dc_ep_enable()
709 ep_state->next_pid = 0; in usb_dc_ep_enable()
712 if (ep_state->ep_ctl) { in usb_dc_ep_enable()
716 (ep_state->type << EP_CTRL_BUFFER_TYPE_LSB) | in usb_dc_ep_enable()
717 usb_dc_ep_rpi_pico_buffer_offset(ep_state->buf); in usb_dc_ep_enable()
719 *ep_state->ep_ctl = val; in usb_dc_ep_enable()
736 return -EINVAL; in usb_dc_ep_disable()
740 if (!ep_state->ep_ctl) { in usb_dc_ep_disable()
751 uint8_t val = *ep_state->ep_ctl & ~EP_CTRL_ENABLE_BITS; in usb_dc_ep_disable()
753 *ep_state->ep_ctl = val; in usb_dc_ep_disable()
769 return -EINVAL; in usb_dc_ep_write()
788 } else if (len > ep_state->mps) { in usb_dc_ep_write()
789 len = ep_state->mps; in usb_dc_ep_write()
792 ret = k_sem_take(&ep_state->write_sem, K_NO_WAIT); in usb_dc_ep_write()
794 return -EAGAIN; in usb_dc_ep_write()
804 k_sem_give(&ep_state->write_sem); in usb_dc_ep_write()
805 ret = -EIO; in usb_dc_ep_write()
822 uint32_t buf_ctl = *ep_state->buf_ctl; in udc_rpi_get_ep_buffer_len()
835 return -EINVAL; in usb_dc_ep_read_wait()
840 return -EINVAL; in usb_dc_ep_read_wait()
850 read_count = udc_rpi_get_ep_buffer_len(ep) - ep_state->read_offset; in usb_dc_ep_read_wait()
853 LOG_DBG("ep 0x%02x, %u bytes, %u+%u, %p", ep, max_data_len, ep_state->read_offset, in usb_dc_ep_read_wait()
860 memcpy(data, (const void *)&usb_dpram->setup_packet, read_count); in usb_dc_ep_read_wait()
862 memcpy(data, ep_state->buf + ep_state->read_offset, read_count); in usb_dc_ep_read_wait()
865 ep_state->read_offset += read_count; in usb_dc_ep_read_wait()
880 const struct usb_setup_packet *const setup = (const void *)&usb_dpram->setup_packet; in usb_dc_control_ep_read_continue()
884 setup->wLength, usb_reqtype_is_to_device(setup)); in usb_dc_control_ep_read_continue()
885 if (setup->wLength != 0U) { in usb_dc_control_ep_read_continue()
889 * 2) in the to_host case, to receive a 0-length status stage transfer in usb_dc_control_ep_read_continue()
903 len, ep_state->read_offset); in usb_dc_control_ep_read_continue()
905 if (state.control_out_ep_rcvd + ep_state->read_offset < setup->wLength) { in usb_dc_control_ep_read_continue()
909 if (len == ep_state->read_offset) { in usb_dc_control_ep_read_continue()
910 state.control_out_ep_rcvd += ep_state->read_offset; in usb_dc_control_ep_read_continue()
926 return -EINVAL; in usb_dc_ep_read_continue()
938 ep, len, ep_state->read_offset); in usb_dc_ep_read_continue()
940 if (len == ep_state->read_offset) { in usb_dc_ep_read_continue()
959 return -EINVAL; in usb_dc_ep_read()
967 return -EINVAL; in usb_dc_ep_read()
983 return -EINVAL; in usb_dc_ep_flush()
996 return -EINVAL; in usb_dc_ep_mps()
999 return ep_state->mps; in usb_dc_ep_mps()
1020 hw_set_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_RESUME_BITS; in usb_dc_wakeup_request()
1049 if (ep_state->cb) { in udc_rpi_thread_main()
1050 ep_state->cb(msg.ep, msg.type); in udc_rpi_thread_main()