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

4  * SPDX-License-Identifier: Apache-2.0
80 const struct udc_mcux_config *config = dev->config; in udc_mcux_control()
81 const usb_device_controller_interface_struct_t *mcux_if = config->mcux_if; in udc_mcux_control()
85 status = mcux_if->deviceControl(priv->mcux_device.controllerHandle, in udc_mcux_control()
89 return -ENOMEM; in udc_mcux_control()
100 const struct udc_mcux_config *config = dev->config; in udc_mcux_ep_feed()
101 const usb_device_controller_interface_struct_t *mcux_if = config->mcux_if; in udc_mcux_ep_feed()
108 ep_status.endpointAddress = cfg->addr; in udc_mcux_ep_feed()
111 return -EACCES; /* stalled */ in udc_mcux_ep_feed()
115 if (!udc_ep_is_busy(dev, cfg->addr)) { in udc_mcux_ep_feed()
116 udc_ep_set_busy(dev, cfg->addr, true); in udc_mcux_ep_feed()
119 if (USB_EP_DIR_IS_OUT(cfg->addr)) { in udc_mcux_ep_feed()
122 status = mcux_if->deviceRecv(priv->mcux_device.controllerHandle, in udc_mcux_ep_feed()
123 cfg->addr, data, len); in udc_mcux_ep_feed()
125 len = buf->len; in udc_mcux_ep_feed()
126 data = buf->data; in udc_mcux_ep_feed()
127 status = mcux_if->deviceSend(priv->mcux_device.controllerHandle, in udc_mcux_ep_feed()
128 cfg->addr, data, len); in udc_mcux_ep_feed()
133 udc_ep_set_busy(dev, cfg->addr, false); in udc_mcux_ep_feed()
138 return -EBUSY; in udc_mcux_ep_feed()
141 return (status == kStatus_USB_Success ? 0 : -EIO); in udc_mcux_ep_feed()
150 feed_buf = udc_buf_peek(dev, cfg->addr); in udc_mcux_ep_try_feed()
154 return ((ret == -EBUSY || ret == -EACCES || ret == 0) ? 0 : -EIO); in udc_mcux_ep_try_feed()
161 * Allocate buffer and initiate a new control OUT transfer.
172 return -ENOMEM; in udc_mcux_ctrl_feed_dout()
175 k_fifo_put(&cfg->fifo, buf); in udc_mcux_ctrl_feed_dout()
197 return -EIO; in udc_mcux_handler_setup()
201 memcpy(buf->data, setup, 8); in udc_mcux_handler_setup()
204 if (setup->RequestType.type == USB_REQTYPE_TYPE_STANDARD && in udc_mcux_handler_setup()
205 setup->RequestType.direction == USB_REQTYPE_DIR_TO_DEVICE && in udc_mcux_handler_setup()
206 setup->bRequest == USB_SREQ_SET_ADDRESS && in udc_mcux_handler_setup()
207 setup->wLength == 0) { in udc_mcux_handler_setup()
209 &setup->wValue); in udc_mcux_handler_setup()
215 if (!buf->len) { in udc_mcux_handler_setup()
216 return -EIO; in udc_mcux_handler_setup()
220 /* Allocate and feed buffer for data OUT stage */ in udc_mcux_handler_setup()
221 LOG_DBG("s:%p|feed for -out-", buf); in udc_mcux_handler_setup()
223 if (err == -ENOMEM) { in udc_mcux_handler_setup()
266 len = MIN(buf->len, mcux_len); in udc_mcux_handler_ctrl_in()
267 buf->data += len; in udc_mcux_handler_ctrl_in()
268 buf->len -= len; in udc_mcux_handler_ctrl_in()
282 * control OUT buffer should be already fed. in udc_mcux_handler_ctrl_in()
297 len = MIN(buf->len, mcux_len); in udc_mcux_handler_non_ctrl_in()
298 buf->data += len; in udc_mcux_handler_non_ctrl_in()
299 buf->len -= len; in udc_mcux_handler_non_ctrl_in()
335 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in udc_mcux_handler_out()
336 return -ENOBUFS; in udc_mcux_handler_out()
348 /* return true - zlp is feed; false - no zlp */
352 const struct udc_mcux_config *config = dev->config; in udc_mcux_handler_zlt()
353 const usb_device_controller_interface_struct_t *mcux_if = config->mcux_if; in udc_mcux_handler_zlt()
357 if (mcux_len >= buf->len) { in udc_mcux_handler_zlt()
362 status = mcux_if->deviceRecv(priv->mcux_device.controllerHandle, in udc_mcux_handler_zlt()
365 udc_submit_event(dev, UDC_EVT_ERROR, -EIO); in udc_mcux_handler_zlt()
383 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in udc_mcux_handler_in()
384 return -ENOBUFS; in udc_mcux_handler_in()
398 udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); in udc_mcux_handler_in()
399 return -ENOBUFS; in udc_mcux_handler_in()
424 ev->dev = dev; in udc_mcux_event_submit()
425 ev->mcux_msg = *mcux_msg; in udc_mcux_event_submit()
426 k_fifo_put(&priv->fifo, ev); in udc_mcux_event_submit()
427 k_work_submit_to_queue(udc_get_work_q(), &priv->work); in udc_mcux_event_submit()
439 while ((ev = k_fifo_get(&priv->fifo, K_NO_WAIT)) != NULL) { in udc_mcux_work_handler()
440 mcux_msg = &ev->mcux_msg; in udc_mcux_work_handler()
442 if (mcux_msg->code == kUSB_DeviceNotifyBusReset) { in udc_mcux_work_handler()
445 udc_mcux_control(ev->dev, kUSB_DeviceControlSetDefaultStatus, NULL); in udc_mcux_work_handler()
446 cfg = udc_get_ep_cfg(ev->dev, USB_CONTROL_EP_OUT); in udc_mcux_work_handler()
447 if (cfg->stat.enabled) { in udc_mcux_work_handler()
448 udc_ep_disable_internal(ev->dev, USB_CONTROL_EP_OUT); in udc_mcux_work_handler()
450 cfg = udc_get_ep_cfg(ev->dev, USB_CONTROL_EP_IN); in udc_mcux_work_handler()
451 if (cfg->stat.enabled) { in udc_mcux_work_handler()
452 udc_ep_disable_internal(ev->dev, USB_CONTROL_EP_IN); in udc_mcux_work_handler()
454 if (udc_ep_enable_internal(ev->dev, USB_CONTROL_EP_OUT, in udc_mcux_work_handler()
460 if (udc_ep_enable_internal(ev->dev, USB_CONTROL_EP_IN, in udc_mcux_work_handler()
465 udc_submit_event(ev->dev, UDC_EVT_RESET, 0); in udc_mcux_work_handler()
467 ep = mcux_msg->code; in udc_mcux_work_handler()
469 if (mcux_msg->isSetup) { in udc_mcux_work_handler()
471 (struct usb_setup_packet *)mcux_msg->buffer; in udc_mcux_work_handler()
473 err = udc_mcux_handler_setup(ev->dev, setup); in udc_mcux_work_handler()
475 err = udc_mcux_handler_in(ev->dev, ep, mcux_msg->buffer, in udc_mcux_work_handler()
476 mcux_msg->length); in udc_mcux_work_handler()
478 err = udc_mcux_handler_out(ev->dev, ep, mcux_msg->buffer, in udc_mcux_work_handler()
479 mcux_msg->length); in udc_mcux_work_handler()
483 udc_submit_event(ev->dev, UDC_EVT_ERROR, err); in udc_mcux_work_handler()
504 mcux_notify = (usb_device_notification_t)mcux_msg->code; in USB_DeviceNotificationTrigger()
506 dev = priv->dev; in USB_DeviceNotificationTrigger()
513 udc_submit_event(dev, UDC_EVT_ERROR, -EIO); in USB_DeviceNotificationTrigger()
546 USB_DeviceLpcIp3511IsrFunction((void *)(&priv->mcux_device)); in udc_mcux_isr()
582 if (cfg->stat.halted) { in udc_mcux_ep_enqueue()
583 LOG_DBG("ep 0x%02x halted", cfg->addr); in udc_mcux_ep_enqueue()
595 cfg->stat.halted = false; in udc_mcux_ep_dequeue()
596 buf = udc_buf_get_all(dev, cfg->addr); in udc_mcux_ep_dequeue()
598 udc_submit_ep_event(dev, buf, -ECONNABORTED); in udc_mcux_ep_dequeue()
602 udc_ep_set_busy(dev, cfg->addr, false); in udc_mcux_ep_dequeue()
611 return udc_mcux_control(dev, kUSB_DeviceControlEndpointStall, &cfg->addr); in udc_mcux_ep_set_halt()
617 (void)udc_mcux_control(dev, kUSB_DeviceControlEndpointUnstall, &cfg->addr); in udc_mcux_ep_clear_halt()
627 LOG_DBG("Enable ep 0x%02x", cfg->addr); in udc_mcux_ep_enable()
630 ep_init.interval = cfg->interval; in udc_mcux_ep_enable()
631 ep_init.endpointAddress = cfg->addr; in udc_mcux_ep_enable()
633 ep_init.maxPacketSize = cfg->mps; in udc_mcux_ep_enable()
635 switch (cfg->attributes & USB_EP_TRANSFER_TYPE_MASK) { in udc_mcux_ep_enable()
649 return -EINVAL; in udc_mcux_ep_enable()
658 LOG_DBG("Disable ep 0x%02x", cfg->addr); in udc_mcux_ep_disable()
660 return udc_mcux_control(dev, kUSB_DeviceControlEndpointDeinit, &cfg->addr); in udc_mcux_ep_disable()
665 return -ENOTSUP; in udc_mcux_host_wakeup()
687 const struct udc_mcux_config *config = dev->config; in udc_mcux_init()
688 const usb_device_controller_interface_struct_t *mcux_if = config->mcux_if; in udc_mcux_init()
692 if (priv->controller_id == 0xFFu) { in udc_mcux_init()
693 return -ENOMEM; in udc_mcux_init()
697 if (config->phy_config != NULL) { in udc_mcux_init()
698 USB_EhciPhyInit(priv->controller_id, 0u, config->phy_config); in udc_mcux_init()
703 status = mcux_if->deviceInit(priv->controller_id, in udc_mcux_init()
704 &priv->mcux_device, &(priv->mcux_device.controllerHandle)); in udc_mcux_init()
706 return -ENOMEM; in udc_mcux_init()
710 config->irq_enable_func(dev); in udc_mcux_init()
712 LOG_DBG("Initialized USB controller %x", (uint32_t)config->base); in udc_mcux_init()
719 const struct udc_mcux_config *config = dev->config; in udc_mcux_shutdown()
720 const usb_device_controller_interface_struct_t *mcux_if = config->mcux_if; in udc_mcux_shutdown()
725 config->irq_disable_func(dev); in udc_mcux_shutdown()
727 /* De-init MCUX USB device driver. */ in udc_mcux_shutdown()
728 status = mcux_if->deviceDeinit(priv->mcux_device.controllerHandle); in udc_mcux_shutdown()
730 return -ENOMEM; in udc_mcux_shutdown()
752 priv->controller_id = 0xFFu; /* invalid value */ in udc_mcux_get_hal_driver_id()
755 if (ip3511_fs_base[i] == config->base) { in udc_mcux_get_hal_driver_id()
756 priv->controller_id = kUSB_ControllerLpcIp3511Fs0 + i; in udc_mcux_get_hal_driver_id()
763 if (priv->controller_id == 0xFF) { in udc_mcux_get_hal_driver_id()
765 if (ip3511_hs_base[i] == config->base) { in udc_mcux_get_hal_driver_id()
766 priv->controller_id = kUSB_ControllerLpcIp3511Hs0 + i; in udc_mcux_get_hal_driver_id()
776 const struct udc_mcux_config *config = dev->config; in udc_mcux_driver_preinit()
777 struct udc_data *data = dev->data; in udc_mcux_driver_preinit()
778 struct udc_mcux_data *priv = data->priv; in udc_mcux_driver_preinit()
782 if (priv->controller_id == 0xFFu) { in udc_mcux_driver_preinit()
783 return -ENOMEM; in udc_mcux_driver_preinit()
786 k_mutex_init(&data->mutex); in udc_mcux_driver_preinit()
787 k_fifo_init(&priv->fifo); in udc_mcux_driver_preinit()
788 k_work_init(&priv->work, udc_mcux_work_handler); in udc_mcux_driver_preinit()
790 for (int i = 0; i < config->num_of_eps; i++) { in udc_mcux_driver_preinit()
791 config->ep_cfg_out[i].caps.out = 1; in udc_mcux_driver_preinit()
793 config->ep_cfg_out[i].caps.control = 1; in udc_mcux_driver_preinit()
794 config->ep_cfg_out[i].caps.mps = 64; in udc_mcux_driver_preinit()
796 config->ep_cfg_out[i].caps.bulk = 1; in udc_mcux_driver_preinit()
797 config->ep_cfg_out[i].caps.interrupt = 1; in udc_mcux_driver_preinit()
798 config->ep_cfg_out[i].caps.iso = 1; in udc_mcux_driver_preinit()
799 config->ep_cfg_out[i].caps.mps = 1024; in udc_mcux_driver_preinit()
800 if ((priv->controller_id == kUSB_ControllerLpcIp3511Hs0) || in udc_mcux_driver_preinit()
801 (priv->controller_id == kUSB_ControllerLpcIp3511Hs1)) { in udc_mcux_driver_preinit()
802 config->ep_cfg_out[i].caps.high_bandwidth = 1; in udc_mcux_driver_preinit()
806 config->ep_cfg_out[i].addr = USB_EP_DIR_OUT | i; in udc_mcux_driver_preinit()
807 err = udc_register_ep(dev, &config->ep_cfg_out[i]); in udc_mcux_driver_preinit()
814 for (int i = 0; i < config->num_of_eps; i++) { in udc_mcux_driver_preinit()
815 config->ep_cfg_in[i].caps.in = 1; in udc_mcux_driver_preinit()
817 config->ep_cfg_in[i].caps.control = 1; in udc_mcux_driver_preinit()
818 config->ep_cfg_in[i].caps.mps = 64; in udc_mcux_driver_preinit()
820 config->ep_cfg_in[i].caps.bulk = 1; in udc_mcux_driver_preinit()
821 config->ep_cfg_in[i].caps.interrupt = 1; in udc_mcux_driver_preinit()
822 config->ep_cfg_in[i].caps.iso = 1; in udc_mcux_driver_preinit()
823 config->ep_cfg_in[i].caps.mps = 1024; in udc_mcux_driver_preinit()
824 if ((priv->controller_id == kUSB_ControllerLpcIp3511Hs0) || in udc_mcux_driver_preinit()
825 (priv->controller_id == kUSB_ControllerLpcIp3511Hs1)) { in udc_mcux_driver_preinit()
826 config->ep_cfg_in[i].caps.high_bandwidth = 1; in udc_mcux_driver_preinit()
830 config->ep_cfg_in[i].addr = USB_EP_DIR_IN | i; in udc_mcux_driver_preinit()
831 err = udc_register_ep(dev, &config->ep_cfg_in[i]); in udc_mcux_driver_preinit()
839 data->caps.rwup = false; in udc_mcux_driver_preinit()
840 data->caps.mps0 = USB_MCUX_MPS0; in udc_mcux_driver_preinit()
841 if ((priv->controller_id == kUSB_ControllerLpcIp3511Hs0) || in udc_mcux_driver_preinit()
842 (priv->controller_id == kUSB_ControllerLpcIp3511Hs1)) { in udc_mcux_driver_preinit()
843 data->caps.hs = true; in udc_mcux_driver_preinit()
845 priv->dev = dev; in udc_mcux_driver_preinit()
847 pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in udc_mcux_driver_preinit()