patch_conexant.c 53 KB

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