patch_conexant.c 28 KB

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