patch_conexant.c 43 KB

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