patch_conexant.c 30 KB

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