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

5  * SPDX-License-Identifier: Apache-2.0
85 const struct rpi_pico_config *config = dev->config; in sie_status_clr()
86 usb_hw_t *base = config->base; in sie_status_clr()
88 rpi_pico_bit_clr((mm_reg_t)&base->sie_status, bit); in sie_status_clr()
101 const struct rpi_pico_config *config = dev->config; in get_ep_ctrl_reg()
102 usb_device_dpram_t *dpram = config->dpram; in get_ep_ctrl_reg()
109 return (uintptr_t)&dpram->ep_ctrl[USB_EP_GET_IDX(ep) - 1].out; in get_ep_ctrl_reg()
112 return (uintptr_t)&dpram->ep_ctrl[USB_EP_GET_IDX(ep) - 1].in; in get_ep_ctrl_reg()
118 const struct rpi_pico_config *config = dev->config; in get_buf_ctrl_reg()
119 usb_device_dpram_t *dpram = config->dpram; in get_buf_ctrl_reg()
122 return (uintptr_t)&dpram->ep_buf_ctrl[USB_EP_GET_IDX(ep)].out; in get_buf_ctrl_reg()
125 return (uintptr_t)&dpram->ep_buf_ctrl[USB_EP_GET_IDX(ep)].in; in get_buf_ctrl_reg()
134 return &priv->out_ep[USB_EP_GET_IDX(ep)]; in get_ep_data()
137 return &priv->in_ep[USB_EP_GET_IDX(ep)]; in get_ep_data()
166 const struct rpi_pico_config *config = dev->config; in rpi_pico_ep_cancel()
167 usb_hw_t *base = config->base; in rpi_pico_ep_cancel()
168 mm_reg_t abort_done_reg = (mm_reg_t)&base->abort_done; in rpi_pico_ep_cancel()
169 mm_reg_t abort_reg = (mm_reg_t)&base->abort; in rpi_pico_ep_cancel()
198 struct rpi_pico_ep_data *const ep_data = get_ep_data(dev, cfg->addr); in rpi_pico_prep_rx()
201 buf_ctrl = read_buf_ctrl_reg(dev, cfg->addr); in rpi_pico_prep_rx()
203 LOG_ERR("ep 0x%02x buffer is used by the controller", cfg->addr); in rpi_pico_prep_rx()
204 return -EBUSY; in rpi_pico_prep_rx()
208 cfg->addr, net_buf_tailroom(buf), ep_data->next_pid); in rpi_pico_prep_rx()
210 buf_ctrl = cfg->mps; in rpi_pico_prep_rx()
211 buf_ctrl |= ep_data->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID; in rpi_pico_prep_rx()
212 ep_data->next_pid ^= 1U; in rpi_pico_prep_rx()
214 write_buf_ctrl_reg(dev, cfg->addr, buf_ctrl); in rpi_pico_prep_rx()
222 write_buf_ctrl_reg(dev, cfg->addr, buf_ctrl | USB_BUF_CTRL_AVAIL); in rpi_pico_prep_rx()
230 struct rpi_pico_ep_data *const ep_data = get_ep_data(dev, cfg->addr); in rpi_pico_prep_tx()
234 buf_ctrl = read_buf_ctrl_reg(dev, cfg->addr); in rpi_pico_prep_tx()
236 LOG_ERR("ep 0x%02x buffer is used by the controller", cfg->addr); in rpi_pico_prep_tx()
237 return -EBUSY; in rpi_pico_prep_tx()
240 len = MIN(cfg->mps, buf->len); in rpi_pico_prep_tx()
241 memcpy(ep_data->buf, buf->data, len); in rpi_pico_prep_tx()
244 cfg->addr, len, ep_data->next_pid); in rpi_pico_prep_tx()
247 buf_ctrl |= ep_data->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID; in rpi_pico_prep_tx()
249 ep_data->next_pid ^= 1U; in rpi_pico_prep_tx()
251 write_buf_ctrl_reg(dev, cfg->addr, buf_ctrl); in rpi_pico_prep_tx()
259 write_buf_ctrl_reg(dev, cfg->addr, buf_ctrl | USB_BUF_CTRL_AVAIL); in rpi_pico_prep_tx()
271 return -ENOMEM; in rpi_pico_ctrl_feed_dout()
304 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in rpi_pico_handle_evt_setup()
305 return -ENOMEM; in rpi_pico_handle_evt_setup()
308 net_buf_add_mem(buf, priv->setup, sizeof(priv->setup)); in rpi_pico_handle_evt_setup()
310 LOG_HEXDUMP_DBG(buf->data, buf->len, "setup"); in rpi_pico_handle_evt_setup()
317 LOG_DBG("s:%p|feed for -out-", buf); in rpi_pico_handle_evt_setup()
324 LOG_DBG("s:%p|feed for -in-status", buf); in rpi_pico_handle_evt_setup()
340 buf = udc_buf_get(dev, cfg->addr); in rpi_pico_handle_evt_dout()
342 LOG_ERR("No buffer for OUT ep 0x%02x", cfg->addr); in rpi_pico_handle_evt_dout()
343 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in rpi_pico_handle_evt_dout()
344 return -ENODATA; in rpi_pico_handle_evt_dout()
347 udc_ep_set_busy(dev, cfg->addr, false); in rpi_pico_handle_evt_dout()
349 if (cfg->addr == USB_CONTROL_EP_OUT) { in rpi_pico_handle_evt_dout()
376 buf = udc_buf_peek(dev, cfg->addr); in rpi_pico_handle_evt_din()
378 LOG_ERR("No buffer for ep 0x%02x", cfg->addr); in rpi_pico_handle_evt_din()
379 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in rpi_pico_handle_evt_din()
380 return -ENOBUFS; in rpi_pico_handle_evt_din()
383 buf = udc_buf_get(dev, cfg->addr); in rpi_pico_handle_evt_din()
384 udc_ep_set_busy(dev, cfg->addr, false); in rpi_pico_handle_evt_din()
386 if (cfg->addr == USB_CONTROL_EP_IN) { in rpi_pico_handle_evt_din()
401 if (err == -ENOMEM) { in rpi_pico_handle_evt_din()
418 buf = udc_buf_peek(dev, cfg->addr); in rpi_pico_handle_xfer_next()
423 if (USB_EP_DIR_IS_OUT(cfg->addr)) { in rpi_pico_handle_xfer_next()
430 udc_submit_ep_event(dev, buf, -ECONNREFUSED); in rpi_pico_handle_xfer_next()
432 udc_ep_set_busy(dev, cfg->addr, true); in rpi_pico_handle_xfer_next()
454 LOG_DBG("DOUT event ep 0x%02x", ep_cfg->addr); in rpi_pico_thread_handler()
463 if (ep_cfg->addr != USB_CONTROL_EP_OUT && !udc_ep_is_busy(dev, ep_cfg->addr)) { in rpi_pico_thread_handler()
470 const struct rpi_pico_config *config = dev->config; in rpi_pico_handle_setup()
472 usb_device_dpram_t *dpram = config->dpram; in rpi_pico_handle_setup()
485 sys_put_le32(sys_read32((uintptr_t)&dpram->setup_packet[0]), &priv->setup[0]); in rpi_pico_handle_setup()
486 sys_put_le32(sys_read32((uintptr_t)&dpram->setup_packet[4]), &priv->setup[4]); in rpi_pico_handle_setup()
489 get_ep_data(dev, USB_CONTROL_EP_IN)->next_pid = 1; in rpi_pico_handle_setup()
490 get_ep_data(dev, USB_CONTROL_EP_OUT)->next_pid = 1; in rpi_pico_handle_setup()
509 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in rpi_pico_handle_buff_status_in()
516 if (buf->len) { in rpi_pico_handle_buff_status_in()
544 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in rpi_pico_handle_buff_status_out()
549 net_buf_add_mem(buf, ep_data->buf, MIN(len, net_buf_tailroom(buf))); in rpi_pico_handle_buff_status_out()
564 const struct rpi_pico_config *config = dev->config; in rpi_pico_handle_buff_status()
565 usb_hw_t *base = config->base; in rpi_pico_handle_buff_status()
569 buf_status = sys_read32((mm_reg_t)&base->buf_status); in rpi_pico_handle_buff_status()
585 rpi_pico_bit_clr((mm_reg_t)&base->buf_status, BIT(i)); in rpi_pico_handle_buff_status()
592 const struct rpi_pico_config *config = dev->config; in rpi_pico_isr_handler()
594 usb_hw_t *base = config->base; in rpi_pico_isr_handler()
595 uint32_t status = base->ints; in rpi_pico_isr_handler()
600 sys_read32((mm_reg_t)&base->sof_rd); in rpi_pico_isr_handler()
609 sie_status = sys_read32((mm_reg_t)&base->sie_status); in rpi_pico_isr_handler()
618 priv->rwu_pending) { in rpi_pico_isr_handler()
625 priv->rwu_pending = false; in rpi_pico_isr_handler()
633 priv->rwu_pending = false; in rpi_pico_isr_handler()
648 sys_write32(0, (mm_reg_t)&base->dev_addr_ctrl); in rpi_pico_isr_handler()
657 udc_submit_event(dev, UDC_EVT_ERROR, -EINVAL); in rpi_pico_isr_handler()
665 udc_submit_event(dev, UDC_EVT_ERROR, -EINVAL); in rpi_pico_isr_handler()
673 udc_submit_event(dev, UDC_EVT_ERROR, -EINVAL); in rpi_pico_isr_handler()
681 udc_submit_event(dev, UDC_EVT_ERROR, -EINVAL); in rpi_pico_isr_handler()
689 udc_submit_event(dev, UDC_EVT_ERROR, -EINVAL); in rpi_pico_isr_handler()
720 .ep = cfg->addr, in udc_rpi_pico_ep_enqueue()
726 if (!cfg->stat.halted) { in udc_rpi_pico_ep_enqueue()
741 rpi_pico_ep_cancel(dev, cfg->addr); in udc_rpi_pico_ep_dequeue()
742 buf = udc_buf_get_all(dev, cfg->addr); in udc_rpi_pico_ep_dequeue()
744 udc_submit_ep_event(dev, buf, -ECONNABORTED); in udc_rpi_pico_ep_dequeue()
755 struct rpi_pico_ep_data *const ep_data = get_ep_data(dev, cfg->addr); in udc_rpi_pico_ep_enable()
756 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_ep_enable()
757 uint8_t type = cfg->attributes & USB_EP_TRANSFER_TYPE_MASK; in udc_rpi_pico_ep_enable()
758 usb_device_dpram_t *dpram = config->dpram; in udc_rpi_pico_ep_enable()
761 write_buf_ctrl_reg(dev, cfg->addr, USB_BUF_CTRL_DATA0_PID); in udc_rpi_pico_ep_enable()
762 ep_data->next_pid = 0; in udc_rpi_pico_ep_enable()
764 if (USB_EP_GET_IDX(cfg->addr) != 0) { in udc_rpi_pico_ep_enable()
768 size_t blocks = DIV_ROUND_UP(cfg->mps, 64U); in udc_rpi_pico_ep_enable()
770 err = sys_mem_blocks_alloc(config->mem_block, blocks, &ep_data->buf); in udc_rpi_pico_ep_enable()
773 cfg->addr, blocks); in udc_rpi_pico_ep_enable()
777 ep_ctrl |= (uintptr_t)ep_data->buf & 0xFFFFUL; in udc_rpi_pico_ep_enable()
778 write_ep_ctrl_reg(dev, cfg->addr, ep_ctrl); in udc_rpi_pico_ep_enable()
780 ep_data->buf = dpram->ep0_buf_a; in udc_rpi_pico_ep_enable()
783 LOG_DBG("Enable ep 0x%02x", cfg->addr); in udc_rpi_pico_ep_enable()
791 struct rpi_pico_ep_data *const ep_data = get_ep_data(dev, cfg->addr); in udc_rpi_pico_ep_disable()
792 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_ep_disable()
795 rpi_pico_ep_cancel(dev, cfg->addr); in udc_rpi_pico_ep_disable()
797 if (USB_EP_GET_IDX(cfg->addr) != 0) { in udc_rpi_pico_ep_disable()
798 size_t blocks = DIV_ROUND_UP(cfg->mps, 64U); in udc_rpi_pico_ep_disable()
800 write_ep_ctrl_reg(dev, cfg->addr, 0UL); in udc_rpi_pico_ep_disable()
801 err = sys_mem_blocks_free(config->mem_block, blocks, &ep_data->buf); in udc_rpi_pico_ep_disable()
808 LOG_DBG("Disable ep 0x%02x", cfg->addr); in udc_rpi_pico_ep_disable()
816 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_ep_set_halt()
817 mem_addr_t buf_ctrl_reg = get_buf_ctrl_reg(dev, cfg->addr); in udc_rpi_pico_ep_set_halt()
818 usb_hw_t *base = config->base; in udc_rpi_pico_ep_set_halt()
820 if (USB_EP_GET_IDX(cfg->addr) == 0) { in udc_rpi_pico_ep_set_halt()
821 uint32_t bit = USB_EP_DIR_IS_OUT(cfg->addr) ? in udc_rpi_pico_ep_set_halt()
824 rpi_pico_bit_set((mm_reg_t)&base->ep_stall_arm, bit); in udc_rpi_pico_ep_set_halt()
829 LOG_INF("Set halt ep 0x%02x", cfg->addr); in udc_rpi_pico_ep_set_halt()
830 if (USB_EP_GET_IDX(cfg->addr) != 0) { in udc_rpi_pico_ep_set_halt()
831 cfg->stat.halted = true; in udc_rpi_pico_ep_set_halt()
840 struct rpi_pico_ep_data *const ep_data = get_ep_data(dev, cfg->addr); in udc_rpi_pico_ep_clear_halt()
841 mem_addr_t buf_ctrl_reg = get_buf_ctrl_reg(dev, cfg->addr); in udc_rpi_pico_ep_clear_halt()
843 .ep = cfg->addr, in udc_rpi_pico_ep_clear_halt()
847 if (USB_EP_GET_IDX(cfg->addr) != 0) { in udc_rpi_pico_ep_clear_halt()
848 ep_data->next_pid = 0; in udc_rpi_pico_ep_clear_halt()
859 if (udc_buf_peek(dev, cfg->addr)) { in udc_rpi_pico_ep_clear_halt()
864 cfg->stat.halted = false; in udc_rpi_pico_ep_clear_halt()
866 cfg->addr, sys_read32(buf_ctrl_reg)); in udc_rpi_pico_ep_clear_halt()
873 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_set_address()
874 usb_hw_t *base = config->base; in udc_rpi_pico_set_address()
876 sys_write32(addr, (mm_reg_t)&base->dev_addr_ctrl); in udc_rpi_pico_set_address()
877 LOG_DBG("Set new address %u for %s", addr, dev->name); in udc_rpi_pico_set_address()
884 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_host_wakeup()
886 usb_hw_t *base = config->base; in udc_rpi_pico_host_wakeup()
888 rpi_pico_bit_set((mm_reg_t)&base->sie_ctrl, USB_SIE_CTRL_RESUME_BITS); in udc_rpi_pico_host_wakeup()
889 priv->rwu_pending = true; in udc_rpi_pico_host_wakeup()
891 LOG_DBG("Remote wakeup from %s", dev->name); in udc_rpi_pico_host_wakeup()
898 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_enable()
899 usb_device_dpram_t *dpram = config->dpram; in udc_rpi_pico_enable()
900 usb_hw_t *base = config->base; in udc_rpi_pico_enable()
912 (mm_reg_t)&base->muxing); in udc_rpi_pico_enable()
914 /* Force VBUS detect so the device thinks it is plugged into a host */ in udc_rpi_pico_enable()
916 (mm_reg_t)&base->pwr); in udc_rpi_pico_enable()
919 sys_write32(USB_SIE_CTRL_EP0_INT_1BUF_BITS, (mm_reg_t)&base->sie_ctrl); in udc_rpi_pico_enable()
935 (mm_reg_t)&base->inte); in udc_rpi_pico_enable()
938 rpi_pico_bit_set((mm_reg_t)&base->sie_ctrl, USB_SIE_CTRL_PULLUP_EN_BITS); in udc_rpi_pico_enable()
941 sys_write32(USB_MAIN_CTRL_CONTROLLER_EN_BITS, (mm_reg_t)&base->main_ctrl); in udc_rpi_pico_enable()
943 config->irq_enable_func(dev); in udc_rpi_pico_enable()
945 LOG_DBG("Enable device %s %p", dev->name, (void *)base); in udc_rpi_pico_enable()
952 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_disable()
954 config->irq_disable_func(dev); in udc_rpi_pico_disable()
962 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_init()
967 return -EIO; in udc_rpi_pico_init()
973 return -EIO; in udc_rpi_pico_init()
976 return clock_control_on(config->clk_dev, config->clk_sys); in udc_rpi_pico_init()
981 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_shutdown()
985 return -EIO; in udc_rpi_pico_shutdown()
990 return -EIO; in udc_rpi_pico_shutdown()
993 return clock_control_off(config->clk_dev, config->clk_sys); in udc_rpi_pico_shutdown()
998 const struct rpi_pico_config *config = dev->config; in udc_rpi_pico_driver_preinit()
999 struct udc_data *data = dev->data; in udc_rpi_pico_driver_preinit()
1003 k_mutex_init(&data->mutex); in udc_rpi_pico_driver_preinit()
1005 data->caps.rwup = true; in udc_rpi_pico_driver_preinit()
1006 data->caps.mps0 = UDC_MPS0_64; in udc_rpi_pico_driver_preinit()
1008 for (int i = 0; i < config->num_of_eps; i++) { in udc_rpi_pico_driver_preinit()
1009 config->ep_cfg_out[i].caps.out = 1; in udc_rpi_pico_driver_preinit()
1011 config->ep_cfg_out[i].caps.control = 1; in udc_rpi_pico_driver_preinit()
1012 config->ep_cfg_out[i].caps.mps = 64; in udc_rpi_pico_driver_preinit()
1014 config->ep_cfg_out[i].caps.bulk = 1; in udc_rpi_pico_driver_preinit()
1015 config->ep_cfg_out[i].caps.interrupt = 1; in udc_rpi_pico_driver_preinit()
1016 config->ep_cfg_out[i].caps.iso = 1; in udc_rpi_pico_driver_preinit()
1017 config->ep_cfg_out[i].caps.mps = mps; in udc_rpi_pico_driver_preinit()
1020 config->ep_cfg_out[i].addr = USB_EP_DIR_OUT | i; in udc_rpi_pico_driver_preinit()
1021 err = udc_register_ep(dev, &config->ep_cfg_out[i]); in udc_rpi_pico_driver_preinit()
1028 for (int i = 0; i < config->num_of_eps; i++) { in udc_rpi_pico_driver_preinit()
1029 config->ep_cfg_in[i].caps.in = 1; in udc_rpi_pico_driver_preinit()
1031 config->ep_cfg_in[i].caps.control = 1; in udc_rpi_pico_driver_preinit()
1032 config->ep_cfg_in[i].caps.mps = 64; in udc_rpi_pico_driver_preinit()
1034 config->ep_cfg_in[i].caps.bulk = 1; in udc_rpi_pico_driver_preinit()
1035 config->ep_cfg_in[i].caps.interrupt = 1; in udc_rpi_pico_driver_preinit()
1036 config->ep_cfg_in[i].caps.iso = 1; in udc_rpi_pico_driver_preinit()
1037 config->ep_cfg_in[i].caps.mps = mps; in udc_rpi_pico_driver_preinit()
1040 config->ep_cfg_in[i].addr = USB_EP_DIR_IN | i; in udc_rpi_pico_driver_preinit()
1041 err = udc_register_ep(dev, &config->ep_cfg_in[i]); in udc_rpi_pico_driver_preinit()
1048 config->make_thread(dev); in udc_rpi_pico_driver_preinit()
1087 usb_dpram->epx_data) \
1100 k_thread_create(&priv->thread_data, \
1108 k_thread_name_set(&priv->thread_data, dev->name); \