patch_conexant.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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 <sound/driver.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <linux/pci.h>
  27. #include <sound/core.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #define CXT_PIN_DIR_IN 0x00
  31. #define CXT_PIN_DIR_OUT 0x01
  32. #define CXT_PIN_DIR_INOUT 0x02
  33. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  34. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  35. #define CONEXANT_HP_EVENT 0x37
  36. #define CONEXANT_MIC_EVENT 0x38
  37. struct conexant_spec {
  38. struct snd_kcontrol_new *mixers[5];
  39. int num_mixers;
  40. const struct hda_verb *init_verbs[5]; /* initialization verbs
  41. * don't forget NULL
  42. * termination!
  43. */
  44. unsigned int num_init_verbs;
  45. /* playback */
  46. struct hda_multi_out multiout; /* playback set-up
  47. * max_channels, dacs must be set
  48. * dig_out_nid and hp_nid are optional
  49. */
  50. unsigned int cur_eapd;
  51. unsigned int hp_present;
  52. unsigned int need_dac_fix;
  53. /* capture */
  54. unsigned int num_adc_nids;
  55. hda_nid_t *adc_nids;
  56. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  57. /* capture source */
  58. const struct hda_input_mux *input_mux;
  59. hda_nid_t *capsrc_nids;
  60. unsigned int cur_mux[3];
  61. /* channel model */
  62. const struct hda_channel_mode *channel_mode;
  63. int num_channel_mode;
  64. /* PCM information */
  65. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  66. struct mutex amp_mutex; /* PCM volume/mute control mutex */
  67. unsigned int spdif_route;
  68. /* dynamic controls, init_verbs and input_mux */
  69. struct auto_pin_cfg autocfg;
  70. unsigned int num_kctl_alloc, num_kctl_used;
  71. struct snd_kcontrol_new *kctl_alloc;
  72. struct hda_input_mux private_imux;
  73. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  74. };
  75. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  76. struct hda_codec *codec,
  77. struct snd_pcm_substream *substream)
  78. {
  79. struct conexant_spec *spec = codec->spec;
  80. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  81. }
  82. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  83. struct hda_codec *codec,
  84. unsigned int stream_tag,
  85. unsigned int format,
  86. struct snd_pcm_substream *substream)
  87. {
  88. struct conexant_spec *spec = codec->spec;
  89. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  90. stream_tag,
  91. format, substream);
  92. }
  93. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  94. struct hda_codec *codec,
  95. struct snd_pcm_substream *substream)
  96. {
  97. struct conexant_spec *spec = codec->spec;
  98. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  99. }
  100. /*
  101. * Digital out
  102. */
  103. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  104. struct hda_codec *codec,
  105. struct snd_pcm_substream *substream)
  106. {
  107. struct conexant_spec *spec = codec->spec;
  108. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  109. }
  110. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  111. struct hda_codec *codec,
  112. struct snd_pcm_substream *substream)
  113. {
  114. struct conexant_spec *spec = codec->spec;
  115. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  116. }
  117. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  118. struct hda_codec *codec,
  119. unsigned int stream_tag,
  120. unsigned int format,
  121. struct snd_pcm_substream *substream)
  122. {
  123. struct conexant_spec *spec = codec->spec;
  124. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  125. stream_tag,
  126. format, substream);
  127. }
  128. /*
  129. * Analog capture
  130. */
  131. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  132. struct hda_codec *codec,
  133. unsigned int stream_tag,
  134. unsigned int format,
  135. struct snd_pcm_substream *substream)
  136. {
  137. struct conexant_spec *spec = codec->spec;
  138. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  139. stream_tag, 0, format);
  140. return 0;
  141. }
  142. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  143. struct hda_codec *codec,
  144. struct snd_pcm_substream *substream)
  145. {
  146. struct conexant_spec *spec = codec->spec;
  147. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  148. 0, 0, 0);
  149. return 0;
  150. }
  151. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  152. .substreams = 1,
  153. .channels_min = 2,
  154. .channels_max = 2,
  155. .nid = 0, /* fill later */
  156. .ops = {
  157. .open = conexant_playback_pcm_open,
  158. .prepare = conexant_playback_pcm_prepare,
  159. .cleanup = conexant_playback_pcm_cleanup
  160. },
  161. };
  162. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  163. .substreams = 1,
  164. .channels_min = 2,
  165. .channels_max = 2,
  166. .nid = 0, /* fill later */
  167. .ops = {
  168. .prepare = conexant_capture_pcm_prepare,
  169. .cleanup = conexant_capture_pcm_cleanup
  170. },
  171. };
  172. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  173. .substreams = 1,
  174. .channels_min = 2,
  175. .channels_max = 2,
  176. .nid = 0, /* fill later */
  177. .ops = {
  178. .open = conexant_dig_playback_pcm_open,
  179. .close = conexant_dig_playback_pcm_close,
  180. .prepare = conexant_dig_playback_pcm_prepare
  181. },
  182. };
  183. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  184. .substreams = 1,
  185. .channels_min = 2,
  186. .channels_max = 2,
  187. /* NID is set in alc_build_pcms */
  188. };
  189. static int conexant_build_pcms(struct hda_codec *codec)
  190. {
  191. struct conexant_spec *spec = codec->spec;
  192. struct hda_pcm *info = spec->pcm_rec;
  193. codec->num_pcms = 1;
  194. codec->pcm_info = info;
  195. info->name = "CONEXANT Analog";
  196. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  197. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  198. spec->multiout.max_channels;
  199. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  200. spec->multiout.dac_nids[0];
  201. info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
  202. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  203. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  204. if (spec->multiout.dig_out_nid) {
  205. info++;
  206. codec->num_pcms++;
  207. info->name = "Conexant Digital";
  208. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  209. conexant_pcm_digital_playback;
  210. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  211. spec->multiout.dig_out_nid;
  212. if (spec->dig_in_nid) {
  213. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  214. conexant_pcm_digital_capture;
  215. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  216. spec->dig_in_nid;
  217. }
  218. }
  219. return 0;
  220. }
  221. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  222. struct snd_ctl_elem_info *uinfo)
  223. {
  224. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  225. struct conexant_spec *spec = codec->spec;
  226. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  227. }
  228. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  229. struct snd_ctl_elem_value *ucontrol)
  230. {
  231. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  232. struct conexant_spec *spec = codec->spec;
  233. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  234. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  235. return 0;
  236. }
  237. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  238. struct snd_ctl_elem_value *ucontrol)
  239. {
  240. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  241. struct conexant_spec *spec = codec->spec;
  242. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  243. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  244. spec->capsrc_nids[adc_idx],
  245. &spec->cur_mux[adc_idx]);
  246. }
  247. static int conexant_init(struct hda_codec *codec)
  248. {
  249. struct conexant_spec *spec = codec->spec;
  250. int i;
  251. for (i = 0; i < spec->num_init_verbs; i++)
  252. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  253. return 0;
  254. }
  255. static void conexant_free(struct hda_codec *codec)
  256. {
  257. struct conexant_spec *spec = codec->spec;
  258. unsigned int i;
  259. if (spec->kctl_alloc) {
  260. for (i = 0; i < spec->num_kctl_used; i++)
  261. kfree(spec->kctl_alloc[i].name);
  262. kfree(spec->kctl_alloc);
  263. }
  264. kfree(codec->spec);
  265. }
  266. static int conexant_build_controls(struct hda_codec *codec)
  267. {
  268. struct conexant_spec *spec = codec->spec;
  269. unsigned int i;
  270. int err;
  271. for (i = 0; i < spec->num_mixers; i++) {
  272. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  273. if (err < 0)
  274. return err;
  275. }
  276. if (spec->multiout.dig_out_nid) {
  277. err = snd_hda_create_spdif_out_ctls(codec,
  278. spec->multiout.dig_out_nid);
  279. if (err < 0)
  280. return err;
  281. }
  282. if (spec->dig_in_nid) {
  283. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  284. if (err < 0)
  285. return err;
  286. }
  287. return 0;
  288. }
  289. static struct hda_codec_ops conexant_patch_ops = {
  290. .build_controls = conexant_build_controls,
  291. .build_pcms = conexant_build_pcms,
  292. .init = conexant_init,
  293. .free = conexant_free,
  294. };
  295. /*
  296. * EAPD control
  297. * the private value = nid | (invert << 8)
  298. */
  299. #define cxt_eapd_info snd_ctl_boolean_mono_info
  300. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  301. struct snd_ctl_elem_value *ucontrol)
  302. {
  303. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  304. struct conexant_spec *spec = codec->spec;
  305. int invert = (kcontrol->private_value >> 8) & 1;
  306. if (invert)
  307. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  308. else
  309. ucontrol->value.integer.value[0] = spec->cur_eapd;
  310. return 0;
  311. }
  312. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  313. struct snd_ctl_elem_value *ucontrol)
  314. {
  315. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  316. struct conexant_spec *spec = codec->spec;
  317. int invert = (kcontrol->private_value >> 8) & 1;
  318. hda_nid_t nid = kcontrol->private_value & 0xff;
  319. unsigned int eapd;
  320. eapd = ucontrol->value.integer.value[0];
  321. if (invert)
  322. eapd = !eapd;
  323. if (eapd == spec->cur_eapd)
  324. return 0;
  325. spec->cur_eapd = eapd;
  326. snd_hda_codec_write_cache(codec, nid,
  327. 0, AC_VERB_SET_EAPD_BTLENABLE,
  328. eapd ? 0x02 : 0x00);
  329. return 1;
  330. }
  331. /* controls for test mode */
  332. #ifdef CONFIG_SND_DEBUG
  333. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  334. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  335. .info = cxt_eapd_info, \
  336. .get = cxt_eapd_get, \
  337. .put = cxt_eapd_put, \
  338. .private_value = nid | (mask<<16) }
  339. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  340. struct snd_ctl_elem_info *uinfo)
  341. {
  342. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  343. struct conexant_spec *spec = codec->spec;
  344. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  345. spec->num_channel_mode);
  346. }
  347. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  348. struct snd_ctl_elem_value *ucontrol)
  349. {
  350. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  351. struct conexant_spec *spec = codec->spec;
  352. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  353. spec->num_channel_mode,
  354. spec->multiout.max_channels);
  355. }
  356. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  357. struct snd_ctl_elem_value *ucontrol)
  358. {
  359. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  360. struct conexant_spec *spec = codec->spec;
  361. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  362. spec->num_channel_mode,
  363. &spec->multiout.max_channels);
  364. if (err >= 0 && spec->need_dac_fix)
  365. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  366. return err;
  367. }
  368. #define CXT_PIN_MODE(xname, nid, dir) \
  369. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  370. .info = conexant_ch_mode_info, \
  371. .get = conexant_ch_mode_get, \
  372. .put = conexant_ch_mode_put, \
  373. .private_value = nid | (dir<<16) }
  374. #endif /* CONFIG_SND_DEBUG */
  375. /* Conexant 5045 specific */
  376. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  377. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  378. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  379. #define CXT5045_SPDIF_OUT 0x13
  380. static struct hda_channel_mode cxt5045_modes[1] = {
  381. { 2, NULL },
  382. };
  383. static struct hda_input_mux cxt5045_capture_source = {
  384. .num_items = 2,
  385. .items = {
  386. { "IntMic", 0x1 },
  387. { "LineIn", 0x2 },
  388. }
  389. };
  390. /* turn on/off EAPD (+ mute HP) as a master switch */
  391. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  392. struct snd_ctl_elem_value *ucontrol)
  393. {
  394. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  395. struct conexant_spec *spec = codec->spec;
  396. unsigned int bits;
  397. if (!cxt_eapd_put(kcontrol, ucontrol))
  398. return 0;
  399. /* toggle internal speakers mute depending of presence of
  400. * the headphone jack
  401. */
  402. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  403. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  404. HDA_AMP_MUTE, bits);
  405. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  406. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  407. HDA_AMP_MUTE, bits);
  408. return 1;
  409. }
  410. /* bind volumes of both NID 0x10 and 0x11 */
  411. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  412. .ops = &snd_hda_bind_vol,
  413. .values = {
  414. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  415. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  416. 0
  417. },
  418. };
  419. /* toggle input of built-in and mic jack appropriately */
  420. static void cxt5045_hp_automic(struct hda_codec *codec)
  421. {
  422. static struct hda_verb mic_jack_on[] = {
  423. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  424. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  425. {}
  426. };
  427. static struct hda_verb mic_jack_off[] = {
  428. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  429. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  430. {}
  431. };
  432. unsigned int present;
  433. present = snd_hda_codec_read(codec, 0x12, 0,
  434. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  435. if (present)
  436. snd_hda_sequence_write(codec, mic_jack_on);
  437. else
  438. snd_hda_sequence_write(codec, mic_jack_off);
  439. }
  440. /* mute internal speaker if HP is plugged */
  441. static void cxt5045_hp_automute(struct hda_codec *codec)
  442. {
  443. struct conexant_spec *spec = codec->spec;
  444. unsigned int bits;
  445. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  446. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  447. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  448. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  449. HDA_AMP_MUTE, bits);
  450. }
  451. /* unsolicited event for HP jack sensing */
  452. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  453. unsigned int res)
  454. {
  455. res >>= 26;
  456. switch (res) {
  457. case CONEXANT_HP_EVENT:
  458. cxt5045_hp_automute(codec);
  459. break;
  460. case CONEXANT_MIC_EVENT:
  461. cxt5045_hp_automic(codec);
  462. break;
  463. }
  464. }
  465. static struct snd_kcontrol_new cxt5045_mixers[] = {
  466. {
  467. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  468. .name = "Capture Source",
  469. .info = conexant_mux_enum_info,
  470. .get = conexant_mux_enum_get,
  471. .put = conexant_mux_enum_put
  472. },
  473. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  474. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  475. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  476. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  477. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  478. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  479. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  480. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  481. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  482. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  483. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  484. {
  485. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  486. .name = "Master Playback Switch",
  487. .info = cxt_eapd_info,
  488. .get = cxt_eapd_get,
  489. .put = cxt5045_hp_master_sw_put,
  490. .private_value = 0x10,
  491. },
  492. {}
  493. };
  494. static struct hda_verb cxt5045_init_verbs[] = {
  495. /* Line in, Mic */
  496. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  497. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  498. /* HP, Amp */
  499. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  500. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  501. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  502. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  503. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  504. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  505. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  506. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  507. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  508. /* Record selector: Int mic */
  509. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  510. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  511. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  512. /* SPDIF route: PCM */
  513. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  514. /* EAPD */
  515. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  516. { } /* end */
  517. };
  518. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  519. /* pin sensing on HP jack */
  520. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  521. { } /* end */
  522. };
  523. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  524. /* pin sensing on HP jack */
  525. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  526. { } /* end */
  527. };
  528. #ifdef CONFIG_SND_DEBUG
  529. /* Test configuration for debugging, modelled after the ALC260 test
  530. * configuration.
  531. */
  532. static struct hda_input_mux cxt5045_test_capture_source = {
  533. .num_items = 5,
  534. .items = {
  535. { "MIXER", 0x0 },
  536. { "MIC1 pin", 0x1 },
  537. { "LINE1 pin", 0x2 },
  538. { "HP-OUT pin", 0x3 },
  539. { "CD pin", 0x4 },
  540. },
  541. };
  542. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  543. /* Output controls */
  544. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  545. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  546. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  547. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  548. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  549. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  550. /* Modes for retasking pin widgets */
  551. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  552. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  553. /* EAPD Switch Control */
  554. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  555. /* Loopback mixer controls */
  556. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  557. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  558. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  559. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  560. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  561. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  562. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  563. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  564. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  565. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  566. {
  567. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  568. .name = "Input Source",
  569. .info = conexant_mux_enum_info,
  570. .get = conexant_mux_enum_get,
  571. .put = conexant_mux_enum_put,
  572. },
  573. /* Audio input controls */
  574. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  575. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  576. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  577. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  578. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  579. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  580. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  581. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  582. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  583. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  584. { } /* end */
  585. };
  586. static struct hda_verb cxt5045_test_init_verbs[] = {
  587. /* Set connections */
  588. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  589. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  590. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  591. /* Enable retasking pins as output, initially without power amp */
  592. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  593. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  594. /* Disable digital (SPDIF) pins initially, but users can enable
  595. * them via a mixer switch. In the case of SPDIF-out, this initverb
  596. * payload also sets the generation to 0, output to be in "consumer"
  597. * PCM format, copyright asserted, no pre-emphasis and no validity
  598. * control.
  599. */
  600. {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
  601. /* Start with output sum widgets muted and their output gains at min */
  602. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  603. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  604. /* Unmute retasking pin widget output buffers since the default
  605. * state appears to be output. As the pin mode is changed by the
  606. * user the pin mode control will take care of enabling the pin's
  607. * input/output buffers as needed.
  608. */
  609. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  610. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  611. /* Mute capture amp left and right */
  612. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  613. /* Set ADC connection select to match default mixer setting (mic1
  614. * pin)
  615. */
  616. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  617. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  618. /* Mute all inputs to mixer widget (even unconnected ones) */
  619. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  620. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  621. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  622. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  623. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  624. { }
  625. };
  626. #endif
  627. /* initialize jack-sensing, too */
  628. static int cxt5045_init(struct hda_codec *codec)
  629. {
  630. conexant_init(codec);
  631. cxt5045_hp_automute(codec);
  632. return 0;
  633. }
  634. enum {
  635. CXT5045_LAPTOP, /* Laptops w/ EAPD support */
  636. CXT5045_FUJITSU, /* Laptops w/ EAPD support */
  637. #ifdef CONFIG_SND_DEBUG
  638. CXT5045_TEST,
  639. #endif
  640. CXT5045_MODELS
  641. };
  642. static const char *cxt5045_models[CXT5045_MODELS] = {
  643. [CXT5045_LAPTOP] = "laptop",
  644. [CXT5045_FUJITSU] = "fujitsu",
  645. #ifdef CONFIG_SND_DEBUG
  646. [CXT5045_TEST] = "test",
  647. #endif
  648. };
  649. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  650. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
  651. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
  652. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
  653. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
  654. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
  655. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
  656. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
  657. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
  658. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
  659. {}
  660. };
  661. static int patch_cxt5045(struct hda_codec *codec)
  662. {
  663. struct conexant_spec *spec;
  664. int board_config;
  665. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  666. if (!spec)
  667. return -ENOMEM;
  668. mutex_init(&spec->amp_mutex);
  669. codec->spec = spec;
  670. spec->multiout.max_channels = 2;
  671. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  672. spec->multiout.dac_nids = cxt5045_dac_nids;
  673. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  674. spec->num_adc_nids = 1;
  675. spec->adc_nids = cxt5045_adc_nids;
  676. spec->capsrc_nids = cxt5045_capsrc_nids;
  677. spec->input_mux = &cxt5045_capture_source;
  678. spec->num_mixers = 1;
  679. spec->mixers[0] = cxt5045_mixers;
  680. spec->num_init_verbs = 1;
  681. spec->init_verbs[0] = cxt5045_init_verbs;
  682. spec->spdif_route = 0;
  683. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  684. spec->channel_mode = cxt5045_modes,
  685. codec->patch_ops = conexant_patch_ops;
  686. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  687. cxt5045_models,
  688. cxt5045_cfg_tbl);
  689. switch (board_config) {
  690. case CXT5045_LAPTOP:
  691. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  692. spec->input_mux = &cxt5045_capture_source;
  693. spec->num_init_verbs = 2;
  694. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  695. spec->mixers[0] = cxt5045_mixers;
  696. codec->patch_ops.init = cxt5045_init;
  697. break;
  698. case CXT5045_FUJITSU:
  699. spec->input_mux = &cxt5045_capture_source;
  700. spec->num_init_verbs = 2;
  701. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  702. spec->mixers[0] = cxt5045_mixers;
  703. codec->patch_ops.init = cxt5045_init;
  704. break;
  705. #ifdef CONFIG_SND_DEBUG
  706. case CXT5045_TEST:
  707. spec->input_mux = &cxt5045_test_capture_source;
  708. spec->mixers[0] = cxt5045_test_mixer;
  709. spec->init_verbs[0] = cxt5045_test_init_verbs;
  710. #endif
  711. }
  712. return 0;
  713. }
  714. /* Conexant 5047 specific */
  715. #define CXT5047_SPDIF_OUT 0x11
  716. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  717. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  718. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  719. static struct hda_channel_mode cxt5047_modes[1] = {
  720. { 2, NULL },
  721. };
  722. static struct hda_input_mux cxt5047_capture_source = {
  723. .num_items = 1,
  724. .items = {
  725. { "Mic", 0x2 },
  726. }
  727. };
  728. static struct hda_input_mux cxt5047_hp_capture_source = {
  729. .num_items = 1,
  730. .items = {
  731. { "ExtMic", 0x2 },
  732. }
  733. };
  734. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  735. .num_items = 2,
  736. .items = {
  737. { "ExtMic", 0x2 },
  738. { "Line-In", 0x1 },
  739. }
  740. };
  741. /* turn on/off EAPD (+ mute HP) as a master switch */
  742. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  743. struct snd_ctl_elem_value *ucontrol)
  744. {
  745. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  746. struct conexant_spec *spec = codec->spec;
  747. unsigned int bits;
  748. if (!cxt_eapd_put(kcontrol, ucontrol))
  749. return 0;
  750. /* toggle internal speakers mute depending of presence of
  751. * the headphone jack
  752. */
  753. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  754. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  755. HDA_AMP_MUTE, bits);
  756. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  757. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  758. HDA_AMP_MUTE, bits);
  759. return 1;
  760. }
  761. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  762. static struct hda_bind_ctls cxt5047_bind_master_vol = {
  763. .ops = &snd_hda_bind_vol,
  764. .values = {
  765. HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  766. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  767. 0
  768. },
  769. };
  770. /* mute internal speaker if HP is plugged */
  771. static void cxt5047_hp_automute(struct hda_codec *codec)
  772. {
  773. struct conexant_spec *spec = codec->spec;
  774. unsigned int bits;
  775. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  776. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  777. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  778. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  779. HDA_AMP_MUTE, bits);
  780. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  781. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  782. HDA_AMP_MUTE, bits);
  783. }
  784. /* mute internal speaker if HP is plugged */
  785. static void cxt5047_hp2_automute(struct hda_codec *codec)
  786. {
  787. struct conexant_spec *spec = codec->spec;
  788. unsigned int bits;
  789. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  790. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  791. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  792. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  793. HDA_AMP_MUTE, bits);
  794. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  795. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  796. HDA_AMP_MUTE, bits);
  797. }
  798. /* toggle input of built-in and mic jack appropriately */
  799. static void cxt5047_hp_automic(struct hda_codec *codec)
  800. {
  801. static struct hda_verb mic_jack_on[] = {
  802. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  803. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  804. {}
  805. };
  806. static struct hda_verb mic_jack_off[] = {
  807. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  808. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  809. {}
  810. };
  811. unsigned int present;
  812. present = snd_hda_codec_read(codec, 0x15, 0,
  813. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  814. if (present)
  815. snd_hda_sequence_write(codec, mic_jack_on);
  816. else
  817. snd_hda_sequence_write(codec, mic_jack_off);
  818. }
  819. /* unsolicited event for HP jack sensing */
  820. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  821. unsigned int res)
  822. {
  823. res >>= 26;
  824. switch (res) {
  825. case CONEXANT_HP_EVENT:
  826. cxt5047_hp_automute(codec);
  827. break;
  828. case CONEXANT_MIC_EVENT:
  829. cxt5047_hp_automic(codec);
  830. break;
  831. }
  832. }
  833. /* unsolicited event for HP jack sensing - non-EAPD systems */
  834. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  835. unsigned int res)
  836. {
  837. res >>= 26;
  838. switch (res) {
  839. case CONEXANT_HP_EVENT:
  840. cxt5047_hp2_automute(codec);
  841. break;
  842. case CONEXANT_MIC_EVENT:
  843. cxt5047_hp_automic(codec);
  844. break;
  845. }
  846. }
  847. static struct snd_kcontrol_new cxt5047_mixers[] = {
  848. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  849. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  850. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  851. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  852. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  853. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  854. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  855. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  856. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  857. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  858. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  859. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  860. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  861. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  862. {}
  863. };
  864. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  865. {
  866. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  867. .name = "Capture Source",
  868. .info = conexant_mux_enum_info,
  869. .get = conexant_mux_enum_get,
  870. .put = conexant_mux_enum_put
  871. },
  872. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  873. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  874. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  875. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  876. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  877. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  878. HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
  879. {
  880. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  881. .name = "Master Playback Switch",
  882. .info = cxt_eapd_info,
  883. .get = cxt_eapd_get,
  884. .put = cxt5047_hp_master_sw_put,
  885. .private_value = 0x13,
  886. },
  887. {}
  888. };
  889. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  890. {
  891. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  892. .name = "Capture Source",
  893. .info = conexant_mux_enum_info,
  894. .get = conexant_mux_enum_get,
  895. .put = conexant_mux_enum_put
  896. },
  897. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  898. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  899. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  900. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  901. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  902. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  903. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  904. {
  905. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  906. .name = "Master Playback Switch",
  907. .info = cxt_eapd_info,
  908. .get = cxt_eapd_get,
  909. .put = cxt5047_hp_master_sw_put,
  910. .private_value = 0x13,
  911. },
  912. { } /* end */
  913. };
  914. static struct hda_verb cxt5047_init_verbs[] = {
  915. /* Line in, Mic, Built-in Mic */
  916. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  917. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  918. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  919. /* HP, Speaker */
  920. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  921. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  922. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  923. /* Record selector: Mic */
  924. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  925. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  926. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  927. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  928. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  929. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  930. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  931. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  932. /* SPDIF route: PCM */
  933. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  934. /* Enable unsolicited events */
  935. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  936. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  937. { } /* end */
  938. };
  939. /* configuration for Toshiba Laptops */
  940. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  941. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  942. /* pin sensing on HP and Mic jacks */
  943. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  944. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  945. /* Speaker routing */
  946. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  947. {}
  948. };
  949. /* configuration for HP Laptops */
  950. static struct hda_verb cxt5047_hp_init_verbs[] = {
  951. /* pin sensing on HP jack */
  952. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  953. /* Record selector: Ext Mic */
  954. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  955. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  956. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  957. /* Speaker routing */
  958. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  959. {}
  960. };
  961. /* Test configuration for debugging, modelled after the ALC260 test
  962. * configuration.
  963. */
  964. #ifdef CONFIG_SND_DEBUG
  965. static struct hda_input_mux cxt5047_test_capture_source = {
  966. .num_items = 4,
  967. .items = {
  968. { "LINE1 pin", 0x0 },
  969. { "MIC1 pin", 0x1 },
  970. { "MIC2 pin", 0x2 },
  971. { "CD pin", 0x3 },
  972. },
  973. };
  974. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  975. /* Output only controls */
  976. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  977. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  978. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  979. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  980. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  981. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  982. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  983. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  984. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  985. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  986. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  987. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  988. /* Modes for retasking pin widgets */
  989. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  990. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  991. /* EAPD Switch Control */
  992. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  993. /* Loopback mixer controls */
  994. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  995. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  996. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  997. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  998. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  999. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1000. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1001. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1002. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1003. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1004. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1005. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1006. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1007. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1008. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1009. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1010. {
  1011. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1012. .name = "Input Source",
  1013. .info = conexant_mux_enum_info,
  1014. .get = conexant_mux_enum_get,
  1015. .put = conexant_mux_enum_put,
  1016. },
  1017. { } /* end */
  1018. };
  1019. static struct hda_verb cxt5047_test_init_verbs[] = {
  1020. /* Enable retasking pins as output, initially without power amp */
  1021. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1022. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1023. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1024. /* Disable digital (SPDIF) pins initially, but users can enable
  1025. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1026. * payload also sets the generation to 0, output to be in "consumer"
  1027. * PCM format, copyright asserted, no pre-emphasis and no validity
  1028. * control.
  1029. */
  1030. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1031. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1032. * OUT1 sum bus when acting as an output.
  1033. */
  1034. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1035. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1036. /* Start with output sum widgets muted and their output gains at min */
  1037. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1038. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1039. /* Unmute retasking pin widget output buffers since the default
  1040. * state appears to be output. As the pin mode is changed by the
  1041. * user the pin mode control will take care of enabling the pin's
  1042. * input/output buffers as needed.
  1043. */
  1044. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1045. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1046. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1047. /* Mute capture amp left and right */
  1048. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1049. /* Set ADC connection select to match default mixer setting (mic1
  1050. * pin)
  1051. */
  1052. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1053. /* Mute all inputs to mixer widget (even unconnected ones) */
  1054. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1055. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1056. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1057. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1058. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1059. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1060. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1061. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1062. { }
  1063. };
  1064. #endif
  1065. /* initialize jack-sensing, too */
  1066. static int cxt5047_hp_init(struct hda_codec *codec)
  1067. {
  1068. conexant_init(codec);
  1069. cxt5047_hp_automute(codec);
  1070. return 0;
  1071. }
  1072. enum {
  1073. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1074. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1075. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1076. #ifdef CONFIG_SND_DEBUG
  1077. CXT5047_TEST,
  1078. #endif
  1079. CXT5047_MODELS
  1080. };
  1081. static const char *cxt5047_models[CXT5047_MODELS] = {
  1082. [CXT5047_LAPTOP] = "laptop",
  1083. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1084. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1085. #ifdef CONFIG_SND_DEBUG
  1086. [CXT5047_TEST] = "test",
  1087. #endif
  1088. };
  1089. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1090. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1091. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1092. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1093. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1094. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1095. {}
  1096. };
  1097. static int patch_cxt5047(struct hda_codec *codec)
  1098. {
  1099. struct conexant_spec *spec;
  1100. int board_config;
  1101. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1102. if (!spec)
  1103. return -ENOMEM;
  1104. mutex_init(&spec->amp_mutex);
  1105. codec->spec = spec;
  1106. spec->multiout.max_channels = 2;
  1107. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1108. spec->multiout.dac_nids = cxt5047_dac_nids;
  1109. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1110. spec->num_adc_nids = 1;
  1111. spec->adc_nids = cxt5047_adc_nids;
  1112. spec->capsrc_nids = cxt5047_capsrc_nids;
  1113. spec->input_mux = &cxt5047_capture_source;
  1114. spec->num_mixers = 1;
  1115. spec->mixers[0] = cxt5047_mixers;
  1116. spec->num_init_verbs = 1;
  1117. spec->init_verbs[0] = cxt5047_init_verbs;
  1118. spec->spdif_route = 0;
  1119. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1120. spec->channel_mode = cxt5047_modes,
  1121. codec->patch_ops = conexant_patch_ops;
  1122. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1123. cxt5047_models,
  1124. cxt5047_cfg_tbl);
  1125. switch (board_config) {
  1126. case CXT5047_LAPTOP:
  1127. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1128. break;
  1129. case CXT5047_LAPTOP_HP:
  1130. spec->input_mux = &cxt5047_hp_capture_source;
  1131. spec->num_init_verbs = 2;
  1132. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1133. spec->mixers[0] = cxt5047_hp_mixers;
  1134. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1135. codec->patch_ops.init = cxt5047_hp_init;
  1136. break;
  1137. case CXT5047_LAPTOP_EAPD:
  1138. spec->input_mux = &cxt5047_toshiba_capture_source;
  1139. spec->num_init_verbs = 2;
  1140. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1141. spec->mixers[0] = cxt5047_toshiba_mixers;
  1142. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1143. break;
  1144. #ifdef CONFIG_SND_DEBUG
  1145. case CXT5047_TEST:
  1146. spec->input_mux = &cxt5047_test_capture_source;
  1147. spec->mixers[0] = cxt5047_test_mixer;
  1148. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1149. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1150. #endif
  1151. }
  1152. return 0;
  1153. }
  1154. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1155. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1156. .patch = patch_cxt5045 },
  1157. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1158. .patch = patch_cxt5047 },
  1159. {} /* terminator */
  1160. };