xref: /openbmc/linux/sound/pci/hda/hda_local.h (revision 009f8c90f571d87855914dbc20e6c0ea2a3b19ae)
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)
132a686ec4cSTakashi Iwai int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
133a686ec4cSTakashi Iwai 			     int ch, int dir, 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);
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 
181532d5381STakashi Iwai /*
182532d5381STakashi Iwai  * SPDIF I/O
183532d5381STakashi Iwai  */
184dcda5806STakashi Iwai int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
18574b654c9SStephen Warren 				hda_nid_t associated_nid,
186dcda5806STakashi Iwai 				hda_nid_t cvt_nid, int type);
187dcda5806STakashi Iwai #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
188dcda5806STakashi Iwai 	snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
1891da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds /*
1921da177e4SLinus Torvalds  * input MUX helper
1931da177e4SLinus Torvalds  */
19454d17403STakashi Iwai #define HDA_MAX_NUM_INPUTS	16
1951da177e4SLinus Torvalds struct hda_input_mux_item {
196b5786e85STakashi Iwai 	char label[32];
1971da177e4SLinus Torvalds 	unsigned int index;
1981da177e4SLinus Torvalds };
1991da177e4SLinus Torvalds struct hda_input_mux {
2001da177e4SLinus Torvalds 	unsigned int num_items;
2011da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
2021da177e4SLinus Torvalds };
2031da177e4SLinus Torvalds 
204d01ce99fSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux,
205d01ce99fSTakashi Iwai 			   struct snd_ctl_elem_info *uinfo);
206d01ce99fSTakashi Iwai int snd_hda_input_mux_put(struct hda_codec *codec,
207d01ce99fSTakashi Iwai 			  const struct hda_input_mux *imux,
208c8b6bf9bSTakashi Iwai 			  struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
2091da177e4SLinus Torvalds 			  unsigned int *cur_val);
2106194b99dSTakashi Iwai int snd_hda_add_imux_item(struct hda_codec *codec,
2116194b99dSTakashi Iwai 			  struct hda_input_mux *imux, const char *label,
212128bc4baSTakashi Iwai 			  int index, int *type_index_ret);
2131da177e4SLinus Torvalds 
214d2a6d7dcSTakashi Iwai /*
2151da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
2161da177e4SLinus Torvalds  */
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
2191da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
2201da177e4SLinus Torvalds 
221a06dbfc2STakashi Iwai #define HDA_MAX_OUTS	5
222a06dbfc2STakashi Iwai 
2231da177e4SLinus Torvalds struct hda_multi_out {
2241da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
225dda14410STakashi Iwai 	const hda_nid_t *dac_nids;	/* DAC list */
2261da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
227a06dbfc2STakashi Iwai 	hda_nid_t hp_out_nid[HDA_MAX_OUTS];	/* DACs for multiple HPs */
228a06dbfc2STakashi Iwai 	hda_nid_t extra_out_nid[HDA_MAX_OUTS];	/* other (e.g. speaker) DACs */
2291da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
230dda14410STakashi Iwai 	const hda_nid_t *slave_dig_outs;
2311da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
2321da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
233d29240ceSTakashi Iwai 	int no_share_stream;	/* don't share a stream with multiple pins */
2349a08160bSTakashi Iwai 	int share_spdif;	/* share SPDIF pin */
2359a08160bSTakashi Iwai 	/* PCM information for both analog and SPDIF DACs */
2369a08160bSTakashi Iwai 	unsigned int analog_rates;
2379a08160bSTakashi Iwai 	unsigned int analog_maxbps;
2389a08160bSTakashi Iwai 	u64 analog_formats;
2399a08160bSTakashi Iwai 	unsigned int spdif_rates;
2409a08160bSTakashi Iwai 	unsigned int spdif_maxbps;
2419a08160bSTakashi Iwai 	u64 spdif_formats;
2421da177e4SLinus Torvalds };
2431da177e4SLinus Torvalds 
2449a08160bSTakashi Iwai int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2459a08160bSTakashi Iwai 				  struct hda_multi_out *mout);
246d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_open(struct hda_codec *codec,
247d01ce99fSTakashi Iwai 			       struct hda_multi_out *mout);
248d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_close(struct hda_codec *codec,
249d01ce99fSTakashi Iwai 				struct hda_multi_out *mout);
2506b97eb45STakashi Iwai int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2516b97eb45STakashi Iwai 				  struct hda_multi_out *mout,
2526b97eb45STakashi Iwai 				  unsigned int stream_tag,
2536b97eb45STakashi Iwai 				  unsigned int format,
2546b97eb45STakashi Iwai 				  struct snd_pcm_substream *substream);
2559411e21cSTakashi Iwai int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
2569411e21cSTakashi Iwai 				  struct hda_multi_out *mout);
257d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_open(struct hda_codec *codec,
258d01ce99fSTakashi Iwai 				  struct hda_multi_out *mout,
2599a08160bSTakashi Iwai 				  struct snd_pcm_substream *substream,
2609a08160bSTakashi Iwai 				  struct hda_pcm_stream *hinfo);
261d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
262d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout,
2631da177e4SLinus Torvalds 				     unsigned int stream_tag,
2641da177e4SLinus Torvalds 				     unsigned int format,
265c8b6bf9bSTakashi Iwai 				     struct snd_pcm_substream *substream);
266d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
267d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout);
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds /*
2701da177e4SLinus Torvalds  * generic proc interface
2711da177e4SLinus Torvalds  */
272cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
2731da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
2741da177e4SLinus Torvalds #else
2751da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
2761da177e4SLinus Torvalds #endif
2771da177e4SLinus Torvalds 
278d39b4352SWu Fengguang #define SND_PRINT_BITS_ADVISED_BUFSIZE	16
279d39b4352SWu Fengguang void snd_print_pcm_bits(int pcm, char *buf, int buflen);
280d39b4352SWu Fengguang 
2811da177e4SLinus Torvalds /*
2821da177e4SLinus Torvalds  * Misc
2831da177e4SLinus Torvalds  */
284d01ce99fSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec,
285031024eeSTakashi Iwai 			 const struct snd_kcontrol_new *knew);
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds /*
288c9ce6b26STakashi Iwai  * Fix-up pin default configurations and add default verbs
289c9ce6b26STakashi Iwai  */
290c9ce6b26STakashi Iwai 
291c9ce6b26STakashi Iwai struct hda_pintbl {
292c9ce6b26STakashi Iwai 	hda_nid_t nid;
293c9ce6b26STakashi Iwai 	u32 val;
294c9ce6b26STakashi Iwai };
295c9ce6b26STakashi Iwai 
296c9ce6b26STakashi Iwai struct hda_model_fixup {
297c9ce6b26STakashi Iwai 	const int id;
298c9ce6b26STakashi Iwai 	const char *name;
299c9ce6b26STakashi Iwai };
300c9ce6b26STakashi Iwai 
301c9ce6b26STakashi Iwai struct hda_fixup {
302c9ce6b26STakashi Iwai 	int type;
3031f578250STakashi Iwai 	bool chained:1;		/* call the chained fixup(s) after this */
3041f578250STakashi Iwai 	bool chained_before:1;	/* call the chained fixup(s) before this */
305c9ce6b26STakashi Iwai 	int chain_id;
306c9ce6b26STakashi Iwai 	union {
307c9ce6b26STakashi Iwai 		const struct hda_pintbl *pins;
308c9ce6b26STakashi Iwai 		const struct hda_verb *verbs;
309c9ce6b26STakashi Iwai 		void (*func)(struct hda_codec *codec,
310c9ce6b26STakashi Iwai 			     const struct hda_fixup *fix,
311c9ce6b26STakashi Iwai 			     int action);
312c9ce6b26STakashi Iwai 	} v;
313c9ce6b26STakashi Iwai };
314c9ce6b26STakashi Iwai 
31520531415SDavid Henningsson struct snd_hda_pin_quirk {
31620531415SDavid Henningsson 	unsigned int codec;             /* Codec vendor/device ID */
31720531415SDavid Henningsson 	unsigned short subvendor;	/* PCI subvendor ID */
31820531415SDavid Henningsson 	const struct hda_pintbl *pins;  /* list of matching pins */
31920531415SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
32020531415SDavid Henningsson 	const char *name;
32120531415SDavid Henningsson #endif
32220531415SDavid Henningsson 	int value;			/* quirk value */
32320531415SDavid Henningsson };
32420531415SDavid Henningsson 
325a2d2fa02SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
326a2d2fa02SDavid Henningsson 
327a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
328a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
329a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
330a2d2fa02SDavid Henningsson 	  .name = _name,\
331a2d2fa02SDavid Henningsson 	  .value = _value,\
332fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
333a2d2fa02SDavid Henningsson 	}
334a2d2fa02SDavid Henningsson #else
335a2d2fa02SDavid Henningsson 
336a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
337a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
338a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
339a2d2fa02SDavid Henningsson 	  .value = _value,\
340fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
341a2d2fa02SDavid Henningsson 	}
342a2d2fa02SDavid Henningsson 
343a2d2fa02SDavid Henningsson #endif
344a2d2fa02SDavid Henningsson 
345f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NOT_SET -1
346f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NO_FIXUP -2
347a2d2fa02SDavid Henningsson 
348c9ce6b26STakashi Iwai /* fixup types */
349c9ce6b26STakashi Iwai enum {
350c9ce6b26STakashi Iwai 	HDA_FIXUP_INVALID,
351c9ce6b26STakashi Iwai 	HDA_FIXUP_PINS,
352c9ce6b26STakashi Iwai 	HDA_FIXUP_VERBS,
353c9ce6b26STakashi Iwai 	HDA_FIXUP_FUNC,
354fd108215STakashi Iwai 	HDA_FIXUP_PINCTLS,
355c9ce6b26STakashi Iwai };
356c9ce6b26STakashi Iwai 
357c9ce6b26STakashi Iwai /* fixup action definitions */
358c9ce6b26STakashi Iwai enum {
359c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PRE_PROBE,
360c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PROBE,
361c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_INIT,
362c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_BUILD,
363360fec28SDavid Henningsson 	HDA_FIXUP_ACT_FREE,
364c9ce6b26STakashi Iwai };
365c9ce6b26STakashi Iwai 
366c9ce6b26STakashi Iwai int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
367c9ce6b26STakashi Iwai void snd_hda_apply_verbs(struct hda_codec *codec);
368c9ce6b26STakashi Iwai void snd_hda_apply_pincfgs(struct hda_codec *codec,
369c9ce6b26STakashi Iwai 			   const struct hda_pintbl *cfg);
370c9ce6b26STakashi Iwai void snd_hda_apply_fixup(struct hda_codec *codec, int action);
371c9ce6b26STakashi Iwai void snd_hda_pick_fixup(struct hda_codec *codec,
372c9ce6b26STakashi Iwai 			const struct hda_model_fixup *models,
373c9ce6b26STakashi Iwai 			const struct snd_pci_quirk *quirk,
374c9ce6b26STakashi Iwai 			const struct hda_fixup *fixlist);
37520531415SDavid Henningsson void snd_hda_pick_pin_fixup(struct hda_codec *codec,
37620531415SDavid Henningsson 			    const struct snd_hda_pin_quirk *pin_quirk,
37720531415SDavid Henningsson 			    const struct hda_fixup *fixlist);
37820531415SDavid Henningsson 
379128bc4baSTakashi Iwai /* helper macros to retrieve pin default-config values */
380d01ce99fSTakashi Iwai #define get_defcfg_connect(cfg) \
381d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
382d01ce99fSTakashi Iwai #define get_defcfg_association(cfg) \
383d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
384d01ce99fSTakashi Iwai #define get_defcfg_location(cfg) \
385d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
386d01ce99fSTakashi Iwai #define get_defcfg_sequence(cfg) \
387d01ce99fSTakashi Iwai 	(cfg & AC_DEFCFG_SEQUENCE)
388d01ce99fSTakashi Iwai #define get_defcfg_device(cfg) \
389d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
39008a1f5ebSTakashi Iwai #define get_defcfg_misc(cfg) \
39108a1f5ebSTakashi Iwai 	((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
392e9edcee0STakashi Iwai 
3938d88bc3dSTakashi Iwai /* amp values */
3948d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))
3958d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))
3968d88bc3dSTakashi Iwai #define AMP_OUT_MUTE		0xb080
3978d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE		0xb000
3988d88bc3dSTakashi Iwai #define AMP_OUT_ZERO		0xb000
3998d88bc3dSTakashi Iwai /* pinctl values */
40035e8901eSRobin H. Johnson #define PIN_IN			(AC_PINCTL_IN_EN)
40135e8901eSRobin H. Johnson #define PIN_VREFHIZ		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
40235e8901eSRobin H. Johnson #define PIN_VREF50		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
40335e8901eSRobin H. Johnson #define PIN_VREFGRD		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
40435e8901eSRobin H. Johnson #define PIN_VREF80		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
40535e8901eSRobin H. Johnson #define PIN_VREF100		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
40635e8901eSRobin H. Johnson #define PIN_OUT			(AC_PINCTL_OUT_EN)
40735e8901eSRobin H. Johnson #define PIN_HP			(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
40835e8901eSRobin H. Johnson #define PIN_HP_AMP		(AC_PINCTL_HP_EN)
4098d88bc3dSTakashi Iwai 
4104740860bSTakashi Iwai unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
41162f3a2f7STakashi Iwai unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
41262f3a2f7STakashi Iwai 				     hda_nid_t pin, unsigned int val);
413cdd03cedSTakashi Iwai int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
414cdd03cedSTakashi Iwai 			 unsigned int val, bool cached);
415cdd03cedSTakashi Iwai 
416cdd03cedSTakashi Iwai /**
417cdd03cedSTakashi Iwai  * _snd_hda_set_pin_ctl - Set a pin-control value safely
418cdd03cedSTakashi Iwai  * @codec: the codec instance
419cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
420cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
421cdd03cedSTakashi Iwai  *
422cdd03cedSTakashi Iwai  * This function sets the pin-control value to the given pin, but
423cdd03cedSTakashi Iwai  * filters out the invalid pin-control bits when the pin has no such
424cdd03cedSTakashi Iwai  * capabilities.  For example, when PIN_HP is passed but the pin has no
425cdd03cedSTakashi Iwai  * HP-drive capability, the HP bit is omitted.
426cdd03cedSTakashi Iwai  *
427cdd03cedSTakashi Iwai  * The function doesn't check the input VREF capability bits, though.
4284740860bSTakashi Iwai  * Use snd_hda_get_default_vref() to guess the right value.
429cdd03cedSTakashi Iwai  * Also, this function is only for analog pins, not for HDMI pins.
430cdd03cedSTakashi Iwai  */
431cdd03cedSTakashi Iwai static inline int
432cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
433cdd03cedSTakashi Iwai {
434cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, false);
435cdd03cedSTakashi Iwai }
436cdd03cedSTakashi Iwai 
437cdd03cedSTakashi Iwai /**
438cdd03cedSTakashi Iwai  * snd_hda_set_pin_ctl_cache - 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  * Just like snd_hda_set_pin_ctl() but write to cache as well.
444cdd03cedSTakashi Iwai  */
445cdd03cedSTakashi Iwai static inline int
446cdd03cedSTakashi Iwai snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
447cdd03cedSTakashi Iwai 			  unsigned int val)
448cdd03cedSTakashi Iwai {
449cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, true);
450cdd03cedSTakashi Iwai }
451cdd03cedSTakashi Iwai 
452d7fdc00aSTakashi Iwai int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
453d7fdc00aSTakashi Iwai int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
454d7fdc00aSTakashi Iwai 				 unsigned int val);
455d7fdc00aSTakashi Iwai 
4567639a06cSTakashi Iwai #define for_each_hda_codec_node(nid, codec) \
4577639a06cSTakashi Iwai 	for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
4587639a06cSTakashi Iwai 
45954d17403STakashi Iwai /*
46054d17403STakashi Iwai  * get widget capabilities
46154d17403STakashi Iwai  */
46254d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
46354d17403STakashi Iwai {
4647639a06cSTakashi Iwai 	if (nid < codec->core.start_nid ||
4657639a06cSTakashi Iwai 	    nid >= codec->core.start_nid + codec->core.num_nodes)
466dca008f3STakashi Iwai 		return 0;
4677639a06cSTakashi Iwai 	return codec->wcaps[nid - codec->core.start_nid];
46854d17403STakashi Iwai }
46954d17403STakashi Iwai 
470a22d543aSTakashi Iwai /* get the widget type from widget capability bits */
4713a90274dSTakashi Iwai static inline int get_wcaps_type(unsigned int wcaps)
4723a90274dSTakashi Iwai {
4733a90274dSTakashi Iwai 	if (!wcaps)
4743a90274dSTakashi Iwai 		return -1; /* invalid type */
4753a90274dSTakashi Iwai 	return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4763a90274dSTakashi Iwai }
477a22d543aSTakashi Iwai 
478fd72d008SWu Fengguang static inline unsigned int get_wcaps_channels(u32 wcaps)
479fd72d008SWu Fengguang {
480fd72d008SWu Fengguang 	unsigned int chans;
481fd72d008SWu Fengguang 
482fd72d008SWu Fengguang 	chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
483fd72d008SWu Fengguang 	chans = ((chans << 1) | 1) + 1;
484fd72d008SWu Fengguang 
485fd72d008SWu Fengguang 	return chans;
486fd72d008SWu Fengguang }
487fd72d008SWu Fengguang 
488d045c5dcSTakashi Iwai static inline void snd_hda_override_wcaps(struct hda_codec *codec,
489d045c5dcSTakashi Iwai 					  hda_nid_t nid, u32 val)
490d045c5dcSTakashi Iwai {
4917639a06cSTakashi Iwai 	if (nid >= codec->core.start_nid &&
4927639a06cSTakashi Iwai 	    nid < codec->core.start_nid + codec->core.num_nodes)
4937639a06cSTakashi Iwai 		codec->wcaps[nid - codec->core.start_nid] = val;
494d045c5dcSTakashi Iwai }
495d045c5dcSTakashi Iwai 
49609a99959SMatthew Ranostay u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
497897cc188STakashi Iwai int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
498897cc188STakashi Iwai 			      unsigned int caps);
499faa75f8aSTakashi Iwai /**
500faa75f8aSTakashi Iwai  * snd_hda_query_pin_caps - Query PIN capabilities
501faa75f8aSTakashi Iwai  * @codec: the HD-auio codec
502faa75f8aSTakashi Iwai  * @nid: the NID to query
503faa75f8aSTakashi Iwai  *
504faa75f8aSTakashi Iwai  * Query PIN capabilities for the given widget.
505faa75f8aSTakashi Iwai  * Returns the obtained capability bits.
506faa75f8aSTakashi Iwai  *
507faa75f8aSTakashi Iwai  * When cap bits have been already read, this doesn't read again but
508faa75f8aSTakashi Iwai  * returns the cached value.
509faa75f8aSTakashi Iwai  */
510faa75f8aSTakashi Iwai static inline u32
511faa75f8aSTakashi Iwai snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
512faa75f8aSTakashi Iwai {
513faa75f8aSTakashi Iwai 	return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
514faa75f8aSTakashi Iwai 
515faa75f8aSTakashi Iwai }
516faa75f8aSTakashi Iwai 
517faa75f8aSTakashi Iwai /**
518faa75f8aSTakashi Iwai  * snd_hda_override_pin_caps - Override the pin capabilities
519faa75f8aSTakashi Iwai  * @codec: the CODEC
520faa75f8aSTakashi Iwai  * @nid: the NID to override
521faa75f8aSTakashi Iwai  * @caps: the capability bits to set
522faa75f8aSTakashi Iwai  *
523faa75f8aSTakashi Iwai  * Override the cached PIN capabilitiy bits value by the given one.
524faa75f8aSTakashi Iwai  *
525faa75f8aSTakashi Iwai  * Returns zero if successful or a negative error code.
526faa75f8aSTakashi Iwai  */
527faa75f8aSTakashi Iwai static inline int
528faa75f8aSTakashi Iwai snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
529faa75f8aSTakashi Iwai 			  unsigned int caps)
530faa75f8aSTakashi Iwai {
531faa75f8aSTakashi Iwai 	return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
532faa75f8aSTakashi Iwai }
533faa75f8aSTakashi Iwai 
534861a04edSDavid Henningsson bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
535861a04edSDavid Henningsson 			   int dir, unsigned int bits);
536861a04edSDavid Henningsson 
537861a04edSDavid Henningsson #define nid_has_mute(codec, nid, dir) \
538861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
539861a04edSDavid Henningsson #define nid_has_volume(codec, nid, dir) \
540861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
541861a04edSDavid Henningsson 
54203697e2aSTakashi Iwai 
5439e3fd871SJaroslav Kysela /* flags for hda_nid_item */
5449e3fd871SJaroslav Kysela #define HDA_NID_ITEM_AMP	(1<<0)
5459e3fd871SJaroslav Kysela 
5463911a4c1SJaroslav Kysela struct hda_nid_item {
5473911a4c1SJaroslav Kysela 	struct snd_kcontrol *kctl;
5485b0cb1d8SJaroslav Kysela 	unsigned int index;
5493911a4c1SJaroslav Kysela 	hda_nid_t nid;
5509e3fd871SJaroslav Kysela 	unsigned short flags;
5513911a4c1SJaroslav Kysela };
5523911a4c1SJaroslav Kysela 
5533911a4c1SJaroslav Kysela int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
5543911a4c1SJaroslav Kysela 		    struct snd_kcontrol *kctl);
5555b0cb1d8SJaroslav Kysela int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
5565b0cb1d8SJaroslav Kysela 		    unsigned int index, hda_nid_t nid);
557d13bd412STakashi Iwai void snd_hda_ctls_clear(struct hda_codec *codec);
558d13bd412STakashi Iwai 
5592807314dSTakashi Iwai /*
5602807314dSTakashi Iwai  * hwdep interface
5612807314dSTakashi Iwai  */
562d7ffba19STakashi Iwai #ifdef CONFIG_SND_HDA_HWDEP
5632807314dSTakashi Iwai int snd_hda_create_hwdep(struct hda_codec *codec);
564d7ffba19STakashi Iwai #else
565d7ffba19STakashi Iwai static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
566d7ffba19STakashi Iwai #endif
5672807314dSTakashi Iwai 
568648a8d27STakashi Iwai void snd_hda_sysfs_init(struct hda_codec *codec);
569648a8d27STakashi Iwai void snd_hda_sysfs_clear(struct hda_codec *codec);
570648a8d27STakashi Iwai 
571648a8d27STakashi Iwai extern const struct attribute_group *snd_hda_dev_attr_groups[];
572648a8d27STakashi Iwai 
57343b62713STakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
57443b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
57543b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
576bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
57743b62713STakashi Iwai #else
57843b62713STakashi Iwai static inline
57943b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
58043b62713STakashi Iwai {
58143b62713STakashi Iwai 	return NULL;
58243b62713STakashi Iwai }
58343b62713STakashi Iwai 
58443b62713STakashi Iwai static inline
58543b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
58643b62713STakashi Iwai {
58743b62713STakashi Iwai 	return -ENOENT;
58843b62713STakashi Iwai }
589bc759721STakashi Iwai 
590bc759721STakashi Iwai static inline
591bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
592bc759721STakashi Iwai {
593bc759721STakashi Iwai 	return -ENOENT;
594bc759721STakashi Iwai }
59543b62713STakashi Iwai #endif
59643b62713STakashi Iwai 
597cb53c626STakashi Iwai /*
598cb53c626STakashi Iwai  * power-management
599cb53c626STakashi Iwai  */
600cb53c626STakashi Iwai 
601cb53c626STakashi Iwai void snd_hda_schedule_power_save(struct hda_codec *codec);
602cb53c626STakashi Iwai 
603cb53c626STakashi Iwai struct hda_amp_list {
604cb53c626STakashi Iwai 	hda_nid_t nid;
605cb53c626STakashi Iwai 	unsigned char dir;
606cb53c626STakashi Iwai 	unsigned char idx;
607cb53c626STakashi Iwai };
608cb53c626STakashi Iwai 
609cb53c626STakashi Iwai struct hda_loopback_check {
610031024eeSTakashi Iwai 	const struct hda_amp_list *amplist;
611cb53c626STakashi Iwai 	int power_on;
612cb53c626STakashi Iwai };
613cb53c626STakashi Iwai 
614cb53c626STakashi Iwai int snd_hda_check_amp_list_power(struct hda_codec *codec,
615cb53c626STakashi Iwai 				 struct hda_loopback_check *check,
616cb53c626STakashi Iwai 				 hda_nid_t nid);
617cb53c626STakashi Iwai 
6189040d102STakashi Iwai /* check whether the actual power state matches with the target state */
6199040d102STakashi Iwai static inline bool
6209040d102STakashi Iwai snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
6219040d102STakashi Iwai 			  unsigned int target_state)
6229040d102STakashi Iwai {
62370b4891cSVinod Koul 	return snd_hdac_check_power_state(&codec->core, nid, target_state);
6249040d102STakashi Iwai }
625*009f8c90SLukas Wunner 
626*009f8c90SLukas Wunner static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
627*009f8c90SLukas Wunner 						    hda_nid_t nid,
628*009f8c90SLukas Wunner 						    unsigned int target_state)
6293b5b899cSAbhijeet Kumar {
6303b5b899cSAbhijeet Kumar 	return snd_hdac_sync_power_state(&codec->core, nid, target_state);
6313b5b899cSAbhijeet Kumar }
632ba615b86STakashi Iwai unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
633ba615b86STakashi Iwai 					     hda_nid_t nid,
634ba615b86STakashi Iwai 					     unsigned int power_state);
635ba615b86STakashi Iwai 
63689385035SMatthew Ranostay /*
63789385035SMatthew Ranostay  * AMP control callbacks
63889385035SMatthew Ranostay  */
63989385035SMatthew Ranostay /* retrieve parameters from private_value */
6403911a4c1SJaroslav Kysela #define get_amp_nid_(pv)	((pv) & 0xffff)
6413911a4c1SJaroslav Kysela #define get_amp_nid(kc)		get_amp_nid_((kc)->private_value)
64289385035SMatthew Ranostay #define get_amp_channels(kc)	(((kc)->private_value >> 16) & 0x3)
643527e4d73STakashi Iwai #define get_amp_direction_(pv)	(((pv) >> 18) & 0x1)
644527e4d73STakashi Iwai #define get_amp_direction(kc)	get_amp_direction_((kc)->private_value)
645130e5f06STakashi Iwai #define get_amp_index_(pv)	(((pv) >> 19) & 0xf)
646130e5f06STakashi Iwai #define get_amp_index(kc)	get_amp_index_((kc)->private_value)
64729fdbec2STakashi Iwai #define get_amp_offset(kc)	(((kc)->private_value >> 23) & 0x3f)
648de8c85f7SClemens Ladisch #define get_amp_min_mute(kc)	(((kc)->private_value >> 29) & 0x1)
64989385035SMatthew Ranostay 
6507f4a9f43SWu Fengguang /*
651dda415d4STakashi Iwai  * enum control helper
652dda415d4STakashi Iwai  */
653dda415d4STakashi Iwai int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
654dda415d4STakashi Iwai 			     struct snd_ctl_elem_info *uinfo,
655dda415d4STakashi Iwai 			     int num_entries, const char * const *texts);
656dda415d4STakashi Iwai #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
657dda415d4STakashi Iwai 	snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
658dda415d4STakashi Iwai 
659dda415d4STakashi Iwai /*
6607f4a9f43SWu Fengguang  * CEA Short Audio Descriptor data
6617f4a9f43SWu Fengguang  */
6627f4a9f43SWu Fengguang struct cea_sad {
6637f4a9f43SWu Fengguang 	int	channels;
6647f4a9f43SWu Fengguang 	int	format;		/* (format == 0) indicates invalid SAD */
6657f4a9f43SWu Fengguang 	int	rates;
6667f4a9f43SWu Fengguang 	int	sample_bits;	/* for LPCM */
6677f4a9f43SWu Fengguang 	int	max_bitrate;	/* for AC3...ATRAC */
6687f4a9f43SWu Fengguang 	int	profile;	/* for WMAPRO */
6697f4a9f43SWu Fengguang };
6707f4a9f43SWu Fengguang 
6717f4a9f43SWu Fengguang #define ELD_FIXED_BYTES	20
67214bc52b8SPierre-Louis Bossart #define ELD_MAX_SIZE    256
6737f4a9f43SWu Fengguang #define ELD_MAX_MNL	16
6747f4a9f43SWu Fengguang #define ELD_MAX_SAD	16
6757f4a9f43SWu Fengguang 
6767f4a9f43SWu Fengguang /*
6777f4a9f43SWu Fengguang  * ELD: EDID Like Data
6787f4a9f43SWu Fengguang  */
6791613d6b4SDavid Henningsson struct parsed_hdmi_eld {
6801613d6b4SDavid Henningsson 	/*
6811613d6b4SDavid Henningsson 	 * all fields will be cleared before updating ELD
6821613d6b4SDavid Henningsson 	 */
6837f4a9f43SWu Fengguang 	int	baseline_len;
68423ccc2bdSWu Fengguang 	int	eld_ver;
6857f4a9f43SWu Fengguang 	int	cea_edid_ver;
6867f4a9f43SWu Fengguang 	char	monitor_name[ELD_MAX_MNL + 1];
6877f4a9f43SWu Fengguang 	int	manufacture_id;
6887f4a9f43SWu Fengguang 	int	product_id;
6897f4a9f43SWu Fengguang 	u64	port_id;
6907f4a9f43SWu Fengguang 	int	support_hdcp;
6917f4a9f43SWu Fengguang 	int	support_ai;
6927f4a9f43SWu Fengguang 	int	conn_type;
6937f4a9f43SWu Fengguang 	int	aud_synch_delay;
6947f4a9f43SWu Fengguang 	int	spk_alloc;
6957f4a9f43SWu Fengguang 	int	sad_count;
6967f4a9f43SWu Fengguang 	struct cea_sad sad[ELD_MAX_SAD];
6971613d6b4SDavid Henningsson };
6981613d6b4SDavid Henningsson 
6991613d6b4SDavid Henningsson struct hdmi_eld {
7001613d6b4SDavid Henningsson 	bool	monitor_present;
7011613d6b4SDavid Henningsson 	bool	eld_valid;
7021613d6b4SDavid Henningsson 	int	eld_size;
70314bc52b8SPierre-Louis Bossart 	char    eld_buffer[ELD_MAX_SIZE];
7041613d6b4SDavid Henningsson 	struct parsed_hdmi_eld info;
7057f4a9f43SWu Fengguang };
7067f4a9f43SWu Fengguang 
7077f4a9f43SWu Fengguang int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
7081613d6b4SDavid Henningsson int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
7091613d6b4SDavid Henningsson 		     unsigned char *buf, int *eld_size);
71079514d47STakashi Iwai int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
7111613d6b4SDavid Henningsson 		       const unsigned char *buf, int size);
71279514d47STakashi Iwai void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
7131613d6b4SDavid Henningsson void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
7142def8172SStephen Warren 			      struct hda_pcm_stream *hinfo);
7157f4a9f43SWu Fengguang 
71689250f84SAnssi Hannula int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
71789250f84SAnssi Hannula 			 unsigned char *buf, int *eld_size,
71889250f84SAnssi Hannula 			 bool rev3_or_later);
71989250f84SAnssi Hannula 
720cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
721a4e9a38bSTakashi Iwai void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
722a4e9a38bSTakashi Iwai 			     struct snd_info_buffer *buffer);
723a4e9a38bSTakashi Iwai void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
724a4e9a38bSTakashi Iwai 			     struct snd_info_buffer *buffer);
7255f1e71b1SWu Fengguang #endif
7265f1e71b1SWu Fengguang 
727903b21d8SWu Fengguang #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
728903b21d8SWu Fengguang void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
729903b21d8SWu Fengguang 
7304e76a883STakashi Iwai /*
7314e76a883STakashi Iwai  */
732d8a766a1STakashi Iwai #define codec_err(codec, fmt, args...) \
733d8a766a1STakashi Iwai 	dev_err(hda_codec_dev(codec), fmt, ##args)
734d8a766a1STakashi Iwai #define codec_warn(codec, fmt, args...) \
735d8a766a1STakashi Iwai 	dev_warn(hda_codec_dev(codec), fmt, ##args)
736d8a766a1STakashi Iwai #define codec_info(codec, fmt, args...) \
737d8a766a1STakashi Iwai 	dev_info(hda_codec_dev(codec), fmt, ##args)
738d8a766a1STakashi Iwai #define codec_dbg(codec, fmt, args...) \
739d8a766a1STakashi Iwai 	dev_dbg(hda_codec_dev(codec), fmt, ##args)
7404e76a883STakashi Iwai 
7411da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
742