patch_conexant.c 53 KB

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