2 * Common codes for Realtek codec quirks
3 * included by patch_realtek.c
7 * configuration template - to be copied to the spec instance
9 struct alc_config_preset
{
10 const struct snd_kcontrol_new
*mixers
[5]; /* should be identical size
13 const struct snd_kcontrol_new
*cap_mixer
; /* capture mixer */
14 const struct hda_verb
*init_verbs
[5];
15 unsigned int num_dacs
;
16 const hda_nid_t
*dac_nids
;
17 hda_nid_t dig_out_nid
; /* optional */
18 hda_nid_t hp_nid
; /* optional */
19 const hda_nid_t
*slave_dig_outs
;
20 unsigned int num_adc_nids
;
21 const hda_nid_t
*adc_nids
;
22 const hda_nid_t
*capsrc_nids
;
24 unsigned int num_channel_mode
;
25 const struct hda_channel_mode
*channel_mode
;
27 int const_channel_count
;
28 unsigned int num_mux_defs
;
29 const struct hda_input_mux
*input_mux
;
30 void (*unsol_event
)(struct hda_codec
*, unsigned int);
31 void (*setup
)(struct hda_codec
*);
32 void (*init_hook
)(struct hda_codec
*);
33 #ifdef CONFIG_SND_HDA_POWER_SAVE
34 const struct hda_amp_list
*loopbacks
;
35 void (*power_hook
)(struct hda_codec
*codec
);
40 * channel mode setting
42 static int alc_ch_mode_info(struct snd_kcontrol
*kcontrol
,
43 struct snd_ctl_elem_info
*uinfo
)
45 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
46 struct alc_spec
*spec
= codec
->spec
;
47 return snd_hda_ch_mode_info(codec
, uinfo
, spec
->channel_mode
,
48 spec
->num_channel_mode
);
51 static int alc_ch_mode_get(struct snd_kcontrol
*kcontrol
,
52 struct snd_ctl_elem_value
*ucontrol
)
54 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
55 struct alc_spec
*spec
= codec
->spec
;
56 return snd_hda_ch_mode_get(codec
, ucontrol
, spec
->channel_mode
,
57 spec
->num_channel_mode
,
58 spec
->ext_channel_count
);
61 static int alc_ch_mode_put(struct snd_kcontrol
*kcontrol
,
62 struct snd_ctl_elem_value
*ucontrol
)
64 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
65 struct alc_spec
*spec
= codec
->spec
;
66 int err
= snd_hda_ch_mode_put(codec
, ucontrol
, spec
->channel_mode
,
67 spec
->num_channel_mode
,
68 &spec
->ext_channel_count
);
69 if (err
>= 0 && !spec
->const_channel_count
) {
70 spec
->multiout
.max_channels
= spec
->ext_channel_count
;
71 if (spec
->need_dac_fix
)
72 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
78 * Control the mode of pin widget settings via the mixer. "pc" is used
79 * instead of "%" to avoid consequences of accidentally treating the % as
80 * being part of a format specifier. Maximum allowed length of a value is
81 * 63 characters plus NULL terminator.
83 * Note: some retasking pin complexes seem to ignore requests for input
84 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
85 * are requested. Therefore order this list so that this behaviour will not
86 * cause problems when mixer clients move through the enum sequentially.
87 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
90 static const char * const alc_pin_mode_names
[] = {
91 "Mic 50pc bias", "Mic 80pc bias",
92 "Line in", "Line out", "Headphone out",
94 static const unsigned char alc_pin_mode_values
[] = {
95 PIN_VREF50
, PIN_VREF80
, PIN_IN
, PIN_OUT
, PIN_HP
,
97 /* The control can present all 5 options, or it can limit the options based
98 * in the pin being assumed to be exclusively an input or an output pin. In
99 * addition, "input" pins may or may not process the mic bias option
100 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
101 * accept requests for bias as of chip versions up to March 2006) and/or
102 * wiring in the computer.
104 #define ALC_PIN_DIR_IN 0x00
105 #define ALC_PIN_DIR_OUT 0x01
106 #define ALC_PIN_DIR_INOUT 0x02
107 #define ALC_PIN_DIR_IN_NOMICBIAS 0x03
108 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
110 /* Info about the pin modes supported by the different pin direction modes.
111 * For each direction the minimum and maximum values are given.
113 static const signed char alc_pin_mode_dir_info
[5][2] = {
114 { 0, 2 }, /* ALC_PIN_DIR_IN */
115 { 3, 4 }, /* ALC_PIN_DIR_OUT */
116 { 0, 4 }, /* ALC_PIN_DIR_INOUT */
117 { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */
118 { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */
120 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
121 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
122 #define alc_pin_mode_n_items(_dir) \
123 (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
125 static int alc_pin_mode_info(struct snd_kcontrol
*kcontrol
,
126 struct snd_ctl_elem_info
*uinfo
)
128 unsigned int item_num
= uinfo
->value
.enumerated
.item
;
129 unsigned char dir
= (kcontrol
->private_value
>> 16) & 0xff;
131 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
133 uinfo
->value
.enumerated
.items
= alc_pin_mode_n_items(dir
);
135 if (item_num
<alc_pin_mode_min(dir
) || item_num
>alc_pin_mode_max(dir
))
136 item_num
= alc_pin_mode_min(dir
);
137 strcpy(uinfo
->value
.enumerated
.name
, alc_pin_mode_names
[item_num
]);
141 static int alc_pin_mode_get(struct snd_kcontrol
*kcontrol
,
142 struct snd_ctl_elem_value
*ucontrol
)
145 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
146 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
147 unsigned char dir
= (kcontrol
->private_value
>> 16) & 0xff;
148 long *valp
= ucontrol
->value
.integer
.value
;
149 unsigned int pinctl
= snd_hda_codec_read(codec
, nid
, 0,
150 AC_VERB_GET_PIN_WIDGET_CONTROL
,
153 /* Find enumerated value for current pinctl setting */
154 i
= alc_pin_mode_min(dir
);
155 while (i
<= alc_pin_mode_max(dir
) && alc_pin_mode_values
[i
] != pinctl
)
157 *valp
= i
<= alc_pin_mode_max(dir
) ? i
: alc_pin_mode_min(dir
);
161 static int alc_pin_mode_put(struct snd_kcontrol
*kcontrol
,
162 struct snd_ctl_elem_value
*ucontrol
)
165 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
166 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
167 unsigned char dir
= (kcontrol
->private_value
>> 16) & 0xff;
168 long val
= *ucontrol
->value
.integer
.value
;
169 unsigned int pinctl
= snd_hda_codec_read(codec
, nid
, 0,
170 AC_VERB_GET_PIN_WIDGET_CONTROL
,
173 if (val
< alc_pin_mode_min(dir
) || val
> alc_pin_mode_max(dir
))
174 val
= alc_pin_mode_min(dir
);
176 change
= pinctl
!= alc_pin_mode_values
[val
];
178 /* Set pin mode to that requested */
179 snd_hda_codec_write_cache(codec
, nid
, 0,
180 AC_VERB_SET_PIN_WIDGET_CONTROL
,
181 alc_pin_mode_values
[val
]);
183 /* Also enable the retasking pin's input/output as required
184 * for the requested pin mode. Enum values of 2 or less are
187 * Dynamically switching the input/output buffers probably
188 * reduces noise slightly (particularly on input) so we'll
189 * do it. However, having both input and output buffers
190 * enabled simultaneously doesn't seem to be problematic if
191 * this turns out to be necessary in the future.
194 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
195 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
196 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
199 snd_hda_codec_amp_stereo(codec
, nid
, HDA_INPUT
, 0,
200 HDA_AMP_MUTE
, HDA_AMP_MUTE
);
201 snd_hda_codec_amp_stereo(codec
, nid
, HDA_OUTPUT
, 0,
208 #define ALC_PIN_MODE(xname, nid, dir) \
209 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
210 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
211 .info = alc_pin_mode_info, \
212 .get = alc_pin_mode_get, \
213 .put = alc_pin_mode_put, \
214 .private_value = nid | (dir<<16) }
216 /* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged
217 * together using a mask with more than one bit set. This control is
218 * currently used only by the ALC260 test model. At this stage they are not
219 * needed for any "production" models.
221 #ifdef CONFIG_SND_DEBUG
222 #define alc_gpio_data_info snd_ctl_boolean_mono_info
224 static int alc_gpio_data_get(struct snd_kcontrol
*kcontrol
,
225 struct snd_ctl_elem_value
*ucontrol
)
227 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
228 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
229 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
230 long *valp
= ucontrol
->value
.integer
.value
;
231 unsigned int val
= snd_hda_codec_read(codec
, nid
, 0,
232 AC_VERB_GET_GPIO_DATA
, 0x00);
234 *valp
= (val
& mask
) != 0;
237 static int alc_gpio_data_put(struct snd_kcontrol
*kcontrol
,
238 struct snd_ctl_elem_value
*ucontrol
)
241 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
242 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
243 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
244 long val
= *ucontrol
->value
.integer
.value
;
245 unsigned int gpio_data
= snd_hda_codec_read(codec
, nid
, 0,
246 AC_VERB_GET_GPIO_DATA
,
249 /* Set/unset the masked GPIO bit(s) as needed */
250 change
= (val
== 0 ? 0 : mask
) != (gpio_data
& mask
);
255 snd_hda_codec_write_cache(codec
, nid
, 0,
256 AC_VERB_SET_GPIO_DATA
, gpio_data
);
260 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
261 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
262 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
263 .info = alc_gpio_data_info, \
264 .get = alc_gpio_data_get, \
265 .put = alc_gpio_data_put, \
266 .private_value = nid | (mask<<16) }
267 #endif /* CONFIG_SND_DEBUG */
269 /* A switch control to allow the enabling of the digital IO pins on the
270 * ALC260. This is incredibly simplistic; the intention of this control is
271 * to provide something in the test model allowing digital outputs to be
272 * identified if present. If models are found which can utilise these
273 * outputs a more complete mixer control can be devised for those models if
276 #ifdef CONFIG_SND_DEBUG
277 #define alc_spdif_ctrl_info snd_ctl_boolean_mono_info
279 static int alc_spdif_ctrl_get(struct snd_kcontrol
*kcontrol
,
280 struct snd_ctl_elem_value
*ucontrol
)
282 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
283 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
284 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
285 long *valp
= ucontrol
->value
.integer
.value
;
286 unsigned int val
= snd_hda_codec_read(codec
, nid
, 0,
287 AC_VERB_GET_DIGI_CONVERT_1
, 0x00);
289 *valp
= (val
& mask
) != 0;
292 static int alc_spdif_ctrl_put(struct snd_kcontrol
*kcontrol
,
293 struct snd_ctl_elem_value
*ucontrol
)
296 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
297 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
298 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
299 long val
= *ucontrol
->value
.integer
.value
;
300 unsigned int ctrl_data
= snd_hda_codec_read(codec
, nid
, 0,
301 AC_VERB_GET_DIGI_CONVERT_1
,
304 /* Set/unset the masked control bit(s) as needed */
305 change
= (val
== 0 ? 0 : mask
) != (ctrl_data
& mask
);
310 snd_hda_codec_write_cache(codec
, nid
, 0, AC_VERB_SET_DIGI_CONVERT_1
,
315 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
316 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
317 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
318 .info = alc_spdif_ctrl_info, \
319 .get = alc_spdif_ctrl_get, \
320 .put = alc_spdif_ctrl_put, \
321 .private_value = nid | (mask<<16) }
322 #endif /* CONFIG_SND_DEBUG */
324 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
325 * Again, this is only used in the ALC26x test models to help identify when
326 * the EAPD line must be asserted for features to work.
328 #ifdef CONFIG_SND_DEBUG
329 #define alc_eapd_ctrl_info snd_ctl_boolean_mono_info
331 static int alc_eapd_ctrl_get(struct snd_kcontrol
*kcontrol
,
332 struct snd_ctl_elem_value
*ucontrol
)
334 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
335 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
336 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
337 long *valp
= ucontrol
->value
.integer
.value
;
338 unsigned int val
= snd_hda_codec_read(codec
, nid
, 0,
339 AC_VERB_GET_EAPD_BTLENABLE
, 0x00);
341 *valp
= (val
& mask
) != 0;
345 static int alc_eapd_ctrl_put(struct snd_kcontrol
*kcontrol
,
346 struct snd_ctl_elem_value
*ucontrol
)
349 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
350 hda_nid_t nid
= kcontrol
->private_value
& 0xffff;
351 unsigned char mask
= (kcontrol
->private_value
>> 16) & 0xff;
352 long val
= *ucontrol
->value
.integer
.value
;
353 unsigned int ctrl_data
= snd_hda_codec_read(codec
, nid
, 0,
354 AC_VERB_GET_EAPD_BTLENABLE
,
357 /* Set/unset the masked control bit(s) as needed */
358 change
= (!val
? 0 : mask
) != (ctrl_data
& mask
);
363 snd_hda_codec_write_cache(codec
, nid
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
369 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
370 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
371 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
372 .info = alc_eapd_ctrl_info, \
373 .get = alc_eapd_ctrl_get, \
374 .put = alc_eapd_ctrl_put, \
375 .private_value = nid | (mask<<16) }
376 #endif /* CONFIG_SND_DEBUG */
378 static void alc_fixup_autocfg_pin_nums(struct hda_codec
*codec
)
380 struct alc_spec
*spec
= codec
->spec
;
381 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
383 if (!cfg
->line_outs
) {
384 while (cfg
->line_outs
< AUTO_CFG_MAX_OUTS
&&
385 cfg
->line_out_pins
[cfg
->line_outs
])
388 if (!cfg
->speaker_outs
) {
389 while (cfg
->speaker_outs
< AUTO_CFG_MAX_OUTS
&&
390 cfg
->speaker_pins
[cfg
->speaker_outs
])
394 while (cfg
->hp_outs
< AUTO_CFG_MAX_OUTS
&&
395 cfg
->hp_pins
[cfg
->hp_outs
])
401 * set up from the preset table
403 static void setup_preset(struct hda_codec
*codec
,
404 const struct alc_config_preset
*preset
)
406 struct alc_spec
*spec
= codec
->spec
;
409 for (i
= 0; i
< ARRAY_SIZE(preset
->mixers
) && preset
->mixers
[i
]; i
++)
410 add_mixer(spec
, preset
->mixers
[i
]);
411 spec
->cap_mixer
= preset
->cap_mixer
;
412 for (i
= 0; i
< ARRAY_SIZE(preset
->init_verbs
) && preset
->init_verbs
[i
];
414 add_verb(spec
, preset
->init_verbs
[i
]);
416 spec
->channel_mode
= preset
->channel_mode
;
417 spec
->num_channel_mode
= preset
->num_channel_mode
;
418 spec
->need_dac_fix
= preset
->need_dac_fix
;
419 spec
->const_channel_count
= preset
->const_channel_count
;
421 if (preset
->const_channel_count
)
422 spec
->multiout
.max_channels
= preset
->const_channel_count
;
424 spec
->multiout
.max_channels
= spec
->channel_mode
[0].channels
;
425 spec
->ext_channel_count
= spec
->channel_mode
[0].channels
;
427 spec
->multiout
.num_dacs
= preset
->num_dacs
;
428 spec
->multiout
.dac_nids
= preset
->dac_nids
;
429 spec
->multiout
.dig_out_nid
= preset
->dig_out_nid
;
430 spec
->multiout
.slave_dig_outs
= preset
->slave_dig_outs
;
431 spec
->multiout
.hp_nid
= preset
->hp_nid
;
433 spec
->num_mux_defs
= preset
->num_mux_defs
;
434 if (!spec
->num_mux_defs
)
435 spec
->num_mux_defs
= 1;
436 spec
->input_mux
= preset
->input_mux
;
438 spec
->num_adc_nids
= preset
->num_adc_nids
;
439 spec
->adc_nids
= preset
->adc_nids
;
440 spec
->capsrc_nids
= preset
->capsrc_nids
;
441 spec
->dig_in_nid
= preset
->dig_in_nid
;
443 spec
->unsol_event
= preset
->unsol_event
;
444 spec
->init_hook
= preset
->init_hook
;
445 #ifdef CONFIG_SND_HDA_POWER_SAVE
446 spec
->power_hook
= preset
->power_hook
;
447 spec
->loopback
.amplist
= preset
->loopbacks
;
451 preset
->setup(codec
);
453 alc_fixup_autocfg_pin_nums(codec
);
457 /* auto-toggle front mic */
458 static void alc88x_simple_mic_automute(struct hda_codec
*codec
)
460 unsigned int present
;
463 present
= snd_hda_jack_detect(codec
, 0x18);
464 bits
= present
? HDA_AMP_MUTE
: 0;
465 snd_hda_codec_amp_stereo(codec
, 0x0b, HDA_INPUT
, 1, HDA_AMP_MUTE
, bits
);