patch_conexant.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_patch.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. unsigned int cur_adc_idx;
  58. hda_nid_t cur_adc;
  59. unsigned int cur_adc_stream_tag;
  60. unsigned int cur_adc_format;
  61. /* capture source */
  62. const struct hda_input_mux *input_mux;
  63. hda_nid_t *capsrc_nids;
  64. unsigned int cur_mux[3];
  65. /* channel model */
  66. const struct hda_channel_mode *channel_mode;
  67. int num_channel_mode;
  68. /* PCM information */
  69. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  70. unsigned int spdif_route;
  71. /* dynamic controls, init_verbs and input_mux */
  72. struct auto_pin_cfg autocfg;
  73. unsigned int num_kctl_alloc, num_kctl_used;
  74. struct snd_kcontrol_new *kctl_alloc;
  75. struct hda_input_mux private_imux;
  76. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  77. };
  78. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  79. struct hda_codec *codec,
  80. struct snd_pcm_substream *substream)
  81. {
  82. struct conexant_spec *spec = codec->spec;
  83. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  84. hinfo);
  85. }
  86. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  87. struct hda_codec *codec,
  88. unsigned int stream_tag,
  89. unsigned int format,
  90. struct snd_pcm_substream *substream)
  91. {
  92. struct conexant_spec *spec = codec->spec;
  93. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  94. stream_tag,
  95. format, substream);
  96. }
  97. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  98. struct hda_codec *codec,
  99. struct snd_pcm_substream *substream)
  100. {
  101. struct conexant_spec *spec = codec->spec;
  102. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  103. }
  104. /*
  105. * Digital out
  106. */
  107. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  108. struct hda_codec *codec,
  109. struct snd_pcm_substream *substream)
  110. {
  111. struct conexant_spec *spec = codec->spec;
  112. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  113. }
  114. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  115. struct hda_codec *codec,
  116. struct snd_pcm_substream *substream)
  117. {
  118. struct conexant_spec *spec = codec->spec;
  119. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  120. }
  121. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  122. struct hda_codec *codec,
  123. unsigned int stream_tag,
  124. unsigned int format,
  125. struct snd_pcm_substream *substream)
  126. {
  127. struct conexant_spec *spec = codec->spec;
  128. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  129. stream_tag,
  130. format, substream);
  131. }
  132. /*
  133. * Analog capture
  134. */
  135. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  136. struct hda_codec *codec,
  137. unsigned int stream_tag,
  138. unsigned int format,
  139. struct snd_pcm_substream *substream)
  140. {
  141. struct conexant_spec *spec = codec->spec;
  142. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  143. stream_tag, 0, format);
  144. return 0;
  145. }
  146. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  147. struct hda_codec *codec,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  152. return 0;
  153. }
  154. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  155. .substreams = 1,
  156. .channels_min = 2,
  157. .channels_max = 2,
  158. .nid = 0, /* fill later */
  159. .ops = {
  160. .open = conexant_playback_pcm_open,
  161. .prepare = conexant_playback_pcm_prepare,
  162. .cleanup = conexant_playback_pcm_cleanup
  163. },
  164. };
  165. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  166. .substreams = 1,
  167. .channels_min = 2,
  168. .channels_max = 2,
  169. .nid = 0, /* fill later */
  170. .ops = {
  171. .prepare = conexant_capture_pcm_prepare,
  172. .cleanup = conexant_capture_pcm_cleanup
  173. },
  174. };
  175. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  176. .substreams = 1,
  177. .channels_min = 2,
  178. .channels_max = 2,
  179. .nid = 0, /* fill later */
  180. .ops = {
  181. .open = conexant_dig_playback_pcm_open,
  182. .close = conexant_dig_playback_pcm_close,
  183. .prepare = conexant_dig_playback_pcm_prepare
  184. },
  185. };
  186. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  187. .substreams = 1,
  188. .channels_min = 2,
  189. .channels_max = 2,
  190. /* NID is set in alc_build_pcms */
  191. };
  192. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  193. struct hda_codec *codec,
  194. unsigned int stream_tag,
  195. unsigned int format,
  196. struct snd_pcm_substream *substream)
  197. {
  198. struct conexant_spec *spec = codec->spec;
  199. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  200. spec->cur_adc_stream_tag = stream_tag;
  201. spec->cur_adc_format = format;
  202. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  203. return 0;
  204. }
  205. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  206. struct hda_codec *codec,
  207. struct snd_pcm_substream *substream)
  208. {
  209. struct conexant_spec *spec = codec->spec;
  210. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  211. spec->cur_adc = 0;
  212. return 0;
  213. }
  214. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  215. .substreams = 1,
  216. .channels_min = 2,
  217. .channels_max = 2,
  218. .nid = 0, /* fill later */
  219. .ops = {
  220. .prepare = cx5051_capture_pcm_prepare,
  221. .cleanup = cx5051_capture_pcm_cleanup
  222. },
  223. };
  224. static int conexant_build_pcms(struct hda_codec *codec)
  225. {
  226. struct conexant_spec *spec = codec->spec;
  227. struct hda_pcm *info = spec->pcm_rec;
  228. codec->num_pcms = 1;
  229. codec->pcm_info = info;
  230. info->name = "CONEXANT Analog";
  231. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  232. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  233. spec->multiout.max_channels;
  234. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  235. spec->multiout.dac_nids[0];
  236. if (codec->vendor_id == 0x14f15051)
  237. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  238. cx5051_pcm_analog_capture;
  239. else
  240. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  241. conexant_pcm_analog_capture;
  242. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  243. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  244. if (spec->multiout.dig_out_nid) {
  245. info++;
  246. codec->num_pcms++;
  247. info->name = "Conexant Digital";
  248. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  249. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  250. conexant_pcm_digital_playback;
  251. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  252. spec->multiout.dig_out_nid;
  253. if (spec->dig_in_nid) {
  254. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  255. conexant_pcm_digital_capture;
  256. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  257. spec->dig_in_nid;
  258. }
  259. }
  260. return 0;
  261. }
  262. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  263. struct snd_ctl_elem_info *uinfo)
  264. {
  265. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  266. struct conexant_spec *spec = codec->spec;
  267. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  268. }
  269. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  270. struct snd_ctl_elem_value *ucontrol)
  271. {
  272. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  273. struct conexant_spec *spec = codec->spec;
  274. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  275. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  276. return 0;
  277. }
  278. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  279. struct snd_ctl_elem_value *ucontrol)
  280. {
  281. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  282. struct conexant_spec *spec = codec->spec;
  283. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  284. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  285. spec->capsrc_nids[adc_idx],
  286. &spec->cur_mux[adc_idx]);
  287. }
  288. static int conexant_init(struct hda_codec *codec)
  289. {
  290. struct conexant_spec *spec = codec->spec;
  291. int i;
  292. for (i = 0; i < spec->num_init_verbs; i++)
  293. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  294. return 0;
  295. }
  296. static void conexant_free(struct hda_codec *codec)
  297. {
  298. struct conexant_spec *spec = codec->spec;
  299. unsigned int i;
  300. if (spec->kctl_alloc) {
  301. for (i = 0; i < spec->num_kctl_used; i++)
  302. kfree(spec->kctl_alloc[i].name);
  303. kfree(spec->kctl_alloc);
  304. }
  305. kfree(codec->spec);
  306. }
  307. static int conexant_build_controls(struct hda_codec *codec)
  308. {
  309. struct conexant_spec *spec = codec->spec;
  310. unsigned int i;
  311. int err;
  312. for (i = 0; i < spec->num_mixers; i++) {
  313. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  314. if (err < 0)
  315. return err;
  316. }
  317. if (spec->multiout.dig_out_nid) {
  318. err = snd_hda_create_spdif_out_ctls(codec,
  319. spec->multiout.dig_out_nid);
  320. if (err < 0)
  321. return err;
  322. err = snd_hda_create_spdif_share_sw(codec,
  323. &spec->multiout);
  324. if (err < 0)
  325. return err;
  326. spec->multiout.share_spdif = 1;
  327. }
  328. if (spec->dig_in_nid) {
  329. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  330. if (err < 0)
  331. return err;
  332. }
  333. return 0;
  334. }
  335. static struct hda_codec_ops conexant_patch_ops = {
  336. .build_controls = conexant_build_controls,
  337. .build_pcms = conexant_build_pcms,
  338. .init = conexant_init,
  339. .free = conexant_free,
  340. };
  341. /*
  342. * EAPD control
  343. * the private value = nid | (invert << 8)
  344. */
  345. #define cxt_eapd_info snd_ctl_boolean_mono_info
  346. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  347. struct snd_ctl_elem_value *ucontrol)
  348. {
  349. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  350. struct conexant_spec *spec = codec->spec;
  351. int invert = (kcontrol->private_value >> 8) & 1;
  352. if (invert)
  353. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  354. else
  355. ucontrol->value.integer.value[0] = spec->cur_eapd;
  356. return 0;
  357. }
  358. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  359. struct snd_ctl_elem_value *ucontrol)
  360. {
  361. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  362. struct conexant_spec *spec = codec->spec;
  363. int invert = (kcontrol->private_value >> 8) & 1;
  364. hda_nid_t nid = kcontrol->private_value & 0xff;
  365. unsigned int eapd;
  366. eapd = !!ucontrol->value.integer.value[0];
  367. if (invert)
  368. eapd = !eapd;
  369. if (eapd == spec->cur_eapd)
  370. return 0;
  371. spec->cur_eapd = eapd;
  372. snd_hda_codec_write_cache(codec, nid,
  373. 0, AC_VERB_SET_EAPD_BTLENABLE,
  374. eapd ? 0x02 : 0x00);
  375. return 1;
  376. }
  377. /* controls for test mode */
  378. #ifdef CONFIG_SND_DEBUG
  379. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  380. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  381. .info = cxt_eapd_info, \
  382. .get = cxt_eapd_get, \
  383. .put = cxt_eapd_put, \
  384. .private_value = nid | (mask<<16) }
  385. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  386. struct snd_ctl_elem_info *uinfo)
  387. {
  388. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  389. struct conexant_spec *spec = codec->spec;
  390. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  391. spec->num_channel_mode);
  392. }
  393. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_value *ucontrol)
  395. {
  396. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  397. struct conexant_spec *spec = codec->spec;
  398. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  399. spec->num_channel_mode,
  400. spec->multiout.max_channels);
  401. }
  402. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  403. struct snd_ctl_elem_value *ucontrol)
  404. {
  405. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  406. struct conexant_spec *spec = codec->spec;
  407. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  408. spec->num_channel_mode,
  409. &spec->multiout.max_channels);
  410. if (err >= 0 && spec->need_dac_fix)
  411. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  412. return err;
  413. }
  414. #define CXT_PIN_MODE(xname, nid, dir) \
  415. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  416. .info = conexant_ch_mode_info, \
  417. .get = conexant_ch_mode_get, \
  418. .put = conexant_ch_mode_put, \
  419. .private_value = nid | (dir<<16) }
  420. #endif /* CONFIG_SND_DEBUG */
  421. /* Conexant 5045 specific */
  422. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  423. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  424. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  425. #define CXT5045_SPDIF_OUT 0x18
  426. static struct hda_channel_mode cxt5045_modes[1] = {
  427. { 2, NULL },
  428. };
  429. static struct hda_input_mux cxt5045_capture_source = {
  430. .num_items = 2,
  431. .items = {
  432. { "IntMic", 0x1 },
  433. { "ExtMic", 0x2 },
  434. }
  435. };
  436. static struct hda_input_mux cxt5045_capture_source_benq = {
  437. .num_items = 3,
  438. .items = {
  439. { "IntMic", 0x1 },
  440. { "ExtMic", 0x2 },
  441. { "LineIn", 0x3 },
  442. }
  443. };
  444. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  445. .num_items = 2,
  446. .items = {
  447. { "ExtMic", 0x1 },
  448. { "IntMic", 0x2 },
  449. }
  450. };
  451. /* turn on/off EAPD (+ mute HP) as a master switch */
  452. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  453. struct snd_ctl_elem_value *ucontrol)
  454. {
  455. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  456. struct conexant_spec *spec = codec->spec;
  457. unsigned int bits;
  458. if (!cxt_eapd_put(kcontrol, ucontrol))
  459. return 0;
  460. /* toggle internal speakers mute depending of presence of
  461. * the headphone jack
  462. */
  463. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  464. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  465. HDA_AMP_MUTE, bits);
  466. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  467. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  468. HDA_AMP_MUTE, bits);
  469. return 1;
  470. }
  471. /* bind volumes of both NID 0x10 and 0x11 */
  472. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  473. .ops = &snd_hda_bind_vol,
  474. .values = {
  475. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  476. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  477. 0
  478. },
  479. };
  480. /* toggle input of built-in and mic jack appropriately */
  481. static void cxt5045_hp_automic(struct hda_codec *codec)
  482. {
  483. static struct hda_verb mic_jack_on[] = {
  484. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  485. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  486. {}
  487. };
  488. static struct hda_verb mic_jack_off[] = {
  489. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  490. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  491. {}
  492. };
  493. unsigned int present;
  494. present = snd_hda_codec_read(codec, 0x12, 0,
  495. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  496. if (present)
  497. snd_hda_sequence_write(codec, mic_jack_on);
  498. else
  499. snd_hda_sequence_write(codec, mic_jack_off);
  500. }
  501. /* mute internal speaker if HP is plugged */
  502. static void cxt5045_hp_automute(struct hda_codec *codec)
  503. {
  504. struct conexant_spec *spec = codec->spec;
  505. unsigned int bits;
  506. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  507. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  508. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  509. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  510. HDA_AMP_MUTE, bits);
  511. }
  512. /* unsolicited event for HP jack sensing */
  513. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  514. unsigned int res)
  515. {
  516. res >>= 26;
  517. switch (res) {
  518. case CONEXANT_HP_EVENT:
  519. cxt5045_hp_automute(codec);
  520. break;
  521. case CONEXANT_MIC_EVENT:
  522. cxt5045_hp_automic(codec);
  523. break;
  524. }
  525. }
  526. static struct snd_kcontrol_new cxt5045_mixers[] = {
  527. {
  528. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  529. .name = "Capture Source",
  530. .info = conexant_mux_enum_info,
  531. .get = conexant_mux_enum_get,
  532. .put = conexant_mux_enum_put
  533. },
  534. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  535. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  536. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  537. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  538. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  539. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  540. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  541. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  542. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  543. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  544. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  545. {
  546. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  547. .name = "Master Playback Switch",
  548. .info = cxt_eapd_info,
  549. .get = cxt_eapd_get,
  550. .put = cxt5045_hp_master_sw_put,
  551. .private_value = 0x10,
  552. },
  553. {}
  554. };
  555. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  556. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  557. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  558. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  559. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  560. {}
  561. };
  562. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  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 Capture Volume", 0x1a, 0x02, HDA_INPUT),
  571. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  572. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  573. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  574. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  575. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  576. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  577. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  578. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  579. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  580. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  581. {
  582. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  583. .name = "Master Playback Switch",
  584. .info = cxt_eapd_info,
  585. .get = cxt_eapd_get,
  586. .put = cxt5045_hp_master_sw_put,
  587. .private_value = 0x10,
  588. },
  589. {}
  590. };
  591. static struct hda_verb cxt5045_init_verbs[] = {
  592. /* Line in, Mic */
  593. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  594. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  595. /* HP, Amp */
  596. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  597. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  598. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  599. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  600. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  601. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  602. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  603. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  604. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  605. /* Record selector: Int mic */
  606. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  607. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  608. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  609. /* SPDIF route: PCM */
  610. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  611. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  612. /* EAPD */
  613. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  614. { } /* end */
  615. };
  616. static struct hda_verb cxt5045_benq_init_verbs[] = {
  617. /* Int Mic, Mic */
  618. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  619. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  620. /* Line In,HP, Amp */
  621. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  622. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  623. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  624. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  625. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  626. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  627. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  628. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  629. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  630. /* Record selector: Int mic */
  631. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  632. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  633. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  634. /* SPDIF route: PCM */
  635. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  636. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  637. /* EAPD */
  638. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  639. { } /* end */
  640. };
  641. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  642. /* pin sensing on HP jack */
  643. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  644. { } /* end */
  645. };
  646. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  647. /* pin sensing on HP jack */
  648. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  649. { } /* end */
  650. };
  651. #ifdef CONFIG_SND_DEBUG
  652. /* Test configuration for debugging, modelled after the ALC260 test
  653. * configuration.
  654. */
  655. static struct hda_input_mux cxt5045_test_capture_source = {
  656. .num_items = 5,
  657. .items = {
  658. { "MIXER", 0x0 },
  659. { "MIC1 pin", 0x1 },
  660. { "LINE1 pin", 0x2 },
  661. { "HP-OUT pin", 0x3 },
  662. { "CD pin", 0x4 },
  663. },
  664. };
  665. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  666. /* Output controls */
  667. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  668. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  669. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  670. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  671. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  672. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  673. /* Modes for retasking pin widgets */
  674. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  675. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  676. /* EAPD Switch Control */
  677. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  678. /* Loopback mixer controls */
  679. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  680. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  681. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  682. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  683. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  684. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  685. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  686. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  687. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  688. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  689. {
  690. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  691. .name = "Input Source",
  692. .info = conexant_mux_enum_info,
  693. .get = conexant_mux_enum_get,
  694. .put = conexant_mux_enum_put,
  695. },
  696. /* Audio input controls */
  697. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  698. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  699. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  700. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  701. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  702. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  703. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  704. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  706. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  707. { } /* end */
  708. };
  709. static struct hda_verb cxt5045_test_init_verbs[] = {
  710. /* Set connections */
  711. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  712. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  713. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  714. /* Enable retasking pins as output, initially without power amp */
  715. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  716. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  717. /* Disable digital (SPDIF) pins initially, but users can enable
  718. * them via a mixer switch. In the case of SPDIF-out, this initverb
  719. * payload also sets the generation to 0, output to be in "consumer"
  720. * PCM format, copyright asserted, no pre-emphasis and no validity
  721. * control.
  722. */
  723. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  724. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  725. /* Start with output sum widgets muted and their output gains at min */
  726. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  727. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  728. /* Unmute retasking pin widget output buffers since the default
  729. * state appears to be output. As the pin mode is changed by the
  730. * user the pin mode control will take care of enabling the pin's
  731. * input/output buffers as needed.
  732. */
  733. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  734. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  735. /* Mute capture amp left and right */
  736. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  737. /* Set ADC connection select to match default mixer setting (mic1
  738. * pin)
  739. */
  740. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  741. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  742. /* Mute all inputs to mixer widget (even unconnected ones) */
  743. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  744. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  745. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  746. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  747. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  748. { }
  749. };
  750. #endif
  751. /* initialize jack-sensing, too */
  752. static int cxt5045_init(struct hda_codec *codec)
  753. {
  754. conexant_init(codec);
  755. cxt5045_hp_automute(codec);
  756. return 0;
  757. }
  758. enum {
  759. CXT5045_LAPTOP_HPSENSE,
  760. CXT5045_LAPTOP_MICSENSE,
  761. CXT5045_LAPTOP_HPMICSENSE,
  762. CXT5045_BENQ,
  763. CXT5045_LAPTOP_HP530,
  764. #ifdef CONFIG_SND_DEBUG
  765. CXT5045_TEST,
  766. #endif
  767. CXT5045_MODELS
  768. };
  769. static const char *cxt5045_models[CXT5045_MODELS] = {
  770. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  771. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  772. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  773. [CXT5045_BENQ] = "benq",
  774. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  775. #ifdef CONFIG_SND_DEBUG
  776. [CXT5045_TEST] = "test",
  777. #endif
  778. };
  779. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  780. SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
  781. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  782. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
  783. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
  784. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
  785. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  786. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
  787. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  788. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
  789. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  790. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  791. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  792. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
  793. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  794. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  795. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  796. SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  797. SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  798. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  799. {}
  800. };
  801. static int patch_cxt5045(struct hda_codec *codec)
  802. {
  803. struct conexant_spec *spec;
  804. int board_config;
  805. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  806. if (!spec)
  807. return -ENOMEM;
  808. codec->spec = spec;
  809. spec->multiout.max_channels = 2;
  810. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  811. spec->multiout.dac_nids = cxt5045_dac_nids;
  812. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  813. spec->num_adc_nids = 1;
  814. spec->adc_nids = cxt5045_adc_nids;
  815. spec->capsrc_nids = cxt5045_capsrc_nids;
  816. spec->input_mux = &cxt5045_capture_source;
  817. spec->num_mixers = 1;
  818. spec->mixers[0] = cxt5045_mixers;
  819. spec->num_init_verbs = 1;
  820. spec->init_verbs[0] = cxt5045_init_verbs;
  821. spec->spdif_route = 0;
  822. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  823. spec->channel_mode = cxt5045_modes,
  824. codec->patch_ops = conexant_patch_ops;
  825. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  826. cxt5045_models,
  827. cxt5045_cfg_tbl);
  828. switch (board_config) {
  829. case CXT5045_LAPTOP_HPSENSE:
  830. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  831. spec->input_mux = &cxt5045_capture_source;
  832. spec->num_init_verbs = 2;
  833. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  834. spec->mixers[0] = cxt5045_mixers;
  835. codec->patch_ops.init = cxt5045_init;
  836. break;
  837. case CXT5045_LAPTOP_MICSENSE:
  838. spec->input_mux = &cxt5045_capture_source;
  839. spec->num_init_verbs = 2;
  840. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  841. spec->mixers[0] = cxt5045_mixers;
  842. codec->patch_ops.init = cxt5045_init;
  843. break;
  844. default:
  845. case CXT5045_LAPTOP_HPMICSENSE:
  846. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  847. spec->input_mux = &cxt5045_capture_source;
  848. spec->num_init_verbs = 3;
  849. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  850. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  851. spec->mixers[0] = cxt5045_mixers;
  852. codec->patch_ops.init = cxt5045_init;
  853. break;
  854. case CXT5045_BENQ:
  855. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  856. spec->input_mux = &cxt5045_capture_source_benq;
  857. spec->num_init_verbs = 1;
  858. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  859. spec->mixers[0] = cxt5045_mixers;
  860. spec->mixers[1] = cxt5045_benq_mixers;
  861. spec->num_mixers = 2;
  862. codec->patch_ops.init = cxt5045_init;
  863. break;
  864. case CXT5045_LAPTOP_HP530:
  865. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  866. spec->input_mux = &cxt5045_capture_source_hp530;
  867. spec->num_init_verbs = 2;
  868. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  869. spec->mixers[0] = cxt5045_mixers_hp530;
  870. codec->patch_ops.init = cxt5045_init;
  871. break;
  872. #ifdef CONFIG_SND_DEBUG
  873. case CXT5045_TEST:
  874. spec->input_mux = &cxt5045_test_capture_source;
  875. spec->mixers[0] = cxt5045_test_mixer;
  876. spec->init_verbs[0] = cxt5045_test_init_verbs;
  877. break;
  878. #endif
  879. }
  880. /*
  881. * Fix max PCM level to 0 dB
  882. * (originall it has 0x2b steps with 0dB offset 0x14)
  883. */
  884. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  885. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  886. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  887. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  888. (1 << AC_AMPCAP_MUTE_SHIFT));
  889. return 0;
  890. }
  891. /* Conexant 5047 specific */
  892. #define CXT5047_SPDIF_OUT 0x11
  893. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  894. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  895. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  896. static struct hda_channel_mode cxt5047_modes[1] = {
  897. { 2, NULL },
  898. };
  899. static struct hda_input_mux cxt5047_capture_source = {
  900. .num_items = 1,
  901. .items = {
  902. { "Mic", 0x2 },
  903. }
  904. };
  905. static struct hda_input_mux cxt5047_hp_capture_source = {
  906. .num_items = 1,
  907. .items = {
  908. { "ExtMic", 0x2 },
  909. }
  910. };
  911. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  912. .num_items = 2,
  913. .items = {
  914. { "ExtMic", 0x2 },
  915. { "Line-In", 0x1 },
  916. }
  917. };
  918. /* turn on/off EAPD (+ mute HP) as a master switch */
  919. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  920. struct snd_ctl_elem_value *ucontrol)
  921. {
  922. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  923. struct conexant_spec *spec = codec->spec;
  924. unsigned int bits;
  925. if (!cxt_eapd_put(kcontrol, ucontrol))
  926. return 0;
  927. /* toggle internal speakers mute depending of presence of
  928. * the headphone jack
  929. */
  930. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  931. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  932. HDA_AMP_MUTE, bits);
  933. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  934. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  935. HDA_AMP_MUTE, bits);
  936. return 1;
  937. }
  938. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  939. static struct hda_bind_ctls cxt5047_bind_master_vol = {
  940. .ops = &snd_hda_bind_vol,
  941. .values = {
  942. HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  943. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  944. 0
  945. },
  946. };
  947. /* mute internal speaker if HP is plugged */
  948. static void cxt5047_hp_automute(struct hda_codec *codec)
  949. {
  950. struct conexant_spec *spec = codec->spec;
  951. unsigned int bits;
  952. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  953. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  954. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  955. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  956. HDA_AMP_MUTE, bits);
  957. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  958. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  959. HDA_AMP_MUTE, bits);
  960. }
  961. /* mute internal speaker if HP is plugged */
  962. static void cxt5047_hp2_automute(struct hda_codec *codec)
  963. {
  964. struct conexant_spec *spec = codec->spec;
  965. unsigned int bits;
  966. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  967. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  968. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  969. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  970. HDA_AMP_MUTE, bits);
  971. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  972. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  973. HDA_AMP_MUTE, bits);
  974. }
  975. /* toggle input of built-in and mic jack appropriately */
  976. static void cxt5047_hp_automic(struct hda_codec *codec)
  977. {
  978. static struct hda_verb mic_jack_on[] = {
  979. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  980. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  981. {}
  982. };
  983. static struct hda_verb mic_jack_off[] = {
  984. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  985. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  986. {}
  987. };
  988. unsigned int present;
  989. present = snd_hda_codec_read(codec, 0x15, 0,
  990. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  991. if (present)
  992. snd_hda_sequence_write(codec, mic_jack_on);
  993. else
  994. snd_hda_sequence_write(codec, mic_jack_off);
  995. }
  996. /* unsolicited event for HP jack sensing */
  997. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  998. unsigned int res)
  999. {
  1000. switch (res >> 26) {
  1001. case CONEXANT_HP_EVENT:
  1002. cxt5047_hp_automute(codec);
  1003. break;
  1004. case CONEXANT_MIC_EVENT:
  1005. cxt5047_hp_automic(codec);
  1006. break;
  1007. }
  1008. }
  1009. /* unsolicited event for HP jack sensing - non-EAPD systems */
  1010. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  1011. unsigned int res)
  1012. {
  1013. res >>= 26;
  1014. switch (res) {
  1015. case CONEXANT_HP_EVENT:
  1016. cxt5047_hp2_automute(codec);
  1017. break;
  1018. case CONEXANT_MIC_EVENT:
  1019. cxt5047_hp_automic(codec);
  1020. break;
  1021. }
  1022. }
  1023. static struct snd_kcontrol_new cxt5047_mixers[] = {
  1024. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1025. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1026. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  1027. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  1028. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1029. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1030. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1031. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1032. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  1033. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  1034. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  1035. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  1036. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1037. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  1038. {}
  1039. };
  1040. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  1041. {
  1042. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1043. .name = "Capture Source",
  1044. .info = conexant_mux_enum_info,
  1045. .get = conexant_mux_enum_get,
  1046. .put = conexant_mux_enum_put
  1047. },
  1048. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1049. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1050. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1051. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1052. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1053. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1054. HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
  1055. {
  1056. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1057. .name = "Master Playback Switch",
  1058. .info = cxt_eapd_info,
  1059. .get = cxt_eapd_get,
  1060. .put = cxt5047_hp_master_sw_put,
  1061. .private_value = 0x13,
  1062. },
  1063. {}
  1064. };
  1065. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  1066. {
  1067. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1068. .name = "Capture Source",
  1069. .info = conexant_mux_enum_info,
  1070. .get = conexant_mux_enum_get,
  1071. .put = conexant_mux_enum_put
  1072. },
  1073. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1074. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  1075. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1076. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1077. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1078. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1079. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1080. {
  1081. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1082. .name = "Master Playback Switch",
  1083. .info = cxt_eapd_info,
  1084. .get = cxt_eapd_get,
  1085. .put = cxt5047_hp_master_sw_put,
  1086. .private_value = 0x13,
  1087. },
  1088. { } /* end */
  1089. };
  1090. static struct hda_verb cxt5047_init_verbs[] = {
  1091. /* Line in, Mic, Built-in Mic */
  1092. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1093. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1094. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1095. /* HP, Speaker */
  1096. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1097. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  1098. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  1099. /* Record selector: Mic */
  1100. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1101. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1102. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1103. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1104. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1105. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1106. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1107. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1108. /* SPDIF route: PCM */
  1109. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1110. /* Enable unsolicited events */
  1111. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1112. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1113. { } /* end */
  1114. };
  1115. /* configuration for Toshiba Laptops */
  1116. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1117. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  1118. /* pin sensing on HP and Mic jacks */
  1119. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1120. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1121. /* Speaker routing */
  1122. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1123. {}
  1124. };
  1125. /* configuration for HP Laptops */
  1126. static struct hda_verb cxt5047_hp_init_verbs[] = {
  1127. /* pin sensing on HP jack */
  1128. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1129. /* 0x13 is actually shared by both HP and speaker;
  1130. * setting the connection to 0 (=0x19) makes the master volume control
  1131. * working mysteriouslly...
  1132. */
  1133. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  1134. /* Record selector: Ext Mic */
  1135. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1136. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1137. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1138. /* Speaker routing */
  1139. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1140. {}
  1141. };
  1142. /* Test configuration for debugging, modelled after the ALC260 test
  1143. * configuration.
  1144. */
  1145. #ifdef CONFIG_SND_DEBUG
  1146. static struct hda_input_mux cxt5047_test_capture_source = {
  1147. .num_items = 4,
  1148. .items = {
  1149. { "LINE1 pin", 0x0 },
  1150. { "MIC1 pin", 0x1 },
  1151. { "MIC2 pin", 0x2 },
  1152. { "CD pin", 0x3 },
  1153. },
  1154. };
  1155. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1156. /* Output only controls */
  1157. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1158. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1159. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1160. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1161. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1162. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1163. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1164. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1165. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1166. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1167. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1168. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1169. /* Modes for retasking pin widgets */
  1170. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1171. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1172. /* EAPD Switch Control */
  1173. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1174. /* Loopback mixer controls */
  1175. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1176. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1177. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1178. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1179. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1180. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1181. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1182. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1183. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1184. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1185. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1186. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1187. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1188. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1189. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1190. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1191. {
  1192. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1193. .name = "Input Source",
  1194. .info = conexant_mux_enum_info,
  1195. .get = conexant_mux_enum_get,
  1196. .put = conexant_mux_enum_put,
  1197. },
  1198. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  1199. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  1200. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  1201. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  1202. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  1203. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  1204. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  1205. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  1206. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  1207. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  1208. { } /* end */
  1209. };
  1210. static struct hda_verb cxt5047_test_init_verbs[] = {
  1211. /* Enable retasking pins as output, initially without power amp */
  1212. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1213. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1214. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1215. /* Disable digital (SPDIF) pins initially, but users can enable
  1216. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1217. * payload also sets the generation to 0, output to be in "consumer"
  1218. * PCM format, copyright asserted, no pre-emphasis and no validity
  1219. * control.
  1220. */
  1221. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1222. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1223. * OUT1 sum bus when acting as an output.
  1224. */
  1225. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1226. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1227. /* Start with output sum widgets muted and their output gains at min */
  1228. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1229. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1230. /* Unmute retasking pin widget output buffers since the default
  1231. * state appears to be output. As the pin mode is changed by the
  1232. * user the pin mode control will take care of enabling the pin's
  1233. * input/output buffers as needed.
  1234. */
  1235. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1236. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1237. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1238. /* Mute capture amp left and right */
  1239. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1240. /* Set ADC connection select to match default mixer setting (mic1
  1241. * pin)
  1242. */
  1243. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1244. /* Mute all inputs to mixer widget (even unconnected ones) */
  1245. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1246. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1247. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1248. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1249. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1250. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1251. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1252. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1253. { }
  1254. };
  1255. #endif
  1256. /* initialize jack-sensing, too */
  1257. static int cxt5047_hp_init(struct hda_codec *codec)
  1258. {
  1259. conexant_init(codec);
  1260. cxt5047_hp_automute(codec);
  1261. return 0;
  1262. }
  1263. enum {
  1264. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1265. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1266. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1267. #ifdef CONFIG_SND_DEBUG
  1268. CXT5047_TEST,
  1269. #endif
  1270. CXT5047_MODELS
  1271. };
  1272. static const char *cxt5047_models[CXT5047_MODELS] = {
  1273. [CXT5047_LAPTOP] = "laptop",
  1274. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1275. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1276. #ifdef CONFIG_SND_DEBUG
  1277. [CXT5047_TEST] = "test",
  1278. #endif
  1279. };
  1280. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1281. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1282. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1283. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1284. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1285. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1286. {}
  1287. };
  1288. static int patch_cxt5047(struct hda_codec *codec)
  1289. {
  1290. struct conexant_spec *spec;
  1291. int board_config;
  1292. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1293. if (!spec)
  1294. return -ENOMEM;
  1295. codec->spec = spec;
  1296. spec->multiout.max_channels = 2;
  1297. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1298. spec->multiout.dac_nids = cxt5047_dac_nids;
  1299. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1300. spec->num_adc_nids = 1;
  1301. spec->adc_nids = cxt5047_adc_nids;
  1302. spec->capsrc_nids = cxt5047_capsrc_nids;
  1303. spec->input_mux = &cxt5047_capture_source;
  1304. spec->num_mixers = 1;
  1305. spec->mixers[0] = cxt5047_mixers;
  1306. spec->num_init_verbs = 1;
  1307. spec->init_verbs[0] = cxt5047_init_verbs;
  1308. spec->spdif_route = 0;
  1309. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1310. spec->channel_mode = cxt5047_modes,
  1311. codec->patch_ops = conexant_patch_ops;
  1312. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1313. cxt5047_models,
  1314. cxt5047_cfg_tbl);
  1315. switch (board_config) {
  1316. case CXT5047_LAPTOP:
  1317. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1318. break;
  1319. case CXT5047_LAPTOP_HP:
  1320. spec->input_mux = &cxt5047_hp_capture_source;
  1321. spec->num_init_verbs = 2;
  1322. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1323. spec->mixers[0] = cxt5047_hp_mixers;
  1324. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1325. codec->patch_ops.init = cxt5047_hp_init;
  1326. break;
  1327. case CXT5047_LAPTOP_EAPD:
  1328. spec->input_mux = &cxt5047_toshiba_capture_source;
  1329. spec->num_init_verbs = 2;
  1330. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1331. spec->mixers[0] = cxt5047_toshiba_mixers;
  1332. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1333. break;
  1334. #ifdef CONFIG_SND_DEBUG
  1335. case CXT5047_TEST:
  1336. spec->input_mux = &cxt5047_test_capture_source;
  1337. spec->mixers[0] = cxt5047_test_mixer;
  1338. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1339. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1340. #endif
  1341. }
  1342. return 0;
  1343. }
  1344. /* Conexant 5051 specific */
  1345. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1346. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1347. #define CXT5051_SPDIF_OUT 0x1C
  1348. #define CXT5051_PORTB_EVENT 0x38
  1349. #define CXT5051_PORTC_EVENT 0x39
  1350. static struct hda_channel_mode cxt5051_modes[1] = {
  1351. { 2, NULL },
  1352. };
  1353. static void cxt5051_update_speaker(struct hda_codec *codec)
  1354. {
  1355. struct conexant_spec *spec = codec->spec;
  1356. unsigned int pinctl;
  1357. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1358. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1359. pinctl);
  1360. }
  1361. /* turn on/off EAPD (+ mute HP) as a master switch */
  1362. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1363. struct snd_ctl_elem_value *ucontrol)
  1364. {
  1365. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1366. if (!cxt_eapd_put(kcontrol, ucontrol))
  1367. return 0;
  1368. cxt5051_update_speaker(codec);
  1369. return 1;
  1370. }
  1371. /* toggle input of built-in and mic jack appropriately */
  1372. static void cxt5051_portb_automic(struct hda_codec *codec)
  1373. {
  1374. unsigned int present;
  1375. present = snd_hda_codec_read(codec, 0x17, 0,
  1376. AC_VERB_GET_PIN_SENSE, 0) &
  1377. AC_PINSENSE_PRESENCE;
  1378. snd_hda_codec_write(codec, 0x14, 0,
  1379. AC_VERB_SET_CONNECT_SEL,
  1380. present ? 0x01 : 0x00);
  1381. }
  1382. /* switch the current ADC according to the jack state */
  1383. static void cxt5051_portc_automic(struct hda_codec *codec)
  1384. {
  1385. struct conexant_spec *spec = codec->spec;
  1386. unsigned int present;
  1387. hda_nid_t new_adc;
  1388. present = snd_hda_codec_read(codec, 0x18, 0,
  1389. AC_VERB_GET_PIN_SENSE, 0) &
  1390. AC_PINSENSE_PRESENCE;
  1391. if (present)
  1392. spec->cur_adc_idx = 1;
  1393. else
  1394. spec->cur_adc_idx = 0;
  1395. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1396. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1397. /* stream is running, let's swap the current ADC */
  1398. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1399. spec->cur_adc = new_adc;
  1400. snd_hda_codec_setup_stream(codec, new_adc,
  1401. spec->cur_adc_stream_tag, 0,
  1402. spec->cur_adc_format);
  1403. }
  1404. }
  1405. /* mute internal speaker if HP is plugged */
  1406. static void cxt5051_hp_automute(struct hda_codec *codec)
  1407. {
  1408. struct conexant_spec *spec = codec->spec;
  1409. spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
  1410. AC_VERB_GET_PIN_SENSE, 0) &
  1411. AC_PINSENSE_PRESENCE;
  1412. cxt5051_update_speaker(codec);
  1413. }
  1414. /* unsolicited event for HP jack sensing */
  1415. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1416. unsigned int res)
  1417. {
  1418. switch (res >> 26) {
  1419. case CONEXANT_HP_EVENT:
  1420. cxt5051_hp_automute(codec);
  1421. break;
  1422. case CXT5051_PORTB_EVENT:
  1423. cxt5051_portb_automic(codec);
  1424. break;
  1425. case CXT5051_PORTC_EVENT:
  1426. cxt5051_portc_automic(codec);
  1427. break;
  1428. }
  1429. }
  1430. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1431. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1432. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1433. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1434. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1435. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1436. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1437. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1438. {
  1439. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1440. .name = "Master Playback Switch",
  1441. .info = cxt_eapd_info,
  1442. .get = cxt_eapd_get,
  1443. .put = cxt5051_hp_master_sw_put,
  1444. .private_value = 0x1a,
  1445. },
  1446. {}
  1447. };
  1448. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1449. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1450. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1451. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1452. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1453. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1454. {
  1455. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1456. .name = "Master Playback Switch",
  1457. .info = cxt_eapd_info,
  1458. .get = cxt_eapd_get,
  1459. .put = cxt5051_hp_master_sw_put,
  1460. .private_value = 0x1a,
  1461. },
  1462. {}
  1463. };
  1464. static struct hda_verb cxt5051_init_verbs[] = {
  1465. /* Line in, Mic */
  1466. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1467. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1468. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1469. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1470. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1471. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1472. /* SPK */
  1473. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1474. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1475. /* HP, Amp */
  1476. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1477. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1478. /* DAC1 */
  1479. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1480. /* Record selector: Int mic */
  1481. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1482. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1483. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1484. /* SPDIF route: PCM */
  1485. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1486. /* EAPD */
  1487. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1488. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1489. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1490. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1491. { } /* end */
  1492. };
  1493. /* initialize jack-sensing, too */
  1494. static int cxt5051_init(struct hda_codec *codec)
  1495. {
  1496. conexant_init(codec);
  1497. if (codec->patch_ops.unsol_event) {
  1498. cxt5051_hp_automute(codec);
  1499. cxt5051_portb_automic(codec);
  1500. cxt5051_portc_automic(codec);
  1501. }
  1502. return 0;
  1503. }
  1504. enum {
  1505. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1506. CXT5051_HP, /* no docking */
  1507. CXT5051_MODELS
  1508. };
  1509. static const char *cxt5051_models[CXT5051_MODELS] = {
  1510. [CXT5051_LAPTOP] = "laptop",
  1511. [CXT5051_HP] = "hp",
  1512. };
  1513. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1514. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1515. CXT5051_LAPTOP),
  1516. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1517. {}
  1518. };
  1519. static int patch_cxt5051(struct hda_codec *codec)
  1520. {
  1521. struct conexant_spec *spec;
  1522. int board_config;
  1523. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1524. if (!spec)
  1525. return -ENOMEM;
  1526. codec->spec = spec;
  1527. codec->patch_ops = conexant_patch_ops;
  1528. codec->patch_ops.init = cxt5051_init;
  1529. spec->multiout.max_channels = 2;
  1530. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1531. spec->multiout.dac_nids = cxt5051_dac_nids;
  1532. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1533. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1534. spec->adc_nids = cxt5051_adc_nids;
  1535. spec->num_mixers = 1;
  1536. spec->mixers[0] = cxt5051_mixers;
  1537. spec->num_init_verbs = 1;
  1538. spec->init_verbs[0] = cxt5051_init_verbs;
  1539. spec->spdif_route = 0;
  1540. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1541. spec->channel_mode = cxt5051_modes;
  1542. spec->cur_adc = 0;
  1543. spec->cur_adc_idx = 0;
  1544. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1545. cxt5051_models,
  1546. cxt5051_cfg_tbl);
  1547. switch (board_config) {
  1548. case CXT5051_HP:
  1549. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1550. spec->mixers[0] = cxt5051_hp_mixers;
  1551. break;
  1552. default:
  1553. case CXT5051_LAPTOP:
  1554. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1555. break;
  1556. }
  1557. return 0;
  1558. }
  1559. /*
  1560. */
  1561. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1562. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1563. .patch = patch_cxt5045 },
  1564. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1565. .patch = patch_cxt5047 },
  1566. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  1567. .patch = patch_cxt5051 },
  1568. {} /* terminator */
  1569. };