xref: /linux/sound/pci/hda/hda_local.h (revision 2fa22c3c)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Universal Interface for Intel High Definition Audio Codec
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Local helper functions
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #ifndef __SOUND_HDA_LOCAL_H
111da177e4SLinus Torvalds #define __SOUND_HDA_LOCAL_H
121da177e4SLinus Torvalds 
139c96fa59STakashi Iwai /* We abuse kcontrol_new.subdev field to pass the NID corresponding to
149c96fa59STakashi Iwai  * the given new control.  If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
159c96fa59STakashi Iwai  * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
169c96fa59STakashi Iwai  *
179c96fa59STakashi Iwai  * Note that the subdevice field is cleared again before the real registration
189c96fa59STakashi Iwai  * in snd_hda_ctl_add(), so that this value won't appear in the outside.
199c96fa59STakashi Iwai  */
209c96fa59STakashi Iwai #define HDA_SUBDEV_NID_FLAG	(1U << 31)
219e3fd871SJaroslav Kysela #define HDA_SUBDEV_AMP_FLAG	(1U << 30)
229c96fa59STakashi Iwai 
231da177e4SLinus Torvalds /*
241da177e4SLinus Torvalds  * for mixer controls
251da177e4SLinus Torvalds  */
2629fdbec2STakashi Iwai #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs)		\
2729fdbec2STakashi Iwai 	((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
28de8c85f7SClemens Ladisch #define HDA_AMP_VAL_MIN_MUTE (1<<29)
29d01ce99fSTakashi Iwai #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
3029fdbec2STakashi Iwai 	HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
31985be54bSTakashi Iwai /* mono volume with index (index=0,1,...) (channel=1,2) */
32de8c85f7SClemens Ladisch #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, dir, flags) \
331da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx,  \
345e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
35302e9c5aSJaroslav Kysela 	  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
36302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
37302e9c5aSJaroslav Kysela 	  	    SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
381da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_volume_info, \
391da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_volume_get, \
401da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_volume_put, \
417cf0a953STakashi Iwai 	  .tlv = { .c = snd_hda_mixer_amp_tlv },		\
42de8c85f7SClemens Ladisch 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, dir) | flags }
43985be54bSTakashi Iwai /* stereo volume with index */
441da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
45de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction, 0)
46985be54bSTakashi Iwai /* mono volume */
471da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
48de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction, 0)
49985be54bSTakashi Iwai /* stereo volume */
501da177e4SLinus Torvalds #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
511da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
52de8c85f7SClemens Ladisch /* stereo volume with min=mute */
53de8c85f7SClemens Ladisch #define HDA_CODEC_VOLUME_MIN_MUTE(xname, nid, xindex, direction) \
54de8c85f7SClemens Ladisch 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, 3, xindex, direction, \
55de8c85f7SClemens Ladisch 				  HDA_AMP_VAL_MIN_MUTE)
56985be54bSTakashi Iwai /* mono mute switch with index (index=0,1,...) (channel=1,2) */
571da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
581da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
595e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
601da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_switch_info, \
611da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_switch_get, \
621da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_switch_put, \
631da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
64985be54bSTakashi Iwai /* stereo mute switch with index */
651da177e4SLinus Torvalds #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
661da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
67985be54bSTakashi Iwai /* mono mute switch */
681da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
691da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
70985be54bSTakashi Iwai /* stereo mute switch */
711da177e4SLinus Torvalds #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
721da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
7367d634c0STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
74123c07aeSJaroslav Kysela /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
75123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
76123c07aeSJaroslav Kysela 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
775e26dfd0SJaroslav Kysela 	  .subdevice = HDA_SUBDEV_AMP_FLAG, \
78123c07aeSJaroslav Kysela 	  .info = snd_hda_mixer_amp_switch_info, \
790401e854STakashi Iwai 	  .get = snd_hda_mixer_amp_switch_get_beep, \
80123c07aeSJaroslav Kysela 	  .put = snd_hda_mixer_amp_switch_put_beep, \
81123c07aeSJaroslav Kysela 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
8267d634c0STakashi Iwai #else
8367d634c0STakashi Iwai /* no digital beep - just the standard one */
8467d634c0STakashi Iwai #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
8567d634c0STakashi Iwai 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
8667d634c0STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_BEEP */
87123c07aeSJaroslav Kysela /* special beep mono mute switch */
88123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
89123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
90123c07aeSJaroslav Kysela /* special beep stereo mute switch */
91123c07aeSJaroslav Kysela #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
92123c07aeSJaroslav Kysela 	HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
931da177e4SLinus Torvalds 
9485dd662fSJaroslav Kysela extern const char *snd_hda_pcm_type_name[];
9585dd662fSJaroslav Kysela 
96d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
97d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
98d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
99d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
100d01ce99fSTakashi Iwai int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
101d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
102d01ce99fSTakashi Iwai int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
10374610eafSPierre-Louis Bossart 			  unsigned int size, unsigned int __user *_tlv);
104d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
105d01ce99fSTakashi Iwai 				  struct snd_ctl_elem_info *uinfo);
106d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
107d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
108d01ce99fSTakashi Iwai int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
109d01ce99fSTakashi Iwai 				 struct snd_ctl_elem_value *ucontrol);
11067d634c0STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
1110401e854STakashi Iwai int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
1120401e854STakashi Iwai 				      struct snd_ctl_elem_value *ucontrol);
113123c07aeSJaroslav Kysela int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
114123c07aeSJaroslav Kysela 				      struct snd_ctl_elem_value *ucontrol);
11567d634c0STakashi Iwai #endif
116834be88dSTakashi Iwai /* lowlevel accessor with caching; use carefully */
117eeecd9d1STakashi Iwai #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
118eeecd9d1STakashi Iwai 	snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
119a686ec4cSTakashi Iwai int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
120a686ec4cSTakashi Iwai 			     int ch, int dir, int idx, int mask, int val);
12147fd830aSTakashi Iwai int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
12274610eafSPierre-Louis Bossart 			     int direction, int idx, int mask, int val);
123280e57d5STakashi Iwai int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
124280e57d5STakashi Iwai 			   int direction, int idx, int mask, int val);
125280e57d5STakashi Iwai int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
126280e57d5STakashi Iwai 				  int dir, int idx, int mask, int val);
1272134ea4fSTakashi Iwai void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1282134ea4fSTakashi Iwai 			     unsigned int *tlv);
1292134ea4fSTakashi Iwai struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1302134ea4fSTakashi Iwai 					    const char *name);
13118478e8bSTakashi Iwai int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1329ab0cb30STakashi Iwai 			  unsigned int *tlv, const char * const *followers,
1339ab0cb30STakashi Iwai 			  const char *suffix, bool init_follower_vol,
134e65bf997SJaroslav Kysela 			  unsigned int access, struct snd_kcontrol **ctl_ret);
135e65bf997SJaroslav Kysela #define snd_hda_add_vmaster(codec, name, tlv, followers, suffix, access) \
136e65bf997SJaroslav Kysela 	__snd_hda_add_vmaster(codec, name, tlv, followers, suffix, true, access, NULL)
137a65d629cSTakashi Iwai int snd_hda_codec_reset(struct hda_codec *codec);
1387206998fSTakashi Iwai void snd_hda_codec_disconnect_pcms(struct hda_codec *codec);
1392134ea4fSTakashi Iwai 
1401a462be5STakashi Iwai #define snd_hda_regmap_sync(codec)	snd_hdac_regmap_sync(&(codec)->core)
1411a462be5STakashi Iwai 
142d2f344b5STakashi Iwai struct hda_vmaster_mute_hook {
143d2f344b5STakashi Iwai 	/* below two fields must be filled by the caller of
144d2f344b5STakashi Iwai 	 * snd_hda_add_vmaster_hook() beforehand
145d2f344b5STakashi Iwai 	 */
146d2f344b5STakashi Iwai 	struct snd_kcontrol *sw_kctl;
147d2f344b5STakashi Iwai 	void (*hook)(void *, int);
148d2f344b5STakashi Iwai 	/* below are initialized automatically */
149d2f344b5STakashi Iwai 	struct hda_codec *codec;
150d2f344b5STakashi Iwai };
151d2f344b5STakashi Iwai 
152d2f344b5STakashi Iwai int snd_hda_add_vmaster_hook(struct hda_codec *codec,
153e65bf997SJaroslav Kysela 			     struct hda_vmaster_mute_hook *hook);
154d2f344b5STakashi Iwai void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
155d2f344b5STakashi Iwai 
15647fd830aSTakashi Iwai /* amp value bits */
15747fd830aSTakashi Iwai #define HDA_AMP_MUTE	0x80
15847fd830aSTakashi Iwai #define HDA_AMP_UNMUTE	0x00
15947fd830aSTakashi Iwai #define HDA_AMP_VOLMASK	0x7f
16047fd830aSTakashi Iwai 
161532d5381STakashi Iwai /*
162532d5381STakashi Iwai  * SPDIF I/O
163532d5381STakashi Iwai  */
164dcda5806STakashi Iwai int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
16574b654c9SStephen Warren 				hda_nid_t associated_nid,
166dcda5806STakashi Iwai 				hda_nid_t cvt_nid, int type);
167dcda5806STakashi Iwai #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
168dcda5806STakashi Iwai 	snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
1691da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds /*
1721da177e4SLinus Torvalds  * input MUX helper
1731da177e4SLinus Torvalds  */
174b95a913cSVitaly Rodionov #define HDA_MAX_NUM_INPUTS	36
1751da177e4SLinus Torvalds struct hda_input_mux_item {
176b5786e85STakashi Iwai 	char label[32];
1771da177e4SLinus Torvalds 	unsigned int index;
1781da177e4SLinus Torvalds };
1791da177e4SLinus Torvalds struct hda_input_mux {
1801da177e4SLinus Torvalds 	unsigned int num_items;
1811da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
1821da177e4SLinus Torvalds };
1831da177e4SLinus Torvalds 
184d01ce99fSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux,
185d01ce99fSTakashi Iwai 			   struct snd_ctl_elem_info *uinfo);
186d01ce99fSTakashi Iwai int snd_hda_input_mux_put(struct hda_codec *codec,
187d01ce99fSTakashi Iwai 			  const struct hda_input_mux *imux,
188c8b6bf9bSTakashi Iwai 			  struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
1891da177e4SLinus Torvalds 			  unsigned int *cur_val);
1906194b99dSTakashi Iwai int snd_hda_add_imux_item(struct hda_codec *codec,
1916194b99dSTakashi Iwai 			  struct hda_input_mux *imux, const char *label,
19274610eafSPierre-Louis Bossart 			  int index, int *type_idx);
1931da177e4SLinus Torvalds 
194d2a6d7dcSTakashi Iwai /*
1951da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
1961da177e4SLinus Torvalds  */
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
1991da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
2001da177e4SLinus Torvalds 
201a06dbfc2STakashi Iwai #define HDA_MAX_OUTS	5
202a06dbfc2STakashi Iwai 
2031da177e4SLinus Torvalds struct hda_multi_out {
2041da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
205dda14410STakashi Iwai 	const hda_nid_t *dac_nids;	/* DAC list */
2061da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
207a06dbfc2STakashi Iwai 	hda_nid_t hp_out_nid[HDA_MAX_OUTS];	/* DACs for multiple HPs */
208a06dbfc2STakashi Iwai 	hda_nid_t extra_out_nid[HDA_MAX_OUTS];	/* other (e.g. speaker) DACs */
2091da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
2109ab0cb30STakashi Iwai 	const hda_nid_t *follower_dig_outs;
2111da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
2121da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
213d29240ceSTakashi Iwai 	int no_share_stream;	/* don't share a stream with multiple pins */
2149a08160bSTakashi Iwai 	int share_spdif;	/* share SPDIF pin */
2159a08160bSTakashi Iwai 	/* PCM information for both analog and SPDIF DACs */
2169a08160bSTakashi Iwai 	unsigned int analog_rates;
2179a08160bSTakashi Iwai 	unsigned int analog_maxbps;
2189a08160bSTakashi Iwai 	u64 analog_formats;
2199a08160bSTakashi Iwai 	unsigned int spdif_rates;
2209a08160bSTakashi Iwai 	unsigned int spdif_maxbps;
2219a08160bSTakashi Iwai 	u64 spdif_formats;
2221da177e4SLinus Torvalds };
2231da177e4SLinus Torvalds 
2249a08160bSTakashi Iwai int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2259a08160bSTakashi Iwai 				  struct hda_multi_out *mout);
226d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_open(struct hda_codec *codec,
227d01ce99fSTakashi Iwai 			       struct hda_multi_out *mout);
228d01ce99fSTakashi Iwai int snd_hda_multi_out_dig_close(struct hda_codec *codec,
229d01ce99fSTakashi Iwai 				struct hda_multi_out *mout);
2306b97eb45STakashi Iwai int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2316b97eb45STakashi Iwai 				  struct hda_multi_out *mout,
2326b97eb45STakashi Iwai 				  unsigned int stream_tag,
2336b97eb45STakashi Iwai 				  unsigned int format,
2346b97eb45STakashi Iwai 				  struct snd_pcm_substream *substream);
2359411e21cSTakashi Iwai int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
2369411e21cSTakashi Iwai 				  struct hda_multi_out *mout);
237d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_open(struct hda_codec *codec,
238d01ce99fSTakashi Iwai 				  struct hda_multi_out *mout,
2399a08160bSTakashi Iwai 				  struct snd_pcm_substream *substream,
2409a08160bSTakashi Iwai 				  struct hda_pcm_stream *hinfo);
241d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
242d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout,
2431da177e4SLinus Torvalds 				     unsigned int stream_tag,
2441da177e4SLinus Torvalds 				     unsigned int format,
245c8b6bf9bSTakashi Iwai 				     struct snd_pcm_substream *substream);
246d01ce99fSTakashi Iwai int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
247d01ce99fSTakashi Iwai 				     struct hda_multi_out *mout);
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds /*
2501da177e4SLinus Torvalds  * generic proc interface
2511da177e4SLinus Torvalds  */
252cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
2531da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
2541da177e4SLinus Torvalds #else
snd_hda_codec_proc_new(struct hda_codec * codec)2551da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
2561da177e4SLinus Torvalds #endif
2571da177e4SLinus Torvalds 
258d39b4352SWu Fengguang #define SND_PRINT_BITS_ADVISED_BUFSIZE	16
259d39b4352SWu Fengguang void snd_print_pcm_bits(int pcm, char *buf, int buflen);
260d39b4352SWu Fengguang 
2611da177e4SLinus Torvalds /*
2621da177e4SLinus Torvalds  * Misc
2631da177e4SLinus Torvalds  */
264d01ce99fSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec,
265031024eeSTakashi Iwai 			 const struct snd_kcontrol_new *knew);
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds /*
268c9ce6b26STakashi Iwai  * Fix-up pin default configurations and add default verbs
269c9ce6b26STakashi Iwai  */
270c9ce6b26STakashi Iwai 
271c9ce6b26STakashi Iwai struct hda_pintbl {
272c9ce6b26STakashi Iwai 	hda_nid_t nid;
273c9ce6b26STakashi Iwai 	u32 val;
274c9ce6b26STakashi Iwai };
275c9ce6b26STakashi Iwai 
276c9ce6b26STakashi Iwai struct hda_model_fixup {
277c9ce6b26STakashi Iwai 	const int id;
278c9ce6b26STakashi Iwai 	const char *name;
279c9ce6b26STakashi Iwai };
280c9ce6b26STakashi Iwai 
281c9ce6b26STakashi Iwai struct hda_fixup {
282c9ce6b26STakashi Iwai 	int type;
2831f578250STakashi Iwai 	bool chained:1;		/* call the chained fixup(s) after this */
2841f578250STakashi Iwai 	bool chained_before:1;	/* call the chained fixup(s) before this */
285c9ce6b26STakashi Iwai 	int chain_id;
286c9ce6b26STakashi Iwai 	union {
287c9ce6b26STakashi Iwai 		const struct hda_pintbl *pins;
288c9ce6b26STakashi Iwai 		const struct hda_verb *verbs;
289c9ce6b26STakashi Iwai 		void (*func)(struct hda_codec *codec,
290c9ce6b26STakashi Iwai 			     const struct hda_fixup *fix,
291c9ce6b26STakashi Iwai 			     int action);
292c9ce6b26STakashi Iwai 	} v;
293c9ce6b26STakashi Iwai };
294c9ce6b26STakashi Iwai 
29520531415SDavid Henningsson struct snd_hda_pin_quirk {
29620531415SDavid Henningsson 	unsigned int codec;             /* Codec vendor/device ID */
29720531415SDavid Henningsson 	unsigned short subvendor;	/* PCI subvendor ID */
29820531415SDavid Henningsson 	const struct hda_pintbl *pins;  /* list of matching pins */
29920531415SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
30020531415SDavid Henningsson 	const char *name;
30120531415SDavid Henningsson #endif
30220531415SDavid Henningsson 	int value;			/* quirk value */
30320531415SDavid Henningsson };
30420531415SDavid Henningsson 
305a2d2fa02SDavid Henningsson #ifdef CONFIG_SND_DEBUG_VERBOSE
306a2d2fa02SDavid Henningsson 
307a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
308a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
309a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
310a2d2fa02SDavid Henningsson 	  .name = _name,\
311a2d2fa02SDavid Henningsson 	  .value = _value,\
312fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
313a2d2fa02SDavid Henningsson 	}
314a2d2fa02SDavid Henningsson #else
315a2d2fa02SDavid Henningsson 
316a2d2fa02SDavid Henningsson #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
317a2d2fa02SDavid Henningsson 	{ .codec = _codec,\
318a2d2fa02SDavid Henningsson 	  .subvendor = _subvendor,\
319a2d2fa02SDavid Henningsson 	  .value = _value,\
320fb54a645SDavid Henningsson 	  .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
321a2d2fa02SDavid Henningsson 	}
322a2d2fa02SDavid Henningsson 
323a2d2fa02SDavid Henningsson #endif
324a2d2fa02SDavid Henningsson 
325f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NOT_SET -1
326f5662e1cSDavid Henningsson #define HDA_FIXUP_ID_NO_FIXUP -2
327a2d2fa02SDavid Henningsson 
328c9ce6b26STakashi Iwai /* fixup types */
329c9ce6b26STakashi Iwai enum {
330c9ce6b26STakashi Iwai 	HDA_FIXUP_INVALID,
331c9ce6b26STakashi Iwai 	HDA_FIXUP_PINS,
332c9ce6b26STakashi Iwai 	HDA_FIXUP_VERBS,
333c9ce6b26STakashi Iwai 	HDA_FIXUP_FUNC,
334fd108215STakashi Iwai 	HDA_FIXUP_PINCTLS,
335c9ce6b26STakashi Iwai };
336c9ce6b26STakashi Iwai 
337c9ce6b26STakashi Iwai /* fixup action definitions */
338c9ce6b26STakashi Iwai enum {
339c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PRE_PROBE,
340c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_PROBE,
341c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_INIT,
342c9ce6b26STakashi Iwai 	HDA_FIXUP_ACT_BUILD,
343360fec28SDavid Henningsson 	HDA_FIXUP_ACT_FREE,
344c9ce6b26STakashi Iwai };
345c9ce6b26STakashi Iwai 
346c9ce6b26STakashi Iwai int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
347c9ce6b26STakashi Iwai void snd_hda_apply_verbs(struct hda_codec *codec);
348c9ce6b26STakashi Iwai void snd_hda_apply_pincfgs(struct hda_codec *codec,
349c9ce6b26STakashi Iwai 			   const struct hda_pintbl *cfg);
350c9ce6b26STakashi Iwai void snd_hda_apply_fixup(struct hda_codec *codec, int action);
35156ec3e75STakashi Iwai void __snd_hda_apply_fixup(struct hda_codec *codec, int id, int action, int depth);
352c9ce6b26STakashi Iwai void snd_hda_pick_fixup(struct hda_codec *codec,
353c9ce6b26STakashi Iwai 			const struct hda_model_fixup *models,
354c9ce6b26STakashi Iwai 			const struct snd_pci_quirk *quirk,
355c9ce6b26STakashi Iwai 			const struct hda_fixup *fixlist);
35620531415SDavid Henningsson void snd_hda_pick_pin_fixup(struct hda_codec *codec,
35720531415SDavid Henningsson 			    const struct snd_hda_pin_quirk *pin_quirk,
3580fc1e447SHui Wang 			    const struct hda_fixup *fixlist,
3590fc1e447SHui Wang 			    bool match_all_pins);
36020531415SDavid Henningsson 
361128bc4baSTakashi Iwai /* helper macros to retrieve pin default-config values */
362d01ce99fSTakashi Iwai #define get_defcfg_connect(cfg) \
363d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
364d01ce99fSTakashi Iwai #define get_defcfg_association(cfg) \
365d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
366d01ce99fSTakashi Iwai #define get_defcfg_location(cfg) \
367d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
368d01ce99fSTakashi Iwai #define get_defcfg_sequence(cfg) \
369d01ce99fSTakashi Iwai 	(cfg & AC_DEFCFG_SEQUENCE)
370d01ce99fSTakashi Iwai #define get_defcfg_device(cfg) \
371d01ce99fSTakashi Iwai 	((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
37208a1f5ebSTakashi Iwai #define get_defcfg_misc(cfg) \
37308a1f5ebSTakashi Iwai 	((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
374e9edcee0STakashi Iwai 
3758d88bc3dSTakashi Iwai /* amp values */
3768d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))
3778d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))
3788d88bc3dSTakashi Iwai #define AMP_OUT_MUTE		0xb080
3798d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE		0xb000
3808d88bc3dSTakashi Iwai #define AMP_OUT_ZERO		0xb000
3818d88bc3dSTakashi Iwai /* pinctl values */
38235e8901eSRobin H. Johnson #define PIN_IN			(AC_PINCTL_IN_EN)
38335e8901eSRobin H. Johnson #define PIN_VREFHIZ		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
38435e8901eSRobin H. Johnson #define PIN_VREF50		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
38535e8901eSRobin H. Johnson #define PIN_VREFGRD		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
38635e8901eSRobin H. Johnson #define PIN_VREF80		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
38735e8901eSRobin H. Johnson #define PIN_VREF100		(AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
38835e8901eSRobin H. Johnson #define PIN_OUT			(AC_PINCTL_OUT_EN)
38935e8901eSRobin H. Johnson #define PIN_HP			(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
39035e8901eSRobin H. Johnson #define PIN_HP_AMP		(AC_PINCTL_HP_EN)
3918d88bc3dSTakashi Iwai 
3924740860bSTakashi Iwai unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
39362f3a2f7STakashi Iwai unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
39462f3a2f7STakashi Iwai 				     hda_nid_t pin, unsigned int val);
395cdd03cedSTakashi Iwai int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
396cdd03cedSTakashi Iwai 			 unsigned int val, bool cached);
397cdd03cedSTakashi Iwai 
398cdd03cedSTakashi Iwai /**
399cdd03cedSTakashi Iwai  * _snd_hda_set_pin_ctl - Set a pin-control value safely
400cdd03cedSTakashi Iwai  * @codec: the codec instance
401cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
402cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
403cdd03cedSTakashi Iwai  *
404cdd03cedSTakashi Iwai  * This function sets the pin-control value to the given pin, but
405cdd03cedSTakashi Iwai  * filters out the invalid pin-control bits when the pin has no such
406cdd03cedSTakashi Iwai  * capabilities.  For example, when PIN_HP is passed but the pin has no
407cdd03cedSTakashi Iwai  * HP-drive capability, the HP bit is omitted.
408cdd03cedSTakashi Iwai  *
409cdd03cedSTakashi Iwai  * The function doesn't check the input VREF capability bits, though.
4104740860bSTakashi Iwai  * Use snd_hda_get_default_vref() to guess the right value.
411cdd03cedSTakashi Iwai  * Also, this function is only for analog pins, not for HDMI pins.
412cdd03cedSTakashi Iwai  */
413cdd03cedSTakashi Iwai static inline int
snd_hda_set_pin_ctl(struct hda_codec * codec,hda_nid_t pin,unsigned int val)414cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
415cdd03cedSTakashi Iwai {
416cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, false);
417cdd03cedSTakashi Iwai }
418cdd03cedSTakashi Iwai 
419cdd03cedSTakashi Iwai /**
420cdd03cedSTakashi Iwai  * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
421cdd03cedSTakashi Iwai  * @codec: the codec instance
422cdd03cedSTakashi Iwai  * @pin: the pin NID to set the control
423cdd03cedSTakashi Iwai  * @val: the pin-control value (AC_PINCTL_* bits)
424cdd03cedSTakashi Iwai  *
425cdd03cedSTakashi Iwai  * Just like snd_hda_set_pin_ctl() but write to cache as well.
426cdd03cedSTakashi Iwai  */
427cdd03cedSTakashi Iwai static inline int
snd_hda_set_pin_ctl_cache(struct hda_codec * codec,hda_nid_t pin,unsigned int val)428cdd03cedSTakashi Iwai snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
429cdd03cedSTakashi Iwai 			  unsigned int val)
430cdd03cedSTakashi Iwai {
431cdd03cedSTakashi Iwai 	return _snd_hda_set_pin_ctl(codec, pin, val, true);
432cdd03cedSTakashi Iwai }
433cdd03cedSTakashi Iwai 
434d7fdc00aSTakashi Iwai int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
435d7fdc00aSTakashi Iwai int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
436d7fdc00aSTakashi Iwai 				 unsigned int val);
437d7fdc00aSTakashi Iwai 
4387639a06cSTakashi Iwai #define for_each_hda_codec_node(nid, codec) \
4397639a06cSTakashi Iwai 	for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
4407639a06cSTakashi Iwai 
44165cc4ad6SStefan Binding /* Set the codec power_state flag to indicate to allow unsol event handling;
44265cc4ad6SStefan Binding  * see hda_codec_unsol_event() in hda_bind.c.  Calling this might confuse the
44365cc4ad6SStefan Binding  * state tracking, so use with care.
44465cc4ad6SStefan Binding  */
snd_hda_codec_allow_unsol_events(struct hda_codec * codec)44565cc4ad6SStefan Binding static inline void snd_hda_codec_allow_unsol_events(struct hda_codec *codec)
44665cc4ad6SStefan Binding {
44765cc4ad6SStefan Binding 	codec->core.dev.power.power_state = PMSG_ON;
44865cc4ad6SStefan Binding }
44965cc4ad6SStefan Binding 
45054d17403STakashi Iwai /*
45154d17403STakashi Iwai  * get widget capabilities
45254d17403STakashi Iwai  */
get_wcaps(struct hda_codec * codec,hda_nid_t nid)45354d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
45454d17403STakashi Iwai {
4557639a06cSTakashi Iwai 	if (nid < codec->core.start_nid ||
4567639a06cSTakashi Iwai 	    nid >= codec->core.start_nid + codec->core.num_nodes)
457dca008f3STakashi Iwai 		return 0;
4587639a06cSTakashi Iwai 	return codec->wcaps[nid - codec->core.start_nid];
45954d17403STakashi Iwai }
46054d17403STakashi Iwai 
461a22d543aSTakashi Iwai /* get the widget type from widget capability bits */
get_wcaps_type(unsigned int wcaps)4623a90274dSTakashi Iwai static inline int get_wcaps_type(unsigned int wcaps)
4633a90274dSTakashi Iwai {
4643a90274dSTakashi Iwai 	if (!wcaps)
4653a90274dSTakashi Iwai 		return -1; /* invalid type */
4663a90274dSTakashi Iwai 	return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4673a90274dSTakashi Iwai }
468a22d543aSTakashi Iwai 
get_wcaps_channels(u32 wcaps)469fd72d008SWu Fengguang static inline unsigned int get_wcaps_channels(u32 wcaps)
470fd72d008SWu Fengguang {
471fd72d008SWu Fengguang 	unsigned int chans;
472fd72d008SWu Fengguang 
473fd72d008SWu Fengguang 	chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
474fd72d008SWu Fengguang 	chans = ((chans << 1) | 1) + 1;
475fd72d008SWu Fengguang 
476fd72d008SWu Fengguang 	return chans;
477fd72d008SWu Fengguang }
478fd72d008SWu Fengguang 
snd_hda_override_wcaps(struct hda_codec * codec,hda_nid_t nid,u32 val)479d045c5dcSTakashi Iwai static inline void snd_hda_override_wcaps(struct hda_codec *codec,
480d045c5dcSTakashi Iwai 					  hda_nid_t nid, u32 val)
481d045c5dcSTakashi Iwai {
4827639a06cSTakashi Iwai 	if (nid >= codec->core.start_nid &&
4837639a06cSTakashi Iwai 	    nid < codec->core.start_nid + codec->core.num_nodes)
4847639a06cSTakashi Iwai 		codec->wcaps[nid - codec->core.start_nid] = val;
485d045c5dcSTakashi Iwai }
486d045c5dcSTakashi Iwai 
48709a99959SMatthew Ranostay u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
488897cc188STakashi Iwai int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
489897cc188STakashi Iwai 			      unsigned int caps);
490faa75f8aSTakashi Iwai /**
491faa75f8aSTakashi Iwai  * snd_hda_query_pin_caps - Query PIN capabilities
492faa75f8aSTakashi Iwai  * @codec: the HD-auio codec
493faa75f8aSTakashi Iwai  * @nid: the NID to query
494faa75f8aSTakashi Iwai  *
495faa75f8aSTakashi Iwai  * Query PIN capabilities for the given widget.
496faa75f8aSTakashi Iwai  * Returns the obtained capability bits.
497faa75f8aSTakashi Iwai  *
498faa75f8aSTakashi Iwai  * When cap bits have been already read, this doesn't read again but
499faa75f8aSTakashi Iwai  * returns the cached value.
500faa75f8aSTakashi Iwai  */
501faa75f8aSTakashi Iwai static inline u32
snd_hda_query_pin_caps(struct hda_codec * codec,hda_nid_t nid)502faa75f8aSTakashi Iwai snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
503faa75f8aSTakashi Iwai {
504faa75f8aSTakashi Iwai 	return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
505faa75f8aSTakashi Iwai 
506faa75f8aSTakashi Iwai }
507faa75f8aSTakashi Iwai 
508faa75f8aSTakashi Iwai /**
509faa75f8aSTakashi Iwai  * snd_hda_override_pin_caps - Override the pin capabilities
510faa75f8aSTakashi Iwai  * @codec: the CODEC
511faa75f8aSTakashi Iwai  * @nid: the NID to override
512faa75f8aSTakashi Iwai  * @caps: the capability bits to set
513faa75f8aSTakashi Iwai  *
514faa75f8aSTakashi Iwai  * Override the cached PIN capabilitiy bits value by the given one.
515faa75f8aSTakashi Iwai  *
516faa75f8aSTakashi Iwai  * Returns zero if successful or a negative error code.
517faa75f8aSTakashi Iwai  */
518faa75f8aSTakashi Iwai static inline int
snd_hda_override_pin_caps(struct hda_codec * codec,hda_nid_t nid,unsigned int caps)519faa75f8aSTakashi Iwai snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
520faa75f8aSTakashi Iwai 			  unsigned int caps)
521faa75f8aSTakashi Iwai {
522faa75f8aSTakashi Iwai 	return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
523faa75f8aSTakashi Iwai }
524faa75f8aSTakashi Iwai 
525861a04edSDavid Henningsson bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
526861a04edSDavid Henningsson 			   int dir, unsigned int bits);
527861a04edSDavid Henningsson 
528861a04edSDavid Henningsson #define nid_has_mute(codec, nid, dir) \
529861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
530861a04edSDavid Henningsson #define nid_has_volume(codec, nid, dir) \
531861a04edSDavid Henningsson 	snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
532861a04edSDavid Henningsson 
53303697e2aSTakashi Iwai 
5349e3fd871SJaroslav Kysela /* flags for hda_nid_item */
5359e3fd871SJaroslav Kysela #define HDA_NID_ITEM_AMP	(1<<0)
5369e3fd871SJaroslav Kysela 
5373911a4c1SJaroslav Kysela struct hda_nid_item {
5383911a4c1SJaroslav Kysela 	struct snd_kcontrol *kctl;
5395b0cb1d8SJaroslav Kysela 	unsigned int index;
5403911a4c1SJaroslav Kysela 	hda_nid_t nid;
5419e3fd871SJaroslav Kysela 	unsigned short flags;
5423911a4c1SJaroslav Kysela };
5433911a4c1SJaroslav Kysela 
5443911a4c1SJaroslav Kysela int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
5453911a4c1SJaroslav Kysela 		    struct snd_kcontrol *kctl);
5465b0cb1d8SJaroslav Kysela int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
5475b0cb1d8SJaroslav Kysela 		    unsigned int index, hda_nid_t nid);
548d13bd412STakashi Iwai void snd_hda_ctls_clear(struct hda_codec *codec);
549d13bd412STakashi Iwai 
5502807314dSTakashi Iwai /*
5512807314dSTakashi Iwai  * hwdep interface
5522807314dSTakashi Iwai  */
553d7ffba19STakashi Iwai #ifdef CONFIG_SND_HDA_HWDEP
5542807314dSTakashi Iwai int snd_hda_create_hwdep(struct hda_codec *codec);
555d7ffba19STakashi Iwai #else
snd_hda_create_hwdep(struct hda_codec * codec)556d7ffba19STakashi Iwai static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
557d7ffba19STakashi Iwai #endif
5582807314dSTakashi Iwai 
559648a8d27STakashi Iwai void snd_hda_sysfs_init(struct hda_codec *codec);
560648a8d27STakashi Iwai void snd_hda_sysfs_clear(struct hda_codec *codec);
561648a8d27STakashi Iwai 
562648a8d27STakashi Iwai extern const struct attribute_group *snd_hda_dev_attr_groups[];
563648a8d27STakashi Iwai 
56443b62713STakashi Iwai #ifdef CONFIG_SND_HDA_RECONFIG
56543b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
56643b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
567bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
56843b62713STakashi Iwai #else
56943b62713STakashi Iwai static inline
snd_hda_get_hint(struct hda_codec * codec,const char * key)57043b62713STakashi Iwai const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
57143b62713STakashi Iwai {
57243b62713STakashi Iwai 	return NULL;
57343b62713STakashi Iwai }
57443b62713STakashi Iwai 
57543b62713STakashi Iwai static inline
snd_hda_get_bool_hint(struct hda_codec * codec,const char * key)57643b62713STakashi Iwai int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
57743b62713STakashi Iwai {
57843b62713STakashi Iwai 	return -ENOENT;
57943b62713STakashi Iwai }
580bc759721STakashi Iwai 
581bc759721STakashi Iwai static inline
snd_hda_get_int_hint(struct hda_codec * codec,const char * key,int * valp)582bc759721STakashi Iwai int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
583bc759721STakashi Iwai {
584bc759721STakashi Iwai 	return -ENOENT;
585bc759721STakashi Iwai }
58643b62713STakashi Iwai #endif
58743b62713STakashi Iwai 
588cb53c626STakashi Iwai /*
589cb53c626STakashi Iwai  * power-management
590cb53c626STakashi Iwai  */
591cb53c626STakashi Iwai 
592cb53c626STakashi Iwai void snd_hda_schedule_power_save(struct hda_codec *codec);
593cb53c626STakashi Iwai 
594cb53c626STakashi Iwai struct hda_amp_list {
595cb53c626STakashi Iwai 	hda_nid_t nid;
596cb53c626STakashi Iwai 	unsigned char dir;
597cb53c626STakashi Iwai 	unsigned char idx;
598cb53c626STakashi Iwai };
599cb53c626STakashi Iwai 
600cb53c626STakashi Iwai struct hda_loopback_check {
601031024eeSTakashi Iwai 	const struct hda_amp_list *amplist;
602cb53c626STakashi Iwai 	int power_on;
603cb53c626STakashi Iwai };
604cb53c626STakashi Iwai 
605cb53c626STakashi Iwai int snd_hda_check_amp_list_power(struct hda_codec *codec,
606cb53c626STakashi Iwai 				 struct hda_loopback_check *check,
607cb53c626STakashi Iwai 				 hda_nid_t nid);
608cb53c626STakashi Iwai 
6099040d102STakashi Iwai /* check whether the actual power state matches with the target state */
6109040d102STakashi Iwai static inline bool
snd_hda_check_power_state(struct hda_codec * codec,hda_nid_t nid,unsigned int target_state)6119040d102STakashi Iwai snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
6129040d102STakashi Iwai 			  unsigned int target_state)
6139040d102STakashi Iwai {
61470b4891cSVinod Koul 	return snd_hdac_check_power_state(&codec->core, nid, target_state);
6159040d102STakashi Iwai }
616009f8c90SLukas Wunner 
snd_hda_sync_power_state(struct hda_codec * codec,hda_nid_t nid,unsigned int target_state)617009f8c90SLukas Wunner static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
618009f8c90SLukas Wunner 						    hda_nid_t nid,
619009f8c90SLukas Wunner 						    unsigned int target_state)
6203b5b899cSAbhijeet Kumar {
6213b5b899cSAbhijeet Kumar 	return snd_hdac_sync_power_state(&codec->core, nid, target_state);
6223b5b899cSAbhijeet Kumar }
623ba615b86STakashi Iwai unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
624ba615b86STakashi Iwai 					     hda_nid_t nid,
625ba615b86STakashi Iwai 					     unsigned int power_state);
626ba615b86STakashi Iwai 
627b98444edSTakashi Iwai void snd_hda_codec_shutdown(struct hda_codec *codec);
628b98444edSTakashi Iwai 
62989385035SMatthew Ranostay /*
63089385035SMatthew Ranostay  * AMP control callbacks
63189385035SMatthew Ranostay  */
63289385035SMatthew Ranostay /* retrieve parameters from private_value */
6333911a4c1SJaroslav Kysela #define get_amp_nid_(pv)	((pv) & 0xffff)
6343911a4c1SJaroslav Kysela #define get_amp_nid(kc)		get_amp_nid_((kc)->private_value)
63589385035SMatthew Ranostay #define get_amp_channels(kc)	(((kc)->private_value >> 16) & 0x3)
636527e4d73STakashi Iwai #define get_amp_direction_(pv)	(((pv) >> 18) & 0x1)
637527e4d73STakashi Iwai #define get_amp_direction(kc)	get_amp_direction_((kc)->private_value)
638130e5f06STakashi Iwai #define get_amp_index_(pv)	(((pv) >> 19) & 0xf)
639130e5f06STakashi Iwai #define get_amp_index(kc)	get_amp_index_((kc)->private_value)
64029fdbec2STakashi Iwai #define get_amp_offset(kc)	(((kc)->private_value >> 23) & 0x3f)
641de8c85f7SClemens Ladisch #define get_amp_min_mute(kc)	(((kc)->private_value >> 29) & 0x1)
64289385035SMatthew Ranostay 
6437f4a9f43SWu Fengguang /*
644dda415d4STakashi Iwai  * enum control helper
645dda415d4STakashi Iwai  */
646dda415d4STakashi Iwai int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
647dda415d4STakashi Iwai 			     struct snd_ctl_elem_info *uinfo,
64874610eafSPierre-Louis Bossart 			     int num_items, const char * const *texts);
649dda415d4STakashi Iwai #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
650dda415d4STakashi Iwai 	snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
651dda415d4STakashi Iwai 
652dda415d4STakashi Iwai /*
6537f4a9f43SWu Fengguang  * CEA Short Audio Descriptor data
6547f4a9f43SWu Fengguang  */
6557f4a9f43SWu Fengguang struct cea_sad {
6567f4a9f43SWu Fengguang 	int	channels;
6577f4a9f43SWu Fengguang 	int	format;		/* (format == 0) indicates invalid SAD */
6587f4a9f43SWu Fengguang 	int	rates;
6597f4a9f43SWu Fengguang 	int	sample_bits;	/* for LPCM */
6607f4a9f43SWu Fengguang 	int	max_bitrate;	/* for AC3...ATRAC */
6617f4a9f43SWu Fengguang 	int	profile;	/* for WMAPRO */
6627f4a9f43SWu Fengguang };
6637f4a9f43SWu Fengguang 
6647f4a9f43SWu Fengguang #define ELD_FIXED_BYTES	20
66514bc52b8SPierre-Louis Bossart #define ELD_MAX_SIZE    256
6667f4a9f43SWu Fengguang #define ELD_MAX_MNL	16
6677f4a9f43SWu Fengguang #define ELD_MAX_SAD	16
6687f4a9f43SWu Fengguang 
6697f4a9f43SWu Fengguang /*
6707f4a9f43SWu Fengguang  * ELD: EDID Like Data
6717f4a9f43SWu Fengguang  */
6721613d6b4SDavid Henningsson struct parsed_hdmi_eld {
6731613d6b4SDavid Henningsson 	/*
6741613d6b4SDavid Henningsson 	 * all fields will be cleared before updating ELD
6751613d6b4SDavid Henningsson 	 */
6767f4a9f43SWu Fengguang 	int	baseline_len;
67723ccc2bdSWu Fengguang 	int	eld_ver;
6787f4a9f43SWu Fengguang 	int	cea_edid_ver;
6797f4a9f43SWu Fengguang 	char	monitor_name[ELD_MAX_MNL + 1];
6807f4a9f43SWu Fengguang 	int	manufacture_id;
6817f4a9f43SWu Fengguang 	int	product_id;
6827f4a9f43SWu Fengguang 	u64	port_id;
6837f4a9f43SWu Fengguang 	int	support_hdcp;
6847f4a9f43SWu Fengguang 	int	support_ai;
6857f4a9f43SWu Fengguang 	int	conn_type;
6867f4a9f43SWu Fengguang 	int	aud_synch_delay;
6877f4a9f43SWu Fengguang 	int	spk_alloc;
6887f4a9f43SWu Fengguang 	int	sad_count;
6897f4a9f43SWu Fengguang 	struct cea_sad sad[ELD_MAX_SAD];
6901613d6b4SDavid Henningsson };
6911613d6b4SDavid Henningsson 
6921613d6b4SDavid Henningsson struct hdmi_eld {
6931613d6b4SDavid Henningsson 	bool	monitor_present;
6941613d6b4SDavid Henningsson 	bool	eld_valid;
6951613d6b4SDavid Henningsson 	int	eld_size;
69614bc52b8SPierre-Louis Bossart 	char    eld_buffer[ELD_MAX_SIZE];
6971613d6b4SDavid Henningsson 	struct parsed_hdmi_eld info;
6987f4a9f43SWu Fengguang };
6997f4a9f43SWu Fengguang 
7007f4a9f43SWu Fengguang int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
7011613d6b4SDavid Henningsson int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
7021613d6b4SDavid Henningsson 		     unsigned char *buf, int *eld_size);
70379514d47STakashi Iwai int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
7041613d6b4SDavid Henningsson 		       const unsigned char *buf, int size);
70579514d47STakashi Iwai void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
7061613d6b4SDavid Henningsson void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
7072def8172SStephen Warren 			      struct hda_pcm_stream *hinfo);
7087f4a9f43SWu Fengguang 
70989250f84SAnssi Hannula int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
71089250f84SAnssi Hannula 			 unsigned char *buf, int *eld_size,
71189250f84SAnssi Hannula 			 bool rev3_or_later);
71289250f84SAnssi Hannula 
713cd6a6503SJie Yang #ifdef CONFIG_SND_PROC_FS
714a4e9a38bSTakashi Iwai void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
715*2fa22c3cSJaroslav Kysela 			     struct snd_info_buffer *buffer,
716*2fa22c3cSJaroslav Kysela 			     hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid);
717a4e9a38bSTakashi Iwai void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
718a4e9a38bSTakashi Iwai 			     struct snd_info_buffer *buffer);
7195f1e71b1SWu Fengguang #endif
7205f1e71b1SWu Fengguang 
721903b21d8SWu Fengguang #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
722903b21d8SWu Fengguang void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
723903b21d8SWu Fengguang 
7243099406eSImre Deak void snd_hda_codec_display_power(struct hda_codec *codec, bool enable);
7253099406eSImre Deak 
7264e76a883STakashi Iwai /*
7274e76a883STakashi Iwai  */
728d8a766a1STakashi Iwai #define codec_err(codec, fmt, args...) \
729d8a766a1STakashi Iwai 	dev_err(hda_codec_dev(codec), fmt, ##args)
730d8a766a1STakashi Iwai #define codec_warn(codec, fmt, args...) \
731d8a766a1STakashi Iwai 	dev_warn(hda_codec_dev(codec), fmt, ##args)
732d8a766a1STakashi Iwai #define codec_info(codec, fmt, args...) \
733d8a766a1STakashi Iwai 	dev_info(hda_codec_dev(codec), fmt, ##args)
734d8a766a1STakashi Iwai #define codec_dbg(codec, fmt, args...) \
735d8a766a1STakashi Iwai 	dev_dbg(hda_codec_dev(codec), fmt, ##args)
7364e76a883STakashi Iwai 
7371da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
738