xref: /linux/sound/usb/mixer.h (revision 9e4d5c1be21f0c00e747e92186784f3298309b3e)
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 
766354f18SShuah Khan struct media_mixer_ctl;
866354f18SShuah 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];
2866354f18SShuah Khan 	struct media_mixer_ctl *media_mixer_ctl;
29124751d5STakashi Iwai 
30124751d5STakashi Iwai 	bool disconnected;
31*9e4d5c1bSGeoffrey D. Bennett 
32*9e4d5c1bSGeoffrey D. Bennett 	void *private_data;
33*9e4d5c1bSGeoffrey D. Bennett 	void (*private_free)(struct usb_mixer_interface *mixer);
34*9e4d5c1bSGeoffrey D. Bennett 	void (*private_suspend)(struct usb_mixer_interface *mixer);
35f0b5e634SDaniel Mack };
36f0b5e634SDaniel Mack 
379e38658fSDaniel Mack #define MAX_CHANNELS	16	/* max logical channels */
389e38658fSDaniel Mack 
399e38658fSDaniel Mack enum {
409e38658fSDaniel Mack 	USB_MIXER_BOOLEAN,
419e38658fSDaniel Mack 	USB_MIXER_INV_BOOLEAN,
429e38658fSDaniel Mack 	USB_MIXER_S8,
439e38658fSDaniel Mack 	USB_MIXER_U8,
449e38658fSDaniel Mack 	USB_MIXER_S16,
459e38658fSDaniel Mack 	USB_MIXER_U16,
46bc18e31cSJulian Scheel 	USB_MIXER_S32,
47bc18e31cSJulian Scheel 	USB_MIXER_U32,
489e38658fSDaniel Mack };
49f0b5e634SDaniel Mack 
503360b84bSTakashi Iwai typedef void (*usb_mixer_elem_dump_func_t)(struct snd_info_buffer *buffer,
513360b84bSTakashi Iwai 					 struct usb_mixer_elem_list *list);
523360b84bSTakashi Iwai typedef int (*usb_mixer_elem_resume_func_t)(struct usb_mixer_elem_list *elem);
533360b84bSTakashi Iwai 
543360b84bSTakashi Iwai struct usb_mixer_elem_list {
55f0b5e634SDaniel Mack 	struct usb_mixer_interface *mixer;
563360b84bSTakashi Iwai 	struct usb_mixer_elem_list *next_id_elem; /* list of controls with same id */
573360b84bSTakashi Iwai 	struct snd_kcontrol *kctl;
58f0b5e634SDaniel Mack 	unsigned int id;
593360b84bSTakashi Iwai 	usb_mixer_elem_dump_func_t dump;
603360b84bSTakashi Iwai 	usb_mixer_elem_resume_func_t resume;
613360b84bSTakashi Iwai };
623360b84bSTakashi Iwai 
638c558076STakashi Iwai /* iterate over mixer element list of the given unit id */
648c558076STakashi Iwai #define for_each_mixer_elem(list, mixer, id)	\
658c558076STakashi Iwai 	for ((list) = (mixer)->id_elems[id]; (list); (list) = (list)->next_id_elem)
668c558076STakashi Iwai #define mixer_elem_list_to_info(list) \
678c558076STakashi Iwai 	container_of(list, struct usb_mixer_elem_info, head)
688c558076STakashi Iwai 
693360b84bSTakashi Iwai struct usb_mixer_elem_info {
703360b84bSTakashi Iwai 	struct usb_mixer_elem_list head;
71f0b5e634SDaniel Mack 	unsigned int control;	/* CS or ICN (high byte) */
72f0b5e634SDaniel Mack 	unsigned int cmask; /* channel mask bitmap: 0 = master */
739f814105SEldad Zack 	unsigned int idx_off; /* Control index offset */
74a6a33259SDaniel Mack 	unsigned int ch_readonly;
75a6a33259SDaniel Mack 	unsigned int master_readonly;
76f0b5e634SDaniel Mack 	int channels;
77f0b5e634SDaniel Mack 	int val_type;
78f0b5e634SDaniel Mack 	int min, max, res;
79f0b5e634SDaniel Mack 	int dBmin, dBmax;
80f0b5e634SDaniel Mack 	int cached;
81f0b5e634SDaniel Mack 	int cache_val[MAX_CHANNELS];
82f0b5e634SDaniel Mack 	u8 initialized;
830f174b35STakashi Iwai 	u8 min_mute;
84f41d6049SChris J Arges 	void *private_data;
85f0b5e634SDaniel Mack };
86f0b5e634SDaniel Mack 
87f0b5e634SDaniel Mack int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
88f0b5e634SDaniel Mack 			 int ignore_error);
89a6cece9dSTakashi Iwai void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer);
90f0b5e634SDaniel Mack 
91f0b5e634SDaniel Mack void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
92f0b5e634SDaniel Mack 
93f0b5e634SDaniel Mack int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
94f0b5e634SDaniel Mack 				int request, int validx, int value_set);
95f0b5e634SDaniel Mack 
963360b84bSTakashi Iwai int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
97ef9d5970SDaniel Mack 			      struct snd_kcontrol *kctl);
98ef9d5970SDaniel Mack 
993360b84bSTakashi Iwai void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
1003360b84bSTakashi Iwai 				 struct usb_mixer_interface *mixer,
1013360b84bSTakashi Iwai 				 int unitid);
1023360b84bSTakashi Iwai 
103285de9c0SFelix Homann int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
104285de9c0SFelix Homann 			  unsigned int size, unsigned int __user *_tlv);
105285de9c0SFelix Homann 
106400362f1STakashi Iwai #ifdef CONFIG_PM
107400362f1STakashi Iwai int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer);
108400362f1STakashi Iwai int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume);
109400362f1STakashi Iwai #endif
110400362f1STakashi Iwai 
111eef90451SChris J Arges int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
112eef90451SChris J Arges                              int index, int value);
113eef90451SChris J Arges 
114eef90451SChris J Arges int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
115eef90451SChris J Arges                              int channel, int index, int *value);
116eef90451SChris J Arges 
117eef90451SChris J Arges extern void snd_usb_mixer_elem_free(struct snd_kcontrol *kctl);
118eef90451SChris J Arges 
11900966dcdSTakashi Iwai extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
12000966dcdSTakashi Iwai 
121f0b5e634SDaniel Mack #endif /* __USBMIXER_H */
122