patch_conexant.c 35 KB

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