Lines Matching +full:positive +full:- +full:cs
4 * SPDX-License-Identifier: Apache-2.0
190 return (fu->bLength - FU_FIXED_ELEMS_SIZE)/sizeof(uint16_t); in get_num_of_channels()
199 return sys_get_le16((uint8_t *)&fu->bmaControls[0]); in get_controls()
210 ((uint8_t *)fu + fu->bLength); in get_fu_dir()
213 if (ot->wTerminalType == USB_AUDIO_USB_STREAMING) { in get_fu_dir()
234 header->bLength + in fix_fu_descriptors()
239 (void)memcpy(&fu->bmaControls[i], in fix_fu_descriptors()
240 &fu->bmaControls[0], in fix_fu_descriptors()
244 if (header->bInCollection == 2) { in fix_fu_descriptors()
246 fu->bLength + in fix_fu_descriptors()
250 (void)memcpy(&fu->bmaControls[i], in fix_fu_descriptors()
251 &fu->bmaControls[0], in fix_fu_descriptors()
269 ((uint8_t *)audio_dev_data->desc_hdr + in get_feature_unit()
270 audio_dev_data->desc_hdr->bLength + in get_feature_unit()
273 if (fu->bUnitID == fu_id) { in get_feature_unit()
279 ((uint8_t *)fu + fu->bLength + in get_feature_unit()
297 ep_addr = cfg->endpoint[0].ep_addr; in audio_dc_sof()
298 if ((ep_addr & USB_EP_DIR_MASK) && (dev_data->tx_enable)) { in audio_dc_sof()
299 if (dev_data->ops && dev_data->ops->data_request_cb) { in audio_dc_sof()
300 dev_data->ops->data_request_cb( in audio_dc_sof()
301 dev_data->common.dev); in audio_dc_sof()
314 ((char *)iface - sizeof(struct usb_association_descriptor)); in audio_interface_config()
315 iad->bFirstInterface = bInterfaceNumber; in audio_interface_config()
319 iface->bInterfaceNumber = bInterfaceNumber; in audio_interface_config()
321 ((uint8_t *)iface + iface->bLength); in audio_interface_config()
322 header->baInterfaceNr[0] = bInterfaceNumber + 1; in audio_interface_config()
326 ((uint8_t *)header + header->wTotalLength); in audio_interface_config()
327 iface->bInterfaceNumber = bInterfaceNumber + 1; in audio_interface_config()
331 ((uint8_t *)iface + iface->bLength); in audio_interface_config()
332 iface->bInterfaceNumber = bInterfaceNumber + 1; in audio_interface_config()
334 if (header->bInCollection == 2) { in audio_interface_config()
335 header->baInterfaceNr[1] = bInterfaceNumber + 2; in audio_interface_config()
339 iface->bInterfaceNumber = bInterfaceNumber + 2; in audio_interface_config()
344 iface->bInterfaceNumber = bInterfaceNumber + 2; in audio_interface_config()
400 header = audio_dev_data->desc_hdr; in is_entity_valid()
402 header->bLength + in is_entity_valid()
404 if (fu->bUnitID == entity->id) { in is_entity_valid()
405 entity->subtype = fu->bDescriptorSubtype; in is_entity_valid()
409 if (header->bInCollection == 2) { in is_entity_valid()
411 fu->bLength + in is_entity_valid()
414 if (fu->bUnitID == entity->id) { in is_entity_valid()
415 entity->subtype = fu->bDescriptorSubtype; in is_entity_valid()
471 header = audio_dev_data->desc_hdr; in is_interface_valid()
474 for (size_t i = 0; i < header->bInCollection; i++) { in is_interface_valid()
475 desc_iface = header->baInterfaceNr[i]; in is_interface_valid()
533 uint8_t ch = (setup->wValue) & 0xFF; in handle_fu_mute_req()
534 uint8_t ch_cnt = audio_dev_data->ch_cnt[device]; in handle_fu_mute_req()
535 uint8_t *controls = audio_dev_data->controls[device]; in handle_fu_mute_req()
541 return -EINVAL; in handle_fu_mute_req()
544 if (setup->bRequest == USB_AUDIO_SET_CUR) { in handle_fu_mute_req()
545 evt->val = control_val; in handle_fu_mute_req()
546 evt->val_len = *len; in handle_fu_mute_req()
551 if (setup->bRequest == USB_AUDIO_GET_CUR) { in handle_fu_mute_req()
558 return -EINVAL; in handle_fu_mute_req()
566 uint8_t ch = (setup->wValue) & 0xFF; in handle_fu_volume_req()
567 uint8_t ch_cnt = audio_dev_data->ch_cnt[device]; in handle_fu_volume_req()
568 uint8_t *controls = audio_dev_data->controls[device]; in handle_fu_volume_req()
577 return -EINVAL; in handle_fu_volume_req()
579 if (setup->bRequest == USB_AUDIO_SET_CUR) { in handle_fu_volume_req()
581 if (!IN_RANGE(target_vol, audio_dev_data->volumes.volume_min, in handle_fu_volume_req()
582 audio_dev_data->volumes.volume_max)) { in handle_fu_volume_req()
584 return -EINVAL; in handle_fu_volume_req()
586 if (target_vol % audio_dev_data->volumes.volume_res != 0) { in handle_fu_volume_req()
588 audio_dev_data->volumes.volume_res); in handle_fu_volume_req()
592 evt->val = control_val; in handle_fu_volume_req()
593 evt->val_len = *len; in handle_fu_volume_req()
597 if (setup->bRequest == USB_AUDIO_GET_CUR) { in handle_fu_volume_req()
602 } else if (setup->bRequest == USB_AUDIO_GET_MIN) { in handle_fu_volume_req()
603 *len = sizeof(audio_dev_data->volumes.volume_min); in handle_fu_volume_req()
604 temp_vol = sys_cpu_to_le16(audio_dev_data->volumes.volume_min); in handle_fu_volume_req()
607 } else if (setup->bRequest == USB_AUDIO_GET_MAX) { in handle_fu_volume_req()
608 *len = sizeof(audio_dev_data->volumes.volume_max); in handle_fu_volume_req()
609 temp_vol = sys_cpu_to_le16(audio_dev_data->volumes.volume_max); in handle_fu_volume_req()
612 } else if (setup->bRequest == USB_AUDIO_GET_RES) { in handle_fu_volume_req()
613 *len = sizeof(audio_dev_data->volumes.volume_res); in handle_fu_volume_req()
614 temp_vol = sys_cpu_to_le16(audio_dev_data->volumes.volume_res); in handle_fu_volume_req()
620 return -EINVAL; in handle_fu_volume_req()
643 enum usb_audio_fucs cs; in handle_feature_unit_req() local
650 fu_id = ((pSetup->wIndex) >> 8) & 0xFF; in handle_feature_unit_req()
652 ch = (pSetup->wValue) & 0xFF; in handle_feature_unit_req()
653 cs = ((pSetup->wValue) >> 8) & 0xFF; in handle_feature_unit_req()
654 ch_cnt = audio_dev_data->ch_cnt[device]; in handle_feature_unit_req()
656 LOG_DBG("CS: %d, CN: %d, len: %d", cs, ch, *len); in handle_feature_unit_req()
659 if (!(BIT(cs) & (get_controls(fu) << 1))) { in handle_feature_unit_req()
661 return -EINVAL; in handle_feature_unit_req()
664 return -EINVAL; in handle_feature_unit_req()
667 switch (cs) { in handle_feature_unit_req()
677 return -ENOTSUP; in handle_feature_unit_req()
685 if (audio_dev_data->ops && audio_dev_data->ops->feature_update_cb) { in handle_feature_unit_req()
687 pSetup->bRequest == USB_AUDIO_SET_CUR) { in handle_feature_unit_req()
688 evt.cs = cs; in handle_feature_unit_req()
691 audio_dev_data->ops->feature_update_cb( in handle_feature_unit_req()
692 audio_dev_data->common.dev, &evt); in handle_feature_unit_req()
720 uint8_t entity_id = ((pSetup->wIndex) >> 8) & 0xFF; in handle_interface_req()
727 * uint8_t interface = (pSetup->wIndex) & 0xFF; in handle_interface_req()
738 return -ENODEV; in handle_interface_req()
747 return -ENODEV; in handle_interface_req()
765 * @return 0 on success, positive value if request is intended to be handled
776 uint8_t iface = (pSetup->wIndex) & 0xFF; in audio_custom_handler()
778 if (pSetup->RequestType.recipient != USB_REQTYPE_RECIPIENT_INTERFACE || in audio_custom_handler()
780 return -EINVAL; in audio_custom_handler()
785 return -EINVAL; in audio_custom_handler()
792 header = audio_dev_data->desc_hdr; in audio_custom_handler()
796 header->wTotalLength + in audio_custom_handler()
799 if (if_desc->bInterfaceNumber == iface) { in audio_custom_handler()
818 if (pSetup->bRequest == USB_SREQ_SET_INTERFACE) { in audio_custom_handler()
819 if (ep_desc->bEndpointAddress & USB_EP_DIR_MASK) { in audio_custom_handler()
820 audio_dev_data->tx_enable = pSetup->wValue; in audio_custom_handler()
822 audio_dev_data->rx_enable = pSetup->wValue; in audio_custom_handler()
826 return -EINVAL; in audio_custom_handler()
842 pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, in audio_class_handle_req()
843 pSetup->wIndex, pSetup->wLength); in audio_class_handle_req()
845 switch (pSetup->RequestType.recipient) { in audio_class_handle_req()
850 return -EINVAL; in audio_class_handle_req()
856 LOG_DBG("Init Audio Device: dev %p (%s)", dev, dev->name); in usb_audio_device_init()
868 audio_dev_data = dev_data->dev->data; in audio_write_cb()
877 if (audio_dev_data->ops && audio_dev_data->ops->data_written_cb) { in audio_write_cb()
878 audio_dev_data->ops->data_written_cb(dev_data->dev, in audio_write_cb()
889 struct usb_audio_dev_data *audio_dev_data = dev->data; in usb_audio_send()
890 struct usb_cfg_data *cfg = (void *)dev->config; in usb_audio_send()
892 uint8_t ep = cfg->endpoint[0].ep_addr; in usb_audio_send()
896 return -EINVAL; in usb_audio_send()
899 if (!audio_dev_data->tx_enable) { in usb_audio_send()
900 LOG_DBG("sending dropped -> Host chose passive interface"); in usb_audio_send()
901 return -EAGAIN; in usb_audio_send()
904 if (len > buffer->size) { in usb_audio_send()
906 return -EINVAL; in usb_audio_send()
912 return usb_transfer(ep, buffer->data, len, USB_TRANS_WRITE | USB_TRANS_NO_ZLP, in usb_audio_send()
918 struct usb_audio_dev_data *audio_dev_data = dev->data; in usb_audio_get_in_frame_size()
920 return audio_dev_data->in_frame_size; in usb_audio_get_in_frame_size()
945 if (!audio_dev_data->rx_enable) { in audio_receive_cb()
952 if (audio_dev_data->ops && audio_dev_data->ops->data_received_cb) { in audio_receive_cb()
953 buffer = net_buf_alloc(audio_dev_data->pool, K_NO_WAIT); in audio_receive_cb()
959 ret = usb_read(ep, buffer->data, buffer->size, &ret_bytes); in audio_receive_cb()
971 audio_dev_data->ops->data_received_cb(common->dev, in audio_receive_cb()
980 struct usb_audio_dev_data *audio_dev_data = dev->data; in usb_audio_register()
981 const struct usb_cfg_data *cfg = dev->config; in usb_audio_register()
983 cfg->interface_descriptor; in usb_audio_register()
988 audio_dev_data->ops = ops; in usb_audio_register()
989 audio_dev_data->common.dev = dev; in usb_audio_register()
990 audio_dev_data->rx_enable = false; in usb_audio_register()
991 audio_dev_data->tx_enable = false; in usb_audio_register()
992 audio_dev_data->desc_hdr = header; in usb_audio_register()
994 sys_slist_append(&usb_audio_data_devlist, &audio_dev_data->common.node); in usb_audio_register()
997 dev, audio_dev_data, dev->config, in usb_audio_register()