1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * HD audio codec driver for Conexant HDA audio codec
4 *
5 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
6 * Takashi Iwai <tiwai@suse.de>
7 * Tobin Davis <tdavis@dsl-only.net>
8 */
9
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16
17 #include <sound/hda_codec.h>
18 #include "hda_local.h"
19 #include "hda_auto_parser.h"
20 #include "hda_beep.h"
21 #include "hda_jack.h"
22 #include "generic.h"
23
24 struct conexant_spec {
25 struct hda_gen_spec gen;
26
27 /* extra EAPD pins */
28 unsigned int num_eapds;
29 hda_nid_t eapds[4];
30 bool dynamic_eapd;
31 hda_nid_t mute_led_eapd;
32
33 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
34
35 /* OLPC XO specific */
36 bool recording;
37 bool dc_enable;
38 unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
39 struct nid_path *dc_mode_path;
40
41 int mute_led_polarity;
42 unsigned int gpio_led;
43 unsigned int gpio_mute_led_mask;
44 unsigned int gpio_mic_led_mask;
45 bool is_cx11880_sn6140;
46 };
47
48
49 #ifdef CONFIG_SND_HDA_INPUT_BEEP
50 /* additional beep mixers; private_value will be overwritten */
51 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
52 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
53 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
54 };
55
set_beep_amp(struct conexant_spec * spec,hda_nid_t nid,int idx,int dir)56 static int set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
57 int idx, int dir)
58 {
59 struct snd_kcontrol_new *knew;
60 unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
61 int i;
62
63 spec->gen.beep_nid = nid;
64 for (i = 0; i < ARRAY_SIZE(cxt_beep_mixer); i++) {
65 knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
66 &cxt_beep_mixer[i]);
67 if (!knew)
68 return -ENOMEM;
69 knew->private_value = beep_amp;
70 }
71 return 0;
72 }
73
cx_auto_parse_beep(struct hda_codec * codec)74 static int cx_auto_parse_beep(struct hda_codec *codec)
75 {
76 struct conexant_spec *spec = codec->spec;
77 hda_nid_t nid;
78
79 for_each_hda_codec_node(nid, codec)
80 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
81 return set_beep_amp(spec, nid, 0, HDA_OUTPUT);
82 return 0;
83 }
84 #else
85 #define cx_auto_parse_beep(codec) 0
86 #endif
87
88 /*
89 * Automatic parser for CX20641 & co
90 */
91
92 /* parse EAPDs */
cx_auto_parse_eapd(struct hda_codec * codec)93 static void cx_auto_parse_eapd(struct hda_codec *codec)
94 {
95 struct conexant_spec *spec = codec->spec;
96 hda_nid_t nid;
97
98 for_each_hda_codec_node(nid, codec) {
99 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
100 continue;
101 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
102 continue;
103 spec->eapds[spec->num_eapds++] = nid;
104 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
105 break;
106 }
107
108 /* NOTE: below is a wild guess; if we have more than two EAPDs,
109 * it's a new chip, where EAPDs are supposed to be associated to
110 * pins, and we can control EAPD per pin.
111 * OTOH, if only one or two EAPDs are found, it's an old chip,
112 * thus it might control over all pins.
113 */
114 if (spec->num_eapds > 2)
115 spec->dynamic_eapd = 1;
116 }
117
cx_auto_turn_eapd(struct hda_codec * codec,int num_pins,const hda_nid_t * pins,bool on)118 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
119 const hda_nid_t *pins, bool on)
120 {
121 int i;
122 for (i = 0; i < num_pins; i++) {
123 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
124 snd_hda_codec_write(codec, pins[i], 0,
125 AC_VERB_SET_EAPD_BTLENABLE,
126 on ? 0x02 : 0);
127 }
128 }
129
130 /* turn on/off EAPD according to Master switch */
cx_auto_vmaster_hook(void * private_data,int enabled)131 static void cx_auto_vmaster_hook(void *private_data, int enabled)
132 {
133 struct hda_codec *codec = private_data;
134 struct conexant_spec *spec = codec->spec;
135
136 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
137 }
138
139 /* turn on/off EAPD according to Master switch (inversely!) for mute LED */
cx_auto_vmaster_mute_led(struct led_classdev * led_cdev,enum led_brightness brightness)140 static int cx_auto_vmaster_mute_led(struct led_classdev *led_cdev,
141 enum led_brightness brightness)
142 {
143 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
144 struct conexant_spec *spec = codec->spec;
145
146 snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
147 AC_VERB_SET_EAPD_BTLENABLE,
148 brightness ? 0x02 : 0x00);
149 return 0;
150 }
151
cxt_init_gpio_led(struct hda_codec * codec)152 static void cxt_init_gpio_led(struct hda_codec *codec)
153 {
154 struct conexant_spec *spec = codec->spec;
155 unsigned int mask = spec->gpio_mute_led_mask | spec->gpio_mic_led_mask;
156
157 if (mask)
158 snd_hda_codec_set_gpio(codec, mask, mask, spec->gpio_led, 0);
159 }
160
cx_fixup_headset_recog(struct hda_codec * codec)161 static void cx_fixup_headset_recog(struct hda_codec *codec)
162 {
163 unsigned int mic_present;
164
165 /* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias register
166 * value adjustment trim from 2.2K ohms to 2.0K ohms.
167 */
168 snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
169 /* fix reboot headset type recognize fail issue */
170 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0);
171 if (mic_present & AC_PINSENSE_PRESENCE)
172 /* enable headset mic VREF */
173 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
174 else
175 /* disable headset mic VREF */
176 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
177 }
178
cx_init(struct hda_codec * codec)179 static int cx_init(struct hda_codec *codec)
180 {
181 struct conexant_spec *spec = codec->spec;
182 snd_hda_gen_init(codec);
183 if (!spec->dynamic_eapd)
184 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
185
186 cxt_init_gpio_led(codec);
187 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
188
189 if (spec->is_cx11880_sn6140)
190 cx_fixup_headset_recog(codec);
191
192 return 0;
193 }
194
cx_auto_shutdown(struct hda_codec * codec)195 static void cx_auto_shutdown(struct hda_codec *codec)
196 {
197 struct conexant_spec *spec = codec->spec;
198
199 /* Turn the problematic codec into D3 to avoid spurious noises
200 from the internal speaker during (and after) reboot */
201 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
202 }
203
cx_remove(struct hda_codec * codec)204 static void cx_remove(struct hda_codec *codec)
205 {
206 cx_auto_shutdown(codec);
207 snd_hda_gen_remove(codec);
208 }
209
cx_process_headset_detect_plug_type(struct hda_codec * codec)210 static void cx_process_headset_detect_plug_type(struct hda_codec *codec)
211 {
212 unsigned int val;
213 unsigned int count = 0;
214
215 /* Wait headset detect done. */
216 do {
217 val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);
218 if (val & 0x080) {
219 codec_dbg(codec, "headset type detect done!\n");
220 break;
221 }
222 msleep(20);
223 count++;
224 } while (count < 3);
225 val = snd_hda_codec_read(codec, 0x1c, 0, 0xcb0, 0x0);
226 if (val & 0xc00) {
227 codec_dbg(codec, "headset plugin, type is %s\n",
228 val & 0x800 ? "CTIA" : "OMTP");
229 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
230 } else {
231 codec_dbg(codec, "headphone plugin\n");
232 }
233 }
234
cx_update_headset_mic_vref(struct hda_codec * codec,struct hda_jack_callback * event)235 static void cx_update_headset_mic_vref(struct hda_codec *codec, struct hda_jack_callback *event)
236 {
237 unsigned int mic_present;
238
239 /* In cx11880 and sn6140, the node 16 can only be configured to headphone or disabled,
240 * the node 19 can only be configured to microphone or disabled.
241 * Check hp&mic tag to process headset plugin & plugout.
242 */
243 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0);
244 if (!(mic_present & AC_PINSENSE_PRESENCE)) { /* mic plugout */
245 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
246 } else {
247 cx_process_headset_detect_plug_type(codec);
248 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
249 }
250 }
251
252 #define SN6140_S3_AFG_D0_DELAY_MS 1000
253
cx_set_power_state(struct hda_codec * codec,hda_nid_t fg,unsigned int power_state)254 static void cx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
255 unsigned int power_state)
256 {
257 snd_hda_codec_write_sync(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
258
259 /*
260 * SN6140 may not respond to AFG D0 immediately after S3.
261 * Wait before the D0 verb so the power-state command itself succeeds.
262 */
263 if (codec->core.vendor_id == 0x14f11f87 &&
264 power_state == AC_PWRST_D0 &&
265 codec->core.dev.power.power_state.event == PM_EVENT_RESUME)
266 msleep(SN6140_S3_AFG_D0_DELAY_MS);
267
268 snd_hda_codec_set_power_to_all(codec, fg, power_state);
269 }
270
cx_suspend(struct hda_codec * codec)271 static int cx_suspend(struct hda_codec *codec)
272 {
273 cx_auto_shutdown(codec);
274 return 0;
275 }
276
277 /*
278 * pin fix-up
279 */
280 enum {
281 CXT_PINCFG_LENOVO_X200,
282 CXT_PINCFG_LENOVO_TP410,
283 CXT_PINCFG_LEMOTE_A1004,
284 CXT_PINCFG_LEMOTE_A1205,
285 CXT_PINCFG_COMPAQ_CQ60,
286 CXT_FIXUP_STEREO_DMIC,
287 CXT_PINCFG_LENOVO_NOTEBOOK,
288 CXT_FIXUP_INC_MIC_BOOST,
289 CXT_FIXUP_HEADPHONE_MIC_PIN,
290 CXT_FIXUP_HEADPHONE_MIC,
291 CXT_FIXUP_GPIO1,
292 CXT_FIXUP_ASPIRE_DMIC,
293 CXT_FIXUP_THINKPAD_ACPI,
294 CXT_FIXUP_LENOVO_XPAD_ACPI,
295 CXT_FIXUP_OLPC_XO,
296 CXT_FIXUP_CAP_MIX_AMP,
297 CXT_FIXUP_TOSHIBA_P105,
298 CXT_FIXUP_HP_530,
299 CXT_FIXUP_CAP_MIX_AMP_5047,
300 CXT_FIXUP_MUTE_LED_EAPD,
301 CXT_FIXUP_HP_DOCK,
302 CXT_FIXUP_HP_SPECTRE,
303 CXT_FIXUP_HP_GATE_MIC,
304 CXT_FIXUP_MUTE_LED_GPIO,
305 CXT_FIXUP_HP_ELITEONE_OUT_DIS,
306 CXT_FIXUP_HP_ZBOOK_MUTE_LED,
307 CXT_FIXUP_HEADSET_MIC,
308 CXT_FIXUP_HP_MIC_NO_PRESENCE,
309 CXT_PINCFG_SWS_JS201D,
310 CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10,
311 CXT_PINCFG_TOP_SPEAKER,
312 CXT_FIXUP_HP_A_U,
313 CXT_FIXUP_ACER_SWIFT_HP,
314 CXT_FIXUP_HUAWEI_MATEBOOK_HP,
315 };
316
317 /* for hda_fixup_thinkpad_acpi() */
318 #include "helpers/thinkpad.c"
319
320 /* for hda_fixup_ideapad_acpi() */
321 #include "helpers/ideapad_hotkey_led.c"
322
cxt_fixup_stereo_dmic(struct hda_codec * codec,const struct hda_fixup * fix,int action)323 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
324 const struct hda_fixup *fix, int action)
325 {
326 struct conexant_spec *spec = codec->spec;
327 spec->gen.inv_dmic_split = 1;
328 }
329
330 /* fix widget control pin settings */
cxt_fixup_update_pinctl(struct hda_codec * codec,const struct hda_fixup * fix,int action)331 static void cxt_fixup_update_pinctl(struct hda_codec *codec,
332 const struct hda_fixup *fix, int action)
333 {
334 if (action == HDA_FIXUP_ACT_PROBE) {
335 /* Unset OUT_EN for this Node pin, leaving only HP_EN.
336 * This is the value stored in the codec register after
337 * the correct initialization of the previous windows boot.
338 */
339 snd_hda_set_pin_ctl_cache(codec, 0x1d, AC_PINCTL_HP_EN);
340 }
341 }
342
cxt5066_increase_mic_boost(struct hda_codec * codec,const struct hda_fixup * fix,int action)343 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
344 const struct hda_fixup *fix, int action)
345 {
346 if (action != HDA_FIXUP_ACT_PRE_PROBE)
347 return;
348
349 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
350 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
351 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
352 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
353 (0 << AC_AMPCAP_MUTE_SHIFT));
354 }
355
cxt_update_headset_mode(struct hda_codec * codec)356 static void cxt_update_headset_mode(struct hda_codec *codec)
357 {
358 /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
359 int i;
360 bool mic_mode = false;
361 struct conexant_spec *spec = codec->spec;
362 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
363
364 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
365
366 for (i = 0; i < cfg->num_inputs; i++)
367 if (cfg->inputs[i].pin == mux_pin) {
368 mic_mode = !!cfg->inputs[i].is_headphone_mic;
369 break;
370 }
371
372 if (mic_mode) {
373 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
374 spec->gen.hp_jack_present = false;
375 } else {
376 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
377 spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
378 }
379
380 snd_hda_gen_update_outputs(codec);
381 }
382
cxt_update_headset_mode_hook(struct hda_codec * codec,struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)383 static void cxt_update_headset_mode_hook(struct hda_codec *codec,
384 struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
386 {
387 cxt_update_headset_mode(codec);
388 }
389
cxt_fixup_headphone_mic(struct hda_codec * codec,const struct hda_fixup * fix,int action)390 static void cxt_fixup_headphone_mic(struct hda_codec *codec,
391 const struct hda_fixup *fix, int action)
392 {
393 struct conexant_spec *spec = codec->spec;
394
395 switch (action) {
396 case HDA_FIXUP_ACT_PRE_PROBE:
397 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
398 snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
399 break;
400 case HDA_FIXUP_ACT_PROBE:
401 WARN_ON(spec->gen.cap_sync_hook);
402 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
403 spec->gen.automute_hook = cxt_update_headset_mode;
404 break;
405 case HDA_FIXUP_ACT_INIT:
406 cxt_update_headset_mode(codec);
407 break;
408 }
409 }
410
cxt_fixup_headset_mic(struct hda_codec * codec,const struct hda_fixup * fix,int action)411 static void cxt_fixup_headset_mic(struct hda_codec *codec,
412 const struct hda_fixup *fix, int action)
413 {
414 struct conexant_spec *spec = codec->spec;
415
416 switch (action) {
417 case HDA_FIXUP_ACT_PRE_PROBE:
418 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
419 break;
420 }
421 }
422
423 /* OLPC XO 1.5 fixup */
424
425 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
426 * through the microphone jack.
427 * When the user enables this through a mixer switch, both internal and
428 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
429 * we also allow the bias to be configured through a separate mixer
430 * control. */
431
432 #define update_mic_pin(codec, nid, val) \
433 snd_hda_codec_write_cache(codec, nid, 0, \
434 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
435
436 static const struct hda_input_mux olpc_xo_dc_bias = {
437 .num_items = 3,
438 .items = {
439 { "Off", PIN_IN },
440 { "50%", PIN_VREF50 },
441 { "80%", PIN_VREF80 },
442 },
443 };
444
olpc_xo_update_mic_boost(struct hda_codec * codec)445 static void olpc_xo_update_mic_boost(struct hda_codec *codec)
446 {
447 struct conexant_spec *spec = codec->spec;
448 int ch, val;
449
450 for (ch = 0; ch < 2; ch++) {
451 val = AC_AMP_SET_OUTPUT |
452 (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
453 if (!spec->dc_enable)
454 val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
455 snd_hda_codec_write(codec, 0x17, 0,
456 AC_VERB_SET_AMP_GAIN_MUTE, val);
457 }
458 }
459
olpc_xo_update_mic_pins(struct hda_codec * codec)460 static void olpc_xo_update_mic_pins(struct hda_codec *codec)
461 {
462 struct conexant_spec *spec = codec->spec;
463 int cur_input, val;
464 struct nid_path *path;
465
466 cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
467
468 /* Set up mic pins for port-B, C and F dynamically as the recording
469 * LED is turned on/off by these pin controls
470 */
471 if (!spec->dc_enable) {
472 /* disable DC bias path and pin for port F */
473 update_mic_pin(codec, 0x1e, 0);
474 if (spec->dc_mode_path)
475 snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
476
477 /* update port B (ext mic) and C (int mic) */
478 /* OLPC defers mic widget control until when capture is
479 * started because the microphone LED comes on as soon as
480 * these settings are put in place. if we did this before
481 * recording, it would give the false indication that
482 * recording is happening when it is not.
483 */
484 update_mic_pin(codec, 0x1a, spec->recording ?
485 snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
486 update_mic_pin(codec, 0x1b, spec->recording ?
487 snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
488 /* enable normal mic path */
489 path = snd_hda_get_path_from_idx(codec, cur_input);
490 if (path)
491 snd_hda_activate_path(codec, path, true, false);
492 } else {
493 /* disable normal mic path */
494 path = snd_hda_get_path_from_idx(codec, cur_input);
495 if (path)
496 snd_hda_activate_path(codec, path, false, false);
497
498 /* Even though port F is the DC input, the bias is controlled
499 * on port B. We also leave that port as an active input (but
500 * unselected) in DC mode just in case that is necessary to
501 * make the bias setting take effect.
502 */
503 if (spec->recording)
504 val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
505 else
506 val = 0;
507 update_mic_pin(codec, 0x1a, val);
508 update_mic_pin(codec, 0x1b, 0);
509 /* enable DC bias path and pin */
510 update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
511 if (spec->dc_mode_path)
512 snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
513 }
514 }
515
516 /* mic_autoswitch hook */
olpc_xo_automic(struct hda_codec * codec,struct hda_jack_callback * jack)517 static void olpc_xo_automic(struct hda_codec *codec,
518 struct hda_jack_callback *jack)
519 {
520 struct conexant_spec *spec = codec->spec;
521
522 /* in DC mode, we don't handle automic */
523 if (!spec->dc_enable)
524 snd_hda_gen_mic_autoswitch(codec, jack);
525 olpc_xo_update_mic_pins(codec);
526 if (spec->dc_enable)
527 olpc_xo_update_mic_boost(codec);
528 }
529
530 /* pcm_capture hook */
olpc_xo_capture_hook(struct hda_pcm_stream * hinfo,struct hda_codec * codec,struct snd_pcm_substream * substream,int action)531 static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
532 struct hda_codec *codec,
533 struct snd_pcm_substream *substream,
534 int action)
535 {
536 struct conexant_spec *spec = codec->spec;
537
538 /* toggle spec->recording flag and update mic pins accordingly
539 * for turning on/off LED
540 */
541 switch (action) {
542 case HDA_GEN_PCM_ACT_PREPARE:
543 spec->recording = 1;
544 olpc_xo_update_mic_pins(codec);
545 break;
546 case HDA_GEN_PCM_ACT_CLEANUP:
547 spec->recording = 0;
548 olpc_xo_update_mic_pins(codec);
549 break;
550 }
551 }
552
olpc_xo_dc_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)553 static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
554 struct snd_ctl_elem_value *ucontrol)
555 {
556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557 struct conexant_spec *spec = codec->spec;
558 ucontrol->value.integer.value[0] = spec->dc_enable;
559 return 0;
560 }
561
olpc_xo_dc_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)562 static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol)
564 {
565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
566 struct conexant_spec *spec = codec->spec;
567 int dc_enable = !!ucontrol->value.integer.value[0];
568
569 if (dc_enable == spec->dc_enable)
570 return 0;
571
572 spec->dc_enable = dc_enable;
573 olpc_xo_update_mic_pins(codec);
574 olpc_xo_update_mic_boost(codec);
575 return 1;
576 }
577
olpc_xo_dc_bias_enum_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)578 static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
579 struct snd_ctl_elem_value *ucontrol)
580 {
581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582 struct conexant_spec *spec = codec->spec;
583 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
584 return 0;
585 }
586
olpc_xo_dc_bias_enum_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)587 static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
588 struct snd_ctl_elem_info *uinfo)
589 {
590 return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
591 }
592
olpc_xo_dc_bias_enum_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)593 static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
594 struct snd_ctl_elem_value *ucontrol)
595 {
596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
597 struct conexant_spec *spec = codec->spec;
598 const struct hda_input_mux *imux = &olpc_xo_dc_bias;
599 unsigned int idx;
600
601 idx = ucontrol->value.enumerated.item[0];
602 if (idx >= imux->num_items)
603 idx = imux->num_items - 1;
604 if (spec->dc_input_bias == idx)
605 return 0;
606
607 spec->dc_input_bias = idx;
608 if (spec->dc_enable)
609 olpc_xo_update_mic_pins(codec);
610 return 1;
611 }
612
613 static const struct snd_kcontrol_new olpc_xo_mixers[] = {
614 {
615 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
616 .name = "DC Mode Enable Switch",
617 .info = snd_ctl_boolean_mono_info,
618 .get = olpc_xo_dc_mode_get,
619 .put = olpc_xo_dc_mode_put,
620 },
621 {
622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
623 .name = "DC Input Bias Enum",
624 .info = olpc_xo_dc_bias_enum_info,
625 .get = olpc_xo_dc_bias_enum_get,
626 .put = olpc_xo_dc_bias_enum_put,
627 },
628 {}
629 };
630
631 /* overriding mic boost put callback; update mic boost volume only when
632 * DC mode is disabled
633 */
olpc_xo_mic_boost_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)634 static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636 {
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
639 int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
640 if (ret > 0 && spec->dc_enable)
641 olpc_xo_update_mic_boost(codec);
642 return ret;
643 }
644
cxt_fixup_olpc_xo(struct hda_codec * codec,const struct hda_fixup * fix,int action)645 static void cxt_fixup_olpc_xo(struct hda_codec *codec,
646 const struct hda_fixup *fix, int action)
647 {
648 struct conexant_spec *spec = codec->spec;
649 struct snd_kcontrol_new *kctl;
650 int i;
651
652 if (action != HDA_FIXUP_ACT_PROBE)
653 return;
654
655 spec->gen.mic_autoswitch_hook = olpc_xo_automic;
656 spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
657 spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
658
659 snd_hda_add_new_ctls(codec, olpc_xo_mixers);
660
661 /* OLPC's microphone port is DC coupled for use with external sensors,
662 * therefore we use a 50% mic bias in order to center the input signal
663 * with the DC input range of the codec.
664 */
665 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
666
667 /* override mic boost control */
668 snd_array_for_each(&spec->gen.kctls, i, kctl) {
669 if (!strcmp(kctl->name, "Mic Boost Volume")) {
670 kctl->put = olpc_xo_mic_boost_put;
671 break;
672 }
673 }
674 }
675
cxt_fixup_mute_led_eapd(struct hda_codec * codec,const struct hda_fixup * fix,int action)676 static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
677 const struct hda_fixup *fix, int action)
678 {
679 struct conexant_spec *spec = codec->spec;
680
681 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
682 spec->mute_led_eapd = 0x1b;
683 spec->dynamic_eapd = true;
684 snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led);
685 }
686 }
687
688 /*
689 * Fix max input level on mixer widget to 0dB
690 * (originally it has 0x2b steps with 0dB offset 0x14)
691 */
cxt_fixup_cap_mix_amp(struct hda_codec * codec,const struct hda_fixup * fix,int action)692 static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
693 const struct hda_fixup *fix, int action)
694 {
695 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
696 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
697 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
698 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
699 (1 << AC_AMPCAP_MUTE_SHIFT));
700 }
701
702 /*
703 * Fix max input level on mixer widget to 0dB
704 * (originally it has 0x1e steps with 0 dB offset 0x17)
705 */
cxt_fixup_cap_mix_amp_5047(struct hda_codec * codec,const struct hda_fixup * fix,int action)706 static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
707 const struct hda_fixup *fix, int action)
708 {
709 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
710 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
711 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
712 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
713 (1 << AC_AMPCAP_MUTE_SHIFT));
714 }
715
cxt_fixup_hp_gate_mic_jack(struct hda_codec * codec,const struct hda_fixup * fix,int action)716 static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec,
717 const struct hda_fixup *fix,
718 int action)
719 {
720 /* the mic pin (0x19) doesn't give an unsolicited event;
721 * probe the mic pin together with the headphone pin (0x16)
722 */
723 if (action == HDA_FIXUP_ACT_PROBE)
724 snd_hda_jack_set_gating_jack(codec, 0x19, 0x16);
725 }
726
727 /* update LED status via GPIO */
cxt_update_gpio_led(struct hda_codec * codec,unsigned int mask,bool led_on)728 static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
729 bool led_on)
730 {
731 struct conexant_spec *spec = codec->spec;
732 unsigned int oldval = spec->gpio_led;
733
734 if (spec->mute_led_polarity)
735 led_on = !led_on;
736
737 if (led_on)
738 spec->gpio_led |= mask;
739 else
740 spec->gpio_led &= ~mask;
741 codec_dbg(codec, "mask:%d enabled:%d gpio_led:%d\n",
742 mask, led_on, spec->gpio_led);
743 if (spec->gpio_led != oldval)
744 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
745 spec->gpio_led);
746 }
747
748 /* turn on/off mute LED via GPIO per vmaster hook */
cxt_gpio_mute_update(struct led_classdev * led_cdev,enum led_brightness brightness)749 static int cxt_gpio_mute_update(struct led_classdev *led_cdev,
750 enum led_brightness brightness)
751 {
752 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
753 struct conexant_spec *spec = codec->spec;
754
755 cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness);
756 return 0;
757 }
758
759 /* turn on/off mic-mute LED via GPIO per capture hook */
cxt_gpio_micmute_update(struct led_classdev * led_cdev,enum led_brightness brightness)760 static int cxt_gpio_micmute_update(struct led_classdev *led_cdev,
761 enum led_brightness brightness)
762 {
763 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
764 struct conexant_spec *spec = codec->spec;
765
766 cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness);
767 return 0;
768 }
769
cxt_setup_mute_led(struct hda_codec * codec,unsigned int mute,unsigned int mic_mute)770 static void cxt_setup_mute_led(struct hda_codec *codec,
771 unsigned int mute, unsigned int mic_mute)
772 {
773 struct conexant_spec *spec = codec->spec;
774
775 spec->gpio_led = 0;
776 spec->mute_led_polarity = 0;
777 if (mute) {
778 snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update);
779 spec->gpio_mute_led_mask = mute;
780 }
781 if (mic_mute) {
782 snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update);
783 spec->gpio_mic_led_mask = mic_mute;
784 }
785 }
786
cxt_setup_gpio_unmute(struct hda_codec * codec,unsigned int gpio_mute_mask)787 static void cxt_setup_gpio_unmute(struct hda_codec *codec,
788 unsigned int gpio_mute_mask)
789 {
790 if (gpio_mute_mask) {
791 // set gpio data to 0.
792 snd_hda_codec_set_gpio(codec, gpio_mute_mask, gpio_mute_mask, 0, 0);
793 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_STICKY_MASK, 0);
794 }
795 }
796
cxt_fixup_mute_led_gpio(struct hda_codec * codec,const struct hda_fixup * fix,int action)797 static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
798 const struct hda_fixup *fix, int action)
799 {
800 if (action == HDA_FIXUP_ACT_PRE_PROBE)
801 cxt_setup_mute_led(codec, 0x01, 0x02);
802 }
803
cxt_fixup_hp_zbook_mute_led(struct hda_codec * codec,const struct hda_fixup * fix,int action)804 static void cxt_fixup_hp_zbook_mute_led(struct hda_codec *codec,
805 const struct hda_fixup *fix, int action)
806 {
807 if (action == HDA_FIXUP_ACT_PRE_PROBE)
808 cxt_setup_mute_led(codec, 0x10, 0x20);
809 }
810
cxt_fixup_hp_a_u(struct hda_codec * codec,const struct hda_fixup * fix,int action)811 static void cxt_fixup_hp_a_u(struct hda_codec *codec,
812 const struct hda_fixup *fix, int action)
813 {
814 // Init vers in BIOS mute the spk/hp by set gpio high to avoid pop noise,
815 // so need to unmute once by clearing the gpio data when runs into the system.
816 if (action == HDA_FIXUP_ACT_INIT)
817 cxt_setup_gpio_unmute(codec, 0x2);
818 }
819
820 /* ThinkPad X200 & co with cxt5051 */
821 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
822 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
823 { 0x17, 0x21a11000 }, /* dock-mic */
824 { 0x19, 0x2121103f }, /* dock-HP */
825 { 0x1c, 0x21440100 }, /* dock SPDIF out */
826 {}
827 };
828
829 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
830 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
831 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
832 { 0x1a, 0x21a190f0 }, /* dock-mic */
833 { 0x1c, 0x212140ff }, /* dock-HP */
834 {}
835 };
836
837 /* Lemote A1004/A1205 with cxt5066 */
838 static const struct hda_pintbl cxt_pincfg_lemote[] = {
839 { 0x1a, 0x90a10020 }, /* Internal mic */
840 { 0x1b, 0x03a11020 }, /* External mic */
841 { 0x1d, 0x400101f0 }, /* Not used */
842 { 0x1e, 0x40a701f0 }, /* Not used */
843 { 0x20, 0x404501f0 }, /* Not used */
844 { 0x22, 0x404401f0 }, /* Not used */
845 { 0x23, 0x40a701f0 }, /* Not used */
846 {}
847 };
848
849 /* Lenovo IdeaPad Slim 5 16AKP10 with SN6140 */
850 static const struct hda_pintbl cxt_pincfg_lenovo_ideapad_slim5_16akp10[] = {
851 { 0x1a, 0x95a60130 }, /* Internal mic, fixed/always-connected */
852 {}
853 };
854
855 /* SuoWoSi/South-holding JS201D with sn6140 */
856 static const struct hda_pintbl cxt_pincfg_sws_js201d[] = {
857 { 0x16, 0x03211040 }, /* hp out */
858 { 0x17, 0x91170110 }, /* SPK/Class_D */
859 { 0x18, 0x95a70130 }, /* Internal mic */
860 { 0x19, 0x03a11020 }, /* Headset Mic */
861 { 0x1a, 0x40f001f0 }, /* Not used */
862 { 0x21, 0x40f001f0 }, /* Not used */
863 {}
864 };
865
866 static const struct hda_fixup cxt_fixups[] = {
867 [CXT_PINCFG_LENOVO_X200] = {
868 .type = HDA_FIXUP_PINS,
869 .v.pins = cxt_pincfg_lenovo_x200,
870 },
871 [CXT_PINCFG_LENOVO_TP410] = {
872 .type = HDA_FIXUP_PINS,
873 .v.pins = cxt_pincfg_lenovo_tp410,
874 .chained = true,
875 .chain_id = CXT_FIXUP_THINKPAD_ACPI,
876 },
877 [CXT_PINCFG_LEMOTE_A1004] = {
878 .type = HDA_FIXUP_PINS,
879 .chained = true,
880 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
881 .v.pins = cxt_pincfg_lemote,
882 },
883 [CXT_PINCFG_LEMOTE_A1205] = {
884 .type = HDA_FIXUP_PINS,
885 .v.pins = cxt_pincfg_lemote,
886 },
887 [CXT_PINCFG_COMPAQ_CQ60] = {
888 .type = HDA_FIXUP_PINS,
889 .v.pins = (const struct hda_pintbl[]) {
890 /* 0x17 was falsely set up as a mic, it should 0x1d */
891 { 0x17, 0x400001f0 },
892 { 0x1d, 0x97a70120 },
893 { }
894 }
895 },
896 [CXT_FIXUP_STEREO_DMIC] = {
897 .type = HDA_FIXUP_FUNC,
898 .v.func = cxt_fixup_stereo_dmic,
899 },
900 [CXT_PINCFG_LENOVO_NOTEBOOK] = {
901 .type = HDA_FIXUP_PINS,
902 .v.pins = (const struct hda_pintbl[]) {
903 { 0x1a, 0x05d71030 },
904 { }
905 },
906 .chain_id = CXT_FIXUP_STEREO_DMIC,
907 },
908 [CXT_FIXUP_INC_MIC_BOOST] = {
909 .type = HDA_FIXUP_FUNC,
910 .v.func = cxt5066_increase_mic_boost,
911 },
912 [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
913 .type = HDA_FIXUP_PINS,
914 .chained = true,
915 .chain_id = CXT_FIXUP_HEADPHONE_MIC,
916 .v.pins = (const struct hda_pintbl[]) {
917 { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
918 { }
919 }
920 },
921 [CXT_FIXUP_HEADPHONE_MIC] = {
922 .type = HDA_FIXUP_FUNC,
923 .v.func = cxt_fixup_headphone_mic,
924 },
925 [CXT_FIXUP_GPIO1] = {
926 .type = HDA_FIXUP_VERBS,
927 .v.verbs = (const struct hda_verb[]) {
928 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
929 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
930 { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
931 { }
932 },
933 },
934 [CXT_FIXUP_ASPIRE_DMIC] = {
935 .type = HDA_FIXUP_FUNC,
936 .v.func = cxt_fixup_stereo_dmic,
937 .chained = true,
938 .chain_id = CXT_FIXUP_GPIO1,
939 },
940 [CXT_FIXUP_THINKPAD_ACPI] = {
941 .type = HDA_FIXUP_FUNC,
942 .v.func = hda_fixup_thinkpad_acpi,
943 },
944 [CXT_FIXUP_LENOVO_XPAD_ACPI] = {
945 .type = HDA_FIXUP_FUNC,
946 .v.func = hda_fixup_ideapad_acpi,
947 .chained = true,
948 .chain_id = CXT_FIXUP_THINKPAD_ACPI,
949 },
950 [CXT_FIXUP_OLPC_XO] = {
951 .type = HDA_FIXUP_FUNC,
952 .v.func = cxt_fixup_olpc_xo,
953 },
954 [CXT_FIXUP_CAP_MIX_AMP] = {
955 .type = HDA_FIXUP_FUNC,
956 .v.func = cxt_fixup_cap_mix_amp,
957 },
958 [CXT_FIXUP_TOSHIBA_P105] = {
959 .type = HDA_FIXUP_PINS,
960 .v.pins = (const struct hda_pintbl[]) {
961 { 0x10, 0x961701f0 }, /* speaker/hp */
962 { 0x12, 0x02a1901e }, /* ext mic */
963 { 0x14, 0x95a70110 }, /* int mic */
964 {}
965 },
966 },
967 [CXT_FIXUP_HP_530] = {
968 .type = HDA_FIXUP_PINS,
969 .v.pins = (const struct hda_pintbl[]) {
970 { 0x12, 0x90a60160 }, /* int mic */
971 {}
972 },
973 .chained = true,
974 .chain_id = CXT_FIXUP_CAP_MIX_AMP,
975 },
976 [CXT_FIXUP_CAP_MIX_AMP_5047] = {
977 .type = HDA_FIXUP_FUNC,
978 .v.func = cxt_fixup_cap_mix_amp_5047,
979 },
980 [CXT_FIXUP_MUTE_LED_EAPD] = {
981 .type = HDA_FIXUP_FUNC,
982 .v.func = cxt_fixup_mute_led_eapd,
983 },
984 [CXT_FIXUP_HP_DOCK] = {
985 .type = HDA_FIXUP_PINS,
986 .v.pins = (const struct hda_pintbl[]) {
987 { 0x16, 0x21011020 }, /* line-out */
988 { 0x18, 0x2181103f }, /* line-in */
989 { }
990 },
991 .chained = true,
992 .chain_id = CXT_FIXUP_MUTE_LED_GPIO,
993 },
994 [CXT_FIXUP_HP_SPECTRE] = {
995 .type = HDA_FIXUP_PINS,
996 .v.pins = (const struct hda_pintbl[]) {
997 /* enable NID 0x1d for the speaker on top */
998 { 0x1d, 0x91170111 },
999 { }
1000 }
1001 },
1002 [CXT_FIXUP_HP_GATE_MIC] = {
1003 .type = HDA_FIXUP_FUNC,
1004 .v.func = cxt_fixup_hp_gate_mic_jack,
1005 },
1006 [CXT_FIXUP_MUTE_LED_GPIO] = {
1007 .type = HDA_FIXUP_FUNC,
1008 .v.func = cxt_fixup_mute_led_gpio,
1009 },
1010 [CXT_FIXUP_HP_ELITEONE_OUT_DIS] = {
1011 .type = HDA_FIXUP_FUNC,
1012 .v.func = cxt_fixup_update_pinctl,
1013 },
1014 [CXT_FIXUP_HP_ZBOOK_MUTE_LED] = {
1015 .type = HDA_FIXUP_FUNC,
1016 .v.func = cxt_fixup_hp_zbook_mute_led,
1017 },
1018 [CXT_FIXUP_HEADSET_MIC] = {
1019 .type = HDA_FIXUP_FUNC,
1020 .v.func = cxt_fixup_headset_mic,
1021 },
1022 [CXT_FIXUP_HP_MIC_NO_PRESENCE] = {
1023 .type = HDA_FIXUP_PINS,
1024 .v.pins = (const struct hda_pintbl[]) {
1025 { 0x1a, 0x02a1113c },
1026 { }
1027 },
1028 .chained = true,
1029 .chain_id = CXT_FIXUP_HEADSET_MIC,
1030 },
1031 [CXT_PINCFG_SWS_JS201D] = {
1032 .type = HDA_FIXUP_PINS,
1033 .v.pins = cxt_pincfg_sws_js201d,
1034 },
1035 [CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10] = {
1036 .type = HDA_FIXUP_PINS,
1037 .v.pins = cxt_pincfg_lenovo_ideapad_slim5_16akp10,
1038 },
1039 [CXT_PINCFG_TOP_SPEAKER] = {
1040 .type = HDA_FIXUP_PINS,
1041 .v.pins = (const struct hda_pintbl[]) {
1042 { 0x1d, 0x82170111 },
1043 { }
1044 },
1045 },
1046 [CXT_FIXUP_HP_A_U] = {
1047 .type = HDA_FIXUP_FUNC,
1048 .v.func = cxt_fixup_hp_a_u,
1049 },
1050 [CXT_FIXUP_ACER_SWIFT_HP] = {
1051 .type = HDA_FIXUP_PINS,
1052 .v.pins = (const struct hda_pintbl[]) {
1053 { 0x16, 0x0321403f }, /* Headphone */
1054 { 0x19, 0x40f001f0 }, /* Mic */
1055 { }
1056 },
1057 },
1058 [CXT_FIXUP_HUAWEI_MATEBOOK_HP] = {
1059 .type = HDA_FIXUP_PINS,
1060 .v.pins = (const struct hda_pintbl[]) {
1061 { 0x18, 0x03211020 }, /* Headphone */
1062 { }
1063 },
1064 },
1065 };
1066
1067 static const struct hda_quirk cxt5045_fixups[] = {
1068 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
1069 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
1070 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1071 * really bad sound over 0dB on NID 0x17.
1072 */
1073 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
1074 SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
1075 SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
1076 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
1077 {}
1078 };
1079
1080 static const struct hda_model_fixup cxt5045_fixup_models[] = {
1081 { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
1082 { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
1083 { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
1084 {}
1085 };
1086
1087 static const struct hda_quirk cxt5047_fixups[] = {
1088 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1089 */
1090 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
1091 {}
1092 };
1093
1094 static const struct hda_model_fixup cxt5047_fixup_models[] = {
1095 { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
1096 {}
1097 };
1098
1099 static const struct hda_quirk cxt5051_fixups[] = {
1100 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
1101 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
1102 {}
1103 };
1104
1105 static const struct hda_model_fixup cxt5051_fixup_models[] = {
1106 { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
1107 {}
1108 };
1109
1110 static const struct hda_quirk cxt5066_fixups[] = {
1111 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
1112 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
1113 SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
1114 SND_PCI_QUIRK(0x1025, 0x136d, "Acer Swift SF314", CXT_FIXUP_ACER_SWIFT_HP),
1115 SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
1116 SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
1117 SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
1118 SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
1119 SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO),
1120 SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
1121 SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO),
1122 SND_PCI_QUIRK(0x103c, 0x8231, "HP ProBook 450 G4", CXT_FIXUP_MUTE_LED_GPIO),
1123 SND_PCI_QUIRK(0x103c, 0x826b, "HP ZBook Studio G4", CXT_FIXUP_MUTE_LED_GPIO),
1124 SND_PCI_QUIRK(0x103c, 0x828c, "HP EliteBook 840 G4", CXT_FIXUP_HP_DOCK),
1125 SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1126 SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1127 SND_PCI_QUIRK(0x103c, 0x82b4, "HP ProDesk 600 G3", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1128 SND_PCI_QUIRK(0x103c, 0x836e, "HP ProBook 455 G5", CXT_FIXUP_MUTE_LED_GPIO),
1129 SND_PCI_QUIRK(0x103c, 0x837b, "HP ProBook 440 G5", CXT_FIXUP_MUTE_LED_GPIO),
1130 SND_PCI_QUIRK(0x103c, 0x837f, "HP ProBook 470 G5", CXT_FIXUP_MUTE_LED_GPIO),
1131 SND_PCI_QUIRK(0x103c, 0x83b2, "HP EliteBook 840 G5", CXT_FIXUP_HP_DOCK),
1132 SND_PCI_QUIRK(0x103c, 0x83b3, "HP EliteBook 830 G5", CXT_FIXUP_HP_DOCK),
1133 SND_PCI_QUIRK(0x103c, 0x83d3, "HP ProBook 640 G4", CXT_FIXUP_HP_DOCK),
1134 SND_PCI_QUIRK(0x103c, 0x83e5, "HP EliteOne 1000 G2", CXT_FIXUP_HP_ELITEONE_OUT_DIS),
1135 SND_PCI_QUIRK(0x103c, 0x8402, "HP ProBook 645 G4", CXT_FIXUP_MUTE_LED_GPIO),
1136 SND_PCI_QUIRK(0x103c, 0x8427, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
1137 SND_PCI_QUIRK(0x103c, 0x844f, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
1138 SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1139 SND_PCI_QUIRK(0x103c, 0x8456, "HP Z2 G4 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1140 SND_PCI_QUIRK(0x103c, 0x8457, "HP Z2 G4 mini", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1141 SND_PCI_QUIRK(0x103c, 0x8458, "HP Z2 G4 mini premium", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1142 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
1143 SND_PCI_QUIRK(0x14f1, 0x0252, "MBX-Z60MR100", CXT_FIXUP_HP_A_U),
1144 SND_PCI_QUIRK(0x14f1, 0x0265, "SWS JS201D", CXT_PINCFG_SWS_JS201D),
1145 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
1146 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
1147 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
1148 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
1149 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
1150 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
1151 SND_PCI_QUIRK(0x17aa, 0x21d2, "Lenovo T420s", CXT_PINCFG_LENOVO_TP410),
1152 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
1153 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
1154 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
1155 SND_PCI_QUIRK(0x17aa, 0x38b6, "Lenovo IdeaPad Slim 5 16AKP10", CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10),
1156 SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC),
1157 SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
1158 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
1159 /* NOTE: we'd need to extend the quirk for 17aa:3977 as the same
1160 * PCI SSID is used on multiple Lenovo models
1161 */
1162 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
1163 SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC),
1164 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
1165 SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad/Ideapad", CXT_FIXUP_LENOVO_XPAD_ACPI),
1166 SND_PCI_QUIRK(0x19e5, 0x3289, "Huawei Matebook", CXT_FIXUP_HUAWEI_MATEBOOK_HP),
1167 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
1168 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
1169 SND_PCI_QUIRK(0x1d05, 0x3012, "MECHREVO Wujie 15X Pro", CXT_FIXUP_HEADSET_MIC),
1170 HDA_CODEC_QUIRK(0x2782, 0x12c3, "Sirius Gen1", CXT_PINCFG_TOP_SPEAKER),
1171 HDA_CODEC_QUIRK(0x2782, 0x12c5, "Sirius Gen2", CXT_PINCFG_TOP_SPEAKER),
1172 {}
1173 };
1174
1175 static const struct hda_model_fixup cxt5066_fixup_models[] = {
1176 { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
1177 { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
1178 { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
1179 { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
1180 { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
1181 { .id = CXT_FIXUP_LENOVO_XPAD_ACPI, .name = "thinkpad-ideapad" },
1182 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
1183 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
1184 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
1185 { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
1186 { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" },
1187 { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" },
1188 { .id = CXT_FIXUP_HP_ZBOOK_MUTE_LED, .name = "hp-zbook-mute-led" },
1189 { .id = CXT_FIXUP_HP_MIC_NO_PRESENCE, .name = "hp-mic-fix" },
1190 { .id = CXT_PINCFG_LENOVO_NOTEBOOK, .name = "lenovo-20149" },
1191 { .id = CXT_PINCFG_SWS_JS201D, .name = "sws-js201d" },
1192 { .id = CXT_PINCFG_TOP_SPEAKER, .name = "sirius-top-speaker" },
1193 { .id = CXT_FIXUP_HP_A_U, .name = "HP-U-support" },
1194 {}
1195 };
1196
1197 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
1198 * can be created (bko#42825)
1199 */
add_cx5051_fake_mutes(struct hda_codec * codec)1200 static void add_cx5051_fake_mutes(struct hda_codec *codec)
1201 {
1202 struct conexant_spec *spec = codec->spec;
1203 static const hda_nid_t out_nids[] = {
1204 0x10, 0x11, 0
1205 };
1206 const hda_nid_t *p;
1207
1208 for (p = out_nids; *p; p++)
1209 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
1210 AC_AMPCAP_MIN_MUTE |
1211 query_amp_caps(codec, *p, HDA_OUTPUT));
1212 spec->gen.dac_min_mute = true;
1213 }
1214
cx_probe(struct hda_codec * codec,const struct hda_device_id * id)1215 static int cx_probe(struct hda_codec *codec, const struct hda_device_id *id)
1216 {
1217 struct conexant_spec *spec;
1218 struct hda_jack_callback *callback;
1219 int err;
1220
1221 codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
1222
1223 spec = kzalloc_obj(*spec);
1224 if (!spec)
1225 return -ENOMEM;
1226 snd_hda_gen_spec_init(&spec->gen);
1227 codec->spec = spec;
1228
1229 /* init cx11880/sn6140 flag and reset headset_present_flag */
1230 switch (codec->core.vendor_id) {
1231 case 0x14f11f86:
1232 case 0x14f11f87:
1233 spec->is_cx11880_sn6140 = true;
1234 callback = snd_hda_jack_detect_enable_callback(codec, 0x19,
1235 cx_update_headset_mic_vref);
1236 if (IS_ERR(callback)) {
1237 err = PTR_ERR(callback);
1238 goto error;
1239 }
1240 break;
1241 }
1242
1243 cx_auto_parse_eapd(codec);
1244 spec->gen.own_eapd_ctl = 1;
1245
1246 switch (codec->core.vendor_id) {
1247 case 0x14f15045:
1248 codec->single_adc_amp = 1;
1249 spec->gen.mixer_nid = 0x17;
1250 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1251 snd_hda_pick_fixup(codec, cxt5045_fixup_models,
1252 cxt5045_fixups, cxt_fixups);
1253 break;
1254 case 0x14f15047:
1255 codec->pin_amp_workaround = 1;
1256 spec->gen.mixer_nid = 0x19;
1257 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1258 snd_hda_pick_fixup(codec, cxt5047_fixup_models,
1259 cxt5047_fixups, cxt_fixups);
1260 break;
1261 case 0x14f15051:
1262 add_cx5051_fake_mutes(codec);
1263 codec->pin_amp_workaround = 1;
1264 snd_hda_pick_fixup(codec, cxt5051_fixup_models,
1265 cxt5051_fixups, cxt_fixups);
1266 break;
1267 case 0x14f15098:
1268 codec->pin_amp_workaround = 1;
1269 spec->gen.mixer_nid = 0x22;
1270 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1271 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1272 cxt5066_fixups, cxt_fixups);
1273 break;
1274 case 0x14f150f2:
1275 codec->power_save_node = 1;
1276 fallthrough;
1277 default:
1278 codec->pin_amp_workaround = 1;
1279 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1280 cxt5066_fixups, cxt_fixups);
1281 break;
1282 }
1283
1284 if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
1285 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
1286
1287 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1288
1289 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
1290 spec->parse_flags);
1291 if (err < 0)
1292 goto error;
1293
1294 err = cx_auto_parse_beep(codec);
1295 if (err < 0)
1296 goto error;
1297
1298 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1299 if (err < 0)
1300 goto error;
1301
1302 /* Some laptops with Conexant chips show stalls in S3 resume,
1303 * which falls into the single-cmd mode.
1304 * Better to make reset, then.
1305 */
1306 if (!codec->bus->core.sync_write) {
1307 codec_info(codec,
1308 "Enable sync_write for stable communication\n");
1309 codec->bus->core.sync_write = 1;
1310 codec->bus->allow_bus_reset = 1;
1311 }
1312
1313 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1314
1315 return 0;
1316
1317 error:
1318 cx_remove(codec);
1319 return err;
1320 }
1321
1322 static const struct hda_codec_ops cx_codec_ops = {
1323 .probe = cx_probe,
1324 .remove = cx_remove,
1325 .build_controls = snd_hda_gen_build_controls,
1326 .build_pcms = snd_hda_gen_build_pcms,
1327 .init = cx_init,
1328 .unsol_event = snd_hda_jack_unsol_event,
1329 .suspend = cx_suspend,
1330 .set_power_state = cx_set_power_state,
1331 .check_power_status = snd_hda_gen_check_power_status,
1332 .stream_pm = snd_hda_gen_stream_pm,
1333 };
1334
1335 /*
1336 */
1337
1338 static const struct hda_device_id snd_hda_id_conexant[] = {
1339 HDA_CODEC_ID(0x14f11f86, "CX11880"),
1340 HDA_CODEC_ID(0x14f11f87, "SN6140"),
1341 HDA_CODEC_ID(0x14f12008, "CX8200"),
1342 HDA_CODEC_ID(0x14f120d0, "CX11970"),
1343 HDA_CODEC_ID(0x14f120d1, "SN6180"),
1344 HDA_CODEC_ID(0x14f15045, "CX20549 (Venice)"),
1345 HDA_CODEC_ID(0x14f15047, "CX20551 (Waikiki)"),
1346 HDA_CODEC_ID(0x14f15051, "CX20561 (Hermosa)"),
1347 HDA_CODEC_ID(0x14f15066, "CX20582 (Pebble)"),
1348 HDA_CODEC_ID(0x14f15067, "CX20583 (Pebble HSF)"),
1349 HDA_CODEC_ID(0x14f15068, "CX20584"),
1350 HDA_CODEC_ID(0x14f15069, "CX20585"),
1351 HDA_CODEC_ID(0x14f1506c, "CX20588"),
1352 HDA_CODEC_ID(0x14f1506e, "CX20590"),
1353 HDA_CODEC_ID(0x14f15097, "CX20631"),
1354 HDA_CODEC_ID(0x14f15098, "CX20632"),
1355 HDA_CODEC_ID(0x14f150a1, "CX20641"),
1356 HDA_CODEC_ID(0x14f150a2, "CX20642"),
1357 HDA_CODEC_ID(0x14f150ab, "CX20651"),
1358 HDA_CODEC_ID(0x14f150ac, "CX20652"),
1359 HDA_CODEC_ID(0x14f150b8, "CX20664"),
1360 HDA_CODEC_ID(0x14f150b9, "CX20665"),
1361 HDA_CODEC_ID(0x14f150f1, "CX21722"),
1362 HDA_CODEC_ID(0x14f150f2, "CX20722"),
1363 HDA_CODEC_ID(0x14f150f3, "CX21724"),
1364 HDA_CODEC_ID(0x14f150f4, "CX20724"),
1365 HDA_CODEC_ID(0x14f1510f, "CX20751/2"),
1366 HDA_CODEC_ID(0x14f15110, "CX20751/2"),
1367 HDA_CODEC_ID(0x14f15111, "CX20753/4"),
1368 HDA_CODEC_ID(0x14f15113, "CX20755"),
1369 HDA_CODEC_ID(0x14f15114, "CX20756"),
1370 HDA_CODEC_ID(0x14f15115, "CX20757"),
1371 HDA_CODEC_ID(0x14f151d7, "CX20952"),
1372 {} /* terminator */
1373 };
1374 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant);
1375
1376 MODULE_LICENSE("GPL");
1377 MODULE_DESCRIPTION("Conexant HD-audio codec");
1378
1379 static struct hda_codec_driver conexant_driver = {
1380 .id = snd_hda_id_conexant,
1381 .ops = &cx_codec_ops,
1382 };
1383
1384 module_hda_codec_driver(conexant_driver);
1385