patch_conexant.c 57 KB

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