patch_conexant.c 40 KB

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