xref: /linux/sound/usb/mixer.h (revision 66354f18fe5fbb65f7b10a519654013d6df09f80)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f0b5e634SDaniel Mack #ifndef __USBMIXER_H
3f0b5e634SDaniel Mack #define __USBMIXER_H
4f0b5e634SDaniel Mack 
53360b84bSTakashi Iwai #include <sound/info.h>
63360b84bSTakashi Iwai 
7*66354f18SShuah Khan struct media_mixer_ctl;
8*66354f18SShuah Khan 
9f0b5e634SDaniel Mack struct usb_mixer_interface {
10f0b5e634SDaniel Mack 	struct snd_usb_audio *chip;
111faa5d07SDaniel Mack 	struct usb_host_interface *hostif;
12f0b5e634SDaniel Mack 	struct list_head list;
13f0b5e634SDaniel Mack 	unsigned int ignore_ctl_error;
14f0b5e634SDaniel Mack 	struct urb *urb;
15f0b5e634SDaniel Mack 	/* array[MAX_ID_ELEMS], indexed by unit id */
163360b84bSTakashi Iwai 	struct usb_mixer_elem_list **id_elems;
17f0b5e634SDaniel Mack 
1823caaf19SDaniel Mack 	/* the usb audio specification version this interface complies to */
1923caaf19SDaniel Mack 	int protocol;
2023caaf19SDaniel Mack 
21f0b5e634SDaniel Mack 	/* Sound Blaster remote control stuff */
22f0b5e634SDaniel Mack 	const struct rc_config *rc_cfg;
23f0b5e634SDaniel Mack 	u32 rc_code;
24f0b5e634SDaniel Mack 	wait_queue_head_t rc_waitq;
25f0b5e634SDaniel Mack 	struct urb *rc_urb;
26f0b5e634SDaniel Mack 	struct usb_ctrlrequest *rc_setup_packet;
27f0b5e634SDaniel Mack 	u8 rc_buffer[6];
28*66354f18SShuah Khan 	struct media_mixer_ctl *media_mixer_ctl;
29124751d5STakashi Iwai 
30124751d5STakashi Iwai 	bool disconnected;
31f0b5e634SDaniel Mack };
32f0b5e634SDaniel Mack 
339e38658fSDaniel Mack #define MAX_CHANNELS	16	/* max logical channels */
349e38658fSDaniel Mack 
359e38658fSDaniel Mack enum {
369e38658fSDaniel Mack 	USB_MIXER_BOOLEAN,
379e38658fSDaniel Mack 	USB_MIXER_INV_BOOLEAN,
389e38658fSDaniel Mack 	USB_MIXER_S8,
399e38658fSDaniel Mack 	USB_MIXER_U8,
409e38658fSDaniel Mack 	USB_MIXER_S16,
419e38658fSDaniel Mack 	USB_MIXER_U16,
42bc18e31cSJulian Scheel 	USB_MIXER_S32,
43bc18e31cSJulian Scheel 	USB_MIXER_U32,
449e38658fSDaniel Mack };
45f0b5e634SDaniel Mack 
463360b84bSTakashi Iwai typedef void (*usb_mixer_elem_dump_func_t)(struct snd_info_buffer *buffer,
473360b84bSTakashi Iwai 					 struct usb_mixer_elem_list *list);
483360b84bSTakashi Iwai typedef int (*usb_mixer_elem_resume_func_t)(struct usb_mixer_elem_list *elem);
493360b84bSTakashi Iwai 
503360b84bSTakashi Iwai struct usb_mixer_elem_list {
51f0b5e634SDaniel Mack 	struct usb_mixer_interface *mixer;
523360b84bSTakashi Iwai 	struct usb_mixer_elem_list *next_id_elem; /* list of controls with same id */
533360b84bSTakashi Iwai 	struct snd_kcontrol *kctl;
54f0b5e634SDaniel Mack 	unsigned int id;
553360b84bSTakashi Iwai 	usb_mixer_elem_dump_func_t dump;
563360b84bSTakashi Iwai 	usb_mixer_elem_resume_func_t resume;
573360b84bSTakashi Iwai };
583360b84bSTakashi Iwai 
598c558076STakashi Iwai /* iterate over mixer element list of the given unit id */
608c558076STakashi Iwai #define for_each_mixer_elem(list, mixer, id)	\
618c558076STakashi Iwai 	for ((list) = (mixer)->id_elems[id]; (list); (list) = (list)->next_id_elem)
628c558076STakashi Iwai #define mixer_elem_list_to_info(list) \
638c558076STakashi Iwai 	container_of(list, struct usb_mixer_elem_info, head)
648c558076STakashi Iwai 
653360b84bSTakashi Iwai struct usb_mixer_elem_info {
663360b84bSTakashi Iwai 	struct usb_mixer_elem_list head;
67f0b5e634SDaniel Mack 	unsigned int control;	/* CS or ICN (high byte) */
68f0b5e634SDaniel Mack 	unsigned int cmask; /* channel mask bitmap: 0 = master */
699f814105SEldad Zack 	unsigned int idx_off; /* Control index offset */
70a6a33259SDaniel Mack 	unsigned int ch_readonly;
71a6a33259SDaniel Mack 	unsigned int master_readonly;
72f0b5e634SDaniel Mack 	int channels;
73f0b5e634SDaniel Mack 	int val_type;
74f0b5e634SDaniel Mack 	int min, max, res;
75f0b5e634SDaniel Mack 	int dBmin, dBmax;
76f0b5e634SDaniel Mack 	int cached;
77f0b5e634SDaniel Mack 	int cache_val[MAX_CHANNELS];
78f0b5e634SDaniel Mack 	u8 initialized;
790f174b35STakashi Iwai 	u8 min_mute;
80f41d6049SChris J Arges 	void *private_data;
81f0b5e634SDaniel Mack };
82f0b5e634SDaniel Mack 
83f0b5e634SDaniel Mack int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
84f0b5e634SDaniel Mack 			 int ignore_error);
85a6cece9dSTakashi Iwai void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer);
86f0b5e634SDaniel Mack 
87f0b5e634SDaniel Mack void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
88f0b5e634SDaniel Mack 
89f0b5e634SDaniel Mack int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
90f0b5e634SDaniel Mack 				int request, int validx, int value_set);
91f0b5e634SDaniel Mack 
923360b84bSTakashi Iwai int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
93ef9d5970SDaniel Mack 			      struct snd_kcontrol *kctl);
94ef9d5970SDaniel Mack 
953360b84bSTakashi Iwai void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
963360b84bSTakashi Iwai 				 struct usb_mixer_interface *mixer,
973360b84bSTakashi Iwai 				 int unitid);
983360b84bSTakashi Iwai 
99285de9c0SFelix Homann int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
100285de9c0SFelix Homann 			  unsigned int size, unsigned int __user *_tlv);
101285de9c0SFelix Homann 
102400362f1STakashi Iwai #ifdef CONFIG_PM
103400362f1STakashi Iwai int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer);
104400362f1STakashi Iwai int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume);
105400362f1STakashi Iwai #endif
106400362f1STakashi Iwai 
107eef90451SChris J Arges int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
108eef90451SChris J Arges                              int index, int value);
109eef90451SChris J Arges 
110eef90451SChris J Arges int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
111eef90451SChris J Arges                              int channel, int index, int *value);
112eef90451SChris J Arges 
113eef90451SChris J Arges extern void snd_usb_mixer_elem_free(struct snd_kcontrol *kctl);
114eef90451SChris J Arges 
11500966dcdSTakashi Iwai extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
11600966dcdSTakashi Iwai 
117f0b5e634SDaniel Mack #endif /* __USBMIXER_H */
118