xref: /openbmc/linux/sound/pci/hda/hda_local.h (revision cd6a65036f0eac4ad83dc371bb458e9e6ba6e306)
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 */
130eeecd9d1STakashi Iwai #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
131eeecd9d1STakashi Iwai 	snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
132eeecd9d1STakashi Iwai #define snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val) \
133eeecd9d1STakashi Iwai 	snd_hdac_regmap_update_amp(&(codec)->core, nid, ch, dir, idx, mask, 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);
136280e57d5STakashi Iwai int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
137280e57d5STakashi Iwai 			   int direction, int idx, int mask, int val);
138280e57d5STakashi Iwai int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
139280e57d5STakashi Iwai 				  int dir, int idx, int mask, int val);
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);
151c4c2533fSTakashi Iwai void snd_hda_codec_register(struct hda_codec *codec);
1529a6246ffSTakashi Iwai void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
1532134ea4fSTakashi Iwai 
154d2f344b5STakashi Iwai enum {
155d2f344b5STakashi Iwai 	HDA_VMUTE_OFF,
156d2f344b5STakashi Iwai 	HDA_VMUTE_ON,
157d2f344b5STakashi Iwai 	HDA_VMUTE_FOLLOW_MASTER,
158d2f344b5STakashi Iwai };
159d2f344b5STakashi Iwai 
160d2f344b5STakashi Iwai struct hda_vmaster_mute_hook {
161d2f344b5STakashi Iwai 	/* below two fields must be filled by the caller of
162d2f344b5STakashi Iwai 	 * snd_hda_add_vmaster_hook() beforehand
163d2f344b5STakashi Iwai 	 */
164d2f344b5STakashi Iwai 	struct snd_kcontrol *sw_kctl;
165d2f344b5STakashi Iwai 	void (*hook)(void *, int);
166d2f344b5STakashi Iwai 	/* below are initialized automatically */
167d2f344b5STakashi Iwai 	unsigned int mute_mode; /* HDA_VMUTE_XXX */
168d2f344b5STakashi Iwai 	struct hda_codec *codec;
169d2f344b5STakashi Iwai };
170d2f344b5STakashi Iwai 
171d2f344b5STakashi Iwai int snd_hda_add_vmaster_hook(struct hda_codec *codec,
172f29735cbSTakashi Iwai 			     struct hda_vmaster_mute_hook *hook,
173f29735cbSTakashi Iwai 			     bool expose_enum_ctl);
174d2f344b5STakashi Iwai void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
175d2f344b5STakashi Iwai 
17647fd830aSTakashi Iwai /* amp value bits */
17747fd830aSTakashi Iwai #define HDA_AMP_MUTE	0x80
17847fd830aSTakashi Iwai #define HDA_AMP_UNMUTE	0x00
17947fd830aSTakashi Iwai #define HDA_AMP_VOLMASK	0x7f
18047fd830aSTakashi Iwai 
181985be54bSTakashi Iwai /* mono switch binding multiple inputs */
182985be54bSTakashi Iwai #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
183985be54bSTakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
184985be54bSTakashi Iwai 	  .info = snd_hda_mixer_amp_switch_info, \
185985be54bSTakashi Iwai 	  .get = snd_hda_mixer_bind_switch_get, \
186985be54bSTakashi Iwai 	  .put = snd_hda_mixer_bind_switch_put, \
187985be54bSTakashi Iwai 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
188985be54bSTakashi Iwai 
189985be54bSTakashi Iwai /* stereo switch binding multiple inputs */
190d01ce99fSTakashi Iwai #define HDA_BIND_MUTE(xname,nid,indices,dir) \
191d01ce99fSTakashi Iwai 	HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
192985be54bSTakashi Iwai 
193d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
194d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
195d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
196d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
197985be54bSTakashi Iwai 
198532d5381STakashi Iwai /* more generic bound controls */
199532d5381STakashi Iwai struct hda_ctl_ops {
200532d5381STakashi Iwai 	snd_kcontrol_info_t *info;
201532d5381STakashi Iwai 	snd_kcontrol_get_t *get;
202532d5381STakashi Iwai 	snd_kcontrol_put_t *put;
203532d5381STakashi Iwai 	snd_kcontrol_tlv_rw_t *tlv;
204532d5381STakashi Iwai };
205532d5381STakashi Iwai 
206532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_vol;	/* for bind-volume with TLV */
207532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_sw;	/* for bind-switch */
208532d5381STakashi Iwai 
209532d5381STakashi Iwai struct hda_bind_ctls {
210532d5381STakashi Iwai 	struct hda_ctl_ops *ops;
2115d9b6c07SHannes Eder 	unsigned long values[];
212532d5381STakashi Iwai };
213532d5381STakashi Iwai 
214532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
215532d5381STakashi Iwai 				 struct snd_ctl_elem_info *uinfo);
216532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
217532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
218532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
219532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
220532d5381STakashi Iwai int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
221532d5381STakashi Iwai 			   unsigned int size, unsigned int __user *tlv);
222532d5381STakashi Iwai 
223532d5381STakashi Iwai #define HDA_BIND_VOL(xname, bindrec) \
224532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
225532d5381STakashi Iwai 	  .name = xname, \
226532d5381STakashi Iwai 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
227532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
228532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,\
229532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
230532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
231532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
232532d5381STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_bind_tlv },\
233532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
234532d5381STakashi Iwai #define HDA_BIND_SW(xname, bindrec) \
235532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
236532d5381STakashi Iwai 	  .name = xname, \
237532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
238532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
239532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
240532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
241532d5381STakashi Iwai 
242532d5381STakashi Iwai /*
243532d5381STakashi Iwai  * SPDIF I/O
244532d5381STakashi Iwai  */
245dcda5806STakashi Iwai int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
24674b654c9SStephen Warren 				hda_nid_t associated_nid,
247dcda5806STakashi Iwai 				hda_nid_t cvt_nid, int type);
248dcda5806STakashi Iwai #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
249dcda5806STakashi Iwai 	snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
2501da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds /*
2531da177e4SLinus Torvalds  * input MUX helper
2541da177e4SLinus Torvalds  */
25554d17403STakashi Iwai #define HDA_MAX_NUM_INPUTS	16
2561da177e4SLinus Torvalds struct hda_input_mux_item {
257b5786e85STakashi Iwai 	char label[32];
2581da177e4SLinus Torvalds 	unsigned int index;
2591da177e4SLinus Torvalds };
2601da177e4SLinus Torvalds struct hda_input_mux {
2611da177e4SLinus Torvalds 	unsigned int num_items;
2621da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
2631da177e4SLinus Torvalds };
2641da177e4SLinus Torvalds 
265d01ce99fSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux,
266d01ce99fSTakashi Iwai 			   struct snd_ctl_elem_info *uinfo);
267d01ce99fSTakashi Iwai int snd_hda_input_mux_put(struct hda_codec *codec,
268d01ce99fSTakashi Iwai 			  const struct hda_input_mux *imux,
269c8b6bf9bSTakashi Iwai 			  struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
2701da177e4SLinus Torvalds 			  unsigned int *cur_val);
2716194b99dSTakashi Iwai int snd_hda_add_imux_item(struct hda_codec *codec,
2726194b99dSTakashi Iwai 			  struct hda_input_mux *imux, const char *label,
273128bc4baSTakashi Iwai 			  int index, int *type_index_ret);
2741da177e4SLinus Torvalds 
275d2a6d7dcSTakashi Iwai /*
2761da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
2771da177e4SLinus Torvalds  */
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
2801da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
2811da177e4SLinus Torvalds 
282a06dbfc2STakashi Iwai #define HDA_MAX_OUTS	5
283a06dbfc2STakashi Iwai 
2841da177e4SLinus Torvalds struct hda_multi_out {
2851da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
286dda14410STakashi Iwai 	const hda_nid_t *dac_nids;	/* DAC list */
2871da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
288a06dbfc2STakashi Iwai 	hda_nid_t hp_out_nid[HDA_MAX_OUTS];	/* DACs for multiple HPs */
289a06dbfc2STakashi Iwai 	hda_nid_t extra_out_nid[HDA_MAX_OUTS];	/* other (e.g. speaker) DACs */
2901da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
291dda14410STakashi Iwai 	const hda_nid_t *slave_dig_outs;
2921da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
2931da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
294d29240ceSTakashi Iwai 	int no_share_stream;	/* don't share a stream with multiple pins */
2959a08160bSTakashi Iwai 	int share_spdif;	/* share SPDIF pin */
2969a08160bSTakashi Iwai 	/* PCM information for both analog and SPDIF DACs */
2979a08160bSTakashi Iwai 	unsigned int analog_rates;
2989a08160bSTakashi Iwai 	unsigned int analog_maxbps;
2999a08160bSTakashi Iwai 	u64 analog_formats;
3009a08160bSTakashi Iwai 	unsigned int spdif_rates;
3019a08160bSTakashi Iwai 	unsigned int spdif_maxbps;
3029a08160bSTakashi Iwai 	u64 spdif_formats;
3031da177e4SLinus Torvalds };
3041da177e4SLinus Torvalds 
3059a08160bSTakashi Iwai int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
3069a08160bSTakashi Iwai 				  struct hda_multi_out *mout);
307d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_open(struct hda_codec *codec,
308d01ce99fSTakashi Iwai 			       struct hda_multi_out *mout);
309d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_close(struct hda_codec *codec,
310d01ce99fSTakashi Iwai 				struct hda_multi_out *mout);
3116b97eb45STakashi Iwai int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3126b97eb45STakashi Iwai 				  struct hda_multi_out *mout,
3136b97eb45STakashi Iwai 				  unsigned int stream_tag,
3146b97eb45STakashi Iwai 				  unsigned int format,
3156b97eb45STakashi Iwai 				  struct snd_pcm_substream *substream);
3169411e21cSTakashi Iwai int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3179411e21cSTakashi Iwai 				  struct hda_multi_out *mout);
318d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_open(struct hda_codec *codec,
319d01ce99fSTakashi Iwai 				  struct hda_multi_out *mout,
3209a08160bSTakashi Iwai 				  struct snd_pcm_substream *substream,
3219a08160bSTakashi Iwai 				  struct hda_pcm_stream *hinfo);
322d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
323d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout,
3241da177e4SLinus Torvalds 				     unsigned int stream_tag,
3251da177e4SLinus Torvalds 				     unsigned int format,
326c8b6bf9bSTakashi Iwai 				     struct snd_pcm_substream *substream);
327d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
328d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout);
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds /*
3311da177e4SLinus Torvalds  * generic proc interface
3321da177e4SLinus Torvalds  */
333*cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
3341da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
3351da177e4SLinus Torvalds #else
3361da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
3371da177e4SLinus Torvalds #endif
3381da177e4SLinus Torvalds 
339d39b4352SWu Fengguang #define SND_PRINT_BITS_ADVISED_BUFSIZE	16
340d39b4352SWu Fengguang void snd_print_pcm_bits(int pcm, char *buf, int buflen);
341d39b4352SWu Fengguang 
3421da177e4SLinus Torvalds /*
3431da177e4SLinus Torvalds  * Misc
3441da177e4SLinus Torvalds  */
345d01ce99fSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec,
346031024eeSTakashi Iwai 			 const struct snd_kcontrol_new *knew);
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds /*
349c9ce6b26STakashi Iwai  * Fix-up pin default configurations and add default verbs
350c9ce6b26STakashi Iwai  */
351c9ce6b26STakashi Iwai 
352c9ce6b26STakashi Iwai struct hda_pintbl {
353c9ce6b26STakashi Iwai 	hda_nid_t nid;
354c9ce6b26STakashi Iwai 	u32 val;
355c9ce6b26STakashi Iwai };
356c9ce6b26STakashi Iwai 
357c9ce6b26STakashi Iwai struct hda_model_fixup {
358c9ce6b26STakashi Iwai 	const int id;
359c9ce6b26STakashi Iwai 	const char *name;
360c9ce6b26STakashi Iwai };
361c9ce6b26STakashi Iwai 
362c9ce6b26STakashi Iwai struct hda_fixup {
363c9ce6b26STakashi Iwai 	int type;
3641f578250STakashi Iwai 	bool chained:1;		/* call the chained fixup(s) after this */
3651f578250STakashi Iwai 	bool chained_before:1;	/* call the chained fixup(s) before this */
366c9ce6b26STakashi Iwai 	int chain_id;
367c9ce6b26STakashi Iwai 	union {
368c9ce6b26STakashi Iwai 		const struct hda_pintbl *pins;
369c9ce6b26STakashi Iwai 		const struct hda_verb *verbs;
370c9ce6b26STakashi Iwai 		void (*func)(struct hda_codec *codec,
371c9ce6b26STakashi Iwai 			     const struct hda_fixup *fix,
372c9ce6b26STakashi Iwai 			     int action);
373c9ce6b26STakashi Iwai 	} v;
374c9ce6b26STakashi Iwai };
375c9ce6b26STakashi Iwai 
37620531415SDavid Henningsson struct snd_hda_pin_quirk {
37720531415SDavid Henningsson 	unsigned int codec;             /* Codec vendor/device ID */
37820531415SDavid Henningsson 	unsigned short subvendor;	/* PCI subvendor ID */
37920531415SDavid Henningsson 	const struct hda_pintbl *pins;  /* list of matching pins */
38020531415SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
38120531415SDavid Henningsson 	const char *name;
38220531415SDavid Henningsson #endif
38320531415SDavid Henningsson 	int value;			/* quirk value */
38420531415SDavid Henningsson };
38520531415SDavid Henningsson 
386a2d2fa02SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
387a2d2fa02SDavid Henningsson 
388a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
389a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
390a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
391a2d2fa02SDavid Henningsson 	  .name = _name,\
392a2d2fa02SDavid Henningsson 	  .value = _value,\
393fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
394a2d2fa02SDavid Henningsson 	}
395a2d2fa02SDavid Henningsson #else
396a2d2fa02SDavid Henningsson 
397a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
398a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
399a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
400a2d2fa02SDavid Henningsson 	  .value = _value,\
401fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
402a2d2fa02SDavid Henningsson 	}
403a2d2fa02SDavid Henningsson 
404a2d2fa02SDavid Henningsson #endif
405a2d2fa02SDavid Henningsson 
406f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NOT_SET -1
407f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NO_FIXUP -2
408a2d2fa02SDavid Henningsson 
409c9ce6b26STakashi Iwai /* fixup types */
410c9ce6b26STakashi Iwai enum {
411c9ce6b26STakashi Iwai 	HDA_FIXUP_INVALID,
412c9ce6b26STakashi Iwai 	HDA_FIXUP_PINS,
413c9ce6b26STakashi Iwai 	HDA_FIXUP_VERBS,
414c9ce6b26STakashi Iwai 	HDA_FIXUP_FUNC,
415fd108215STakashi Iwai 	HDA_FIXUP_PINCTLS,
416c9ce6b26STakashi Iwai };
417c9ce6b26STakashi Iwai 
418c9ce6b26STakashi Iwai /* fixup action definitions */
419c9ce6b26STakashi Iwai enum {
420c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PRE_PROBE,
421c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PROBE,
422c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_INIT,
423c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_BUILD,
424360fec28SDavid Henningsson 	HDA_FIXUP_ACT_FREE,
425c9ce6b26STakashi Iwai };
426c9ce6b26STakashi Iwai 
427c9ce6b26STakashi Iwai int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
428c9ce6b26STakashi Iwai void snd_hda_apply_verbs(struct hda_codec *codec);
429c9ce6b26STakashi Iwai void snd_hda_apply_pincfgs(struct hda_codec *codec,
430c9ce6b26STakashi Iwai 			   const struct hda_pintbl *cfg);
431c9ce6b26STakashi Iwai void snd_hda_apply_fixup(struct hda_codec *codec, int action);
432c9ce6b26STakashi Iwai void snd_hda_pick_fixup(struct hda_codec *codec,
433c9ce6b26STakashi Iwai 			const struct hda_model_fixup *models,
434c9ce6b26STakashi Iwai 			const struct snd_pci_quirk *quirk,
435c9ce6b26STakashi Iwai 			const struct hda_fixup *fixlist);
43620531415SDavid Henningsson void snd_hda_pick_pin_fixup(struct hda_codec *codec,
43720531415SDavid Henningsson 			    const struct snd_hda_pin_quirk *pin_quirk,
43820531415SDavid Henningsson 			    const struct hda_fixup *fixlist);
43920531415SDavid Henningsson 
440128bc4baSTakashi Iwai /* helper macros to retrieve pin default-config values */
441d01ce99fSTakashi Iwai #define get_defcfg_connect(cfg) \
442d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
443d01ce99fSTakashi Iwai #define get_defcfg_association(cfg) \
444d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
445d01ce99fSTakashi Iwai #define get_defcfg_location(cfg) \
446d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
447d01ce99fSTakashi Iwai #define get_defcfg_sequence(cfg) \
448d01ce99fSTakashi Iwai 	(cfg & AC_DEFCFG_SEQUENCE)
449d01ce99fSTakashi Iwai #define get_defcfg_device(cfg) \
450d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
45108a1f5ebSTakashi Iwai #define get_defcfg_misc(cfg) \
45208a1f5ebSTakashi Iwai 	((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
453e9edcee0STakashi Iwai 
4548d88bc3dSTakashi Iwai /* amp values */
4558d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))
4568d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))
4578d88bc3dSTakashi Iwai #define AMP_OUT_MUTE		0xb080
4588d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE		0xb000
4598d88bc3dSTakashi Iwai #define AMP_OUT_ZERO		0xb000
4608d88bc3dSTakashi Iwai /* pinctl values */
46135e8901eSRobin H. Johnson #define PIN_IN			(AC_PINCTL_IN_EN)
46235e8901eSRobin H. Johnson #define PIN_VREFHIZ		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
46335e8901eSRobin H. Johnson #define PIN_VREF50		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
46435e8901eSRobin H. Johnson #define PIN_VREFGRD		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
46535e8901eSRobin H. Johnson #define PIN_VREF80		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
46635e8901eSRobin H. Johnson #define PIN_VREF100		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
46735e8901eSRobin H. Johnson #define PIN_OUT			(AC_PINCTL_OUT_EN)
46835e8901eSRobin H. Johnson #define PIN_HP			(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
46935e8901eSRobin H. Johnson #define PIN_HP_AMP		(AC_PINCTL_HP_EN)
4708d88bc3dSTakashi Iwai 
4714740860bSTakashi Iwai unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
47262f3a2f7STakashi Iwai unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
47362f3a2f7STakashi Iwai 				     hda_nid_t pin, unsigned int val);
474cdd03cedSTakashi Iwai int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
475cdd03cedSTakashi Iwai 			 unsigned int val, bool cached);
476cdd03cedSTakashi Iwai 
477cdd03cedSTakashi Iwai /**
478cdd03cedSTakashi Iwai  * _snd_hda_set_pin_ctl - Set a pin-control value safely
479cdd03cedSTakashi Iwai  * @codec: the codec instance
480cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
481cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
482cdd03cedSTakashi Iwai  *
483cdd03cedSTakashi Iwai  * This function sets the pin-control value to the given pin, but
484cdd03cedSTakashi Iwai  * filters out the invalid pin-control bits when the pin has no such
485cdd03cedSTakashi Iwai  * capabilities.  For example, when PIN_HP is passed but the pin has no
486cdd03cedSTakashi Iwai  * HP-drive capability, the HP bit is omitted.
487cdd03cedSTakashi Iwai  *
488cdd03cedSTakashi Iwai  * The function doesn't check the input VREF capability bits, though.
4894740860bSTakashi Iwai  * Use snd_hda_get_default_vref() to guess the right value.
490cdd03cedSTakashi Iwai  * Also, this function is only for analog pins, not for HDMI pins.
491cdd03cedSTakashi Iwai  */
492cdd03cedSTakashi Iwai static inline int
493cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
494cdd03cedSTakashi Iwai {
495cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, false);
496cdd03cedSTakashi Iwai }
497cdd03cedSTakashi Iwai 
498cdd03cedSTakashi Iwai /**
499cdd03cedSTakashi Iwai  * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
500cdd03cedSTakashi Iwai  * @codec: the codec instance
501cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
502cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
503cdd03cedSTakashi Iwai  *
504cdd03cedSTakashi Iwai  * Just like snd_hda_set_pin_ctl() but write to cache as well.
505cdd03cedSTakashi Iwai  */
506cdd03cedSTakashi Iwai static inline int
507cdd03cedSTakashi Iwai snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
508cdd03cedSTakashi Iwai 			  unsigned int val)
509cdd03cedSTakashi Iwai {
510cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, true);
511cdd03cedSTakashi Iwai }
512cdd03cedSTakashi Iwai 
513d7fdc00aSTakashi Iwai int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
514d7fdc00aSTakashi Iwai int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
515d7fdc00aSTakashi Iwai 				 unsigned int val);
516d7fdc00aSTakashi Iwai 
5177639a06cSTakashi Iwai #define for_each_hda_codec_node(nid, codec) \
5187639a06cSTakashi Iwai 	for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
5197639a06cSTakashi Iwai 
52054d17403STakashi Iwai /*
52154d17403STakashi Iwai  * get widget capabilities
52254d17403STakashi Iwai  */
52354d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
52454d17403STakashi Iwai {
5257639a06cSTakashi Iwai 	if (nid < codec->core.start_nid ||
5267639a06cSTakashi Iwai 	    nid >= codec->core.start_nid + codec->core.num_nodes)
527dca008f3STakashi Iwai 		return 0;
5287639a06cSTakashi Iwai 	return codec->wcaps[nid - codec->core.start_nid];
52954d17403STakashi Iwai }
53054d17403STakashi Iwai 
531a22d543aSTakashi Iwai /* get the widget type from widget capability bits */
5323a90274dSTakashi Iwai static inline int get_wcaps_type(unsigned int wcaps)
5333a90274dSTakashi Iwai {
5343a90274dSTakashi Iwai 	if (!wcaps)
5353a90274dSTakashi Iwai 		return -1; /* invalid type */
5363a90274dSTakashi Iwai 	return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5373a90274dSTakashi Iwai }
538a22d543aSTakashi Iwai 
539fd72d008SWu Fengguang static inline unsigned int get_wcaps_channels(u32 wcaps)
540fd72d008SWu Fengguang {
541fd72d008SWu Fengguang 	unsigned int chans;
542fd72d008SWu Fengguang 
543fd72d008SWu Fengguang 	chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
544fd72d008SWu Fengguang 	chans = ((chans << 1) | 1) + 1;
545fd72d008SWu Fengguang 
546fd72d008SWu Fengguang 	return chans;
547fd72d008SWu Fengguang }
548fd72d008SWu Fengguang 
549d045c5dcSTakashi Iwai static inline void snd_hda_override_wcaps(struct hda_codec *codec,
550d045c5dcSTakashi Iwai 					  hda_nid_t nid, u32 val)
551d045c5dcSTakashi Iwai {
5527639a06cSTakashi Iwai 	if (nid >= codec->core.start_nid &&
5537639a06cSTakashi Iwai 	    nid < codec->core.start_nid + codec->core.num_nodes)
5547639a06cSTakashi Iwai 		codec->wcaps[nid - codec->core.start_nid] = val;
555d045c5dcSTakashi Iwai }
556d045c5dcSTakashi Iwai 
55709a99959SMatthew Ranostay u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
558897cc188STakashi Iwai int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
559897cc188STakashi Iwai 			      unsigned int caps);
560faa75f8aSTakashi Iwai /**
561faa75f8aSTakashi Iwai  * snd_hda_query_pin_caps - Query PIN capabilities
562faa75f8aSTakashi Iwai  * @codec: the HD-auio codec
563faa75f8aSTakashi Iwai  * @nid: the NID to query
564faa75f8aSTakashi Iwai  *
565faa75f8aSTakashi Iwai  * Query PIN capabilities for the given widget.
566faa75f8aSTakashi Iwai  * Returns the obtained capability bits.
567faa75f8aSTakashi Iwai  *
568faa75f8aSTakashi Iwai  * When cap bits have been already read, this doesn't read again but
569faa75f8aSTakashi Iwai  * returns the cached value.
570faa75f8aSTakashi Iwai  */
571faa75f8aSTakashi Iwai static inline u32
572faa75f8aSTakashi Iwai snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
573faa75f8aSTakashi Iwai {
574faa75f8aSTakashi Iwai 	return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
575faa75f8aSTakashi Iwai 
576faa75f8aSTakashi Iwai }
577faa75f8aSTakashi Iwai 
578faa75f8aSTakashi Iwai /**
579faa75f8aSTakashi Iwai  * snd_hda_override_pin_caps - Override the pin capabilities
580faa75f8aSTakashi Iwai  * @codec: the CODEC
581faa75f8aSTakashi Iwai  * @nid: the NID to override
582faa75f8aSTakashi Iwai  * @caps: the capability bits to set
583faa75f8aSTakashi Iwai  *
584faa75f8aSTakashi Iwai  * Override the cached PIN capabilitiy bits value by the given one.
585faa75f8aSTakashi Iwai  *
586faa75f8aSTakashi Iwai  * Returns zero if successful or a negative error code.
587faa75f8aSTakashi Iwai  */
588faa75f8aSTakashi Iwai static inline int
589faa75f8aSTakashi Iwai snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
590faa75f8aSTakashi Iwai 			  unsigned int caps)
591faa75f8aSTakashi Iwai {
592faa75f8aSTakashi Iwai 	return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
593faa75f8aSTakashi Iwai }
594faa75f8aSTakashi Iwai 
595861a04edSDavid Henningsson bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
596861a04edSDavid Henningsson 			   int dir, unsigned int bits);
597861a04edSDavid Henningsson 
598861a04edSDavid Henningsson #define nid_has_mute(codec, nid, dir) \
599861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
600861a04edSDavid Henningsson #define nid_has_volume(codec, nid, dir) \
601861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
602861a04edSDavid Henningsson 
60303697e2aSTakashi Iwai 
6049e3fd871SJaroslav Kysela /* flags for hda_nid_item */
6059e3fd871SJaroslav Kysela #define HDA_NID_ITEM_AMP	(1<<0)
6069e3fd871SJaroslav Kysela 
6073911a4c1SJaroslav Kysela struct hda_nid_item {
6083911a4c1SJaroslav Kysela 	struct snd_kcontrol *kctl;
6095b0cb1d8SJaroslav Kysela 	unsigned int index;
6103911a4c1SJaroslav Kysela 	hda_nid_t nid;
6119e3fd871SJaroslav Kysela 	unsigned short flags;
6123911a4c1SJaroslav Kysela };
6133911a4c1SJaroslav Kysela 
6143911a4c1SJaroslav Kysela int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
6153911a4c1SJaroslav Kysela 		    struct snd_kcontrol *kctl);
6165b0cb1d8SJaroslav Kysela int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
6175b0cb1d8SJaroslav Kysela 		    unsigned int index, hda_nid_t nid);
618d13bd412STakashi Iwai void snd_hda_ctls_clear(struct hda_codec *codec);
619d13bd412STakashi Iwai 
6202807314dSTakashi Iwai /*
6212807314dSTakashi Iwai  * hwdep interface
6222807314dSTakashi Iwai  */
623d7ffba19STakashi Iwai #ifdef CONFIG_SND_HDA_HWDEP
6242807314dSTakashi Iwai int snd_hda_create_hwdep(struct hda_codec *codec);
625d7ffba19STakashi Iwai #else
626d7ffba19STakashi Iwai static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
627d7ffba19STakashi Iwai #endif
6282807314dSTakashi Iwai 
629648a8d27STakashi Iwai void snd_hda_sysfs_init(struct hda_codec *codec);
630648a8d27STakashi Iwai void snd_hda_sysfs_clear(struct hda_codec *codec);
631648a8d27STakashi Iwai 
632648a8d27STakashi Iwai extern const struct attribute_group *snd_hda_dev_attr_groups[];
633648a8d27STakashi Iwai 
63443b62713STakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
63543b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
63643b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
637bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
63843b62713STakashi Iwai #else
63943b62713STakashi Iwai static inline
64043b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
64143b62713STakashi Iwai {
64243b62713STakashi Iwai 	return NULL;
64343b62713STakashi Iwai }
64443b62713STakashi Iwai 
64543b62713STakashi Iwai static inline
64643b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
64743b62713STakashi Iwai {
64843b62713STakashi Iwai 	return -ENOENT;
64943b62713STakashi Iwai }
650bc759721STakashi Iwai 
651bc759721STakashi Iwai static inline
652bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
653bc759721STakashi Iwai {
654bc759721STakashi Iwai 	return -ENOENT;
655bc759721STakashi Iwai }
65643b62713STakashi Iwai #endif
65743b62713STakashi Iwai 
658cb53c626STakashi Iwai /*
659cb53c626STakashi Iwai  * power-management
660cb53c626STakashi Iwai  */
661cb53c626STakashi Iwai 
662cb53c626STakashi Iwai void snd_hda_schedule_power_save(struct hda_codec *codec);
663cb53c626STakashi Iwai 
664cb53c626STakashi Iwai struct hda_amp_list {
665cb53c626STakashi Iwai 	hda_nid_t nid;
666cb53c626STakashi Iwai 	unsigned char dir;
667cb53c626STakashi Iwai 	unsigned char idx;
668cb53c626STakashi Iwai };
669cb53c626STakashi Iwai 
670cb53c626STakashi Iwai struct hda_loopback_check {
671031024eeSTakashi Iwai 	const struct hda_amp_list *amplist;
672cb53c626STakashi Iwai 	int power_on;
673cb53c626STakashi Iwai };
674cb53c626STakashi Iwai 
675cb53c626STakashi Iwai int snd_hda_check_amp_list_power(struct hda_codec *codec,
676cb53c626STakashi Iwai 				 struct hda_loopback_check *check,
677cb53c626STakashi Iwai 				 hda_nid_t nid);
678cb53c626STakashi Iwai 
6799040d102STakashi Iwai /* check whether the actual power state matches with the target state */
6809040d102STakashi Iwai static inline bool
6819040d102STakashi Iwai snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
6829040d102STakashi Iwai 			  unsigned int target_state)
6839040d102STakashi Iwai {
6849040d102STakashi Iwai 	unsigned int state = snd_hda_codec_read(codec, nid, 0,
6859040d102STakashi Iwai 						AC_VERB_GET_POWER_STATE, 0);
6869040d102STakashi Iwai 	if (state & AC_PWRST_ERROR)
6879040d102STakashi Iwai 		return true;
6889040d102STakashi Iwai 	state = (state >> 4) & 0x0f;
68906ec56d3STakashi Iwai 	return (state == target_state);
6909040d102STakashi Iwai }
6919040d102STakashi Iwai 
692ba615b86STakashi Iwai unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
693ba615b86STakashi Iwai 					     hda_nid_t nid,
694ba615b86STakashi Iwai 					     unsigned int power_state);
695ba615b86STakashi Iwai 
69689385035SMatthew Ranostay /*
69789385035SMatthew Ranostay  * AMP control callbacks
69889385035SMatthew Ranostay  */
69989385035SMatthew Ranostay /* retrieve parameters from private_value */
7003911a4c1SJaroslav Kysela #define get_amp_nid_(pv)	((pv) & 0xffff)
7013911a4c1SJaroslav Kysela #define get_amp_nid(kc)		get_amp_nid_((kc)->private_value)
70289385035SMatthew Ranostay #define get_amp_channels(kc)	(((kc)->private_value >> 16) & 0x3)
703527e4d73STakashi Iwai #define get_amp_direction_(pv)	(((pv) >> 18) & 0x1)
704527e4d73STakashi Iwai #define get_amp_direction(kc)	get_amp_direction_((kc)->private_value)
705130e5f06STakashi Iwai #define get_amp_index_(pv)	(((pv) >> 19) & 0xf)
706130e5f06STakashi Iwai #define get_amp_index(kc)	get_amp_index_((kc)->private_value)
70729fdbec2STakashi Iwai #define get_amp_offset(kc)	(((kc)->private_value >> 23) & 0x3f)
708de8c85f7SClemens Ladisch #define get_amp_min_mute(kc)	(((kc)->private_value >> 29) & 0x1)
70989385035SMatthew Ranostay 
7107f4a9f43SWu Fengguang /*
711dda415d4STakashi Iwai  * enum control helper
712dda415d4STakashi Iwai  */
713dda415d4STakashi Iwai int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
714dda415d4STakashi Iwai 			     struct snd_ctl_elem_info *uinfo,
715dda415d4STakashi Iwai 			     int num_entries, const char * const *texts);
716dda415d4STakashi Iwai #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
717dda415d4STakashi Iwai 	snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
718dda415d4STakashi Iwai 
719dda415d4STakashi Iwai /*
7207f4a9f43SWu Fengguang  * CEA Short Audio Descriptor data
7217f4a9f43SWu Fengguang  */
7227f4a9f43SWu Fengguang struct cea_sad {
7237f4a9f43SWu Fengguang 	int	channels;
7247f4a9f43SWu Fengguang 	int	format;		/* (format == 0) indicates invalid SAD */
7257f4a9f43SWu Fengguang 	int	rates;
7267f4a9f43SWu Fengguang 	int	sample_bits;	/* for LPCM */
7277f4a9f43SWu Fengguang 	int	max_bitrate;	/* for AC3...ATRAC */
7287f4a9f43SWu Fengguang 	int	profile;	/* for WMAPRO */
7297f4a9f43SWu Fengguang };
7307f4a9f43SWu Fengguang 
7317f4a9f43SWu Fengguang #define ELD_FIXED_BYTES	20
73214bc52b8SPierre-Louis Bossart #define ELD_MAX_SIZE    256
7337f4a9f43SWu Fengguang #define ELD_MAX_MNL	16
7347f4a9f43SWu Fengguang #define ELD_MAX_SAD	16
7357f4a9f43SWu Fengguang 
7367f4a9f43SWu Fengguang /*
7377f4a9f43SWu Fengguang  * ELD: EDID Like Data
7387f4a9f43SWu Fengguang  */
7391613d6b4SDavid Henningsson struct parsed_hdmi_eld {
7401613d6b4SDavid Henningsson 	/*
7411613d6b4SDavid Henningsson 	 * all fields will be cleared before updating ELD
7421613d6b4SDavid Henningsson 	 */
7437f4a9f43SWu Fengguang 	int	baseline_len;
74423ccc2bdSWu Fengguang 	int	eld_ver;
7457f4a9f43SWu Fengguang 	int	cea_edid_ver;
7467f4a9f43SWu Fengguang 	char	monitor_name[ELD_MAX_MNL + 1];
7477f4a9f43SWu Fengguang 	int	manufacture_id;
7487f4a9f43SWu Fengguang 	int	product_id;
7497f4a9f43SWu Fengguang 	u64	port_id;
7507f4a9f43SWu Fengguang 	int	support_hdcp;
7517f4a9f43SWu Fengguang 	int	support_ai;
7527f4a9f43SWu Fengguang 	int	conn_type;
7537f4a9f43SWu Fengguang 	int	aud_synch_delay;
7547f4a9f43SWu Fengguang 	int	spk_alloc;
7557f4a9f43SWu Fengguang 	int	sad_count;
7567f4a9f43SWu Fengguang 	struct cea_sad sad[ELD_MAX_SAD];
7571613d6b4SDavid Henningsson };
7581613d6b4SDavid Henningsson 
7591613d6b4SDavid Henningsson struct hdmi_eld {
7601613d6b4SDavid Henningsson 	bool	monitor_present;
7611613d6b4SDavid Henningsson 	bool	eld_valid;
7621613d6b4SDavid Henningsson 	int	eld_size;
76314bc52b8SPierre-Louis Bossart 	char    eld_buffer[ELD_MAX_SIZE];
7641613d6b4SDavid Henningsson 	struct parsed_hdmi_eld info;
7657f4a9f43SWu Fengguang };
7667f4a9f43SWu Fengguang 
7677f4a9f43SWu Fengguang int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
7681613d6b4SDavid Henningsson int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
7691613d6b4SDavid Henningsson 		     unsigned char *buf, int *eld_size);
77079514d47STakashi Iwai int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
7711613d6b4SDavid Henningsson 		       const unsigned char *buf, int size);
77279514d47STakashi Iwai void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
7731613d6b4SDavid Henningsson void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
7742def8172SStephen Warren 			      struct hda_pcm_stream *hinfo);
7757f4a9f43SWu Fengguang 
77689250f84SAnssi Hannula int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
77789250f84SAnssi Hannula 			 unsigned char *buf, int *eld_size,
77889250f84SAnssi Hannula 			 bool rev3_or_later);
77989250f84SAnssi Hannula 
780*cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
781a4e9a38bSTakashi Iwai void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
782a4e9a38bSTakashi Iwai 			     struct snd_info_buffer *buffer);
783a4e9a38bSTakashi Iwai void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
784a4e9a38bSTakashi Iwai 			     struct snd_info_buffer *buffer);
7855f1e71b1SWu Fengguang #endif
7865f1e71b1SWu Fengguang 
787903b21d8SWu Fengguang #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
788903b21d8SWu Fengguang void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
789903b21d8SWu Fengguang 
7904e76a883STakashi Iwai /*
7914e76a883STakashi Iwai  */
792d8a766a1STakashi Iwai #define codec_err(codec, fmt, args...) \
793d8a766a1STakashi Iwai 	dev_err(hda_codec_dev(codec), fmt, ##args)
794d8a766a1STakashi Iwai #define codec_warn(codec, fmt, args...) \
795d8a766a1STakashi Iwai 	dev_warn(hda_codec_dev(codec), fmt, ##args)
796d8a766a1STakashi Iwai #define codec_info(codec, fmt, args...) \
797d8a766a1STakashi Iwai 	dev_info(hda_codec_dev(codec), fmt, ##args)
798d8a766a1STakashi Iwai #define codec_dbg(codec, fmt, args...) \
799d8a766a1STakashi Iwai 	dev_dbg(hda_codec_dev(codec), fmt, ##args)
8004e76a883STakashi Iwai 
8011da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
802