patch_conexant.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  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 0x13
  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_CONNECT_SEL, 0x0 },
  569. /* EAPD */
  570. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  571. { } /* end */
  572. };
  573. static struct hda_verb cxt5045_benq_init_verbs[] = {
  574. /* Int Mic, Mic */
  575. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  576. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  577. /* Line In,HP, Amp */
  578. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  579. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  580. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  581. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  582. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  583. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  584. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  585. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  586. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  587. /* Record selector: Int mic */
  588. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  589. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  590. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  591. /* SPDIF route: PCM */
  592. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  593. /* EAPD */
  594. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  595. { } /* end */
  596. };
  597. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  598. /* pin sensing on HP jack */
  599. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  600. { } /* end */
  601. };
  602. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  603. /* pin sensing on HP jack */
  604. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  605. { } /* end */
  606. };
  607. #ifdef CONFIG_SND_DEBUG
  608. /* Test configuration for debugging, modelled after the ALC260 test
  609. * configuration.
  610. */
  611. static struct hda_input_mux cxt5045_test_capture_source = {
  612. .num_items = 5,
  613. .items = {
  614. { "MIXER", 0x0 },
  615. { "MIC1 pin", 0x1 },
  616. { "LINE1 pin", 0x2 },
  617. { "HP-OUT pin", 0x3 },
  618. { "CD pin", 0x4 },
  619. },
  620. };
  621. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  622. /* Output controls */
  623. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  624. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  625. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  626. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  627. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  628. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  629. /* Modes for retasking pin widgets */
  630. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  631. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  632. /* EAPD Switch Control */
  633. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  634. /* Loopback mixer controls */
  635. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  636. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  637. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  638. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  639. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  640. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  641. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  642. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  643. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  644. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  645. {
  646. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  647. .name = "Input Source",
  648. .info = conexant_mux_enum_info,
  649. .get = conexant_mux_enum_get,
  650. .put = conexant_mux_enum_put,
  651. },
  652. /* Audio input controls */
  653. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  654. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  655. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  656. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  657. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  658. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  659. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  660. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  661. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  662. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  663. { } /* end */
  664. };
  665. static struct hda_verb cxt5045_test_init_verbs[] = {
  666. /* Set connections */
  667. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  668. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  669. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  670. /* Enable retasking pins as output, initially without power amp */
  671. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  672. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  673. /* Disable digital (SPDIF) pins initially, but users can enable
  674. * them via a mixer switch. In the case of SPDIF-out, this initverb
  675. * payload also sets the generation to 0, output to be in "consumer"
  676. * PCM format, copyright asserted, no pre-emphasis and no validity
  677. * control.
  678. */
  679. {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
  680. /* Start with output sum widgets muted and their output gains at min */
  681. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  682. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  683. /* Unmute retasking pin widget output buffers since the default
  684. * state appears to be output. As the pin mode is changed by the
  685. * user the pin mode control will take care of enabling the pin's
  686. * input/output buffers as needed.
  687. */
  688. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  689. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  690. /* Mute capture amp left and right */
  691. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  692. /* Set ADC connection select to match default mixer setting (mic1
  693. * pin)
  694. */
  695. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  696. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  697. /* Mute all inputs to mixer widget (even unconnected ones) */
  698. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  699. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  700. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  701. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  702. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  703. { }
  704. };
  705. #endif
  706. /* initialize jack-sensing, too */
  707. static int cxt5045_init(struct hda_codec *codec)
  708. {
  709. conexant_init(codec);
  710. cxt5045_hp_automute(codec);
  711. return 0;
  712. }
  713. enum {
  714. CXT5045_LAPTOP_HPSENSE,
  715. CXT5045_LAPTOP_MICSENSE,
  716. CXT5045_LAPTOP_HPMICSENSE,
  717. CXT5045_BENQ,
  718. #ifdef CONFIG_SND_DEBUG
  719. CXT5045_TEST,
  720. #endif
  721. CXT5045_MODELS
  722. };
  723. static const char *cxt5045_models[CXT5045_MODELS] = {
  724. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  725. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  726. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  727. [CXT5045_BENQ] = "benq",
  728. #ifdef CONFIG_SND_DEBUG
  729. [CXT5045_TEST] = "test",
  730. #endif
  731. };
  732. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  733. SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
  734. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  735. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
  736. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
  737. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
  738. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  739. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
  740. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
  741. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
  742. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  743. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  744. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  745. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
  746. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  747. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  748. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  749. SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  750. SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  751. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  752. {}
  753. };
  754. static int patch_cxt5045(struct hda_codec *codec)
  755. {
  756. struct conexant_spec *spec;
  757. int board_config;
  758. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  759. if (!spec)
  760. return -ENOMEM;
  761. mutex_init(&spec->amp_mutex);
  762. codec->spec = spec;
  763. spec->multiout.max_channels = 2;
  764. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  765. spec->multiout.dac_nids = cxt5045_dac_nids;
  766. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  767. spec->num_adc_nids = 1;
  768. spec->adc_nids = cxt5045_adc_nids;
  769. spec->capsrc_nids = cxt5045_capsrc_nids;
  770. spec->input_mux = &cxt5045_capture_source;
  771. spec->num_mixers = 1;
  772. spec->mixers[0] = cxt5045_mixers;
  773. spec->num_init_verbs = 1;
  774. spec->init_verbs[0] = cxt5045_init_verbs;
  775. spec->spdif_route = 0;
  776. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  777. spec->channel_mode = cxt5045_modes,
  778. codec->patch_ops = conexant_patch_ops;
  779. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  780. cxt5045_models,
  781. cxt5045_cfg_tbl);
  782. switch (board_config) {
  783. case CXT5045_LAPTOP_HPSENSE:
  784. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  785. spec->input_mux = &cxt5045_capture_source;
  786. spec->num_init_verbs = 2;
  787. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  788. spec->mixers[0] = cxt5045_mixers;
  789. codec->patch_ops.init = cxt5045_init;
  790. break;
  791. case CXT5045_LAPTOP_MICSENSE:
  792. spec->input_mux = &cxt5045_capture_source;
  793. spec->num_init_verbs = 2;
  794. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  795. spec->mixers[0] = cxt5045_mixers;
  796. codec->patch_ops.init = cxt5045_init;
  797. break;
  798. default:
  799. case CXT5045_LAPTOP_HPMICSENSE:
  800. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  801. spec->input_mux = &cxt5045_capture_source;
  802. spec->num_init_verbs = 3;
  803. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  804. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  805. spec->mixers[0] = cxt5045_mixers;
  806. codec->patch_ops.init = cxt5045_init;
  807. break;
  808. case CXT5045_BENQ:
  809. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  810. spec->input_mux = &cxt5045_capture_source_benq;
  811. spec->num_init_verbs = 1;
  812. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  813. spec->mixers[0] = cxt5045_mixers;
  814. spec->mixers[1] = cxt5045_benq_mixers;
  815. spec->num_mixers = 2;
  816. codec->patch_ops.init = cxt5045_init;
  817. break;
  818. #ifdef CONFIG_SND_DEBUG
  819. case CXT5045_TEST:
  820. spec->input_mux = &cxt5045_test_capture_source;
  821. spec->mixers[0] = cxt5045_test_mixer;
  822. spec->init_verbs[0] = cxt5045_test_init_verbs;
  823. break;
  824. #endif
  825. }
  826. /*
  827. * Fix max PCM level to 0 dB
  828. * (originall it has 0x2b steps with 0dB offset 0x14)
  829. */
  830. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  831. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  832. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  833. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  834. (1 << AC_AMPCAP_MUTE_SHIFT));
  835. return 0;
  836. }
  837. /* Conexant 5047 specific */
  838. #define CXT5047_SPDIF_OUT 0x11
  839. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  840. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  841. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  842. static struct hda_channel_mode cxt5047_modes[1] = {
  843. { 2, NULL },
  844. };
  845. static struct hda_input_mux cxt5047_capture_source = {
  846. .num_items = 1,
  847. .items = {
  848. { "Mic", 0x2 },
  849. }
  850. };
  851. static struct hda_input_mux cxt5047_hp_capture_source = {
  852. .num_items = 1,
  853. .items = {
  854. { "ExtMic", 0x2 },
  855. }
  856. };
  857. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  858. .num_items = 2,
  859. .items = {
  860. { "ExtMic", 0x2 },
  861. { "Line-In", 0x1 },
  862. }
  863. };
  864. /* turn on/off EAPD (+ mute HP) as a master switch */
  865. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  866. struct snd_ctl_elem_value *ucontrol)
  867. {
  868. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  869. struct conexant_spec *spec = codec->spec;
  870. unsigned int bits;
  871. if (!cxt_eapd_put(kcontrol, ucontrol))
  872. return 0;
  873. /* toggle internal speakers mute depending of presence of
  874. * the headphone jack
  875. */
  876. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  877. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  878. HDA_AMP_MUTE, bits);
  879. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  880. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  881. HDA_AMP_MUTE, bits);
  882. return 1;
  883. }
  884. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  885. static struct hda_bind_ctls cxt5047_bind_master_vol = {
  886. .ops = &snd_hda_bind_vol,
  887. .values = {
  888. HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  889. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  890. 0
  891. },
  892. };
  893. /* mute internal speaker if HP is plugged */
  894. static void cxt5047_hp_automute(struct hda_codec *codec)
  895. {
  896. struct conexant_spec *spec = codec->spec;
  897. unsigned int bits;
  898. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  899. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  900. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  901. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  902. HDA_AMP_MUTE, bits);
  903. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  904. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  905. HDA_AMP_MUTE, bits);
  906. }
  907. /* mute internal speaker if HP is plugged */
  908. static void cxt5047_hp2_automute(struct hda_codec *codec)
  909. {
  910. struct conexant_spec *spec = codec->spec;
  911. unsigned int bits;
  912. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  913. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  914. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  915. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  916. HDA_AMP_MUTE, bits);
  917. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  918. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  919. HDA_AMP_MUTE, bits);
  920. }
  921. /* toggle input of built-in and mic jack appropriately */
  922. static void cxt5047_hp_automic(struct hda_codec *codec)
  923. {
  924. static struct hda_verb mic_jack_on[] = {
  925. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  926. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  927. {}
  928. };
  929. static struct hda_verb mic_jack_off[] = {
  930. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  931. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  932. {}
  933. };
  934. unsigned int present;
  935. present = snd_hda_codec_read(codec, 0x15, 0,
  936. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  937. if (present)
  938. snd_hda_sequence_write(codec, mic_jack_on);
  939. else
  940. snd_hda_sequence_write(codec, mic_jack_off);
  941. }
  942. /* unsolicited event for HP jack sensing */
  943. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  944. unsigned int res)
  945. {
  946. switch (res >> 26) {
  947. case CONEXANT_HP_EVENT:
  948. cxt5047_hp_automute(codec);
  949. break;
  950. case CONEXANT_MIC_EVENT:
  951. cxt5047_hp_automic(codec);
  952. break;
  953. }
  954. }
  955. /* unsolicited event for HP jack sensing - non-EAPD systems */
  956. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  957. unsigned int res)
  958. {
  959. res >>= 26;
  960. switch (res) {
  961. case CONEXANT_HP_EVENT:
  962. cxt5047_hp2_automute(codec);
  963. break;
  964. case CONEXANT_MIC_EVENT:
  965. cxt5047_hp_automic(codec);
  966. break;
  967. }
  968. }
  969. static struct snd_kcontrol_new cxt5047_mixers[] = {
  970. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  971. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  972. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  973. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  974. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  975. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  976. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  977. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  978. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  979. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  980. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  981. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  982. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  983. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  984. {}
  985. };
  986. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  987. {
  988. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  989. .name = "Capture Source",
  990. .info = conexant_mux_enum_info,
  991. .get = conexant_mux_enum_get,
  992. .put = conexant_mux_enum_put
  993. },
  994. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  995. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  996. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  997. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  998. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  999. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1000. HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
  1001. {
  1002. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1003. .name = "Master Playback Switch",
  1004. .info = cxt_eapd_info,
  1005. .get = cxt_eapd_get,
  1006. .put = cxt5047_hp_master_sw_put,
  1007. .private_value = 0x13,
  1008. },
  1009. {}
  1010. };
  1011. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  1012. {
  1013. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1014. .name = "Capture Source",
  1015. .info = conexant_mux_enum_info,
  1016. .get = conexant_mux_enum_get,
  1017. .put = conexant_mux_enum_put
  1018. },
  1019. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1020. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  1021. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1022. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1023. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1024. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1025. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1026. {
  1027. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1028. .name = "Master Playback Switch",
  1029. .info = cxt_eapd_info,
  1030. .get = cxt_eapd_get,
  1031. .put = cxt5047_hp_master_sw_put,
  1032. .private_value = 0x13,
  1033. },
  1034. { } /* end */
  1035. };
  1036. static struct hda_verb cxt5047_init_verbs[] = {
  1037. /* Line in, Mic, Built-in Mic */
  1038. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1039. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1040. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1041. /* HP, Speaker */
  1042. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1043. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  1044. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  1045. /* Record selector: Mic */
  1046. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1047. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1048. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1049. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1050. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1051. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1052. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1053. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1054. /* SPDIF route: PCM */
  1055. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1056. /* Enable unsolicited events */
  1057. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1058. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1059. { } /* end */
  1060. };
  1061. /* configuration for Toshiba Laptops */
  1062. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1063. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  1064. /* pin sensing on HP and Mic jacks */
  1065. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1066. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1067. /* Speaker routing */
  1068. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1069. {}
  1070. };
  1071. /* configuration for HP Laptops */
  1072. static struct hda_verb cxt5047_hp_init_verbs[] = {
  1073. /* pin sensing on HP jack */
  1074. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1075. /* Record selector: Ext Mic */
  1076. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1077. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1078. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1079. /* Speaker routing */
  1080. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1081. {}
  1082. };
  1083. /* Test configuration for debugging, modelled after the ALC260 test
  1084. * configuration.
  1085. */
  1086. #ifdef CONFIG_SND_DEBUG
  1087. static struct hda_input_mux cxt5047_test_capture_source = {
  1088. .num_items = 4,
  1089. .items = {
  1090. { "LINE1 pin", 0x0 },
  1091. { "MIC1 pin", 0x1 },
  1092. { "MIC2 pin", 0x2 },
  1093. { "CD pin", 0x3 },
  1094. },
  1095. };
  1096. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1097. /* Output only controls */
  1098. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1099. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1100. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1101. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1102. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1103. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1104. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1105. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1106. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1107. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1108. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1109. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1110. /* Modes for retasking pin widgets */
  1111. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1112. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1113. /* EAPD Switch Control */
  1114. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1115. /* Loopback mixer controls */
  1116. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1117. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1118. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1119. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1120. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1121. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1122. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1123. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1124. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1125. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1126. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1127. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1128. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1129. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1130. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1131. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1132. {
  1133. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1134. .name = "Input Source",
  1135. .info = conexant_mux_enum_info,
  1136. .get = conexant_mux_enum_get,
  1137. .put = conexant_mux_enum_put,
  1138. },
  1139. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  1140. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  1141. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  1142. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  1143. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  1144. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  1145. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  1146. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  1147. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  1148. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  1149. { } /* end */
  1150. };
  1151. static struct hda_verb cxt5047_test_init_verbs[] = {
  1152. /* Enable retasking pins as output, initially without power amp */
  1153. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1154. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1155. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1156. /* Disable digital (SPDIF) pins initially, but users can enable
  1157. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1158. * payload also sets the generation to 0, output to be in "consumer"
  1159. * PCM format, copyright asserted, no pre-emphasis and no validity
  1160. * control.
  1161. */
  1162. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1163. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1164. * OUT1 sum bus when acting as an output.
  1165. */
  1166. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1167. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1168. /* Start with output sum widgets muted and their output gains at min */
  1169. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1170. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1171. /* Unmute retasking pin widget output buffers since the default
  1172. * state appears to be output. As the pin mode is changed by the
  1173. * user the pin mode control will take care of enabling the pin's
  1174. * input/output buffers as needed.
  1175. */
  1176. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1177. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1178. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1179. /* Mute capture amp left and right */
  1180. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1181. /* Set ADC connection select to match default mixer setting (mic1
  1182. * pin)
  1183. */
  1184. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1185. /* Mute all inputs to mixer widget (even unconnected ones) */
  1186. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1187. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1188. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1189. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1190. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1191. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1192. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1193. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1194. { }
  1195. };
  1196. #endif
  1197. /* initialize jack-sensing, too */
  1198. static int cxt5047_hp_init(struct hda_codec *codec)
  1199. {
  1200. conexant_init(codec);
  1201. cxt5047_hp_automute(codec);
  1202. return 0;
  1203. }
  1204. enum {
  1205. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1206. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1207. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1208. #ifdef CONFIG_SND_DEBUG
  1209. CXT5047_TEST,
  1210. #endif
  1211. CXT5047_MODELS
  1212. };
  1213. static const char *cxt5047_models[CXT5047_MODELS] = {
  1214. [CXT5047_LAPTOP] = "laptop",
  1215. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1216. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1217. #ifdef CONFIG_SND_DEBUG
  1218. [CXT5047_TEST] = "test",
  1219. #endif
  1220. };
  1221. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1222. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1223. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1224. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1225. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1226. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1227. {}
  1228. };
  1229. static int patch_cxt5047(struct hda_codec *codec)
  1230. {
  1231. struct conexant_spec *spec;
  1232. int board_config;
  1233. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1234. if (!spec)
  1235. return -ENOMEM;
  1236. mutex_init(&spec->amp_mutex);
  1237. codec->spec = spec;
  1238. spec->multiout.max_channels = 2;
  1239. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1240. spec->multiout.dac_nids = cxt5047_dac_nids;
  1241. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1242. spec->num_adc_nids = 1;
  1243. spec->adc_nids = cxt5047_adc_nids;
  1244. spec->capsrc_nids = cxt5047_capsrc_nids;
  1245. spec->input_mux = &cxt5047_capture_source;
  1246. spec->num_mixers = 1;
  1247. spec->mixers[0] = cxt5047_mixers;
  1248. spec->num_init_verbs = 1;
  1249. spec->init_verbs[0] = cxt5047_init_verbs;
  1250. spec->spdif_route = 0;
  1251. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1252. spec->channel_mode = cxt5047_modes,
  1253. codec->patch_ops = conexant_patch_ops;
  1254. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1255. cxt5047_models,
  1256. cxt5047_cfg_tbl);
  1257. switch (board_config) {
  1258. case CXT5047_LAPTOP:
  1259. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1260. break;
  1261. case CXT5047_LAPTOP_HP:
  1262. spec->input_mux = &cxt5047_hp_capture_source;
  1263. spec->num_init_verbs = 2;
  1264. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1265. spec->mixers[0] = cxt5047_hp_mixers;
  1266. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1267. codec->patch_ops.init = cxt5047_hp_init;
  1268. break;
  1269. case CXT5047_LAPTOP_EAPD:
  1270. spec->input_mux = &cxt5047_toshiba_capture_source;
  1271. spec->num_init_verbs = 2;
  1272. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1273. spec->mixers[0] = cxt5047_toshiba_mixers;
  1274. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1275. break;
  1276. #ifdef CONFIG_SND_DEBUG
  1277. case CXT5047_TEST:
  1278. spec->input_mux = &cxt5047_test_capture_source;
  1279. spec->mixers[0] = cxt5047_test_mixer;
  1280. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1281. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1282. #endif
  1283. }
  1284. return 0;
  1285. }
  1286. /* Conexant 5051 specific */
  1287. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1288. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1289. #define CXT5051_SPDIF_OUT 0x1C
  1290. #define CXT5051_PORTB_EVENT 0x38
  1291. #define CXT5051_PORTC_EVENT 0x39
  1292. static struct hda_channel_mode cxt5051_modes[1] = {
  1293. { 2, NULL },
  1294. };
  1295. static void cxt5051_update_speaker(struct hda_codec *codec)
  1296. {
  1297. struct conexant_spec *spec = codec->spec;
  1298. unsigned int pinctl;
  1299. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1300. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1301. pinctl);
  1302. }
  1303. /* turn on/off EAPD (+ mute HP) as a master switch */
  1304. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1305. struct snd_ctl_elem_value *ucontrol)
  1306. {
  1307. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1308. if (!cxt_eapd_put(kcontrol, ucontrol))
  1309. return 0;
  1310. cxt5051_update_speaker(codec);
  1311. return 1;
  1312. }
  1313. /* toggle input of built-in and mic jack appropriately */
  1314. static void cxt5051_portb_automic(struct hda_codec *codec)
  1315. {
  1316. unsigned int present;
  1317. present = snd_hda_codec_read(codec, 0x17, 0,
  1318. AC_VERB_GET_PIN_SENSE, 0) &
  1319. AC_PINSENSE_PRESENCE;
  1320. snd_hda_codec_write(codec, 0x14, 0,
  1321. AC_VERB_SET_CONNECT_SEL,
  1322. present ? 0x01 : 0x00);
  1323. }
  1324. /* switch the current ADC according to the jack state */
  1325. static void cxt5051_portc_automic(struct hda_codec *codec)
  1326. {
  1327. struct conexant_spec *spec = codec->spec;
  1328. unsigned int present;
  1329. hda_nid_t new_adc;
  1330. present = snd_hda_codec_read(codec, 0x18, 0,
  1331. AC_VERB_GET_PIN_SENSE, 0) &
  1332. AC_PINSENSE_PRESENCE;
  1333. if (present)
  1334. spec->cur_adc_idx = 1;
  1335. else
  1336. spec->cur_adc_idx = 0;
  1337. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1338. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1339. /* stream is running, let's swap the current ADC */
  1340. snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
  1341. spec->cur_adc = new_adc;
  1342. snd_hda_codec_setup_stream(codec, new_adc,
  1343. spec->cur_adc_stream_tag, 0,
  1344. spec->cur_adc_format);
  1345. }
  1346. }
  1347. /* mute internal speaker if HP is plugged */
  1348. static void cxt5051_hp_automute(struct hda_codec *codec)
  1349. {
  1350. struct conexant_spec *spec = codec->spec;
  1351. spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
  1352. AC_VERB_GET_PIN_SENSE, 0) &
  1353. AC_PINSENSE_PRESENCE;
  1354. cxt5051_update_speaker(codec);
  1355. }
  1356. /* unsolicited event for HP jack sensing */
  1357. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1358. unsigned int res)
  1359. {
  1360. switch (res >> 26) {
  1361. case CONEXANT_HP_EVENT:
  1362. cxt5051_hp_automute(codec);
  1363. break;
  1364. case CXT5051_PORTB_EVENT:
  1365. cxt5051_portb_automic(codec);
  1366. break;
  1367. case CXT5051_PORTC_EVENT:
  1368. cxt5051_portc_automic(codec);
  1369. break;
  1370. }
  1371. }
  1372. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1373. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1374. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1375. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1376. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1377. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1378. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1379. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1380. {
  1381. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1382. .name = "Master Playback Switch",
  1383. .info = cxt_eapd_info,
  1384. .get = cxt_eapd_get,
  1385. .put = cxt5051_hp_master_sw_put,
  1386. .private_value = 0x1a,
  1387. },
  1388. {}
  1389. };
  1390. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1391. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1392. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1393. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1394. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1395. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1396. {
  1397. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1398. .name = "Master Playback Switch",
  1399. .info = cxt_eapd_info,
  1400. .get = cxt_eapd_get,
  1401. .put = cxt5051_hp_master_sw_put,
  1402. .private_value = 0x1a,
  1403. },
  1404. {}
  1405. };
  1406. static struct hda_verb cxt5051_init_verbs[] = {
  1407. /* Line in, Mic */
  1408. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1409. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1410. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1411. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1412. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1413. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1414. /* SPK */
  1415. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1416. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1417. /* HP, Amp */
  1418. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1419. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1420. /* DAC1 */
  1421. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1422. /* Record selector: Int mic */
  1423. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1424. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1425. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1426. /* SPDIF route: PCM */
  1427. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1428. /* EAPD */
  1429. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1430. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1431. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1432. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1433. { } /* end */
  1434. };
  1435. /* initialize jack-sensing, too */
  1436. static int cxt5051_init(struct hda_codec *codec)
  1437. {
  1438. conexant_init(codec);
  1439. if (codec->patch_ops.unsol_event) {
  1440. cxt5051_hp_automute(codec);
  1441. cxt5051_portb_automic(codec);
  1442. cxt5051_portc_automic(codec);
  1443. }
  1444. return 0;
  1445. }
  1446. enum {
  1447. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1448. CXT5051_HP, /* no docking */
  1449. CXT5051_MODELS
  1450. };
  1451. static const char *cxt5051_models[CXT5051_MODELS] = {
  1452. [CXT5051_LAPTOP] = "laptop",
  1453. [CXT5051_HP] = "hp",
  1454. };
  1455. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1456. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1457. CXT5051_LAPTOP),
  1458. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1459. {}
  1460. };
  1461. static int patch_cxt5051(struct hda_codec *codec)
  1462. {
  1463. struct conexant_spec *spec;
  1464. int board_config;
  1465. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1466. if (!spec)
  1467. return -ENOMEM;
  1468. mutex_init(&spec->amp_mutex);
  1469. codec->spec = spec;
  1470. codec->patch_ops = conexant_patch_ops;
  1471. codec->patch_ops.init = cxt5051_init;
  1472. spec->multiout.max_channels = 2;
  1473. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1474. spec->multiout.dac_nids = cxt5051_dac_nids;
  1475. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1476. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1477. spec->adc_nids = cxt5051_adc_nids;
  1478. spec->num_mixers = 1;
  1479. spec->mixers[0] = cxt5051_mixers;
  1480. spec->num_init_verbs = 1;
  1481. spec->init_verbs[0] = cxt5051_init_verbs;
  1482. spec->spdif_route = 0;
  1483. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1484. spec->channel_mode = cxt5051_modes;
  1485. spec->cur_adc = 0;
  1486. spec->cur_adc_idx = 0;
  1487. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1488. cxt5051_models,
  1489. cxt5051_cfg_tbl);
  1490. switch (board_config) {
  1491. case CXT5051_HP:
  1492. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1493. spec->mixers[0] = cxt5051_hp_mixers;
  1494. break;
  1495. default:
  1496. case CXT5051_LAPTOP:
  1497. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1498. break;
  1499. }
  1500. return 0;
  1501. }
  1502. /*
  1503. */
  1504. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1505. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1506. .patch = patch_cxt5045 },
  1507. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1508. .patch = patch_cxt5047 },
  1509. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  1510. .patch = patch_cxt5051 },
  1511. {} /* terminator */
  1512. };