Lines Matching +full:codec +full:- +full:gpio1
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Cirrus Logic CS420x HD-audio codec
52 /* Vendor-specific processing widget */
65 * 1 = digital immediate, analog zero-cross
66 * 2 = digtail & analog soft-ramp
67 * 3 = digital soft-ramp, analog zero-cross
71 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
72 /* PGA mode: 0 = differential, 1 = signle-ended */
74 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
78 * 1 = zero-cross
79 * 2 = soft-ramp
80 * 3 = soft-ramp on zero-cross
87 /* 0x0008 - test reg key */
88 /* 0x0009 - 0x0014 -> 12 test regs */
89 /* 0x0015 - visibility reg */
94 static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx) in cs_vendor_coef_get() argument
96 struct cs_spec *spec = codec->spec; in cs_vendor_coef_get()
98 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_get()
100 return snd_hda_codec_read(codec, spec->vendor_nid, 0, in cs_vendor_coef_get()
104 static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, in cs_vendor_coef_set() argument
107 struct cs_spec *spec = codec->spec; in cs_vendor_coef_set()
109 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_set()
111 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_set()
116 * auto-mute and auto-mic switching
117 * CS421x auto-output redirecting
121 static void cs_automute(struct hda_codec *codec) in cs_automute() argument
123 struct cs_spec *spec = codec->spec; in cs_automute()
125 snd_hda_gen_update_outputs(codec); in cs_automute()
127 if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) { in cs_automute()
128 if (spec->gen.automute_speaker) in cs_automute()
129 spec->gpio_data = spec->gen.hp_jack_present ? in cs_automute()
130 spec->gpio_eapd_hp : spec->gpio_eapd_speaker; in cs_automute()
132 spec->gpio_data = in cs_automute()
133 spec->gpio_eapd_hp | spec->gpio_eapd_speaker; in cs_automute()
134 snd_hda_codec_write(codec, 0x01, 0, in cs_automute()
135 AC_VERB_SET_GPIO_DATA, spec->gpio_data); in cs_automute()
139 static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid) in is_active_pin() argument
143 val = snd_hda_codec_get_pincfg(codec, nid); in is_active_pin()
147 static void init_input_coef(struct hda_codec *codec) in init_input_coef() argument
149 struct cs_spec *spec = codec->spec; in init_input_coef()
153 if (spec->vendor_nid == CS420X_VENDOR_NID) { in init_input_coef()
154 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); in init_input_coef()
155 if (is_active_pin(codec, CS_DMIC2_PIN_NID)) in init_input_coef()
156 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ in init_input_coef()
157 if (is_active_pin(codec, CS_DMIC1_PIN_NID)) in init_input_coef()
163 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); in init_input_coef()
176 /* ADC1/2 - Digital and Analog Soft Ramp */
239 static void init_digital_coef(struct hda_codec *codec) in init_digital_coef() argument
243 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */ in init_digital_coef()
245 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID)) in init_digital_coef()
247 * SPDIF_OUT2 is shared with GPIO1 and in init_digital_coef()
250 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef); in init_digital_coef()
253 static int cs_init(struct hda_codec *codec) in cs_init() argument
255 struct cs_spec *spec = codec->spec; in cs_init()
257 if (spec->vendor_nid == CS420X_VENDOR_NID) { in cs_init()
259 snd_hda_sequence_write(codec, cs_errata_init_verbs); in cs_init()
260 snd_hda_sequence_write(codec, cs_coef_init_verbs); in cs_init()
261 } else if (spec->vendor_nid == CS4208_VENDOR_NID) { in cs_init()
262 snd_hda_sequence_write(codec, cs4208_coef_init_verbs); in cs_init()
265 snd_hda_gen_init(codec); in cs_init()
267 if (spec->gpio_mask) { in cs_init()
268 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, in cs_init()
269 spec->gpio_mask); in cs_init()
270 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, in cs_init()
271 spec->gpio_dir); in cs_init()
272 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, in cs_init()
273 spec->gpio_data); in cs_init()
276 if (spec->vendor_nid == CS420X_VENDOR_NID) { in cs_init()
277 init_input_coef(codec); in cs_init()
278 init_digital_coef(codec); in cs_init()
284 static int cs_build_controls(struct hda_codec *codec) in cs_build_controls() argument
288 err = snd_hda_gen_build_controls(codec); in cs_build_controls()
291 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD); in cs_build_controls()
295 static int cs_parse_auto_config(struct hda_codec *codec) in cs_parse_auto_config() argument
297 struct cs_spec *spec = codec->spec; in cs_parse_auto_config()
301 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); in cs_parse_auto_config()
305 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); in cs_parse_auto_config()
310 if (spec->gen.dyn_adc_switch) { in cs_parse_auto_config()
313 for (i = 0; i < spec->gen.input_mux.num_items; i++) { in cs_parse_auto_config()
314 int idx = spec->gen.dyn_adc_idx[i]; in cs_parse_auto_config()
318 snd_hda_gen_fix_pin_power(codec, in cs_parse_auto_config()
319 spec->gen.adc_nids[idx]); in cs_parse_auto_config()
347 /* codec SSID */
445 static void cs420x_fixup_gpio_13(struct hda_codec *codec, in cs420x_fixup_gpio_13() argument
449 struct cs_spec *spec = codec->spec; in cs420x_fixup_gpio_13()
451 spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */ in cs420x_fixup_gpio_13()
452 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ in cs420x_fixup_gpio_13()
453 spec->gpio_mask = spec->gpio_dir = in cs420x_fixup_gpio_13()
454 spec->gpio_eapd_hp | spec->gpio_eapd_speaker; in cs420x_fixup_gpio_13()
458 static void cs420x_fixup_gpio_23(struct hda_codec *codec, in cs420x_fixup_gpio_23() argument
462 struct cs_spec *spec = codec->spec; in cs420x_fixup_gpio_23()
464 spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */ in cs420x_fixup_gpio_23()
465 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ in cs420x_fixup_gpio_23()
466 spec->gpio_mask = spec->gpio_dir = in cs420x_fixup_gpio_23()
467 spec->gpio_eapd_hp | spec->gpio_eapd_speaker; in cs420x_fixup_gpio_23()
523 static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid) in cs_alloc_spec() argument
530 codec->spec = spec; in cs_alloc_spec()
531 spec->vendor_nid = vendor_nid; in cs_alloc_spec()
532 codec->power_save_node = 1; in cs_alloc_spec()
533 snd_hda_gen_spec_init(&spec->gen); in cs_alloc_spec()
538 static int cs420x_probe(struct hda_codec *codec) in cs420x_probe() argument
542 codec->single_adc_amp = 1; in cs420x_probe()
544 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, in cs420x_probe()
546 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); in cs420x_probe()
548 err = cs_parse_auto_config(codec); in cs420x_probe()
552 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); in cs420x_probe()
582 /* codec SSID matching */
592 static void cs4208_fixup_gpio0(struct hda_codec *codec, in cs4208_fixup_gpio0() argument
596 struct cs_spec *spec = codec->spec; in cs4208_fixup_gpio0()
598 spec->gpio_eapd_hp = 0; in cs4208_fixup_gpio0()
599 spec->gpio_eapd_speaker = 1; in cs4208_fixup_gpio0()
600 spec->gpio_mask = spec->gpio_dir = in cs4208_fixup_gpio0()
601 spec->gpio_eapd_hp | spec->gpio_eapd_speaker; in cs4208_fixup_gpio0()
607 /* remap the fixup from codec SSID and apply it */
608 static void cs4208_fixup_mac(struct hda_codec *codec, in cs4208_fixup_mac() argument
614 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in cs4208_fixup_mac()
615 snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups); in cs4208_fixup_mac()
616 if (codec->fixup_id == HDA_FIXUP_ID_NOT_SET) in cs4208_fixup_mac()
617 codec->fixup_id = CS4208_GPIO0; /* default fixup */ in cs4208_fixup_mac()
618 snd_hda_apply_fixup(codec, action); in cs4208_fixup_mac()
622 static void cs4208_fixup_macmini(struct hda_codec *codec, in cs4208_fixup_macmini() argument
626 { 0x18, 0x00ab9150 }, /* mic (audio-in) jack: disable detect */ in cs4208_fixup_macmini()
633 codec->inv_jack_detect = 1; in cs4208_fixup_macmini()
635 snd_hda_apply_pincfgs(codec, pincfgs); in cs4208_fixup_macmini()
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in cs4208_spdif_sw_put() local
643 struct cs_spec *spec = codec->spec; in cs4208_spdif_sw_put()
644 hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0]; in cs4208_spdif_sw_put()
645 int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0; in cs4208_spdif_sw_put()
647 snd_hda_set_pin_ctl_cache(codec, pin, pinctl); in cs4208_spdif_sw_put()
648 return spec->spdif_sw_put(kcontrol, ucontrol); in cs4208_spdif_sw_put()
652 static void cs4208_fixup_spdif_switch(struct hda_codec *codec, in cs4208_fixup_spdif_switch() argument
656 struct cs_spec *spec = codec->spec; in cs4208_fixup_spdif_switch()
659 if (!spec->gen.autocfg.dig_out_pins[0]) in cs4208_fixup_spdif_switch()
661 kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch"); in cs4208_fixup_spdif_switch()
664 spec->spdif_sw_put = kctl->put; in cs4208_fixup_spdif_switch()
665 kctl->put = cs4208_spdif_sw_put; in cs4208_fixup_spdif_switch()
699 static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc) in cs4208_fix_amp_caps() argument
703 caps = query_amp_caps(codec, adc, HDA_INPUT); in cs4208_fix_amp_caps()
706 snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps); in cs4208_fix_amp_caps()
709 static int cs4208_probe(struct hda_codec *codec) in cs4208_probe() argument
711 struct cs_spec *spec = codec->spec; in cs4208_probe()
715 spec->gen.out_vol_mask = 1ULL << 0x10; in cs4208_probe()
717 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl, in cs4208_probe()
719 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); in cs4208_probe()
721 snd_hda_override_wcaps(codec, 0x18, in cs4208_probe()
722 get_wcaps(codec, 0x18) | AC_WCAP_STEREO); in cs4208_probe()
723 cs4208_fix_amp_caps(codec, 0x18); in cs4208_probe()
724 cs4208_fix_amp_caps(codec, 0x1b); in cs4208_probe()
725 cs4208_fix_amp_caps(codec, 0x1c); in cs4208_probe()
727 err = cs_parse_auto_config(codec); in cs4208_probe()
731 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); in cs4208_probe()
736 static int cs_codec_probe(struct hda_codec *codec, in cs_codec_probe() argument
742 spec = cs_alloc_spec(codec, id->driver_data); in cs_codec_probe()
744 return -ENOMEM; in cs_codec_probe()
745 spec->gen.automute_hook = cs_automute; in cs_codec_probe()
747 if (spec->vendor_nid == CS4208_VENDOR_NID) in cs_codec_probe()
748 err = cs4208_probe(codec); in cs_codec_probe()
750 err = cs420x_probe(codec); in cs_codec_probe()
752 snd_hda_gen_remove(codec); in cs_codec_probe()
778 MODULE_DESCRIPTION("Cirrus Logic CS420x HD-audio codec");