Lines Matching +full:iso +full:- +full:out +full:- +full:mps

4  * SPDX-License-Identifier: Apache-2.0
28 /* OUT transaction completed */
85 return -ENOMEM; in usbd_ctrl_feed_dout()
88 k_fifo_put(&cfg->fifo, buf); in usbd_ctrl_feed_dout()
90 udc_ambiq_rx(dev, cfg->addr, buf); in usbd_ctrl_feed_dout()
109 status = am_hal_usb_ep_xfer(priv->usb_handle, ep, NULL, 0); in udc_ambiq_tx()
111 status = am_hal_usb_ep_xfer(priv->usb_handle, ep, buf->data, buf->len); in udc_ambiq_tx()
117 return -EIO; in udc_ambiq_tx()
128 uint16_t rx_size = buf->size; in udc_ambiq_rx()
136 /* Make sure that OUT transaction size triggered doesn't exceed EP's MPS */ in udc_ambiq_rx()
137 if ((ep != USB_CONTROL_EP_OUT) && (cfg->mps < rx_size)) { in udc_ambiq_rx()
138 rx_size = cfg->mps; in udc_ambiq_rx()
141 status = am_hal_usb_ep_xfer(priv->usb_handle, ep, buf->data, rx_size); in udc_ambiq_rx()
145 return -EIO; in udc_ambiq_rx()
158 am_hal_usb_intr_usb_enable(priv->usb_handle, in udc_ambiq_evt_callback()
162 am_hal_usb_ep_init(priv->usb_handle, 0, 0, EP0_MPS); in udc_ambiq_evt_callback()
164 am_hal_usb_set_dev_speed(priv->usb_handle, priv->usb_speed); in udc_ambiq_evt_callback()
171 am_hal_usb_set_dev_state(priv->usb_handle, AM_HAL_USB_DEV_STATE_ACTIVE); in udc_ambiq_evt_callback()
181 am_hal_usb_set_dev_state(priv->usb_handle, AM_HAL_USB_DEV_STATE_SUSPENDED); in udc_ambiq_evt_callback()
197 * status stage for OUT data control transfer to be completed in udc_ambiq_ep0_setup_callback()
199 if (priv->ctrl_pending_in_ack) { in udc_ambiq_ep0_setup_callback()
200 priv->ctrl_pending_setup = true; in udc_ambiq_ep0_setup_callback()
201 memcpy(priv->ctrl_pending_setup_buffer, usb_setup, 8); in udc_ambiq_ep0_setup_callback()
209 priv->ctrl_setup_recv_at_status_in = udc_ctrl_stage_is_status_in(dev); in udc_ambiq_ep0_setup_callback()
210 memcpy(priv->setup, usb_setup, sizeof(struct usb_setup_packet)); in udc_ambiq_ep0_setup_callback()
229 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in udc_ambiq_ep_xfer_complete_callback()
243 am_hal_usb_dev_speed_e e_speed = am_hal_get_usb_dev_speed(priv->usb_handle); in udc_ambiq_device_speed()
257 .ep = ep_cfg->addr, in udc_ambiq_ep_enqueue()
261 LOG_DBG("%p enqueue %x %p", dev, ep_cfg->addr, buf); in udc_ambiq_ep_enqueue()
263 if (ep_cfg->addr == USB_CONTROL_EP_IN && buf->len == 0 && priv->ctrl_pending_in_ack) { in udc_ambiq_ep_enqueue()
264 priv->ctrl_pending_in_ack = false; in udc_ambiq_ep_enqueue()
269 if (!ep_cfg->stat.halted) { in udc_ambiq_ep_enqueue()
284 buf = udc_buf_get_all(dev, ep_cfg->addr); in udc_ambiq_ep_dequeue()
286 udc_submit_ep_event(dev, buf, -ECONNABORTED); in udc_ambiq_ep_dequeue()
289 udc_ep_set_busy(dev, ep_cfg->addr, false); in udc_ambiq_ep_dequeue()
290 am_hal_usb_ep_state_reset(priv->usb_handle, ep_cfg->addr); in udc_ambiq_ep_dequeue()
293 LOG_DBG("dequeue ep 0x%02x", ep_cfg->addr); in udc_ambiq_ep_dequeue()
302 LOG_DBG("Halt ep 0x%02x", ep_cfg->addr); in udc_ambiq_ep_set_halt()
304 am_hal_usb_ep_stall(priv->usb_handle, ep_cfg->addr); in udc_ambiq_ep_set_halt()
305 if (USB_EP_GET_IDX(ep_cfg->addr)) { in udc_ambiq_ep_set_halt()
306 ep_cfg->stat.halted = true; in udc_ambiq_ep_set_halt()
316 LOG_DBG("Clear halt ep 0x%02x", ep_cfg->addr); in udc_ambiq_ep_clear_halt()
318 am_hal_usb_ep_clear_stall(priv->usb_handle, ep_cfg->addr); in udc_ambiq_ep_clear_halt()
320 ep_cfg->stat.halted = false; in udc_ambiq_ep_clear_halt()
323 if (udc_buf_peek(dev, ep_cfg->addr)) { in udc_ambiq_ep_clear_halt()
325 .ep = ep_cfg->addr, in udc_ambiq_ep_clear_halt()
342 switch (ep_cfg->attributes) { in udc_ambiq_ep_enable()
356 return -EINVAL; in udc_ambiq_ep_enable()
359 status = am_hal_usb_ep_init(priv->usb_handle, ep_cfg->addr, endpoint_type, ep_cfg->mps); in udc_ambiq_ep_enable()
361 LOG_ERR("am_hal_usb_ep_init failed(0x%02x), %d", ep_cfg->addr, (int)status); in udc_ambiq_ep_enable()
362 return -EIO; in udc_ambiq_ep_enable()
365 LOG_DBG("Enable ep 0x%02x", ep_cfg->addr); in udc_ambiq_ep_enable()
375 am_hal_usb_ep_state_reset(priv->usb_handle, ep_cfg->addr); in udc_ambiq_ep_disable()
376 LOG_DBG("Disable ep 0x%02x", ep_cfg->addr); in udc_ambiq_ep_disable()
385 am_hal_usb_start_remote_wakeup(priv->usb_handle); in udc_ambiq_host_wakeup()
395 am_hal_usb_set_addr(priv->usb_handle, addr); in udc_ambiq_set_address()
396 am_hal_usb_set_dev_state(priv->usb_handle, AM_HAL_USB_DEV_STATE_ADDRESSED); in udc_ambiq_set_address()
420 return -EINVAL; in udc_ambiq_test_mode()
428 am_hal_usb_enter_test_mode(priv->usb_handle); in udc_ambiq_test_mode()
429 am_hal_usb_test_mode(priv->usb_handle, am_usb_test_mode); in udc_ambiq_test_mode()
439 am_hal_usb_attach(priv->usb_handle); in udc_ambiq_enable()
449 const struct udc_ambiq_config *cfg = dev->config; in udc_ambiq_disable()
453 cfg->irq_disable_func(dev); in udc_ambiq_disable()
457 am_hal_usb_detach(priv->usb_handle); in udc_ambiq_disable()
458 am_hal_usb_intr_usb_disable(priv->usb_handle, USB_CFG2_SOFE_Msk | USB_CFG2_ResumeE_Msk | in udc_ambiq_disable()
461 am_hal_usb_intr_usb_clear(priv->usb_handle); in udc_ambiq_disable()
462 for (unsigned int i = 0; i < cfg->num_endpoints; i++) { in udc_ambiq_disable()
463 am_hal_usb_ep_state_reset(priv->usb_handle, i); in udc_ambiq_disable()
464 am_hal_usb_ep_state_reset(priv->usb_handle, BIT(7) | i); in udc_ambiq_disable()
476 am_hal_usb_intr_status_get(priv->usb_handle, &int_status[0], &int_status[1], in udc_ambiq_usb_isr()
478 am_hal_usb_interrupt_service(priv->usb_handle, int_status[0], int_status[1], int_status[2]); in udc_ambiq_usb_isr()
484 const struct udc_ambiq_config *cfg = dev->config; in usb_power_rails_set()
487 if ((cfg->vddusb33_gpio.port == NULL) || (cfg->vddusb0p9_gpio.port == NULL)) { in usb_power_rails_set()
489 return -EINVAL; in usb_power_rails_set()
493 ret = gpio_pin_configure_dt(&cfg->vddusb33_gpio, GPIO_OUTPUT); in usb_power_rails_set()
498 ret = gpio_pin_configure_dt(&cfg->vddusb0p9_gpio, GPIO_OUTPUT); in usb_power_rails_set()
504 ret = gpio_pin_set_dt(&cfg->vddusb33_gpio, on); in usb_power_rails_set()
508 ret = gpio_pin_set_dt(&cfg->vddusb0p9_gpio, on); in usb_power_rails_set()
520 const struct udc_ambiq_config *cfg = dev->config; in udc_ambiq_init()
524 if (am_hal_usb_initialize(0, (void *)&priv->usb_handle) != AM_HAL_STATUS_SUCCESS) { in udc_ambiq_init()
525 return -EIO; in udc_ambiq_init()
529 cfg->callback_register_func(dev); in udc_ambiq_init()
531 am_hal_usb_power_control(priv->usb_handle, AM_HAL_SYSCTRL_WAKE, false); in udc_ambiq_init()
544 am_hal_usb_set_dev_speed(priv->usb_handle, priv->usb_speed); in udc_ambiq_init()
546 am_hal_usb_intr_usb_enable(priv->usb_handle, USB_INTRUSB_Reset_Msk); in udc_ambiq_init()
550 return -EIO; in udc_ambiq_init()
554 return -EIO; in udc_ambiq_init()
557 cfg->irq_enable_func(dev); in udc_ambiq_init()
565 const struct udc_ambiq_config *cfg = dev->config; in udc_ambiq_shutdown()
573 return -EIO; in udc_ambiq_shutdown()
577 return -EIO; in udc_ambiq_shutdown()
580 cfg->irq_disable_func(dev); in udc_ambiq_shutdown()
589 am_hal_usb_power_control(priv->usb_handle, AM_HAL_SYSCTRL_DEEPSLEEP, false); in udc_ambiq_shutdown()
591 am_hal_usb_deinitialize(priv->usb_handle); in udc_ambiq_shutdown()
592 priv->usb_handle = NULL; in udc_ambiq_shutdown()
619 net_buf_add_mem(buf, priv->setup, sizeof(priv->setup)); in ambiq_handle_evt_setup()
621 LOG_HEXDUMP_DBG(buf->data, buf->len, "setup"); in ambiq_handle_evt_setup()
627 /* Allocate and feed buffer for data OUT stage */ in ambiq_handle_evt_setup()
628 LOG_DBG("s:%p|feed for -out-", buf); in ambiq_handle_evt_setup()
630 priv->ctrl_pending_in_ack = true; in ambiq_handle_evt_setup()
631 if (err == -ENOMEM) { in ambiq_handle_evt_setup()
636 LOG_DBG("s:%p|feed for -in-status", buf); in ambiq_handle_evt_setup()
639 /* Submit event for no-data stage */ in ambiq_handle_evt_setup()
650 buf = udc_buf_get(dev, cfg->addr); in ambiq_handle_evt_dout()
657 udc_ep_set_busy(dev, cfg->addr, false); in ambiq_handle_evt_dout()
660 if (cfg->addr == USB_CONTROL_EP_OUT) { in ambiq_handle_evt_dout()
678 udc_ambiq_tx(dev, cfg->addr, NULL); in ambiq_handle_zlp_tx()
684 struct udc_data *data = dev->data; in ambiq_handle_evt_din()
689 udc_ep_set_busy(dev, cfg->addr, false); in ambiq_handle_evt_din()
691 buf = udc_buf_peek(dev, cfg->addr); in ambiq_handle_evt_din()
692 if (cfg->addr != USB_CONTROL_EP_IN) { in ambiq_handle_evt_din()
695 udc_ambiq_tx(dev, cfg->addr, NULL); in ambiq_handle_evt_din()
702 buf = udc_buf_get(dev, cfg->addr); in ambiq_handle_evt_din()
707 LOG_DBG("DataIn ep 0x%02x len %u", cfg->addr, buf->size); in ambiq_handle_evt_din()
710 if (cfg->addr == USB_CONTROL_EP_IN) { in ambiq_handle_evt_din()
712 if (data->caps.out_ack == 0) { in ambiq_handle_evt_din()
722 if (priv->ctrl_setup_recv_at_status_in && (buf->len == 0)) { in ambiq_handle_evt_din()
723 priv->ctrl_setup_recv_at_status_in = false; in ambiq_handle_evt_din()
727 priv->ctrl_setup_recv_at_status_in = false; in ambiq_handle_evt_din()
731 if (((data->caps.out_ack == false) && udc_ctrl_stage_is_status_out(dev)) || in ambiq_handle_evt_din()
732 ((data->caps.out_ack == true) && (data->stage == CTRL_PIPE_STAGE_SETUP))) { in ambiq_handle_evt_din()
735 * control OUT buffer should be already fed. in ambiq_handle_evt_din()
744 if (udc_ambiq_rx_status_in_completed && priv->ctrl_pending_setup) { in ambiq_handle_evt_din()
745 priv->ctrl_pending_setup = false; in ambiq_handle_evt_din()
746 udc_ambiq_ep0_setup_callback(dev, priv->ctrl_pending_setup_buffer); in ambiq_handle_evt_din()
757 buf = udc_buf_peek(dev, cfg->addr); in udc_event_xfer()
759 LOG_ERR("No buffer for ep 0x%02x", cfg->addr); in udc_event_xfer()
763 if (USB_EP_DIR_IS_IN(cfg->addr)) { in udc_event_xfer()
764 udc_ambiq_tx(dev, cfg->addr, buf); in udc_event_xfer()
766 udc_ambiq_rx(dev, cfg->addr, buf); in udc_event_xfer()
789 LOG_DBG("DOUT event ep 0x%02x", ep_cfg->addr); in ambiq_thread_handler()
810 const struct udc_ambiq_config *cfg = dev->config; in udc_ambiq_driver_init()
811 struct udc_data *data = dev->data; in udc_ambiq_driver_init()
815 if (cfg->speed_idx == 1) { in udc_ambiq_driver_init()
816 data->caps.hs = false; in udc_ambiq_driver_init()
817 priv->usb_speed = AM_HAL_USB_SPEED_FULL; in udc_ambiq_driver_init()
819 } else if ((cfg->speed_idx == 2)) { in udc_ambiq_driver_init()
820 data->caps.hs = true; in udc_ambiq_driver_init()
821 priv->usb_speed = AM_HAL_USB_SPEED_HIGH; in udc_ambiq_driver_init()
825 for (unsigned int i = 0; i < cfg->num_endpoints; i++) { in udc_ambiq_driver_init()
826 cfg->ep_cfg_out[i].caps.out = 1; in udc_ambiq_driver_init()
828 cfg->ep_cfg_out[i].caps.control = 1; in udc_ambiq_driver_init()
829 cfg->ep_cfg_out[i].caps.mps = EP0_MPS; in udc_ambiq_driver_init()
831 cfg->ep_cfg_out[i].caps.bulk = 1; in udc_ambiq_driver_init()
832 cfg->ep_cfg_out[i].caps.interrupt = 1; in udc_ambiq_driver_init()
833 cfg->ep_cfg_out[i].caps.iso = 1; in udc_ambiq_driver_init()
834 cfg->ep_cfg_out[i].caps.mps = ep_mps; in udc_ambiq_driver_init()
837 cfg->ep_cfg_out[i].addr = USB_EP_DIR_OUT | i; in udc_ambiq_driver_init()
838 err = udc_register_ep(dev, &cfg->ep_cfg_out[i]); in udc_ambiq_driver_init()
845 for (unsigned int i = 0; i < cfg->num_endpoints; i++) { in udc_ambiq_driver_init()
846 cfg->ep_cfg_in[i].caps.in = 1; in udc_ambiq_driver_init()
848 cfg->ep_cfg_in[i].caps.control = 1; in udc_ambiq_driver_init()
849 cfg->ep_cfg_in[i].caps.mps = EP0_MPS; in udc_ambiq_driver_init()
851 cfg->ep_cfg_in[i].caps.bulk = 1; in udc_ambiq_driver_init()
852 cfg->ep_cfg_in[i].caps.interrupt = 1; in udc_ambiq_driver_init()
853 cfg->ep_cfg_in[i].caps.iso = 1; in udc_ambiq_driver_init()
854 cfg->ep_cfg_in[i].caps.mps = ep_mps; in udc_ambiq_driver_init()
857 cfg->ep_cfg_in[i].addr = USB_EP_DIR_IN | i; in udc_ambiq_driver_init()
858 err = udc_register_ep(dev, &cfg->ep_cfg_in[i]); in udc_ambiq_driver_init()
864 data->caps.addr_before_status = true; in udc_ambiq_driver_init()
865 data->caps.rwup = true; in udc_ambiq_driver_init()
866 data->caps.out_ack = true; in udc_ambiq_driver_init()
867 data->caps.mps0 = UDC_MPS0_64; in udc_ambiq_driver_init()
869 cfg->make_thread(dev); in udc_ambiq_driver_init()
895 * A UDC driver should always be implemented as a multi-instance
922 am_hal_usb_register_dev_evt_callback(priv->usb_handle, \
924 am_hal_usb_register_ep0_setup_received_callback(priv->usb_handle, \
927 priv->usb_handle, udc_ambiq_ep_xfer_complete_callback_##n); \
938 k_thread_create(&priv->thread_data, udc_ambiq_stack_##n, \
943 k_thread_name_set(&priv->thread_data, dev->name); \