xref: /openbmc/linux/sound/pci/hda/hda_local.h (revision dda415d41882449f841f88d829dd65b6ee1c374c)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Universal Interface for Intel High Definition Audio Codec
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Local helper functions
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *  This program is free software; you can redistribute it and/or modify it
91da177e4SLinus Torvalds  *  under the terms of the GNU General Public License as published by the Free
101da177e4SLinus Torvalds  *  Software Foundation; either version 2 of the License, or (at your option)
111da177e4SLinus Torvalds  *  any later version.
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  *  This program is distributed in the hope that it will be useful, but WITHOUT
141da177e4SLinus Torvalds  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
151da177e4SLinus Torvalds  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
161da177e4SLinus Torvalds  *  more details.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  *  You should have received a copy of the GNU General Public License along with
191da177e4SLinus Torvalds  *  this program; if not, write to the Free Software Foundation, Inc., 59
201da177e4SLinus Torvalds  *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
211da177e4SLinus Torvalds  */
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #ifndef __SOUND_HDA_LOCAL_H
241da177e4SLinus Torvalds #define __SOUND_HDA_LOCAL_H
251da177e4SLinus Torvalds 
269c96fa59STakashi Iwai /* We abuse kcontrol_new.subdev field to pass the NID corresponding to
279c96fa59STakashi Iwai  * the given new control.  If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
289c96fa59STakashi Iwai  * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
299c96fa59STakashi Iwai  *
309c96fa59STakashi Iwai  * Note that the subdevice field is cleared again before the real registration
319c96fa59STakashi Iwai  * in snd_hda_ctl_add(), so that this value won't appear in the outside.
329c96fa59STakashi Iwai  */
339c96fa59STakashi Iwai #define HDA_SUBDEV_NID_FLAG	(1U << 31)
349e3fd871SJaroslav Kysela #define HDA_SUBDEV_AMP_FLAG	(1U << 30)
359c96fa59STakashi Iwai 
361da177e4SLinus Torvalds /*
371da177e4SLinus Torvalds  * for mixer controls
381da177e4SLinus Torvalds  */
3929fdbec2STakashi Iwai #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs)		\
4029fdbec2STakashi Iwai 	((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
41de8c85f7SClemens Ladisch #define HDA_AMP_VAL_MIN_MUTE (1<<29)
42d01ce99fSTakashi Iwai #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
4329fdbec2STakashi Iwai 	HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
44985be54bSTakashi Iwai /* mono volume with index (index=0,1,...) (channel=1,2) */
45de8c85f7SClemens Ladisch #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, dir, flags) \
461da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx,  \
475e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
48302e9c5aSJaroslav Kysela 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
49302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
50302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
511da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_volume_info, \
521da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_volume_get, \
531da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_volume_put, \
547cf0a953STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_amp_tlv },		\
55de8c85f7SClemens Ladisch 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, dir) | flags }
56985be54bSTakashi Iwai /* stereo volume with index */
571da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
58de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction, 0)
59985be54bSTakashi Iwai /* mono volume */
601da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
61de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction, 0)
62985be54bSTakashi Iwai /* stereo volume */
631da177e4SLinus Torvalds #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
641da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
65de8c85f7SClemens Ladisch /* stereo volume with min=mute */
66de8c85f7SClemens Ladisch #define HDA_CODEC_VOLUME_MIN_MUTE(xname, nid, xindex, direction) \
67de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, 3, xindex, direction, \
68de8c85f7SClemens Ladisch 				  HDA_AMP_VAL_MIN_MUTE)
69985be54bSTakashi Iwai /* mono mute switch with index (index=0,1,...) (channel=1,2) */
701da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
711da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
725e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
731da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_switch_info, \
741da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_switch_get, \
751da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_switch_put, \
761da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
77985be54bSTakashi Iwai /* stereo mute switch with index */
781da177e4SLinus Torvalds #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
791da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
80985be54bSTakashi Iwai /* mono mute switch */
811da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
821da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
83985be54bSTakashi Iwai /* stereo mute switch */
841da177e4SLinus Torvalds #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
851da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
8667d634c0STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
87123c07aeSJaroslav Kysela /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
88123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
89123c07aeSJaroslav Kysela 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
905e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
91123c07aeSJaroslav Kysela 	  .info = snd_hda_mixer_amp_switch_info, \
920401e854STakashi Iwai 	  .get = snd_hda_mixer_amp_switch_get_beep, \
93123c07aeSJaroslav Kysela 	  .put = snd_hda_mixer_amp_switch_put_beep, \
94123c07aeSJaroslav Kysela 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
9567d634c0STakashi Iwai #else
9667d634c0STakashi Iwai /* no digital beep - just the standard one */
9767d634c0STakashi Iwai #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
9867d634c0STakashi Iwai 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
9967d634c0STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_BEEP */
100123c07aeSJaroslav Kysela /* special beep mono mute switch */
101123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
102123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
103123c07aeSJaroslav Kysela /* special beep stereo mute switch */
104123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
105123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
1061da177e4SLinus Torvalds 
10785dd662fSJaroslav Kysela extern const char *snd_hda_pcm_type_name[];
10885dd662fSJaroslav Kysela 
109d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
110d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
111d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
112d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
113d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
114d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
115d01ce99fSTakashi Iwai int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
116d01ce99fSTakashi Iwai 			  unsigned int size, unsigned int __user *tlv);
117d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
118d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
119d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
120d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
121d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
122d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
12367d634c0STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
1240401e854STakashi Iwai int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
1250401e854STakashi Iwai 				      struct snd_ctl_elem_value *ucontrol);
126123c07aeSJaroslav Kysela int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
127123c07aeSJaroslav Kysela 				      struct snd_ctl_elem_value *ucontrol);
12867d634c0STakashi Iwai #endif
129834be88dSTakashi Iwai /* lowlevel accessor with caching; use carefully */
130834be88dSTakashi Iwai int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
131834be88dSTakashi Iwai 			   int direction, int index);
132834be88dSTakashi Iwai int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
133834be88dSTakashi Iwai 			     int direction, int idx, int mask, int val);
13447fd830aSTakashi Iwai int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
13547fd830aSTakashi Iwai 			     int dir, int idx, int mask, int val);
1362a43952aSTakashi Iwai #ifdef CONFIG_PM
137b3ac5636STakashi Iwai void snd_hda_codec_resume_amp(struct hda_codec *codec);
13882beb8fdSTakashi Iwai #endif
1391da177e4SLinus Torvalds 
1402134ea4fSTakashi Iwai void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1412134ea4fSTakashi Iwai 			     unsigned int *tlv);
1422134ea4fSTakashi Iwai struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1432134ea4fSTakashi Iwai 					    const char *name);
14418478e8bSTakashi Iwai int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1459322ca54STakashi Iwai 			  unsigned int *tlv, const char * const *slaves,
14629e5853dSTakashi Iwai 			  const char *suffix, bool init_slave_vol,
14729e5853dSTakashi Iwai 			  struct snd_kcontrol **ctl_ret);
14818478e8bSTakashi Iwai #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \
14929e5853dSTakashi Iwai 	__snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL)
150a65d629cSTakashi Iwai int snd_hda_codec_reset(struct hda_codec *codec);
1512134ea4fSTakashi Iwai 
152d2f344b5STakashi Iwai enum {
153d2f344b5STakashi Iwai 	HDA_VMUTE_OFF,
154d2f344b5STakashi Iwai 	HDA_VMUTE_ON,
155d2f344b5STakashi Iwai 	HDA_VMUTE_FOLLOW_MASTER,
156d2f344b5STakashi Iwai };
157d2f344b5STakashi Iwai 
158d2f344b5STakashi Iwai struct hda_vmaster_mute_hook {
159d2f344b5STakashi Iwai 	/* below two fields must be filled by the caller of
160d2f344b5STakashi Iwai 	 * snd_hda_add_vmaster_hook() beforehand
161d2f344b5STakashi Iwai 	 */
162d2f344b5STakashi Iwai 	struct snd_kcontrol *sw_kctl;
163d2f344b5STakashi Iwai 	void (*hook)(void *, int);
164d2f344b5STakashi Iwai 	/* below are initialized automatically */
165d2f344b5STakashi Iwai 	unsigned int mute_mode; /* HDA_VMUTE_XXX */
166d2f344b5STakashi Iwai 	struct hda_codec *codec;
167d2f344b5STakashi Iwai };
168d2f344b5STakashi Iwai 
169d2f344b5STakashi Iwai int snd_hda_add_vmaster_hook(struct hda_codec *codec,
170f29735cbSTakashi Iwai 			     struct hda_vmaster_mute_hook *hook,
171f29735cbSTakashi Iwai 			     bool expose_enum_ctl);
172d2f344b5STakashi Iwai void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
173d2f344b5STakashi Iwai 
17447fd830aSTakashi Iwai /* amp value bits */
17547fd830aSTakashi Iwai #define HDA_AMP_MUTE	0x80
17647fd830aSTakashi Iwai #define HDA_AMP_UNMUTE	0x00
17747fd830aSTakashi Iwai #define HDA_AMP_VOLMASK	0x7f
17847fd830aSTakashi Iwai 
179985be54bSTakashi Iwai /* mono switch binding multiple inputs */
180985be54bSTakashi Iwai #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
181985be54bSTakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
182985be54bSTakashi Iwai 	  .info = snd_hda_mixer_amp_switch_info, \
183985be54bSTakashi Iwai 	  .get = snd_hda_mixer_bind_switch_get, \
184985be54bSTakashi Iwai 	  .put = snd_hda_mixer_bind_switch_put, \
185985be54bSTakashi Iwai 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
186985be54bSTakashi Iwai 
187985be54bSTakashi Iwai /* stereo switch binding multiple inputs */
188d01ce99fSTakashi Iwai #define HDA_BIND_MUTE(xname,nid,indices,dir) \
189d01ce99fSTakashi Iwai 	HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
190985be54bSTakashi Iwai 
191d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
192d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
193d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
194d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
195985be54bSTakashi Iwai 
196532d5381STakashi Iwai /* more generic bound controls */
197532d5381STakashi Iwai struct hda_ctl_ops {
198532d5381STakashi Iwai 	snd_kcontrol_info_t *info;
199532d5381STakashi Iwai 	snd_kcontrol_get_t *get;
200532d5381STakashi Iwai 	snd_kcontrol_put_t *put;
201532d5381STakashi Iwai 	snd_kcontrol_tlv_rw_t *tlv;
202532d5381STakashi Iwai };
203532d5381STakashi Iwai 
204532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_vol;	/* for bind-volume with TLV */
205532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_sw;	/* for bind-switch */
206532d5381STakashi Iwai 
207532d5381STakashi Iwai struct hda_bind_ctls {
208532d5381STakashi Iwai 	struct hda_ctl_ops *ops;
2095d9b6c07SHannes Eder 	unsigned long values[];
210532d5381STakashi Iwai };
211532d5381STakashi Iwai 
212532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
213532d5381STakashi Iwai 				 struct snd_ctl_elem_info *uinfo);
214532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
215532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
216532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
217532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
218532d5381STakashi Iwai int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
219532d5381STakashi Iwai 			   unsigned int size, unsigned int __user *tlv);
220532d5381STakashi Iwai 
221532d5381STakashi Iwai #define HDA_BIND_VOL(xname, bindrec) \
222532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
223532d5381STakashi Iwai 	  .name = xname, \
224532d5381STakashi Iwai 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
225532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
226532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,\
227532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
228532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
229532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
230532d5381STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_bind_tlv },\
231532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
232532d5381STakashi Iwai #define HDA_BIND_SW(xname, bindrec) \
233532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
234532d5381STakashi Iwai 	  .name = xname, \
235532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
236532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
237532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
238532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
239532d5381STakashi Iwai 
240532d5381STakashi Iwai /*
241532d5381STakashi Iwai  * SPDIF I/O
242532d5381STakashi Iwai  */
243dcda5806STakashi Iwai int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
24474b654c9SStephen Warren 				hda_nid_t associated_nid,
245dcda5806STakashi Iwai 				hda_nid_t cvt_nid, int type);
246dcda5806STakashi Iwai #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
247dcda5806STakashi Iwai 	snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
2481da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds /*
2511da177e4SLinus Torvalds  * input MUX helper
2521da177e4SLinus Torvalds  */
25354d17403STakashi Iwai #define HDA_MAX_NUM_INPUTS	16
2541da177e4SLinus Torvalds struct hda_input_mux_item {
255b5786e85STakashi Iwai 	char label[32];
2561da177e4SLinus Torvalds 	unsigned int index;
2571da177e4SLinus Torvalds };
2581da177e4SLinus Torvalds struct hda_input_mux {
2591da177e4SLinus Torvalds 	unsigned int num_items;
2601da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
2611da177e4SLinus Torvalds };
2621da177e4SLinus Torvalds 
263d01ce99fSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux,
264d01ce99fSTakashi Iwai 			   struct snd_ctl_elem_info *uinfo);
265d01ce99fSTakashi Iwai int snd_hda_input_mux_put(struct hda_codec *codec,
266d01ce99fSTakashi Iwai 			  const struct hda_input_mux *imux,
267c8b6bf9bSTakashi Iwai 			  struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
2681da177e4SLinus Torvalds 			  unsigned int *cur_val);
269128bc4baSTakashi Iwai int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
270128bc4baSTakashi Iwai 			  int index, int *type_index_ret);
2711da177e4SLinus Torvalds 
272d2a6d7dcSTakashi Iwai /*
273d2a6d7dcSTakashi Iwai  * Channel mode helper
274d2a6d7dcSTakashi Iwai  */
275d2a6d7dcSTakashi Iwai struct hda_channel_mode {
276d2a6d7dcSTakashi Iwai 	int channels;
277d2a6d7dcSTakashi Iwai 	const struct hda_verb *sequence;
278d2a6d7dcSTakashi Iwai };
279d2a6d7dcSTakashi Iwai 
280d01ce99fSTakashi Iwai int snd_hda_ch_mode_info(struct hda_codec *codec,
281d01ce99fSTakashi Iwai 			 struct snd_ctl_elem_info *uinfo,
282d01ce99fSTakashi Iwai 			 const struct hda_channel_mode *chmode,
283d01ce99fSTakashi Iwai 			 int num_chmodes);
284d01ce99fSTakashi Iwai int snd_hda_ch_mode_get(struct hda_codec *codec,
285d01ce99fSTakashi Iwai 			struct snd_ctl_elem_value *ucontrol,
286d01ce99fSTakashi Iwai 			const struct hda_channel_mode *chmode,
287d01ce99fSTakashi Iwai 			int num_chmodes,
288d2a6d7dcSTakashi Iwai 			int max_channels);
289d01ce99fSTakashi Iwai int snd_hda_ch_mode_put(struct hda_codec *codec,
290d01ce99fSTakashi Iwai 			struct snd_ctl_elem_value *ucontrol,
291d01ce99fSTakashi Iwai 			const struct hda_channel_mode *chmode,
292d01ce99fSTakashi Iwai 			int num_chmodes,
293d2a6d7dcSTakashi Iwai 			int *max_channelsp);
294d2a6d7dcSTakashi Iwai 
2951da177e4SLinus Torvalds /*
2961da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
2971da177e4SLinus Torvalds  */
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
3001da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
3011da177e4SLinus Torvalds 
302a06dbfc2STakashi Iwai #define HDA_MAX_OUTS	5
303a06dbfc2STakashi Iwai 
3041da177e4SLinus Torvalds struct hda_multi_out {
3051da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
306dda14410STakashi Iwai 	const hda_nid_t *dac_nids;	/* DAC list */
3071da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
308a06dbfc2STakashi Iwai 	hda_nid_t hp_out_nid[HDA_MAX_OUTS];	/* DACs for multiple HPs */
309a06dbfc2STakashi Iwai 	hda_nid_t extra_out_nid[HDA_MAX_OUTS];	/* other (e.g. speaker) DACs */
3101da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
311dda14410STakashi Iwai 	const hda_nid_t *slave_dig_outs;
3121da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
3131da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
314d29240ceSTakashi Iwai 	int no_share_stream;	/* don't share a stream with multiple pins */
3159a08160bSTakashi Iwai 	int share_spdif;	/* share SPDIF pin */
3169a08160bSTakashi Iwai 	/* PCM information for both analog and SPDIF DACs */
3179a08160bSTakashi Iwai 	unsigned int analog_rates;
3189a08160bSTakashi Iwai 	unsigned int analog_maxbps;
3199a08160bSTakashi Iwai 	u64 analog_formats;
3209a08160bSTakashi Iwai 	unsigned int spdif_rates;
3219a08160bSTakashi Iwai 	unsigned int spdif_maxbps;
3229a08160bSTakashi Iwai 	u64 spdif_formats;
3231da177e4SLinus Torvalds };
3241da177e4SLinus Torvalds 
3259a08160bSTakashi Iwai int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
3269a08160bSTakashi Iwai 				  struct hda_multi_out *mout);
327d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_open(struct hda_codec *codec,
328d01ce99fSTakashi Iwai 			       struct hda_multi_out *mout);
329d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_close(struct hda_codec *codec,
330d01ce99fSTakashi Iwai 				struct hda_multi_out *mout);
3316b97eb45STakashi Iwai int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3326b97eb45STakashi Iwai 				  struct hda_multi_out *mout,
3336b97eb45STakashi Iwai 				  unsigned int stream_tag,
3346b97eb45STakashi Iwai 				  unsigned int format,
3356b97eb45STakashi Iwai 				  struct snd_pcm_substream *substream);
3369411e21cSTakashi Iwai int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3379411e21cSTakashi Iwai 				  struct hda_multi_out *mout);
338d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_open(struct hda_codec *codec,
339d01ce99fSTakashi Iwai 				  struct hda_multi_out *mout,
3409a08160bSTakashi Iwai 				  struct snd_pcm_substream *substream,
3419a08160bSTakashi Iwai 				  struct hda_pcm_stream *hinfo);
342d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
343d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout,
3441da177e4SLinus Torvalds 				     unsigned int stream_tag,
3451da177e4SLinus Torvalds 				     unsigned int format,
346c8b6bf9bSTakashi Iwai 				     struct snd_pcm_substream *substream);
347d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
348d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout);
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds /*
3511da177e4SLinus Torvalds  * generic codec parser
3521da177e4SLinus Torvalds  */
35335a1e0ccSTakashi Iwai #ifdef CONFIG_SND_HDA_GENERIC
3541da177e4SLinus Torvalds int snd_hda_parse_generic_codec(struct hda_codec *codec);
35535a1e0ccSTakashi Iwai #else
35635a1e0ccSTakashi Iwai static inline int snd_hda_parse_generic_codec(struct hda_codec *codec)
35735a1e0ccSTakashi Iwai {
35835a1e0ccSTakashi Iwai 	return -ENODEV;
35935a1e0ccSTakashi Iwai }
36035a1e0ccSTakashi Iwai #endif
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds /*
3631da177e4SLinus Torvalds  * generic proc interface
3641da177e4SLinus Torvalds  */
3651da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
3661da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
3671da177e4SLinus Torvalds #else
3681da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
3691da177e4SLinus Torvalds #endif
3701da177e4SLinus Torvalds 
371d39b4352SWu Fengguang #define SND_PRINT_BITS_ADVISED_BUFSIZE	16
372d39b4352SWu Fengguang void snd_print_pcm_bits(int pcm, char *buf, int buflen);
373d39b4352SWu Fengguang 
3741da177e4SLinus Torvalds /*
3751da177e4SLinus Torvalds  * Misc
3761da177e4SLinus Torvalds  */
377f5fcc13cSTakashi Iwai int snd_hda_check_board_config(struct hda_codec *codec, int num_configs,
378ea734963STakashi Iwai 			       const char * const *modelnames,
379f5fcc13cSTakashi Iwai 			       const struct snd_pci_quirk *pci_list);
3802eda3445SMauro Carvalho Chehab int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
381ea734963STakashi Iwai                                int num_configs, const char * const *models,
3822eda3445SMauro Carvalho Chehab                                const struct snd_pci_quirk *tbl);
383d01ce99fSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec,
384031024eeSTakashi Iwai 			 const struct snd_kcontrol_new *knew);
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds /*
3871da177e4SLinus Torvalds  * unsolicited event handler
3881da177e4SLinus Torvalds  */
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds #define HDA_UNSOL_QUEUE_SIZE	64
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds struct hda_bus_unsolicited {
3931da177e4SLinus Torvalds 	/* ring buffer */
3941da177e4SLinus Torvalds 	u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
3951da177e4SLinus Torvalds 	unsigned int rp, wp;
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	/* workqueue */
3981da177e4SLinus Torvalds 	struct work_struct work;
399c4028958SDavid Howells 	struct hda_bus *bus;
4001da177e4SLinus Torvalds };
4011da177e4SLinus Torvalds 
402128bc4baSTakashi Iwai /* helper macros to retrieve pin default-config values */
403d01ce99fSTakashi Iwai #define get_defcfg_connect(cfg) \
404d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
405d01ce99fSTakashi Iwai #define get_defcfg_association(cfg) \
406d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
407d01ce99fSTakashi Iwai #define get_defcfg_location(cfg) \
408d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
409d01ce99fSTakashi Iwai #define get_defcfg_sequence(cfg) \
410d01ce99fSTakashi Iwai 	(cfg & AC_DEFCFG_SEQUENCE)
411d01ce99fSTakashi Iwai #define get_defcfg_device(cfg) \
412d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
41308a1f5ebSTakashi Iwai #define get_defcfg_misc(cfg) \
41408a1f5ebSTakashi Iwai 	((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
415e9edcee0STakashi Iwai 
4168d88bc3dSTakashi Iwai /* amp values */
4178d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))
4188d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))
4198d88bc3dSTakashi Iwai #define AMP_OUT_MUTE		0xb080
4208d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE		0xb000
4218d88bc3dSTakashi Iwai #define AMP_OUT_ZERO		0xb000
4228d88bc3dSTakashi Iwai /* pinctl values */
42335e8901eSRobin H. Johnson #define PIN_IN			(AC_PINCTL_IN_EN)
42435e8901eSRobin H. Johnson #define PIN_VREFHIZ		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
42535e8901eSRobin H. Johnson #define PIN_VREF50		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
42635e8901eSRobin H. Johnson #define PIN_VREFGRD		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
42735e8901eSRobin H. Johnson #define PIN_VREF80		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
42835e8901eSRobin H. Johnson #define PIN_VREF100		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
42935e8901eSRobin H. Johnson #define PIN_OUT			(AC_PINCTL_OUT_EN)
43035e8901eSRobin H. Johnson #define PIN_HP			(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
43135e8901eSRobin H. Johnson #define PIN_HP_AMP		(AC_PINCTL_HP_EN)
4328d88bc3dSTakashi Iwai 
4334740860bSTakashi Iwai unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
434cdd03cedSTakashi Iwai int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
435cdd03cedSTakashi Iwai 			 unsigned int val, bool cached);
436cdd03cedSTakashi Iwai 
437cdd03cedSTakashi Iwai /**
438cdd03cedSTakashi Iwai  * _snd_hda_set_pin_ctl - Set a pin-control value safely
439cdd03cedSTakashi Iwai  * @codec: the codec instance
440cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
441cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
442cdd03cedSTakashi Iwai  *
443cdd03cedSTakashi Iwai  * This function sets the pin-control value to the given pin, but
444cdd03cedSTakashi Iwai  * filters out the invalid pin-control bits when the pin has no such
445cdd03cedSTakashi Iwai  * capabilities.  For example, when PIN_HP is passed but the pin has no
446cdd03cedSTakashi Iwai  * HP-drive capability, the HP bit is omitted.
447cdd03cedSTakashi Iwai  *
448cdd03cedSTakashi Iwai  * The function doesn't check the input VREF capability bits, though.
4494740860bSTakashi Iwai  * Use snd_hda_get_default_vref() to guess the right value.
450cdd03cedSTakashi Iwai  * Also, this function is only for analog pins, not for HDMI pins.
451cdd03cedSTakashi Iwai  */
452cdd03cedSTakashi Iwai static inline int
453cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
454cdd03cedSTakashi Iwai {
455cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, false);
456cdd03cedSTakashi Iwai }
457cdd03cedSTakashi Iwai 
458cdd03cedSTakashi Iwai /**
459cdd03cedSTakashi Iwai  * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
460cdd03cedSTakashi Iwai  * @codec: the codec instance
461cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
462cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
463cdd03cedSTakashi Iwai  *
464cdd03cedSTakashi Iwai  * Just like snd_hda_set_pin_ctl() but write to cache as well.
465cdd03cedSTakashi Iwai  */
466cdd03cedSTakashi Iwai static inline int
467cdd03cedSTakashi Iwai snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
468cdd03cedSTakashi Iwai 			  unsigned int val)
469cdd03cedSTakashi Iwai {
470cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, true);
471cdd03cedSTakashi Iwai }
472cdd03cedSTakashi Iwai 
47354d17403STakashi Iwai /*
47454d17403STakashi Iwai  * get widget capabilities
47554d17403STakashi Iwai  */
47654d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
47754d17403STakashi Iwai {
47854d17403STakashi Iwai 	if (nid < codec->start_nid ||
47954d17403STakashi Iwai 	    nid >= codec->start_nid + codec->num_nodes)
480dca008f3STakashi Iwai 		return 0;
48154d17403STakashi Iwai 	return codec->wcaps[nid - codec->start_nid];
48254d17403STakashi Iwai }
48354d17403STakashi Iwai 
484a22d543aSTakashi Iwai /* get the widget type from widget capability bits */
4853a90274dSTakashi Iwai static inline int get_wcaps_type(unsigned int wcaps)
4863a90274dSTakashi Iwai {
4873a90274dSTakashi Iwai 	if (!wcaps)
4883a90274dSTakashi Iwai 		return -1; /* invalid type */
4893a90274dSTakashi Iwai 	return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4903a90274dSTakashi Iwai }
491a22d543aSTakashi Iwai 
492fd72d008SWu Fengguang static inline unsigned int get_wcaps_channels(u32 wcaps)
493fd72d008SWu Fengguang {
494fd72d008SWu Fengguang 	unsigned int chans;
495fd72d008SWu Fengguang 
496fd72d008SWu Fengguang 	chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
497fd72d008SWu Fengguang 	chans = ((chans << 1) | 1) + 1;
498fd72d008SWu Fengguang 
499fd72d008SWu Fengguang 	return chans;
500fd72d008SWu Fengguang }
501fd72d008SWu Fengguang 
50209a99959SMatthew Ranostay u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
503897cc188STakashi Iwai int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
504897cc188STakashi Iwai 			      unsigned int caps);
5051327a32bSTakashi Iwai u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
506f57c2565STakashi Iwai int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
507f57c2565STakashi Iwai 			      unsigned int caps);
50803697e2aSTakashi Iwai 
5099e3fd871SJaroslav Kysela /* flags for hda_nid_item */
5109e3fd871SJaroslav Kysela #define HDA_NID_ITEM_AMP	(1<<0)
5119e3fd871SJaroslav Kysela 
5123911a4c1SJaroslav Kysela struct hda_nid_item {
5133911a4c1SJaroslav Kysela 	struct snd_kcontrol *kctl;
5145b0cb1d8SJaroslav Kysela 	unsigned int index;
5153911a4c1SJaroslav Kysela 	hda_nid_t nid;
5169e3fd871SJaroslav Kysela 	unsigned short flags;
5173911a4c1SJaroslav Kysela };
5183911a4c1SJaroslav Kysela 
5193911a4c1SJaroslav Kysela int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
5203911a4c1SJaroslav Kysela 		    struct snd_kcontrol *kctl);
5215b0cb1d8SJaroslav Kysela int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
5225b0cb1d8SJaroslav Kysela 		    unsigned int index, hda_nid_t nid);
523d13bd412STakashi Iwai void snd_hda_ctls_clear(struct hda_codec *codec);
524d13bd412STakashi Iwai 
5252807314dSTakashi Iwai /*
5262807314dSTakashi Iwai  * hwdep interface
5272807314dSTakashi Iwai  */
528d7ffba19STakashi Iwai #ifdef CONFIG_SND_HDA_HWDEP
5292807314dSTakashi Iwai int snd_hda_create_hwdep(struct hda_codec *codec);
530d7ffba19STakashi Iwai #else
531d7ffba19STakashi Iwai static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
532d7ffba19STakashi Iwai #endif
5332807314dSTakashi Iwai 
53483012a7cSTakashi Iwai #if defined(CONFIG_PM) && defined(CONFIG_SND_HDA_HWDEP)
535a2f6309eSTakashi Iwai int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
536a2f6309eSTakashi Iwai #else
537a2f6309eSTakashi Iwai static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
538a2f6309eSTakashi Iwai {
539a2f6309eSTakashi Iwai 	return 0;
540a2f6309eSTakashi Iwai }
541a2f6309eSTakashi Iwai #endif
542a2f6309eSTakashi Iwai 
543e7ee058cSTakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
544e7ee058cSTakashi Iwai int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
545e7ee058cSTakashi Iwai #else
546e7ee058cSTakashi Iwai static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
547e7ee058cSTakashi Iwai {
548e7ee058cSTakashi Iwai 	return 0;
549e7ee058cSTakashi Iwai }
550e7ee058cSTakashi Iwai #endif
551e7ee058cSTakashi Iwai 
55243b62713STakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
55343b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
55443b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
55543b62713STakashi Iwai #else
55643b62713STakashi Iwai static inline
55743b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
55843b62713STakashi Iwai {
55943b62713STakashi Iwai 	return NULL;
56043b62713STakashi Iwai }
56143b62713STakashi Iwai 
56243b62713STakashi Iwai static inline
56343b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
56443b62713STakashi Iwai {
56543b62713STakashi Iwai 	return -ENOENT;
56643b62713STakashi Iwai }
56743b62713STakashi Iwai #endif
56843b62713STakashi Iwai 
569cb53c626STakashi Iwai /*
570cb53c626STakashi Iwai  * power-management
571cb53c626STakashi Iwai  */
572cb53c626STakashi Iwai 
573cb53c626STakashi Iwai void snd_hda_schedule_power_save(struct hda_codec *codec);
574cb53c626STakashi Iwai 
575cb53c626STakashi Iwai struct hda_amp_list {
576cb53c626STakashi Iwai 	hda_nid_t nid;
577cb53c626STakashi Iwai 	unsigned char dir;
578cb53c626STakashi Iwai 	unsigned char idx;
579cb53c626STakashi Iwai };
580cb53c626STakashi Iwai 
581cb53c626STakashi Iwai struct hda_loopback_check {
582031024eeSTakashi Iwai 	const struct hda_amp_list *amplist;
583cb53c626STakashi Iwai 	int power_on;
584cb53c626STakashi Iwai };
585cb53c626STakashi Iwai 
586cb53c626STakashi Iwai int snd_hda_check_amp_list_power(struct hda_codec *codec,
587cb53c626STakashi Iwai 				 struct hda_loopback_check *check,
588cb53c626STakashi Iwai 				 hda_nid_t nid);
589cb53c626STakashi Iwai 
59089385035SMatthew Ranostay /*
59189385035SMatthew Ranostay  * AMP control callbacks
59289385035SMatthew Ranostay  */
59389385035SMatthew Ranostay /* retrieve parameters from private_value */
5943911a4c1SJaroslav Kysela #define get_amp_nid_(pv)	((pv) & 0xffff)
5953911a4c1SJaroslav Kysela #define get_amp_nid(kc)		get_amp_nid_((kc)->private_value)
59689385035SMatthew Ranostay #define get_amp_channels(kc)	(((kc)->private_value >> 16) & 0x3)
597527e4d73STakashi Iwai #define get_amp_direction_(pv)	(((pv) >> 18) & 0x1)
598527e4d73STakashi Iwai #define get_amp_direction(kc)	get_amp_direction_((kc)->private_value)
59989385035SMatthew Ranostay #define get_amp_index(kc)	(((kc)->private_value >> 19) & 0xf)
60029fdbec2STakashi Iwai #define get_amp_offset(kc)	(((kc)->private_value >> 23) & 0x3f)
601de8c85f7SClemens Ladisch #define get_amp_min_mute(kc)	(((kc)->private_value >> 29) & 0x1)
60289385035SMatthew Ranostay 
6037f4a9f43SWu Fengguang /*
604*dda415d4STakashi Iwai  * enum control helper
605*dda415d4STakashi Iwai  */
606*dda415d4STakashi Iwai int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
607*dda415d4STakashi Iwai 			     struct snd_ctl_elem_info *uinfo,
608*dda415d4STakashi Iwai 			     int num_entries, const char * const *texts);
609*dda415d4STakashi Iwai #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
610*dda415d4STakashi Iwai 	snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
611*dda415d4STakashi Iwai 
612*dda415d4STakashi Iwai /*
6137f4a9f43SWu Fengguang  * CEA Short Audio Descriptor data
6147f4a9f43SWu Fengguang  */
6157f4a9f43SWu Fengguang struct cea_sad {
6167f4a9f43SWu Fengguang 	int	channels;
6177f4a9f43SWu Fengguang 	int	format;		/* (format == 0) indicates invalid SAD */
6187f4a9f43SWu Fengguang 	int	rates;
6197f4a9f43SWu Fengguang 	int	sample_bits;	/* for LPCM */
6207f4a9f43SWu Fengguang 	int	max_bitrate;	/* for AC3...ATRAC */
6217f4a9f43SWu Fengguang 	int	profile;	/* for WMAPRO */
6227f4a9f43SWu Fengguang };
6237f4a9f43SWu Fengguang 
6247f4a9f43SWu Fengguang #define ELD_FIXED_BYTES	20
62514bc52b8SPierre-Louis Bossart #define ELD_MAX_SIZE    256
6267f4a9f43SWu Fengguang #define ELD_MAX_MNL	16
6277f4a9f43SWu Fengguang #define ELD_MAX_SAD	16
6287f4a9f43SWu Fengguang 
6297f4a9f43SWu Fengguang /*
6307f4a9f43SWu Fengguang  * ELD: EDID Like Data
6317f4a9f43SWu Fengguang  */
6325b87ebb7SWu Fengguang struct hdmi_eld {
63323ccc2bdSWu Fengguang 	bool	monitor_present;
63423ccc2bdSWu Fengguang 	bool	eld_valid;
6357f4a9f43SWu Fengguang 	int	eld_size;
6367f4a9f43SWu Fengguang 	int	baseline_len;
63723ccc2bdSWu Fengguang 	int	eld_ver;
6387f4a9f43SWu Fengguang 	int	cea_edid_ver;
6397f4a9f43SWu Fengguang 	char	monitor_name[ELD_MAX_MNL + 1];
6407f4a9f43SWu Fengguang 	int	manufacture_id;
6417f4a9f43SWu Fengguang 	int	product_id;
6427f4a9f43SWu Fengguang 	u64	port_id;
6437f4a9f43SWu Fengguang 	int	support_hdcp;
6447f4a9f43SWu Fengguang 	int	support_ai;
6457f4a9f43SWu Fengguang 	int	conn_type;
6467f4a9f43SWu Fengguang 	int	aud_synch_delay;
6477f4a9f43SWu Fengguang 	int	spk_alloc;
6487f4a9f43SWu Fengguang 	int	sad_count;
6497f4a9f43SWu Fengguang 	struct cea_sad sad[ELD_MAX_SAD];
650b95d68b8SWu Fengguang 	/*
651b95d68b8SWu Fengguang 	 * all fields above eld_buffer will be cleared before updating ELD
652b95d68b8SWu Fengguang 	 */
65314bc52b8SPierre-Louis Bossart 	char    eld_buffer[ELD_MAX_SIZE];
654f208dba9STakashi Iwai #ifdef CONFIG_PROC_FS
655f208dba9STakashi Iwai 	struct snd_info_entry *proc_entry;
656f208dba9STakashi Iwai #endif
6577f4a9f43SWu Fengguang };
6587f4a9f43SWu Fengguang 
6597f4a9f43SWu Fengguang int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
6605b87ebb7SWu Fengguang int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
6615b87ebb7SWu Fengguang void snd_hdmi_show_eld(struct hdmi_eld *eld);
6622def8172SStephen Warren void snd_hdmi_eld_update_pcm_info(struct hdmi_eld *eld,
6632def8172SStephen Warren 			      struct hda_pcm_stream *hinfo);
6647f4a9f43SWu Fengguang 
6655f1e71b1SWu Fengguang #ifdef CONFIG_PROC_FS
66654a25f87SWu Fengguang int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
66754a25f87SWu Fengguang 			 int index);
668f208dba9STakashi Iwai void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
6695f1e71b1SWu Fengguang #else
6700623536cSTakashi Iwai static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
67154a25f87SWu Fengguang 				       struct hdmi_eld *eld,
67254a25f87SWu Fengguang 				       int index)
6735f1e71b1SWu Fengguang {
6745f1e71b1SWu Fengguang 	return 0;
6755f1e71b1SWu Fengguang }
676f208dba9STakashi Iwai static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
677f208dba9STakashi Iwai 					 struct hdmi_eld *eld)
678f208dba9STakashi Iwai {
679f208dba9STakashi Iwai }
6805f1e71b1SWu Fengguang #endif
6815f1e71b1SWu Fengguang 
682903b21d8SWu Fengguang #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
683903b21d8SWu Fengguang void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
684903b21d8SWu Fengguang 
6851da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
686