1c9b443d4STobin Davis /* 2c9b443d4STobin Davis * HD audio interface patch for Conexant HDA audio codec 3c9b443d4STobin Davis * 4c9b443d4STobin Davis * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5c9b443d4STobin Davis * Takashi Iwai <tiwai@suse.de> 6c9b443d4STobin Davis * Tobin Davis <tdavis@dsl-only.net> 7c9b443d4STobin Davis * 8c9b443d4STobin Davis * This driver is free software; you can redistribute it and/or modify 9c9b443d4STobin Davis * it under the terms of the GNU General Public License as published by 10c9b443d4STobin Davis * the Free Software Foundation; either version 2 of the License, or 11c9b443d4STobin Davis * (at your option) any later version. 12c9b443d4STobin Davis * 13c9b443d4STobin Davis * This driver is distributed in the hope that it will be useful, 14c9b443d4STobin Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9b443d4STobin Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9b443d4STobin Davis * GNU General Public License for more details. 17c9b443d4STobin Davis * 18c9b443d4STobin Davis * You should have received a copy of the GNU General Public License 19c9b443d4STobin Davis * along with this program; if not, write to the Free Software 20c9b443d4STobin Davis * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c9b443d4STobin Davis */ 22c9b443d4STobin Davis 23c9b443d4STobin Davis #include <linux/init.h> 24c9b443d4STobin Davis #include <linux/delay.h> 25c9b443d4STobin Davis #include <linux/slab.h> 26da155d5bSPaul Gortmaker #include <linux/module.h> 27c9b443d4STobin Davis #include <sound/core.h> 28bc7a166dSUlrich Dangel #include <sound/jack.h> 29bc7a166dSUlrich Dangel 30c9b443d4STobin Davis #include "hda_codec.h" 31c9b443d4STobin Davis #include "hda_local.h" 3223d30f28STakashi Iwai #include "hda_auto_parser.h" 33c0f8faf0SEinar Rünkaru #include "hda_beep.h" 341835a0f9STakashi Iwai #include "hda_jack.h" 35aed523f1STakashi Iwai #include "hda_generic.h" 36c9b443d4STobin Davis 37c9b443d4STobin Davis struct conexant_spec { 3823d30f28STakashi Iwai struct hda_gen_spec gen; 39c9b443d4STobin Davis 40bf92d1d5STakashi Iwai unsigned int beep_amp; 41bf92d1d5STakashi Iwai 42bf92d1d5STakashi Iwai /* extra EAPD pins */ 43bf92d1d5STakashi Iwai unsigned int num_eapds; 44bf92d1d5STakashi Iwai hda_nid_t eapds[4]; 45ff359b14STakashi Iwai bool dynamic_eapd; 463542aed7STakashi Iwai hda_nid_t mute_led_eapd; 47bf92d1d5STakashi Iwai 48e4c3bce2SDavid Henningsson unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ 49e4c3bce2SDavid Henningsson 503a00c660STakashi Iwai /* OPLC XO specific */ 513a00c660STakashi Iwai bool recording; 523a00c660STakashi Iwai bool dc_enable; 533a00c660STakashi Iwai unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */ 543a00c660STakashi Iwai struct nid_path *dc_mode_path; 555cd5b1bdSJerónimo Borque 565cd5b1bdSJerónimo Borque int mute_led_polarity; 575cd5b1bdSJerónimo Borque unsigned int gpio_led; 585cd5b1bdSJerónimo Borque unsigned int gpio_mute_led_mask; 595cd5b1bdSJerónimo Borque unsigned int gpio_mic_led_mask; 605cd5b1bdSJerónimo Borque 61c9b443d4STobin Davis }; 62c9b443d4STobin Davis 63bf92d1d5STakashi Iwai 64bf92d1d5STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 657504b6cdSTakashi Iwai static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid, 667504b6cdSTakashi Iwai int idx, int dir) 677504b6cdSTakashi Iwai { 687504b6cdSTakashi Iwai spec->gen.beep_nid = nid; 697504b6cdSTakashi Iwai spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); 707504b6cdSTakashi Iwai } 71bf92d1d5STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 72bf92d1d5STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 73bf92d1d5STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 74bf92d1d5STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 75bf92d1d5STakashi Iwai { } /* end */ 76bf92d1d5STakashi Iwai }; 77bf92d1d5STakashi Iwai 78bf92d1d5STakashi Iwai /* create beep controls if needed */ 79bf92d1d5STakashi Iwai static int add_beep_ctls(struct hda_codec *codec) 80bf92d1d5STakashi Iwai { 81bf92d1d5STakashi Iwai struct conexant_spec *spec = codec->spec; 82bf92d1d5STakashi Iwai int err; 83bf92d1d5STakashi Iwai 84bf92d1d5STakashi Iwai if (spec->beep_amp) { 85bf92d1d5STakashi Iwai const struct snd_kcontrol_new *knew; 86bf92d1d5STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 87bf92d1d5STakashi Iwai struct snd_kcontrol *kctl; 88bf92d1d5STakashi Iwai kctl = snd_ctl_new1(knew, codec); 89bf92d1d5STakashi Iwai if (!kctl) 90bf92d1d5STakashi Iwai return -ENOMEM; 91bf92d1d5STakashi Iwai kctl->private_value = spec->beep_amp; 92bf92d1d5STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 93bf92d1d5STakashi Iwai if (err < 0) 94bf92d1d5STakashi Iwai return err; 95bf92d1d5STakashi Iwai } 96bf92d1d5STakashi Iwai } 97bf92d1d5STakashi Iwai return 0; 98bf92d1d5STakashi Iwai } 99bf92d1d5STakashi Iwai #else 100bf92d1d5STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 101bf92d1d5STakashi Iwai #define add_beep_ctls(codec) 0 102bf92d1d5STakashi Iwai #endif 103bf92d1d5STakashi Iwai 104461e2c78STakashi Iwai /* 105f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 106f2e5731dSTakashi Iwai */ 107f2e5731dSTakashi Iwai 108f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 109f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 110f2e5731dSTakashi Iwai { 111f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 1127639a06cSTakashi Iwai hda_nid_t nid; 113f2e5731dSTakashi Iwai 1147639a06cSTakashi Iwai for_each_hda_codec_node(nid, codec) 115f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 116f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 117f2e5731dSTakashi Iwai break; 118f2e5731dSTakashi Iwai } 119f2e5731dSTakashi Iwai } 120f2e5731dSTakashi Iwai #else 121f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 122f2e5731dSTakashi Iwai #endif 123f2e5731dSTakashi Iwai 124254f2968STakashi Iwai /* parse EAPDs */ 12519110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 12619110595STakashi Iwai { 12719110595STakashi Iwai struct conexant_spec *spec = codec->spec; 1287639a06cSTakashi Iwai hda_nid_t nid; 12919110595STakashi Iwai 1307639a06cSTakashi Iwai for_each_hda_codec_node(nid, codec) { 13119110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 13219110595STakashi Iwai continue; 13319110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 13419110595STakashi Iwai continue; 13519110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 13619110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 13719110595STakashi Iwai break; 13819110595STakashi Iwai } 139254f2968STakashi Iwai 140254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 141254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 142254f2968STakashi Iwai * pins, and we can control EAPD per pin. 143254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 144254f2968STakashi Iwai * thus it might control over all pins. 145254f2968STakashi Iwai */ 146aed523f1STakashi Iwai if (spec->num_eapds > 2) 147ff359b14STakashi Iwai spec->dynamic_eapd = 1; 148f2e5731dSTakashi Iwai } 149f2e5731dSTakashi Iwai 150da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 151da339866STakashi Iwai hda_nid_t *pins, bool on) 152f2e5731dSTakashi Iwai { 153f2e5731dSTakashi Iwai int i; 154f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 155f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 156f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 157da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 158da339866STakashi Iwai on ? 0x02 : 0); 159f2e5731dSTakashi Iwai } 160f2e5731dSTakashi Iwai } 161f2e5731dSTakashi Iwai 162527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */ 163527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled) 164527c73baSTakashi Iwai { 165527c73baSTakashi Iwai struct hda_codec *codec = private_data; 166527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 167527c73baSTakashi Iwai 168527c73baSTakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 169527c73baSTakashi Iwai } 170527c73baSTakashi Iwai 1713542aed7STakashi Iwai /* turn on/off EAPD according to Master switch (inversely!) for mute LED */ 1723542aed7STakashi Iwai static void cx_auto_vmaster_hook_mute_led(void *private_data, int enabled) 1733542aed7STakashi Iwai { 1743542aed7STakashi Iwai struct hda_codec *codec = private_data; 1753542aed7STakashi Iwai struct conexant_spec *spec = codec->spec; 1763542aed7STakashi Iwai 1773542aed7STakashi Iwai snd_hda_codec_write(codec, spec->mute_led_eapd, 0, 1783542aed7STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 1793542aed7STakashi Iwai enabled ? 0x00 : 0x02); 1803542aed7STakashi Iwai } 1813542aed7STakashi Iwai 182f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 183f2e5731dSTakashi Iwai { 184f2e5731dSTakashi Iwai int err; 185f2e5731dSTakashi Iwai 186aed523f1STakashi Iwai err = snd_hda_gen_build_controls(codec); 187f2e5731dSTakashi Iwai if (err < 0) 188f2e5731dSTakashi Iwai return err; 189f2e5731dSTakashi Iwai 190aed523f1STakashi Iwai err = add_beep_ctls(codec); 191aed523f1STakashi Iwai if (err < 0) 192aed523f1STakashi Iwai return err; 19322ce5f74STakashi Iwai 19422ce5f74STakashi Iwai return 0; 19522ce5f74STakashi Iwai } 19622ce5f74STakashi Iwai 197ff359b14STakashi Iwai static int cx_auto_init(struct hda_codec *codec) 198ff359b14STakashi Iwai { 199ff359b14STakashi Iwai struct conexant_spec *spec = codec->spec; 200ff359b14STakashi Iwai snd_hda_gen_init(codec); 201ff359b14STakashi Iwai if (!spec->dynamic_eapd) 202ff359b14STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 203e4c3bce2SDavid Henningsson 204e4c3bce2SDavid Henningsson snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT); 205e4c3bce2SDavid Henningsson 206ff359b14STakashi Iwai return 0; 207ff359b14STakashi Iwai } 208ff359b14STakashi Iwai 209f6b28e4dSDavid Henningsson static void cx_auto_reboot_notify(struct hda_codec *codec) 210f6b28e4dSDavid Henningsson { 211f6b28e4dSDavid Henningsson struct conexant_spec *spec = codec->spec; 212f6b28e4dSDavid Henningsson 21356dc66ffSTakashi Iwai switch (codec->core.vendor_id) { 21456dc66ffSTakashi Iwai case 0x14f150f2: /* CX20722 */ 21556dc66ffSTakashi Iwai case 0x14f150f4: /* CX20724 */ 21656dc66ffSTakashi Iwai break; 21756dc66ffSTakashi Iwai default: 218f6b28e4dSDavid Henningsson return; 21956dc66ffSTakashi Iwai } 220f6b28e4dSDavid Henningsson 221f6b28e4dSDavid Henningsson /* Turn the CX20722 codec into D3 to avoid spurious noises 222f6b28e4dSDavid Henningsson from the internal speaker during (and after) reboot */ 223f6b28e4dSDavid Henningsson cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false); 224f6b28e4dSDavid Henningsson 225f6b28e4dSDavid Henningsson snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); 226f6b28e4dSDavid Henningsson snd_hda_codec_write(codec, codec->core.afg, 0, 227f6b28e4dSDavid Henningsson AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 228f6b28e4dSDavid Henningsson } 229f6b28e4dSDavid Henningsson 230f6b28e4dSDavid Henningsson static void cx_auto_free(struct hda_codec *codec) 231f6b28e4dSDavid Henningsson { 232f6b28e4dSDavid Henningsson cx_auto_reboot_notify(codec); 233f6b28e4dSDavid Henningsson snd_hda_gen_free(codec); 234f6b28e4dSDavid Henningsson } 23508cf680cSDavid Henningsson 23634cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 237f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 238aed523f1STakashi Iwai .build_pcms = snd_hda_gen_build_pcms, 239ff359b14STakashi Iwai .init = cx_auto_init, 240f6b28e4dSDavid Henningsson .reboot_notify = cx_auto_reboot_notify, 24108cf680cSDavid Henningsson .free = cx_auto_free, 24229adc4b9SDavid Henningsson .unsol_event = snd_hda_jack_unsol_event, 243164a7adaSTakashi Iwai #ifdef CONFIG_PM 244164a7adaSTakashi Iwai .check_power_status = snd_hda_gen_check_power_status, 245164a7adaSTakashi Iwai #endif 246f2e5731dSTakashi Iwai }; 247f2e5731dSTakashi Iwai 248e92d4b08STakashi Iwai /* 249e92d4b08STakashi Iwai * pin fix-up 250e92d4b08STakashi Iwai */ 25118dcd304SDavid Henningsson enum { 25218dcd304SDavid Henningsson CXT_PINCFG_LENOVO_X200, 253d3980110STakashi Iwai CXT_PINCFG_LENOVO_TP410, 254239fb862SHuacai Chen CXT_PINCFG_LEMOTE_A1004, 255239fb862SHuacai Chen CXT_PINCFG_LEMOTE_A1205, 256ddb6ca75STakashi Iwai CXT_PINCFG_COMPAQ_CQ60, 25718dcd304SDavid Henningsson CXT_FIXUP_STEREO_DMIC, 258239fb862SHuacai Chen CXT_FIXUP_INC_MIC_BOOST, 259e4c3bce2SDavid Henningsson CXT_FIXUP_HEADPHONE_MIC_PIN, 260e4c3bce2SDavid Henningsson CXT_FIXUP_HEADPHONE_MIC, 2614a437044STakashi Iwai CXT_FIXUP_GPIO1, 262ff50479aSTakashi Iwai CXT_FIXUP_ASPIRE_DMIC, 26308cf680cSDavid Henningsson CXT_FIXUP_THINKPAD_ACPI, 2643a00c660STakashi Iwai CXT_FIXUP_OLPC_XO, 265ad7725d3STakashi Iwai CXT_FIXUP_CAP_MIX_AMP, 2666dcbadefSTakashi Iwai CXT_FIXUP_TOSHIBA_P105, 267e5eac90dSTakashi Iwai CXT_FIXUP_HP_530, 268ea30e7dfSTakashi Iwai CXT_FIXUP_CAP_MIX_AMP_5047, 2693542aed7STakashi Iwai CXT_FIXUP_MUTE_LED_EAPD, 270cc3a47a2SJaroslav Kysela CXT_FIXUP_HP_DOCK, 2710eec8809STakashi Iwai CXT_FIXUP_HP_SPECTRE, 272f73cd43aSTakashi Iwai CXT_FIXUP_HP_GATE_MIC, 2735cd5b1bdSJerónimo Borque CXT_FIXUP_MUTE_LED_GPIO, 274*322f74edSHui Wang CXT_FIXUP_HEADSET_MIC, 275*322f74edSHui Wang CXT_FIXUP_HP_MIC_NO_PRESENCE, 27618dcd304SDavid Henningsson }; 27718dcd304SDavid Henningsson 278b317b032STakashi Iwai /* for hda_fixup_thinkpad_acpi() */ 279b317b032STakashi Iwai #include "thinkpad_helper.c" 28008cf680cSDavid Henningsson 28123d30f28STakashi Iwai static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 28223d30f28STakashi Iwai const struct hda_fixup *fix, int action) 283e92d4b08STakashi Iwai { 28418dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 285aed523f1STakashi Iwai spec->gen.inv_dmic_split = 1; 286e92d4b08STakashi Iwai } 287e92d4b08STakashi Iwai 288239fb862SHuacai Chen static void cxt5066_increase_mic_boost(struct hda_codec *codec, 289239fb862SHuacai Chen const struct hda_fixup *fix, int action) 290239fb862SHuacai Chen { 291239fb862SHuacai Chen if (action != HDA_FIXUP_ACT_PRE_PROBE) 292239fb862SHuacai Chen return; 293239fb862SHuacai Chen 294239fb862SHuacai Chen snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT, 295239fb862SHuacai Chen (0x3 << AC_AMPCAP_OFFSET_SHIFT) | 296239fb862SHuacai Chen (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) | 297239fb862SHuacai Chen (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | 298239fb862SHuacai Chen (0 << AC_AMPCAP_MUTE_SHIFT)); 299239fb862SHuacai Chen } 300239fb862SHuacai Chen 301e4c3bce2SDavid Henningsson static void cxt_update_headset_mode(struct hda_codec *codec) 302e4c3bce2SDavid Henningsson { 303e4c3bce2SDavid Henningsson /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */ 304e4c3bce2SDavid Henningsson int i; 305e4c3bce2SDavid Henningsson bool mic_mode = false; 306e4c3bce2SDavid Henningsson struct conexant_spec *spec = codec->spec; 307e4c3bce2SDavid Henningsson struct auto_pin_cfg *cfg = &spec->gen.autocfg; 308e4c3bce2SDavid Henningsson 309e4c3bce2SDavid Henningsson hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]]; 310e4c3bce2SDavid Henningsson 311e4c3bce2SDavid Henningsson for (i = 0; i < cfg->num_inputs; i++) 312e4c3bce2SDavid Henningsson if (cfg->inputs[i].pin == mux_pin) { 313e4c3bce2SDavid Henningsson mic_mode = !!cfg->inputs[i].is_headphone_mic; 314e4c3bce2SDavid Henningsson break; 315e4c3bce2SDavid Henningsson } 316e4c3bce2SDavid Henningsson 317e4c3bce2SDavid Henningsson if (mic_mode) { 318e4c3bce2SDavid Henningsson snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */ 319e4c3bce2SDavid Henningsson spec->gen.hp_jack_present = false; 320e4c3bce2SDavid Henningsson } else { 321e4c3bce2SDavid Henningsson snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */ 322e4c3bce2SDavid Henningsson spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]); 323e4c3bce2SDavid Henningsson } 324e4c3bce2SDavid Henningsson 325e4c3bce2SDavid Henningsson snd_hda_gen_update_outputs(codec); 326e4c3bce2SDavid Henningsson } 327e4c3bce2SDavid Henningsson 328e4c3bce2SDavid Henningsson static void cxt_update_headset_mode_hook(struct hda_codec *codec, 3297fe30711STakashi Iwai struct snd_kcontrol *kcontrol, 330e4c3bce2SDavid Henningsson struct snd_ctl_elem_value *ucontrol) 331e4c3bce2SDavid Henningsson { 332e4c3bce2SDavid Henningsson cxt_update_headset_mode(codec); 333e4c3bce2SDavid Henningsson } 334e4c3bce2SDavid Henningsson 335e4c3bce2SDavid Henningsson static void cxt_fixup_headphone_mic(struct hda_codec *codec, 336e4c3bce2SDavid Henningsson const struct hda_fixup *fix, int action) 337e4c3bce2SDavid Henningsson { 338e4c3bce2SDavid Henningsson struct conexant_spec *spec = codec->spec; 339e4c3bce2SDavid Henningsson 340e4c3bce2SDavid Henningsson switch (action) { 341e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_PRE_PROBE: 342e4c3bce2SDavid Henningsson spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; 343a551d914STakashi Iwai snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410); 344e4c3bce2SDavid Henningsson break; 345e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_PROBE: 346e4c3bce2SDavid Henningsson spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; 347e4c3bce2SDavid Henningsson spec->gen.automute_hook = cxt_update_headset_mode; 348e4c3bce2SDavid Henningsson break; 349e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_INIT: 350e4c3bce2SDavid Henningsson cxt_update_headset_mode(codec); 351e4c3bce2SDavid Henningsson break; 352e4c3bce2SDavid Henningsson } 353e4c3bce2SDavid Henningsson } 354e4c3bce2SDavid Henningsson 355*322f74edSHui Wang static void cxt_fixup_headset_mic(struct hda_codec *codec, 356*322f74edSHui Wang const struct hda_fixup *fix, int action) 357*322f74edSHui Wang { 358*322f74edSHui Wang struct conexant_spec *spec = codec->spec; 359*322f74edSHui Wang 360*322f74edSHui Wang switch (action) { 361*322f74edSHui Wang case HDA_FIXUP_ACT_PRE_PROBE: 362*322f74edSHui Wang spec->parse_flags |= HDA_PINCFG_HEADSET_MIC; 363*322f74edSHui Wang break; 364*322f74edSHui Wang } 365*322f74edSHui Wang } 366*322f74edSHui Wang 3673a00c660STakashi Iwai /* OPLC XO 1.5 fixup */ 3683a00c660STakashi Iwai 3693a00c660STakashi Iwai /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 3703a00c660STakashi Iwai * through the microphone jack. 3713a00c660STakashi Iwai * When the user enables this through a mixer switch, both internal and 3723a00c660STakashi Iwai * external microphones are disabled. Gain is fixed at 0dB. In this mode, 3733a00c660STakashi Iwai * we also allow the bias to be configured through a separate mixer 3743a00c660STakashi Iwai * control. */ 3753a00c660STakashi Iwai 3763a00c660STakashi Iwai #define update_mic_pin(codec, nid, val) \ 3773a00c660STakashi Iwai snd_hda_codec_update_cache(codec, nid, 0, \ 3783a00c660STakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, val) 3793a00c660STakashi Iwai 3803a00c660STakashi Iwai static const struct hda_input_mux olpc_xo_dc_bias = { 3813a00c660STakashi Iwai .num_items = 3, 3823a00c660STakashi Iwai .items = { 3833a00c660STakashi Iwai { "Off", PIN_IN }, 3843a00c660STakashi Iwai { "50%", PIN_VREF50 }, 3853a00c660STakashi Iwai { "80%", PIN_VREF80 }, 3863a00c660STakashi Iwai }, 3873a00c660STakashi Iwai }; 3883a00c660STakashi Iwai 3893a00c660STakashi Iwai static void olpc_xo_update_mic_boost(struct hda_codec *codec) 3903a00c660STakashi Iwai { 3913a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 3923a00c660STakashi Iwai int ch, val; 3933a00c660STakashi Iwai 3943a00c660STakashi Iwai for (ch = 0; ch < 2; ch++) { 3953a00c660STakashi Iwai val = AC_AMP_SET_OUTPUT | 3963a00c660STakashi Iwai (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT); 3973a00c660STakashi Iwai if (!spec->dc_enable) 3983a00c660STakashi Iwai val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0); 3993a00c660STakashi Iwai snd_hda_codec_write(codec, 0x17, 0, 4003a00c660STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 4013a00c660STakashi Iwai } 4023a00c660STakashi Iwai } 4033a00c660STakashi Iwai 4043a00c660STakashi Iwai static void olpc_xo_update_mic_pins(struct hda_codec *codec) 4053a00c660STakashi Iwai { 4063a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4073a00c660STakashi Iwai int cur_input, val; 4083a00c660STakashi Iwai struct nid_path *path; 4093a00c660STakashi Iwai 4103a00c660STakashi Iwai cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]]; 4113a00c660STakashi Iwai 4123a00c660STakashi Iwai /* Set up mic pins for port-B, C and F dynamically as the recording 4133a00c660STakashi Iwai * LED is turned on/off by these pin controls 4143a00c660STakashi Iwai */ 4153a00c660STakashi Iwai if (!spec->dc_enable) { 4163a00c660STakashi Iwai /* disable DC bias path and pin for port F */ 4173a00c660STakashi Iwai update_mic_pin(codec, 0x1e, 0); 4183a00c660STakashi Iwai snd_hda_activate_path(codec, spec->dc_mode_path, false, false); 4193a00c660STakashi Iwai 4203a00c660STakashi Iwai /* update port B (ext mic) and C (int mic) */ 4213a00c660STakashi Iwai /* OLPC defers mic widget control until when capture is 4223a00c660STakashi Iwai * started because the microphone LED comes on as soon as 4233a00c660STakashi Iwai * these settings are put in place. if we did this before 4243a00c660STakashi Iwai * recording, it would give the false indication that 4253a00c660STakashi Iwai * recording is happening when it is not. 4263a00c660STakashi Iwai */ 4273a00c660STakashi Iwai update_mic_pin(codec, 0x1a, spec->recording ? 4283a00c660STakashi Iwai snd_hda_codec_get_pin_target(codec, 0x1a) : 0); 4293a00c660STakashi Iwai update_mic_pin(codec, 0x1b, spec->recording ? 4303a00c660STakashi Iwai snd_hda_codec_get_pin_target(codec, 0x1b) : 0); 4313a00c660STakashi Iwai /* enable normal mic path */ 4323a00c660STakashi Iwai path = snd_hda_get_path_from_idx(codec, cur_input); 4333a00c660STakashi Iwai if (path) 4343a00c660STakashi Iwai snd_hda_activate_path(codec, path, true, false); 4353a00c660STakashi Iwai } else { 4363a00c660STakashi Iwai /* disable normal mic path */ 4373a00c660STakashi Iwai path = snd_hda_get_path_from_idx(codec, cur_input); 4383a00c660STakashi Iwai if (path) 4393a00c660STakashi Iwai snd_hda_activate_path(codec, path, false, false); 4403a00c660STakashi Iwai 4413a00c660STakashi Iwai /* Even though port F is the DC input, the bias is controlled 4423a00c660STakashi Iwai * on port B. We also leave that port as an active input (but 4433a00c660STakashi Iwai * unselected) in DC mode just in case that is necessary to 4443a00c660STakashi Iwai * make the bias setting take effect. 4453a00c660STakashi Iwai */ 4463a00c660STakashi Iwai if (spec->recording) 4473a00c660STakashi Iwai val = olpc_xo_dc_bias.items[spec->dc_input_bias].index; 4483a00c660STakashi Iwai else 4493a00c660STakashi Iwai val = 0; 4503a00c660STakashi Iwai update_mic_pin(codec, 0x1a, val); 4513a00c660STakashi Iwai update_mic_pin(codec, 0x1b, 0); 4523a00c660STakashi Iwai /* enable DC bias path and pin */ 4533a00c660STakashi Iwai update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0); 4543a00c660STakashi Iwai snd_hda_activate_path(codec, spec->dc_mode_path, true, false); 4553a00c660STakashi Iwai } 4563a00c660STakashi Iwai } 4573a00c660STakashi Iwai 4583a00c660STakashi Iwai /* mic_autoswitch hook */ 4591a4f69d5STakashi Iwai static void olpc_xo_automic(struct hda_codec *codec, 4601a4f69d5STakashi Iwai struct hda_jack_callback *jack) 4613a00c660STakashi Iwai { 4623a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4633a00c660STakashi Iwai 4643a00c660STakashi Iwai /* in DC mode, we don't handle automic */ 4653a00c660STakashi Iwai if (!spec->dc_enable) 4663a00c660STakashi Iwai snd_hda_gen_mic_autoswitch(codec, jack); 4673a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4683a00c660STakashi Iwai if (spec->dc_enable) 4693a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 4703a00c660STakashi Iwai } 4713a00c660STakashi Iwai 4723a00c660STakashi Iwai /* pcm_capture hook */ 4733a00c660STakashi Iwai static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo, 4743a00c660STakashi Iwai struct hda_codec *codec, 4753a00c660STakashi Iwai struct snd_pcm_substream *substream, 4763a00c660STakashi Iwai int action) 4773a00c660STakashi Iwai { 4783a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4793a00c660STakashi Iwai 4803a00c660STakashi Iwai /* toggle spec->recording flag and update mic pins accordingly 4813a00c660STakashi Iwai * for turning on/off LED 4823a00c660STakashi Iwai */ 4833a00c660STakashi Iwai switch (action) { 4843a00c660STakashi Iwai case HDA_GEN_PCM_ACT_PREPARE: 4853a00c660STakashi Iwai spec->recording = 1; 4863a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4873a00c660STakashi Iwai break; 4883a00c660STakashi Iwai case HDA_GEN_PCM_ACT_CLEANUP: 4893a00c660STakashi Iwai spec->recording = 0; 4903a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4913a00c660STakashi Iwai break; 4923a00c660STakashi Iwai } 4933a00c660STakashi Iwai } 4943a00c660STakashi Iwai 4953a00c660STakashi Iwai static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol, 4963a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 4973a00c660STakashi Iwai { 4983a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 4993a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5003a00c660STakashi Iwai ucontrol->value.integer.value[0] = spec->dc_enable; 5013a00c660STakashi Iwai return 0; 5023a00c660STakashi Iwai } 5033a00c660STakashi Iwai 5043a00c660STakashi Iwai static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol, 5053a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 5063a00c660STakashi Iwai { 5073a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 5083a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5093a00c660STakashi Iwai int dc_enable = !!ucontrol->value.integer.value[0]; 5103a00c660STakashi Iwai 5113a00c660STakashi Iwai if (dc_enable == spec->dc_enable) 5123a00c660STakashi Iwai return 0; 5133a00c660STakashi Iwai 5143a00c660STakashi Iwai spec->dc_enable = dc_enable; 5153a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 5163a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 5173a00c660STakashi Iwai return 1; 5183a00c660STakashi Iwai } 5193a00c660STakashi Iwai 5203a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 5213a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 5223a00c660STakashi Iwai { 5233a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 5243a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5253a00c660STakashi Iwai ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 5263a00c660STakashi Iwai return 0; 5273a00c660STakashi Iwai } 5283a00c660STakashi Iwai 5293a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 5303a00c660STakashi Iwai struct snd_ctl_elem_info *uinfo) 5313a00c660STakashi Iwai { 5323a00c660STakashi Iwai return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo); 5333a00c660STakashi Iwai } 5343a00c660STakashi Iwai 5353a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 5363a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 5373a00c660STakashi Iwai { 5383a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 5393a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5403a00c660STakashi Iwai const struct hda_input_mux *imux = &olpc_xo_dc_bias; 5413a00c660STakashi Iwai unsigned int idx; 5423a00c660STakashi Iwai 5433a00c660STakashi Iwai idx = ucontrol->value.enumerated.item[0]; 5443a00c660STakashi Iwai if (idx >= imux->num_items) 5453a00c660STakashi Iwai idx = imux->num_items - 1; 5463a00c660STakashi Iwai if (spec->dc_input_bias == idx) 5473a00c660STakashi Iwai return 0; 5483a00c660STakashi Iwai 5493a00c660STakashi Iwai spec->dc_input_bias = idx; 5503a00c660STakashi Iwai if (spec->dc_enable) 5513a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 5523a00c660STakashi Iwai return 1; 5533a00c660STakashi Iwai } 5543a00c660STakashi Iwai 5553a00c660STakashi Iwai static const struct snd_kcontrol_new olpc_xo_mixers[] = { 5563a00c660STakashi Iwai { 5573a00c660STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5583a00c660STakashi Iwai .name = "DC Mode Enable Switch", 5593a00c660STakashi Iwai .info = snd_ctl_boolean_mono_info, 5603a00c660STakashi Iwai .get = olpc_xo_dc_mode_get, 5613a00c660STakashi Iwai .put = olpc_xo_dc_mode_put, 5623a00c660STakashi Iwai }, 5633a00c660STakashi Iwai { 5643a00c660STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5653a00c660STakashi Iwai .name = "DC Input Bias Enum", 5663a00c660STakashi Iwai .info = olpc_xo_dc_bias_enum_info, 5673a00c660STakashi Iwai .get = olpc_xo_dc_bias_enum_get, 5683a00c660STakashi Iwai .put = olpc_xo_dc_bias_enum_put, 5693a00c660STakashi Iwai }, 5703a00c660STakashi Iwai {} 5713a00c660STakashi Iwai }; 5723a00c660STakashi Iwai 5733a00c660STakashi Iwai /* overriding mic boost put callback; update mic boost volume only when 5743a00c660STakashi Iwai * DC mode is disabled 5753a00c660STakashi Iwai */ 5763a00c660STakashi Iwai static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol, 5773a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 5783a00c660STakashi Iwai { 5793a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 5803a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5813a00c660STakashi Iwai int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol); 5823a00c660STakashi Iwai if (ret > 0 && spec->dc_enable) 5833a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 5843a00c660STakashi Iwai return ret; 5853a00c660STakashi Iwai } 5863a00c660STakashi Iwai 5873a00c660STakashi Iwai static void cxt_fixup_olpc_xo(struct hda_codec *codec, 5883a00c660STakashi Iwai const struct hda_fixup *fix, int action) 5893a00c660STakashi Iwai { 5903a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5913a00c660STakashi Iwai int i; 5923a00c660STakashi Iwai 5933a00c660STakashi Iwai if (action != HDA_FIXUP_ACT_PROBE) 5943a00c660STakashi Iwai return; 5953a00c660STakashi Iwai 5963a00c660STakashi Iwai spec->gen.mic_autoswitch_hook = olpc_xo_automic; 5973a00c660STakashi Iwai spec->gen.pcm_capture_hook = olpc_xo_capture_hook; 5983a00c660STakashi Iwai spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0); 5993a00c660STakashi Iwai 6003a00c660STakashi Iwai snd_hda_add_new_ctls(codec, olpc_xo_mixers); 6013a00c660STakashi Iwai 6023a00c660STakashi Iwai /* OLPC's microphone port is DC coupled for use with external sensors, 6033a00c660STakashi Iwai * therefore we use a 50% mic bias in order to center the input signal 6043a00c660STakashi Iwai * with the DC input range of the codec. 6053a00c660STakashi Iwai */ 6063a00c660STakashi Iwai snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50); 6073a00c660STakashi Iwai 6083a00c660STakashi Iwai /* override mic boost control */ 6093a00c660STakashi Iwai for (i = 0; i < spec->gen.kctls.used; i++) { 6103a00c660STakashi Iwai struct snd_kcontrol_new *kctl = 6113a00c660STakashi Iwai snd_array_elem(&spec->gen.kctls, i); 6123a00c660STakashi Iwai if (!strcmp(kctl->name, "Mic Boost Volume")) { 6133a00c660STakashi Iwai kctl->put = olpc_xo_mic_boost_put; 6143a00c660STakashi Iwai break; 6153a00c660STakashi Iwai } 6163a00c660STakashi Iwai } 6173a00c660STakashi Iwai } 6183a00c660STakashi Iwai 6193542aed7STakashi Iwai static void cxt_fixup_mute_led_eapd(struct hda_codec *codec, 6203542aed7STakashi Iwai const struct hda_fixup *fix, int action) 6213542aed7STakashi Iwai { 6223542aed7STakashi Iwai struct conexant_spec *spec = codec->spec; 6233542aed7STakashi Iwai 6243542aed7STakashi Iwai if (action == HDA_FIXUP_ACT_PRE_PROBE) { 6253542aed7STakashi Iwai spec->mute_led_eapd = 0x1b; 6263542aed7STakashi Iwai spec->dynamic_eapd = 1; 6273542aed7STakashi Iwai spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook_mute_led; 6283542aed7STakashi Iwai } 6293542aed7STakashi Iwai } 6303542aed7STakashi Iwai 631ad7725d3STakashi Iwai /* 632ad7725d3STakashi Iwai * Fix max input level on mixer widget to 0dB 633ad7725d3STakashi Iwai * (originally it has 0x2b steps with 0dB offset 0x14) 634ad7725d3STakashi Iwai */ 635ad7725d3STakashi Iwai static void cxt_fixup_cap_mix_amp(struct hda_codec *codec, 636ad7725d3STakashi Iwai const struct hda_fixup *fix, int action) 637ad7725d3STakashi Iwai { 638ad7725d3STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 639ad7725d3STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 640ad7725d3STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 641ad7725d3STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 642ad7725d3STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 643ad7725d3STakashi Iwai } 644e4c3bce2SDavid Henningsson 645ea30e7dfSTakashi Iwai /* 646ea30e7dfSTakashi Iwai * Fix max input level on mixer widget to 0dB 647ea30e7dfSTakashi Iwai * (originally it has 0x1e steps with 0 dB offset 0x17) 648ea30e7dfSTakashi Iwai */ 649ea30e7dfSTakashi Iwai static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec, 650ea30e7dfSTakashi Iwai const struct hda_fixup *fix, int action) 651ea30e7dfSTakashi Iwai { 652ea30e7dfSTakashi Iwai snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 653ea30e7dfSTakashi Iwai (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 654ea30e7dfSTakashi Iwai (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 655ea30e7dfSTakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 656ea30e7dfSTakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 657ea30e7dfSTakashi Iwai } 658ea30e7dfSTakashi Iwai 659f73cd43aSTakashi Iwai static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec, 660f73cd43aSTakashi Iwai const struct hda_fixup *fix, 661f73cd43aSTakashi Iwai int action) 662f73cd43aSTakashi Iwai { 663f73cd43aSTakashi Iwai /* the mic pin (0x19) doesn't give an unsolicited event; 664f73cd43aSTakashi Iwai * probe the mic pin together with the headphone pin (0x16) 665f73cd43aSTakashi Iwai */ 666f73cd43aSTakashi Iwai if (action == HDA_FIXUP_ACT_PROBE) 667f73cd43aSTakashi Iwai snd_hda_jack_set_gating_jack(codec, 0x19, 0x16); 668f73cd43aSTakashi Iwai } 669f73cd43aSTakashi Iwai 6705cd5b1bdSJerónimo Borque /* update LED status via GPIO */ 6715cd5b1bdSJerónimo Borque static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask, 6725cd5b1bdSJerónimo Borque bool enabled) 6735cd5b1bdSJerónimo Borque { 6745cd5b1bdSJerónimo Borque struct conexant_spec *spec = codec->spec; 6755cd5b1bdSJerónimo Borque unsigned int oldval = spec->gpio_led; 6765cd5b1bdSJerónimo Borque 6775cd5b1bdSJerónimo Borque if (spec->mute_led_polarity) 6785cd5b1bdSJerónimo Borque enabled = !enabled; 6795cd5b1bdSJerónimo Borque 6805cd5b1bdSJerónimo Borque if (enabled) 6815cd5b1bdSJerónimo Borque spec->gpio_led &= ~mask; 6825cd5b1bdSJerónimo Borque else 6835cd5b1bdSJerónimo Borque spec->gpio_led |= mask; 6845cd5b1bdSJerónimo Borque if (spec->gpio_led != oldval) 6855cd5b1bdSJerónimo Borque snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 6865cd5b1bdSJerónimo Borque spec->gpio_led); 6875cd5b1bdSJerónimo Borque } 6885cd5b1bdSJerónimo Borque 6895cd5b1bdSJerónimo Borque /* turn on/off mute LED via GPIO per vmaster hook */ 6905cd5b1bdSJerónimo Borque static void cxt_fixup_gpio_mute_hook(void *private_data, int enabled) 6915cd5b1bdSJerónimo Borque { 6925cd5b1bdSJerónimo Borque struct hda_codec *codec = private_data; 6935cd5b1bdSJerónimo Borque struct conexant_spec *spec = codec->spec; 6945cd5b1bdSJerónimo Borque 6955cd5b1bdSJerónimo Borque cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled); 6965cd5b1bdSJerónimo Borque } 6975cd5b1bdSJerónimo Borque 6985cd5b1bdSJerónimo Borque /* turn on/off mic-mute LED via GPIO per capture hook */ 6995cd5b1bdSJerónimo Borque static void cxt_fixup_gpio_mic_mute_hook(struct hda_codec *codec, 7005cd5b1bdSJerónimo Borque struct snd_kcontrol *kcontrol, 7015cd5b1bdSJerónimo Borque struct snd_ctl_elem_value *ucontrol) 7025cd5b1bdSJerónimo Borque { 7035cd5b1bdSJerónimo Borque struct conexant_spec *spec = codec->spec; 7045cd5b1bdSJerónimo Borque 7055cd5b1bdSJerónimo Borque if (ucontrol) 7065cd5b1bdSJerónimo Borque cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, 7075cd5b1bdSJerónimo Borque ucontrol->value.integer.value[0] || 7085cd5b1bdSJerónimo Borque ucontrol->value.integer.value[1]); 7095cd5b1bdSJerónimo Borque } 7105cd5b1bdSJerónimo Borque 7115cd5b1bdSJerónimo Borque 7125cd5b1bdSJerónimo Borque static void cxt_fixup_mute_led_gpio(struct hda_codec *codec, 7135cd5b1bdSJerónimo Borque const struct hda_fixup *fix, int action) 7145cd5b1bdSJerónimo Borque { 7155cd5b1bdSJerónimo Borque struct conexant_spec *spec = codec->spec; 7165cd5b1bdSJerónimo Borque static const struct hda_verb gpio_init[] = { 7175cd5b1bdSJerónimo Borque { 0x01, AC_VERB_SET_GPIO_MASK, 0x03 }, 7185cd5b1bdSJerónimo Borque { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03 }, 7195cd5b1bdSJerónimo Borque {} 7205cd5b1bdSJerónimo Borque }; 7215cd5b1bdSJerónimo Borque codec_info(codec, "action: %d gpio_led: %d\n", action, spec->gpio_led); 7225cd5b1bdSJerónimo Borque 7235cd5b1bdSJerónimo Borque if (action == HDA_FIXUP_ACT_PRE_PROBE) { 7245cd5b1bdSJerónimo Borque spec->gen.vmaster_mute.hook = cxt_fixup_gpio_mute_hook; 7255cd5b1bdSJerónimo Borque spec->gen.cap_sync_hook = cxt_fixup_gpio_mic_mute_hook; 7265cd5b1bdSJerónimo Borque spec->gpio_led = 0; 7275cd5b1bdSJerónimo Borque spec->mute_led_polarity = 0; 7285cd5b1bdSJerónimo Borque spec->gpio_mute_led_mask = 0x01; 7295cd5b1bdSJerónimo Borque spec->gpio_mic_led_mask = 0x02; 7305cd5b1bdSJerónimo Borque } 7315cd5b1bdSJerónimo Borque snd_hda_add_verbs(codec, gpio_init); 7325cd5b1bdSJerónimo Borque if (spec->gpio_led) 7335cd5b1bdSJerónimo Borque snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 7345cd5b1bdSJerónimo Borque spec->gpio_led); 7355cd5b1bdSJerónimo Borque } 7365cd5b1bdSJerónimo Borque 7375cd5b1bdSJerónimo Borque 738d70f3632STakashi Iwai /* ThinkPad X200 & co with cxt5051 */ 73923d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 740e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 741e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 742e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 7433e93f5efSTakashi Iwai { 0x1c, 0x21440100 }, /* dock SPDIF out */ 744e92d4b08STakashi Iwai {} 745e92d4b08STakashi Iwai }; 746e92d4b08STakashi Iwai 747d70f3632STakashi Iwai /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 74823d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { 749d70f3632STakashi Iwai { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 750d70f3632STakashi Iwai { 0x1a, 0x21a190f0 }, /* dock-mic */ 751d70f3632STakashi Iwai { 0x1c, 0x212140ff }, /* dock-HP */ 752d70f3632STakashi Iwai {} 753e92d4b08STakashi Iwai }; 754e92d4b08STakashi Iwai 755239fb862SHuacai Chen /* Lemote A1004/A1205 with cxt5066 */ 756239fb862SHuacai Chen static const struct hda_pintbl cxt_pincfg_lemote[] = { 757239fb862SHuacai Chen { 0x1a, 0x90a10020 }, /* Internal mic */ 758239fb862SHuacai Chen { 0x1b, 0x03a11020 }, /* External mic */ 759239fb862SHuacai Chen { 0x1d, 0x400101f0 }, /* Not used */ 760239fb862SHuacai Chen { 0x1e, 0x40a701f0 }, /* Not used */ 761239fb862SHuacai Chen { 0x20, 0x404501f0 }, /* Not used */ 762239fb862SHuacai Chen { 0x22, 0x404401f0 }, /* Not used */ 763239fb862SHuacai Chen { 0x23, 0x40a701f0 }, /* Not used */ 764239fb862SHuacai Chen {} 765239fb862SHuacai Chen }; 766239fb862SHuacai Chen 76723d30f28STakashi Iwai static const struct hda_fixup cxt_fixups[] = { 76823d30f28STakashi Iwai [CXT_PINCFG_LENOVO_X200] = { 76923d30f28STakashi Iwai .type = HDA_FIXUP_PINS, 77023d30f28STakashi Iwai .v.pins = cxt_pincfg_lenovo_x200, 77123d30f28STakashi Iwai }, 77223d30f28STakashi Iwai [CXT_PINCFG_LENOVO_TP410] = { 77323d30f28STakashi Iwai .type = HDA_FIXUP_PINS, 77423d30f28STakashi Iwai .v.pins = cxt_pincfg_lenovo_tp410, 77508cf680cSDavid Henningsson .chained = true, 77608cf680cSDavid Henningsson .chain_id = CXT_FIXUP_THINKPAD_ACPI, 77723d30f28STakashi Iwai }, 778239fb862SHuacai Chen [CXT_PINCFG_LEMOTE_A1004] = { 779239fb862SHuacai Chen .type = HDA_FIXUP_PINS, 780239fb862SHuacai Chen .chained = true, 781239fb862SHuacai Chen .chain_id = CXT_FIXUP_INC_MIC_BOOST, 782239fb862SHuacai Chen .v.pins = cxt_pincfg_lemote, 783239fb862SHuacai Chen }, 784239fb862SHuacai Chen [CXT_PINCFG_LEMOTE_A1205] = { 785239fb862SHuacai Chen .type = HDA_FIXUP_PINS, 786239fb862SHuacai Chen .v.pins = cxt_pincfg_lemote, 787239fb862SHuacai Chen }, 788ddb6ca75STakashi Iwai [CXT_PINCFG_COMPAQ_CQ60] = { 789ddb6ca75STakashi Iwai .type = HDA_FIXUP_PINS, 790ddb6ca75STakashi Iwai .v.pins = (const struct hda_pintbl[]) { 791ddb6ca75STakashi Iwai /* 0x17 was falsely set up as a mic, it should 0x1d */ 792ddb6ca75STakashi Iwai { 0x17, 0x400001f0 }, 793ddb6ca75STakashi Iwai { 0x1d, 0x97a70120 }, 794ddb6ca75STakashi Iwai { } 795ddb6ca75STakashi Iwai } 796ddb6ca75STakashi Iwai }, 79723d30f28STakashi Iwai [CXT_FIXUP_STEREO_DMIC] = { 79823d30f28STakashi Iwai .type = HDA_FIXUP_FUNC, 79923d30f28STakashi Iwai .v.func = cxt_fixup_stereo_dmic, 80023d30f28STakashi Iwai }, 801239fb862SHuacai Chen [CXT_FIXUP_INC_MIC_BOOST] = { 802239fb862SHuacai Chen .type = HDA_FIXUP_FUNC, 803239fb862SHuacai Chen .v.func = cxt5066_increase_mic_boost, 804239fb862SHuacai Chen }, 805e4c3bce2SDavid Henningsson [CXT_FIXUP_HEADPHONE_MIC_PIN] = { 806e4c3bce2SDavid Henningsson .type = HDA_FIXUP_PINS, 807e4c3bce2SDavid Henningsson .chained = true, 808e4c3bce2SDavid Henningsson .chain_id = CXT_FIXUP_HEADPHONE_MIC, 809e4c3bce2SDavid Henningsson .v.pins = (const struct hda_pintbl[]) { 810e4c3bce2SDavid Henningsson { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */ 811e4c3bce2SDavid Henningsson { } 812e4c3bce2SDavid Henningsson } 813e4c3bce2SDavid Henningsson }, 814e4c3bce2SDavid Henningsson [CXT_FIXUP_HEADPHONE_MIC] = { 815e4c3bce2SDavid Henningsson .type = HDA_FIXUP_FUNC, 816e4c3bce2SDavid Henningsson .v.func = cxt_fixup_headphone_mic, 817e4c3bce2SDavid Henningsson }, 8184a437044STakashi Iwai [CXT_FIXUP_GPIO1] = { 8194a437044STakashi Iwai .type = HDA_FIXUP_VERBS, 8204a437044STakashi Iwai .v.verbs = (const struct hda_verb[]) { 8214a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 }, 8224a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 }, 8234a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 }, 8244a437044STakashi Iwai { } 8254a437044STakashi Iwai }, 8264a437044STakashi Iwai }, 827ff50479aSTakashi Iwai [CXT_FIXUP_ASPIRE_DMIC] = { 828ff50479aSTakashi Iwai .type = HDA_FIXUP_FUNC, 829ff50479aSTakashi Iwai .v.func = cxt_fixup_stereo_dmic, 830ff50479aSTakashi Iwai .chained = true, 831ff50479aSTakashi Iwai .chain_id = CXT_FIXUP_GPIO1, 832ff50479aSTakashi Iwai }, 83308cf680cSDavid Henningsson [CXT_FIXUP_THINKPAD_ACPI] = { 83408cf680cSDavid Henningsson .type = HDA_FIXUP_FUNC, 835b317b032STakashi Iwai .v.func = hda_fixup_thinkpad_acpi, 83608cf680cSDavid Henningsson }, 8373a00c660STakashi Iwai [CXT_FIXUP_OLPC_XO] = { 8383a00c660STakashi Iwai .type = HDA_FIXUP_FUNC, 8393a00c660STakashi Iwai .v.func = cxt_fixup_olpc_xo, 8403a00c660STakashi Iwai }, 841ad7725d3STakashi Iwai [CXT_FIXUP_CAP_MIX_AMP] = { 842ad7725d3STakashi Iwai .type = HDA_FIXUP_FUNC, 843ad7725d3STakashi Iwai .v.func = cxt_fixup_cap_mix_amp, 844ad7725d3STakashi Iwai }, 8456dcbadefSTakashi Iwai [CXT_FIXUP_TOSHIBA_P105] = { 8466dcbadefSTakashi Iwai .type = HDA_FIXUP_PINS, 8476dcbadefSTakashi Iwai .v.pins = (const struct hda_pintbl[]) { 8486dcbadefSTakashi Iwai { 0x10, 0x961701f0 }, /* speaker/hp */ 8496dcbadefSTakashi Iwai { 0x12, 0x02a1901e }, /* ext mic */ 8506dcbadefSTakashi Iwai { 0x14, 0x95a70110 }, /* int mic */ 8516dcbadefSTakashi Iwai {} 8526dcbadefSTakashi Iwai }, 8536dcbadefSTakashi Iwai }, 854e5eac90dSTakashi Iwai [CXT_FIXUP_HP_530] = { 855e5eac90dSTakashi Iwai .type = HDA_FIXUP_PINS, 856e5eac90dSTakashi Iwai .v.pins = (const struct hda_pintbl[]) { 857e5eac90dSTakashi Iwai { 0x12, 0x90a60160 }, /* int mic */ 858e5eac90dSTakashi Iwai {} 859e5eac90dSTakashi Iwai }, 860e5eac90dSTakashi Iwai .chained = true, 861e5eac90dSTakashi Iwai .chain_id = CXT_FIXUP_CAP_MIX_AMP, 862e5eac90dSTakashi Iwai }, 863ea30e7dfSTakashi Iwai [CXT_FIXUP_CAP_MIX_AMP_5047] = { 864ea30e7dfSTakashi Iwai .type = HDA_FIXUP_FUNC, 865ea30e7dfSTakashi Iwai .v.func = cxt_fixup_cap_mix_amp_5047, 866ea30e7dfSTakashi Iwai }, 8673542aed7STakashi Iwai [CXT_FIXUP_MUTE_LED_EAPD] = { 8683542aed7STakashi Iwai .type = HDA_FIXUP_FUNC, 8693542aed7STakashi Iwai .v.func = cxt_fixup_mute_led_eapd, 8703542aed7STakashi Iwai }, 871cc3a47a2SJaroslav Kysela [CXT_FIXUP_HP_DOCK] = { 872cc3a47a2SJaroslav Kysela .type = HDA_FIXUP_PINS, 873cc3a47a2SJaroslav Kysela .v.pins = (const struct hda_pintbl[]) { 874cc3a47a2SJaroslav Kysela { 0x16, 0x21011020 }, /* line-out */ 875cc3a47a2SJaroslav Kysela { 0x18, 0x2181103f }, /* line-in */ 876cc3a47a2SJaroslav Kysela { } 877c3123d6aSFlorin Tudorache }, 878c3123d6aSFlorin Tudorache .chained = true, 879c3123d6aSFlorin Tudorache .chain_id = CXT_FIXUP_MUTE_LED_GPIO, 880cc3a47a2SJaroslav Kysela }, 8810eec8809STakashi Iwai [CXT_FIXUP_HP_SPECTRE] = { 8820eec8809STakashi Iwai .type = HDA_FIXUP_PINS, 8830eec8809STakashi Iwai .v.pins = (const struct hda_pintbl[]) { 8840eec8809STakashi Iwai /* enable NID 0x1d for the speaker on top */ 8850eec8809STakashi Iwai { 0x1d, 0x91170111 }, 8860eec8809STakashi Iwai { } 8870eec8809STakashi Iwai } 8880eec8809STakashi Iwai }, 889f73cd43aSTakashi Iwai [CXT_FIXUP_HP_GATE_MIC] = { 890f73cd43aSTakashi Iwai .type = HDA_FIXUP_FUNC, 891f73cd43aSTakashi Iwai .v.func = cxt_fixup_hp_gate_mic_jack, 892f73cd43aSTakashi Iwai }, 8935cd5b1bdSJerónimo Borque [CXT_FIXUP_MUTE_LED_GPIO] = { 8945cd5b1bdSJerónimo Borque .type = HDA_FIXUP_FUNC, 8955cd5b1bdSJerónimo Borque .v.func = cxt_fixup_mute_led_gpio, 8965cd5b1bdSJerónimo Borque }, 897*322f74edSHui Wang [CXT_FIXUP_HEADSET_MIC] = { 898*322f74edSHui Wang .type = HDA_FIXUP_FUNC, 899*322f74edSHui Wang .v.func = cxt_fixup_headset_mic, 900*322f74edSHui Wang }, 901*322f74edSHui Wang [CXT_FIXUP_HP_MIC_NO_PRESENCE] = { 902*322f74edSHui Wang .type = HDA_FIXUP_PINS, 903*322f74edSHui Wang .v.pins = (const struct hda_pintbl[]) { 904*322f74edSHui Wang { 0x1a, 0x02a1113c }, 905*322f74edSHui Wang { } 906*322f74edSHui Wang }, 907*322f74edSHui Wang .chained = true, 908*322f74edSHui Wang .chain_id = CXT_FIXUP_HEADSET_MIC, 909*322f74edSHui Wang }, 910ad7725d3STakashi Iwai }; 911ad7725d3STakashi Iwai 912ad7725d3STakashi Iwai static const struct snd_pci_quirk cxt5045_fixups[] = { 913e5eac90dSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530), 9146dcbadefSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105), 915ad7725d3STakashi Iwai /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 916ad7725d3STakashi Iwai * really bad sound over 0dB on NID 0x17. 917ad7725d3STakashi Iwai */ 918ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP), 919ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP), 920ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP), 921ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP), 922ad7725d3STakashi Iwai {} 923ad7725d3STakashi Iwai }; 924ad7725d3STakashi Iwai 925ad7725d3STakashi Iwai static const struct hda_model_fixup cxt5045_fixup_models[] = { 926ad7725d3STakashi Iwai { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" }, 9276dcbadefSTakashi Iwai { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" }, 928e5eac90dSTakashi Iwai { .id = CXT_FIXUP_HP_530, .name = "hp-530" }, 929ad7725d3STakashi Iwai {} 930e92d4b08STakashi Iwai }; 931e92d4b08STakashi Iwai 932ea30e7dfSTakashi Iwai static const struct snd_pci_quirk cxt5047_fixups[] = { 933ea30e7dfSTakashi Iwai /* HP laptops have really bad sound over 0 dB on NID 0x10. 934ea30e7dfSTakashi Iwai */ 935ea30e7dfSTakashi Iwai SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047), 936ea30e7dfSTakashi Iwai {} 937ea30e7dfSTakashi Iwai }; 938ea30e7dfSTakashi Iwai 939ea30e7dfSTakashi Iwai static const struct hda_model_fixup cxt5047_fixup_models[] = { 940ea30e7dfSTakashi Iwai { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" }, 941ea30e7dfSTakashi Iwai {} 942ea30e7dfSTakashi Iwai }; 943ea30e7dfSTakashi Iwai 944d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = { 945ddb6ca75STakashi Iwai SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60), 946e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 947e92d4b08STakashi Iwai {} 948e92d4b08STakashi Iwai }; 949e92d4b08STakashi Iwai 950a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5051_fixup_models[] = { 951a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" }, 952a2dd933dSTakashi Iwai {} 953a2dd933dSTakashi Iwai }; 954a2dd933dSTakashi Iwai 955d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = { 95663a077e2STakashi Iwai SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 957ff50479aSTakashi Iwai SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC), 958522a7fa8SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC), 959cc3a47a2SJaroslav Kysela SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK), 9600eec8809STakashi Iwai SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE), 961f73cd43aSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC), 9625cd5b1bdSJerónimo Borque SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO), 963ba92b114SKai-Heng Feng SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO), 964*322f74edSHui Wang SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE), 965*322f74edSHui Wang SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE), 966e4c3bce2SDavid Henningsson SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 9673a00c660STakashi Iwai SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO), 968d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 969d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 970d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 971d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 972d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 973a555bb8cSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410), 97488d57606SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410), 9753542aed7STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD), 976e8d65a8dSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC), 97718dcd304SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 978e4db0952SFelix Kaechele SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), 979bbba6f9dSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC), 980b3c5dce8SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), 9812fd3f170SHui Wang SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI), 982239fb862SHuacai Chen SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004), 983239fb862SHuacai Chen SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205), 984f2e5731dSTakashi Iwai {} 985f2e5731dSTakashi Iwai }; 986f2e5731dSTakashi Iwai 987a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5066_fixup_models[] = { 988a2dd933dSTakashi Iwai { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" }, 989a2dd933dSTakashi Iwai { .id = CXT_FIXUP_GPIO1, .name = "gpio1" }, 990a2dd933dSTakashi Iwai { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" }, 991a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" }, 992a2dd933dSTakashi Iwai { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" }, 993a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" }, 9948245b363SHuacai Chen { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" }, 9953a00c660STakashi Iwai { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" }, 9963542aed7STakashi Iwai { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" }, 997cc3a47a2SJaroslav Kysela { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" }, 9985cd5b1bdSJerónimo Borque { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" }, 999a2dd933dSTakashi Iwai {} 1000a2dd933dSTakashi Iwai }; 1001a2dd933dSTakashi Iwai 10023868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 10033868137eSTakashi Iwai * can be created (bko#42825) 10043868137eSTakashi Iwai */ 10053868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec) 10063868137eSTakashi Iwai { 1007d89c6c0cSTakashi Iwai struct conexant_spec *spec = codec->spec; 10083868137eSTakashi Iwai static hda_nid_t out_nids[] = { 10093868137eSTakashi Iwai 0x10, 0x11, 0 10103868137eSTakashi Iwai }; 10113868137eSTakashi Iwai hda_nid_t *p; 10123868137eSTakashi Iwai 10133868137eSTakashi Iwai for (p = out_nids; *p; p++) 10143868137eSTakashi Iwai snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 10153868137eSTakashi Iwai AC_AMPCAP_MIN_MUTE | 10163868137eSTakashi Iwai query_amp_caps(codec, *p, HDA_OUTPUT)); 1017d89c6c0cSTakashi Iwai spec->gen.dac_min_mute = true; 10183868137eSTakashi Iwai } 10193868137eSTakashi Iwai 1020f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 1021f2e5731dSTakashi Iwai { 1022f2e5731dSTakashi Iwai struct conexant_spec *spec; 1023f2e5731dSTakashi Iwai int err; 1024f2e5731dSTakashi Iwai 10257639a06cSTakashi Iwai codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name); 10261f8458a2STakashi Iwai 1027f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1028f2e5731dSTakashi Iwai if (!spec) 1029f2e5731dSTakashi Iwai return -ENOMEM; 1030aed523f1STakashi Iwai snd_hda_gen_spec_init(&spec->gen); 1031f2e5731dSTakashi Iwai codec->spec = spec; 1032225068abSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 1033e92d4b08STakashi Iwai 1034aed523f1STakashi Iwai cx_auto_parse_beep(codec); 1035aed523f1STakashi Iwai cx_auto_parse_eapd(codec); 1036ff359b14STakashi Iwai spec->gen.own_eapd_ctl = 1; 1037ff359b14STakashi Iwai if (spec->dynamic_eapd) 1038aed523f1STakashi Iwai spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; 1039e92d4b08STakashi Iwai 10407639a06cSTakashi Iwai switch (codec->core.vendor_id) { 10416b452142STakashi Iwai case 0x14f15045: 10424f32456eSMichael Karcher codec->single_adc_amp = 1; 104370540e24STakashi Iwai spec->gen.mixer_nid = 0x17; 104474f14b36STakashi Iwai spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 1045ad7725d3STakashi Iwai snd_hda_pick_fixup(codec, cxt5045_fixup_models, 1046ad7725d3STakashi Iwai cxt5045_fixups, cxt_fixups); 10476b452142STakashi Iwai break; 1048164a7adaSTakashi Iwai case 0x14f15047: 1049164a7adaSTakashi Iwai codec->pin_amp_workaround = 1; 1050164a7adaSTakashi Iwai spec->gen.mixer_nid = 0x19; 105174f14b36STakashi Iwai spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 1052ea30e7dfSTakashi Iwai snd_hda_pick_fixup(codec, cxt5047_fixup_models, 1053ea30e7dfSTakashi Iwai cxt5047_fixups, cxt_fixups); 1054164a7adaSTakashi Iwai break; 10553868137eSTakashi Iwai case 0x14f15051: 10563868137eSTakashi Iwai add_cx5051_fake_mutes(codec); 105751969d62SMichael Karcher codec->pin_amp_workaround = 1; 1058a2dd933dSTakashi Iwai snd_hda_pick_fixup(codec, cxt5051_fixup_models, 1059a2dd933dSTakashi Iwai cxt5051_fixups, cxt_fixups); 10603868137eSTakashi Iwai break; 1061b03d61d6SDavid Henningsson case 0x14f150f2: 1062b03d61d6SDavid Henningsson codec->power_save_node = 1; 1063b03d61d6SDavid Henningsson /* Fall through */ 106451969d62SMichael Karcher default: 106551969d62SMichael Karcher codec->pin_amp_workaround = 1; 1066a2dd933dSTakashi Iwai snd_hda_pick_fixup(codec, cxt5066_fixup_models, 1067a2dd933dSTakashi Iwai cxt5066_fixups, cxt_fixups); 106823d30f28STakashi Iwai break; 10696b452142STakashi Iwai } 10706b452142STakashi Iwai 1071f29735cbSTakashi Iwai /* Show mute-led control only on HP laptops 1072f29735cbSTakashi Iwai * This is a sort of white-list: on HP laptops, EAPD corresponds 1073f29735cbSTakashi Iwai * only to the mute-LED without actualy amp function. Meanwhile, 1074f29735cbSTakashi Iwai * others may use EAPD really as an amp switch, so it might be 1075f29735cbSTakashi Iwai * not good to expose it blindly. 1076527c73baSTakashi Iwai */ 10777639a06cSTakashi Iwai switch (codec->core.subsystem_id >> 16) { 1078f29735cbSTakashi Iwai case 0x103c: 1079aed523f1STakashi Iwai spec->gen.vmaster_mute_enum = 1; 1080f29735cbSTakashi Iwai break; 1081f29735cbSTakashi Iwai } 1082527c73baSTakashi Iwai 1083aed523f1STakashi Iwai snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 1084aed523f1STakashi Iwai 1085e4c3bce2SDavid Henningsson err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 1086e4c3bce2SDavid Henningsson spec->parse_flags); 108722ce5f74STakashi Iwai if (err < 0) 1088aed523f1STakashi Iwai goto error; 1089aed523f1STakashi Iwai 1090aed523f1STakashi Iwai err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); 1091aed523f1STakashi Iwai if (err < 0) 1092aed523f1STakashi Iwai goto error; 1093aed523f1STakashi Iwai 10944f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 10954f2864a4STakashi Iwai * which falls into the single-cmd mode. 10964f2864a4STakashi Iwai * Better to make reset, then. 10974f2864a4STakashi Iwai */ 1098d068ebc2STakashi Iwai if (!codec->bus->core.sync_write) { 10994e76a883STakashi Iwai codec_info(codec, 11004f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 1101d068ebc2STakashi Iwai codec->bus->core.sync_write = 1; 11024f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 11034f2864a4STakashi Iwai } 11044f2864a4STakashi Iwai 1105e4c3bce2SDavid Henningsson snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 1106e4c3bce2SDavid Henningsson 1107f2e5731dSTakashi Iwai return 0; 1108aed523f1STakashi Iwai 1109aed523f1STakashi Iwai error: 111008cf680cSDavid Henningsson cx_auto_free(codec); 1111aed523f1STakashi Iwai return err; 1112f2e5731dSTakashi Iwai } 1113f2e5731dSTakashi Iwai 1114f2e5731dSTakashi Iwai /* 1115461e2c78STakashi Iwai */ 1116461e2c78STakashi Iwai 1117b9a94a9cSTakashi Iwai static const struct hda_device_id snd_hda_id_conexant[] = { 1118bcdda2ecSTakashi Iwai HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto), 1119b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto), 1120b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto), 1121b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15051, "CX20561 (Hermosa)", patch_conexant_auto), 1122b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15066, "CX20582 (Pebble)", patch_conexant_auto), 1123b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15067, "CX20583 (Pebble HSF)", patch_conexant_auto), 1124b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15068, "CX20584", patch_conexant_auto), 1125b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15069, "CX20585", patch_conexant_auto), 1126b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f1506c, "CX20588", patch_conexant_auto), 1127b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f1506e, "CX20590", patch_conexant_auto), 1128b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15097, "CX20631", patch_conexant_auto), 1129b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15098, "CX20632", patch_conexant_auto), 1130b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150a1, "CX20641", patch_conexant_auto), 1131b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150a2, "CX20642", patch_conexant_auto), 1132b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150ab, "CX20651", patch_conexant_auto), 1133b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150ac, "CX20652", patch_conexant_auto), 1134b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150b8, "CX20664", patch_conexant_auto), 1135b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150b9, "CX20665", patch_conexant_auto), 11363b7e2a7dSTakashi Iwai HDA_CODEC_ENTRY(0x14f150f1, "CX21722", patch_conexant_auto), 1137b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150f2, "CX20722", patch_conexant_auto), 11383b7e2a7dSTakashi Iwai HDA_CODEC_ENTRY(0x14f150f3, "CX21724", patch_conexant_auto), 1139b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f150f4, "CX20724", patch_conexant_auto), 1140b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f1510f, "CX20751/2", patch_conexant_auto), 1141b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15110, "CX20751/2", patch_conexant_auto), 1142b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15111, "CX20753/4", patch_conexant_auto), 1143b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15113, "CX20755", patch_conexant_auto), 1144b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15114, "CX20756", patch_conexant_auto), 1145b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f15115, "CX20757", patch_conexant_auto), 1146b9a94a9cSTakashi Iwai HDA_CODEC_ENTRY(0x14f151d7, "CX20952", patch_conexant_auto), 1147c9b443d4STobin Davis {} /* terminator */ 1148c9b443d4STobin Davis }; 1149b9a94a9cSTakashi Iwai MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant); 11501289e9e8STakashi Iwai 11511289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 11521289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 11531289e9e8STakashi Iwai 1154d8a766a1STakashi Iwai static struct hda_codec_driver conexant_driver = { 1155b9a94a9cSTakashi Iwai .id = snd_hda_id_conexant, 11561289e9e8STakashi Iwai }; 11571289e9e8STakashi Iwai 1158d8a766a1STakashi Iwai module_hda_codec_driver(conexant_driver); 1159