conexant.c 40 KB

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