xref: /openbmc/linux/sound/pci/hda/hda_local.h (revision 3911a4c19e927738766003839aa447becbdbaa27)
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 
261da177e4SLinus Torvalds /*
271da177e4SLinus Torvalds  * for mixer controls
281da177e4SLinus Torvalds  */
2929fdbec2STakashi Iwai #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs)		\
3029fdbec2STakashi Iwai 	((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
31d01ce99fSTakashi Iwai #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
3229fdbec2STakashi Iwai 	HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
33985be54bSTakashi Iwai /* mono volume with index (index=0,1,...) (channel=1,2) */
341da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
351da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx,  \
36302e9c5aSJaroslav Kysela 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
37302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
38302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
391da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_volume_info, \
401da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_volume_get, \
411da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_volume_put, \
427cf0a953STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_amp_tlv },		\
431da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
44985be54bSTakashi Iwai /* stereo volume with index */
451da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
461da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
47985be54bSTakashi Iwai /* mono volume */
481da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
491da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction)
50985be54bSTakashi Iwai /* stereo volume */
511da177e4SLinus Torvalds #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
521da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
53985be54bSTakashi Iwai /* mono mute switch with index (index=0,1,...) (channel=1,2) */
541da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
551da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
561da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_switch_info, \
571da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_switch_get, \
581da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_switch_put, \
591da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
60985be54bSTakashi Iwai /* stereo mute switch with index */
611da177e4SLinus Torvalds #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
621da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
63985be54bSTakashi Iwai /* mono mute switch */
641da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
651da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
66985be54bSTakashi Iwai /* stereo mute switch */
671da177e4SLinus Torvalds #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
681da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
69123c07aeSJaroslav Kysela /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
70123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
71123c07aeSJaroslav Kysela 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
72123c07aeSJaroslav Kysela 	  .info = snd_hda_mixer_amp_switch_info, \
73123c07aeSJaroslav Kysela 	  .get = snd_hda_mixer_amp_switch_get, \
74123c07aeSJaroslav Kysela 	  .put = snd_hda_mixer_amp_switch_put_beep, \
75123c07aeSJaroslav Kysela 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
76123c07aeSJaroslav Kysela /* special beep mono mute switch */
77123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
78123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
79123c07aeSJaroslav Kysela /* special beep stereo mute switch */
80123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
81123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
821da177e4SLinus Torvalds 
83d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
84d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
85d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
86d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
87d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
88d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
89d01ce99fSTakashi Iwai int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
90d01ce99fSTakashi Iwai 			  unsigned int size, unsigned int __user *tlv);
91d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
92d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
93d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
94d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
95d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
96d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
97123c07aeSJaroslav Kysela int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
98123c07aeSJaroslav Kysela 				      struct snd_ctl_elem_value *ucontrol);
99834be88dSTakashi Iwai /* lowlevel accessor with caching; use carefully */
100834be88dSTakashi Iwai int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
101834be88dSTakashi Iwai 			   int direction, int index);
102834be88dSTakashi Iwai int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
103834be88dSTakashi Iwai 			     int direction, int idx, int mask, int val);
10447fd830aSTakashi Iwai int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
10547fd830aSTakashi Iwai 			     int dir, int idx, int mask, int val);
106cb53c626STakashi Iwai #ifdef SND_HDA_NEEDS_RESUME
107b3ac5636STakashi Iwai void snd_hda_codec_resume_amp(struct hda_codec *codec);
10882beb8fdSTakashi Iwai #endif
1091da177e4SLinus Torvalds 
1102134ea4fSTakashi Iwai void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1112134ea4fSTakashi Iwai 			     unsigned int *tlv);
1122134ea4fSTakashi Iwai struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1132134ea4fSTakashi Iwai 					    const char *name);
1142134ea4fSTakashi Iwai int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1152134ea4fSTakashi Iwai 			unsigned int *tlv, const char **slaves);
116a65d629cSTakashi Iwai int snd_hda_codec_reset(struct hda_codec *codec);
1172134ea4fSTakashi Iwai 
11847fd830aSTakashi Iwai /* amp value bits */
11947fd830aSTakashi Iwai #define HDA_AMP_MUTE	0x80
12047fd830aSTakashi Iwai #define HDA_AMP_UNMUTE	0x00
12147fd830aSTakashi Iwai #define HDA_AMP_VOLMASK	0x7f
12247fd830aSTakashi Iwai 
123985be54bSTakashi Iwai /* mono switch binding multiple inputs */
124985be54bSTakashi Iwai #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
125985be54bSTakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
126985be54bSTakashi Iwai 	  .info = snd_hda_mixer_amp_switch_info, \
127985be54bSTakashi Iwai 	  .get = snd_hda_mixer_bind_switch_get, \
128985be54bSTakashi Iwai 	  .put = snd_hda_mixer_bind_switch_put, \
129985be54bSTakashi Iwai 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
130985be54bSTakashi Iwai 
131985be54bSTakashi Iwai /* stereo switch binding multiple inputs */
132d01ce99fSTakashi Iwai #define HDA_BIND_MUTE(xname,nid,indices,dir) \
133d01ce99fSTakashi Iwai 	HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
134985be54bSTakashi Iwai 
135d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
136d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
137d01ce99fSTakashi Iwai int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
138d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_value *ucontrol);
139985be54bSTakashi Iwai 
140532d5381STakashi Iwai /* more generic bound controls */
141532d5381STakashi Iwai struct hda_ctl_ops {
142532d5381STakashi Iwai 	snd_kcontrol_info_t *info;
143532d5381STakashi Iwai 	snd_kcontrol_get_t *get;
144532d5381STakashi Iwai 	snd_kcontrol_put_t *put;
145532d5381STakashi Iwai 	snd_kcontrol_tlv_rw_t *tlv;
146532d5381STakashi Iwai };
147532d5381STakashi Iwai 
148532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_vol;	/* for bind-volume with TLV */
149532d5381STakashi Iwai extern struct hda_ctl_ops snd_hda_bind_sw;	/* for bind-switch */
150532d5381STakashi Iwai 
151532d5381STakashi Iwai struct hda_bind_ctls {
152532d5381STakashi Iwai 	struct hda_ctl_ops *ops;
1535d9b6c07SHannes Eder 	unsigned long values[];
154532d5381STakashi Iwai };
155532d5381STakashi Iwai 
156532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
157532d5381STakashi Iwai 				 struct snd_ctl_elem_info *uinfo);
158532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
159532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
160532d5381STakashi Iwai int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
161532d5381STakashi Iwai 				struct snd_ctl_elem_value *ucontrol);
162532d5381STakashi Iwai int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
163532d5381STakashi Iwai 			   unsigned int size, unsigned int __user *tlv);
164532d5381STakashi Iwai 
165532d5381STakashi Iwai #define HDA_BIND_VOL(xname, bindrec) \
166532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
167532d5381STakashi Iwai 	  .name = xname, \
168532d5381STakashi Iwai 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
169532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
170532d5381STakashi Iwai 			  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,\
171532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
172532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
173532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
174532d5381STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_bind_tlv },\
175532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
176532d5381STakashi Iwai #define HDA_BIND_SW(xname, bindrec) \
177532d5381STakashi Iwai 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
178532d5381STakashi Iwai 	  .name = xname, \
179532d5381STakashi Iwai 	  .info = snd_hda_mixer_bind_ctls_info,\
180532d5381STakashi Iwai 	  .get =  snd_hda_mixer_bind_ctls_get,\
181532d5381STakashi Iwai 	  .put = snd_hda_mixer_bind_ctls_put,\
182532d5381STakashi Iwai 	  .private_value = (long) (bindrec) }
183532d5381STakashi Iwai 
184532d5381STakashi Iwai /*
185532d5381STakashi Iwai  * SPDIF I/O
186532d5381STakashi Iwai  */
1871da177e4SLinus Torvalds int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
1881da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds /*
1911da177e4SLinus Torvalds  * input MUX helper
1921da177e4SLinus Torvalds  */
19354d17403STakashi Iwai #define HDA_MAX_NUM_INPUTS	16
1941da177e4SLinus Torvalds struct hda_input_mux_item {
1951da177e4SLinus Torvalds 	const char *label;
1961da177e4SLinus Torvalds 	unsigned int index;
1971da177e4SLinus Torvalds };
1981da177e4SLinus Torvalds struct hda_input_mux {
1991da177e4SLinus Torvalds 	unsigned int num_items;
2001da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
2011da177e4SLinus Torvalds };
2021da177e4SLinus Torvalds 
203d01ce99fSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux,
204d01ce99fSTakashi Iwai 			   struct snd_ctl_elem_info *uinfo);
205d01ce99fSTakashi Iwai int snd_hda_input_mux_put(struct hda_codec *codec,
206d01ce99fSTakashi Iwai 			  const struct hda_input_mux *imux,
207c8b6bf9bSTakashi Iwai 			  struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
2081da177e4SLinus Torvalds 			  unsigned int *cur_val);
2091da177e4SLinus Torvalds 
210d2a6d7dcSTakashi Iwai /*
211d2a6d7dcSTakashi Iwai  * Channel mode helper
212d2a6d7dcSTakashi Iwai  */
213d2a6d7dcSTakashi Iwai struct hda_channel_mode {
214d2a6d7dcSTakashi Iwai 	int channels;
215d2a6d7dcSTakashi Iwai 	const struct hda_verb *sequence;
216d2a6d7dcSTakashi Iwai };
217d2a6d7dcSTakashi Iwai 
218d01ce99fSTakashi Iwai int snd_hda_ch_mode_info(struct hda_codec *codec,
219d01ce99fSTakashi Iwai 			 struct snd_ctl_elem_info *uinfo,
220d01ce99fSTakashi Iwai 			 const struct hda_channel_mode *chmode,
221d01ce99fSTakashi Iwai 			 int num_chmodes);
222d01ce99fSTakashi Iwai int snd_hda_ch_mode_get(struct hda_codec *codec,
223d01ce99fSTakashi Iwai 			struct snd_ctl_elem_value *ucontrol,
224d01ce99fSTakashi Iwai 			const struct hda_channel_mode *chmode,
225d01ce99fSTakashi Iwai 			int num_chmodes,
226d2a6d7dcSTakashi Iwai 			int max_channels);
227d01ce99fSTakashi Iwai int snd_hda_ch_mode_put(struct hda_codec *codec,
228d01ce99fSTakashi Iwai 			struct snd_ctl_elem_value *ucontrol,
229d01ce99fSTakashi Iwai 			const struct hda_channel_mode *chmode,
230d01ce99fSTakashi Iwai 			int num_chmodes,
231d2a6d7dcSTakashi Iwai 			int *max_channelsp);
232d2a6d7dcSTakashi Iwai 
2331da177e4SLinus Torvalds /*
2341da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
2351da177e4SLinus Torvalds  */
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
2381da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds struct hda_multi_out {
2411da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
2421da177e4SLinus Torvalds 	hda_nid_t *dac_nids;	/* DAC list */
2431da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
24482bc955fSTakashi Iwai 	hda_nid_t extra_out_nid[3];	/* optional DACs, 0 when not exists */
2451da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
246b25c9da1SWu Fengguang 	hda_nid_t *slave_dig_outs;
2471da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
2481da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
249d29240ceSTakashi Iwai 	int no_share_stream;	/* don't share a stream with multiple pins */
2509a08160bSTakashi Iwai 	int share_spdif;	/* share SPDIF pin */
2519a08160bSTakashi Iwai 	/* PCM information for both analog and SPDIF DACs */
2529a08160bSTakashi Iwai 	unsigned int analog_rates;
2539a08160bSTakashi Iwai 	unsigned int analog_maxbps;
2549a08160bSTakashi Iwai 	u64 analog_formats;
2559a08160bSTakashi Iwai 	unsigned int spdif_rates;
2569a08160bSTakashi Iwai 	unsigned int spdif_maxbps;
2579a08160bSTakashi Iwai 	u64 spdif_formats;
2581da177e4SLinus Torvalds };
2591da177e4SLinus Torvalds 
2609a08160bSTakashi Iwai int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2619a08160bSTakashi Iwai 				  struct hda_multi_out *mout);
262d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_open(struct hda_codec *codec,
263d01ce99fSTakashi Iwai 			       struct hda_multi_out *mout);
264d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_close(struct hda_codec *codec,
265d01ce99fSTakashi Iwai 				struct hda_multi_out *mout);
2666b97eb45STakashi Iwai int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2676b97eb45STakashi Iwai 				  struct hda_multi_out *mout,
2686b97eb45STakashi Iwai 				  unsigned int stream_tag,
2696b97eb45STakashi Iwai 				  unsigned int format,
2706b97eb45STakashi Iwai 				  struct snd_pcm_substream *substream);
2719411e21cSTakashi Iwai int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
2729411e21cSTakashi Iwai 				  struct hda_multi_out *mout);
273d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_open(struct hda_codec *codec,
274d01ce99fSTakashi Iwai 				  struct hda_multi_out *mout,
2759a08160bSTakashi Iwai 				  struct snd_pcm_substream *substream,
2769a08160bSTakashi Iwai 				  struct hda_pcm_stream *hinfo);
277d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
278d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout,
2791da177e4SLinus Torvalds 				     unsigned int stream_tag,
2801da177e4SLinus Torvalds 				     unsigned int format,
281c8b6bf9bSTakashi Iwai 				     struct snd_pcm_substream *substream);
282d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
283d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout);
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds /*
2861da177e4SLinus Torvalds  * generic codec parser
2871da177e4SLinus Torvalds  */
28835a1e0ccSTakashi Iwai #ifdef CONFIG_SND_HDA_GENERIC
2891da177e4SLinus Torvalds int snd_hda_parse_generic_codec(struct hda_codec *codec);
29035a1e0ccSTakashi Iwai #else
29135a1e0ccSTakashi Iwai static inline int snd_hda_parse_generic_codec(struct hda_codec *codec)
29235a1e0ccSTakashi Iwai {
29335a1e0ccSTakashi Iwai 	return -ENODEV;
29435a1e0ccSTakashi Iwai }
29535a1e0ccSTakashi Iwai #endif
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds /*
2981da177e4SLinus Torvalds  * generic proc interface
2991da177e4SLinus Torvalds  */
3001da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
3011da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
3021da177e4SLinus Torvalds #else
3031da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
3041da177e4SLinus Torvalds #endif
3051da177e4SLinus Torvalds 
30633deeca3SWu Fengguang #define SND_PRINT_RATES_ADVISED_BUFSIZE	80
30733deeca3SWu Fengguang void snd_print_pcm_rates(int pcm, char *buf, int buflen);
30833deeca3SWu Fengguang 
309d39b4352SWu Fengguang #define SND_PRINT_BITS_ADVISED_BUFSIZE	16
310d39b4352SWu Fengguang void snd_print_pcm_bits(int pcm, char *buf, int buflen);
311d39b4352SWu Fengguang 
3121da177e4SLinus Torvalds /*
3131da177e4SLinus Torvalds  * Misc
3141da177e4SLinus Torvalds  */
315f5fcc13cSTakashi Iwai int snd_hda_check_board_config(struct hda_codec *codec, int num_configs,
316f5fcc13cSTakashi Iwai 			       const char **modelnames,
317f5fcc13cSTakashi Iwai 			       const struct snd_pci_quirk *pci_list);
3182eda3445SMauro Carvalho Chehab int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
3192eda3445SMauro Carvalho Chehab                                int num_configs, const char **models,
3202eda3445SMauro Carvalho Chehab                                const struct snd_pci_quirk *tbl);
321d01ce99fSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec,
322d01ce99fSTakashi Iwai 			 struct snd_kcontrol_new *knew);
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds /*
3251da177e4SLinus Torvalds  * unsolicited event handler
3261da177e4SLinus Torvalds  */
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds #define HDA_UNSOL_QUEUE_SIZE	64
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds struct hda_bus_unsolicited {
3311da177e4SLinus Torvalds 	/* ring buffer */
3321da177e4SLinus Torvalds 	u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
3331da177e4SLinus Torvalds 	unsigned int rp, wp;
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	/* workqueue */
3361da177e4SLinus Torvalds 	struct work_struct work;
337c4028958SDavid Howells 	struct hda_bus *bus;
3381da177e4SLinus Torvalds };
3391da177e4SLinus Torvalds 
340e9edcee0STakashi Iwai /*
341e9edcee0STakashi Iwai  * Helper for automatic ping configuration
342e9edcee0STakashi Iwai  */
343e9edcee0STakashi Iwai 
344e9edcee0STakashi Iwai enum {
345e9edcee0STakashi Iwai 	AUTO_PIN_MIC,
346e9edcee0STakashi Iwai 	AUTO_PIN_FRONT_MIC,
347e9edcee0STakashi Iwai 	AUTO_PIN_LINE,
348e9edcee0STakashi Iwai 	AUTO_PIN_FRONT_LINE,
349e9edcee0STakashi Iwai 	AUTO_PIN_CD,
350e9edcee0STakashi Iwai 	AUTO_PIN_AUX,
351e9edcee0STakashi Iwai 	AUTO_PIN_LAST
352e9edcee0STakashi Iwai };
353e9edcee0STakashi Iwai 
354d258e24aSTakashi Iwai enum {
355d258e24aSTakashi Iwai 	AUTO_PIN_LINE_OUT,
356d258e24aSTakashi Iwai 	AUTO_PIN_SPEAKER_OUT,
357d258e24aSTakashi Iwai 	AUTO_PIN_HP_OUT
358d258e24aSTakashi Iwai };
359d258e24aSTakashi Iwai 
3604a471b7dSTakashi Iwai extern const char *auto_pin_cfg_labels[AUTO_PIN_LAST];
3614a471b7dSTakashi Iwai 
36241923e44STakashi Iwai #define AUTO_CFG_MAX_OUTS	5
36341923e44STakashi Iwai 
364e9edcee0STakashi Iwai struct auto_pin_cfg {
365e9edcee0STakashi Iwai 	int line_outs;
36641923e44STakashi Iwai 	/* sorted in the order of Front/Surr/CLFE/Side */
36741923e44STakashi Iwai 	hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
36882bc955fSTakashi Iwai 	int speaker_outs;
36941923e44STakashi Iwai 	hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
370eb06ed8fSTakashi Iwai 	int hp_outs;
371d258e24aSTakashi Iwai 	int line_out_type;	/* AUTO_PIN_XXX_OUT */
37241923e44STakashi Iwai 	hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
373e9edcee0STakashi Iwai 	hda_nid_t input_pins[AUTO_PIN_LAST];
3740852d7a6STakashi Iwai 	int dig_outs;
3750852d7a6STakashi Iwai 	hda_nid_t dig_out_pins[2];
376e9edcee0STakashi Iwai 	hda_nid_t dig_in_pin;
37790da78bfSMatthew Ranostay 	hda_nid_t mono_out_pin;
3780852d7a6STakashi Iwai 	int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
3792297bd6eSTakashi Iwai 	int dig_in_type; /* HDA_PCM_TYPE_XXX */
380e9edcee0STakashi Iwai };
381e9edcee0STakashi Iwai 
382d01ce99fSTakashi Iwai #define get_defcfg_connect(cfg) \
383d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
384d01ce99fSTakashi Iwai #define get_defcfg_association(cfg) \
385d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
386d01ce99fSTakashi Iwai #define get_defcfg_location(cfg) \
387d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
388d01ce99fSTakashi Iwai #define get_defcfg_sequence(cfg) \
389d01ce99fSTakashi Iwai 	(cfg & AC_DEFCFG_SEQUENCE)
390d01ce99fSTakashi Iwai #define get_defcfg_device(cfg) \
391d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
392e9edcee0STakashi Iwai 
393d01ce99fSTakashi Iwai int snd_hda_parse_pin_def_config(struct hda_codec *codec,
394d01ce99fSTakashi Iwai 				 struct auto_pin_cfg *cfg,
395df694daaSKailang Yang 				 hda_nid_t *ignore_nids);
396e9edcee0STakashi Iwai 
3978d88bc3dSTakashi Iwai /* amp values */
3988d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))
3998d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))
4008d88bc3dSTakashi Iwai #define AMP_OUT_MUTE		0xb080
4018d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE		0xb000
4028d88bc3dSTakashi Iwai #define AMP_OUT_ZERO		0xb000
4038d88bc3dSTakashi Iwai /* pinctl values */
40435e8901eSRobin H. Johnson #define PIN_IN			(AC_PINCTL_IN_EN)
40535e8901eSRobin H. Johnson #define PIN_VREFHIZ		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
40635e8901eSRobin H. Johnson #define PIN_VREF50		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
40735e8901eSRobin H. Johnson #define PIN_VREFGRD		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
40835e8901eSRobin H. Johnson #define PIN_VREF80		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
40935e8901eSRobin H. Johnson #define PIN_VREF100		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
41035e8901eSRobin H. Johnson #define PIN_OUT			(AC_PINCTL_OUT_EN)
41135e8901eSRobin H. Johnson #define PIN_HP			(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
41235e8901eSRobin H. Johnson #define PIN_HP_AMP		(AC_PINCTL_HP_EN)
4138d88bc3dSTakashi Iwai 
41454d17403STakashi Iwai /*
41554d17403STakashi Iwai  * get widget capabilities
41654d17403STakashi Iwai  */
41754d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
41854d17403STakashi Iwai {
41954d17403STakashi Iwai 	if (nid < codec->start_nid ||
42054d17403STakashi Iwai 	    nid >= codec->start_nid + codec->num_nodes)
421dca008f3STakashi Iwai 		return 0;
42254d17403STakashi Iwai 	return codec->wcaps[nid - codec->start_nid];
42354d17403STakashi Iwai }
42454d17403STakashi Iwai 
425a22d543aSTakashi Iwai /* get the widget type from widget capability bits */
426a22d543aSTakashi Iwai #define get_wcaps_type(wcaps) (((wcaps) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT)
427a22d543aSTakashi Iwai 
428fd72d008SWu Fengguang static inline unsigned int get_wcaps_channels(u32 wcaps)
429fd72d008SWu Fengguang {
430fd72d008SWu Fengguang 	unsigned int chans;
431fd72d008SWu Fengguang 
432fd72d008SWu Fengguang 	chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
433fd72d008SWu Fengguang 	chans = ((chans << 1) | 1) + 1;
434fd72d008SWu Fengguang 
435fd72d008SWu Fengguang 	return chans;
436fd72d008SWu Fengguang }
437fd72d008SWu Fengguang 
43809a99959SMatthew Ranostay u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
439897cc188STakashi Iwai int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
440897cc188STakashi Iwai 			      unsigned int caps);
4411327a32bSTakashi Iwai u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
44254d17403STakashi Iwai 
443*3911a4c1SJaroslav Kysela struct hda_nid_item {
444*3911a4c1SJaroslav Kysela 	struct snd_kcontrol *kctl;
445*3911a4c1SJaroslav Kysela 	hda_nid_t nid;
446*3911a4c1SJaroslav Kysela };
447*3911a4c1SJaroslav Kysela 
448*3911a4c1SJaroslav Kysela int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
449*3911a4c1SJaroslav Kysela 		    struct snd_kcontrol *kctl);
450d13bd412STakashi Iwai void snd_hda_ctls_clear(struct hda_codec *codec);
451d13bd412STakashi Iwai 
4522807314dSTakashi Iwai /*
4532807314dSTakashi Iwai  * hwdep interface
4542807314dSTakashi Iwai  */
455d7ffba19STakashi Iwai #ifdef CONFIG_SND_HDA_HWDEP
4562807314dSTakashi Iwai int snd_hda_create_hwdep(struct hda_codec *codec);
457d7ffba19STakashi Iwai #else
458d7ffba19STakashi Iwai static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
459d7ffba19STakashi Iwai #endif
4602807314dSTakashi Iwai 
4617288561aSTakashi Iwai #if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
462a2f6309eSTakashi Iwai int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
463a2f6309eSTakashi Iwai #else
464a2f6309eSTakashi Iwai static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
465a2f6309eSTakashi Iwai {
466a2f6309eSTakashi Iwai 	return 0;
467a2f6309eSTakashi Iwai }
468a2f6309eSTakashi Iwai #endif
469a2f6309eSTakashi Iwai 
470e7ee058cSTakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
471e7ee058cSTakashi Iwai int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
472e7ee058cSTakashi Iwai #else
473e7ee058cSTakashi Iwai static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
474e7ee058cSTakashi Iwai {
475e7ee058cSTakashi Iwai 	return 0;
476e7ee058cSTakashi Iwai }
477e7ee058cSTakashi Iwai #endif
478e7ee058cSTakashi Iwai 
47943b62713STakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
48043b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
48143b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
48243b62713STakashi Iwai #else
48343b62713STakashi Iwai static inline
48443b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
48543b62713STakashi Iwai {
48643b62713STakashi Iwai 	return NULL;
48743b62713STakashi Iwai }
48843b62713STakashi Iwai 
48943b62713STakashi Iwai static inline
49043b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
49143b62713STakashi Iwai {
49243b62713STakashi Iwai 	return -ENOENT;
49343b62713STakashi Iwai }
49443b62713STakashi Iwai #endif
49543b62713STakashi Iwai 
496cb53c626STakashi Iwai /*
497cb53c626STakashi Iwai  * power-management
498cb53c626STakashi Iwai  */
499cb53c626STakashi Iwai 
500cb53c626STakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
501cb53c626STakashi Iwai void snd_hda_schedule_power_save(struct hda_codec *codec);
502cb53c626STakashi Iwai 
503cb53c626STakashi Iwai struct hda_amp_list {
504cb53c626STakashi Iwai 	hda_nid_t nid;
505cb53c626STakashi Iwai 	unsigned char dir;
506cb53c626STakashi Iwai 	unsigned char idx;
507cb53c626STakashi Iwai };
508cb53c626STakashi Iwai 
509cb53c626STakashi Iwai struct hda_loopback_check {
510cb53c626STakashi Iwai 	struct hda_amp_list *amplist;
511cb53c626STakashi Iwai 	int power_on;
512cb53c626STakashi Iwai };
513cb53c626STakashi Iwai 
514cb53c626STakashi Iwai int snd_hda_check_amp_list_power(struct hda_codec *codec,
515cb53c626STakashi Iwai 				 struct hda_loopback_check *check,
516cb53c626STakashi Iwai 				 hda_nid_t nid);
517cb53c626STakashi Iwai #endif /* CONFIG_SND_HDA_POWER_SAVE */
518cb53c626STakashi Iwai 
51989385035SMatthew Ranostay /*
52089385035SMatthew Ranostay  * AMP control callbacks
52189385035SMatthew Ranostay  */
52289385035SMatthew Ranostay /* retrieve parameters from private_value */
523*3911a4c1SJaroslav Kysela #define get_amp_nid_(pv)	((pv) & 0xffff)
524*3911a4c1SJaroslav Kysela #define get_amp_nid(kc)		get_amp_nid_((kc)->private_value)
52589385035SMatthew Ranostay #define get_amp_channels(kc)	(((kc)->private_value >> 16) & 0x3)
52689385035SMatthew Ranostay #define get_amp_direction(kc)	(((kc)->private_value >> 18) & 0x1)
52789385035SMatthew Ranostay #define get_amp_index(kc)	(((kc)->private_value >> 19) & 0xf)
52829fdbec2STakashi Iwai #define get_amp_offset(kc)	(((kc)->private_value >> 23) & 0x3f)
52989385035SMatthew Ranostay 
5307f4a9f43SWu Fengguang /*
5317f4a9f43SWu Fengguang  * CEA Short Audio Descriptor data
5327f4a9f43SWu Fengguang  */
5337f4a9f43SWu Fengguang struct cea_sad {
5347f4a9f43SWu Fengguang 	int	channels;
5357f4a9f43SWu Fengguang 	int	format;		/* (format == 0) indicates invalid SAD */
5367f4a9f43SWu Fengguang 	int	rates;
5377f4a9f43SWu Fengguang 	int	sample_bits;	/* for LPCM */
5387f4a9f43SWu Fengguang 	int	max_bitrate;	/* for AC3...ATRAC */
5397f4a9f43SWu Fengguang 	int	profile;	/* for WMAPRO */
5407f4a9f43SWu Fengguang };
5417f4a9f43SWu Fengguang 
5427f4a9f43SWu Fengguang #define ELD_FIXED_BYTES	20
5437f4a9f43SWu Fengguang #define ELD_MAX_MNL	16
5447f4a9f43SWu Fengguang #define ELD_MAX_SAD	16
5457f4a9f43SWu Fengguang 
5467f4a9f43SWu Fengguang /*
5477f4a9f43SWu Fengguang  * ELD: EDID Like Data
5487f4a9f43SWu Fengguang  */
5495b87ebb7SWu Fengguang struct hdmi_eld {
5507f4a9f43SWu Fengguang 	int	eld_size;
5517f4a9f43SWu Fengguang 	int	baseline_len;
5527f4a9f43SWu Fengguang 	int	eld_ver;	/* (eld_ver == 0) indicates invalid ELD */
5537f4a9f43SWu Fengguang 	int	cea_edid_ver;
5547f4a9f43SWu Fengguang 	char	monitor_name[ELD_MAX_MNL + 1];
5557f4a9f43SWu Fengguang 	int	manufacture_id;
5567f4a9f43SWu Fengguang 	int	product_id;
5577f4a9f43SWu Fengguang 	u64	port_id;
5587f4a9f43SWu Fengguang 	int	support_hdcp;
5597f4a9f43SWu Fengguang 	int	support_ai;
5607f4a9f43SWu Fengguang 	int	conn_type;
5617f4a9f43SWu Fengguang 	int	aud_synch_delay;
5627f4a9f43SWu Fengguang 	int	spk_alloc;
5637f4a9f43SWu Fengguang 	int	sad_count;
5647f4a9f43SWu Fengguang 	struct cea_sad sad[ELD_MAX_SAD];
565f208dba9STakashi Iwai #ifdef CONFIG_PROC_FS
566f208dba9STakashi Iwai 	struct snd_info_entry *proc_entry;
567f208dba9STakashi Iwai #endif
5687f4a9f43SWu Fengguang };
5697f4a9f43SWu Fengguang 
5707f4a9f43SWu Fengguang int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
5715b87ebb7SWu Fengguang int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
5725b87ebb7SWu Fengguang void snd_hdmi_show_eld(struct hdmi_eld *eld);
5737f4a9f43SWu Fengguang 
5745f1e71b1SWu Fengguang #ifdef CONFIG_PROC_FS
57554a25f87SWu Fengguang int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
57654a25f87SWu Fengguang 			 int index);
577f208dba9STakashi Iwai void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
5785f1e71b1SWu Fengguang #else
5790623536cSTakashi Iwai static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
58054a25f87SWu Fengguang 				       struct hdmi_eld *eld,
58154a25f87SWu Fengguang 				       int index)
5825f1e71b1SWu Fengguang {
5835f1e71b1SWu Fengguang 	return 0;
5845f1e71b1SWu Fengguang }
585f208dba9STakashi Iwai static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
586f208dba9STakashi Iwai 					 struct hdmi_eld *eld)
587f208dba9STakashi Iwai {
588f208dba9STakashi Iwai }
5895f1e71b1SWu Fengguang #endif
5905f1e71b1SWu Fengguang 
591903b21d8SWu Fengguang #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
592903b21d8SWu Fengguang void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
593903b21d8SWu Fengguang 
5941da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
595