Lines Matching +full:codec +full:- +full:0

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Cirrus Logic CS421x HD-audio codec
45 /* Vendor-specific processing widget */
46 #define CS_DIG_OUT1_PIN_NID 0x10
47 #define CS_DIG_OUT2_PIN_NID 0x15
48 #define CS_DMIC1_PIN_NID 0x0e
49 #define CS_DMIC2_PIN_NID 0x12
52 #define IDX_SPDIF_STAT 0x0000
53 #define IDX_SPDIF_CTL 0x0001
54 #define IDX_ADC_CFG 0x0002
56 * 0 = immediate,
57 * 1 = digital immediate, analog zero-cross
58 * 2 = digtail & analog soft-ramp
59 * 3 = digital soft-ramp, analog zero-cross
61 #define CS_COEF_ADC_SZC_MASK (3 << 0)
62 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
63 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
64 /* PGA mode: 0 = differential, 1 = signle-ended */
66 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
67 #define IDX_DAC_CFG 0x0003
69 * 0 = Immediate
70 * 1 = zero-cross
71 * 2 = soft-ramp
72 * 3 = soft-ramp on zero-cross
74 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
75 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
76 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
78 #define IDX_BEEP_CFG 0x0004
79 /* 0x0008 - test reg key */
80 /* 0x0009 - 0x0014 -> 12 test regs */
81 /* 0x0015 - visibility reg */
90 #define CS4210_DAC_NID 0x02
91 #define CS4210_ADC_NID 0x03
92 #define CS4210_VENDOR_NID 0x0B
93 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
94 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
96 #define CS421X_IDX_DEV_CFG 0x01
97 #define CS421X_IDX_ADC_CFG 0x02
98 #define CS421X_IDX_DAC_CFG 0x03
99 #define CS421X_IDX_SPK_CTL 0x04
102 #define CS4213_VENDOR_NID 0x09
105 static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx) in cs_vendor_coef_get() argument
107 struct cs_spec *spec = codec->spec; in cs_vendor_coef_get()
109 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_get()
111 return snd_hda_codec_read(codec, spec->vendor_nid, 0, in cs_vendor_coef_get()
112 AC_VERB_GET_PROC_COEF, 0); in cs_vendor_coef_get()
115 static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, in cs_vendor_coef_set() argument
118 struct cs_spec *spec = codec->spec; in cs_vendor_coef_set()
120 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_set()
122 snd_hda_codec_write(codec, spec->vendor_nid, 0, in cs_vendor_coef_set()
127 * auto-mute and auto-mic switching
128 * CS421x auto-output redirecting
132 static void cs_automute(struct hda_codec *codec) in cs_automute() argument
134 struct cs_spec *spec = codec->spec; in cs_automute()
137 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b); in cs_automute()
139 snd_hda_gen_update_outputs(codec); in cs_automute()
141 if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) { in cs_automute()
142 if (spec->gen.automute_speaker) in cs_automute()
143 spec->gpio_data = spec->gen.hp_jack_present ? in cs_automute()
144 spec->gpio_eapd_hp : spec->gpio_eapd_speaker; in cs_automute()
146 spec->gpio_data = in cs_automute()
147 spec->gpio_eapd_hp | spec->gpio_eapd_speaker; in cs_automute()
148 snd_hda_codec_write(codec, 0x01, 0, in cs_automute()
149 AC_VERB_SET_GPIO_DATA, spec->gpio_data); in cs_automute()
153 static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid) in is_active_pin() argument
157 val = snd_hda_codec_get_pincfg(codec, nid); in is_active_pin()
161 static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid) in cs_alloc_spec() argument
168 codec->spec = spec; in cs_alloc_spec()
169 spec->vendor_nid = vendor_nid; in cs_alloc_spec()
170 codec->power_save_node = 1; in cs_alloc_spec()
171 snd_hda_gen_spec_init(&spec->gen); in cs_alloc_spec()
193 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
200 { 0x05, 0x0321401f },
201 { 0x06, 0x90170010 },
202 { 0x07, 0x03813031 },
203 { 0x08, 0xb7a70037 },
204 { 0x09, 0xb7a6003e },
205 { 0x0a, 0x034510f0 },
211 { 0x05, 0x022120f0 },
212 { 0x06, 0x901700f0 },
213 { 0x07, 0x02a120f0 },
214 { 0x08, 0x77a70037 },
215 { 0x09, 0x77a6003e },
216 { 0x0a, 0x434510f0 },
221 static void cs421x_fixup_sense_b(struct hda_codec *codec, in cs421x_fixup_sense_b() argument
224 struct cs_spec *spec = codec->spec; in cs421x_fixup_sense_b()
227 spec->sense_b = 1; in cs421x_fixup_sense_b()
248 {0x0B, AC_VERB_SET_PROC_STATE, 1},
249 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
251 * Disable Coefficient Index Auto-Increment(DAI)=1,
252 * PDREF=0
254 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
256 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
258 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
260 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
261 {0x0B, AC_VERB_SET_PROC_COEF,
262 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
263 | 0x0004 /* Mute DAC on FIFO error */
264 | 0x0008 /* Enable DAC High Pass Filter */
285 {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
287 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
288 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
290 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
291 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
293 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
294 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
296 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
297 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
299 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
300 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
306 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
311 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in cs421x_boost_vol_info()
312 uinfo->count = 1; in cs421x_boost_vol_info()
313 uinfo->value.integer.min = 0; in cs421x_boost_vol_info()
314 uinfo->value.integer.max = 3; in cs421x_boost_vol_info()
315 return 0; in cs421x_boost_vol_info()
321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in cs421x_boost_vol_get() local
323 ucontrol->value.integer.value[0] = in cs421x_boost_vol_get()
324 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003; in cs421x_boost_vol_get()
325 return 0; in cs421x_boost_vol_get()
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in cs421x_boost_vol_put() local
333 unsigned int vol = ucontrol->value.integer.value[0]; in cs421x_boost_vol_put()
335 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL); in cs421x_boost_vol_put()
338 coef &= ~0x0003; in cs421x_boost_vol_put()
339 coef |= (vol & 0x0003); in cs421x_boost_vol_put()
341 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef); in cs421x_boost_vol_put()
345 return 0; in cs421x_boost_vol_put()
360 static void cs4210_pinmux_init(struct hda_codec *codec) in cs4210_pinmux_init() argument
362 struct cs_spec *spec = codec->spec; in cs4210_pinmux_init()
366 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); in cs4210_pinmux_init()
368 if (spec->gpio_mask) in cs4210_pinmux_init()
369 coef |= 0x0008; /* B1,B2 are GPIOs */ in cs4210_pinmux_init()
371 coef &= ~0x0008; in cs4210_pinmux_init()
373 if (spec->sense_b) in cs4210_pinmux_init()
374 coef |= 0x0010; /* B2 is SENSE_B, not inverted */ in cs4210_pinmux_init()
376 coef &= ~0x0010; in cs4210_pinmux_init()
378 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); in cs4210_pinmux_init()
380 if ((spec->gpio_mask || spec->sense_b) && in cs4210_pinmux_init()
381 is_active_pin(codec, CS421X_DMIC_PIN_NID)) { in cs4210_pinmux_init()
384 * GPIO or SENSE_B forced - disconnect the DMIC pin. in cs4210_pinmux_init()
386 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID); in cs4210_pinmux_init()
389 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf); in cs4210_pinmux_init()
393 static void cs4210_spdif_automute(struct hda_codec *codec, in cs4210_spdif_automute() argument
396 struct cs_spec *spec = codec->spec; in cs4210_spdif_automute()
398 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0]; in cs4210_spdif_automute()
401 if (!spec->spdif_detect || in cs4210_spdif_automute()
402 spec->vendor_nid != CS4210_VENDOR_NID) in cs4210_spdif_automute()
405 spdif_present = snd_hda_jack_detect(codec, spdif_pin); in cs4210_spdif_automute()
406 if (spdif_present == spec->spdif_present) in cs4210_spdif_automute()
409 spec->spdif_present = spdif_present; in cs4210_spdif_automute()
411 snd_hda_set_pin_ctl(codec, spdif_pin, spdif_present ? PIN_OUT : 0); in cs4210_spdif_automute()
413 cs_automute(codec); in cs4210_spdif_automute()
416 static void parse_cs421x_digital(struct hda_codec *codec) in parse_cs421x_digital() argument
418 struct cs_spec *spec = codec->spec; in parse_cs421x_digital()
419 struct auto_pin_cfg *cfg = &spec->gen.autocfg; in parse_cs421x_digital()
422 for (i = 0; i < cfg->dig_outs; i++) { in parse_cs421x_digital()
423 hda_nid_t nid = cfg->dig_out_pins[i]; in parse_cs421x_digital()
425 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { in parse_cs421x_digital()
426 spec->spdif_detect = 1; in parse_cs421x_digital()
427 snd_hda_jack_detect_enable_callback(codec, nid, in parse_cs421x_digital()
433 static int cs421x_init(struct hda_codec *codec) in cs421x_init() argument
435 struct cs_spec *spec = codec->spec; in cs421x_init()
437 if (spec->vendor_nid == CS4210_VENDOR_NID) { in cs421x_init()
438 snd_hda_sequence_write(codec, cs421x_coef_init_verbs); in cs421x_init()
439 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes); in cs421x_init()
440 cs4210_pinmux_init(codec); in cs421x_init()
443 snd_hda_gen_init(codec); in cs421x_init()
445 if (spec->gpio_mask) { in cs421x_init()
446 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, in cs421x_init()
447 spec->gpio_mask); in cs421x_init()
448 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, in cs421x_init()
449 spec->gpio_dir); in cs421x_init()
450 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, in cs421x_init()
451 spec->gpio_data); in cs421x_init()
454 cs4210_spdif_automute(codec, NULL); in cs421x_init()
456 return 0; in cs421x_init()
459 static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) in fix_volume_caps() argument
463 /* set the upper-limit for mixer amp to 0dB */ in fix_volume_caps()
464 caps = query_amp_caps(codec, dac, HDA_OUTPUT); in fix_volume_caps()
465 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); in fix_volume_caps()
466 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) in fix_volume_caps()
468 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); in fix_volume_caps()
471 static int cs421x_parse_auto_config(struct hda_codec *codec) in cs421x_parse_auto_config() argument
473 struct cs_spec *spec = codec->spec; in cs421x_parse_auto_config()
477 fix_volume_caps(codec, dac); in cs421x_parse_auto_config()
479 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); in cs421x_parse_auto_config()
480 if (err < 0) in cs421x_parse_auto_config()
483 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); in cs421x_parse_auto_config()
484 if (err < 0) in cs421x_parse_auto_config()
487 parse_cs421x_digital(codec); in cs421x_parse_auto_config()
489 if (spec->gen.autocfg.speaker_outs && in cs421x_parse_auto_config()
490 spec->vendor_nid == CS4210_VENDOR_NID) { in cs421x_parse_auto_config()
491 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, in cs421x_parse_auto_config()
493 return -ENOMEM; in cs421x_parse_auto_config()
496 return 0; in cs421x_parse_auto_config()
501 * (DAC,ADC) -> D3, PDREF=1, AFG->D3
503 static int cs421x_suspend(struct hda_codec *codec) in cs421x_suspend() argument
505 struct cs_spec *spec = codec->spec; in cs421x_suspend()
508 snd_hda_shutup_pins(codec); in cs421x_suspend()
510 snd_hda_codec_write(codec, CS4210_DAC_NID, 0, in cs421x_suspend()
512 snd_hda_codec_write(codec, CS4210_ADC_NID, 0, in cs421x_suspend()
515 if (spec->vendor_nid == CS4210_VENDOR_NID) { in cs421x_suspend()
516 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); in cs421x_suspend()
517 coef |= 0x0004; /* PDREF */ in cs421x_suspend()
518 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); in cs421x_suspend()
521 return 0; in cs421x_suspend()
524 static int cs421x_probe(struct hda_codec *codec, const struct hda_device_id *id) in cs421x_probe() argument
529 spec = cs_alloc_spec(codec, id->driver_data); in cs421x_probe()
531 return -ENOMEM; in cs421x_probe()
533 spec->gen.automute_hook = cs_automute; in cs421x_probe()
535 if (spec->vendor_nid == CS4210_VENDOR_NID) { in cs421x_probe()
536 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, in cs421x_probe()
538 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); in cs421x_probe()
542 * is auto-parsed. If GPIO or SENSE_B is forced, DMIC input in cs421x_probe()
545 cs4210_pinmux_init(codec); in cs421x_probe()
548 err = cs421x_parse_auto_config(codec); in cs421x_probe()
549 if (err < 0) in cs421x_probe()
552 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); in cs421x_probe()
554 return 0; in cs421x_probe()
557 snd_hda_gen_remove(codec); in cs421x_probe()
576 HDA_CODEC_ID_MODEL(0x10134210, "CS4210", CS4210_VENDOR_NID),
577 HDA_CODEC_ID_MODEL(0x10134213, "CS4213", CS4213_VENDOR_NID),
583 MODULE_DESCRIPTION("Cirrus Logic CS421x HD-audio codec");