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; 46bf92d1d5STakashi Iwai 47e4c3bce2SDavid Henningsson unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ 48e4c3bce2SDavid Henningsson 493a00c660STakashi Iwai /* OPLC XO specific */ 503a00c660STakashi Iwai bool recording; 513a00c660STakashi Iwai bool dc_enable; 523a00c660STakashi Iwai unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */ 533a00c660STakashi Iwai struct nid_path *dc_mode_path; 54c9b443d4STobin Davis }; 55c9b443d4STobin Davis 56bf92d1d5STakashi Iwai 57bf92d1d5STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 587504b6cdSTakashi Iwai static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid, 597504b6cdSTakashi Iwai int idx, int dir) 607504b6cdSTakashi Iwai { 617504b6cdSTakashi Iwai spec->gen.beep_nid = nid; 627504b6cdSTakashi Iwai spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); 637504b6cdSTakashi Iwai } 64bf92d1d5STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 65bf92d1d5STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 66bf92d1d5STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 67bf92d1d5STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 68bf92d1d5STakashi Iwai { } /* end */ 69bf92d1d5STakashi Iwai }; 70bf92d1d5STakashi Iwai 71bf92d1d5STakashi Iwai /* create beep controls if needed */ 72bf92d1d5STakashi Iwai static int add_beep_ctls(struct hda_codec *codec) 73bf92d1d5STakashi Iwai { 74bf92d1d5STakashi Iwai struct conexant_spec *spec = codec->spec; 75bf92d1d5STakashi Iwai int err; 76bf92d1d5STakashi Iwai 77bf92d1d5STakashi Iwai if (spec->beep_amp) { 78bf92d1d5STakashi Iwai const struct snd_kcontrol_new *knew; 79bf92d1d5STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 80bf92d1d5STakashi Iwai struct snd_kcontrol *kctl; 81bf92d1d5STakashi Iwai kctl = snd_ctl_new1(knew, codec); 82bf92d1d5STakashi Iwai if (!kctl) 83bf92d1d5STakashi Iwai return -ENOMEM; 84bf92d1d5STakashi Iwai kctl->private_value = spec->beep_amp; 85bf92d1d5STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 86bf92d1d5STakashi Iwai if (err < 0) 87bf92d1d5STakashi Iwai return err; 88bf92d1d5STakashi Iwai } 89bf92d1d5STakashi Iwai } 90bf92d1d5STakashi Iwai return 0; 91bf92d1d5STakashi Iwai } 92bf92d1d5STakashi Iwai #else 93bf92d1d5STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 94bf92d1d5STakashi Iwai #define add_beep_ctls(codec) 0 95bf92d1d5STakashi Iwai #endif 96bf92d1d5STakashi Iwai 97461e2c78STakashi Iwai /* 98f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 99f2e5731dSTakashi Iwai */ 100f2e5731dSTakashi Iwai 101f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 102f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 103f2e5731dSTakashi Iwai { 104f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 105f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 106f2e5731dSTakashi Iwai 107f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 108f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 109f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 110f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 111f2e5731dSTakashi Iwai break; 112f2e5731dSTakashi Iwai } 113f2e5731dSTakashi Iwai } 114f2e5731dSTakashi Iwai #else 115f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 116f2e5731dSTakashi Iwai #endif 117f2e5731dSTakashi Iwai 118254f2968STakashi Iwai /* parse EAPDs */ 11919110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 12019110595STakashi Iwai { 12119110595STakashi Iwai struct conexant_spec *spec = codec->spec; 12219110595STakashi Iwai hda_nid_t nid, end_nid; 12319110595STakashi Iwai 12419110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 12519110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 12619110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 12719110595STakashi Iwai continue; 12819110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 12919110595STakashi Iwai continue; 13019110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 13119110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 13219110595STakashi Iwai break; 13319110595STakashi Iwai } 134254f2968STakashi Iwai 135254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 136254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 137254f2968STakashi Iwai * pins, and we can control EAPD per pin. 138254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 139254f2968STakashi Iwai * thus it might control over all pins. 140254f2968STakashi Iwai */ 141aed523f1STakashi Iwai if (spec->num_eapds > 2) 142ff359b14STakashi Iwai spec->dynamic_eapd = 1; 143f2e5731dSTakashi Iwai } 144f2e5731dSTakashi Iwai 145da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 146da339866STakashi Iwai hda_nid_t *pins, bool on) 147f2e5731dSTakashi Iwai { 148f2e5731dSTakashi Iwai int i; 149f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 150f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 151f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 152da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 153da339866STakashi Iwai on ? 0x02 : 0); 154f2e5731dSTakashi Iwai } 155f2e5731dSTakashi Iwai } 156f2e5731dSTakashi Iwai 157527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */ 158527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled) 159527c73baSTakashi Iwai { 160527c73baSTakashi Iwai struct hda_codec *codec = private_data; 161527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 162527c73baSTakashi Iwai 163527c73baSTakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 164527c73baSTakashi Iwai } 165527c73baSTakashi Iwai 166f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 167f2e5731dSTakashi Iwai { 168f2e5731dSTakashi Iwai int err; 169f2e5731dSTakashi Iwai 170aed523f1STakashi Iwai err = snd_hda_gen_build_controls(codec); 171f2e5731dSTakashi Iwai if (err < 0) 172f2e5731dSTakashi Iwai return err; 173f2e5731dSTakashi Iwai 174aed523f1STakashi Iwai err = add_beep_ctls(codec); 175aed523f1STakashi Iwai if (err < 0) 176aed523f1STakashi Iwai return err; 17722ce5f74STakashi Iwai 17822ce5f74STakashi Iwai return 0; 17922ce5f74STakashi Iwai } 18022ce5f74STakashi Iwai 181ff359b14STakashi Iwai static int cx_auto_init(struct hda_codec *codec) 182ff359b14STakashi Iwai { 183ff359b14STakashi Iwai struct conexant_spec *spec = codec->spec; 184ff359b14STakashi Iwai snd_hda_gen_init(codec); 185ff359b14STakashi Iwai if (!spec->dynamic_eapd) 186ff359b14STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 187e4c3bce2SDavid Henningsson 188e4c3bce2SDavid Henningsson snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT); 189e4c3bce2SDavid Henningsson 190ff359b14STakashi Iwai return 0; 191ff359b14STakashi Iwai } 192ff359b14STakashi Iwai 1938a02c0ccSTakashi Iwai #define cx_auto_free snd_hda_gen_free 19408cf680cSDavid Henningsson 19534cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 196f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 197aed523f1STakashi Iwai .build_pcms = snd_hda_gen_build_pcms, 198ff359b14STakashi Iwai .init = cx_auto_init, 19908cf680cSDavid Henningsson .free = cx_auto_free, 20029adc4b9SDavid Henningsson .unsol_event = snd_hda_jack_unsol_event, 201164a7adaSTakashi Iwai #ifdef CONFIG_PM 202164a7adaSTakashi Iwai .check_power_status = snd_hda_gen_check_power_status, 203164a7adaSTakashi Iwai #endif 204f2e5731dSTakashi Iwai }; 205f2e5731dSTakashi Iwai 206e92d4b08STakashi Iwai /* 207e92d4b08STakashi Iwai * pin fix-up 208e92d4b08STakashi Iwai */ 20918dcd304SDavid Henningsson enum { 21018dcd304SDavid Henningsson CXT_PINCFG_LENOVO_X200, 211d3980110STakashi Iwai CXT_PINCFG_LENOVO_TP410, 212239fb862SHuacai Chen CXT_PINCFG_LEMOTE_A1004, 213239fb862SHuacai Chen CXT_PINCFG_LEMOTE_A1205, 21418dcd304SDavid Henningsson CXT_FIXUP_STEREO_DMIC, 215239fb862SHuacai Chen CXT_FIXUP_INC_MIC_BOOST, 216e4c3bce2SDavid Henningsson CXT_FIXUP_HEADPHONE_MIC_PIN, 217e4c3bce2SDavid Henningsson CXT_FIXUP_HEADPHONE_MIC, 2184a437044STakashi Iwai CXT_FIXUP_GPIO1, 21908cf680cSDavid Henningsson CXT_FIXUP_THINKPAD_ACPI, 2203a00c660STakashi Iwai CXT_FIXUP_OLPC_XO, 221ad7725d3STakashi Iwai CXT_FIXUP_CAP_MIX_AMP, 2226dcbadefSTakashi Iwai CXT_FIXUP_TOSHIBA_P105, 223e5eac90dSTakashi Iwai CXT_FIXUP_HP_530, 224ea30e7dfSTakashi Iwai CXT_FIXUP_CAP_MIX_AMP_5047, 22518dcd304SDavid Henningsson }; 22618dcd304SDavid Henningsson 227b317b032STakashi Iwai /* for hda_fixup_thinkpad_acpi() */ 228b317b032STakashi Iwai #include "thinkpad_helper.c" 22908cf680cSDavid Henningsson 23023d30f28STakashi Iwai static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 23123d30f28STakashi Iwai const struct hda_fixup *fix, int action) 232e92d4b08STakashi Iwai { 23318dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 234aed523f1STakashi Iwai spec->gen.inv_dmic_split = 1; 235e92d4b08STakashi Iwai } 236e92d4b08STakashi Iwai 237239fb862SHuacai Chen static void cxt5066_increase_mic_boost(struct hda_codec *codec, 238239fb862SHuacai Chen const struct hda_fixup *fix, int action) 239239fb862SHuacai Chen { 240239fb862SHuacai Chen if (action != HDA_FIXUP_ACT_PRE_PROBE) 241239fb862SHuacai Chen return; 242239fb862SHuacai Chen 243239fb862SHuacai Chen snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT, 244239fb862SHuacai Chen (0x3 << AC_AMPCAP_OFFSET_SHIFT) | 245239fb862SHuacai Chen (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) | 246239fb862SHuacai Chen (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | 247239fb862SHuacai Chen (0 << AC_AMPCAP_MUTE_SHIFT)); 248239fb862SHuacai Chen } 249239fb862SHuacai Chen 250e4c3bce2SDavid Henningsson static void cxt_update_headset_mode(struct hda_codec *codec) 251e4c3bce2SDavid Henningsson { 252e4c3bce2SDavid Henningsson /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */ 253e4c3bce2SDavid Henningsson int i; 254e4c3bce2SDavid Henningsson bool mic_mode = false; 255e4c3bce2SDavid Henningsson struct conexant_spec *spec = codec->spec; 256e4c3bce2SDavid Henningsson struct auto_pin_cfg *cfg = &spec->gen.autocfg; 257e4c3bce2SDavid Henningsson 258e4c3bce2SDavid Henningsson hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]]; 259e4c3bce2SDavid Henningsson 260e4c3bce2SDavid Henningsson for (i = 0; i < cfg->num_inputs; i++) 261e4c3bce2SDavid Henningsson if (cfg->inputs[i].pin == mux_pin) { 262e4c3bce2SDavid Henningsson mic_mode = !!cfg->inputs[i].is_headphone_mic; 263e4c3bce2SDavid Henningsson break; 264e4c3bce2SDavid Henningsson } 265e4c3bce2SDavid Henningsson 266e4c3bce2SDavid Henningsson if (mic_mode) { 267e4c3bce2SDavid Henningsson snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */ 268e4c3bce2SDavid Henningsson spec->gen.hp_jack_present = false; 269e4c3bce2SDavid Henningsson } else { 270e4c3bce2SDavid Henningsson snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */ 271e4c3bce2SDavid Henningsson spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]); 272e4c3bce2SDavid Henningsson } 273e4c3bce2SDavid Henningsson 274e4c3bce2SDavid Henningsson snd_hda_gen_update_outputs(codec); 275e4c3bce2SDavid Henningsson } 276e4c3bce2SDavid Henningsson 277e4c3bce2SDavid Henningsson static void cxt_update_headset_mode_hook(struct hda_codec *codec, 2787fe30711STakashi Iwai struct snd_kcontrol *kcontrol, 279e4c3bce2SDavid Henningsson struct snd_ctl_elem_value *ucontrol) 280e4c3bce2SDavid Henningsson { 281e4c3bce2SDavid Henningsson cxt_update_headset_mode(codec); 282e4c3bce2SDavid Henningsson } 283e4c3bce2SDavid Henningsson 284e4c3bce2SDavid Henningsson static void cxt_fixup_headphone_mic(struct hda_codec *codec, 285e4c3bce2SDavid Henningsson const struct hda_fixup *fix, int action) 286e4c3bce2SDavid Henningsson { 287e4c3bce2SDavid Henningsson struct conexant_spec *spec = codec->spec; 288e4c3bce2SDavid Henningsson 289e4c3bce2SDavid Henningsson switch (action) { 290e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_PRE_PROBE: 291e4c3bce2SDavid Henningsson spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; 292e4c3bce2SDavid Henningsson break; 293e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_PROBE: 294e4c3bce2SDavid Henningsson spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; 295e4c3bce2SDavid Henningsson spec->gen.automute_hook = cxt_update_headset_mode; 296e4c3bce2SDavid Henningsson break; 297e4c3bce2SDavid Henningsson case HDA_FIXUP_ACT_INIT: 298e4c3bce2SDavid Henningsson cxt_update_headset_mode(codec); 299e4c3bce2SDavid Henningsson break; 300e4c3bce2SDavid Henningsson } 301e4c3bce2SDavid Henningsson } 302e4c3bce2SDavid Henningsson 3033a00c660STakashi Iwai /* OPLC XO 1.5 fixup */ 3043a00c660STakashi Iwai 3053a00c660STakashi Iwai /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 3063a00c660STakashi Iwai * through the microphone jack. 3073a00c660STakashi Iwai * When the user enables this through a mixer switch, both internal and 3083a00c660STakashi Iwai * external microphones are disabled. Gain is fixed at 0dB. In this mode, 3093a00c660STakashi Iwai * we also allow the bias to be configured through a separate mixer 3103a00c660STakashi Iwai * control. */ 3113a00c660STakashi Iwai 3123a00c660STakashi Iwai #define update_mic_pin(codec, nid, val) \ 3133a00c660STakashi Iwai snd_hda_codec_update_cache(codec, nid, 0, \ 3143a00c660STakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, val) 3153a00c660STakashi Iwai 3163a00c660STakashi Iwai static const struct hda_input_mux olpc_xo_dc_bias = { 3173a00c660STakashi Iwai .num_items = 3, 3183a00c660STakashi Iwai .items = { 3193a00c660STakashi Iwai { "Off", PIN_IN }, 3203a00c660STakashi Iwai { "50%", PIN_VREF50 }, 3213a00c660STakashi Iwai { "80%", PIN_VREF80 }, 3223a00c660STakashi Iwai }, 3233a00c660STakashi Iwai }; 3243a00c660STakashi Iwai 3253a00c660STakashi Iwai static void olpc_xo_update_mic_boost(struct hda_codec *codec) 3263a00c660STakashi Iwai { 3273a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 3283a00c660STakashi Iwai int ch, val; 3293a00c660STakashi Iwai 3303a00c660STakashi Iwai for (ch = 0; ch < 2; ch++) { 3313a00c660STakashi Iwai val = AC_AMP_SET_OUTPUT | 3323a00c660STakashi Iwai (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT); 3333a00c660STakashi Iwai if (!spec->dc_enable) 3343a00c660STakashi Iwai val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0); 3353a00c660STakashi Iwai snd_hda_codec_write(codec, 0x17, 0, 3363a00c660STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 3373a00c660STakashi Iwai } 3383a00c660STakashi Iwai } 3393a00c660STakashi Iwai 3403a00c660STakashi Iwai static void olpc_xo_update_mic_pins(struct hda_codec *codec) 3413a00c660STakashi Iwai { 3423a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 3433a00c660STakashi Iwai int cur_input, val; 3443a00c660STakashi Iwai struct nid_path *path; 3453a00c660STakashi Iwai 3463a00c660STakashi Iwai cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]]; 3473a00c660STakashi Iwai 3483a00c660STakashi Iwai /* Set up mic pins for port-B, C and F dynamically as the recording 3493a00c660STakashi Iwai * LED is turned on/off by these pin controls 3503a00c660STakashi Iwai */ 3513a00c660STakashi Iwai if (!spec->dc_enable) { 3523a00c660STakashi Iwai /* disable DC bias path and pin for port F */ 3533a00c660STakashi Iwai update_mic_pin(codec, 0x1e, 0); 3543a00c660STakashi Iwai snd_hda_activate_path(codec, spec->dc_mode_path, false, false); 3553a00c660STakashi Iwai 3563a00c660STakashi Iwai /* update port B (ext mic) and C (int mic) */ 3573a00c660STakashi Iwai /* OLPC defers mic widget control until when capture is 3583a00c660STakashi Iwai * started because the microphone LED comes on as soon as 3593a00c660STakashi Iwai * these settings are put in place. if we did this before 3603a00c660STakashi Iwai * recording, it would give the false indication that 3613a00c660STakashi Iwai * recording is happening when it is not. 3623a00c660STakashi Iwai */ 3633a00c660STakashi Iwai update_mic_pin(codec, 0x1a, spec->recording ? 3643a00c660STakashi Iwai snd_hda_codec_get_pin_target(codec, 0x1a) : 0); 3653a00c660STakashi Iwai update_mic_pin(codec, 0x1b, spec->recording ? 3663a00c660STakashi Iwai snd_hda_codec_get_pin_target(codec, 0x1b) : 0); 3673a00c660STakashi Iwai /* enable normal mic path */ 3683a00c660STakashi Iwai path = snd_hda_get_path_from_idx(codec, cur_input); 3693a00c660STakashi Iwai if (path) 3703a00c660STakashi Iwai snd_hda_activate_path(codec, path, true, false); 3713a00c660STakashi Iwai } else { 3723a00c660STakashi Iwai /* disable normal mic path */ 3733a00c660STakashi Iwai path = snd_hda_get_path_from_idx(codec, cur_input); 3743a00c660STakashi Iwai if (path) 3753a00c660STakashi Iwai snd_hda_activate_path(codec, path, false, false); 3763a00c660STakashi Iwai 3773a00c660STakashi Iwai /* Even though port F is the DC input, the bias is controlled 3783a00c660STakashi Iwai * on port B. We also leave that port as an active input (but 3793a00c660STakashi Iwai * unselected) in DC mode just in case that is necessary to 3803a00c660STakashi Iwai * make the bias setting take effect. 3813a00c660STakashi Iwai */ 3823a00c660STakashi Iwai if (spec->recording) 3833a00c660STakashi Iwai val = olpc_xo_dc_bias.items[spec->dc_input_bias].index; 3843a00c660STakashi Iwai else 3853a00c660STakashi Iwai val = 0; 3863a00c660STakashi Iwai update_mic_pin(codec, 0x1a, val); 3873a00c660STakashi Iwai update_mic_pin(codec, 0x1b, 0); 3883a00c660STakashi Iwai /* enable DC bias path and pin */ 3893a00c660STakashi Iwai update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0); 3903a00c660STakashi Iwai snd_hda_activate_path(codec, spec->dc_mode_path, true, false); 3913a00c660STakashi Iwai } 3923a00c660STakashi Iwai } 3933a00c660STakashi Iwai 3943a00c660STakashi Iwai /* mic_autoswitch hook */ 3953a00c660STakashi Iwai static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack) 3963a00c660STakashi Iwai { 3973a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 3983a00c660STakashi Iwai int saved_cached_write = codec->cached_write; 3993a00c660STakashi Iwai 4003a00c660STakashi Iwai codec->cached_write = 1; 4013a00c660STakashi Iwai /* in DC mode, we don't handle automic */ 4023a00c660STakashi Iwai if (!spec->dc_enable) 4033a00c660STakashi Iwai snd_hda_gen_mic_autoswitch(codec, jack); 4043a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4053a00c660STakashi Iwai snd_hda_codec_flush_cache(codec); 4063a00c660STakashi Iwai codec->cached_write = saved_cached_write; 4073a00c660STakashi Iwai if (spec->dc_enable) 4083a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 4093a00c660STakashi Iwai } 4103a00c660STakashi Iwai 4113a00c660STakashi Iwai /* pcm_capture hook */ 4123a00c660STakashi Iwai static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo, 4133a00c660STakashi Iwai struct hda_codec *codec, 4143a00c660STakashi Iwai struct snd_pcm_substream *substream, 4153a00c660STakashi Iwai int action) 4163a00c660STakashi Iwai { 4173a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4183a00c660STakashi Iwai 4193a00c660STakashi Iwai /* toggle spec->recording flag and update mic pins accordingly 4203a00c660STakashi Iwai * for turning on/off LED 4213a00c660STakashi Iwai */ 4223a00c660STakashi Iwai switch (action) { 4233a00c660STakashi Iwai case HDA_GEN_PCM_ACT_PREPARE: 4243a00c660STakashi Iwai spec->recording = 1; 4253a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4263a00c660STakashi Iwai break; 4273a00c660STakashi Iwai case HDA_GEN_PCM_ACT_CLEANUP: 4283a00c660STakashi Iwai spec->recording = 0; 4293a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4303a00c660STakashi Iwai break; 4313a00c660STakashi Iwai } 4323a00c660STakashi Iwai } 4333a00c660STakashi Iwai 4343a00c660STakashi Iwai static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol, 4353a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 4363a00c660STakashi Iwai { 4373a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 4383a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4393a00c660STakashi Iwai ucontrol->value.integer.value[0] = spec->dc_enable; 4403a00c660STakashi Iwai return 0; 4413a00c660STakashi Iwai } 4423a00c660STakashi Iwai 4433a00c660STakashi Iwai static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol, 4443a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 4453a00c660STakashi Iwai { 4463a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 4473a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4483a00c660STakashi Iwai int dc_enable = !!ucontrol->value.integer.value[0]; 4493a00c660STakashi Iwai 4503a00c660STakashi Iwai if (dc_enable == spec->dc_enable) 4513a00c660STakashi Iwai return 0; 4523a00c660STakashi Iwai 4533a00c660STakashi Iwai spec->dc_enable = dc_enable; 4543a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4553a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 4563a00c660STakashi Iwai return 1; 4573a00c660STakashi Iwai } 4583a00c660STakashi Iwai 4593a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 4603a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 4613a00c660STakashi Iwai { 4623a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 4633a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4643a00c660STakashi Iwai ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 4653a00c660STakashi Iwai return 0; 4663a00c660STakashi Iwai } 4673a00c660STakashi Iwai 4683a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 4693a00c660STakashi Iwai struct snd_ctl_elem_info *uinfo) 4703a00c660STakashi Iwai { 4713a00c660STakashi Iwai return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo); 4723a00c660STakashi Iwai } 4733a00c660STakashi Iwai 4743a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 4753a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 4763a00c660STakashi Iwai { 4773a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 4783a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 4793a00c660STakashi Iwai const struct hda_input_mux *imux = &olpc_xo_dc_bias; 4803a00c660STakashi Iwai unsigned int idx; 4813a00c660STakashi Iwai 4823a00c660STakashi Iwai idx = ucontrol->value.enumerated.item[0]; 4833a00c660STakashi Iwai if (idx >= imux->num_items) 4843a00c660STakashi Iwai idx = imux->num_items - 1; 4853a00c660STakashi Iwai if (spec->dc_input_bias == idx) 4863a00c660STakashi Iwai return 0; 4873a00c660STakashi Iwai 4883a00c660STakashi Iwai spec->dc_input_bias = idx; 4893a00c660STakashi Iwai if (spec->dc_enable) 4903a00c660STakashi Iwai olpc_xo_update_mic_pins(codec); 4913a00c660STakashi Iwai return 1; 4923a00c660STakashi Iwai } 4933a00c660STakashi Iwai 4943a00c660STakashi Iwai static const struct snd_kcontrol_new olpc_xo_mixers[] = { 4953a00c660STakashi Iwai { 4963a00c660STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4973a00c660STakashi Iwai .name = "DC Mode Enable Switch", 4983a00c660STakashi Iwai .info = snd_ctl_boolean_mono_info, 4993a00c660STakashi Iwai .get = olpc_xo_dc_mode_get, 5003a00c660STakashi Iwai .put = olpc_xo_dc_mode_put, 5013a00c660STakashi Iwai }, 5023a00c660STakashi Iwai { 5033a00c660STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5043a00c660STakashi Iwai .name = "DC Input Bias Enum", 5053a00c660STakashi Iwai .info = olpc_xo_dc_bias_enum_info, 5063a00c660STakashi Iwai .get = olpc_xo_dc_bias_enum_get, 5073a00c660STakashi Iwai .put = olpc_xo_dc_bias_enum_put, 5083a00c660STakashi Iwai }, 5093a00c660STakashi Iwai {} 5103a00c660STakashi Iwai }; 5113a00c660STakashi Iwai 5123a00c660STakashi Iwai /* overriding mic boost put callback; update mic boost volume only when 5133a00c660STakashi Iwai * DC mode is disabled 5143a00c660STakashi Iwai */ 5153a00c660STakashi Iwai static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol, 5163a00c660STakashi Iwai struct snd_ctl_elem_value *ucontrol) 5173a00c660STakashi Iwai { 5183a00c660STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 5193a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5203a00c660STakashi Iwai int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol); 5213a00c660STakashi Iwai if (ret > 0 && spec->dc_enable) 5223a00c660STakashi Iwai olpc_xo_update_mic_boost(codec); 5233a00c660STakashi Iwai return ret; 5243a00c660STakashi Iwai } 5253a00c660STakashi Iwai 5263a00c660STakashi Iwai static void cxt_fixup_olpc_xo(struct hda_codec *codec, 5273a00c660STakashi Iwai const struct hda_fixup *fix, int action) 5283a00c660STakashi Iwai { 5293a00c660STakashi Iwai struct conexant_spec *spec = codec->spec; 5303a00c660STakashi Iwai int i; 5313a00c660STakashi Iwai 5323a00c660STakashi Iwai if (action != HDA_FIXUP_ACT_PROBE) 5333a00c660STakashi Iwai return; 5343a00c660STakashi Iwai 5353a00c660STakashi Iwai spec->gen.mic_autoswitch_hook = olpc_xo_automic; 5363a00c660STakashi Iwai spec->gen.pcm_capture_hook = olpc_xo_capture_hook; 5373a00c660STakashi Iwai spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0); 5383a00c660STakashi Iwai 5393a00c660STakashi Iwai snd_hda_add_new_ctls(codec, olpc_xo_mixers); 5403a00c660STakashi Iwai 5413a00c660STakashi Iwai /* OLPC's microphone port is DC coupled for use with external sensors, 5423a00c660STakashi Iwai * therefore we use a 50% mic bias in order to center the input signal 5433a00c660STakashi Iwai * with the DC input range of the codec. 5443a00c660STakashi Iwai */ 5453a00c660STakashi Iwai snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50); 5463a00c660STakashi Iwai 5473a00c660STakashi Iwai /* override mic boost control */ 5483a00c660STakashi Iwai for (i = 0; i < spec->gen.kctls.used; i++) { 5493a00c660STakashi Iwai struct snd_kcontrol_new *kctl = 5503a00c660STakashi Iwai snd_array_elem(&spec->gen.kctls, i); 5513a00c660STakashi Iwai if (!strcmp(kctl->name, "Mic Boost Volume")) { 5523a00c660STakashi Iwai kctl->put = olpc_xo_mic_boost_put; 5533a00c660STakashi Iwai break; 5543a00c660STakashi Iwai } 5553a00c660STakashi Iwai } 5563a00c660STakashi Iwai } 5573a00c660STakashi Iwai 558ad7725d3STakashi Iwai /* 559ad7725d3STakashi Iwai * Fix max input level on mixer widget to 0dB 560ad7725d3STakashi Iwai * (originally it has 0x2b steps with 0dB offset 0x14) 561ad7725d3STakashi Iwai */ 562ad7725d3STakashi Iwai static void cxt_fixup_cap_mix_amp(struct hda_codec *codec, 563ad7725d3STakashi Iwai const struct hda_fixup *fix, int action) 564ad7725d3STakashi Iwai { 565ad7725d3STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 566ad7725d3STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 567ad7725d3STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 568ad7725d3STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 569ad7725d3STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 570ad7725d3STakashi Iwai } 571e4c3bce2SDavid Henningsson 572ea30e7dfSTakashi Iwai /* 573ea30e7dfSTakashi Iwai * Fix max input level on mixer widget to 0dB 574ea30e7dfSTakashi Iwai * (originally it has 0x1e steps with 0 dB offset 0x17) 575ea30e7dfSTakashi Iwai */ 576ea30e7dfSTakashi Iwai static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec, 577ea30e7dfSTakashi Iwai const struct hda_fixup *fix, int action) 578ea30e7dfSTakashi Iwai { 579ea30e7dfSTakashi Iwai snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 580ea30e7dfSTakashi Iwai (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 581ea30e7dfSTakashi Iwai (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 582ea30e7dfSTakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 583ea30e7dfSTakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 584ea30e7dfSTakashi Iwai } 585ea30e7dfSTakashi Iwai 586d70f3632STakashi Iwai /* ThinkPad X200 & co with cxt5051 */ 58723d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 588e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 589e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 590e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 5913e93f5efSTakashi Iwai { 0x1c, 0x21440100 }, /* dock SPDIF out */ 592e92d4b08STakashi Iwai {} 593e92d4b08STakashi Iwai }; 594e92d4b08STakashi Iwai 595d70f3632STakashi Iwai /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 59623d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { 597d70f3632STakashi Iwai { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 598d70f3632STakashi Iwai { 0x1a, 0x21a190f0 }, /* dock-mic */ 599d70f3632STakashi Iwai { 0x1c, 0x212140ff }, /* dock-HP */ 600d70f3632STakashi Iwai {} 601e92d4b08STakashi Iwai }; 602e92d4b08STakashi Iwai 603239fb862SHuacai Chen /* Lemote A1004/A1205 with cxt5066 */ 604239fb862SHuacai Chen static const struct hda_pintbl cxt_pincfg_lemote[] = { 605239fb862SHuacai Chen { 0x1a, 0x90a10020 }, /* Internal mic */ 606239fb862SHuacai Chen { 0x1b, 0x03a11020 }, /* External mic */ 607239fb862SHuacai Chen { 0x1d, 0x400101f0 }, /* Not used */ 608239fb862SHuacai Chen { 0x1e, 0x40a701f0 }, /* Not used */ 609239fb862SHuacai Chen { 0x20, 0x404501f0 }, /* Not used */ 610239fb862SHuacai Chen { 0x22, 0x404401f0 }, /* Not used */ 611239fb862SHuacai Chen { 0x23, 0x40a701f0 }, /* Not used */ 612239fb862SHuacai Chen {} 613239fb862SHuacai Chen }; 614239fb862SHuacai Chen 61523d30f28STakashi Iwai static const struct hda_fixup cxt_fixups[] = { 61623d30f28STakashi Iwai [CXT_PINCFG_LENOVO_X200] = { 61723d30f28STakashi Iwai .type = HDA_FIXUP_PINS, 61823d30f28STakashi Iwai .v.pins = cxt_pincfg_lenovo_x200, 61923d30f28STakashi Iwai }, 62023d30f28STakashi Iwai [CXT_PINCFG_LENOVO_TP410] = { 62123d30f28STakashi Iwai .type = HDA_FIXUP_PINS, 62223d30f28STakashi Iwai .v.pins = cxt_pincfg_lenovo_tp410, 62308cf680cSDavid Henningsson .chained = true, 62408cf680cSDavid Henningsson .chain_id = CXT_FIXUP_THINKPAD_ACPI, 62523d30f28STakashi Iwai }, 626239fb862SHuacai Chen [CXT_PINCFG_LEMOTE_A1004] = { 627239fb862SHuacai Chen .type = HDA_FIXUP_PINS, 628239fb862SHuacai Chen .chained = true, 629239fb862SHuacai Chen .chain_id = CXT_FIXUP_INC_MIC_BOOST, 630239fb862SHuacai Chen .v.pins = cxt_pincfg_lemote, 631239fb862SHuacai Chen }, 632239fb862SHuacai Chen [CXT_PINCFG_LEMOTE_A1205] = { 633239fb862SHuacai Chen .type = HDA_FIXUP_PINS, 634239fb862SHuacai Chen .v.pins = cxt_pincfg_lemote, 635239fb862SHuacai Chen }, 63623d30f28STakashi Iwai [CXT_FIXUP_STEREO_DMIC] = { 63723d30f28STakashi Iwai .type = HDA_FIXUP_FUNC, 63823d30f28STakashi Iwai .v.func = cxt_fixup_stereo_dmic, 63923d30f28STakashi Iwai }, 640239fb862SHuacai Chen [CXT_FIXUP_INC_MIC_BOOST] = { 641239fb862SHuacai Chen .type = HDA_FIXUP_FUNC, 642239fb862SHuacai Chen .v.func = cxt5066_increase_mic_boost, 643239fb862SHuacai Chen }, 644e4c3bce2SDavid Henningsson [CXT_FIXUP_HEADPHONE_MIC_PIN] = { 645e4c3bce2SDavid Henningsson .type = HDA_FIXUP_PINS, 646e4c3bce2SDavid Henningsson .chained = true, 647e4c3bce2SDavid Henningsson .chain_id = CXT_FIXUP_HEADPHONE_MIC, 648e4c3bce2SDavid Henningsson .v.pins = (const struct hda_pintbl[]) { 649e4c3bce2SDavid Henningsson { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */ 650e4c3bce2SDavid Henningsson { } 651e4c3bce2SDavid Henningsson } 652e4c3bce2SDavid Henningsson }, 653e4c3bce2SDavid Henningsson [CXT_FIXUP_HEADPHONE_MIC] = { 654e4c3bce2SDavid Henningsson .type = HDA_FIXUP_FUNC, 655e4c3bce2SDavid Henningsson .v.func = cxt_fixup_headphone_mic, 656e4c3bce2SDavid Henningsson }, 6574a437044STakashi Iwai [CXT_FIXUP_GPIO1] = { 6584a437044STakashi Iwai .type = HDA_FIXUP_VERBS, 6594a437044STakashi Iwai .v.verbs = (const struct hda_verb[]) { 6604a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 }, 6614a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 }, 6624a437044STakashi Iwai { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 }, 6634a437044STakashi Iwai { } 6644a437044STakashi Iwai }, 6654a437044STakashi Iwai }, 66608cf680cSDavid Henningsson [CXT_FIXUP_THINKPAD_ACPI] = { 66708cf680cSDavid Henningsson .type = HDA_FIXUP_FUNC, 668b317b032STakashi Iwai .v.func = hda_fixup_thinkpad_acpi, 66908cf680cSDavid Henningsson }, 6703a00c660STakashi Iwai [CXT_FIXUP_OLPC_XO] = { 6713a00c660STakashi Iwai .type = HDA_FIXUP_FUNC, 6723a00c660STakashi Iwai .v.func = cxt_fixup_olpc_xo, 6733a00c660STakashi Iwai }, 674ad7725d3STakashi Iwai [CXT_FIXUP_CAP_MIX_AMP] = { 675ad7725d3STakashi Iwai .type = HDA_FIXUP_FUNC, 676ad7725d3STakashi Iwai .v.func = cxt_fixup_cap_mix_amp, 677ad7725d3STakashi Iwai }, 6786dcbadefSTakashi Iwai [CXT_FIXUP_TOSHIBA_P105] = { 6796dcbadefSTakashi Iwai .type = HDA_FIXUP_PINS, 6806dcbadefSTakashi Iwai .v.pins = (const struct hda_pintbl[]) { 6816dcbadefSTakashi Iwai { 0x10, 0x961701f0 }, /* speaker/hp */ 6826dcbadefSTakashi Iwai { 0x12, 0x02a1901e }, /* ext mic */ 6836dcbadefSTakashi Iwai { 0x14, 0x95a70110 }, /* int mic */ 6846dcbadefSTakashi Iwai {} 6856dcbadefSTakashi Iwai }, 6866dcbadefSTakashi Iwai }, 687e5eac90dSTakashi Iwai [CXT_FIXUP_HP_530] = { 688e5eac90dSTakashi Iwai .type = HDA_FIXUP_PINS, 689e5eac90dSTakashi Iwai .v.pins = (const struct hda_pintbl[]) { 690e5eac90dSTakashi Iwai { 0x12, 0x90a60160 }, /* int mic */ 691e5eac90dSTakashi Iwai {} 692e5eac90dSTakashi Iwai }, 693e5eac90dSTakashi Iwai .chained = true, 694e5eac90dSTakashi Iwai .chain_id = CXT_FIXUP_CAP_MIX_AMP, 695e5eac90dSTakashi Iwai }, 696ea30e7dfSTakashi Iwai [CXT_FIXUP_CAP_MIX_AMP_5047] = { 697ea30e7dfSTakashi Iwai .type = HDA_FIXUP_FUNC, 698ea30e7dfSTakashi Iwai .v.func = cxt_fixup_cap_mix_amp_5047, 699ea30e7dfSTakashi Iwai }, 700ad7725d3STakashi Iwai }; 701ad7725d3STakashi Iwai 702ad7725d3STakashi Iwai static const struct snd_pci_quirk cxt5045_fixups[] = { 703e5eac90dSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530), 7046dcbadefSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105), 705ad7725d3STakashi Iwai /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 706ad7725d3STakashi Iwai * really bad sound over 0dB on NID 0x17. 707ad7725d3STakashi Iwai */ 708ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP), 709ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP), 710ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP), 711ad7725d3STakashi Iwai SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP), 712ad7725d3STakashi Iwai {} 713ad7725d3STakashi Iwai }; 714ad7725d3STakashi Iwai 715ad7725d3STakashi Iwai static const struct hda_model_fixup cxt5045_fixup_models[] = { 716ad7725d3STakashi Iwai { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" }, 7176dcbadefSTakashi Iwai { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" }, 718e5eac90dSTakashi Iwai { .id = CXT_FIXUP_HP_530, .name = "hp-530" }, 719ad7725d3STakashi Iwai {} 720e92d4b08STakashi Iwai }; 721e92d4b08STakashi Iwai 722ea30e7dfSTakashi Iwai static const struct snd_pci_quirk cxt5047_fixups[] = { 723ea30e7dfSTakashi Iwai /* HP laptops have really bad sound over 0 dB on NID 0x10. 724ea30e7dfSTakashi Iwai */ 725ea30e7dfSTakashi Iwai SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047), 726ea30e7dfSTakashi Iwai {} 727ea30e7dfSTakashi Iwai }; 728ea30e7dfSTakashi Iwai 729ea30e7dfSTakashi Iwai static const struct hda_model_fixup cxt5047_fixup_models[] = { 730ea30e7dfSTakashi Iwai { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" }, 731ea30e7dfSTakashi Iwai {} 732ea30e7dfSTakashi Iwai }; 733ea30e7dfSTakashi Iwai 734d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = { 735e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 736e92d4b08STakashi Iwai {} 737e92d4b08STakashi Iwai }; 738e92d4b08STakashi Iwai 739a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5051_fixup_models[] = { 740a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" }, 741a2dd933dSTakashi Iwai {} 742a2dd933dSTakashi Iwai }; 743a2dd933dSTakashi Iwai 744d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = { 74563a077e2STakashi Iwai SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 7464a437044STakashi Iwai SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1), 747e4c3bce2SDavid Henningsson SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 7483a00c660STakashi Iwai SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO), 749d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 750d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 751d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 752d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 753d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 754a555bb8cSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410), 75588d57606SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410), 75618dcd304SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 757e4db0952SFelix Kaechele SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), 758b3c5dce8SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), 7592fd3f170SHui Wang SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI), 760239fb862SHuacai Chen SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004), 761239fb862SHuacai Chen SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205), 762f2e5731dSTakashi Iwai {} 763f2e5731dSTakashi Iwai }; 764f2e5731dSTakashi Iwai 765a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5066_fixup_models[] = { 766a2dd933dSTakashi Iwai { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" }, 767a2dd933dSTakashi Iwai { .id = CXT_FIXUP_GPIO1, .name = "gpio1" }, 768a2dd933dSTakashi Iwai { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" }, 769a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" }, 770a2dd933dSTakashi Iwai { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" }, 771a2dd933dSTakashi Iwai { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" }, 7723a00c660STakashi Iwai { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" }, 773a2dd933dSTakashi Iwai {} 774a2dd933dSTakashi Iwai }; 775a2dd933dSTakashi Iwai 7763868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 7773868137eSTakashi Iwai * can be created (bko#42825) 7783868137eSTakashi Iwai */ 7793868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec) 7803868137eSTakashi Iwai { 781*d89c6c0cSTakashi Iwai struct conexant_spec *spec = codec->spec; 7823868137eSTakashi Iwai static hda_nid_t out_nids[] = { 7833868137eSTakashi Iwai 0x10, 0x11, 0 7843868137eSTakashi Iwai }; 7853868137eSTakashi Iwai hda_nid_t *p; 7863868137eSTakashi Iwai 7873868137eSTakashi Iwai for (p = out_nids; *p; p++) 7883868137eSTakashi Iwai snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 7893868137eSTakashi Iwai AC_AMPCAP_MIN_MUTE | 7903868137eSTakashi Iwai query_amp_caps(codec, *p, HDA_OUTPUT)); 791*d89c6c0cSTakashi Iwai spec->gen.dac_min_mute = true; 7923868137eSTakashi Iwai } 7933868137eSTakashi Iwai 794f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 795f2e5731dSTakashi Iwai { 796f2e5731dSTakashi Iwai struct conexant_spec *spec; 797f2e5731dSTakashi Iwai int err; 798f2e5731dSTakashi Iwai 7994e76a883STakashi Iwai codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name); 8001f8458a2STakashi Iwai 801f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 802f2e5731dSTakashi Iwai if (!spec) 803f2e5731dSTakashi Iwai return -ENOMEM; 804aed523f1STakashi Iwai snd_hda_gen_spec_init(&spec->gen); 805f2e5731dSTakashi Iwai codec->spec = spec; 806e92d4b08STakashi Iwai 807aed523f1STakashi Iwai cx_auto_parse_beep(codec); 808aed523f1STakashi Iwai cx_auto_parse_eapd(codec); 809ff359b14STakashi Iwai spec->gen.own_eapd_ctl = 1; 810ff359b14STakashi Iwai if (spec->dynamic_eapd) 811aed523f1STakashi Iwai spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; 812e92d4b08STakashi Iwai 8136b452142STakashi Iwai switch (codec->vendor_id) { 8146b452142STakashi Iwai case 0x14f15045: 8154f32456eSMichael Karcher codec->single_adc_amp = 1; 81670540e24STakashi Iwai spec->gen.mixer_nid = 0x17; 817d50ce6c0STakashi Iwai spec->gen.add_stereo_mix_input = 1; 818ad7725d3STakashi Iwai snd_hda_pick_fixup(codec, cxt5045_fixup_models, 819ad7725d3STakashi Iwai cxt5045_fixups, cxt_fixups); 8206b452142STakashi Iwai break; 821164a7adaSTakashi Iwai case 0x14f15047: 822164a7adaSTakashi Iwai codec->pin_amp_workaround = 1; 823164a7adaSTakashi Iwai spec->gen.mixer_nid = 0x19; 824d50ce6c0STakashi Iwai spec->gen.add_stereo_mix_input = 1; 825ea30e7dfSTakashi Iwai snd_hda_pick_fixup(codec, cxt5047_fixup_models, 826ea30e7dfSTakashi Iwai cxt5047_fixups, cxt_fixups); 827164a7adaSTakashi Iwai break; 8283868137eSTakashi Iwai case 0x14f15051: 8293868137eSTakashi Iwai add_cx5051_fake_mutes(codec); 83051969d62SMichael Karcher codec->pin_amp_workaround = 1; 831a2dd933dSTakashi Iwai snd_hda_pick_fixup(codec, cxt5051_fixup_models, 832a2dd933dSTakashi Iwai cxt5051_fixups, cxt_fixups); 8333868137eSTakashi Iwai break; 83451969d62SMichael Karcher default: 83551969d62SMichael Karcher codec->pin_amp_workaround = 1; 836a2dd933dSTakashi Iwai snd_hda_pick_fixup(codec, cxt5066_fixup_models, 837a2dd933dSTakashi Iwai cxt5066_fixups, cxt_fixups); 83823d30f28STakashi Iwai break; 8396b452142STakashi Iwai } 8406b452142STakashi Iwai 841f29735cbSTakashi Iwai /* Show mute-led control only on HP laptops 842f29735cbSTakashi Iwai * This is a sort of white-list: on HP laptops, EAPD corresponds 843f29735cbSTakashi Iwai * only to the mute-LED without actualy amp function. Meanwhile, 844f29735cbSTakashi Iwai * others may use EAPD really as an amp switch, so it might be 845f29735cbSTakashi Iwai * not good to expose it blindly. 846527c73baSTakashi Iwai */ 847f29735cbSTakashi Iwai switch (codec->subsystem_id >> 16) { 848f29735cbSTakashi Iwai case 0x103c: 849aed523f1STakashi Iwai spec->gen.vmaster_mute_enum = 1; 850f29735cbSTakashi Iwai break; 851f29735cbSTakashi Iwai } 852527c73baSTakashi Iwai 853aed523f1STakashi Iwai snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 854aed523f1STakashi Iwai 855e4c3bce2SDavid Henningsson err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 856e4c3bce2SDavid Henningsson spec->parse_flags); 85722ce5f74STakashi Iwai if (err < 0) 858aed523f1STakashi Iwai goto error; 859aed523f1STakashi Iwai 860aed523f1STakashi Iwai err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); 861aed523f1STakashi Iwai if (err < 0) 862aed523f1STakashi Iwai goto error; 863aed523f1STakashi Iwai 864f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 8654f2864a4STakashi Iwai 8664f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 8674f2864a4STakashi Iwai * which falls into the single-cmd mode. 8684f2864a4STakashi Iwai * Better to make reset, then. 8694f2864a4STakashi Iwai */ 8704f2864a4STakashi Iwai if (!codec->bus->sync_write) { 8714e76a883STakashi Iwai codec_info(codec, 8724f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 8734f2864a4STakashi Iwai codec->bus->sync_write = 1; 8744f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 8754f2864a4STakashi Iwai } 8764f2864a4STakashi Iwai 877e4c3bce2SDavid Henningsson snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 878e4c3bce2SDavid Henningsson 879f2e5731dSTakashi Iwai return 0; 880aed523f1STakashi Iwai 881aed523f1STakashi Iwai error: 88208cf680cSDavid Henningsson cx_auto_free(codec); 883aed523f1STakashi Iwai return err; 884f2e5731dSTakashi Iwai } 885f2e5731dSTakashi Iwai 886f2e5731dSTakashi Iwai /* 887461e2c78STakashi Iwai */ 888461e2c78STakashi Iwai 88934cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 89082f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 891d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 89282f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 893d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 894461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 895d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 8960fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 897d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 89895a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 899d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 900850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 901d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 9027b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 903d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 904f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 905d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 9066da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 907d0ea6d27STakashi Iwai .patch = patch_conexant_auto }, 908f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 909f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 910f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 911f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 912f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 913f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 914f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 915f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 916f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 917f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 918f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 919f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 920f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 921f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 922f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 923f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 9242d825fd8STakashi Iwai { .id = 0x14f1510f, .name = "CX20751/2", 9252d825fd8STakashi Iwai .patch = patch_conexant_auto }, 9262d825fd8STakashi Iwai { .id = 0x14f15110, .name = "CX20751/2", 9272d825fd8STakashi Iwai .patch = patch_conexant_auto }, 9282d825fd8STakashi Iwai { .id = 0x14f15111, .name = "CX20753/4", 9292d825fd8STakashi Iwai .patch = patch_conexant_auto }, 93042c364acSTakashi Iwai { .id = 0x14f15113, .name = "CX20755", 93142c364acSTakashi Iwai .patch = patch_conexant_auto }, 93242c364acSTakashi Iwai { .id = 0x14f15114, .name = "CX20756", 93342c364acSTakashi Iwai .patch = patch_conexant_auto }, 93442c364acSTakashi Iwai { .id = 0x14f15115, .name = "CX20757", 93542c364acSTakashi Iwai .patch = patch_conexant_auto }, 9368f42d769STakashi Iwai { .id = 0x14f151d7, .name = "CX20952", 9378f42d769STakashi Iwai .patch = patch_conexant_auto }, 938c9b443d4STobin Davis {} /* terminator */ 939c9b443d4STobin Davis }; 9401289e9e8STakashi Iwai 9411289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 9421289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 9431289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 9440fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 94595a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 946850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 9477b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 948f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 9496da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 950f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 951f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 952f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 953f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 954f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 955f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 956f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 957f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 9582d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f1510f"); 9592d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15110"); 9602d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15111"); 96142c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15113"); 96242c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15114"); 96342c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15115"); 9648f42d769STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f151d7"); 9651289e9e8STakashi Iwai 9661289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 9671289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 9681289e9e8STakashi Iwai 9691289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 9701289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 9711289e9e8STakashi Iwai .owner = THIS_MODULE, 9721289e9e8STakashi Iwai }; 9731289e9e8STakashi Iwai 9741289e9e8STakashi Iwai static int __init patch_conexant_init(void) 9751289e9e8STakashi Iwai { 9761289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 9771289e9e8STakashi Iwai } 9781289e9e8STakashi Iwai 9791289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 9801289e9e8STakashi Iwai { 9811289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 9821289e9e8STakashi Iwai } 9831289e9e8STakashi Iwai 9841289e9e8STakashi Iwai module_init(patch_conexant_init) 9851289e9e8STakashi Iwai module_exit(patch_conexant_exit) 986