patch_conexant.c 42 KB

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