patch_conexant.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_auto_parser.h"
  31. #include "hda_beep.h"
  32. #include "hda_jack.h"
  33. #include "hda_generic.h"
  34. struct conexant_spec {
  35. struct hda_gen_spec gen;
  36. unsigned int beep_amp;
  37. /* extra EAPD pins */
  38. unsigned int num_eapds;
  39. hda_nid_t eapds[4];
  40. bool dynamic_eapd;
  41. hda_nid_t mute_led_eapd;
  42. unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
  43. /* OPLC XO specific */
  44. bool recording;
  45. bool dc_enable;
  46. unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
  47. struct nid_path *dc_mode_path;
  48. };
  49. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  50. static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
  51. int idx, int dir)
  52. {
  53. spec->gen.beep_nid = nid;
  54. spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
  55. }
  56. /* additional beep mixers; the actual parameters are overwritten at build */
  57. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  58. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  59. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  60. { } /* end */
  61. };
  62. /* create beep controls if needed */
  63. static int add_beep_ctls(struct hda_codec *codec)
  64. {
  65. struct conexant_spec *spec = codec->spec;
  66. int err;
  67. if (spec->beep_amp) {
  68. const struct snd_kcontrol_new *knew;
  69. for (knew = cxt_beep_mixer; knew->name; knew++) {
  70. struct snd_kcontrol *kctl;
  71. kctl = snd_ctl_new1(knew, codec);
  72. if (!kctl)
  73. return -ENOMEM;
  74. kctl->private_value = spec->beep_amp;
  75. err = snd_hda_ctl_add(codec, 0, kctl);
  76. if (err < 0)
  77. return err;
  78. }
  79. }
  80. return 0;
  81. }
  82. #else
  83. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  84. #define add_beep_ctls(codec) 0
  85. #endif
  86. /*
  87. * Automatic parser for CX20641 & co
  88. */
  89. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  90. static void cx_auto_parse_beep(struct hda_codec *codec)
  91. {
  92. struct conexant_spec *spec = codec->spec;
  93. hda_nid_t nid;
  94. for_each_hda_codec_node(nid, codec)
  95. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  96. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  97. break;
  98. }
  99. }
  100. #else
  101. #define cx_auto_parse_beep(codec)
  102. #endif
  103. /* parse EAPDs */
  104. static void cx_auto_parse_eapd(struct hda_codec *codec)
  105. {
  106. struct conexant_spec *spec = codec->spec;
  107. hda_nid_t nid;
  108. for_each_hda_codec_node(nid, codec) {
  109. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  110. continue;
  111. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  112. continue;
  113. spec->eapds[spec->num_eapds++] = nid;
  114. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  115. break;
  116. }
  117. /* NOTE: below is a wild guess; if we have more than two EAPDs,
  118. * it's a new chip, where EAPDs are supposed to be associated to
  119. * pins, and we can control EAPD per pin.
  120. * OTOH, if only one or two EAPDs are found, it's an old chip,
  121. * thus it might control over all pins.
  122. */
  123. if (spec->num_eapds > 2)
  124. spec->dynamic_eapd = 1;
  125. }
  126. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  127. hda_nid_t *pins, bool on)
  128. {
  129. int i;
  130. for (i = 0; i < num_pins; i++) {
  131. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  132. snd_hda_codec_write(codec, pins[i], 0,
  133. AC_VERB_SET_EAPD_BTLENABLE,
  134. on ? 0x02 : 0);
  135. }
  136. }
  137. /* turn on/off EAPD according to Master switch */
  138. static void cx_auto_vmaster_hook(void *private_data, int enabled)
  139. {
  140. struct hda_codec *codec = private_data;
  141. struct conexant_spec *spec = codec->spec;
  142. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
  143. }
  144. /* turn on/off EAPD according to Master switch (inversely!) for mute LED */
  145. static void cx_auto_vmaster_hook_mute_led(void *private_data, int enabled)
  146. {
  147. struct hda_codec *codec = private_data;
  148. struct conexant_spec *spec = codec->spec;
  149. snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
  150. AC_VERB_SET_EAPD_BTLENABLE,
  151. enabled ? 0x00 : 0x02);
  152. }
  153. static int cx_auto_build_controls(struct hda_codec *codec)
  154. {
  155. int err;
  156. err = snd_hda_gen_build_controls(codec);
  157. if (err < 0)
  158. return err;
  159. err = add_beep_ctls(codec);
  160. if (err < 0)
  161. return err;
  162. return 0;
  163. }
  164. static int cx_auto_init(struct hda_codec *codec)
  165. {
  166. struct conexant_spec *spec = codec->spec;
  167. snd_hda_gen_init(codec);
  168. if (!spec->dynamic_eapd)
  169. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  170. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
  171. return 0;
  172. }
  173. static void cx_auto_reboot_notify(struct hda_codec *codec)
  174. {
  175. struct conexant_spec *spec = codec->spec;
  176. if (codec->core.vendor_id != 0x14f150f2)
  177. return;
  178. /* Turn the CX20722 codec into D3 to avoid spurious noises
  179. from the internal speaker during (and after) reboot */
  180. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
  181. snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
  182. snd_hda_codec_write(codec, codec->core.afg, 0,
  183. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  184. }
  185. static void cx_auto_free(struct hda_codec *codec)
  186. {
  187. cx_auto_reboot_notify(codec);
  188. snd_hda_gen_free(codec);
  189. }
  190. static const struct hda_codec_ops cx_auto_patch_ops = {
  191. .build_controls = cx_auto_build_controls,
  192. .build_pcms = snd_hda_gen_build_pcms,
  193. .init = cx_auto_init,
  194. .reboot_notify = cx_auto_reboot_notify,
  195. .free = cx_auto_free,
  196. .unsol_event = snd_hda_jack_unsol_event,
  197. #ifdef CONFIG_PM
  198. .check_power_status = snd_hda_gen_check_power_status,
  199. #endif
  200. };
  201. /*
  202. * pin fix-up
  203. */
  204. enum {
  205. CXT_PINCFG_LENOVO_X200,
  206. CXT_PINCFG_LENOVO_TP410,
  207. CXT_PINCFG_LEMOTE_A1004,
  208. CXT_PINCFG_LEMOTE_A1205,
  209. CXT_PINCFG_COMPAQ_CQ60,
  210. CXT_FIXUP_STEREO_DMIC,
  211. CXT_FIXUP_INC_MIC_BOOST,
  212. CXT_FIXUP_HEADPHONE_MIC_PIN,
  213. CXT_FIXUP_HEADPHONE_MIC,
  214. CXT_FIXUP_GPIO1,
  215. CXT_FIXUP_ASPIRE_DMIC,
  216. CXT_FIXUP_THINKPAD_ACPI,
  217. CXT_FIXUP_OLPC_XO,
  218. CXT_FIXUP_CAP_MIX_AMP,
  219. CXT_FIXUP_TOSHIBA_P105,
  220. CXT_FIXUP_HP_530,
  221. CXT_FIXUP_CAP_MIX_AMP_5047,
  222. CXT_FIXUP_MUTE_LED_EAPD,
  223. };
  224. /* for hda_fixup_thinkpad_acpi() */
  225. #include "thinkpad_helper.c"
  226. static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
  227. const struct hda_fixup *fix, int action)
  228. {
  229. struct conexant_spec *spec = codec->spec;
  230. spec->gen.inv_dmic_split = 1;
  231. }
  232. static void cxt5066_increase_mic_boost(struct hda_codec *codec,
  233. const struct hda_fixup *fix, int action)
  234. {
  235. if (action != HDA_FIXUP_ACT_PRE_PROBE)
  236. return;
  237. snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
  238. (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
  239. (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  240. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  241. (0 << AC_AMPCAP_MUTE_SHIFT));
  242. }
  243. static void cxt_update_headset_mode(struct hda_codec *codec)
  244. {
  245. /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
  246. int i;
  247. bool mic_mode = false;
  248. struct conexant_spec *spec = codec->spec;
  249. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  250. hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
  251. for (i = 0; i < cfg->num_inputs; i++)
  252. if (cfg->inputs[i].pin == mux_pin) {
  253. mic_mode = !!cfg->inputs[i].is_headphone_mic;
  254. break;
  255. }
  256. if (mic_mode) {
  257. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
  258. spec->gen.hp_jack_present = false;
  259. } else {
  260. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
  261. spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
  262. }
  263. snd_hda_gen_update_outputs(codec);
  264. }
  265. static void cxt_update_headset_mode_hook(struct hda_codec *codec,
  266. struct snd_kcontrol *kcontrol,
  267. struct snd_ctl_elem_value *ucontrol)
  268. {
  269. cxt_update_headset_mode(codec);
  270. }
  271. static void cxt_fixup_headphone_mic(struct hda_codec *codec,
  272. const struct hda_fixup *fix, int action)
  273. {
  274. struct conexant_spec *spec = codec->spec;
  275. switch (action) {
  276. case HDA_FIXUP_ACT_PRE_PROBE:
  277. spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
  278. snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
  279. break;
  280. case HDA_FIXUP_ACT_PROBE:
  281. spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
  282. spec->gen.automute_hook = cxt_update_headset_mode;
  283. break;
  284. case HDA_FIXUP_ACT_INIT:
  285. cxt_update_headset_mode(codec);
  286. break;
  287. }
  288. }
  289. /* OPLC XO 1.5 fixup */
  290. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  291. * through the microphone jack.
  292. * When the user enables this through a mixer switch, both internal and
  293. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  294. * we also allow the bias to be configured through a separate mixer
  295. * control. */
  296. #define update_mic_pin(codec, nid, val) \
  297. snd_hda_codec_update_cache(codec, nid, 0, \
  298. AC_VERB_SET_PIN_WIDGET_CONTROL, val)
  299. static const struct hda_input_mux olpc_xo_dc_bias = {
  300. .num_items = 3,
  301. .items = {
  302. { "Off", PIN_IN },
  303. { "50%", PIN_VREF50 },
  304. { "80%", PIN_VREF80 },
  305. },
  306. };
  307. static void olpc_xo_update_mic_boost(struct hda_codec *codec)
  308. {
  309. struct conexant_spec *spec = codec->spec;
  310. int ch, val;
  311. for (ch = 0; ch < 2; ch++) {
  312. val = AC_AMP_SET_OUTPUT |
  313. (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
  314. if (!spec->dc_enable)
  315. val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
  316. snd_hda_codec_write(codec, 0x17, 0,
  317. AC_VERB_SET_AMP_GAIN_MUTE, val);
  318. }
  319. }
  320. static void olpc_xo_update_mic_pins(struct hda_codec *codec)
  321. {
  322. struct conexant_spec *spec = codec->spec;
  323. int cur_input, val;
  324. struct nid_path *path;
  325. cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
  326. /* Set up mic pins for port-B, C and F dynamically as the recording
  327. * LED is turned on/off by these pin controls
  328. */
  329. if (!spec->dc_enable) {
  330. /* disable DC bias path and pin for port F */
  331. update_mic_pin(codec, 0x1e, 0);
  332. snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
  333. /* update port B (ext mic) and C (int mic) */
  334. /* OLPC defers mic widget control until when capture is
  335. * started because the microphone LED comes on as soon as
  336. * these settings are put in place. if we did this before
  337. * recording, it would give the false indication that
  338. * recording is happening when it is not.
  339. */
  340. update_mic_pin(codec, 0x1a, spec->recording ?
  341. snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
  342. update_mic_pin(codec, 0x1b, spec->recording ?
  343. snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
  344. /* enable normal mic path */
  345. path = snd_hda_get_path_from_idx(codec, cur_input);
  346. if (path)
  347. snd_hda_activate_path(codec, path, true, false);
  348. } else {
  349. /* disable normal mic path */
  350. path = snd_hda_get_path_from_idx(codec, cur_input);
  351. if (path)
  352. snd_hda_activate_path(codec, path, false, false);
  353. /* Even though port F is the DC input, the bias is controlled
  354. * on port B. We also leave that port as an active input (but
  355. * unselected) in DC mode just in case that is necessary to
  356. * make the bias setting take effect.
  357. */
  358. if (spec->recording)
  359. val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
  360. else
  361. val = 0;
  362. update_mic_pin(codec, 0x1a, val);
  363. update_mic_pin(codec, 0x1b, 0);
  364. /* enable DC bias path and pin */
  365. update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
  366. snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
  367. }
  368. }
  369. /* mic_autoswitch hook */
  370. static void olpc_xo_automic(struct hda_codec *codec,
  371. struct hda_jack_callback *jack)
  372. {
  373. struct conexant_spec *spec = codec->spec;
  374. /* in DC mode, we don't handle automic */
  375. if (!spec->dc_enable)
  376. snd_hda_gen_mic_autoswitch(codec, jack);
  377. olpc_xo_update_mic_pins(codec);
  378. if (spec->dc_enable)
  379. olpc_xo_update_mic_boost(codec);
  380. }
  381. /* pcm_capture hook */
  382. static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
  383. struct hda_codec *codec,
  384. struct snd_pcm_substream *substream,
  385. int action)
  386. {
  387. struct conexant_spec *spec = codec->spec;
  388. /* toggle spec->recording flag and update mic pins accordingly
  389. * for turning on/off LED
  390. */
  391. switch (action) {
  392. case HDA_GEN_PCM_ACT_PREPARE:
  393. spec->recording = 1;
  394. olpc_xo_update_mic_pins(codec);
  395. break;
  396. case HDA_GEN_PCM_ACT_CLEANUP:
  397. spec->recording = 0;
  398. olpc_xo_update_mic_pins(codec);
  399. break;
  400. }
  401. }
  402. static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
  403. struct snd_ctl_elem_value *ucontrol)
  404. {
  405. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  406. struct conexant_spec *spec = codec->spec;
  407. ucontrol->value.integer.value[0] = spec->dc_enable;
  408. return 0;
  409. }
  410. static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
  411. struct snd_ctl_elem_value *ucontrol)
  412. {
  413. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  414. struct conexant_spec *spec = codec->spec;
  415. int dc_enable = !!ucontrol->value.integer.value[0];
  416. if (dc_enable == spec->dc_enable)
  417. return 0;
  418. spec->dc_enable = dc_enable;
  419. olpc_xo_update_mic_pins(codec);
  420. olpc_xo_update_mic_boost(codec);
  421. return 1;
  422. }
  423. static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  424. struct snd_ctl_elem_value *ucontrol)
  425. {
  426. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  427. struct conexant_spec *spec = codec->spec;
  428. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  429. return 0;
  430. }
  431. static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  432. struct snd_ctl_elem_info *uinfo)
  433. {
  434. return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
  435. }
  436. static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  437. struct snd_ctl_elem_value *ucontrol)
  438. {
  439. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  440. struct conexant_spec *spec = codec->spec;
  441. const struct hda_input_mux *imux = &olpc_xo_dc_bias;
  442. unsigned int idx;
  443. idx = ucontrol->value.enumerated.item[0];
  444. if (idx >= imux->num_items)
  445. idx = imux->num_items - 1;
  446. if (spec->dc_input_bias == idx)
  447. return 0;
  448. spec->dc_input_bias = idx;
  449. if (spec->dc_enable)
  450. olpc_xo_update_mic_pins(codec);
  451. return 1;
  452. }
  453. static const struct snd_kcontrol_new olpc_xo_mixers[] = {
  454. {
  455. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  456. .name = "DC Mode Enable Switch",
  457. .info = snd_ctl_boolean_mono_info,
  458. .get = olpc_xo_dc_mode_get,
  459. .put = olpc_xo_dc_mode_put,
  460. },
  461. {
  462. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  463. .name = "DC Input Bias Enum",
  464. .info = olpc_xo_dc_bias_enum_info,
  465. .get = olpc_xo_dc_bias_enum_get,
  466. .put = olpc_xo_dc_bias_enum_put,
  467. },
  468. {}
  469. };
  470. /* overriding mic boost put callback; update mic boost volume only when
  471. * DC mode is disabled
  472. */
  473. static int olpc_xo_mic_boost_put(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. int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
  479. if (ret > 0 && spec->dc_enable)
  480. olpc_xo_update_mic_boost(codec);
  481. return ret;
  482. }
  483. static void cxt_fixup_olpc_xo(struct hda_codec *codec,
  484. const struct hda_fixup *fix, int action)
  485. {
  486. struct conexant_spec *spec = codec->spec;
  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. for (i = 0; i < spec->gen.kctls.used; i++) {
  501. struct snd_kcontrol_new *kctl =
  502. snd_array_elem(&spec->gen.kctls, i);
  503. if (!strcmp(kctl->name, "Mic Boost Volume")) {
  504. kctl->put = olpc_xo_mic_boost_put;
  505. break;
  506. }
  507. }
  508. }
  509. static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
  510. const struct hda_fixup *fix, int action)
  511. {
  512. struct conexant_spec *spec = codec->spec;
  513. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  514. spec->mute_led_eapd = 0x1b;
  515. spec->dynamic_eapd = 1;
  516. spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook_mute_led;
  517. }
  518. }
  519. /*
  520. * Fix max input level on mixer widget to 0dB
  521. * (originally it has 0x2b steps with 0dB offset 0x14)
  522. */
  523. static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
  524. const struct hda_fixup *fix, int action)
  525. {
  526. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  527. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  528. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  529. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  530. (1 << AC_AMPCAP_MUTE_SHIFT));
  531. }
  532. /*
  533. * Fix max input level on mixer widget to 0dB
  534. * (originally it has 0x1e steps with 0 dB offset 0x17)
  535. */
  536. static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
  537. const struct hda_fixup *fix, int action)
  538. {
  539. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  540. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  541. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  542. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  543. (1 << AC_AMPCAP_MUTE_SHIFT));
  544. }
  545. /* ThinkPad X200 & co with cxt5051 */
  546. static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
  547. { 0x16, 0x042140ff }, /* HP (seq# overridden) */
  548. { 0x17, 0x21a11000 }, /* dock-mic */
  549. { 0x19, 0x2121103f }, /* dock-HP */
  550. { 0x1c, 0x21440100 }, /* dock SPDIF out */
  551. {}
  552. };
  553. /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
  554. static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
  555. { 0x19, 0x042110ff }, /* HP (seq# overridden) */
  556. { 0x1a, 0x21a190f0 }, /* dock-mic */
  557. { 0x1c, 0x212140ff }, /* dock-HP */
  558. {}
  559. };
  560. /* Lemote A1004/A1205 with cxt5066 */
  561. static const struct hda_pintbl cxt_pincfg_lemote[] = {
  562. { 0x1a, 0x90a10020 }, /* Internal mic */
  563. { 0x1b, 0x03a11020 }, /* External mic */
  564. { 0x1d, 0x400101f0 }, /* Not used */
  565. { 0x1e, 0x40a701f0 }, /* Not used */
  566. { 0x20, 0x404501f0 }, /* Not used */
  567. { 0x22, 0x404401f0 }, /* Not used */
  568. { 0x23, 0x40a701f0 }, /* Not used */
  569. {}
  570. };
  571. static const struct hda_fixup cxt_fixups[] = {
  572. [CXT_PINCFG_LENOVO_X200] = {
  573. .type = HDA_FIXUP_PINS,
  574. .v.pins = cxt_pincfg_lenovo_x200,
  575. },
  576. [CXT_PINCFG_LENOVO_TP410] = {
  577. .type = HDA_FIXUP_PINS,
  578. .v.pins = cxt_pincfg_lenovo_tp410,
  579. .chained = true,
  580. .chain_id = CXT_FIXUP_THINKPAD_ACPI,
  581. },
  582. [CXT_PINCFG_LEMOTE_A1004] = {
  583. .type = HDA_FIXUP_PINS,
  584. .chained = true,
  585. .chain_id = CXT_FIXUP_INC_MIC_BOOST,
  586. .v.pins = cxt_pincfg_lemote,
  587. },
  588. [CXT_PINCFG_LEMOTE_A1205] = {
  589. .type = HDA_FIXUP_PINS,
  590. .v.pins = cxt_pincfg_lemote,
  591. },
  592. [CXT_PINCFG_COMPAQ_CQ60] = {
  593. .type = HDA_FIXUP_PINS,
  594. .v.pins = (const struct hda_pintbl[]) {
  595. /* 0x17 was falsely set up as a mic, it should 0x1d */
  596. { 0x17, 0x400001f0 },
  597. { 0x1d, 0x97a70120 },
  598. { }
  599. }
  600. },
  601. [CXT_FIXUP_STEREO_DMIC] = {
  602. .type = HDA_FIXUP_FUNC,
  603. .v.func = cxt_fixup_stereo_dmic,
  604. },
  605. [CXT_FIXUP_INC_MIC_BOOST] = {
  606. .type = HDA_FIXUP_FUNC,
  607. .v.func = cxt5066_increase_mic_boost,
  608. },
  609. [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
  610. .type = HDA_FIXUP_PINS,
  611. .chained = true,
  612. .chain_id = CXT_FIXUP_HEADPHONE_MIC,
  613. .v.pins = (const struct hda_pintbl[]) {
  614. { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
  615. { }
  616. }
  617. },
  618. [CXT_FIXUP_HEADPHONE_MIC] = {
  619. .type = HDA_FIXUP_FUNC,
  620. .v.func = cxt_fixup_headphone_mic,
  621. },
  622. [CXT_FIXUP_GPIO1] = {
  623. .type = HDA_FIXUP_VERBS,
  624. .v.verbs = (const struct hda_verb[]) {
  625. { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
  626. { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
  627. { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
  628. { }
  629. },
  630. },
  631. [CXT_FIXUP_ASPIRE_DMIC] = {
  632. .type = HDA_FIXUP_FUNC,
  633. .v.func = cxt_fixup_stereo_dmic,
  634. .chained = true,
  635. .chain_id = CXT_FIXUP_GPIO1,
  636. },
  637. [CXT_FIXUP_THINKPAD_ACPI] = {
  638. .type = HDA_FIXUP_FUNC,
  639. .v.func = hda_fixup_thinkpad_acpi,
  640. },
  641. [CXT_FIXUP_OLPC_XO] = {
  642. .type = HDA_FIXUP_FUNC,
  643. .v.func = cxt_fixup_olpc_xo,
  644. },
  645. [CXT_FIXUP_CAP_MIX_AMP] = {
  646. .type = HDA_FIXUP_FUNC,
  647. .v.func = cxt_fixup_cap_mix_amp,
  648. },
  649. [CXT_FIXUP_TOSHIBA_P105] = {
  650. .type = HDA_FIXUP_PINS,
  651. .v.pins = (const struct hda_pintbl[]) {
  652. { 0x10, 0x961701f0 }, /* speaker/hp */
  653. { 0x12, 0x02a1901e }, /* ext mic */
  654. { 0x14, 0x95a70110 }, /* int mic */
  655. {}
  656. },
  657. },
  658. [CXT_FIXUP_HP_530] = {
  659. .type = HDA_FIXUP_PINS,
  660. .v.pins = (const struct hda_pintbl[]) {
  661. { 0x12, 0x90a60160 }, /* int mic */
  662. {}
  663. },
  664. .chained = true,
  665. .chain_id = CXT_FIXUP_CAP_MIX_AMP,
  666. },
  667. [CXT_FIXUP_CAP_MIX_AMP_5047] = {
  668. .type = HDA_FIXUP_FUNC,
  669. .v.func = cxt_fixup_cap_mix_amp_5047,
  670. },
  671. [CXT_FIXUP_MUTE_LED_EAPD] = {
  672. .type = HDA_FIXUP_FUNC,
  673. .v.func = cxt_fixup_mute_led_eapd,
  674. },
  675. };
  676. static const struct snd_pci_quirk cxt5045_fixups[] = {
  677. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
  678. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
  679. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  680. * really bad sound over 0dB on NID 0x17.
  681. */
  682. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
  683. SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
  684. SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
  685. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
  686. {}
  687. };
  688. static const struct hda_model_fixup cxt5045_fixup_models[] = {
  689. { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
  690. { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
  691. { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
  692. {}
  693. };
  694. static const struct snd_pci_quirk cxt5047_fixups[] = {
  695. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  696. */
  697. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
  698. {}
  699. };
  700. static const struct hda_model_fixup cxt5047_fixup_models[] = {
  701. { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
  702. {}
  703. };
  704. static const struct snd_pci_quirk cxt5051_fixups[] = {
  705. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
  706. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
  707. {}
  708. };
  709. static const struct hda_model_fixup cxt5051_fixup_models[] = {
  710. { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
  711. {}
  712. };
  713. static const struct snd_pci_quirk cxt5066_fixups[] = {
  714. SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
  715. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
  716. SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
  717. SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
  718. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
  719. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
  720. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
  721. SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
  722. SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
  723. SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
  724. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
  725. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
  726. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
  727. SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
  728. SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
  729. SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
  730. SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
  731. SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
  732. SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
  733. SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
  734. {}
  735. };
  736. static const struct hda_model_fixup cxt5066_fixup_models[] = {
  737. { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
  738. { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
  739. { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
  740. { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
  741. { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
  742. { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
  743. { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
  744. { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
  745. { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
  746. {}
  747. };
  748. /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
  749. * can be created (bko#42825)
  750. */
  751. static void add_cx5051_fake_mutes(struct hda_codec *codec)
  752. {
  753. struct conexant_spec *spec = codec->spec;
  754. static hda_nid_t out_nids[] = {
  755. 0x10, 0x11, 0
  756. };
  757. hda_nid_t *p;
  758. for (p = out_nids; *p; p++)
  759. snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
  760. AC_AMPCAP_MIN_MUTE |
  761. query_amp_caps(codec, *p, HDA_OUTPUT));
  762. spec->gen.dac_min_mute = true;
  763. }
  764. static int patch_conexant_auto(struct hda_codec *codec)
  765. {
  766. struct conexant_spec *spec;
  767. int err;
  768. codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
  769. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  770. if (!spec)
  771. return -ENOMEM;
  772. snd_hda_gen_spec_init(&spec->gen);
  773. codec->spec = spec;
  774. codec->patch_ops = cx_auto_patch_ops;
  775. cx_auto_parse_beep(codec);
  776. cx_auto_parse_eapd(codec);
  777. spec->gen.own_eapd_ctl = 1;
  778. if (spec->dynamic_eapd)
  779. spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
  780. switch (codec->core.vendor_id) {
  781. case 0x14f15045:
  782. codec->single_adc_amp = 1;
  783. spec->gen.mixer_nid = 0x17;
  784. spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
  785. snd_hda_pick_fixup(codec, cxt5045_fixup_models,
  786. cxt5045_fixups, cxt_fixups);
  787. break;
  788. case 0x14f15047:
  789. codec->pin_amp_workaround = 1;
  790. spec->gen.mixer_nid = 0x19;
  791. spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
  792. snd_hda_pick_fixup(codec, cxt5047_fixup_models,
  793. cxt5047_fixups, cxt_fixups);
  794. break;
  795. case 0x14f15051:
  796. add_cx5051_fake_mutes(codec);
  797. codec->pin_amp_workaround = 1;
  798. snd_hda_pick_fixup(codec, cxt5051_fixup_models,
  799. cxt5051_fixups, cxt_fixups);
  800. break;
  801. case 0x14f150f2:
  802. codec->power_save_node = 1;
  803. /* Fall through */
  804. default:
  805. codec->pin_amp_workaround = 1;
  806. snd_hda_pick_fixup(codec, cxt5066_fixup_models,
  807. cxt5066_fixups, cxt_fixups);
  808. break;
  809. }
  810. /* Show mute-led control only on HP laptops
  811. * This is a sort of white-list: on HP laptops, EAPD corresponds
  812. * only to the mute-LED without actualy amp function. Meanwhile,
  813. * others may use EAPD really as an amp switch, so it might be
  814. * not good to expose it blindly.
  815. */
  816. switch (codec->core.subsystem_id >> 16) {
  817. case 0x103c:
  818. spec->gen.vmaster_mute_enum = 1;
  819. break;
  820. }
  821. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  822. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
  823. spec->parse_flags);
  824. if (err < 0)
  825. goto error;
  826. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  827. if (err < 0)
  828. goto error;
  829. /* Some laptops with Conexant chips show stalls in S3 resume,
  830. * which falls into the single-cmd mode.
  831. * Better to make reset, then.
  832. */
  833. if (!codec->bus->core.sync_write) {
  834. codec_info(codec,
  835. "Enable sync_write for stable communication\n");
  836. codec->bus->core.sync_write = 1;
  837. codec->bus->allow_bus_reset = 1;
  838. }
  839. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  840. return 0;
  841. error:
  842. cx_auto_free(codec);
  843. return err;
  844. }
  845. /*
  846. */
  847. static const struct hda_device_id snd_hda_id_conexant[] = {
  848. HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto),
  849. HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto),
  850. HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto),
  851. HDA_CODEC_ENTRY(0x14f15051, "CX20561 (Hermosa)", patch_conexant_auto),
  852. HDA_CODEC_ENTRY(0x14f15066, "CX20582 (Pebble)", patch_conexant_auto),
  853. HDA_CODEC_ENTRY(0x14f15067, "CX20583 (Pebble HSF)", patch_conexant_auto),
  854. HDA_CODEC_ENTRY(0x14f15068, "CX20584", patch_conexant_auto),
  855. HDA_CODEC_ENTRY(0x14f15069, "CX20585", patch_conexant_auto),
  856. HDA_CODEC_ENTRY(0x14f1506c, "CX20588", patch_conexant_auto),
  857. HDA_CODEC_ENTRY(0x14f1506e, "CX20590", patch_conexant_auto),
  858. HDA_CODEC_ENTRY(0x14f15097, "CX20631", patch_conexant_auto),
  859. HDA_CODEC_ENTRY(0x14f15098, "CX20632", patch_conexant_auto),
  860. HDA_CODEC_ENTRY(0x14f150a1, "CX20641", patch_conexant_auto),
  861. HDA_CODEC_ENTRY(0x14f150a2, "CX20642", patch_conexant_auto),
  862. HDA_CODEC_ENTRY(0x14f150ab, "CX20651", patch_conexant_auto),
  863. HDA_CODEC_ENTRY(0x14f150ac, "CX20652", patch_conexant_auto),
  864. HDA_CODEC_ENTRY(0x14f150b8, "CX20664", patch_conexant_auto),
  865. HDA_CODEC_ENTRY(0x14f150b9, "CX20665", patch_conexant_auto),
  866. HDA_CODEC_ENTRY(0x14f150f1, "CX21722", patch_conexant_auto),
  867. HDA_CODEC_ENTRY(0x14f150f2, "CX20722", patch_conexant_auto),
  868. HDA_CODEC_ENTRY(0x14f150f3, "CX21724", patch_conexant_auto),
  869. HDA_CODEC_ENTRY(0x14f150f4, "CX20724", patch_conexant_auto),
  870. HDA_CODEC_ENTRY(0x14f1510f, "CX20751/2", patch_conexant_auto),
  871. HDA_CODEC_ENTRY(0x14f15110, "CX20751/2", patch_conexant_auto),
  872. HDA_CODEC_ENTRY(0x14f15111, "CX20753/4", patch_conexant_auto),
  873. HDA_CODEC_ENTRY(0x14f15113, "CX20755", patch_conexant_auto),
  874. HDA_CODEC_ENTRY(0x14f15114, "CX20756", patch_conexant_auto),
  875. HDA_CODEC_ENTRY(0x14f15115, "CX20757", patch_conexant_auto),
  876. HDA_CODEC_ENTRY(0x14f151d7, "CX20952", patch_conexant_auto),
  877. {} /* terminator */
  878. };
  879. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant);
  880. MODULE_LICENSE("GPL");
  881. MODULE_DESCRIPTION("Conexant HD-audio codec");
  882. static struct hda_codec_driver conexant_driver = {
  883. .id = snd_hda_id_conexant,
  884. };
  885. module_hda_codec_driver(conexant_driver);