patch_conexant.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  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. hda_nid_t vmaster_nid;
  50. const struct hda_verb *init_verbs[5]; /* initialization verbs
  51. * don't forget NULL
  52. * termination!
  53. */
  54. unsigned int num_init_verbs;
  55. /* playback */
  56. struct hda_multi_out multiout; /* playback set-up
  57. * max_channels, dacs must be set
  58. * dig_out_nid and hp_nid are optional
  59. */
  60. unsigned int cur_eapd;
  61. unsigned int hp_present;
  62. unsigned int no_auto_mic;
  63. unsigned int need_dac_fix;
  64. /* capture */
  65. unsigned int num_adc_nids;
  66. hda_nid_t *adc_nids;
  67. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  68. unsigned int cur_adc_idx;
  69. hda_nid_t cur_adc;
  70. unsigned int cur_adc_stream_tag;
  71. unsigned int cur_adc_format;
  72. /* capture source */
  73. const struct hda_input_mux *input_mux;
  74. hda_nid_t *capsrc_nids;
  75. unsigned int cur_mux[3];
  76. /* channel model */
  77. const struct hda_channel_mode *channel_mode;
  78. int num_channel_mode;
  79. /* PCM information */
  80. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  81. unsigned int spdif_route;
  82. /* jack detection */
  83. struct snd_array jacks;
  84. /* dynamic controls, init_verbs and input_mux */
  85. struct auto_pin_cfg autocfg;
  86. struct hda_input_mux private_imux;
  87. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  88. unsigned int dell_automute;
  89. unsigned int port_d_mode;
  90. };
  91. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  92. struct hda_codec *codec,
  93. struct snd_pcm_substream *substream)
  94. {
  95. struct conexant_spec *spec = codec->spec;
  96. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  97. hinfo);
  98. }
  99. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  100. struct hda_codec *codec,
  101. unsigned int stream_tag,
  102. unsigned int format,
  103. struct snd_pcm_substream *substream)
  104. {
  105. struct conexant_spec *spec = codec->spec;
  106. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  107. stream_tag,
  108. format, substream);
  109. }
  110. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  111. struct hda_codec *codec,
  112. struct snd_pcm_substream *substream)
  113. {
  114. struct conexant_spec *spec = codec->spec;
  115. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  116. }
  117. /*
  118. * Digital out
  119. */
  120. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  121. struct hda_codec *codec,
  122. struct snd_pcm_substream *substream)
  123. {
  124. struct conexant_spec *spec = codec->spec;
  125. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  126. }
  127. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  128. struct hda_codec *codec,
  129. struct snd_pcm_substream *substream)
  130. {
  131. struct conexant_spec *spec = codec->spec;
  132. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  133. }
  134. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  135. struct hda_codec *codec,
  136. unsigned int stream_tag,
  137. unsigned int format,
  138. struct snd_pcm_substream *substream)
  139. {
  140. struct conexant_spec *spec = codec->spec;
  141. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  142. stream_tag,
  143. format, substream);
  144. }
  145. /*
  146. * Analog capture
  147. */
  148. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  149. struct hda_codec *codec,
  150. unsigned int stream_tag,
  151. unsigned int format,
  152. struct snd_pcm_substream *substream)
  153. {
  154. struct conexant_spec *spec = codec->spec;
  155. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  156. stream_tag, 0, format);
  157. return 0;
  158. }
  159. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  160. struct hda_codec *codec,
  161. struct snd_pcm_substream *substream)
  162. {
  163. struct conexant_spec *spec = codec->spec;
  164. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  165. return 0;
  166. }
  167. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  168. .substreams = 1,
  169. .channels_min = 2,
  170. .channels_max = 2,
  171. .nid = 0, /* fill later */
  172. .ops = {
  173. .open = conexant_playback_pcm_open,
  174. .prepare = conexant_playback_pcm_prepare,
  175. .cleanup = conexant_playback_pcm_cleanup
  176. },
  177. };
  178. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  179. .substreams = 1,
  180. .channels_min = 2,
  181. .channels_max = 2,
  182. .nid = 0, /* fill later */
  183. .ops = {
  184. .prepare = conexant_capture_pcm_prepare,
  185. .cleanup = conexant_capture_pcm_cleanup
  186. },
  187. };
  188. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  189. .substreams = 1,
  190. .channels_min = 2,
  191. .channels_max = 2,
  192. .nid = 0, /* fill later */
  193. .ops = {
  194. .open = conexant_dig_playback_pcm_open,
  195. .close = conexant_dig_playback_pcm_close,
  196. .prepare = conexant_dig_playback_pcm_prepare
  197. },
  198. };
  199. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  200. .substreams = 1,
  201. .channels_min = 2,
  202. .channels_max = 2,
  203. /* NID is set in alc_build_pcms */
  204. };
  205. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  206. struct hda_codec *codec,
  207. unsigned int stream_tag,
  208. unsigned int format,
  209. struct snd_pcm_substream *substream)
  210. {
  211. struct conexant_spec *spec = codec->spec;
  212. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  213. spec->cur_adc_stream_tag = stream_tag;
  214. spec->cur_adc_format = format;
  215. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  216. return 0;
  217. }
  218. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  219. struct hda_codec *codec,
  220. struct snd_pcm_substream *substream)
  221. {
  222. struct conexant_spec *spec = codec->spec;
  223. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  224. spec->cur_adc = 0;
  225. return 0;
  226. }
  227. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  228. .substreams = 1,
  229. .channels_min = 2,
  230. .channels_max = 2,
  231. .nid = 0, /* fill later */
  232. .ops = {
  233. .prepare = cx5051_capture_pcm_prepare,
  234. .cleanup = cx5051_capture_pcm_cleanup
  235. },
  236. };
  237. static int conexant_build_pcms(struct hda_codec *codec)
  238. {
  239. struct conexant_spec *spec = codec->spec;
  240. struct hda_pcm *info = spec->pcm_rec;
  241. codec->num_pcms = 1;
  242. codec->pcm_info = info;
  243. info->name = "CONEXANT Analog";
  244. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  245. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  246. spec->multiout.max_channels;
  247. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  248. spec->multiout.dac_nids[0];
  249. if (codec->vendor_id == 0x14f15051)
  250. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  251. cx5051_pcm_analog_capture;
  252. else
  253. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  254. conexant_pcm_analog_capture;
  255. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  256. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  257. if (spec->multiout.dig_out_nid) {
  258. info++;
  259. codec->num_pcms++;
  260. info->name = "Conexant Digital";
  261. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  262. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  263. conexant_pcm_digital_playback;
  264. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  265. spec->multiout.dig_out_nid;
  266. if (spec->dig_in_nid) {
  267. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  268. conexant_pcm_digital_capture;
  269. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  270. spec->dig_in_nid;
  271. }
  272. }
  273. return 0;
  274. }
  275. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  276. struct snd_ctl_elem_info *uinfo)
  277. {
  278. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  279. struct conexant_spec *spec = codec->spec;
  280. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  281. }
  282. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  283. struct snd_ctl_elem_value *ucontrol)
  284. {
  285. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  286. struct conexant_spec *spec = codec->spec;
  287. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  288. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  289. return 0;
  290. }
  291. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  292. struct snd_ctl_elem_value *ucontrol)
  293. {
  294. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  295. struct conexant_spec *spec = codec->spec;
  296. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  297. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  298. spec->capsrc_nids[adc_idx],
  299. &spec->cur_mux[adc_idx]);
  300. }
  301. #ifdef CONFIG_SND_HDA_INPUT_JACK
  302. static void conexant_free_jack_priv(struct snd_jack *jack)
  303. {
  304. struct conexant_jack *jacks = jack->private_data;
  305. jacks->nid = 0;
  306. jacks->jack = NULL;
  307. }
  308. static int conexant_add_jack(struct hda_codec *codec,
  309. hda_nid_t nid, int type)
  310. {
  311. struct conexant_spec *spec;
  312. struct conexant_jack *jack;
  313. const char *name;
  314. int err;
  315. spec = codec->spec;
  316. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  317. jack = snd_array_new(&spec->jacks);
  318. name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
  319. if (!jack)
  320. return -ENOMEM;
  321. jack->nid = nid;
  322. jack->type = type;
  323. err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
  324. if (err < 0)
  325. return err;
  326. jack->jack->private_data = jack;
  327. jack->jack->private_free = conexant_free_jack_priv;
  328. return 0;
  329. }
  330. static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  331. {
  332. struct conexant_spec *spec = codec->spec;
  333. struct conexant_jack *jacks = spec->jacks.list;
  334. if (jacks) {
  335. int i;
  336. for (i = 0; i < spec->jacks.used; i++) {
  337. if (jacks->nid == nid) {
  338. unsigned int present;
  339. present = snd_hda_codec_read(codec, nid, 0,
  340. AC_VERB_GET_PIN_SENSE, 0) &
  341. AC_PINSENSE_PRESENCE;
  342. present = (present) ? jacks->type : 0 ;
  343. snd_jack_report(jacks->jack,
  344. present);
  345. }
  346. jacks++;
  347. }
  348. }
  349. }
  350. static int conexant_init_jacks(struct hda_codec *codec)
  351. {
  352. struct conexant_spec *spec = codec->spec;
  353. int i;
  354. for (i = 0; i < spec->num_init_verbs; i++) {
  355. const struct hda_verb *hv;
  356. hv = spec->init_verbs[i];
  357. while (hv->nid) {
  358. int err = 0;
  359. switch (hv->param ^ AC_USRSP_EN) {
  360. case CONEXANT_HP_EVENT:
  361. err = conexant_add_jack(codec, hv->nid,
  362. SND_JACK_HEADPHONE);
  363. conexant_report_jack(codec, hv->nid);
  364. break;
  365. case CXT5051_PORTC_EVENT:
  366. case CONEXANT_MIC_EVENT:
  367. err = conexant_add_jack(codec, hv->nid,
  368. SND_JACK_MICROPHONE);
  369. conexant_report_jack(codec, hv->nid);
  370. break;
  371. }
  372. if (err < 0)
  373. return err;
  374. ++hv;
  375. }
  376. }
  377. return 0;
  378. }
  379. #else
  380. static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  381. {
  382. }
  383. static inline int conexant_init_jacks(struct hda_codec *codec)
  384. {
  385. return 0;
  386. }
  387. #endif
  388. static int conexant_init(struct hda_codec *codec)
  389. {
  390. struct conexant_spec *spec = codec->spec;
  391. int i;
  392. for (i = 0; i < spec->num_init_verbs; i++)
  393. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  394. return 0;
  395. }
  396. static void conexant_free(struct hda_codec *codec)
  397. {
  398. #ifdef CONFIG_SND_HDA_INPUT_JACK
  399. struct conexant_spec *spec = codec->spec;
  400. if (spec->jacks.list) {
  401. struct conexant_jack *jacks = spec->jacks.list;
  402. int i;
  403. for (i = 0; i < spec->jacks.used; i++, jacks++) {
  404. if (jacks->jack)
  405. snd_device_free(codec->bus->card, jacks->jack);
  406. }
  407. snd_array_free(&spec->jacks);
  408. }
  409. #endif
  410. kfree(codec->spec);
  411. }
  412. static struct snd_kcontrol_new cxt_capture_mixers[] = {
  413. {
  414. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  415. .name = "Capture Source",
  416. .info = conexant_mux_enum_info,
  417. .get = conexant_mux_enum_get,
  418. .put = conexant_mux_enum_put
  419. },
  420. {}
  421. };
  422. static const char *slave_vols[] = {
  423. "Headphone Playback Volume",
  424. "Speaker Playback Volume",
  425. NULL
  426. };
  427. static const char *slave_sws[] = {
  428. "Headphone Playback Switch",
  429. "Speaker Playback Switch",
  430. NULL
  431. };
  432. static int conexant_build_controls(struct hda_codec *codec)
  433. {
  434. struct conexant_spec *spec = codec->spec;
  435. unsigned int i;
  436. int err;
  437. for (i = 0; i < spec->num_mixers; i++) {
  438. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  439. if (err < 0)
  440. return err;
  441. }
  442. if (spec->multiout.dig_out_nid) {
  443. err = snd_hda_create_spdif_out_ctls(codec,
  444. spec->multiout.dig_out_nid);
  445. if (err < 0)
  446. return err;
  447. err = snd_hda_create_spdif_share_sw(codec,
  448. &spec->multiout);
  449. if (err < 0)
  450. return err;
  451. spec->multiout.share_spdif = 1;
  452. }
  453. if (spec->dig_in_nid) {
  454. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  455. if (err < 0)
  456. return err;
  457. }
  458. /* if we have no master control, let's create it */
  459. if (spec->vmaster_nid &&
  460. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  461. unsigned int vmaster_tlv[4];
  462. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  463. HDA_OUTPUT, vmaster_tlv);
  464. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  465. vmaster_tlv, slave_vols);
  466. if (err < 0)
  467. return err;
  468. }
  469. if (spec->vmaster_nid &&
  470. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  471. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  472. NULL, slave_sws);
  473. if (err < 0)
  474. return err;
  475. }
  476. if (spec->input_mux) {
  477. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  478. if (err < 0)
  479. return err;
  480. }
  481. return 0;
  482. }
  483. static struct hda_codec_ops conexant_patch_ops = {
  484. .build_controls = conexant_build_controls,
  485. .build_pcms = conexant_build_pcms,
  486. .init = conexant_init,
  487. .free = conexant_free,
  488. };
  489. /*
  490. * EAPD control
  491. * the private value = nid | (invert << 8)
  492. */
  493. #define cxt_eapd_info snd_ctl_boolean_mono_info
  494. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  495. struct snd_ctl_elem_value *ucontrol)
  496. {
  497. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  498. struct conexant_spec *spec = codec->spec;
  499. int invert = (kcontrol->private_value >> 8) & 1;
  500. if (invert)
  501. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  502. else
  503. ucontrol->value.integer.value[0] = spec->cur_eapd;
  504. return 0;
  505. }
  506. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_value *ucontrol)
  508. {
  509. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  510. struct conexant_spec *spec = codec->spec;
  511. int invert = (kcontrol->private_value >> 8) & 1;
  512. hda_nid_t nid = kcontrol->private_value & 0xff;
  513. unsigned int eapd;
  514. eapd = !!ucontrol->value.integer.value[0];
  515. if (invert)
  516. eapd = !eapd;
  517. if (eapd == spec->cur_eapd)
  518. return 0;
  519. spec->cur_eapd = eapd;
  520. snd_hda_codec_write_cache(codec, nid,
  521. 0, AC_VERB_SET_EAPD_BTLENABLE,
  522. eapd ? 0x02 : 0x00);
  523. return 1;
  524. }
  525. /* controls for test mode */
  526. #ifdef CONFIG_SND_DEBUG
  527. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  528. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  529. .info = cxt_eapd_info, \
  530. .get = cxt_eapd_get, \
  531. .put = cxt_eapd_put, \
  532. .private_value = nid | (mask<<16) }
  533. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  534. struct snd_ctl_elem_info *uinfo)
  535. {
  536. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  537. struct conexant_spec *spec = codec->spec;
  538. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  539. spec->num_channel_mode);
  540. }
  541. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  542. struct snd_ctl_elem_value *ucontrol)
  543. {
  544. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  545. struct conexant_spec *spec = codec->spec;
  546. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  547. spec->num_channel_mode,
  548. spec->multiout.max_channels);
  549. }
  550. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  551. struct snd_ctl_elem_value *ucontrol)
  552. {
  553. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  554. struct conexant_spec *spec = codec->spec;
  555. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  556. spec->num_channel_mode,
  557. &spec->multiout.max_channels);
  558. if (err >= 0 && spec->need_dac_fix)
  559. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  560. return err;
  561. }
  562. #define CXT_PIN_MODE(xname, nid, dir) \
  563. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  564. .info = conexant_ch_mode_info, \
  565. .get = conexant_ch_mode_get, \
  566. .put = conexant_ch_mode_put, \
  567. .private_value = nid | (dir<<16) }
  568. #endif /* CONFIG_SND_DEBUG */
  569. /* Conexant 5045 specific */
  570. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  571. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  572. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  573. #define CXT5045_SPDIF_OUT 0x18
  574. static struct hda_channel_mode cxt5045_modes[1] = {
  575. { 2, NULL },
  576. };
  577. static struct hda_input_mux cxt5045_capture_source = {
  578. .num_items = 2,
  579. .items = {
  580. { "IntMic", 0x1 },
  581. { "ExtMic", 0x2 },
  582. }
  583. };
  584. static struct hda_input_mux cxt5045_capture_source_benq = {
  585. .num_items = 5,
  586. .items = {
  587. { "IntMic", 0x1 },
  588. { "ExtMic", 0x2 },
  589. { "LineIn", 0x3 },
  590. { "CD", 0x4 },
  591. { "Mixer", 0x0 },
  592. }
  593. };
  594. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  595. .num_items = 2,
  596. .items = {
  597. { "ExtMic", 0x1 },
  598. { "IntMic", 0x2 },
  599. }
  600. };
  601. /* turn on/off EAPD (+ mute HP) as a master switch */
  602. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  603. struct snd_ctl_elem_value *ucontrol)
  604. {
  605. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  606. struct conexant_spec *spec = codec->spec;
  607. unsigned int bits;
  608. if (!cxt_eapd_put(kcontrol, ucontrol))
  609. return 0;
  610. /* toggle internal speakers mute depending of presence of
  611. * the headphone jack
  612. */
  613. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  614. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  615. HDA_AMP_MUTE, bits);
  616. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  617. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  618. HDA_AMP_MUTE, bits);
  619. return 1;
  620. }
  621. /* bind volumes of both NID 0x10 and 0x11 */
  622. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  623. .ops = &snd_hda_bind_vol,
  624. .values = {
  625. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  626. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  627. 0
  628. },
  629. };
  630. /* toggle input of built-in and mic jack appropriately */
  631. static void cxt5045_hp_automic(struct hda_codec *codec)
  632. {
  633. static struct hda_verb mic_jack_on[] = {
  634. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  635. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  636. {}
  637. };
  638. static struct hda_verb mic_jack_off[] = {
  639. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  640. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  641. {}
  642. };
  643. unsigned int present;
  644. present = snd_hda_codec_read(codec, 0x12, 0,
  645. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  646. if (present)
  647. snd_hda_sequence_write(codec, mic_jack_on);
  648. else
  649. snd_hda_sequence_write(codec, mic_jack_off);
  650. }
  651. /* mute internal speaker if HP is plugged */
  652. static void cxt5045_hp_automute(struct hda_codec *codec)
  653. {
  654. struct conexant_spec *spec = codec->spec;
  655. unsigned int bits;
  656. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  657. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  658. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  659. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  660. HDA_AMP_MUTE, bits);
  661. }
  662. /* unsolicited event for HP jack sensing */
  663. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  664. unsigned int res)
  665. {
  666. res >>= 26;
  667. switch (res) {
  668. case CONEXANT_HP_EVENT:
  669. cxt5045_hp_automute(codec);
  670. break;
  671. case CONEXANT_MIC_EVENT:
  672. cxt5045_hp_automic(codec);
  673. break;
  674. }
  675. }
  676. static struct snd_kcontrol_new cxt5045_mixers[] = {
  677. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  678. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  679. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  680. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  681. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  682. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  683. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  684. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  685. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  686. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  687. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  688. {
  689. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  690. .name = "Master Playback Switch",
  691. .info = cxt_eapd_info,
  692. .get = cxt_eapd_get,
  693. .put = cxt5045_hp_master_sw_put,
  694. .private_value = 0x10,
  695. },
  696. {}
  697. };
  698. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  699. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  700. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  701. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  702. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  703. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  704. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  706. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  707. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  708. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  709. {}
  710. };
  711. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  712. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  713. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  714. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  715. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  716. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  717. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  718. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  719. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  720. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  721. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  722. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  723. {
  724. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  725. .name = "Master Playback Switch",
  726. .info = cxt_eapd_info,
  727. .get = cxt_eapd_get,
  728. .put = cxt5045_hp_master_sw_put,
  729. .private_value = 0x10,
  730. },
  731. {}
  732. };
  733. static struct hda_verb cxt5045_init_verbs[] = {
  734. /* Line in, Mic */
  735. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  736. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  737. /* HP, Amp */
  738. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  739. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  740. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  741. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  742. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  743. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  744. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  745. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  746. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  747. /* Record selector: Int mic */
  748. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  749. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  750. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  751. /* SPDIF route: PCM */
  752. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  753. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  754. /* EAPD */
  755. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  756. { } /* end */
  757. };
  758. static struct hda_verb cxt5045_benq_init_verbs[] = {
  759. /* Int Mic, Mic */
  760. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  761. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  762. /* Line In,HP, Amp */
  763. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  764. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  765. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  766. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  767. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  768. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  769. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  770. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  771. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  772. /* Record selector: Int mic */
  773. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  774. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  775. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  776. /* SPDIF route: PCM */
  777. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  778. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  779. /* EAPD */
  780. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  781. { } /* end */
  782. };
  783. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  784. /* pin sensing on HP jack */
  785. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  786. { } /* end */
  787. };
  788. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  789. /* pin sensing on HP jack */
  790. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  791. { } /* end */
  792. };
  793. #ifdef CONFIG_SND_DEBUG
  794. /* Test configuration for debugging, modelled after the ALC260 test
  795. * configuration.
  796. */
  797. static struct hda_input_mux cxt5045_test_capture_source = {
  798. .num_items = 5,
  799. .items = {
  800. { "MIXER", 0x0 },
  801. { "MIC1 pin", 0x1 },
  802. { "LINE1 pin", 0x2 },
  803. { "HP-OUT pin", 0x3 },
  804. { "CD pin", 0x4 },
  805. },
  806. };
  807. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  808. /* Output controls */
  809. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  810. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  811. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  812. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  813. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  814. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  815. /* Modes for retasking pin widgets */
  816. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  817. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  818. /* EAPD Switch Control */
  819. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  820. /* Loopback mixer controls */
  821. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  822. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  823. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  824. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  825. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  826. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  827. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  828. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  829. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  830. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  831. {
  832. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  833. .name = "Input Source",
  834. .info = conexant_mux_enum_info,
  835. .get = conexant_mux_enum_get,
  836. .put = conexant_mux_enum_put,
  837. },
  838. /* Audio input controls */
  839. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  840. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  841. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  842. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  843. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  844. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  845. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  846. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  847. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  848. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  849. { } /* end */
  850. };
  851. static struct hda_verb cxt5045_test_init_verbs[] = {
  852. /* Set connections */
  853. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  854. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  855. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  856. /* Enable retasking pins as output, initially without power amp */
  857. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  858. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  859. /* Disable digital (SPDIF) pins initially, but users can enable
  860. * them via a mixer switch. In the case of SPDIF-out, this initverb
  861. * payload also sets the generation to 0, output to be in "consumer"
  862. * PCM format, copyright asserted, no pre-emphasis and no validity
  863. * control.
  864. */
  865. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  866. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  867. /* Start with output sum widgets muted and their output gains at min */
  868. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  869. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  870. /* Unmute retasking pin widget output buffers since the default
  871. * state appears to be output. As the pin mode is changed by the
  872. * user the pin mode control will take care of enabling the pin's
  873. * input/output buffers as needed.
  874. */
  875. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  876. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  877. /* Mute capture amp left and right */
  878. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  879. /* Set ADC connection select to match default mixer setting (mic1
  880. * pin)
  881. */
  882. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  883. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  884. /* Mute all inputs to mixer widget (even unconnected ones) */
  885. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  886. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  887. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  888. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  889. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  890. { }
  891. };
  892. #endif
  893. /* initialize jack-sensing, too */
  894. static int cxt5045_init(struct hda_codec *codec)
  895. {
  896. conexant_init(codec);
  897. cxt5045_hp_automute(codec);
  898. return 0;
  899. }
  900. enum {
  901. CXT5045_LAPTOP_HPSENSE,
  902. CXT5045_LAPTOP_MICSENSE,
  903. CXT5045_LAPTOP_HPMICSENSE,
  904. CXT5045_BENQ,
  905. CXT5045_LAPTOP_HP530,
  906. #ifdef CONFIG_SND_DEBUG
  907. CXT5045_TEST,
  908. #endif
  909. CXT5045_MODELS
  910. };
  911. static const char *cxt5045_models[CXT5045_MODELS] = {
  912. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  913. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  914. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  915. [CXT5045_BENQ] = "benq",
  916. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  917. #ifdef CONFIG_SND_DEBUG
  918. [CXT5045_TEST] = "test",
  919. #endif
  920. };
  921. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  922. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  923. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  924. CXT5045_LAPTOP_HPSENSE),
  925. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  926. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  927. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  928. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  929. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  930. CXT5045_LAPTOP_HPMICSENSE),
  931. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  932. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  933. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  934. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  935. CXT5045_LAPTOP_HPMICSENSE),
  936. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  937. {}
  938. };
  939. static int patch_cxt5045(struct hda_codec *codec)
  940. {
  941. struct conexant_spec *spec;
  942. int board_config;
  943. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  944. if (!spec)
  945. return -ENOMEM;
  946. codec->spec = spec;
  947. codec->pin_amp_workaround = 1;
  948. spec->multiout.max_channels = 2;
  949. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  950. spec->multiout.dac_nids = cxt5045_dac_nids;
  951. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  952. spec->num_adc_nids = 1;
  953. spec->adc_nids = cxt5045_adc_nids;
  954. spec->capsrc_nids = cxt5045_capsrc_nids;
  955. spec->input_mux = &cxt5045_capture_source;
  956. spec->num_mixers = 1;
  957. spec->mixers[0] = cxt5045_mixers;
  958. spec->num_init_verbs = 1;
  959. spec->init_verbs[0] = cxt5045_init_verbs;
  960. spec->spdif_route = 0;
  961. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  962. spec->channel_mode = cxt5045_modes,
  963. codec->patch_ops = conexant_patch_ops;
  964. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  965. cxt5045_models,
  966. cxt5045_cfg_tbl);
  967. switch (board_config) {
  968. case CXT5045_LAPTOP_HPSENSE:
  969. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  970. spec->input_mux = &cxt5045_capture_source;
  971. spec->num_init_verbs = 2;
  972. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  973. spec->mixers[0] = cxt5045_mixers;
  974. codec->patch_ops.init = cxt5045_init;
  975. break;
  976. case CXT5045_LAPTOP_MICSENSE:
  977. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  978. spec->input_mux = &cxt5045_capture_source;
  979. spec->num_init_verbs = 2;
  980. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  981. spec->mixers[0] = cxt5045_mixers;
  982. codec->patch_ops.init = cxt5045_init;
  983. break;
  984. default:
  985. case CXT5045_LAPTOP_HPMICSENSE:
  986. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  987. spec->input_mux = &cxt5045_capture_source;
  988. spec->num_init_verbs = 3;
  989. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  990. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  991. spec->mixers[0] = cxt5045_mixers;
  992. codec->patch_ops.init = cxt5045_init;
  993. break;
  994. case CXT5045_BENQ:
  995. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  996. spec->input_mux = &cxt5045_capture_source_benq;
  997. spec->num_init_verbs = 1;
  998. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  999. spec->mixers[0] = cxt5045_mixers;
  1000. spec->mixers[1] = cxt5045_benq_mixers;
  1001. spec->num_mixers = 2;
  1002. codec->patch_ops.init = cxt5045_init;
  1003. break;
  1004. case CXT5045_LAPTOP_HP530:
  1005. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1006. spec->input_mux = &cxt5045_capture_source_hp530;
  1007. spec->num_init_verbs = 2;
  1008. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1009. spec->mixers[0] = cxt5045_mixers_hp530;
  1010. codec->patch_ops.init = cxt5045_init;
  1011. break;
  1012. #ifdef CONFIG_SND_DEBUG
  1013. case CXT5045_TEST:
  1014. spec->input_mux = &cxt5045_test_capture_source;
  1015. spec->mixers[0] = cxt5045_test_mixer;
  1016. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1017. break;
  1018. #endif
  1019. }
  1020. switch (codec->subsystem_id >> 16) {
  1021. case 0x103c:
  1022. /* HP laptop has a really bad sound over 0dB on NID 0x17.
  1023. * Fix max PCM level to 0 dB
  1024. * (originall it has 0x2b steps with 0dB offset 0x14)
  1025. */
  1026. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1027. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1028. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1029. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1030. (1 << AC_AMPCAP_MUTE_SHIFT));
  1031. break;
  1032. }
  1033. return 0;
  1034. }
  1035. /* Conexant 5047 specific */
  1036. #define CXT5047_SPDIF_OUT 0x11
  1037. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1038. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1039. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1040. static struct hda_channel_mode cxt5047_modes[1] = {
  1041. { 2, NULL },
  1042. };
  1043. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  1044. .num_items = 2,
  1045. .items = {
  1046. { "ExtMic", 0x2 },
  1047. { "Line-In", 0x1 },
  1048. }
  1049. };
  1050. /* turn on/off EAPD (+ mute HP) as a master switch */
  1051. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1052. struct snd_ctl_elem_value *ucontrol)
  1053. {
  1054. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1055. struct conexant_spec *spec = codec->spec;
  1056. unsigned int bits;
  1057. if (!cxt_eapd_put(kcontrol, ucontrol))
  1058. return 0;
  1059. /* toggle internal speakers mute depending of presence of
  1060. * the headphone jack
  1061. */
  1062. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1063. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1064. * pin widgets unlike other codecs. In this case, we need to
  1065. * set index 0x01 for the volume from the mixer amp 0x19.
  1066. */
  1067. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1068. HDA_AMP_MUTE, bits);
  1069. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1070. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1071. HDA_AMP_MUTE, bits);
  1072. return 1;
  1073. }
  1074. /* mute internal speaker if HP is plugged */
  1075. static void cxt5047_hp_automute(struct hda_codec *codec)
  1076. {
  1077. struct conexant_spec *spec = codec->spec;
  1078. unsigned int bits;
  1079. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  1080. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1081. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1082. /* See the note in cxt5047_hp_master_sw_put */
  1083. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1084. HDA_AMP_MUTE, bits);
  1085. }
  1086. /* toggle input of built-in and mic jack appropriately */
  1087. static void cxt5047_hp_automic(struct hda_codec *codec)
  1088. {
  1089. static struct hda_verb mic_jack_on[] = {
  1090. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1091. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1092. {}
  1093. };
  1094. static struct hda_verb mic_jack_off[] = {
  1095. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1096. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1097. {}
  1098. };
  1099. unsigned int present;
  1100. present = snd_hda_codec_read(codec, 0x15, 0,
  1101. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1102. if (present)
  1103. snd_hda_sequence_write(codec, mic_jack_on);
  1104. else
  1105. snd_hda_sequence_write(codec, mic_jack_off);
  1106. }
  1107. /* unsolicited event for HP jack sensing */
  1108. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1109. unsigned int res)
  1110. {
  1111. switch (res >> 26) {
  1112. case CONEXANT_HP_EVENT:
  1113. cxt5047_hp_automute(codec);
  1114. break;
  1115. case CONEXANT_MIC_EVENT:
  1116. cxt5047_hp_automic(codec);
  1117. break;
  1118. }
  1119. }
  1120. static struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1121. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1122. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1123. HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
  1124. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1125. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1126. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1127. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1128. {
  1129. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1130. .name = "Master Playback Switch",
  1131. .info = cxt_eapd_info,
  1132. .get = cxt_eapd_get,
  1133. .put = cxt5047_hp_master_sw_put,
  1134. .private_value = 0x13,
  1135. },
  1136. {}
  1137. };
  1138. static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1139. /* See the note in cxt5047_hp_master_sw_put */
  1140. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1141. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1142. {}
  1143. };
  1144. static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1145. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1146. { } /* end */
  1147. };
  1148. static struct hda_verb cxt5047_init_verbs[] = {
  1149. /* Line in, Mic, Built-in Mic */
  1150. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1151. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1152. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1153. /* HP, Speaker */
  1154. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1155. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1156. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1157. /* Record selector: Mic */
  1158. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1159. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1160. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1161. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1162. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1163. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1164. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1165. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1166. /* SPDIF route: PCM */
  1167. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1168. /* Enable unsolicited events */
  1169. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1170. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1171. { } /* end */
  1172. };
  1173. /* configuration for Toshiba Laptops */
  1174. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1175. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1176. {}
  1177. };
  1178. /* Test configuration for debugging, modelled after the ALC260 test
  1179. * configuration.
  1180. */
  1181. #ifdef CONFIG_SND_DEBUG
  1182. static struct hda_input_mux cxt5047_test_capture_source = {
  1183. .num_items = 4,
  1184. .items = {
  1185. { "LINE1 pin", 0x0 },
  1186. { "MIC1 pin", 0x1 },
  1187. { "MIC2 pin", 0x2 },
  1188. { "CD pin", 0x3 },
  1189. },
  1190. };
  1191. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1192. /* Output only controls */
  1193. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1194. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1195. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1196. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1197. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1198. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1199. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1200. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1201. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1202. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1203. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1204. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1205. /* Modes for retasking pin widgets */
  1206. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1207. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1208. /* EAPD Switch Control */
  1209. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1210. /* Loopback mixer controls */
  1211. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1212. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1213. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1214. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1215. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1216. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1217. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1218. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1219. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1220. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1221. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1222. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1223. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1224. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1225. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1226. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1227. {
  1228. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1229. .name = "Input Source",
  1230. .info = conexant_mux_enum_info,
  1231. .get = conexant_mux_enum_get,
  1232. .put = conexant_mux_enum_put,
  1233. },
  1234. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  1235. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  1236. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  1237. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  1238. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  1239. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  1240. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  1241. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  1242. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  1243. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  1244. { } /* end */
  1245. };
  1246. static struct hda_verb cxt5047_test_init_verbs[] = {
  1247. /* Enable retasking pins as output, initially without power amp */
  1248. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1249. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1250. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1251. /* Disable digital (SPDIF) pins initially, but users can enable
  1252. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1253. * payload also sets the generation to 0, output to be in "consumer"
  1254. * PCM format, copyright asserted, no pre-emphasis and no validity
  1255. * control.
  1256. */
  1257. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1258. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1259. * OUT1 sum bus when acting as an output.
  1260. */
  1261. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1262. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1263. /* Start with output sum widgets muted and their output gains at min */
  1264. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1265. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1266. /* Unmute retasking pin widget output buffers since the default
  1267. * state appears to be output. As the pin mode is changed by the
  1268. * user the pin mode control will take care of enabling the pin's
  1269. * input/output buffers as needed.
  1270. */
  1271. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1272. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1273. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1274. /* Mute capture amp left and right */
  1275. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1276. /* Set ADC connection select to match default mixer setting (mic1
  1277. * pin)
  1278. */
  1279. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1280. /* Mute all inputs to mixer widget (even unconnected ones) */
  1281. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1282. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1283. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1284. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1285. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1286. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1287. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1288. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1289. { }
  1290. };
  1291. #endif
  1292. /* initialize jack-sensing, too */
  1293. static int cxt5047_hp_init(struct hda_codec *codec)
  1294. {
  1295. conexant_init(codec);
  1296. cxt5047_hp_automute(codec);
  1297. return 0;
  1298. }
  1299. enum {
  1300. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1301. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1302. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1303. #ifdef CONFIG_SND_DEBUG
  1304. CXT5047_TEST,
  1305. #endif
  1306. CXT5047_MODELS
  1307. };
  1308. static const char *cxt5047_models[CXT5047_MODELS] = {
  1309. [CXT5047_LAPTOP] = "laptop",
  1310. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1311. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1312. #ifdef CONFIG_SND_DEBUG
  1313. [CXT5047_TEST] = "test",
  1314. #endif
  1315. };
  1316. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1317. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1318. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1319. CXT5047_LAPTOP),
  1320. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1321. {}
  1322. };
  1323. static int patch_cxt5047(struct hda_codec *codec)
  1324. {
  1325. struct conexant_spec *spec;
  1326. int board_config;
  1327. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1328. if (!spec)
  1329. return -ENOMEM;
  1330. codec->spec = spec;
  1331. codec->pin_amp_workaround = 1;
  1332. spec->multiout.max_channels = 2;
  1333. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1334. spec->multiout.dac_nids = cxt5047_dac_nids;
  1335. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1336. spec->num_adc_nids = 1;
  1337. spec->adc_nids = cxt5047_adc_nids;
  1338. spec->capsrc_nids = cxt5047_capsrc_nids;
  1339. spec->num_mixers = 1;
  1340. spec->mixers[0] = cxt5047_base_mixers;
  1341. spec->num_init_verbs = 1;
  1342. spec->init_verbs[0] = cxt5047_init_verbs;
  1343. spec->spdif_route = 0;
  1344. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1345. spec->channel_mode = cxt5047_modes,
  1346. codec->patch_ops = conexant_patch_ops;
  1347. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1348. cxt5047_models,
  1349. cxt5047_cfg_tbl);
  1350. switch (board_config) {
  1351. case CXT5047_LAPTOP:
  1352. spec->num_mixers = 2;
  1353. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1354. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1355. break;
  1356. case CXT5047_LAPTOP_HP:
  1357. spec->num_mixers = 2;
  1358. spec->mixers[1] = cxt5047_hp_only_mixers;
  1359. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1360. codec->patch_ops.init = cxt5047_hp_init;
  1361. break;
  1362. case CXT5047_LAPTOP_EAPD:
  1363. spec->input_mux = &cxt5047_toshiba_capture_source;
  1364. spec->num_mixers = 2;
  1365. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1366. spec->num_init_verbs = 2;
  1367. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1368. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1369. break;
  1370. #ifdef CONFIG_SND_DEBUG
  1371. case CXT5047_TEST:
  1372. spec->input_mux = &cxt5047_test_capture_source;
  1373. spec->mixers[0] = cxt5047_test_mixer;
  1374. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1375. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1376. #endif
  1377. }
  1378. spec->vmaster_nid = 0x13;
  1379. return 0;
  1380. }
  1381. /* Conexant 5051 specific */
  1382. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1383. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1384. static struct hda_channel_mode cxt5051_modes[1] = {
  1385. { 2, NULL },
  1386. };
  1387. static void cxt5051_update_speaker(struct hda_codec *codec)
  1388. {
  1389. struct conexant_spec *spec = codec->spec;
  1390. unsigned int pinctl;
  1391. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1392. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1393. pinctl);
  1394. }
  1395. /* turn on/off EAPD (+ mute HP) as a master switch */
  1396. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1397. struct snd_ctl_elem_value *ucontrol)
  1398. {
  1399. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1400. if (!cxt_eapd_put(kcontrol, ucontrol))
  1401. return 0;
  1402. cxt5051_update_speaker(codec);
  1403. return 1;
  1404. }
  1405. /* toggle input of built-in and mic jack appropriately */
  1406. static void cxt5051_portb_automic(struct hda_codec *codec)
  1407. {
  1408. struct conexant_spec *spec = codec->spec;
  1409. unsigned int present;
  1410. if (spec->no_auto_mic)
  1411. return;
  1412. present = snd_hda_codec_read(codec, 0x17, 0,
  1413. AC_VERB_GET_PIN_SENSE, 0) &
  1414. AC_PINSENSE_PRESENCE;
  1415. snd_hda_codec_write(codec, 0x14, 0,
  1416. AC_VERB_SET_CONNECT_SEL,
  1417. present ? 0x01 : 0x00);
  1418. }
  1419. /* switch the current ADC according to the jack state */
  1420. static void cxt5051_portc_automic(struct hda_codec *codec)
  1421. {
  1422. struct conexant_spec *spec = codec->spec;
  1423. unsigned int present;
  1424. hda_nid_t new_adc;
  1425. if (spec->no_auto_mic)
  1426. return;
  1427. present = snd_hda_codec_read(codec, 0x18, 0,
  1428. AC_VERB_GET_PIN_SENSE, 0) &
  1429. AC_PINSENSE_PRESENCE;
  1430. if (present)
  1431. spec->cur_adc_idx = 1;
  1432. else
  1433. spec->cur_adc_idx = 0;
  1434. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1435. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1436. /* stream is running, let's swap the current ADC */
  1437. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1438. spec->cur_adc = new_adc;
  1439. snd_hda_codec_setup_stream(codec, new_adc,
  1440. spec->cur_adc_stream_tag, 0,
  1441. spec->cur_adc_format);
  1442. }
  1443. }
  1444. /* mute internal speaker if HP is plugged */
  1445. static void cxt5051_hp_automute(struct hda_codec *codec)
  1446. {
  1447. struct conexant_spec *spec = codec->spec;
  1448. spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
  1449. AC_VERB_GET_PIN_SENSE, 0) &
  1450. AC_PINSENSE_PRESENCE;
  1451. cxt5051_update_speaker(codec);
  1452. }
  1453. /* unsolicited event for HP jack sensing */
  1454. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1455. unsigned int res)
  1456. {
  1457. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1458. switch (res >> 26) {
  1459. case CONEXANT_HP_EVENT:
  1460. cxt5051_hp_automute(codec);
  1461. break;
  1462. case CXT5051_PORTB_EVENT:
  1463. cxt5051_portb_automic(codec);
  1464. break;
  1465. case CXT5051_PORTC_EVENT:
  1466. cxt5051_portc_automic(codec);
  1467. break;
  1468. }
  1469. conexant_report_jack(codec, nid);
  1470. }
  1471. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1472. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1473. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1474. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1475. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1476. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1477. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1478. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1479. {
  1480. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1481. .name = "Master Playback Switch",
  1482. .info = cxt_eapd_info,
  1483. .get = cxt_eapd_get,
  1484. .put = cxt5051_hp_master_sw_put,
  1485. .private_value = 0x1a,
  1486. },
  1487. {}
  1488. };
  1489. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1490. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1491. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1492. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1493. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1494. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1495. {
  1496. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1497. .name = "Master Playback Switch",
  1498. .info = cxt_eapd_info,
  1499. .get = cxt_eapd_get,
  1500. .put = cxt5051_hp_master_sw_put,
  1501. .private_value = 0x1a,
  1502. },
  1503. {}
  1504. };
  1505. static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1506. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
  1507. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
  1508. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1509. {
  1510. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1511. .name = "Master Playback Switch",
  1512. .info = cxt_eapd_info,
  1513. .get = cxt_eapd_get,
  1514. .put = cxt5051_hp_master_sw_put,
  1515. .private_value = 0x1a,
  1516. },
  1517. {}
  1518. };
  1519. static struct hda_verb cxt5051_init_verbs[] = {
  1520. /* Line in, Mic */
  1521. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1522. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1523. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1524. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1525. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1526. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1527. /* SPK */
  1528. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1529. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1530. /* HP, Amp */
  1531. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1532. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1533. /* DAC1 */
  1534. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1535. /* Record selector: Int mic */
  1536. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1537. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1538. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1539. /* SPDIF route: PCM */
  1540. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1541. /* EAPD */
  1542. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1543. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1544. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1545. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1546. { } /* end */
  1547. };
  1548. static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1549. /* Line in, Mic */
  1550. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1551. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1552. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1553. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1554. /* SPK */
  1555. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1556. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1557. /* HP, Amp */
  1558. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1559. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1560. /* DAC1 */
  1561. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1562. /* Record selector: Int mic */
  1563. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1564. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1565. /* SPDIF route: PCM */
  1566. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1567. /* EAPD */
  1568. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1569. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1570. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1571. { } /* end */
  1572. };
  1573. static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1574. /* Line in, Mic */
  1575. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1576. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1577. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1578. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1579. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1580. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1581. /* SPK */
  1582. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1583. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1584. /* HP, Amp */
  1585. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1586. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1587. /* Docking HP */
  1588. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1589. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1590. /* DAC1 */
  1591. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1592. /* Record selector: Int mic */
  1593. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1594. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1595. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1596. /* SPDIF route: PCM */
  1597. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1598. /* EAPD */
  1599. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1600. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1601. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1602. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1603. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1604. { } /* end */
  1605. };
  1606. /* initialize jack-sensing, too */
  1607. static int cxt5051_init(struct hda_codec *codec)
  1608. {
  1609. conexant_init(codec);
  1610. conexant_init_jacks(codec);
  1611. if (codec->patch_ops.unsol_event) {
  1612. cxt5051_hp_automute(codec);
  1613. cxt5051_portb_automic(codec);
  1614. cxt5051_portc_automic(codec);
  1615. }
  1616. return 0;
  1617. }
  1618. enum {
  1619. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1620. CXT5051_HP, /* no docking */
  1621. CXT5051_HP_DV6736, /* HP without mic switch */
  1622. CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
  1623. CXT5051_MODELS
  1624. };
  1625. static const char *cxt5051_models[CXT5051_MODELS] = {
  1626. [CXT5051_LAPTOP] = "laptop",
  1627. [CXT5051_HP] = "hp",
  1628. [CXT5051_HP_DV6736] = "hp-dv6736",
  1629. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1630. };
  1631. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1632. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1633. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1634. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1635. CXT5051_LAPTOP),
  1636. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1637. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1638. {}
  1639. };
  1640. static int patch_cxt5051(struct hda_codec *codec)
  1641. {
  1642. struct conexant_spec *spec;
  1643. int board_config;
  1644. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1645. if (!spec)
  1646. return -ENOMEM;
  1647. codec->spec = spec;
  1648. codec->pin_amp_workaround = 1;
  1649. codec->patch_ops = conexant_patch_ops;
  1650. codec->patch_ops.init = cxt5051_init;
  1651. spec->multiout.max_channels = 2;
  1652. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1653. spec->multiout.dac_nids = cxt5051_dac_nids;
  1654. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1655. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1656. spec->adc_nids = cxt5051_adc_nids;
  1657. spec->num_mixers = 1;
  1658. spec->mixers[0] = cxt5051_mixers;
  1659. spec->num_init_verbs = 1;
  1660. spec->init_verbs[0] = cxt5051_init_verbs;
  1661. spec->spdif_route = 0;
  1662. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1663. spec->channel_mode = cxt5051_modes;
  1664. spec->cur_adc = 0;
  1665. spec->cur_adc_idx = 0;
  1666. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1667. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1668. cxt5051_models,
  1669. cxt5051_cfg_tbl);
  1670. switch (board_config) {
  1671. case CXT5051_HP:
  1672. spec->mixers[0] = cxt5051_hp_mixers;
  1673. break;
  1674. case CXT5051_HP_DV6736:
  1675. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1676. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1677. spec->no_auto_mic = 1;
  1678. break;
  1679. case CXT5051_LENOVO_X200:
  1680. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1681. break;
  1682. }
  1683. return 0;
  1684. }
  1685. /* Conexant 5066 specific */
  1686. static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1687. static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1688. static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1689. #define CXT5066_SPDIF_OUT 0x21
  1690. static struct hda_channel_mode cxt5066_modes[1] = {
  1691. { 2, NULL },
  1692. };
  1693. static void cxt5066_update_speaker(struct hda_codec *codec)
  1694. {
  1695. struct conexant_spec *spec = codec->spec;
  1696. unsigned int pinctl;
  1697. snd_printdd("CXT5066: update speaker, hp_present=%d\n",
  1698. spec->hp_present);
  1699. /* Port A (HP) */
  1700. pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
  1701. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1702. pinctl);
  1703. /* Port D (HP/LO) */
  1704. pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
  1705. ? spec->port_d_mode : 0;
  1706. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1707. pinctl);
  1708. /* CLASS_D AMP */
  1709. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1710. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1711. pinctl);
  1712. if (spec->dell_automute) {
  1713. /* DELL AIO Port Rule: PortA > PortD > IntSpk */
  1714. pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
  1715. ? PIN_OUT : 0;
  1716. snd_hda_codec_write(codec, 0x1c, 0,
  1717. AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
  1718. }
  1719. }
  1720. /* turn on/off EAPD (+ mute HP) as a master switch */
  1721. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1722. struct snd_ctl_elem_value *ucontrol)
  1723. {
  1724. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1725. if (!cxt_eapd_put(kcontrol, ucontrol))
  1726. return 0;
  1727. cxt5066_update_speaker(codec);
  1728. return 1;
  1729. }
  1730. /* toggle input of built-in and mic jack appropriately */
  1731. static void cxt5066_automic(struct hda_codec *codec)
  1732. {
  1733. static struct hda_verb ext_mic_present[] = {
  1734. /* enable external mic, port B */
  1735. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1736. /* switch to external mic input */
  1737. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1738. /* disable internal mic, port C */
  1739. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1740. {}
  1741. };
  1742. static struct hda_verb ext_mic_absent[] = {
  1743. /* enable internal mic, port C */
  1744. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1745. /* switch to internal mic input */
  1746. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1747. /* disable external mic, port B */
  1748. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1749. {}
  1750. };
  1751. unsigned int present;
  1752. present = snd_hda_codec_read(codec, 0x1a, 0,
  1753. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1754. if (present) {
  1755. snd_printdd("CXT5066: external microphone detected\n");
  1756. snd_hda_sequence_write(codec, ext_mic_present);
  1757. } else {
  1758. snd_printdd("CXT5066: external microphone absent\n");
  1759. snd_hda_sequence_write(codec, ext_mic_absent);
  1760. }
  1761. }
  1762. /* mute internal speaker if HP is plugged */
  1763. static void cxt5066_hp_automute(struct hda_codec *codec)
  1764. {
  1765. struct conexant_spec *spec = codec->spec;
  1766. unsigned int portA, portD;
  1767. /* Port A */
  1768. portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
  1769. & AC_PINSENSE_PRESENCE;
  1770. /* Port D */
  1771. portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
  1772. & AC_PINSENSE_PRESENCE) << 1;
  1773. spec->hp_present = !!(portA | portD);
  1774. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1775. portA, portD, spec->hp_present);
  1776. cxt5066_update_speaker(codec);
  1777. }
  1778. /* unsolicited event for jack sensing */
  1779. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  1780. {
  1781. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1782. switch (res >> 26) {
  1783. case CONEXANT_HP_EVENT:
  1784. cxt5066_hp_automute(codec);
  1785. break;
  1786. case CONEXANT_MIC_EVENT:
  1787. cxt5066_automic(codec);
  1788. break;
  1789. }
  1790. }
  1791. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  1792. .num_items = 5,
  1793. .items = {
  1794. { "0dB", 0 },
  1795. { "10dB", 1 },
  1796. { "20dB", 2 },
  1797. { "30dB", 3 },
  1798. { "40dB", 4 },
  1799. },
  1800. };
  1801. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  1802. struct snd_ctl_elem_info *uinfo)
  1803. {
  1804. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  1805. }
  1806. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  1807. struct snd_ctl_elem_value *ucontrol)
  1808. {
  1809. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1810. int val;
  1811. val = snd_hda_codec_read(codec, 0x17, 0,
  1812. AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
  1813. ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
  1814. return 0;
  1815. }
  1816. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  1817. struct snd_ctl_elem_value *ucontrol)
  1818. {
  1819. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1820. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  1821. unsigned int idx;
  1822. if (!imux->num_items)
  1823. return 0;
  1824. idx = ucontrol->value.enumerated.item[0];
  1825. if (idx >= imux->num_items)
  1826. idx = imux->num_items - 1;
  1827. snd_hda_codec_write_cache(codec, 0x17, 0,
  1828. AC_VERB_SET_AMP_GAIN_MUTE,
  1829. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  1830. imux->items[idx].index);
  1831. return 1;
  1832. }
  1833. static struct hda_input_mux cxt5066_capture_source = {
  1834. .num_items = 4,
  1835. .items = {
  1836. { "Mic B", 0 },
  1837. { "Mic C", 1 },
  1838. { "Mic E", 2 },
  1839. { "Mic F", 3 },
  1840. },
  1841. };
  1842. static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  1843. .ops = &snd_hda_bind_vol,
  1844. .values = {
  1845. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1846. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1847. 0
  1848. },
  1849. };
  1850. static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  1851. .ops = &snd_hda_bind_sw,
  1852. .values = {
  1853. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1854. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1855. 0
  1856. },
  1857. };
  1858. static struct snd_kcontrol_new cxt5066_mixer_master[] = {
  1859. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1860. {}
  1861. };
  1862. static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  1863. {
  1864. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1865. .name = "Master Playback Volume",
  1866. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  1867. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  1868. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  1869. .info = snd_hda_mixer_amp_volume_info,
  1870. .get = snd_hda_mixer_amp_volume_get,
  1871. .put = snd_hda_mixer_amp_volume_put,
  1872. .tlv = { .c = snd_hda_mixer_amp_tlv },
  1873. /* offset by 28 volume steps to limit minimum gain to -46dB */
  1874. .private_value =
  1875. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  1876. },
  1877. {}
  1878. };
  1879. static struct snd_kcontrol_new cxt5066_mixers[] = {
  1880. {
  1881. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1882. .name = "Master Playback Switch",
  1883. .info = cxt_eapd_info,
  1884. .get = cxt_eapd_get,
  1885. .put = cxt5066_hp_master_sw_put,
  1886. .private_value = 0x1d,
  1887. },
  1888. {
  1889. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1890. .name = "Analog Mic Boost Capture Enum",
  1891. .info = cxt5066_mic_boost_mux_enum_info,
  1892. .get = cxt5066_mic_boost_mux_enum_get,
  1893. .put = cxt5066_mic_boost_mux_enum_put,
  1894. },
  1895. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  1896. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  1897. {}
  1898. };
  1899. static struct hda_verb cxt5066_init_verbs[] = {
  1900. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  1901. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  1902. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  1903. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  1904. /* Speakers */
  1905. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1906. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1907. /* HP, Amp */
  1908. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1909. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1910. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1911. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1912. /* DAC1 */
  1913. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1914. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  1915. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  1916. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1917. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  1918. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1919. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1920. /* no digital microphone support yet */
  1921. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1922. /* Audio input selector */
  1923. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  1924. /* SPDIF route: PCM */
  1925. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  1926. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  1927. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1928. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1929. /* EAPD */
  1930. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1931. /* not handling these yet */
  1932. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1933. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1934. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1935. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1936. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1937. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1938. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1939. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1940. { } /* end */
  1941. };
  1942. static struct hda_verb cxt5066_init_verbs_olpc[] = {
  1943. /* Port A: headphones */
  1944. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1945. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1946. /* Port B: external microphone */
  1947. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1948. /* Port C: internal microphone */
  1949. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1950. /* Port D: unused */
  1951. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1952. /* Port E: unused, but has primary EAPD */
  1953. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1954. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1955. /* Port F: unused */
  1956. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1957. /* Port G: internal speakers */
  1958. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1959. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1960. /* DAC1 */
  1961. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1962. /* DAC2: unused */
  1963. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1964. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  1965. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1966. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1967. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1968. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1969. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1970. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1971. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1972. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1973. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1974. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1975. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1976. /* Disable digital microphone port */
  1977. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1978. /* Audio input selectors */
  1979. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  1980. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1981. /* Disable SPDIF */
  1982. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1983. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1984. /* enable unsolicited events for Port A and B */
  1985. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1986. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1987. { } /* end */
  1988. };
  1989. static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  1990. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1991. { } /* end */
  1992. };
  1993. /* initialize jack-sensing, too */
  1994. static int cxt5066_init(struct hda_codec *codec)
  1995. {
  1996. snd_printdd("CXT5066: init\n");
  1997. conexant_init(codec);
  1998. if (codec->patch_ops.unsol_event) {
  1999. cxt5066_hp_automute(codec);
  2000. cxt5066_automic(codec);
  2001. }
  2002. return 0;
  2003. }
  2004. enum {
  2005. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2006. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2007. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2008. CXT5066_MODELS
  2009. };
  2010. static const char *cxt5066_models[CXT5066_MODELS] = {
  2011. [CXT5066_LAPTOP] = "laptop",
  2012. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2013. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2014. };
  2015. static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2016. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2017. CXT5066_LAPTOP),
  2018. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
  2019. CXT5066_DELL_LAPTOP),
  2020. {}
  2021. };
  2022. static int patch_cxt5066(struct hda_codec *codec)
  2023. {
  2024. struct conexant_spec *spec;
  2025. int board_config;
  2026. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2027. if (!spec)
  2028. return -ENOMEM;
  2029. codec->spec = spec;
  2030. codec->patch_ops = conexant_patch_ops;
  2031. codec->patch_ops.init = cxt5066_init;
  2032. spec->dell_automute = 0;
  2033. spec->multiout.max_channels = 2;
  2034. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2035. spec->multiout.dac_nids = cxt5066_dac_nids;
  2036. spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
  2037. spec->num_adc_nids = 1;
  2038. spec->adc_nids = cxt5066_adc_nids;
  2039. spec->capsrc_nids = cxt5066_capsrc_nids;
  2040. spec->input_mux = &cxt5066_capture_source;
  2041. spec->port_d_mode = PIN_HP;
  2042. spec->num_init_verbs = 1;
  2043. spec->init_verbs[0] = cxt5066_init_verbs;
  2044. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2045. spec->channel_mode = cxt5066_modes;
  2046. spec->cur_adc = 0;
  2047. spec->cur_adc_idx = 0;
  2048. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2049. cxt5066_models, cxt5066_cfg_tbl);
  2050. switch (board_config) {
  2051. default:
  2052. case CXT5066_LAPTOP:
  2053. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2054. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2055. break;
  2056. case CXT5066_DELL_LAPTOP:
  2057. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2058. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2059. spec->port_d_mode = PIN_OUT;
  2060. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2061. spec->num_init_verbs++;
  2062. spec->dell_automute = 1;
  2063. break;
  2064. case CXT5066_OLPC_XO_1_5:
  2065. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2066. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2067. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2068. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2069. spec->port_d_mode = 0;
  2070. /* no S/PDIF out */
  2071. spec->multiout.dig_out_nid = 0;
  2072. /* input source automatically selected */
  2073. spec->input_mux = NULL;
  2074. break;
  2075. }
  2076. return 0;
  2077. }
  2078. /*
  2079. */
  2080. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  2081. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  2082. .patch = patch_cxt5045 },
  2083. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  2084. .patch = patch_cxt5047 },
  2085. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  2086. .patch = patch_cxt5051 },
  2087. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  2088. .patch = patch_cxt5066 },
  2089. {} /* terminator */
  2090. };
  2091. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  2092. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  2093. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  2094. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  2095. MODULE_LICENSE("GPL");
  2096. MODULE_DESCRIPTION("Conexant HD-audio codec");
  2097. static struct hda_codec_preset_list conexant_list = {
  2098. .preset = snd_hda_preset_conexant,
  2099. .owner = THIS_MODULE,
  2100. };
  2101. static int __init patch_conexant_init(void)
  2102. {
  2103. return snd_hda_add_codec_preset(&conexant_list);
  2104. }
  2105. static void __exit patch_conexant_exit(void)
  2106. {
  2107. snd_hda_delete_codec_preset(&conexant_list);
  2108. }
  2109. module_init(patch_conexant_init)
  2110. module_exit(patch_conexant_exit)