Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * HD audio interface patch for Conexant HDA audio codec
0004  *
0005  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
0006  *            Takashi Iwai <tiwai@suse.de>
0007  *            Tobin Davis  <tdavis@dsl-only.net>
0008  */
0009 
0010 #include <linux/init.h>
0011 #include <linux/delay.h>
0012 #include <linux/slab.h>
0013 #include <linux/module.h>
0014 #include <sound/core.h>
0015 #include <sound/jack.h>
0016 
0017 #include <sound/hda_codec.h>
0018 #include "hda_local.h"
0019 #include "hda_auto_parser.h"
0020 #include "hda_beep.h"
0021 #include "hda_jack.h"
0022 #include "hda_generic.h"
0023 
0024 struct conexant_spec {
0025     struct hda_gen_spec gen;
0026 
0027     /* extra EAPD pins */
0028     unsigned int num_eapds;
0029     hda_nid_t eapds[4];
0030     bool dynamic_eapd;
0031     hda_nid_t mute_led_eapd;
0032 
0033     unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
0034 
0035     /* OPLC XO specific */
0036     bool recording;
0037     bool dc_enable;
0038     unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
0039     struct nid_path *dc_mode_path;
0040 
0041     int mute_led_polarity;
0042     unsigned int gpio_led;
0043     unsigned int gpio_mute_led_mask;
0044     unsigned int gpio_mic_led_mask;
0045 
0046 };
0047 
0048 
0049 #ifdef CONFIG_SND_HDA_INPUT_BEEP
0050 /* additional beep mixers; private_value will be overwritten */
0051 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
0052     HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
0053     HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
0054 };
0055 
0056 static int set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
0057             int idx, int dir)
0058 {
0059     struct snd_kcontrol_new *knew;
0060     unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
0061     int i;
0062 
0063     spec->gen.beep_nid = nid;
0064     for (i = 0; i < ARRAY_SIZE(cxt_beep_mixer); i++) {
0065         knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
0066                         &cxt_beep_mixer[i]);
0067         if (!knew)
0068             return -ENOMEM;
0069         knew->private_value = beep_amp;
0070     }
0071     return 0;
0072 }
0073 
0074 static int cx_auto_parse_beep(struct hda_codec *codec)
0075 {
0076     struct conexant_spec *spec = codec->spec;
0077     hda_nid_t nid;
0078 
0079     for_each_hda_codec_node(nid, codec)
0080         if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
0081             return set_beep_amp(spec, nid, 0, HDA_OUTPUT);
0082     return 0;
0083 }
0084 #else
0085 #define cx_auto_parse_beep(codec)   0
0086 #endif
0087 
0088 /*
0089  * Automatic parser for CX20641 & co
0090  */
0091 
0092 /* parse EAPDs */
0093 static void cx_auto_parse_eapd(struct hda_codec *codec)
0094 {
0095     struct conexant_spec *spec = codec->spec;
0096     hda_nid_t nid;
0097 
0098     for_each_hda_codec_node(nid, codec) {
0099         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
0100             continue;
0101         if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
0102             continue;
0103         spec->eapds[spec->num_eapds++] = nid;
0104         if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
0105             break;
0106     }
0107 
0108     /* NOTE: below is a wild guess; if we have more than two EAPDs,
0109      * it's a new chip, where EAPDs are supposed to be associated to
0110      * pins, and we can control EAPD per pin.
0111      * OTOH, if only one or two EAPDs are found, it's an old chip,
0112      * thus it might control over all pins.
0113      */
0114     if (spec->num_eapds > 2)
0115         spec->dynamic_eapd = 1;
0116 }
0117 
0118 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
0119                   const hda_nid_t *pins, bool on)
0120 {
0121     int i;
0122     for (i = 0; i < num_pins; i++) {
0123         if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
0124             snd_hda_codec_write(codec, pins[i], 0,
0125                         AC_VERB_SET_EAPD_BTLENABLE,
0126                         on ? 0x02 : 0);
0127     }
0128 }
0129 
0130 /* turn on/off EAPD according to Master switch */
0131 static void cx_auto_vmaster_hook(void *private_data, int enabled)
0132 {
0133     struct hda_codec *codec = private_data;
0134     struct conexant_spec *spec = codec->spec;
0135 
0136     cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
0137 }
0138 
0139 /* turn on/off EAPD according to Master switch (inversely!) for mute LED */
0140 static int cx_auto_vmaster_mute_led(struct led_classdev *led_cdev,
0141                     enum led_brightness brightness)
0142 {
0143     struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
0144     struct conexant_spec *spec = codec->spec;
0145 
0146     snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
0147                 AC_VERB_SET_EAPD_BTLENABLE,
0148                 brightness ? 0x02 : 0x00);
0149     return 0;
0150 }
0151 
0152 static void cxt_init_gpio_led(struct hda_codec *codec)
0153 {
0154     struct conexant_spec *spec = codec->spec;
0155     unsigned int mask = spec->gpio_mute_led_mask | spec->gpio_mic_led_mask;
0156 
0157     if (mask) {
0158         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
0159                     mask);
0160         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
0161                     mask);
0162         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
0163                     spec->gpio_led);
0164     }
0165 }
0166 
0167 static int cx_auto_init(struct hda_codec *codec)
0168 {
0169     struct conexant_spec *spec = codec->spec;
0170     snd_hda_gen_init(codec);
0171     if (!spec->dynamic_eapd)
0172         cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
0173 
0174     cxt_init_gpio_led(codec);
0175     snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
0176 
0177     return 0;
0178 }
0179 
0180 static void cx_auto_shutdown(struct hda_codec *codec)
0181 {
0182     struct conexant_spec *spec = codec->spec;
0183 
0184     /* Turn the problematic codec into D3 to avoid spurious noises
0185        from the internal speaker during (and after) reboot */
0186     cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
0187 }
0188 
0189 static void cx_auto_free(struct hda_codec *codec)
0190 {
0191     cx_auto_shutdown(codec);
0192     snd_hda_gen_free(codec);
0193 }
0194 
0195 #ifdef CONFIG_PM
0196 static int cx_auto_suspend(struct hda_codec *codec)
0197 {
0198     cx_auto_shutdown(codec);
0199     return 0;
0200 }
0201 #endif
0202 
0203 static const struct hda_codec_ops cx_auto_patch_ops = {
0204     .build_controls = snd_hda_gen_build_controls,
0205     .build_pcms = snd_hda_gen_build_pcms,
0206     .init = cx_auto_init,
0207     .free = cx_auto_free,
0208     .unsol_event = snd_hda_jack_unsol_event,
0209 #ifdef CONFIG_PM
0210     .suspend = cx_auto_suspend,
0211     .check_power_status = snd_hda_gen_check_power_status,
0212 #endif
0213 };
0214 
0215 /*
0216  * pin fix-up
0217  */
0218 enum {
0219     CXT_PINCFG_LENOVO_X200,
0220     CXT_PINCFG_LENOVO_TP410,
0221     CXT_PINCFG_LEMOTE_A1004,
0222     CXT_PINCFG_LEMOTE_A1205,
0223     CXT_PINCFG_COMPAQ_CQ60,
0224     CXT_FIXUP_STEREO_DMIC,
0225     CXT_PINCFG_LENOVO_NOTEBOOK,
0226     CXT_FIXUP_INC_MIC_BOOST,
0227     CXT_FIXUP_HEADPHONE_MIC_PIN,
0228     CXT_FIXUP_HEADPHONE_MIC,
0229     CXT_FIXUP_GPIO1,
0230     CXT_FIXUP_ASPIRE_DMIC,
0231     CXT_FIXUP_THINKPAD_ACPI,
0232     CXT_FIXUP_OLPC_XO,
0233     CXT_FIXUP_CAP_MIX_AMP,
0234     CXT_FIXUP_TOSHIBA_P105,
0235     CXT_FIXUP_HP_530,
0236     CXT_FIXUP_CAP_MIX_AMP_5047,
0237     CXT_FIXUP_MUTE_LED_EAPD,
0238     CXT_FIXUP_HP_DOCK,
0239     CXT_FIXUP_HP_SPECTRE,
0240     CXT_FIXUP_HP_GATE_MIC,
0241     CXT_FIXUP_MUTE_LED_GPIO,
0242     CXT_FIXUP_HP_ZBOOK_MUTE_LED,
0243     CXT_FIXUP_HEADSET_MIC,
0244     CXT_FIXUP_HP_MIC_NO_PRESENCE,
0245 };
0246 
0247 /* for hda_fixup_thinkpad_acpi() */
0248 #include "thinkpad_helper.c"
0249 
0250 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
0251                   const struct hda_fixup *fix, int action)
0252 {
0253     struct conexant_spec *spec = codec->spec;
0254     spec->gen.inv_dmic_split = 1;
0255 }
0256 
0257 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
0258                    const struct hda_fixup *fix, int action)
0259 {
0260     if (action != HDA_FIXUP_ACT_PRE_PROBE)
0261         return;
0262 
0263     snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
0264                   (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
0265                   (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
0266                   (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
0267                   (0 << AC_AMPCAP_MUTE_SHIFT));
0268 }
0269 
0270 static void cxt_update_headset_mode(struct hda_codec *codec)
0271 {
0272     /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
0273     int i;
0274     bool mic_mode = false;
0275     struct conexant_spec *spec = codec->spec;
0276     struct auto_pin_cfg *cfg = &spec->gen.autocfg;
0277 
0278     hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
0279 
0280     for (i = 0; i < cfg->num_inputs; i++)
0281         if (cfg->inputs[i].pin == mux_pin) {
0282             mic_mode = !!cfg->inputs[i].is_headphone_mic;
0283             break;
0284         }
0285 
0286     if (mic_mode) {
0287         snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
0288         spec->gen.hp_jack_present = false;
0289     } else {
0290         snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
0291         spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
0292     }
0293 
0294     snd_hda_gen_update_outputs(codec);
0295 }
0296 
0297 static void cxt_update_headset_mode_hook(struct hda_codec *codec,
0298                      struct snd_kcontrol *kcontrol,
0299                      struct snd_ctl_elem_value *ucontrol)
0300 {
0301     cxt_update_headset_mode(codec);
0302 }
0303 
0304 static void cxt_fixup_headphone_mic(struct hda_codec *codec,
0305                     const struct hda_fixup *fix, int action)
0306 {
0307     struct conexant_spec *spec = codec->spec;
0308 
0309     switch (action) {
0310     case HDA_FIXUP_ACT_PRE_PROBE:
0311         spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
0312         snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
0313         break;
0314     case HDA_FIXUP_ACT_PROBE:
0315         WARN_ON(spec->gen.cap_sync_hook);
0316         spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
0317         spec->gen.automute_hook = cxt_update_headset_mode;
0318         break;
0319     case HDA_FIXUP_ACT_INIT:
0320         cxt_update_headset_mode(codec);
0321         break;
0322     }
0323 }
0324 
0325 static void cxt_fixup_headset_mic(struct hda_codec *codec,
0326                     const struct hda_fixup *fix, int action)
0327 {
0328     struct conexant_spec *spec = codec->spec;
0329 
0330     switch (action) {
0331     case HDA_FIXUP_ACT_PRE_PROBE:
0332         spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
0333         break;
0334     }
0335 }
0336 
0337 /* OPLC XO 1.5 fixup */
0338 
0339 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
0340  * through the microphone jack.
0341  * When the user enables this through a mixer switch, both internal and
0342  * external microphones are disabled. Gain is fixed at 0dB. In this mode,
0343  * we also allow the bias to be configured through a separate mixer
0344  * control. */
0345 
0346 #define update_mic_pin(codec, nid, val)                 \
0347     snd_hda_codec_write_cache(codec, nid, 0,            \
0348                    AC_VERB_SET_PIN_WIDGET_CONTROL, val)
0349 
0350 static const struct hda_input_mux olpc_xo_dc_bias = {
0351     .num_items = 3,
0352     .items = {
0353         { "Off", PIN_IN },
0354         { "50%", PIN_VREF50 },
0355         { "80%", PIN_VREF80 },
0356     },
0357 };
0358 
0359 static void olpc_xo_update_mic_boost(struct hda_codec *codec)
0360 {
0361     struct conexant_spec *spec = codec->spec;
0362     int ch, val;
0363 
0364     for (ch = 0; ch < 2; ch++) {
0365         val = AC_AMP_SET_OUTPUT |
0366             (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
0367         if (!spec->dc_enable)
0368             val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
0369         snd_hda_codec_write(codec, 0x17, 0,
0370                     AC_VERB_SET_AMP_GAIN_MUTE, val);
0371     }
0372 }
0373 
0374 static void olpc_xo_update_mic_pins(struct hda_codec *codec)
0375 {
0376     struct conexant_spec *spec = codec->spec;
0377     int cur_input, val;
0378     struct nid_path *path;
0379 
0380     cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
0381 
0382     /* Set up mic pins for port-B, C and F dynamically as the recording
0383      * LED is turned on/off by these pin controls
0384      */
0385     if (!spec->dc_enable) {
0386         /* disable DC bias path and pin for port F */
0387         update_mic_pin(codec, 0x1e, 0);
0388         snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
0389 
0390         /* update port B (ext mic) and C (int mic) */
0391         /* OLPC defers mic widget control until when capture is
0392          * started because the microphone LED comes on as soon as
0393          * these settings are put in place. if we did this before
0394          * recording, it would give the false indication that
0395          * recording is happening when it is not.
0396          */
0397         update_mic_pin(codec, 0x1a, spec->recording ?
0398                    snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
0399         update_mic_pin(codec, 0x1b, spec->recording ?
0400                    snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
0401         /* enable normal mic path */
0402         path = snd_hda_get_path_from_idx(codec, cur_input);
0403         if (path)
0404             snd_hda_activate_path(codec, path, true, false);
0405     } else {
0406         /* disable normal mic path */
0407         path = snd_hda_get_path_from_idx(codec, cur_input);
0408         if (path)
0409             snd_hda_activate_path(codec, path, false, false);
0410 
0411         /* Even though port F is the DC input, the bias is controlled
0412          * on port B.  We also leave that port as an active input (but
0413          * unselected) in DC mode just in case that is necessary to
0414          * make the bias setting take effect.
0415          */
0416         if (spec->recording)
0417             val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
0418         else
0419             val = 0;
0420         update_mic_pin(codec, 0x1a, val);
0421         update_mic_pin(codec, 0x1b, 0);
0422         /* enable DC bias path and pin */
0423         update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
0424         snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
0425     }
0426 }
0427 
0428 /* mic_autoswitch hook */
0429 static void olpc_xo_automic(struct hda_codec *codec,
0430                 struct hda_jack_callback *jack)
0431 {
0432     struct conexant_spec *spec = codec->spec;
0433 
0434     /* in DC mode, we don't handle automic */
0435     if (!spec->dc_enable)
0436         snd_hda_gen_mic_autoswitch(codec, jack);
0437     olpc_xo_update_mic_pins(codec);
0438     if (spec->dc_enable)
0439         olpc_xo_update_mic_boost(codec);
0440 }
0441 
0442 /* pcm_capture hook */
0443 static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
0444                  struct hda_codec *codec,
0445                  struct snd_pcm_substream *substream,
0446                  int action)
0447 {
0448     struct conexant_spec *spec = codec->spec;
0449 
0450     /* toggle spec->recording flag and update mic pins accordingly
0451      * for turning on/off LED
0452      */
0453     switch (action) {
0454     case HDA_GEN_PCM_ACT_PREPARE:
0455         spec->recording = 1;
0456         olpc_xo_update_mic_pins(codec);
0457         break;
0458     case HDA_GEN_PCM_ACT_CLEANUP:
0459         spec->recording = 0;
0460         olpc_xo_update_mic_pins(codec);
0461         break;
0462     }
0463 }
0464 
0465 static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
0466                    struct snd_ctl_elem_value *ucontrol)
0467 {
0468     struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
0469     struct conexant_spec *spec = codec->spec;
0470     ucontrol->value.integer.value[0] = spec->dc_enable;
0471     return 0;
0472 }
0473 
0474 static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
0475                    struct snd_ctl_elem_value *ucontrol)
0476 {
0477     struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
0478     struct conexant_spec *spec = codec->spec;
0479     int dc_enable = !!ucontrol->value.integer.value[0];
0480 
0481     if (dc_enable == spec->dc_enable)
0482         return 0;
0483 
0484     spec->dc_enable = dc_enable;
0485     olpc_xo_update_mic_pins(codec);
0486     olpc_xo_update_mic_boost(codec);
0487     return 1;
0488 }
0489 
0490 static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
0491                     struct snd_ctl_elem_value *ucontrol)
0492 {
0493     struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
0494     struct conexant_spec *spec = codec->spec;
0495     ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
0496     return 0;
0497 }
0498 
0499 static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
0500                      struct snd_ctl_elem_info *uinfo)
0501 {
0502     return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
0503 }
0504 
0505 static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
0506                     struct snd_ctl_elem_value *ucontrol)
0507 {
0508     struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
0509     struct conexant_spec *spec = codec->spec;
0510     const struct hda_input_mux *imux = &olpc_xo_dc_bias;
0511     unsigned int idx;
0512 
0513     idx = ucontrol->value.enumerated.item[0];
0514     if (idx >= imux->num_items)
0515         idx = imux->num_items - 1;
0516     if (spec->dc_input_bias == idx)
0517         return 0;
0518 
0519     spec->dc_input_bias = idx;
0520     if (spec->dc_enable)
0521         olpc_xo_update_mic_pins(codec);
0522     return 1;
0523 }
0524 
0525 static const struct snd_kcontrol_new olpc_xo_mixers[] = {
0526     {
0527         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0528         .name = "DC Mode Enable Switch",
0529         .info = snd_ctl_boolean_mono_info,
0530         .get = olpc_xo_dc_mode_get,
0531         .put = olpc_xo_dc_mode_put,
0532     },
0533     {
0534         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0535         .name = "DC Input Bias Enum",
0536         .info = olpc_xo_dc_bias_enum_info,
0537         .get = olpc_xo_dc_bias_enum_get,
0538         .put = olpc_xo_dc_bias_enum_put,
0539     },
0540     {}
0541 };
0542 
0543 /* overriding mic boost put callback; update mic boost volume only when
0544  * DC mode is disabled
0545  */
0546 static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
0547                  struct snd_ctl_elem_value *ucontrol)
0548 {
0549     struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
0550     struct conexant_spec *spec = codec->spec;
0551     int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
0552     if (ret > 0 && spec->dc_enable)
0553         olpc_xo_update_mic_boost(codec);
0554     return ret;
0555 }
0556 
0557 static void cxt_fixup_olpc_xo(struct hda_codec *codec,
0558                     const struct hda_fixup *fix, int action)
0559 {
0560     struct conexant_spec *spec = codec->spec;
0561     struct snd_kcontrol_new *kctl;
0562     int i;
0563 
0564     if (action != HDA_FIXUP_ACT_PROBE)
0565         return;
0566 
0567     spec->gen.mic_autoswitch_hook = olpc_xo_automic;
0568     spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
0569     spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
0570 
0571     snd_hda_add_new_ctls(codec, olpc_xo_mixers);
0572 
0573     /* OLPC's microphone port is DC coupled for use with external sensors,
0574      * therefore we use a 50% mic bias in order to center the input signal
0575      * with the DC input range of the codec.
0576      */
0577     snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
0578 
0579     /* override mic boost control */
0580     snd_array_for_each(&spec->gen.kctls, i, kctl) {
0581         if (!strcmp(kctl->name, "Mic Boost Volume")) {
0582             kctl->put = olpc_xo_mic_boost_put;
0583             break;
0584         }
0585     }
0586 }
0587 
0588 static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
0589                     const struct hda_fixup *fix, int action)
0590 {
0591     struct conexant_spec *spec = codec->spec;
0592 
0593     if (action == HDA_FIXUP_ACT_PRE_PROBE) {
0594         spec->mute_led_eapd = 0x1b;
0595         spec->dynamic_eapd = true;
0596         snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led);
0597     }
0598 }
0599 
0600 /*
0601  * Fix max input level on mixer widget to 0dB
0602  * (originally it has 0x2b steps with 0dB offset 0x14)
0603  */
0604 static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
0605                   const struct hda_fixup *fix, int action)
0606 {
0607     snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
0608                   (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
0609                   (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
0610                   (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
0611                   (1 << AC_AMPCAP_MUTE_SHIFT));
0612 }
0613 
0614 /*
0615  * Fix max input level on mixer widget to 0dB
0616  * (originally it has 0x1e steps with 0 dB offset 0x17)
0617  */
0618 static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
0619                   const struct hda_fixup *fix, int action)
0620 {
0621     snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
0622                   (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
0623                   (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
0624                   (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
0625                   (1 << AC_AMPCAP_MUTE_SHIFT));
0626 }
0627 
0628 static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec,
0629                        const struct hda_fixup *fix,
0630                        int action)
0631 {
0632     /* the mic pin (0x19) doesn't give an unsolicited event;
0633      * probe the mic pin together with the headphone pin (0x16)
0634      */
0635     if (action == HDA_FIXUP_ACT_PROBE)
0636         snd_hda_jack_set_gating_jack(codec, 0x19, 0x16);
0637 }
0638 
0639 /* update LED status via GPIO */
0640 static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
0641                 bool led_on)
0642 {
0643     struct conexant_spec *spec = codec->spec;
0644     unsigned int oldval = spec->gpio_led;
0645 
0646     if (spec->mute_led_polarity)
0647         led_on = !led_on;
0648 
0649     if (led_on)
0650         spec->gpio_led |= mask;
0651     else
0652         spec->gpio_led &= ~mask;
0653     codec_dbg(codec, "mask:%d enabled:%d gpio_led:%d\n",
0654             mask, led_on, spec->gpio_led);
0655     if (spec->gpio_led != oldval)
0656         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
0657                     spec->gpio_led);
0658 }
0659 
0660 /* turn on/off mute LED via GPIO per vmaster hook */
0661 static int cxt_gpio_mute_update(struct led_classdev *led_cdev,
0662                 enum led_brightness brightness)
0663 {
0664     struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
0665     struct conexant_spec *spec = codec->spec;
0666 
0667     cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness);
0668     return 0;
0669 }
0670 
0671 /* turn on/off mic-mute LED via GPIO per capture hook */
0672 static int cxt_gpio_micmute_update(struct led_classdev *led_cdev,
0673                    enum led_brightness brightness)
0674 {
0675     struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
0676     struct conexant_spec *spec = codec->spec;
0677 
0678     cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness);
0679     return 0;
0680 }
0681 
0682 static void cxt_setup_mute_led(struct hda_codec *codec,
0683                    unsigned int mute, unsigned int mic_mute)
0684 {
0685     struct conexant_spec *spec = codec->spec;
0686 
0687     spec->gpio_led = 0;
0688     spec->mute_led_polarity = 0;
0689     if (mute) {
0690         snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update);
0691         spec->gpio_mute_led_mask = mute;
0692     }
0693     if (mic_mute) {
0694         snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update);
0695         spec->gpio_mic_led_mask = mic_mute;
0696     }
0697 }
0698 
0699 static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
0700                 const struct hda_fixup *fix, int action)
0701 {
0702     if (action == HDA_FIXUP_ACT_PRE_PROBE)
0703         cxt_setup_mute_led(codec, 0x01, 0x02);
0704 }
0705 
0706 static void cxt_fixup_hp_zbook_mute_led(struct hda_codec *codec,
0707                     const struct hda_fixup *fix, int action)
0708 {
0709     if (action == HDA_FIXUP_ACT_PRE_PROBE)
0710         cxt_setup_mute_led(codec, 0x10, 0x20);
0711 }
0712 
0713 /* ThinkPad X200 & co with cxt5051 */
0714 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
0715     { 0x16, 0x042140ff }, /* HP (seq# overridden) */
0716     { 0x17, 0x21a11000 }, /* dock-mic */
0717     { 0x19, 0x2121103f }, /* dock-HP */
0718     { 0x1c, 0x21440100 }, /* dock SPDIF out */
0719     {}
0720 };
0721 
0722 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
0723 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
0724     { 0x19, 0x042110ff }, /* HP (seq# overridden) */
0725     { 0x1a, 0x21a190f0 }, /* dock-mic */
0726     { 0x1c, 0x212140ff }, /* dock-HP */
0727     {}
0728 };
0729 
0730 /* Lemote A1004/A1205 with cxt5066 */
0731 static const struct hda_pintbl cxt_pincfg_lemote[] = {
0732     { 0x1a, 0x90a10020 }, /* Internal mic */
0733     { 0x1b, 0x03a11020 }, /* External mic */
0734     { 0x1d, 0x400101f0 }, /* Not used */
0735     { 0x1e, 0x40a701f0 }, /* Not used */
0736     { 0x20, 0x404501f0 }, /* Not used */
0737     { 0x22, 0x404401f0 }, /* Not used */
0738     { 0x23, 0x40a701f0 }, /* Not used */
0739     {}
0740 };
0741 
0742 static const struct hda_fixup cxt_fixups[] = {
0743     [CXT_PINCFG_LENOVO_X200] = {
0744         .type = HDA_FIXUP_PINS,
0745         .v.pins = cxt_pincfg_lenovo_x200,
0746     },
0747     [CXT_PINCFG_LENOVO_TP410] = {
0748         .type = HDA_FIXUP_PINS,
0749         .v.pins = cxt_pincfg_lenovo_tp410,
0750         .chained = true,
0751         .chain_id = CXT_FIXUP_THINKPAD_ACPI,
0752     },
0753     [CXT_PINCFG_LEMOTE_A1004] = {
0754         .type = HDA_FIXUP_PINS,
0755         .chained = true,
0756         .chain_id = CXT_FIXUP_INC_MIC_BOOST,
0757         .v.pins = cxt_pincfg_lemote,
0758     },
0759     [CXT_PINCFG_LEMOTE_A1205] = {
0760         .type = HDA_FIXUP_PINS,
0761         .v.pins = cxt_pincfg_lemote,
0762     },
0763     [CXT_PINCFG_COMPAQ_CQ60] = {
0764         .type = HDA_FIXUP_PINS,
0765         .v.pins = (const struct hda_pintbl[]) {
0766             /* 0x17 was falsely set up as a mic, it should 0x1d */
0767             { 0x17, 0x400001f0 },
0768             { 0x1d, 0x97a70120 },
0769             { }
0770         }
0771     },
0772     [CXT_FIXUP_STEREO_DMIC] = {
0773         .type = HDA_FIXUP_FUNC,
0774         .v.func = cxt_fixup_stereo_dmic,
0775     },
0776     [CXT_PINCFG_LENOVO_NOTEBOOK] = {
0777         .type = HDA_FIXUP_PINS,
0778         .v.pins = (const struct hda_pintbl[]) {
0779             { 0x1a, 0x05d71030 },
0780             { }
0781         },
0782         .chain_id = CXT_FIXUP_STEREO_DMIC,
0783     },
0784     [CXT_FIXUP_INC_MIC_BOOST] = {
0785         .type = HDA_FIXUP_FUNC,
0786         .v.func = cxt5066_increase_mic_boost,
0787     },
0788     [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
0789         .type = HDA_FIXUP_PINS,
0790         .chained = true,
0791         .chain_id = CXT_FIXUP_HEADPHONE_MIC,
0792         .v.pins = (const struct hda_pintbl[]) {
0793             { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
0794             { }
0795         }
0796     },
0797     [CXT_FIXUP_HEADPHONE_MIC] = {
0798         .type = HDA_FIXUP_FUNC,
0799         .v.func = cxt_fixup_headphone_mic,
0800     },
0801     [CXT_FIXUP_GPIO1] = {
0802         .type = HDA_FIXUP_VERBS,
0803         .v.verbs = (const struct hda_verb[]) {
0804             { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
0805             { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
0806             { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
0807             { }
0808         },
0809     },
0810     [CXT_FIXUP_ASPIRE_DMIC] = {
0811         .type = HDA_FIXUP_FUNC,
0812         .v.func = cxt_fixup_stereo_dmic,
0813         .chained = true,
0814         .chain_id = CXT_FIXUP_GPIO1,
0815     },
0816     [CXT_FIXUP_THINKPAD_ACPI] = {
0817         .type = HDA_FIXUP_FUNC,
0818         .v.func = hda_fixup_thinkpad_acpi,
0819     },
0820     [CXT_FIXUP_OLPC_XO] = {
0821         .type = HDA_FIXUP_FUNC,
0822         .v.func = cxt_fixup_olpc_xo,
0823     },
0824     [CXT_FIXUP_CAP_MIX_AMP] = {
0825         .type = HDA_FIXUP_FUNC,
0826         .v.func = cxt_fixup_cap_mix_amp,
0827     },
0828     [CXT_FIXUP_TOSHIBA_P105] = {
0829         .type = HDA_FIXUP_PINS,
0830         .v.pins = (const struct hda_pintbl[]) {
0831             { 0x10, 0x961701f0 }, /* speaker/hp */
0832             { 0x12, 0x02a1901e }, /* ext mic */
0833             { 0x14, 0x95a70110 }, /* int mic */
0834             {}
0835         },
0836     },
0837     [CXT_FIXUP_HP_530] = {
0838         .type = HDA_FIXUP_PINS,
0839         .v.pins = (const struct hda_pintbl[]) {
0840             { 0x12, 0x90a60160 }, /* int mic */
0841             {}
0842         },
0843         .chained = true,
0844         .chain_id = CXT_FIXUP_CAP_MIX_AMP,
0845     },
0846     [CXT_FIXUP_CAP_MIX_AMP_5047] = {
0847         .type = HDA_FIXUP_FUNC,
0848         .v.func = cxt_fixup_cap_mix_amp_5047,
0849     },
0850     [CXT_FIXUP_MUTE_LED_EAPD] = {
0851         .type = HDA_FIXUP_FUNC,
0852         .v.func = cxt_fixup_mute_led_eapd,
0853     },
0854     [CXT_FIXUP_HP_DOCK] = {
0855         .type = HDA_FIXUP_PINS,
0856         .v.pins = (const struct hda_pintbl[]) {
0857             { 0x16, 0x21011020 }, /* line-out */
0858             { 0x18, 0x2181103f }, /* line-in */
0859             { }
0860         },
0861         .chained = true,
0862         .chain_id = CXT_FIXUP_MUTE_LED_GPIO,
0863     },
0864     [CXT_FIXUP_HP_SPECTRE] = {
0865         .type = HDA_FIXUP_PINS,
0866         .v.pins = (const struct hda_pintbl[]) {
0867             /* enable NID 0x1d for the speaker on top */
0868             { 0x1d, 0x91170111 },
0869             { }
0870         }
0871     },
0872     [CXT_FIXUP_HP_GATE_MIC] = {
0873         .type = HDA_FIXUP_FUNC,
0874         .v.func = cxt_fixup_hp_gate_mic_jack,
0875     },
0876     [CXT_FIXUP_MUTE_LED_GPIO] = {
0877         .type = HDA_FIXUP_FUNC,
0878         .v.func = cxt_fixup_mute_led_gpio,
0879     },
0880     [CXT_FIXUP_HP_ZBOOK_MUTE_LED] = {
0881         .type = HDA_FIXUP_FUNC,
0882         .v.func = cxt_fixup_hp_zbook_mute_led,
0883     },
0884     [CXT_FIXUP_HEADSET_MIC] = {
0885         .type = HDA_FIXUP_FUNC,
0886         .v.func = cxt_fixup_headset_mic,
0887     },
0888     [CXT_FIXUP_HP_MIC_NO_PRESENCE] = {
0889         .type = HDA_FIXUP_PINS,
0890         .v.pins = (const struct hda_pintbl[]) {
0891             { 0x1a, 0x02a1113c },
0892             { }
0893         },
0894         .chained = true,
0895         .chain_id = CXT_FIXUP_HEADSET_MIC,
0896     },
0897 };
0898 
0899 static const struct snd_pci_quirk cxt5045_fixups[] = {
0900     SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
0901     SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
0902     /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
0903      * really bad sound over 0dB on NID 0x17.
0904      */
0905     SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
0906     SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
0907     SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
0908     SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
0909     {}
0910 };
0911 
0912 static const struct hda_model_fixup cxt5045_fixup_models[] = {
0913     { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
0914     { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
0915     { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
0916     {}
0917 };
0918 
0919 static const struct snd_pci_quirk cxt5047_fixups[] = {
0920     /* HP laptops have really bad sound over 0 dB on NID 0x10.
0921      */
0922     SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
0923     {}
0924 };
0925 
0926 static const struct hda_model_fixup cxt5047_fixup_models[] = {
0927     { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
0928     {}
0929 };
0930 
0931 static const struct snd_pci_quirk cxt5051_fixups[] = {
0932     SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
0933     SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
0934     {}
0935 };
0936 
0937 static const struct hda_model_fixup cxt5051_fixup_models[] = {
0938     { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
0939     {}
0940 };
0941 
0942 static const struct snd_pci_quirk cxt5066_fixups[] = {
0943     SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
0944     SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
0945     SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
0946     SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
0947     SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
0948     SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
0949     SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
0950     SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO),
0951     SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
0952     SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO),
0953     SND_PCI_QUIRK(0x103c, 0x828c, "HP EliteBook 840 G4", CXT_FIXUP_HP_DOCK),
0954     SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0955     SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0956     SND_PCI_QUIRK(0x103c, 0x82b4, "HP ProDesk 600 G3", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0957     SND_PCI_QUIRK(0x103c, 0x836e, "HP ProBook 455 G5", CXT_FIXUP_MUTE_LED_GPIO),
0958     SND_PCI_QUIRK(0x103c, 0x837f, "HP ProBook 470 G5", CXT_FIXUP_MUTE_LED_GPIO),
0959     SND_PCI_QUIRK(0x103c, 0x83b2, "HP EliteBook 840 G5", CXT_FIXUP_HP_DOCK),
0960     SND_PCI_QUIRK(0x103c, 0x83b3, "HP EliteBook 830 G5", CXT_FIXUP_HP_DOCK),
0961     SND_PCI_QUIRK(0x103c, 0x83d3, "HP ProBook 640 G4", CXT_FIXUP_HP_DOCK),
0962     SND_PCI_QUIRK(0x103c, 0x8402, "HP ProBook 645 G4", CXT_FIXUP_MUTE_LED_GPIO),
0963     SND_PCI_QUIRK(0x103c, 0x8427, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
0964     SND_PCI_QUIRK(0x103c, 0x844f, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
0965     SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0966     SND_PCI_QUIRK(0x103c, 0x8456, "HP Z2 G4 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0967     SND_PCI_QUIRK(0x103c, 0x8457, "HP Z2 G4 mini", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0968     SND_PCI_QUIRK(0x103c, 0x8458, "HP Z2 G4 mini premium", CXT_FIXUP_HP_MIC_NO_PRESENCE),
0969     SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
0970     SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
0971     SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
0972     SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
0973     SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
0974     SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
0975     SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
0976     SND_PCI_QUIRK(0x17aa, 0x21d2, "Lenovo T420s", CXT_PINCFG_LENOVO_TP410),
0977     SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
0978     SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
0979     SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
0980     SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC),
0981     SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
0982     SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
0983     SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_PINCFG_LENOVO_NOTEBOOK),
0984     SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC),
0985     SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
0986     SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
0987     SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
0988     SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
0989     {}
0990 };
0991 
0992 static const struct hda_model_fixup cxt5066_fixup_models[] = {
0993     { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
0994     { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
0995     { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
0996     { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
0997     { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
0998     { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
0999     { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
1000     { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
1001     { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
1002     { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" },
1003     { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" },
1004     { .id = CXT_FIXUP_HP_ZBOOK_MUTE_LED, .name = "hp-zbook-mute-led" },
1005     { .id = CXT_FIXUP_HP_MIC_NO_PRESENCE, .name = "hp-mic-fix" },
1006     {}
1007 };
1008 
1009 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
1010  * can be created (bko#42825)
1011  */
1012 static void add_cx5051_fake_mutes(struct hda_codec *codec)
1013 {
1014     struct conexant_spec *spec = codec->spec;
1015     static const hda_nid_t out_nids[] = {
1016         0x10, 0x11, 0
1017     };
1018     const hda_nid_t *p;
1019 
1020     for (p = out_nids; *p; p++)
1021         snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
1022                       AC_AMPCAP_MIN_MUTE |
1023                       query_amp_caps(codec, *p, HDA_OUTPUT));
1024     spec->gen.dac_min_mute = true;
1025 }
1026 
1027 static int patch_conexant_auto(struct hda_codec *codec)
1028 {
1029     struct conexant_spec *spec;
1030     int err;
1031 
1032     codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
1033 
1034     spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1035     if (!spec)
1036         return -ENOMEM;
1037     snd_hda_gen_spec_init(&spec->gen);
1038     codec->spec = spec;
1039     codec->patch_ops = cx_auto_patch_ops;
1040 
1041     cx_auto_parse_eapd(codec);
1042     spec->gen.own_eapd_ctl = 1;
1043 
1044     switch (codec->core.vendor_id) {
1045     case 0x14f15045:
1046         codec->single_adc_amp = 1;
1047         spec->gen.mixer_nid = 0x17;
1048         spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1049         snd_hda_pick_fixup(codec, cxt5045_fixup_models,
1050                    cxt5045_fixups, cxt_fixups);
1051         break;
1052     case 0x14f15047:
1053         codec->pin_amp_workaround = 1;
1054         spec->gen.mixer_nid = 0x19;
1055         spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1056         snd_hda_pick_fixup(codec, cxt5047_fixup_models,
1057                    cxt5047_fixups, cxt_fixups);
1058         break;
1059     case 0x14f15051:
1060         add_cx5051_fake_mutes(codec);
1061         codec->pin_amp_workaround = 1;
1062         snd_hda_pick_fixup(codec, cxt5051_fixup_models,
1063                    cxt5051_fixups, cxt_fixups);
1064         break;
1065     case 0x14f15098:
1066         codec->pin_amp_workaround = 1;
1067         spec->gen.mixer_nid = 0x22;
1068         spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1069         snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1070                    cxt5066_fixups, cxt_fixups);
1071         break;
1072     case 0x14f150f2:
1073         codec->power_save_node = 1;
1074         fallthrough;
1075     default:
1076         codec->pin_amp_workaround = 1;
1077         snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1078                    cxt5066_fixups, cxt_fixups);
1079         break;
1080     }
1081 
1082     if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
1083         spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
1084 
1085     snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1086 
1087     err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
1088                        spec->parse_flags);
1089     if (err < 0)
1090         goto error;
1091 
1092     err = cx_auto_parse_beep(codec);
1093     if (err < 0)
1094         goto error;
1095 
1096     err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1097     if (err < 0)
1098         goto error;
1099 
1100     /* Some laptops with Conexant chips show stalls in S3 resume,
1101      * which falls into the single-cmd mode.
1102      * Better to make reset, then.
1103      */
1104     if (!codec->bus->core.sync_write) {
1105         codec_info(codec,
1106                "Enable sync_write for stable communication\n");
1107         codec->bus->core.sync_write = 1;
1108         codec->bus->allow_bus_reset = 1;
1109     }
1110 
1111     snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1112 
1113     return 0;
1114 
1115  error:
1116     cx_auto_free(codec);
1117     return err;
1118 }
1119 
1120 /*
1121  */
1122 
1123 static const struct hda_device_id snd_hda_id_conexant[] = {
1124     HDA_CODEC_ENTRY(0x14f11f86, "CX8070", patch_conexant_auto),
1125     HDA_CODEC_ENTRY(0x14f11f87, "SN6140", patch_conexant_auto),
1126     HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto),
1127     HDA_CODEC_ENTRY(0x14f120d0, "CX11970", patch_conexant_auto),
1128     HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto),
1129     HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto),
1130     HDA_CODEC_ENTRY(0x14f15051, "CX20561 (Hermosa)", patch_conexant_auto),
1131     HDA_CODEC_ENTRY(0x14f15066, "CX20582 (Pebble)", patch_conexant_auto),
1132     HDA_CODEC_ENTRY(0x14f15067, "CX20583 (Pebble HSF)", patch_conexant_auto),
1133     HDA_CODEC_ENTRY(0x14f15068, "CX20584", patch_conexant_auto),
1134     HDA_CODEC_ENTRY(0x14f15069, "CX20585", patch_conexant_auto),
1135     HDA_CODEC_ENTRY(0x14f1506c, "CX20588", patch_conexant_auto),
1136     HDA_CODEC_ENTRY(0x14f1506e, "CX20590", patch_conexant_auto),
1137     HDA_CODEC_ENTRY(0x14f15097, "CX20631", patch_conexant_auto),
1138     HDA_CODEC_ENTRY(0x14f15098, "CX20632", patch_conexant_auto),
1139     HDA_CODEC_ENTRY(0x14f150a1, "CX20641", patch_conexant_auto),
1140     HDA_CODEC_ENTRY(0x14f150a2, "CX20642", patch_conexant_auto),
1141     HDA_CODEC_ENTRY(0x14f150ab, "CX20651", patch_conexant_auto),
1142     HDA_CODEC_ENTRY(0x14f150ac, "CX20652", patch_conexant_auto),
1143     HDA_CODEC_ENTRY(0x14f150b8, "CX20664", patch_conexant_auto),
1144     HDA_CODEC_ENTRY(0x14f150b9, "CX20665", patch_conexant_auto),
1145     HDA_CODEC_ENTRY(0x14f150f1, "CX21722", patch_conexant_auto),
1146     HDA_CODEC_ENTRY(0x14f150f2, "CX20722", patch_conexant_auto),
1147     HDA_CODEC_ENTRY(0x14f150f3, "CX21724", patch_conexant_auto),
1148     HDA_CODEC_ENTRY(0x14f150f4, "CX20724", patch_conexant_auto),
1149     HDA_CODEC_ENTRY(0x14f1510f, "CX20751/2", patch_conexant_auto),
1150     HDA_CODEC_ENTRY(0x14f15110, "CX20751/2", patch_conexant_auto),
1151     HDA_CODEC_ENTRY(0x14f15111, "CX20753/4", patch_conexant_auto),
1152     HDA_CODEC_ENTRY(0x14f15113, "CX20755", patch_conexant_auto),
1153     HDA_CODEC_ENTRY(0x14f15114, "CX20756", patch_conexant_auto),
1154     HDA_CODEC_ENTRY(0x14f15115, "CX20757", patch_conexant_auto),
1155     HDA_CODEC_ENTRY(0x14f151d7, "CX20952", patch_conexant_auto),
1156     {} /* terminator */
1157 };
1158 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant);
1159 
1160 MODULE_LICENSE("GPL");
1161 MODULE_DESCRIPTION("Conexant HD-audio codec");
1162 
1163 static struct hda_codec_driver conexant_driver = {
1164     .id = snd_hda_id_conexant,
1165 };
1166 
1167 module_hda_codec_driver(conexant_driver);