]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - sound/pci/hda/patch_conexant.c
ALSA: hda - Add mute LED support for HP ProBook 470 G5
[thirdparty/kernel/stable.git] / sound / pci / hda / patch_conexant.c
CommitLineData
c9b443d4
TD
1/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
c9b443d4
TD
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
da155d5b 26#include <linux/module.h>
c9b443d4 27#include <sound/core.h>
bc7a166d
UD
28#include <sound/jack.h>
29
c9b443d4
TD
30#include "hda_codec.h"
31#include "hda_local.h"
23d30f28 32#include "hda_auto_parser.h"
c0f8faf0 33#include "hda_beep.h"
1835a0f9 34#include "hda_jack.h"
aed523f1 35#include "hda_generic.h"
c9b443d4 36
d0ea6d27
TI
37struct conexant_spec {
38 struct hda_gen_spec gen;
0fb67e98 39
d0ea6d27 40 unsigned int beep_amp;
cfd3d8dc 41
d0ea6d27
TI
42 /* extra EAPD pins */
43 unsigned int num_eapds;
44 hda_nid_t eapds[4];
45 bool dynamic_eapd;
3542aed7 46 hda_nid_t mute_led_eapd;
7b2bfdbc 47
d0ea6d27 48 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
02b6b5b6 49
d0ea6d27
TI
50 /* OPLC XO specific */
51 bool recording;
52 bool dc_enable;
53 unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
54 struct nid_path *dc_mode_path;
5cd5b1bd
JB
55
56 int mute_led_polarity;
57 unsigned int gpio_led;
58 unsigned int gpio_mute_led_mask;
59 unsigned int gpio_mic_led_mask;
60
0fb67e98
DD
61};
62
c4cfe66c 63
d0ea6d27
TI
64#ifdef CONFIG_SND_HDA_INPUT_BEEP
65static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
66 int idx, int dir)
f6a2491c 67{
d0ea6d27
TI
68 spec->gen.beep_nid = nid;
69 spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
f6a2491c 70}
d0ea6d27
TI
71/* additional beep mixers; the actual parameters are overwritten at build */
72static const struct snd_kcontrol_new cxt_beep_mixer[] = {
73 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
74 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
048e78a5
DH
75 { } /* end */
76};
77
d0ea6d27
TI
78/* create beep controls if needed */
79static int add_beep_ctls(struct hda_codec *codec)
0fb67e98 80{
d0ea6d27
TI
81 struct conexant_spec *spec = codec->spec;
82 int err;
048e78a5 83
d0ea6d27
TI
84 if (spec->beep_amp) {
85 const struct snd_kcontrol_new *knew;
86 for (knew = cxt_beep_mixer; knew->name; knew++) {
87 struct snd_kcontrol *kctl;
88 kctl = snd_ctl_new1(knew, codec);
89 if (!kctl)
90 return -ENOMEM;
91 kctl->private_value = spec->beep_amp;
92 err = snd_hda_ctl_add(codec, 0, kctl);
93 if (err < 0)
94 return err;
95 }
0fb67e98 96 }
0fb67e98
DD
97 return 0;
98}
d0ea6d27
TI
99#else
100#define set_beep_amp(spec, nid, idx, dir) /* NOP */
101#define add_beep_ctls(codec) 0
102#endif
bf92d1d5 103
f2e5731d
TI
104/*
105 * Automatic parser for CX20641 & co
106 */
107
f2e5731d
TI
108#ifdef CONFIG_SND_HDA_INPUT_BEEP
109static void cx_auto_parse_beep(struct hda_codec *codec)
6764bcef
TI
110{
111 struct conexant_spec *spec = codec->spec;
7639a06c 112 hda_nid_t nid;
f2e5731d 113
7639a06c 114 for_each_hda_codec_node(nid, codec)
f2e5731d
TI
115 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
116 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
f2e5731d
TI
117 break;
118 }
f2e5731d 119}
f2e5731d
TI
120#else
121#define cx_auto_parse_beep(codec)
122#endif
f2e5731d 123
254f2968 124/* parse EAPDs */
19110595 125static void cx_auto_parse_eapd(struct hda_codec *codec)
f2e5731d 126{
19110595 127 struct conexant_spec *spec = codec->spec;
7639a06c 128 hda_nid_t nid;
f2e5731d 129
7639a06c 130 for_each_hda_codec_node(nid, codec) {
19110595 131 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
468c5458 132 continue;
19110595 133 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
f2e5731d 134 continue;
19110595
TI
135 spec->eapds[spec->num_eapds++] = nid;
136 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
03697e2a 137 break;
03697e2a
TI
138 }
139
254f2968
TI
140 /* NOTE: below is a wild guess; if we have more than two EAPDs,
141 * it's a new chip, where EAPDs are supposed to be associated to
142 * pins, and we can control EAPD per pin.
143 * OTOH, if only one or two EAPDs are found, it's an old chip,
144 * thus it might control over all pins.
145 */
aed523f1 146 if (spec->num_eapds > 2)
ff359b14 147 spec->dynamic_eapd = 1;
f2e5731d
TI
148}
149
da339866 150static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
da339866 151 hda_nid_t *pins, bool on)
03697e2a
TI
152{
153 int i;
03697e2a 154 for (i = 0; i < num_pins; i++) {
f2e5731d
TI
155 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
156 snd_hda_codec_write(codec, pins[i], 0,
da339866
TI
157 AC_VERB_SET_EAPD_BTLENABLE,
158 on ? 0x02 : 0);
e2df82ff 159 }
03697e2a
TI
160}
161
527c73ba
TI
162/* turn on/off EAPD according to Master switch */
163static void cx_auto_vmaster_hook(void *private_data, int enabled)
f2e5731d 164{
527c73ba 165 struct hda_codec *codec = private_data;
f2e5731d 166 struct conexant_spec *spec = codec->spec;
f2e5731d 167
527c73ba 168 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
03697e2a
TI
169}
170
3542aed7
TI
171/* turn on/off EAPD according to Master switch (inversely!) for mute LED */
172static void cx_auto_vmaster_hook_mute_led(void *private_data, int enabled)
173{
174 struct hda_codec *codec = private_data;
175 struct conexant_spec *spec = codec->spec;
176
177 snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
178 AC_VERB_SET_EAPD_BTLENABLE,
179 enabled ? 0x00 : 0x02);
180}
181
f2e5731d 182static int cx_auto_build_controls(struct hda_codec *codec)
03697e2a 183{
f2e5731d 184 int err;
03697e2a 185
aed523f1 186 err = snd_hda_gen_build_controls(codec);
f2e5731d
TI
187 if (err < 0)
188 return err;
03697e2a 189
aed523f1 190 err = add_beep_ctls(codec);
31ef2257
TI
191 if (err < 0)
192 return err;
03697e2a 193
03697e2a
TI
194 return 0;
195}
196
ff359b14
TI
197static int cx_auto_init(struct hda_codec *codec)
198{
199 struct conexant_spec *spec = codec->spec;
200 snd_hda_gen_init(codec);
201 if (!spec->dynamic_eapd)
202 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
e4c3bce2
DH
203
204 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
205
ff359b14
TI
206 return 0;
207}
208
f6b28e4d
DH
209static void cx_auto_reboot_notify(struct hda_codec *codec)
210{
211 struct conexant_spec *spec = codec->spec;
212
56dc66ff 213 switch (codec->core.vendor_id) {
f7de68a8 214 case 0x14f12008: /* CX8200 */
56dc66ff
TI
215 case 0x14f150f2: /* CX20722 */
216 case 0x14f150f4: /* CX20724 */
217 break;
218 default:
f6b28e4d 219 return;
56dc66ff 220 }
f6b28e4d 221
f7de68a8 222 /* Turn the problematic codec into D3 to avoid spurious noises
f6b28e4d
DH
223 from the internal speaker during (and after) reboot */
224 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
225
226 snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
227 snd_hda_codec_write(codec, codec->core.afg, 0,
228 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
7f4c1552 229 msleep(10);
f6b28e4d
DH
230}
231
232static void cx_auto_free(struct hda_codec *codec)
233{
234 cx_auto_reboot_notify(codec);
235 snd_hda_gen_free(codec);
236}
08cf680c 237
34cbe3a6 238static const struct hda_codec_ops cx_auto_patch_ops = {
f2e5731d 239 .build_controls = cx_auto_build_controls,
aed523f1 240 .build_pcms = snd_hda_gen_build_pcms,
ff359b14 241 .init = cx_auto_init,
f6b28e4d 242 .reboot_notify = cx_auto_reboot_notify,
08cf680c 243 .free = cx_auto_free,
29adc4b9 244 .unsol_event = snd_hda_jack_unsol_event,
164a7ada
TI
245#ifdef CONFIG_PM
246 .check_power_status = snd_hda_gen_check_power_status,
247#endif
f2e5731d 248};
f2e5731d 249
e92d4b08
TI
250/*
251 * pin fix-up
252 */
18dcd304
DH
253enum {
254 CXT_PINCFG_LENOVO_X200,
d3980110 255 CXT_PINCFG_LENOVO_TP410,
239fb862
HC
256 CXT_PINCFG_LEMOTE_A1004,
257 CXT_PINCFG_LEMOTE_A1205,
ddb6ca75 258 CXT_PINCFG_COMPAQ_CQ60,
18dcd304 259 CXT_FIXUP_STEREO_DMIC,
239fb862 260 CXT_FIXUP_INC_MIC_BOOST,
e4c3bce2
DH
261 CXT_FIXUP_HEADPHONE_MIC_PIN,
262 CXT_FIXUP_HEADPHONE_MIC,
4a437044 263 CXT_FIXUP_GPIO1,
ff50479a 264 CXT_FIXUP_ASPIRE_DMIC,
08cf680c 265 CXT_FIXUP_THINKPAD_ACPI,
3a00c660 266 CXT_FIXUP_OLPC_XO,
ad7725d3 267 CXT_FIXUP_CAP_MIX_AMP,
6dcbadef 268 CXT_FIXUP_TOSHIBA_P105,
e5eac90d 269 CXT_FIXUP_HP_530,
ea30e7df 270 CXT_FIXUP_CAP_MIX_AMP_5047,
3542aed7 271 CXT_FIXUP_MUTE_LED_EAPD,
cc3a47a2 272 CXT_FIXUP_HP_DOCK,
0eec8809 273 CXT_FIXUP_HP_SPECTRE,
f73cd43a 274 CXT_FIXUP_HP_GATE_MIC,
5cd5b1bd 275 CXT_FIXUP_MUTE_LED_GPIO,
2845bbd1
HW
276 CXT_FIXUP_HEADSET_MIC,
277 CXT_FIXUP_HP_MIC_NO_PRESENCE,
03697e2a
TI
278};
279
b317b032
TI
280/* for hda_fixup_thinkpad_acpi() */
281#include "thinkpad_helper.c"
08cf680c 282
23d30f28
TI
283static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
284 const struct hda_fixup *fix, int action)
6764bcef 285{
6764bcef 286 struct conexant_spec *spec = codec->spec;
aed523f1 287 spec->gen.inv_dmic_split = 1;
6764bcef
TI
288}
289
239fb862
HC
290static void cxt5066_increase_mic_boost(struct hda_codec *codec,
291 const struct hda_fixup *fix, int action)
6764bcef 292{
239fb862
HC
293 if (action != HDA_FIXUP_ACT_PRE_PROBE)
294 return;
6764bcef 295
239fb862
HC
296 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
297 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
298 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
299 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
300 (0 << AC_AMPCAP_MUTE_SHIFT));
301}
302
e4c3bce2
DH
303static void cxt_update_headset_mode(struct hda_codec *codec)
304{
305 /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
306 int i;
307 bool mic_mode = false;
308 struct conexant_spec *spec = codec->spec;
309 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
310
311 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
312
313 for (i = 0; i < cfg->num_inputs; i++)
314 if (cfg->inputs[i].pin == mux_pin) {
315 mic_mode = !!cfg->inputs[i].is_headphone_mic;
316 break;
317 }
318
319 if (mic_mode) {
320 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
321 spec->gen.hp_jack_present = false;
322 } else {
323 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
324 spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
325 }
326
327 snd_hda_gen_update_outputs(codec);
328}
329
330static void cxt_update_headset_mode_hook(struct hda_codec *codec,
7fe30711
TI
331 struct snd_kcontrol *kcontrol,
332 struct snd_ctl_elem_value *ucontrol)
e4c3bce2
DH
333{
334 cxt_update_headset_mode(codec);
335}
336
337static void cxt_fixup_headphone_mic(struct hda_codec *codec,
338 const struct hda_fixup *fix, int action)
339{
340 struct conexant_spec *spec = codec->spec;
341
342 switch (action) {
343 case HDA_FIXUP_ACT_PRE_PROBE:
344 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
a551d914 345 snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
e4c3bce2
DH
346 break;
347 case HDA_FIXUP_ACT_PROBE:
348 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
349 spec->gen.automute_hook = cxt_update_headset_mode;
350 break;
351 case HDA_FIXUP_ACT_INIT:
352 cxt_update_headset_mode(codec);
353 break;
354 }
355}
356
2845bbd1
HW
357static void cxt_fixup_headset_mic(struct hda_codec *codec,
358 const struct hda_fixup *fix, int action)
359{
360 struct conexant_spec *spec = codec->spec;
361
362 switch (action) {
363 case HDA_FIXUP_ACT_PRE_PROBE:
364 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
365 break;
366 }
367}
368
3a00c660
TI
369/* OPLC XO 1.5 fixup */
370
371/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
372 * through the microphone jack.
373 * When the user enables this through a mixer switch, both internal and
374 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
375 * we also allow the bias to be configured through a separate mixer
376 * control. */
377
378#define update_mic_pin(codec, nid, val) \
379 snd_hda_codec_update_cache(codec, nid, 0, \
380 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
381
382static const struct hda_input_mux olpc_xo_dc_bias = {
383 .num_items = 3,
384 .items = {
385 { "Off", PIN_IN },
386 { "50%", PIN_VREF50 },
387 { "80%", PIN_VREF80 },
388 },
389};
390
391static void olpc_xo_update_mic_boost(struct hda_codec *codec)
392{
393 struct conexant_spec *spec = codec->spec;
394 int ch, val;
395
396 for (ch = 0; ch < 2; ch++) {
397 val = AC_AMP_SET_OUTPUT |
398 (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
399 if (!spec->dc_enable)
400 val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
401 snd_hda_codec_write(codec, 0x17, 0,
402 AC_VERB_SET_AMP_GAIN_MUTE, val);
403 }
404}
405
406static void olpc_xo_update_mic_pins(struct hda_codec *codec)
407{
408 struct conexant_spec *spec = codec->spec;
409 int cur_input, val;
410 struct nid_path *path;
411
412 cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
413
414 /* Set up mic pins for port-B, C and F dynamically as the recording
415 * LED is turned on/off by these pin controls
416 */
417 if (!spec->dc_enable) {
418 /* disable DC bias path and pin for port F */
419 update_mic_pin(codec, 0x1e, 0);
420 snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
421
422 /* update port B (ext mic) and C (int mic) */
423 /* OLPC defers mic widget control until when capture is
424 * started because the microphone LED comes on as soon as
425 * these settings are put in place. if we did this before
426 * recording, it would give the false indication that
427 * recording is happening when it is not.
428 */
429 update_mic_pin(codec, 0x1a, spec->recording ?
430 snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
431 update_mic_pin(codec, 0x1b, spec->recording ?
432 snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
433 /* enable normal mic path */
434 path = snd_hda_get_path_from_idx(codec, cur_input);
435 if (path)
436 snd_hda_activate_path(codec, path, true, false);
437 } else {
438 /* disable normal mic path */
439 path = snd_hda_get_path_from_idx(codec, cur_input);
440 if (path)
441 snd_hda_activate_path(codec, path, false, false);
442
443 /* Even though port F is the DC input, the bias is controlled
444 * on port B. We also leave that port as an active input (but
445 * unselected) in DC mode just in case that is necessary to
446 * make the bias setting take effect.
447 */
448 if (spec->recording)
449 val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
450 else
451 val = 0;
452 update_mic_pin(codec, 0x1a, val);
453 update_mic_pin(codec, 0x1b, 0);
454 /* enable DC bias path and pin */
455 update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
456 snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
457 }
458}
459
460/* mic_autoswitch hook */
1a4f69d5
TI
461static void olpc_xo_automic(struct hda_codec *codec,
462 struct hda_jack_callback *jack)
3a00c660
TI
463{
464 struct conexant_spec *spec = codec->spec;
3a00c660 465
3a00c660
TI
466 /* in DC mode, we don't handle automic */
467 if (!spec->dc_enable)
468 snd_hda_gen_mic_autoswitch(codec, jack);
469 olpc_xo_update_mic_pins(codec);
3a00c660
TI
470 if (spec->dc_enable)
471 olpc_xo_update_mic_boost(codec);
472}
473
474/* pcm_capture hook */
475static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
476 struct hda_codec *codec,
477 struct snd_pcm_substream *substream,
478 int action)
479{
480 struct conexant_spec *spec = codec->spec;
481
482 /* toggle spec->recording flag and update mic pins accordingly
483 * for turning on/off LED
484 */
485 switch (action) {
486 case HDA_GEN_PCM_ACT_PREPARE:
487 spec->recording = 1;
488 olpc_xo_update_mic_pins(codec);
489 break;
490 case HDA_GEN_PCM_ACT_CLEANUP:
491 spec->recording = 0;
492 olpc_xo_update_mic_pins(codec);
493 break;
494 }
495}
496
497static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
499{
500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
501 struct conexant_spec *spec = codec->spec;
502 ucontrol->value.integer.value[0] = spec->dc_enable;
503 return 0;
504}
505
506static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
507 struct snd_ctl_elem_value *ucontrol)
508{
509 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
510 struct conexant_spec *spec = codec->spec;
511 int dc_enable = !!ucontrol->value.integer.value[0];
512
513 if (dc_enable == spec->dc_enable)
514 return 0;
515
516 spec->dc_enable = dc_enable;
517 olpc_xo_update_mic_pins(codec);
518 olpc_xo_update_mic_boost(codec);
519 return 1;
520}
521
522static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
523 struct snd_ctl_elem_value *ucontrol)
524{
525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526 struct conexant_spec *spec = codec->spec;
527 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
528 return 0;
529}
530
531static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_info *uinfo)
533{
534 return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
535}
536
537static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_value *ucontrol)
539{
540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541 struct conexant_spec *spec = codec->spec;
542 const struct hda_input_mux *imux = &olpc_xo_dc_bias;
543 unsigned int idx;
544
545 idx = ucontrol->value.enumerated.item[0];
546 if (idx >= imux->num_items)
547 idx = imux->num_items - 1;
548 if (spec->dc_input_bias == idx)
549 return 0;
550
551 spec->dc_input_bias = idx;
552 if (spec->dc_enable)
553 olpc_xo_update_mic_pins(codec);
554 return 1;
555}
556
557static const struct snd_kcontrol_new olpc_xo_mixers[] = {
558 {
559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560 .name = "DC Mode Enable Switch",
561 .info = snd_ctl_boolean_mono_info,
562 .get = olpc_xo_dc_mode_get,
563 .put = olpc_xo_dc_mode_put,
564 },
565 {
566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
567 .name = "DC Input Bias Enum",
568 .info = olpc_xo_dc_bias_enum_info,
569 .get = olpc_xo_dc_bias_enum_get,
570 .put = olpc_xo_dc_bias_enum_put,
571 },
572 {}
573};
574
575/* overriding mic boost put callback; update mic boost volume only when
576 * DC mode is disabled
577 */
578static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
579 struct snd_ctl_elem_value *ucontrol)
580{
581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582 struct conexant_spec *spec = codec->spec;
583 int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
584 if (ret > 0 && spec->dc_enable)
585 olpc_xo_update_mic_boost(codec);
586 return ret;
587}
588
589static void cxt_fixup_olpc_xo(struct hda_codec *codec,
590 const struct hda_fixup *fix, int action)
591{
592 struct conexant_spec *spec = codec->spec;
593 int i;
594
595 if (action != HDA_FIXUP_ACT_PROBE)
596 return;
597
598 spec->gen.mic_autoswitch_hook = olpc_xo_automic;
599 spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
600 spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
601
602 snd_hda_add_new_ctls(codec, olpc_xo_mixers);
603
604 /* OLPC's microphone port is DC coupled for use with external sensors,
605 * therefore we use a 50% mic bias in order to center the input signal
606 * with the DC input range of the codec.
607 */
608 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
609
610 /* override mic boost control */
611 for (i = 0; i < spec->gen.kctls.used; i++) {
612 struct snd_kcontrol_new *kctl =
613 snd_array_elem(&spec->gen.kctls, i);
614 if (!strcmp(kctl->name, "Mic Boost Volume")) {
615 kctl->put = olpc_xo_mic_boost_put;
616 break;
617 }
618 }
619}
620
3542aed7
TI
621static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
622 const struct hda_fixup *fix, int action)
623{
624 struct conexant_spec *spec = codec->spec;
625
626 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
627 spec->mute_led_eapd = 0x1b;
628 spec->dynamic_eapd = 1;
629 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook_mute_led;
630 }
631}
632
ad7725d3
TI
633/*
634 * Fix max input level on mixer widget to 0dB
635 * (originally it has 0x2b steps with 0dB offset 0x14)
636 */
637static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
638 const struct hda_fixup *fix, int action)
639{
640 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
641 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
642 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
643 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
644 (1 << AC_AMPCAP_MUTE_SHIFT));
645}
e4c3bce2 646
ea30e7df
TI
647/*
648 * Fix max input level on mixer widget to 0dB
649 * (originally it has 0x1e steps with 0 dB offset 0x17)
650 */
651static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
652 const struct hda_fixup *fix, int action)
653{
654 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
655 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
656 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
657 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
658 (1 << AC_AMPCAP_MUTE_SHIFT));
659}
660
f73cd43a
TI
661static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec,
662 const struct hda_fixup *fix,
663 int action)
664{
665 /* the mic pin (0x19) doesn't give an unsolicited event;
666 * probe the mic pin together with the headphone pin (0x16)
667 */
668 if (action == HDA_FIXUP_ACT_PROBE)
669 snd_hda_jack_set_gating_jack(codec, 0x19, 0x16);
670}
671
5cd5b1bd
JB
672/* update LED status via GPIO */
673static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
674 bool enabled)
675{
676 struct conexant_spec *spec = codec->spec;
677 unsigned int oldval = spec->gpio_led;
678
679 if (spec->mute_led_polarity)
680 enabled = !enabled;
681
682 if (enabled)
683 spec->gpio_led &= ~mask;
684 else
685 spec->gpio_led |= mask;
686 if (spec->gpio_led != oldval)
687 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
688 spec->gpio_led);
689}
690
691/* turn on/off mute LED via GPIO per vmaster hook */
692static void cxt_fixup_gpio_mute_hook(void *private_data, int enabled)
693{
694 struct hda_codec *codec = private_data;
695 struct conexant_spec *spec = codec->spec;
696
697 cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
698}
699
700/* turn on/off mic-mute LED via GPIO per capture hook */
701static void cxt_fixup_gpio_mic_mute_hook(struct hda_codec *codec,
702 struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
704{
705 struct conexant_spec *spec = codec->spec;
706
707 if (ucontrol)
708 cxt_update_gpio_led(codec, spec->gpio_mic_led_mask,
709 ucontrol->value.integer.value[0] ||
710 ucontrol->value.integer.value[1]);
711}
712
713
714static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
715 const struct hda_fixup *fix, int action)
716{
717 struct conexant_spec *spec = codec->spec;
718 static const struct hda_verb gpio_init[] = {
719 { 0x01, AC_VERB_SET_GPIO_MASK, 0x03 },
720 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03 },
721 {}
722 };
723 codec_info(codec, "action: %d gpio_led: %d\n", action, spec->gpio_led);
724
725 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
726 spec->gen.vmaster_mute.hook = cxt_fixup_gpio_mute_hook;
727 spec->gen.cap_sync_hook = cxt_fixup_gpio_mic_mute_hook;
728 spec->gpio_led = 0;
729 spec->mute_led_polarity = 0;
730 spec->gpio_mute_led_mask = 0x01;
731 spec->gpio_mic_led_mask = 0x02;
732 }
733 snd_hda_add_verbs(codec, gpio_init);
734 if (spec->gpio_led)
735 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
736 spec->gpio_led);
737}
738
739
d70f3632 740/* ThinkPad X200 & co with cxt5051 */
23d30f28 741static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
e92d4b08
TI
742 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
743 { 0x17, 0x21a11000 }, /* dock-mic */
744 { 0x19, 0x2121103f }, /* dock-HP */
3e93f5ef 745 { 0x1c, 0x21440100 }, /* dock SPDIF out */
e92d4b08
TI
746 {}
747};
748
d70f3632 749/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
23d30f28 750static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
d70f3632
TI
751 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
752 { 0x1a, 0x21a190f0 }, /* dock-mic */
753 { 0x1c, 0x212140ff }, /* dock-HP */
754 {}
755};
756
239fb862
HC
757/* Lemote A1004/A1205 with cxt5066 */
758static const struct hda_pintbl cxt_pincfg_lemote[] = {
759 { 0x1a, 0x90a10020 }, /* Internal mic */
760 { 0x1b, 0x03a11020 }, /* External mic */
761 { 0x1d, 0x400101f0 }, /* Not used */
762 { 0x1e, 0x40a701f0 }, /* Not used */
763 { 0x20, 0x404501f0 }, /* Not used */
764 { 0x22, 0x404401f0 }, /* Not used */
765 { 0x23, 0x40a701f0 }, /* Not used */
766 {}
767};
768
23d30f28
TI
769static const struct hda_fixup cxt_fixups[] = {
770 [CXT_PINCFG_LENOVO_X200] = {
771 .type = HDA_FIXUP_PINS,
772 .v.pins = cxt_pincfg_lenovo_x200,
773 },
774 [CXT_PINCFG_LENOVO_TP410] = {
775 .type = HDA_FIXUP_PINS,
776 .v.pins = cxt_pincfg_lenovo_tp410,
08cf680c
DH
777 .chained = true,
778 .chain_id = CXT_FIXUP_THINKPAD_ACPI,
23d30f28 779 },
239fb862
HC
780 [CXT_PINCFG_LEMOTE_A1004] = {
781 .type = HDA_FIXUP_PINS,
782 .chained = true,
783 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
784 .v.pins = cxt_pincfg_lemote,
785 },
786 [CXT_PINCFG_LEMOTE_A1205] = {
787 .type = HDA_FIXUP_PINS,
788 .v.pins = cxt_pincfg_lemote,
789 },
ddb6ca75
TI
790 [CXT_PINCFG_COMPAQ_CQ60] = {
791 .type = HDA_FIXUP_PINS,
792 .v.pins = (const struct hda_pintbl[]) {
793 /* 0x17 was falsely set up as a mic, it should 0x1d */
794 { 0x17, 0x400001f0 },
795 { 0x1d, 0x97a70120 },
796 { }
797 }
798 },
23d30f28
TI
799 [CXT_FIXUP_STEREO_DMIC] = {
800 .type = HDA_FIXUP_FUNC,
801 .v.func = cxt_fixup_stereo_dmic,
802 },
239fb862
HC
803 [CXT_FIXUP_INC_MIC_BOOST] = {
804 .type = HDA_FIXUP_FUNC,
805 .v.func = cxt5066_increase_mic_boost,
806 },
e4c3bce2
DH
807 [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
808 .type = HDA_FIXUP_PINS,
809 .chained = true,
810 .chain_id = CXT_FIXUP_HEADPHONE_MIC,
811 .v.pins = (const struct hda_pintbl[]) {
812 { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
813 { }
814 }
815 },
816 [CXT_FIXUP_HEADPHONE_MIC] = {
817 .type = HDA_FIXUP_FUNC,
818 .v.func = cxt_fixup_headphone_mic,
819 },
4a437044
TI
820 [CXT_FIXUP_GPIO1] = {
821 .type = HDA_FIXUP_VERBS,
822 .v.verbs = (const struct hda_verb[]) {
823 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
824 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
825 { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
826 { }
827 },
828 },
ff50479a
TI
829 [CXT_FIXUP_ASPIRE_DMIC] = {
830 .type = HDA_FIXUP_FUNC,
831 .v.func = cxt_fixup_stereo_dmic,
832 .chained = true,
833 .chain_id = CXT_FIXUP_GPIO1,
834 },
08cf680c
DH
835 [CXT_FIXUP_THINKPAD_ACPI] = {
836 .type = HDA_FIXUP_FUNC,
b317b032 837 .v.func = hda_fixup_thinkpad_acpi,
08cf680c 838 },
3a00c660
TI
839 [CXT_FIXUP_OLPC_XO] = {
840 .type = HDA_FIXUP_FUNC,
841 .v.func = cxt_fixup_olpc_xo,
842 },
ad7725d3
TI
843 [CXT_FIXUP_CAP_MIX_AMP] = {
844 .type = HDA_FIXUP_FUNC,
845 .v.func = cxt_fixup_cap_mix_amp,
846 },
6dcbadef
TI
847 [CXT_FIXUP_TOSHIBA_P105] = {
848 .type = HDA_FIXUP_PINS,
849 .v.pins = (const struct hda_pintbl[]) {
850 { 0x10, 0x961701f0 }, /* speaker/hp */
851 { 0x12, 0x02a1901e }, /* ext mic */
852 { 0x14, 0x95a70110 }, /* int mic */
853 {}
854 },
855 },
e5eac90d
TI
856 [CXT_FIXUP_HP_530] = {
857 .type = HDA_FIXUP_PINS,
858 .v.pins = (const struct hda_pintbl[]) {
859 { 0x12, 0x90a60160 }, /* int mic */
860 {}
861 },
862 .chained = true,
863 .chain_id = CXT_FIXUP_CAP_MIX_AMP,
864 },
ea30e7df
TI
865 [CXT_FIXUP_CAP_MIX_AMP_5047] = {
866 .type = HDA_FIXUP_FUNC,
867 .v.func = cxt_fixup_cap_mix_amp_5047,
868 },
3542aed7
TI
869 [CXT_FIXUP_MUTE_LED_EAPD] = {
870 .type = HDA_FIXUP_FUNC,
871 .v.func = cxt_fixup_mute_led_eapd,
872 },
cc3a47a2
JK
873 [CXT_FIXUP_HP_DOCK] = {
874 .type = HDA_FIXUP_PINS,
875 .v.pins = (const struct hda_pintbl[]) {
876 { 0x16, 0x21011020 }, /* line-out */
877 { 0x18, 0x2181103f }, /* line-in */
878 { }
c3123d6a
FT
879 },
880 .chained = true,
881 .chain_id = CXT_FIXUP_MUTE_LED_GPIO,
cc3a47a2 882 },
0eec8809
TI
883 [CXT_FIXUP_HP_SPECTRE] = {
884 .type = HDA_FIXUP_PINS,
885 .v.pins = (const struct hda_pintbl[]) {
886 /* enable NID 0x1d for the speaker on top */
887 { 0x1d, 0x91170111 },
888 { }
889 }
890 },
f73cd43a
TI
891 [CXT_FIXUP_HP_GATE_MIC] = {
892 .type = HDA_FIXUP_FUNC,
893 .v.func = cxt_fixup_hp_gate_mic_jack,
894 },
5cd5b1bd
JB
895 [CXT_FIXUP_MUTE_LED_GPIO] = {
896 .type = HDA_FIXUP_FUNC,
897 .v.func = cxt_fixup_mute_led_gpio,
898 },
2845bbd1
HW
899 [CXT_FIXUP_HEADSET_MIC] = {
900 .type = HDA_FIXUP_FUNC,
901 .v.func = cxt_fixup_headset_mic,
902 },
903 [CXT_FIXUP_HP_MIC_NO_PRESENCE] = {
904 .type = HDA_FIXUP_PINS,
905 .v.pins = (const struct hda_pintbl[]) {
906 { 0x1a, 0x02a1113c },
907 { }
908 },
909 .chained = true,
910 .chain_id = CXT_FIXUP_HEADSET_MIC,
911 },
ad7725d3
TI
912};
913
914static const struct snd_pci_quirk cxt5045_fixups[] = {
e5eac90d 915 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
6dcbadef 916 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
ad7725d3
TI
917 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
918 * really bad sound over 0dB on NID 0x17.
919 */
920 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
921 SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
922 SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
923 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
924 {}
925};
926
927static const struct hda_model_fixup cxt5045_fixup_models[] = {
928 { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
6dcbadef 929 { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
e5eac90d 930 { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
ad7725d3 931 {}
e92d4b08
TI
932};
933
ea30e7df
TI
934static const struct snd_pci_quirk cxt5047_fixups[] = {
935 /* HP laptops have really bad sound over 0 dB on NID 0x10.
936 */
937 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
938 {}
939};
940
941static const struct hda_model_fixup cxt5047_fixup_models[] = {
942 { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
943 {}
944};
945
d70f3632 946static const struct snd_pci_quirk cxt5051_fixups[] = {
ddb6ca75 947 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
e92d4b08
TI
948 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
949 {}
950};
951
a2dd933d
TI
952static const struct hda_model_fixup cxt5051_fixup_models[] = {
953 { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
954 {}
955};
956
d70f3632 957static const struct snd_pci_quirk cxt5066_fixups[] = {
63a077e2 958 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
ff50479a 959 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
522a7fa8 960 SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
cc3a47a2 961 SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
f2ba41eb 962 SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
3deecffb 963 SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
91056ae4 964 SND_PCI_QUIRK(0x103c, 0x828c, "HP EliteBook 840 G4", CXT_FIXUP_HP_DOCK),
e6c9fd8c 965 SND_PCI_QUIRK(0x103c, 0x83b3, "HP EliteBook 830 G5", CXT_FIXUP_HP_DOCK),
c5c00990 966 SND_PCI_QUIRK(0x103c, 0x83d3, "HP ProBook 640 G4", CXT_FIXUP_HP_DOCK),
0eec8809 967 SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
f73cd43a 968 SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
5cd5b1bd 969 SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO),
ba92b114 970 SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO),
a82d4478 971 SND_PCI_QUIRK(0x103c, 0x836e, "HP ProBook 455 G5", CXT_FIXUP_MUTE_LED_GPIO),
752c738a 972 SND_PCI_QUIRK(0x103c, 0x837f, "HP ProBook 470 G5", CXT_FIXUP_MUTE_LED_GPIO),
2845bbd1
HW
973 SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
974 SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE),
03701e42 975 SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE),
e4c3bce2 976 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
3a00c660 977 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
d70f3632
TI
978 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
979 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
980 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
981 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
982 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
a555bb8c 983 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
88d57606 984 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
3542aed7 985 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
e0404d81 986 SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC),
e8d65a8d 987 SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
18dcd304 988 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
e4db0952 989 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
bbba6f9d 990 SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC),
b3c5dce8 991 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
2fd3f170 992 SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
239fb862
HC
993 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
994 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
e92d4b08
TI
995 {}
996};
997
a2dd933d
TI
998static const struct hda_model_fixup cxt5066_fixup_models[] = {
999 { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
1000 { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
1001 { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
1002 { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
1003 { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
1004 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
8245b363 1005 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
3a00c660 1006 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
3542aed7 1007 { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
cc3a47a2 1008 { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" },
5cd5b1bd 1009 { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" },
a2dd933d
TI
1010 {}
1011};
1012
3868137e
TI
1013/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
1014 * can be created (bko#42825)
1015 */
1016static void add_cx5051_fake_mutes(struct hda_codec *codec)
1017{
d89c6c0c 1018 struct conexant_spec *spec = codec->spec;
3868137e
TI
1019 static hda_nid_t out_nids[] = {
1020 0x10, 0x11, 0
1021 };
1022 hda_nid_t *p;
1023
1024 for (p = out_nids; *p; p++)
1025 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
1026 AC_AMPCAP_MIN_MUTE |
1027 query_amp_caps(codec, *p, HDA_OUTPUT));
d89c6c0c 1028 spec->gen.dac_min_mute = true;
3868137e
TI
1029}
1030
f2e5731d
TI
1031static int patch_conexant_auto(struct hda_codec *codec)
1032{
1033 struct conexant_spec *spec;
1034 int err;
1035
7639a06c 1036 codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
1f8458a2 1037
f2e5731d
TI
1038 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1039 if (!spec)
1040 return -ENOMEM;
aed523f1 1041 snd_hda_gen_spec_init(&spec->gen);
f2e5731d 1042 codec->spec = spec;
225068ab 1043 codec->patch_ops = cx_auto_patch_ops;
e92d4b08 1044
aed523f1
TI
1045 cx_auto_parse_beep(codec);
1046 cx_auto_parse_eapd(codec);
ff359b14
TI
1047 spec->gen.own_eapd_ctl = 1;
1048 if (spec->dynamic_eapd)
aed523f1 1049 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
e92d4b08 1050
7639a06c 1051 switch (codec->core.vendor_id) {
6b452142 1052 case 0x14f15045:
4f32456e 1053 codec->single_adc_amp = 1;
70540e24 1054 spec->gen.mixer_nid = 0x17;
74f14b36 1055 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
ad7725d3
TI
1056 snd_hda_pick_fixup(codec, cxt5045_fixup_models,
1057 cxt5045_fixups, cxt_fixups);
6b452142 1058 break;
164a7ada
TI
1059 case 0x14f15047:
1060 codec->pin_amp_workaround = 1;
1061 spec->gen.mixer_nid = 0x19;
74f14b36 1062 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
ea30e7df
TI
1063 snd_hda_pick_fixup(codec, cxt5047_fixup_models,
1064 cxt5047_fixups, cxt_fixups);
164a7ada 1065 break;
3868137e
TI
1066 case 0x14f15051:
1067 add_cx5051_fake_mutes(codec);
51969d62 1068 codec->pin_amp_workaround = 1;
a2dd933d
TI
1069 snd_hda_pick_fixup(codec, cxt5051_fixup_models,
1070 cxt5051_fixups, cxt_fixups);
3868137e 1071 break;
b03d61d6
DH
1072 case 0x14f150f2:
1073 codec->power_save_node = 1;
1074 /* Fall through */
51969d62
MK
1075 default:
1076 codec->pin_amp_workaround = 1;
a2dd933d
TI
1077 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1078 cxt5066_fixups, cxt_fixups);
23d30f28 1079 break;
6b452142
TI
1080 }
1081
f29735cb
TI
1082 /* Show mute-led control only on HP laptops
1083 * This is a sort of white-list: on HP laptops, EAPD corresponds
1084 * only to the mute-LED without actualy amp function. Meanwhile,
1085 * others may use EAPD really as an amp switch, so it might be
1086 * not good to expose it blindly.
527c73ba 1087 */
7639a06c 1088 switch (codec->core.subsystem_id >> 16) {
f29735cb 1089 case 0x103c:
aed523f1 1090 spec->gen.vmaster_mute_enum = 1;
f29735cb
TI
1091 break;
1092 }
527c73ba 1093
aed523f1
TI
1094 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1095
e4c3bce2
DH
1096 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
1097 spec->parse_flags);
22ce5f74 1098 if (err < 0)
aed523f1
TI
1099 goto error;
1100
1101 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1102 if (err < 0)
1103 goto error;
1104
4f2864a4
TI
1105 /* Some laptops with Conexant chips show stalls in S3 resume,
1106 * which falls into the single-cmd mode.
1107 * Better to make reset, then.
1108 */
d068ebc2 1109 if (!codec->bus->core.sync_write) {
4e76a883 1110 codec_info(codec,
4f2864a4 1111 "Enable sync_write for stable communication\n");
d068ebc2 1112 codec->bus->core.sync_write = 1;
4f2864a4
TI
1113 codec->bus->allow_bus_reset = 1;
1114 }
1115
e4c3bce2
DH
1116 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1117
f2e5731d 1118 return 0;
aed523f1
TI
1119
1120 error:
08cf680c 1121 cx_auto_free(codec);
aed523f1 1122 return err;
f2e5731d
TI
1123}
1124
461e2c78
TI
1125/*
1126 */
1127
b9a94a9c 1128static const struct hda_device_id snd_hda_id_conexant[] = {
bcdda2ec 1129 HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto),
b9a94a9c
TI
1130 HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto),
1131 HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto),
1132 HDA_CODEC_ENTRY(0x14f15051, "CX20561 (Hermosa)", patch_conexant_auto),
1133 HDA_CODEC_ENTRY(0x14f15066, "CX20582 (Pebble)", patch_conexant_auto),
1134 HDA_CODEC_ENTRY(0x14f15067, "CX20583 (Pebble HSF)", patch_conexant_auto),
1135 HDA_CODEC_ENTRY(0x14f15068, "CX20584", patch_conexant_auto),
1136 HDA_CODEC_ENTRY(0x14f15069, "CX20585", patch_conexant_auto),
1137 HDA_CODEC_ENTRY(0x14f1506c, "CX20588", patch_conexant_auto),
1138 HDA_CODEC_ENTRY(0x14f1506e, "CX20590", patch_conexant_auto),
1139 HDA_CODEC_ENTRY(0x14f15097, "CX20631", patch_conexant_auto),
1140 HDA_CODEC_ENTRY(0x14f15098, "CX20632", patch_conexant_auto),
1141 HDA_CODEC_ENTRY(0x14f150a1, "CX20641", patch_conexant_auto),
1142 HDA_CODEC_ENTRY(0x14f150a2, "CX20642", patch_conexant_auto),
1143 HDA_CODEC_ENTRY(0x14f150ab, "CX20651", patch_conexant_auto),
1144 HDA_CODEC_ENTRY(0x14f150ac, "CX20652", patch_conexant_auto),
1145 HDA_CODEC_ENTRY(0x14f150b8, "CX20664", patch_conexant_auto),
1146 HDA_CODEC_ENTRY(0x14f150b9, "CX20665", patch_conexant_auto),
3b7e2a7d 1147 HDA_CODEC_ENTRY(0x14f150f1, "CX21722", patch_conexant_auto),
b9a94a9c 1148 HDA_CODEC_ENTRY(0x14f150f2, "CX20722", patch_conexant_auto),
3b7e2a7d 1149 HDA_CODEC_ENTRY(0x14f150f3, "CX21724", patch_conexant_auto),
b9a94a9c
TI
1150 HDA_CODEC_ENTRY(0x14f150f4, "CX20724", patch_conexant_auto),
1151 HDA_CODEC_ENTRY(0x14f1510f, "CX20751/2", patch_conexant_auto),
1152 HDA_CODEC_ENTRY(0x14f15110, "CX20751/2", patch_conexant_auto),
1153 HDA_CODEC_ENTRY(0x14f15111, "CX20753/4", patch_conexant_auto),
1154 HDA_CODEC_ENTRY(0x14f15113, "CX20755", patch_conexant_auto),
1155 HDA_CODEC_ENTRY(0x14f15114, "CX20756", patch_conexant_auto),
1156 HDA_CODEC_ENTRY(0x14f15115, "CX20757", patch_conexant_auto),
1157 HDA_CODEC_ENTRY(0x14f151d7, "CX20952", patch_conexant_auto),
c9b443d4
TD
1158 {} /* terminator */
1159};
b9a94a9c 1160MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant);
1289e9e8
TI
1161
1162MODULE_LICENSE("GPL");
1163MODULE_DESCRIPTION("Conexant HD-audio codec");
1164
d8a766a1 1165static struct hda_codec_driver conexant_driver = {
b9a94a9c 1166 .id = snd_hda_id_conexant,
1289e9e8
TI
1167};
1168
d8a766a1 1169module_hda_codec_driver(conexant_driver);