patch_conexant.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  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[4];
  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 int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *ucontrol)
  413. {
  414. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  415. long *valp = ucontrol->value.integer.value;
  416. int change;
  417. change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
  418. HDA_AMP_VOLMASK, valp[0]);
  419. change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
  420. HDA_AMP_VOLMASK, valp[1]);
  421. snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
  422. HDA_AMP_VOLMASK, valp[0]);
  423. snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
  424. HDA_AMP_VOLMASK, valp[1]);
  425. return change;
  426. }
  427. /* toggle input of built-in and mic jack appropriately */
  428. static void cxt5045_hp_automic(struct hda_codec *codec)
  429. {
  430. static struct hda_verb mic_jack_on[] = {
  431. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  432. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  433. {}
  434. };
  435. static struct hda_verb mic_jack_off[] = {
  436. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  437. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  438. {}
  439. };
  440. unsigned int present;
  441. present = snd_hda_codec_read(codec, 0x12, 0,
  442. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  443. if (present)
  444. snd_hda_sequence_write(codec, mic_jack_on);
  445. else
  446. snd_hda_sequence_write(codec, mic_jack_off);
  447. }
  448. /* mute internal speaker if HP is plugged */
  449. static void cxt5045_hp_automute(struct hda_codec *codec)
  450. {
  451. struct conexant_spec *spec = codec->spec;
  452. unsigned int bits;
  453. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  454. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  455. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  456. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  457. HDA_AMP_MUTE, bits);
  458. }
  459. /* unsolicited event for HP jack sensing */
  460. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  461. unsigned int res)
  462. {
  463. res >>= 26;
  464. switch (res) {
  465. case CONEXANT_HP_EVENT:
  466. cxt5045_hp_automute(codec);
  467. break;
  468. case CONEXANT_MIC_EVENT:
  469. cxt5045_hp_automic(codec);
  470. break;
  471. }
  472. }
  473. static struct snd_kcontrol_new cxt5045_mixers[] = {
  474. {
  475. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  476. .name = "Capture Source",
  477. .info = conexant_mux_enum_info,
  478. .get = conexant_mux_enum_get,
  479. .put = conexant_mux_enum_put
  480. },
  481. HDA_CODEC_VOLUME("Int Mic Volume", 0x1a, 0x01, HDA_INPUT),
  482. HDA_CODEC_MUTE("Int Mic Switch", 0x1a, 0x01, HDA_INPUT),
  483. HDA_CODEC_VOLUME("Ext Mic Volume", 0x1a, 0x02, HDA_INPUT),
  484. HDA_CODEC_MUTE("Ext Mic Switch", 0x1a, 0x02, HDA_INPUT),
  485. {
  486. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  487. .name = "Master Playback Volume",
  488. .info = snd_hda_mixer_amp_volume_info,
  489. .get = snd_hda_mixer_amp_volume_get,
  490. .put = cxt5045_hp_master_vol_put,
  491. .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  492. },
  493. {
  494. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  495. .name = "Master Playback Switch",
  496. .info = cxt_eapd_info,
  497. .get = cxt_eapd_get,
  498. .put = cxt5045_hp_master_sw_put,
  499. .private_value = 0x10,
  500. },
  501. {}
  502. };
  503. static struct hda_verb cxt5045_init_verbs[] = {
  504. /* Line in, Mic */
  505. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  506. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  507. /* HP, Amp */
  508. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  509. {0x17, AC_VERB_SET_CONNECT_SEL,0x01},
  510. {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
  511. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
  512. {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
  513. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
  514. {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
  515. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  516. {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
  517. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
  518. /* Record selector: Int mic */
  519. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  520. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  521. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  522. /* SPDIF route: PCM */
  523. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  524. /* EAPD */
  525. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  526. { } /* end */
  527. };
  528. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  529. /* pin sensing on HP jack */
  530. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  531. { } /* end */
  532. };
  533. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  534. /* pin sensing on HP jack */
  535. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  536. { } /* end */
  537. };
  538. #ifdef CONFIG_SND_DEBUG
  539. /* Test configuration for debugging, modelled after the ALC260 test
  540. * configuration.
  541. */
  542. static struct hda_input_mux cxt5045_test_capture_source = {
  543. .num_items = 5,
  544. .items = {
  545. { "MIXER", 0x0 },
  546. { "MIC1 pin", 0x1 },
  547. { "LINE1 pin", 0x2 },
  548. { "HP-OUT pin", 0x3 },
  549. { "CD pin", 0x4 },
  550. },
  551. };
  552. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  553. /* Output controls */
  554. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  555. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  556. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  557. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  558. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  559. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  560. /* Modes for retasking pin widgets */
  561. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  562. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  563. /* EAPD Switch Control */
  564. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  565. /* Loopback mixer controls */
  566. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  567. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  568. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  569. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  570. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  571. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  572. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  573. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  574. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  575. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  576. {
  577. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  578. .name = "Input Source",
  579. .info = conexant_mux_enum_info,
  580. .get = conexant_mux_enum_get,
  581. .put = conexant_mux_enum_put,
  582. },
  583. /* Audio input controls */
  584. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  585. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  586. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  587. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  588. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  589. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  590. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  591. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  592. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  593. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  594. { } /* end */
  595. };
  596. static struct hda_verb cxt5045_test_init_verbs[] = {
  597. /* Set connections */
  598. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  599. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  600. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  601. /* Enable retasking pins as output, initially without power amp */
  602. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  603. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  604. /* Disable digital (SPDIF) pins initially, but users can enable
  605. * them via a mixer switch. In the case of SPDIF-out, this initverb
  606. * payload also sets the generation to 0, output to be in "consumer"
  607. * PCM format, copyright asserted, no pre-emphasis and no validity
  608. * control.
  609. */
  610. {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
  611. /* Start with output sum widgets muted and their output gains at min */
  612. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  613. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  614. /* Unmute retasking pin widget output buffers since the default
  615. * state appears to be output. As the pin mode is changed by the
  616. * user the pin mode control will take care of enabling the pin's
  617. * input/output buffers as needed.
  618. */
  619. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  620. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  621. /* Mute capture amp left and right */
  622. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  623. /* Set ADC connection select to match default mixer setting (mic1
  624. * pin)
  625. */
  626. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  627. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  628. /* Mute all inputs to mixer widget (even unconnected ones) */
  629. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  630. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  631. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  632. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  633. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  634. { }
  635. };
  636. #endif
  637. /* initialize jack-sensing, too */
  638. static int cxt5045_init(struct hda_codec *codec)
  639. {
  640. conexant_init(codec);
  641. cxt5045_hp_automute(codec);
  642. return 0;
  643. }
  644. enum {
  645. CXT5045_LAPTOP, /* Laptops w/ EAPD support */
  646. CXT5045_FUJITSU, /* Laptops w/ EAPD support */
  647. #ifdef CONFIG_SND_DEBUG
  648. CXT5045_TEST,
  649. #endif
  650. CXT5045_MODELS
  651. };
  652. static const char *cxt5045_models[CXT5045_MODELS] = {
  653. [CXT5045_LAPTOP] = "laptop",
  654. [CXT5045_FUJITSU] = "fujitsu",
  655. #ifdef CONFIG_SND_DEBUG
  656. [CXT5045_TEST] = "test",
  657. #endif
  658. };
  659. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  660. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
  661. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
  662. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
  663. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
  664. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
  665. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
  666. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
  667. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
  668. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
  669. {}
  670. };
  671. static int patch_cxt5045(struct hda_codec *codec)
  672. {
  673. struct conexant_spec *spec;
  674. int board_config;
  675. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  676. if (!spec)
  677. return -ENOMEM;
  678. mutex_init(&spec->amp_mutex);
  679. codec->spec = spec;
  680. spec->multiout.max_channels = 2;
  681. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  682. spec->multiout.dac_nids = cxt5045_dac_nids;
  683. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  684. spec->num_adc_nids = 1;
  685. spec->adc_nids = cxt5045_adc_nids;
  686. spec->capsrc_nids = cxt5045_capsrc_nids;
  687. spec->input_mux = &cxt5045_capture_source;
  688. spec->num_mixers = 1;
  689. spec->mixers[0] = cxt5045_mixers;
  690. spec->num_init_verbs = 1;
  691. spec->init_verbs[0] = cxt5045_init_verbs;
  692. spec->spdif_route = 0;
  693. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  694. spec->channel_mode = cxt5045_modes,
  695. codec->patch_ops = conexant_patch_ops;
  696. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  697. cxt5045_models,
  698. cxt5045_cfg_tbl);
  699. switch (board_config) {
  700. case CXT5045_LAPTOP:
  701. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  702. spec->input_mux = &cxt5045_capture_source;
  703. spec->num_init_verbs = 2;
  704. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  705. spec->mixers[0] = cxt5045_mixers;
  706. codec->patch_ops.init = cxt5045_init;
  707. break;
  708. case CXT5045_FUJITSU:
  709. spec->input_mux = &cxt5045_capture_source;
  710. spec->num_init_verbs = 2;
  711. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  712. spec->mixers[0] = cxt5045_mixers;
  713. codec->patch_ops.init = cxt5045_init;
  714. break;
  715. #ifdef CONFIG_SND_DEBUG
  716. case CXT5045_TEST:
  717. spec->input_mux = &cxt5045_test_capture_source;
  718. spec->mixers[0] = cxt5045_test_mixer;
  719. spec->init_verbs[0] = cxt5045_test_init_verbs;
  720. #endif
  721. }
  722. return 0;
  723. }
  724. /* Conexant 5047 specific */
  725. #define CXT5047_SPDIF_OUT 0x11
  726. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  727. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  728. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  729. static struct hda_channel_mode cxt5047_modes[1] = {
  730. { 2, NULL },
  731. };
  732. static struct hda_input_mux cxt5047_capture_source = {
  733. .num_items = 1,
  734. .items = {
  735. { "Mic", 0x2 },
  736. }
  737. };
  738. static struct hda_input_mux cxt5047_hp_capture_source = {
  739. .num_items = 1,
  740. .items = {
  741. { "ExtMic", 0x2 },
  742. }
  743. };
  744. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  745. .num_items = 2,
  746. .items = {
  747. { "ExtMic", 0x2 },
  748. { "Line-In", 0x1 },
  749. }
  750. };
  751. /* turn on/off EAPD (+ mute HP) as a master switch */
  752. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  753. struct snd_ctl_elem_value *ucontrol)
  754. {
  755. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  756. struct conexant_spec *spec = codec->spec;
  757. unsigned int bits;
  758. if (!cxt_eapd_put(kcontrol, ucontrol))
  759. return 0;
  760. /* toggle internal speakers mute depending of presence of
  761. * the headphone jack
  762. */
  763. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  764. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  765. HDA_AMP_MUTE, bits);
  766. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  767. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  768. HDA_AMP_MUTE, bits);
  769. return 1;
  770. }
  771. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  772. static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  773. struct snd_ctl_elem_value *ucontrol)
  774. {
  775. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  776. long *valp = ucontrol->value.integer.value;
  777. int change;
  778. change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
  779. HDA_AMP_VOLMASK, valp[0]);
  780. change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
  781. HDA_AMP_VOLMASK, valp[1]);
  782. snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
  783. HDA_AMP_VOLMASK, valp[0]);
  784. snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
  785. HDA_AMP_VOLMASK, valp[1]);
  786. return change;
  787. }
  788. /* mute internal speaker if HP is plugged */
  789. static void cxt5047_hp_automute(struct hda_codec *codec)
  790. {
  791. struct conexant_spec *spec = codec->spec;
  792. unsigned int bits;
  793. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  794. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  795. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  796. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  797. HDA_AMP_MUTE, bits);
  798. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  799. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  800. HDA_AMP_MUTE, bits);
  801. }
  802. /* mute internal speaker if HP is plugged */
  803. static void cxt5047_hp2_automute(struct hda_codec *codec)
  804. {
  805. struct conexant_spec *spec = codec->spec;
  806. unsigned int bits;
  807. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  808. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  809. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  810. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  811. HDA_AMP_MUTE, bits);
  812. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  813. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  814. HDA_AMP_MUTE, bits);
  815. }
  816. /* toggle input of built-in and mic jack appropriately */
  817. static void cxt5047_hp_automic(struct hda_codec *codec)
  818. {
  819. static struct hda_verb mic_jack_on[] = {
  820. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  821. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  822. {}
  823. };
  824. static struct hda_verb mic_jack_off[] = {
  825. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  826. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  827. {}
  828. };
  829. unsigned int present;
  830. present = snd_hda_codec_read(codec, 0x15, 0,
  831. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  832. if (present)
  833. snd_hda_sequence_write(codec, mic_jack_on);
  834. else
  835. snd_hda_sequence_write(codec, mic_jack_off);
  836. }
  837. /* unsolicited event for HP jack sensing */
  838. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  839. unsigned int res)
  840. {
  841. res >>= 26;
  842. switch (res) {
  843. case CONEXANT_HP_EVENT:
  844. cxt5047_hp_automute(codec);
  845. break;
  846. case CONEXANT_MIC_EVENT:
  847. cxt5047_hp_automic(codec);
  848. break;
  849. }
  850. }
  851. /* unsolicited event for HP jack sensing - non-EAPD systems */
  852. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  853. unsigned int res)
  854. {
  855. res >>= 26;
  856. switch (res) {
  857. case CONEXANT_HP_EVENT:
  858. cxt5047_hp2_automute(codec);
  859. break;
  860. case CONEXANT_MIC_EVENT:
  861. cxt5047_hp_automic(codec);
  862. break;
  863. }
  864. }
  865. static struct snd_kcontrol_new cxt5047_mixers[] = {
  866. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  867. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  868. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  869. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  870. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  871. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  872. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  873. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  874. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  875. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  876. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  877. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  878. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  879. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  880. {}
  881. };
  882. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  883. {
  884. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  885. .name = "Capture Source",
  886. .info = conexant_mux_enum_info,
  887. .get = conexant_mux_enum_get,
  888. .put = conexant_mux_enum_put
  889. },
  890. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  891. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  892. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  893. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  894. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  895. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  896. {
  897. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  898. .name = "Master Playback Volume",
  899. .info = snd_hda_mixer_amp_volume_info,
  900. .get = snd_hda_mixer_amp_volume_get,
  901. .put = cxt5047_hp_master_vol_put,
  902. .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  903. },
  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. {}
  913. };
  914. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  915. {
  916. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  917. .name = "Capture Source",
  918. .info = conexant_mux_enum_info,
  919. .get = conexant_mux_enum_get,
  920. .put = conexant_mux_enum_put
  921. },
  922. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  923. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  924. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  925. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  926. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  927. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  928. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  929. {
  930. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  931. .name = "Master Playback Switch",
  932. .info = cxt_eapd_info,
  933. .get = cxt_eapd_get,
  934. .put = cxt5047_hp_master_sw_put,
  935. .private_value = 0x13,
  936. },
  937. { } /* end */
  938. };
  939. static struct hda_verb cxt5047_init_verbs[] = {
  940. /* Line in, Mic, Built-in Mic */
  941. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  942. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  943. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  944. /* HP, Speaker */
  945. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  946. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  947. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  948. /* Record selector: Mic */
  949. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  950. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  951. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  952. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  953. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  954. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  955. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  956. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  957. /* SPDIF route: PCM */
  958. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  959. /* Enable unsolicited events */
  960. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  961. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  962. { } /* end */
  963. };
  964. /* configuration for Toshiba Laptops */
  965. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  966. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  967. /* pin sensing on HP and Mic jacks */
  968. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  969. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  970. /* Speaker routing */
  971. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  972. {}
  973. };
  974. /* configuration for HP Laptops */
  975. static struct hda_verb cxt5047_hp_init_verbs[] = {
  976. /* pin sensing on HP jack */
  977. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  978. /* Record selector: Ext Mic */
  979. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  980. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  981. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  982. /* Speaker routing */
  983. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  984. {}
  985. };
  986. /* Test configuration for debugging, modelled after the ALC260 test
  987. * configuration.
  988. */
  989. #ifdef CONFIG_SND_DEBUG
  990. static struct hda_input_mux cxt5047_test_capture_source = {
  991. .num_items = 4,
  992. .items = {
  993. { "LINE1 pin", 0x0 },
  994. { "MIC1 pin", 0x1 },
  995. { "MIC2 pin", 0x2 },
  996. { "CD pin", 0x3 },
  997. },
  998. };
  999. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1000. /* Output only controls */
  1001. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1002. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1003. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1004. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1005. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1006. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1007. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1008. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1009. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1010. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1011. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1012. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1013. /* Modes for retasking pin widgets */
  1014. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1015. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1016. /* EAPD Switch Control */
  1017. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1018. /* Loopback mixer controls */
  1019. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1020. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1021. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1022. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1023. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1024. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1025. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1026. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1027. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1028. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1029. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1030. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1031. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1032. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1033. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1034. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1035. {
  1036. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1037. .name = "Input Source",
  1038. .info = conexant_mux_enum_info,
  1039. .get = conexant_mux_enum_get,
  1040. .put = conexant_mux_enum_put,
  1041. },
  1042. { } /* end */
  1043. };
  1044. static struct hda_verb cxt5047_test_init_verbs[] = {
  1045. /* Enable retasking pins as output, initially without power amp */
  1046. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1047. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1048. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1049. /* Disable digital (SPDIF) pins initially, but users can enable
  1050. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1051. * payload also sets the generation to 0, output to be in "consumer"
  1052. * PCM format, copyright asserted, no pre-emphasis and no validity
  1053. * control.
  1054. */
  1055. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1056. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1057. * OUT1 sum bus when acting as an output.
  1058. */
  1059. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1060. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1061. /* Start with output sum widgets muted and their output gains at min */
  1062. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1063. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1064. /* Unmute retasking pin widget output buffers since the default
  1065. * state appears to be output. As the pin mode is changed by the
  1066. * user the pin mode control will take care of enabling the pin's
  1067. * input/output buffers as needed.
  1068. */
  1069. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1070. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1071. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1072. /* Mute capture amp left and right */
  1073. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1074. /* Set ADC connection select to match default mixer setting (mic1
  1075. * pin)
  1076. */
  1077. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1078. /* Mute all inputs to mixer widget (even unconnected ones) */
  1079. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1080. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1081. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1082. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1083. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1084. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1085. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1086. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1087. { }
  1088. };
  1089. #endif
  1090. /* initialize jack-sensing, too */
  1091. static int cxt5047_hp_init(struct hda_codec *codec)
  1092. {
  1093. conexant_init(codec);
  1094. cxt5047_hp_automute(codec);
  1095. return 0;
  1096. }
  1097. enum {
  1098. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1099. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1100. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1101. #ifdef CONFIG_SND_DEBUG
  1102. CXT5047_TEST,
  1103. #endif
  1104. CXT5047_MODELS
  1105. };
  1106. static const char *cxt5047_models[CXT5047_MODELS] = {
  1107. [CXT5047_LAPTOP] = "laptop",
  1108. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1109. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1110. #ifdef CONFIG_SND_DEBUG
  1111. [CXT5047_TEST] = "test",
  1112. #endif
  1113. };
  1114. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1115. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1116. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1117. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1118. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1119. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1120. {}
  1121. };
  1122. static int patch_cxt5047(struct hda_codec *codec)
  1123. {
  1124. struct conexant_spec *spec;
  1125. int board_config;
  1126. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1127. if (!spec)
  1128. return -ENOMEM;
  1129. mutex_init(&spec->amp_mutex);
  1130. codec->spec = spec;
  1131. spec->multiout.max_channels = 2;
  1132. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1133. spec->multiout.dac_nids = cxt5047_dac_nids;
  1134. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1135. spec->num_adc_nids = 1;
  1136. spec->adc_nids = cxt5047_adc_nids;
  1137. spec->capsrc_nids = cxt5047_capsrc_nids;
  1138. spec->input_mux = &cxt5047_capture_source;
  1139. spec->num_mixers = 1;
  1140. spec->mixers[0] = cxt5047_mixers;
  1141. spec->num_init_verbs = 1;
  1142. spec->init_verbs[0] = cxt5047_init_verbs;
  1143. spec->spdif_route = 0;
  1144. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1145. spec->channel_mode = cxt5047_modes,
  1146. codec->patch_ops = conexant_patch_ops;
  1147. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1148. cxt5047_models,
  1149. cxt5047_cfg_tbl);
  1150. switch (board_config) {
  1151. case CXT5047_LAPTOP:
  1152. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1153. break;
  1154. case CXT5047_LAPTOP_HP:
  1155. spec->input_mux = &cxt5047_hp_capture_source;
  1156. spec->num_init_verbs = 2;
  1157. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1158. spec->mixers[0] = cxt5047_hp_mixers;
  1159. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1160. codec->patch_ops.init = cxt5047_hp_init;
  1161. break;
  1162. case CXT5047_LAPTOP_EAPD:
  1163. spec->input_mux = &cxt5047_toshiba_capture_source;
  1164. spec->num_init_verbs = 2;
  1165. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1166. spec->mixers[0] = cxt5047_toshiba_mixers;
  1167. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1168. break;
  1169. #ifdef CONFIG_SND_DEBUG
  1170. case CXT5047_TEST:
  1171. spec->input_mux = &cxt5047_test_capture_source;
  1172. spec->mixers[0] = cxt5047_test_mixer;
  1173. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1174. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1175. #endif
  1176. }
  1177. return 0;
  1178. }
  1179. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1180. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1181. .patch = patch_cxt5045 },
  1182. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1183. .patch = patch_cxt5047 },
  1184. {} /* terminator */
  1185. };