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