1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Universal Interface for Intel High Definition Audio Codec
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Local helper functions
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef __SOUND_HDA_LOCAL_H
11*4882a593Smuzhiyun #define __SOUND_HDA_LOCAL_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun /* We abuse kcontrol_new.subdev field to pass the NID corresponding to
14*4882a593Smuzhiyun * the given new control. If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
15*4882a593Smuzhiyun * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * Note that the subdevice field is cleared again before the real registration
18*4882a593Smuzhiyun * in snd_hda_ctl_add(), so that this value won't appear in the outside.
19*4882a593Smuzhiyun */
20*4882a593Smuzhiyun #define HDA_SUBDEV_NID_FLAG (1U << 31)
21*4882a593Smuzhiyun #define HDA_SUBDEV_AMP_FLAG (1U << 30)
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun * for mixer controls
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs) \
27*4882a593Smuzhiyun ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
28*4882a593Smuzhiyun #define HDA_AMP_VAL_MIN_MUTE (1<<29)
29*4882a593Smuzhiyun #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
30*4882a593Smuzhiyun HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
31*4882a593Smuzhiyun /* mono volume with index (index=0,1,...) (channel=1,2) */
32*4882a593Smuzhiyun #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, dir, flags) \
33*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
34*4882a593Smuzhiyun .subdevice = HDA_SUBDEV_AMP_FLAG, \
35*4882a593Smuzhiyun .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
36*4882a593Smuzhiyun SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
37*4882a593Smuzhiyun SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
38*4882a593Smuzhiyun .info = snd_hda_mixer_amp_volume_info, \
39*4882a593Smuzhiyun .get = snd_hda_mixer_amp_volume_get, \
40*4882a593Smuzhiyun .put = snd_hda_mixer_amp_volume_put, \
41*4882a593Smuzhiyun .tlv = { .c = snd_hda_mixer_amp_tlv }, \
42*4882a593Smuzhiyun .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, dir) | flags }
43*4882a593Smuzhiyun /* stereo volume with index */
44*4882a593Smuzhiyun #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
45*4882a593Smuzhiyun HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction, 0)
46*4882a593Smuzhiyun /* mono volume */
47*4882a593Smuzhiyun #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
48*4882a593Smuzhiyun HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction, 0)
49*4882a593Smuzhiyun /* stereo volume */
50*4882a593Smuzhiyun #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
51*4882a593Smuzhiyun HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
52*4882a593Smuzhiyun /* stereo volume with min=mute */
53*4882a593Smuzhiyun #define HDA_CODEC_VOLUME_MIN_MUTE(xname, nid, xindex, direction) \
54*4882a593Smuzhiyun HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, 3, xindex, direction, \
55*4882a593Smuzhiyun HDA_AMP_VAL_MIN_MUTE)
56*4882a593Smuzhiyun /* mono mute switch with index (index=0,1,...) (channel=1,2) */
57*4882a593Smuzhiyun #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
58*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
59*4882a593Smuzhiyun .subdevice = HDA_SUBDEV_AMP_FLAG, \
60*4882a593Smuzhiyun .info = snd_hda_mixer_amp_switch_info, \
61*4882a593Smuzhiyun .get = snd_hda_mixer_amp_switch_get, \
62*4882a593Smuzhiyun .put = snd_hda_mixer_amp_switch_put, \
63*4882a593Smuzhiyun .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
64*4882a593Smuzhiyun /* stereo mute switch with index */
65*4882a593Smuzhiyun #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
66*4882a593Smuzhiyun HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
67*4882a593Smuzhiyun /* mono mute switch */
68*4882a593Smuzhiyun #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
69*4882a593Smuzhiyun HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
70*4882a593Smuzhiyun /* stereo mute switch */
71*4882a593Smuzhiyun #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
72*4882a593Smuzhiyun HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
73*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_INPUT_BEEP
74*4882a593Smuzhiyun /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
75*4882a593Smuzhiyun #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
76*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
77*4882a593Smuzhiyun .subdevice = HDA_SUBDEV_AMP_FLAG, \
78*4882a593Smuzhiyun .info = snd_hda_mixer_amp_switch_info, \
79*4882a593Smuzhiyun .get = snd_hda_mixer_amp_switch_get_beep, \
80*4882a593Smuzhiyun .put = snd_hda_mixer_amp_switch_put_beep, \
81*4882a593Smuzhiyun .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
82*4882a593Smuzhiyun #else
83*4882a593Smuzhiyun /* no digital beep - just the standard one */
84*4882a593Smuzhiyun #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
85*4882a593Smuzhiyun HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
86*4882a593Smuzhiyun #endif /* CONFIG_SND_HDA_INPUT_BEEP */
87*4882a593Smuzhiyun /* special beep mono mute switch */
88*4882a593Smuzhiyun #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
89*4882a593Smuzhiyun HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
90*4882a593Smuzhiyun /* special beep stereo mute switch */
91*4882a593Smuzhiyun #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
92*4882a593Smuzhiyun HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun extern const char *snd_hda_pcm_type_name[];
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
97*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo);
98*4882a593Smuzhiyun int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
99*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
100*4882a593Smuzhiyun int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
101*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
102*4882a593Smuzhiyun int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
103*4882a593Smuzhiyun unsigned int size, unsigned int __user *_tlv);
104*4882a593Smuzhiyun int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
105*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo);
106*4882a593Smuzhiyun int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
107*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
108*4882a593Smuzhiyun int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
109*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
110*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_INPUT_BEEP
111*4882a593Smuzhiyun int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
112*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
113*4882a593Smuzhiyun int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
114*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol);
115*4882a593Smuzhiyun #endif
116*4882a593Smuzhiyun /* lowlevel accessor with caching; use carefully */
117*4882a593Smuzhiyun #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
118*4882a593Smuzhiyun snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
119*4882a593Smuzhiyun int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
120*4882a593Smuzhiyun int ch, int dir, int idx, int mask, int val);
121*4882a593Smuzhiyun int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
122*4882a593Smuzhiyun int direction, int idx, int mask, int val);
123*4882a593Smuzhiyun int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
124*4882a593Smuzhiyun int direction, int idx, int mask, int val);
125*4882a593Smuzhiyun int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
126*4882a593Smuzhiyun int dir, int idx, int mask, int val);
127*4882a593Smuzhiyun void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
128*4882a593Smuzhiyun unsigned int *tlv);
129*4882a593Smuzhiyun struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
130*4882a593Smuzhiyun const char *name);
131*4882a593Smuzhiyun int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
132*4882a593Smuzhiyun unsigned int *tlv, const char * const *followers,
133*4882a593Smuzhiyun const char *suffix, bool init_follower_vol,
134*4882a593Smuzhiyun struct snd_kcontrol **ctl_ret);
135*4882a593Smuzhiyun #define snd_hda_add_vmaster(codec, name, tlv, followers, suffix) \
136*4882a593Smuzhiyun __snd_hda_add_vmaster(codec, name, tlv, followers, suffix, true, NULL)
137*4882a593Smuzhiyun int snd_hda_codec_reset(struct hda_codec *codec);
138*4882a593Smuzhiyun void snd_hda_codec_register(struct hda_codec *codec);
139*4882a593Smuzhiyun void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun #define snd_hda_regmap_sync(codec) snd_hdac_regmap_sync(&(codec)->core)
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun enum {
144*4882a593Smuzhiyun HDA_VMUTE_OFF,
145*4882a593Smuzhiyun HDA_VMUTE_ON,
146*4882a593Smuzhiyun HDA_VMUTE_FOLLOW_MASTER,
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun struct hda_vmaster_mute_hook {
150*4882a593Smuzhiyun /* below two fields must be filled by the caller of
151*4882a593Smuzhiyun * snd_hda_add_vmaster_hook() beforehand
152*4882a593Smuzhiyun */
153*4882a593Smuzhiyun struct snd_kcontrol *sw_kctl;
154*4882a593Smuzhiyun void (*hook)(void *, int);
155*4882a593Smuzhiyun /* below are initialized automatically */
156*4882a593Smuzhiyun unsigned int mute_mode; /* HDA_VMUTE_XXX */
157*4882a593Smuzhiyun struct hda_codec *codec;
158*4882a593Smuzhiyun };
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun int snd_hda_add_vmaster_hook(struct hda_codec *codec,
161*4882a593Smuzhiyun struct hda_vmaster_mute_hook *hook,
162*4882a593Smuzhiyun bool expose_enum_ctl);
163*4882a593Smuzhiyun void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun /* amp value bits */
166*4882a593Smuzhiyun #define HDA_AMP_MUTE 0x80
167*4882a593Smuzhiyun #define HDA_AMP_UNMUTE 0x00
168*4882a593Smuzhiyun #define HDA_AMP_VOLMASK 0x7f
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /*
171*4882a593Smuzhiyun * SPDIF I/O
172*4882a593Smuzhiyun */
173*4882a593Smuzhiyun int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
174*4882a593Smuzhiyun hda_nid_t associated_nid,
175*4882a593Smuzhiyun hda_nid_t cvt_nid, int type);
176*4882a593Smuzhiyun #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
177*4882a593Smuzhiyun snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
178*4882a593Smuzhiyun int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /*
181*4882a593Smuzhiyun * input MUX helper
182*4882a593Smuzhiyun */
183*4882a593Smuzhiyun #define HDA_MAX_NUM_INPUTS 16
184*4882a593Smuzhiyun struct hda_input_mux_item {
185*4882a593Smuzhiyun char label[32];
186*4882a593Smuzhiyun unsigned int index;
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun struct hda_input_mux {
189*4882a593Smuzhiyun unsigned int num_items;
190*4882a593Smuzhiyun struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun int snd_hda_input_mux_info(const struct hda_input_mux *imux,
194*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo);
195*4882a593Smuzhiyun int snd_hda_input_mux_put(struct hda_codec *codec,
196*4882a593Smuzhiyun const struct hda_input_mux *imux,
197*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
198*4882a593Smuzhiyun unsigned int *cur_val);
199*4882a593Smuzhiyun int snd_hda_add_imux_item(struct hda_codec *codec,
200*4882a593Smuzhiyun struct hda_input_mux *imux, const char *label,
201*4882a593Smuzhiyun int index, int *type_idx);
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /*
204*4882a593Smuzhiyun * Multi-channel / digital-out PCM helper
205*4882a593Smuzhiyun */
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
208*4882a593Smuzhiyun enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun #define HDA_MAX_OUTS 5
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun struct hda_multi_out {
213*4882a593Smuzhiyun int num_dacs; /* # of DACs, must be more than 1 */
214*4882a593Smuzhiyun const hda_nid_t *dac_nids; /* DAC list */
215*4882a593Smuzhiyun hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
216*4882a593Smuzhiyun hda_nid_t hp_out_nid[HDA_MAX_OUTS]; /* DACs for multiple HPs */
217*4882a593Smuzhiyun hda_nid_t extra_out_nid[HDA_MAX_OUTS]; /* other (e.g. speaker) DACs */
218*4882a593Smuzhiyun hda_nid_t dig_out_nid; /* digital out audio widget */
219*4882a593Smuzhiyun const hda_nid_t *follower_dig_outs;
220*4882a593Smuzhiyun int max_channels; /* currently supported analog channels */
221*4882a593Smuzhiyun int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
222*4882a593Smuzhiyun int no_share_stream; /* don't share a stream with multiple pins */
223*4882a593Smuzhiyun int share_spdif; /* share SPDIF pin */
224*4882a593Smuzhiyun /* PCM information for both analog and SPDIF DACs */
225*4882a593Smuzhiyun unsigned int analog_rates;
226*4882a593Smuzhiyun unsigned int analog_maxbps;
227*4882a593Smuzhiyun u64 analog_formats;
228*4882a593Smuzhiyun unsigned int spdif_rates;
229*4882a593Smuzhiyun unsigned int spdif_maxbps;
230*4882a593Smuzhiyun u64 spdif_formats;
231*4882a593Smuzhiyun };
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
234*4882a593Smuzhiyun struct hda_multi_out *mout);
235*4882a593Smuzhiyun int snd_hda_multi_out_dig_open(struct hda_codec *codec,
236*4882a593Smuzhiyun struct hda_multi_out *mout);
237*4882a593Smuzhiyun int snd_hda_multi_out_dig_close(struct hda_codec *codec,
238*4882a593Smuzhiyun struct hda_multi_out *mout);
239*4882a593Smuzhiyun int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
240*4882a593Smuzhiyun struct hda_multi_out *mout,
241*4882a593Smuzhiyun unsigned int stream_tag,
242*4882a593Smuzhiyun unsigned int format,
243*4882a593Smuzhiyun struct snd_pcm_substream *substream);
244*4882a593Smuzhiyun int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
245*4882a593Smuzhiyun struct hda_multi_out *mout);
246*4882a593Smuzhiyun int snd_hda_multi_out_analog_open(struct hda_codec *codec,
247*4882a593Smuzhiyun struct hda_multi_out *mout,
248*4882a593Smuzhiyun struct snd_pcm_substream *substream,
249*4882a593Smuzhiyun struct hda_pcm_stream *hinfo);
250*4882a593Smuzhiyun int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
251*4882a593Smuzhiyun struct hda_multi_out *mout,
252*4882a593Smuzhiyun unsigned int stream_tag,
253*4882a593Smuzhiyun unsigned int format,
254*4882a593Smuzhiyun struct snd_pcm_substream *substream);
255*4882a593Smuzhiyun int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
256*4882a593Smuzhiyun struct hda_multi_out *mout);
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun /*
259*4882a593Smuzhiyun * generic proc interface
260*4882a593Smuzhiyun */
261*4882a593Smuzhiyun #ifdef CONFIG_SND_PROC_FS
262*4882a593Smuzhiyun int snd_hda_codec_proc_new(struct hda_codec *codec);
263*4882a593Smuzhiyun #else
snd_hda_codec_proc_new(struct hda_codec * codec)264*4882a593Smuzhiyun static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
268*4882a593Smuzhiyun void snd_print_pcm_bits(int pcm, char *buf, int buflen);
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun /*
271*4882a593Smuzhiyun * Misc
272*4882a593Smuzhiyun */
273*4882a593Smuzhiyun int snd_hda_add_new_ctls(struct hda_codec *codec,
274*4882a593Smuzhiyun const struct snd_kcontrol_new *knew);
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /*
277*4882a593Smuzhiyun * Fix-up pin default configurations and add default verbs
278*4882a593Smuzhiyun */
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun struct hda_pintbl {
281*4882a593Smuzhiyun hda_nid_t nid;
282*4882a593Smuzhiyun u32 val;
283*4882a593Smuzhiyun };
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun struct hda_model_fixup {
286*4882a593Smuzhiyun const int id;
287*4882a593Smuzhiyun const char *name;
288*4882a593Smuzhiyun };
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun struct hda_fixup {
291*4882a593Smuzhiyun int type;
292*4882a593Smuzhiyun bool chained:1; /* call the chained fixup(s) after this */
293*4882a593Smuzhiyun bool chained_before:1; /* call the chained fixup(s) before this */
294*4882a593Smuzhiyun int chain_id;
295*4882a593Smuzhiyun union {
296*4882a593Smuzhiyun const struct hda_pintbl *pins;
297*4882a593Smuzhiyun const struct hda_verb *verbs;
298*4882a593Smuzhiyun void (*func)(struct hda_codec *codec,
299*4882a593Smuzhiyun const struct hda_fixup *fix,
300*4882a593Smuzhiyun int action);
301*4882a593Smuzhiyun } v;
302*4882a593Smuzhiyun };
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun struct snd_hda_pin_quirk {
305*4882a593Smuzhiyun unsigned int codec; /* Codec vendor/device ID */
306*4882a593Smuzhiyun unsigned short subvendor; /* PCI subvendor ID */
307*4882a593Smuzhiyun const struct hda_pintbl *pins; /* list of matching pins */
308*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG_VERBOSE
309*4882a593Smuzhiyun const char *name;
310*4882a593Smuzhiyun #endif
311*4882a593Smuzhiyun int value; /* quirk value */
312*4882a593Smuzhiyun };
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG_VERBOSE
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
317*4882a593Smuzhiyun { .codec = _codec,\
318*4882a593Smuzhiyun .subvendor = _subvendor,\
319*4882a593Smuzhiyun .name = _name,\
320*4882a593Smuzhiyun .value = _value,\
321*4882a593Smuzhiyun .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun #else
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
326*4882a593Smuzhiyun { .codec = _codec,\
327*4882a593Smuzhiyun .subvendor = _subvendor,\
328*4882a593Smuzhiyun .value = _value,\
329*4882a593Smuzhiyun .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun #endif
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun #define HDA_FIXUP_ID_NOT_SET -1
335*4882a593Smuzhiyun #define HDA_FIXUP_ID_NO_FIXUP -2
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun /* fixup types */
338*4882a593Smuzhiyun enum {
339*4882a593Smuzhiyun HDA_FIXUP_INVALID,
340*4882a593Smuzhiyun HDA_FIXUP_PINS,
341*4882a593Smuzhiyun HDA_FIXUP_VERBS,
342*4882a593Smuzhiyun HDA_FIXUP_FUNC,
343*4882a593Smuzhiyun HDA_FIXUP_PINCTLS,
344*4882a593Smuzhiyun };
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /* fixup action definitions */
347*4882a593Smuzhiyun enum {
348*4882a593Smuzhiyun HDA_FIXUP_ACT_PRE_PROBE,
349*4882a593Smuzhiyun HDA_FIXUP_ACT_PROBE,
350*4882a593Smuzhiyun HDA_FIXUP_ACT_INIT,
351*4882a593Smuzhiyun HDA_FIXUP_ACT_BUILD,
352*4882a593Smuzhiyun HDA_FIXUP_ACT_FREE,
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
356*4882a593Smuzhiyun void snd_hda_apply_verbs(struct hda_codec *codec);
357*4882a593Smuzhiyun void snd_hda_apply_pincfgs(struct hda_codec *codec,
358*4882a593Smuzhiyun const struct hda_pintbl *cfg);
359*4882a593Smuzhiyun void snd_hda_apply_fixup(struct hda_codec *codec, int action);
360*4882a593Smuzhiyun void __snd_hda_apply_fixup(struct hda_codec *codec, int id, int action, int depth);
361*4882a593Smuzhiyun void snd_hda_pick_fixup(struct hda_codec *codec,
362*4882a593Smuzhiyun const struct hda_model_fixup *models,
363*4882a593Smuzhiyun const struct snd_pci_quirk *quirk,
364*4882a593Smuzhiyun const struct hda_fixup *fixlist);
365*4882a593Smuzhiyun void snd_hda_pick_pin_fixup(struct hda_codec *codec,
366*4882a593Smuzhiyun const struct snd_hda_pin_quirk *pin_quirk,
367*4882a593Smuzhiyun const struct hda_fixup *fixlist,
368*4882a593Smuzhiyun bool match_all_pins);
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun /* helper macros to retrieve pin default-config values */
371*4882a593Smuzhiyun #define get_defcfg_connect(cfg) \
372*4882a593Smuzhiyun ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
373*4882a593Smuzhiyun #define get_defcfg_association(cfg) \
374*4882a593Smuzhiyun ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
375*4882a593Smuzhiyun #define get_defcfg_location(cfg) \
376*4882a593Smuzhiyun ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
377*4882a593Smuzhiyun #define get_defcfg_sequence(cfg) \
378*4882a593Smuzhiyun (cfg & AC_DEFCFG_SEQUENCE)
379*4882a593Smuzhiyun #define get_defcfg_device(cfg) \
380*4882a593Smuzhiyun ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
381*4882a593Smuzhiyun #define get_defcfg_misc(cfg) \
382*4882a593Smuzhiyun ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /* amp values */
385*4882a593Smuzhiyun #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
386*4882a593Smuzhiyun #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
387*4882a593Smuzhiyun #define AMP_OUT_MUTE 0xb080
388*4882a593Smuzhiyun #define AMP_OUT_UNMUTE 0xb000
389*4882a593Smuzhiyun #define AMP_OUT_ZERO 0xb000
390*4882a593Smuzhiyun /* pinctl values */
391*4882a593Smuzhiyun #define PIN_IN (AC_PINCTL_IN_EN)
392*4882a593Smuzhiyun #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
393*4882a593Smuzhiyun #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
394*4882a593Smuzhiyun #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
395*4882a593Smuzhiyun #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
396*4882a593Smuzhiyun #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
397*4882a593Smuzhiyun #define PIN_OUT (AC_PINCTL_OUT_EN)
398*4882a593Smuzhiyun #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
399*4882a593Smuzhiyun #define PIN_HP_AMP (AC_PINCTL_HP_EN)
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
402*4882a593Smuzhiyun unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
403*4882a593Smuzhiyun hda_nid_t pin, unsigned int val);
404*4882a593Smuzhiyun int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
405*4882a593Smuzhiyun unsigned int val, bool cached);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun /**
408*4882a593Smuzhiyun * _snd_hda_set_pin_ctl - Set a pin-control value safely
409*4882a593Smuzhiyun * @codec: the codec instance
410*4882a593Smuzhiyun * @pin: the pin NID to set the control
411*4882a593Smuzhiyun * @val: the pin-control value (AC_PINCTL_* bits)
412*4882a593Smuzhiyun *
413*4882a593Smuzhiyun * This function sets the pin-control value to the given pin, but
414*4882a593Smuzhiyun * filters out the invalid pin-control bits when the pin has no such
415*4882a593Smuzhiyun * capabilities. For example, when PIN_HP is passed but the pin has no
416*4882a593Smuzhiyun * HP-drive capability, the HP bit is omitted.
417*4882a593Smuzhiyun *
418*4882a593Smuzhiyun * The function doesn't check the input VREF capability bits, though.
419*4882a593Smuzhiyun * Use snd_hda_get_default_vref() to guess the right value.
420*4882a593Smuzhiyun * Also, this function is only for analog pins, not for HDMI pins.
421*4882a593Smuzhiyun */
422*4882a593Smuzhiyun static inline int
snd_hda_set_pin_ctl(struct hda_codec * codec,hda_nid_t pin,unsigned int val)423*4882a593Smuzhiyun snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun return _snd_hda_set_pin_ctl(codec, pin, val, false);
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun /**
429*4882a593Smuzhiyun * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
430*4882a593Smuzhiyun * @codec: the codec instance
431*4882a593Smuzhiyun * @pin: the pin NID to set the control
432*4882a593Smuzhiyun * @val: the pin-control value (AC_PINCTL_* bits)
433*4882a593Smuzhiyun *
434*4882a593Smuzhiyun * Just like snd_hda_set_pin_ctl() but write to cache as well.
435*4882a593Smuzhiyun */
436*4882a593Smuzhiyun static inline int
snd_hda_set_pin_ctl_cache(struct hda_codec * codec,hda_nid_t pin,unsigned int val)437*4882a593Smuzhiyun snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
438*4882a593Smuzhiyun unsigned int val)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun return _snd_hda_set_pin_ctl(codec, pin, val, true);
441*4882a593Smuzhiyun }
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
444*4882a593Smuzhiyun int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
445*4882a593Smuzhiyun unsigned int val);
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun #define for_each_hda_codec_node(nid, codec) \
448*4882a593Smuzhiyun for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * get widget capabilities
452*4882a593Smuzhiyun */
get_wcaps(struct hda_codec * codec,hda_nid_t nid)453*4882a593Smuzhiyun static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
454*4882a593Smuzhiyun {
455*4882a593Smuzhiyun if (nid < codec->core.start_nid ||
456*4882a593Smuzhiyun nid >= codec->core.start_nid + codec->core.num_nodes)
457*4882a593Smuzhiyun return 0;
458*4882a593Smuzhiyun return codec->wcaps[nid - codec->core.start_nid];
459*4882a593Smuzhiyun }
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun /* get the widget type from widget capability bits */
get_wcaps_type(unsigned int wcaps)462*4882a593Smuzhiyun static inline int get_wcaps_type(unsigned int wcaps)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun if (!wcaps)
465*4882a593Smuzhiyun return -1; /* invalid type */
466*4882a593Smuzhiyun return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun
get_wcaps_channels(u32 wcaps)469*4882a593Smuzhiyun static inline unsigned int get_wcaps_channels(u32 wcaps)
470*4882a593Smuzhiyun {
471*4882a593Smuzhiyun unsigned int chans;
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
474*4882a593Smuzhiyun chans = ((chans << 1) | 1) + 1;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun return chans;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun
snd_hda_override_wcaps(struct hda_codec * codec,hda_nid_t nid,u32 val)479*4882a593Smuzhiyun static inline void snd_hda_override_wcaps(struct hda_codec *codec,
480*4882a593Smuzhiyun hda_nid_t nid, u32 val)
481*4882a593Smuzhiyun {
482*4882a593Smuzhiyun if (nid >= codec->core.start_nid &&
483*4882a593Smuzhiyun nid < codec->core.start_nid + codec->core.num_nodes)
484*4882a593Smuzhiyun codec->wcaps[nid - codec->core.start_nid] = val;
485*4882a593Smuzhiyun }
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
488*4882a593Smuzhiyun int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
489*4882a593Smuzhiyun unsigned int caps);
490*4882a593Smuzhiyun /**
491*4882a593Smuzhiyun * snd_hda_query_pin_caps - Query PIN capabilities
492*4882a593Smuzhiyun * @codec: the HD-auio codec
493*4882a593Smuzhiyun * @nid: the NID to query
494*4882a593Smuzhiyun *
495*4882a593Smuzhiyun * Query PIN capabilities for the given widget.
496*4882a593Smuzhiyun * Returns the obtained capability bits.
497*4882a593Smuzhiyun *
498*4882a593Smuzhiyun * When cap bits have been already read, this doesn't read again but
499*4882a593Smuzhiyun * returns the cached value.
500*4882a593Smuzhiyun */
501*4882a593Smuzhiyun static inline u32
snd_hda_query_pin_caps(struct hda_codec * codec,hda_nid_t nid)502*4882a593Smuzhiyun snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
503*4882a593Smuzhiyun {
504*4882a593Smuzhiyun return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun }
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun /**
509*4882a593Smuzhiyun * snd_hda_override_pin_caps - Override the pin capabilities
510*4882a593Smuzhiyun * @codec: the CODEC
511*4882a593Smuzhiyun * @nid: the NID to override
512*4882a593Smuzhiyun * @caps: the capability bits to set
513*4882a593Smuzhiyun *
514*4882a593Smuzhiyun * Override the cached PIN capabilitiy bits value by the given one.
515*4882a593Smuzhiyun *
516*4882a593Smuzhiyun * Returns zero if successful or a negative error code.
517*4882a593Smuzhiyun */
518*4882a593Smuzhiyun static inline int
snd_hda_override_pin_caps(struct hda_codec * codec,hda_nid_t nid,unsigned int caps)519*4882a593Smuzhiyun snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
520*4882a593Smuzhiyun unsigned int caps)
521*4882a593Smuzhiyun {
522*4882a593Smuzhiyun return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
523*4882a593Smuzhiyun }
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
526*4882a593Smuzhiyun int dir, unsigned int bits);
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun #define nid_has_mute(codec, nid, dir) \
529*4882a593Smuzhiyun snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
530*4882a593Smuzhiyun #define nid_has_volume(codec, nid, dir) \
531*4882a593Smuzhiyun snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun /* flags for hda_nid_item */
535*4882a593Smuzhiyun #define HDA_NID_ITEM_AMP (1<<0)
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun struct hda_nid_item {
538*4882a593Smuzhiyun struct snd_kcontrol *kctl;
539*4882a593Smuzhiyun unsigned int index;
540*4882a593Smuzhiyun hda_nid_t nid;
541*4882a593Smuzhiyun unsigned short flags;
542*4882a593Smuzhiyun };
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
545*4882a593Smuzhiyun struct snd_kcontrol *kctl);
546*4882a593Smuzhiyun int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
547*4882a593Smuzhiyun unsigned int index, hda_nid_t nid);
548*4882a593Smuzhiyun void snd_hda_ctls_clear(struct hda_codec *codec);
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /*
551*4882a593Smuzhiyun * hwdep interface
552*4882a593Smuzhiyun */
553*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_HWDEP
554*4882a593Smuzhiyun int snd_hda_create_hwdep(struct hda_codec *codec);
555*4882a593Smuzhiyun #else
snd_hda_create_hwdep(struct hda_codec * codec)556*4882a593Smuzhiyun static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
557*4882a593Smuzhiyun #endif
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun void snd_hda_sysfs_init(struct hda_codec *codec);
560*4882a593Smuzhiyun void snd_hda_sysfs_clear(struct hda_codec *codec);
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun extern const struct attribute_group *snd_hda_dev_attr_groups[];
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_RECONFIG
565*4882a593Smuzhiyun const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
566*4882a593Smuzhiyun int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
567*4882a593Smuzhiyun int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
568*4882a593Smuzhiyun #else
569*4882a593Smuzhiyun static inline
snd_hda_get_hint(struct hda_codec * codec,const char * key)570*4882a593Smuzhiyun const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun return NULL;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun static inline
snd_hda_get_bool_hint(struct hda_codec * codec,const char * key)576*4882a593Smuzhiyun int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
577*4882a593Smuzhiyun {
578*4882a593Smuzhiyun return -ENOENT;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun static inline
snd_hda_get_int_hint(struct hda_codec * codec,const char * key,int * valp)582*4882a593Smuzhiyun int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
583*4882a593Smuzhiyun {
584*4882a593Smuzhiyun return -ENOENT;
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun #endif
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun /*
589*4882a593Smuzhiyun * power-management
590*4882a593Smuzhiyun */
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun void snd_hda_schedule_power_save(struct hda_codec *codec);
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun struct hda_amp_list {
595*4882a593Smuzhiyun hda_nid_t nid;
596*4882a593Smuzhiyun unsigned char dir;
597*4882a593Smuzhiyun unsigned char idx;
598*4882a593Smuzhiyun };
599*4882a593Smuzhiyun
600*4882a593Smuzhiyun struct hda_loopback_check {
601*4882a593Smuzhiyun const struct hda_amp_list *amplist;
602*4882a593Smuzhiyun int power_on;
603*4882a593Smuzhiyun };
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun int snd_hda_check_amp_list_power(struct hda_codec *codec,
606*4882a593Smuzhiyun struct hda_loopback_check *check,
607*4882a593Smuzhiyun hda_nid_t nid);
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /* check whether the actual power state matches with the target state */
610*4882a593Smuzhiyun static inline bool
snd_hda_check_power_state(struct hda_codec * codec,hda_nid_t nid,unsigned int target_state)611*4882a593Smuzhiyun snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
612*4882a593Smuzhiyun unsigned int target_state)
613*4882a593Smuzhiyun {
614*4882a593Smuzhiyun return snd_hdac_check_power_state(&codec->core, nid, target_state);
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun
snd_hda_sync_power_state(struct hda_codec * codec,hda_nid_t nid,unsigned int target_state)617*4882a593Smuzhiyun static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
618*4882a593Smuzhiyun hda_nid_t nid,
619*4882a593Smuzhiyun unsigned int target_state)
620*4882a593Smuzhiyun {
621*4882a593Smuzhiyun return snd_hdac_sync_power_state(&codec->core, nid, target_state);
622*4882a593Smuzhiyun }
623*4882a593Smuzhiyun unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
624*4882a593Smuzhiyun hda_nid_t nid,
625*4882a593Smuzhiyun unsigned int power_state);
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun /*
628*4882a593Smuzhiyun * AMP control callbacks
629*4882a593Smuzhiyun */
630*4882a593Smuzhiyun /* retrieve parameters from private_value */
631*4882a593Smuzhiyun #define get_amp_nid_(pv) ((pv) & 0xffff)
632*4882a593Smuzhiyun #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
633*4882a593Smuzhiyun #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
634*4882a593Smuzhiyun #define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
635*4882a593Smuzhiyun #define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
636*4882a593Smuzhiyun #define get_amp_index_(pv) (((pv) >> 19) & 0xf)
637*4882a593Smuzhiyun #define get_amp_index(kc) get_amp_index_((kc)->private_value)
638*4882a593Smuzhiyun #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
639*4882a593Smuzhiyun #define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun /*
642*4882a593Smuzhiyun * enum control helper
643*4882a593Smuzhiyun */
644*4882a593Smuzhiyun int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
645*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo,
646*4882a593Smuzhiyun int num_items, const char * const *texts);
647*4882a593Smuzhiyun #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
648*4882a593Smuzhiyun snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun /*
651*4882a593Smuzhiyun * CEA Short Audio Descriptor data
652*4882a593Smuzhiyun */
653*4882a593Smuzhiyun struct cea_sad {
654*4882a593Smuzhiyun int channels;
655*4882a593Smuzhiyun int format; /* (format == 0) indicates invalid SAD */
656*4882a593Smuzhiyun int rates;
657*4882a593Smuzhiyun int sample_bits; /* for LPCM */
658*4882a593Smuzhiyun int max_bitrate; /* for AC3...ATRAC */
659*4882a593Smuzhiyun int profile; /* for WMAPRO */
660*4882a593Smuzhiyun };
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun #define ELD_FIXED_BYTES 20
663*4882a593Smuzhiyun #define ELD_MAX_SIZE 256
664*4882a593Smuzhiyun #define ELD_MAX_MNL 16
665*4882a593Smuzhiyun #define ELD_MAX_SAD 16
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun /*
668*4882a593Smuzhiyun * ELD: EDID Like Data
669*4882a593Smuzhiyun */
670*4882a593Smuzhiyun struct parsed_hdmi_eld {
671*4882a593Smuzhiyun /*
672*4882a593Smuzhiyun * all fields will be cleared before updating ELD
673*4882a593Smuzhiyun */
674*4882a593Smuzhiyun int baseline_len;
675*4882a593Smuzhiyun int eld_ver;
676*4882a593Smuzhiyun int cea_edid_ver;
677*4882a593Smuzhiyun char monitor_name[ELD_MAX_MNL + 1];
678*4882a593Smuzhiyun int manufacture_id;
679*4882a593Smuzhiyun int product_id;
680*4882a593Smuzhiyun u64 port_id;
681*4882a593Smuzhiyun int support_hdcp;
682*4882a593Smuzhiyun int support_ai;
683*4882a593Smuzhiyun int conn_type;
684*4882a593Smuzhiyun int aud_synch_delay;
685*4882a593Smuzhiyun int spk_alloc;
686*4882a593Smuzhiyun int sad_count;
687*4882a593Smuzhiyun struct cea_sad sad[ELD_MAX_SAD];
688*4882a593Smuzhiyun };
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun struct hdmi_eld {
691*4882a593Smuzhiyun bool monitor_present;
692*4882a593Smuzhiyun bool eld_valid;
693*4882a593Smuzhiyun int eld_size;
694*4882a593Smuzhiyun char eld_buffer[ELD_MAX_SIZE];
695*4882a593Smuzhiyun struct parsed_hdmi_eld info;
696*4882a593Smuzhiyun };
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
699*4882a593Smuzhiyun int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
700*4882a593Smuzhiyun unsigned char *buf, int *eld_size);
701*4882a593Smuzhiyun int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
702*4882a593Smuzhiyun const unsigned char *buf, int size);
703*4882a593Smuzhiyun void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
704*4882a593Smuzhiyun void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
705*4882a593Smuzhiyun struct hda_pcm_stream *hinfo);
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
708*4882a593Smuzhiyun unsigned char *buf, int *eld_size,
709*4882a593Smuzhiyun bool rev3_or_later);
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun #ifdef CONFIG_SND_PROC_FS
712*4882a593Smuzhiyun void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
713*4882a593Smuzhiyun struct snd_info_buffer *buffer);
714*4882a593Smuzhiyun void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
715*4882a593Smuzhiyun struct snd_info_buffer *buffer);
716*4882a593Smuzhiyun #endif
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
719*4882a593Smuzhiyun void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun /*
722*4882a593Smuzhiyun */
723*4882a593Smuzhiyun #define codec_err(codec, fmt, args...) \
724*4882a593Smuzhiyun dev_err(hda_codec_dev(codec), fmt, ##args)
725*4882a593Smuzhiyun #define codec_warn(codec, fmt, args...) \
726*4882a593Smuzhiyun dev_warn(hda_codec_dev(codec), fmt, ##args)
727*4882a593Smuzhiyun #define codec_info(codec, fmt, args...) \
728*4882a593Smuzhiyun dev_info(hda_codec_dev(codec), fmt, ##args)
729*4882a593Smuzhiyun #define codec_dbg(codec, fmt, args...) \
730*4882a593Smuzhiyun dev_dbg(hda_codec_dev(codec), fmt, ##args)
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun #endif /* __SOUND_HDA_LOCAL_H */
733