1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __USBMIXER_H 3 #define __USBMIXER_H 4 5 #include <sound/info.h> 6 7 struct media_mixer_ctl; 8 9 struct usbmix_connector_map { 10 u8 id; 11 u8 delegated_id; 12 u8 control; 13 u8 channel; 14 }; 15 16 struct usb_mixer_interface { 17 struct snd_usb_audio *chip; 18 struct usb_host_interface *hostif; 19 struct list_head list; 20 unsigned int ignore_ctl_error; 21 struct mutex lock; /* lock for feature unit callbacks */ 22 /* UAC2 status interrupt endpoint; owned by mixer.c */ 23 struct urb *urb; 24 /* array[MAX_ID_ELEMS], indexed by unit id */ 25 struct usb_mixer_elem_list **id_elems; 26 27 /* the usb audio specification version this interface complies to */ 28 int protocol; 29 30 /* optional connector delegation map */ 31 const struct usbmix_connector_map *connector_map; 32 33 /* Sound Blaster remote control stuff */ 34 const struct rc_config *rc_cfg; 35 u32 rc_code; 36 wait_queue_head_t rc_waitq; 37 struct urb *rc_urb; 38 struct usb_ctrlrequest *rc_setup_packet; 39 u8 rc_buffer[6]; 40 struct media_mixer_ctl *media_mixer_ctl; 41 42 bool disconnected; 43 44 void *private_data; 45 void (*private_free)(struct usb_mixer_interface *mixer); 46 void (*private_suspend)(struct usb_mixer_interface *mixer); 47 int (*private_resume)(struct usb_mixer_interface *mixer); 48 }; 49 50 #define MAX_CHANNELS 64 /* max logical channels */ 51 52 enum { 53 USB_MIXER_BOOLEAN, 54 USB_MIXER_INV_BOOLEAN, 55 USB_MIXER_S8, 56 USB_MIXER_U8, 57 USB_MIXER_S16, 58 USB_MIXER_U16, 59 USB_MIXER_S32, 60 USB_MIXER_U32, 61 USB_MIXER_BESPOKEN, /* non-standard type */ 62 }; 63 64 typedef void (*usb_mixer_elem_dump_func_t)(struct snd_info_buffer *buffer, 65 struct usb_mixer_elem_list *list); 66 typedef int (*usb_mixer_elem_resume_func_t)(struct usb_mixer_elem_list *elem); 67 68 struct usb_mixer_elem_list { 69 struct usb_mixer_interface *mixer; 70 struct usb_mixer_elem_list *next_id_elem; /* list of controls with same id */ 71 struct snd_kcontrol *kctl; 72 unsigned int id; 73 bool is_std_info; 74 usb_mixer_elem_dump_func_t dump; 75 usb_mixer_elem_resume_func_t resume; 76 }; 77 78 /* iterate over mixer element list of the given unit id */ 79 #define for_each_mixer_elem(list, mixer, id) \ 80 for ((list) = (mixer)->id_elems[id]; (list); (list) = (list)->next_id_elem) 81 #define mixer_elem_list_to_info(list) \ 82 container_of(list, struct usb_mixer_elem_info, head) 83 84 struct usb_mixer_elem_info { 85 struct usb_mixer_elem_list head; 86 unsigned int control; /* CS or ICN (high byte) */ 87 u64 cmask; /* channel mask bitmap: 0 = master */ 88 unsigned int idx_off; /* Control index offset */ 89 unsigned int ch_readonly; 90 unsigned int master_readonly; 91 int channels; 92 int val_type; 93 int min, max, res; 94 int max_exposed; /* control API exposes the value in 0..max_exposed */ 95 int dBmin, dBmax; 96 DECLARE_BITMAP(cached, MAX_CHANNELS + 1); 97 int cache_val[MAX_CHANNELS]; 98 u8 initialized; 99 u8 min_mute; 100 u8 get_cur_broken; 101 u8 num_outputs; 102 bool v2_mixer; 103 void *private_data; 104 }; 105 106 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif); 107 void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer); 108 109 void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid); 110 111 int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 112 int request, int validx, int value_set); 113 114 int snd_usb_mixer_add_list(struct usb_mixer_elem_list *list, 115 struct snd_kcontrol *kctl, 116 bool is_std_info, 117 bool look_for_empty); 118 119 #define snd_usb_mixer_add_control(list, kctl) \ 120 snd_usb_mixer_add_list(list, kctl, true, true) 121 122 void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list, 123 struct usb_mixer_interface *mixer, 124 int unitid); 125 126 int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 127 unsigned int size, unsigned int __user *_tlv); 128 129 int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer); 130 int snd_usb_mixer_resume(struct usb_mixer_interface *mixer); 131 132 int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, 133 int index, int value); 134 135 int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval, 136 int channel, int index, int *value); 137 138 extern void snd_usb_mixer_elem_free(struct snd_kcontrol *kctl); 139 140 extern const struct snd_kcontrol_new *snd_usb_feature_unit_ctl; 141 142 #endif /* __USBMIXER_H */ 143