patch_conexant.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590
  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. #include "hda_beep.h"
  31. #define CXT_PIN_DIR_IN 0x00
  32. #define CXT_PIN_DIR_OUT 0x01
  33. #define CXT_PIN_DIR_INOUT 0x02
  34. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  35. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  36. #define CONEXANT_HP_EVENT 0x37
  37. #define CONEXANT_MIC_EVENT 0x38
  38. /* Conexant 5051 specific */
  39. #define CXT5051_SPDIF_OUT 0x1C
  40. #define CXT5051_PORTB_EVENT 0x38
  41. #define CXT5051_PORTC_EVENT 0x39
  42. struct conexant_jack {
  43. hda_nid_t nid;
  44. int type;
  45. struct snd_jack *jack;
  46. };
  47. struct conexant_spec {
  48. struct snd_kcontrol_new *mixers[5];
  49. int num_mixers;
  50. hda_nid_t vmaster_nid;
  51. const struct hda_verb *init_verbs[5]; /* initialization verbs
  52. * don't forget NULL
  53. * termination!
  54. */
  55. unsigned int num_init_verbs;
  56. /* playback */
  57. struct hda_multi_out multiout; /* playback set-up
  58. * max_channels, dacs must be set
  59. * dig_out_nid and hp_nid are optional
  60. */
  61. unsigned int cur_eapd;
  62. unsigned int hp_present;
  63. unsigned int no_auto_mic;
  64. unsigned int need_dac_fix;
  65. /* capture */
  66. unsigned int num_adc_nids;
  67. hda_nid_t *adc_nids;
  68. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  69. unsigned int cur_adc_idx;
  70. hda_nid_t cur_adc;
  71. unsigned int cur_adc_stream_tag;
  72. unsigned int cur_adc_format;
  73. /* capture source */
  74. const struct hda_input_mux *input_mux;
  75. hda_nid_t *capsrc_nids;
  76. unsigned int cur_mux[3];
  77. /* channel model */
  78. const struct hda_channel_mode *channel_mode;
  79. int num_channel_mode;
  80. /* PCM information */
  81. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  82. unsigned int spdif_route;
  83. /* jack detection */
  84. struct snd_array jacks;
  85. /* dynamic controls, init_verbs and input_mux */
  86. struct auto_pin_cfg autocfg;
  87. struct hda_input_mux private_imux;
  88. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  89. unsigned int dell_automute;
  90. unsigned int port_d_mode;
  91. unsigned char ext_mic_bias;
  92. unsigned int dell_vostro;
  93. };
  94. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  95. struct hda_codec *codec,
  96. struct snd_pcm_substream *substream)
  97. {
  98. struct conexant_spec *spec = codec->spec;
  99. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  100. hinfo);
  101. }
  102. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  103. struct hda_codec *codec,
  104. unsigned int stream_tag,
  105. unsigned int format,
  106. struct snd_pcm_substream *substream)
  107. {
  108. struct conexant_spec *spec = codec->spec;
  109. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  110. stream_tag,
  111. format, substream);
  112. }
  113. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  114. struct hda_codec *codec,
  115. struct snd_pcm_substream *substream)
  116. {
  117. struct conexant_spec *spec = codec->spec;
  118. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  119. }
  120. /*
  121. * Digital out
  122. */
  123. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  124. struct hda_codec *codec,
  125. struct snd_pcm_substream *substream)
  126. {
  127. struct conexant_spec *spec = codec->spec;
  128. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  129. }
  130. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  131. struct hda_codec *codec,
  132. struct snd_pcm_substream *substream)
  133. {
  134. struct conexant_spec *spec = codec->spec;
  135. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  136. }
  137. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  138. struct hda_codec *codec,
  139. unsigned int stream_tag,
  140. unsigned int format,
  141. struct snd_pcm_substream *substream)
  142. {
  143. struct conexant_spec *spec = codec->spec;
  144. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  145. stream_tag,
  146. format, substream);
  147. }
  148. /*
  149. * Analog capture
  150. */
  151. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  152. struct hda_codec *codec,
  153. unsigned int stream_tag,
  154. unsigned int format,
  155. struct snd_pcm_substream *substream)
  156. {
  157. struct conexant_spec *spec = codec->spec;
  158. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  159. stream_tag, 0, format);
  160. return 0;
  161. }
  162. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  163. struct hda_codec *codec,
  164. struct snd_pcm_substream *substream)
  165. {
  166. struct conexant_spec *spec = codec->spec;
  167. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  168. return 0;
  169. }
  170. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  171. .substreams = 1,
  172. .channels_min = 2,
  173. .channels_max = 2,
  174. .nid = 0, /* fill later */
  175. .ops = {
  176. .open = conexant_playback_pcm_open,
  177. .prepare = conexant_playback_pcm_prepare,
  178. .cleanup = conexant_playback_pcm_cleanup
  179. },
  180. };
  181. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  182. .substreams = 1,
  183. .channels_min = 2,
  184. .channels_max = 2,
  185. .nid = 0, /* fill later */
  186. .ops = {
  187. .prepare = conexant_capture_pcm_prepare,
  188. .cleanup = conexant_capture_pcm_cleanup
  189. },
  190. };
  191. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  192. .substreams = 1,
  193. .channels_min = 2,
  194. .channels_max = 2,
  195. .nid = 0, /* fill later */
  196. .ops = {
  197. .open = conexant_dig_playback_pcm_open,
  198. .close = conexant_dig_playback_pcm_close,
  199. .prepare = conexant_dig_playback_pcm_prepare
  200. },
  201. };
  202. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  203. .substreams = 1,
  204. .channels_min = 2,
  205. .channels_max = 2,
  206. /* NID is set in alc_build_pcms */
  207. };
  208. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  209. struct hda_codec *codec,
  210. unsigned int stream_tag,
  211. unsigned int format,
  212. struct snd_pcm_substream *substream)
  213. {
  214. struct conexant_spec *spec = codec->spec;
  215. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  216. spec->cur_adc_stream_tag = stream_tag;
  217. spec->cur_adc_format = format;
  218. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  219. return 0;
  220. }
  221. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  222. struct hda_codec *codec,
  223. struct snd_pcm_substream *substream)
  224. {
  225. struct conexant_spec *spec = codec->spec;
  226. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  227. spec->cur_adc = 0;
  228. return 0;
  229. }
  230. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  231. .substreams = 1,
  232. .channels_min = 2,
  233. .channels_max = 2,
  234. .nid = 0, /* fill later */
  235. .ops = {
  236. .prepare = cx5051_capture_pcm_prepare,
  237. .cleanup = cx5051_capture_pcm_cleanup
  238. },
  239. };
  240. static int conexant_build_pcms(struct hda_codec *codec)
  241. {
  242. struct conexant_spec *spec = codec->spec;
  243. struct hda_pcm *info = spec->pcm_rec;
  244. codec->num_pcms = 1;
  245. codec->pcm_info = info;
  246. info->name = "CONEXANT Analog";
  247. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  248. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  249. spec->multiout.max_channels;
  250. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  251. spec->multiout.dac_nids[0];
  252. if (codec->vendor_id == 0x14f15051)
  253. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  254. cx5051_pcm_analog_capture;
  255. else
  256. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  257. conexant_pcm_analog_capture;
  258. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  259. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  260. if (spec->multiout.dig_out_nid) {
  261. info++;
  262. codec->num_pcms++;
  263. info->name = "Conexant Digital";
  264. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  265. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  266. conexant_pcm_digital_playback;
  267. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  268. spec->multiout.dig_out_nid;
  269. if (spec->dig_in_nid) {
  270. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  271. conexant_pcm_digital_capture;
  272. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  273. spec->dig_in_nid;
  274. }
  275. }
  276. return 0;
  277. }
  278. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  279. struct snd_ctl_elem_info *uinfo)
  280. {
  281. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  282. struct conexant_spec *spec = codec->spec;
  283. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  284. }
  285. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  286. struct snd_ctl_elem_value *ucontrol)
  287. {
  288. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  289. struct conexant_spec *spec = codec->spec;
  290. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  291. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  292. return 0;
  293. }
  294. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_value *ucontrol)
  296. {
  297. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  298. struct conexant_spec *spec = codec->spec;
  299. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  300. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  301. spec->capsrc_nids[adc_idx],
  302. &spec->cur_mux[adc_idx]);
  303. }
  304. #ifdef CONFIG_SND_HDA_INPUT_JACK
  305. static void conexant_free_jack_priv(struct snd_jack *jack)
  306. {
  307. struct conexant_jack *jacks = jack->private_data;
  308. jacks->nid = 0;
  309. jacks->jack = NULL;
  310. }
  311. static int conexant_add_jack(struct hda_codec *codec,
  312. hda_nid_t nid, int type)
  313. {
  314. struct conexant_spec *spec;
  315. struct conexant_jack *jack;
  316. const char *name;
  317. int err;
  318. spec = codec->spec;
  319. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  320. jack = snd_array_new(&spec->jacks);
  321. name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
  322. if (!jack)
  323. return -ENOMEM;
  324. jack->nid = nid;
  325. jack->type = type;
  326. err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
  327. if (err < 0)
  328. return err;
  329. jack->jack->private_data = jack;
  330. jack->jack->private_free = conexant_free_jack_priv;
  331. return 0;
  332. }
  333. static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  334. {
  335. struct conexant_spec *spec = codec->spec;
  336. struct conexant_jack *jacks = spec->jacks.list;
  337. if (jacks) {
  338. int i;
  339. for (i = 0; i < spec->jacks.used; i++) {
  340. if (jacks->nid == nid) {
  341. unsigned int present;
  342. present = snd_hda_jack_detect(codec, nid);
  343. present = (present) ? jacks->type : 0 ;
  344. snd_jack_report(jacks->jack,
  345. present);
  346. }
  347. jacks++;
  348. }
  349. }
  350. }
  351. static int conexant_init_jacks(struct hda_codec *codec)
  352. {
  353. struct conexant_spec *spec = codec->spec;
  354. int i;
  355. for (i = 0; i < spec->num_init_verbs; i++) {
  356. const struct hda_verb *hv;
  357. hv = spec->init_verbs[i];
  358. while (hv->nid) {
  359. int err = 0;
  360. switch (hv->param ^ AC_USRSP_EN) {
  361. case CONEXANT_HP_EVENT:
  362. err = conexant_add_jack(codec, hv->nid,
  363. SND_JACK_HEADPHONE);
  364. conexant_report_jack(codec, hv->nid);
  365. break;
  366. case CXT5051_PORTC_EVENT:
  367. case CONEXANT_MIC_EVENT:
  368. err = conexant_add_jack(codec, hv->nid,
  369. SND_JACK_MICROPHONE);
  370. conexant_report_jack(codec, hv->nid);
  371. break;
  372. }
  373. if (err < 0)
  374. return err;
  375. ++hv;
  376. }
  377. }
  378. return 0;
  379. }
  380. #else
  381. static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  382. {
  383. }
  384. static inline int conexant_init_jacks(struct hda_codec *codec)
  385. {
  386. return 0;
  387. }
  388. #endif
  389. static int conexant_init(struct hda_codec *codec)
  390. {
  391. struct conexant_spec *spec = codec->spec;
  392. int i;
  393. for (i = 0; i < spec->num_init_verbs; i++)
  394. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  395. return 0;
  396. }
  397. static void conexant_free(struct hda_codec *codec)
  398. {
  399. #ifdef CONFIG_SND_HDA_INPUT_JACK
  400. struct conexant_spec *spec = codec->spec;
  401. if (spec->jacks.list) {
  402. struct conexant_jack *jacks = spec->jacks.list;
  403. int i;
  404. for (i = 0; i < spec->jacks.used; i++, jacks++) {
  405. if (jacks->jack)
  406. snd_device_free(codec->bus->card, jacks->jack);
  407. }
  408. snd_array_free(&spec->jacks);
  409. }
  410. #endif
  411. snd_hda_detach_beep_device(codec);
  412. kfree(codec->spec);
  413. }
  414. static struct snd_kcontrol_new cxt_capture_mixers[] = {
  415. {
  416. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  417. .name = "Capture Source",
  418. .info = conexant_mux_enum_info,
  419. .get = conexant_mux_enum_get,
  420. .put = conexant_mux_enum_put
  421. },
  422. {}
  423. };
  424. static const char *slave_vols[] = {
  425. "Headphone Playback Volume",
  426. "Speaker Playback Volume",
  427. NULL
  428. };
  429. static const char *slave_sws[] = {
  430. "Headphone Playback Switch",
  431. "Speaker Playback Switch",
  432. NULL
  433. };
  434. static int conexant_build_controls(struct hda_codec *codec)
  435. {
  436. struct conexant_spec *spec = codec->spec;
  437. unsigned int i;
  438. int err;
  439. for (i = 0; i < spec->num_mixers; i++) {
  440. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  441. if (err < 0)
  442. return err;
  443. }
  444. if (spec->multiout.dig_out_nid) {
  445. err = snd_hda_create_spdif_out_ctls(codec,
  446. spec->multiout.dig_out_nid);
  447. if (err < 0)
  448. return err;
  449. err = snd_hda_create_spdif_share_sw(codec,
  450. &spec->multiout);
  451. if (err < 0)
  452. return err;
  453. spec->multiout.share_spdif = 1;
  454. }
  455. if (spec->dig_in_nid) {
  456. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  457. if (err < 0)
  458. return err;
  459. }
  460. /* if we have no master control, let's create it */
  461. if (spec->vmaster_nid &&
  462. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  463. unsigned int vmaster_tlv[4];
  464. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  465. HDA_OUTPUT, vmaster_tlv);
  466. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  467. vmaster_tlv, slave_vols);
  468. if (err < 0)
  469. return err;
  470. }
  471. if (spec->vmaster_nid &&
  472. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  473. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  474. NULL, slave_sws);
  475. if (err < 0)
  476. return err;
  477. }
  478. if (spec->input_mux) {
  479. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  480. if (err < 0)
  481. return err;
  482. }
  483. return 0;
  484. }
  485. static struct hda_codec_ops conexant_patch_ops = {
  486. .build_controls = conexant_build_controls,
  487. .build_pcms = conexant_build_pcms,
  488. .init = conexant_init,
  489. .free = conexant_free,
  490. };
  491. /*
  492. * EAPD control
  493. * the private value = nid | (invert << 8)
  494. */
  495. #define cxt_eapd_info snd_ctl_boolean_mono_info
  496. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  497. struct snd_ctl_elem_value *ucontrol)
  498. {
  499. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  500. struct conexant_spec *spec = codec->spec;
  501. int invert = (kcontrol->private_value >> 8) & 1;
  502. if (invert)
  503. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  504. else
  505. ucontrol->value.integer.value[0] = spec->cur_eapd;
  506. return 0;
  507. }
  508. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  509. struct snd_ctl_elem_value *ucontrol)
  510. {
  511. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  512. struct conexant_spec *spec = codec->spec;
  513. int invert = (kcontrol->private_value >> 8) & 1;
  514. hda_nid_t nid = kcontrol->private_value & 0xff;
  515. unsigned int eapd;
  516. eapd = !!ucontrol->value.integer.value[0];
  517. if (invert)
  518. eapd = !eapd;
  519. if (eapd == spec->cur_eapd)
  520. return 0;
  521. spec->cur_eapd = eapd;
  522. snd_hda_codec_write_cache(codec, nid,
  523. 0, AC_VERB_SET_EAPD_BTLENABLE,
  524. eapd ? 0x02 : 0x00);
  525. return 1;
  526. }
  527. /* controls for test mode */
  528. #ifdef CONFIG_SND_DEBUG
  529. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  530. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  531. .info = cxt_eapd_info, \
  532. .get = cxt_eapd_get, \
  533. .put = cxt_eapd_put, \
  534. .private_value = nid | (mask<<16) }
  535. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  536. struct snd_ctl_elem_info *uinfo)
  537. {
  538. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  539. struct conexant_spec *spec = codec->spec;
  540. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  541. spec->num_channel_mode);
  542. }
  543. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  544. struct snd_ctl_elem_value *ucontrol)
  545. {
  546. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  547. struct conexant_spec *spec = codec->spec;
  548. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  549. spec->num_channel_mode,
  550. spec->multiout.max_channels);
  551. }
  552. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  553. struct snd_ctl_elem_value *ucontrol)
  554. {
  555. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  556. struct conexant_spec *spec = codec->spec;
  557. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  558. spec->num_channel_mode,
  559. &spec->multiout.max_channels);
  560. if (err >= 0 && spec->need_dac_fix)
  561. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  562. return err;
  563. }
  564. #define CXT_PIN_MODE(xname, nid, dir) \
  565. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  566. .info = conexant_ch_mode_info, \
  567. .get = conexant_ch_mode_get, \
  568. .put = conexant_ch_mode_put, \
  569. .private_value = nid | (dir<<16) }
  570. #endif /* CONFIG_SND_DEBUG */
  571. /* Conexant 5045 specific */
  572. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  573. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  574. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  575. #define CXT5045_SPDIF_OUT 0x18
  576. static struct hda_channel_mode cxt5045_modes[1] = {
  577. { 2, NULL },
  578. };
  579. static struct hda_input_mux cxt5045_capture_source = {
  580. .num_items = 2,
  581. .items = {
  582. { "IntMic", 0x1 },
  583. { "ExtMic", 0x2 },
  584. }
  585. };
  586. static struct hda_input_mux cxt5045_capture_source_benq = {
  587. .num_items = 5,
  588. .items = {
  589. { "IntMic", 0x1 },
  590. { "ExtMic", 0x2 },
  591. { "LineIn", 0x3 },
  592. { "CD", 0x4 },
  593. { "Mixer", 0x0 },
  594. }
  595. };
  596. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  597. .num_items = 2,
  598. .items = {
  599. { "ExtMic", 0x1 },
  600. { "IntMic", 0x2 },
  601. }
  602. };
  603. /* turn on/off EAPD (+ mute HP) as a master switch */
  604. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  605. struct snd_ctl_elem_value *ucontrol)
  606. {
  607. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  608. struct conexant_spec *spec = codec->spec;
  609. unsigned int bits;
  610. if (!cxt_eapd_put(kcontrol, ucontrol))
  611. return 0;
  612. /* toggle internal speakers mute depending of presence of
  613. * the headphone jack
  614. */
  615. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  616. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  617. HDA_AMP_MUTE, bits);
  618. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  619. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  620. HDA_AMP_MUTE, bits);
  621. return 1;
  622. }
  623. /* bind volumes of both NID 0x10 and 0x11 */
  624. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  625. .ops = &snd_hda_bind_vol,
  626. .values = {
  627. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  628. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  629. 0
  630. },
  631. };
  632. /* toggle input of built-in and mic jack appropriately */
  633. static void cxt5045_hp_automic(struct hda_codec *codec)
  634. {
  635. static struct hda_verb mic_jack_on[] = {
  636. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  637. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  638. {}
  639. };
  640. static struct hda_verb mic_jack_off[] = {
  641. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  642. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  643. {}
  644. };
  645. unsigned int present;
  646. present = snd_hda_jack_detect(codec, 0x12);
  647. if (present)
  648. snd_hda_sequence_write(codec, mic_jack_on);
  649. else
  650. snd_hda_sequence_write(codec, mic_jack_off);
  651. }
  652. /* mute internal speaker if HP is plugged */
  653. static void cxt5045_hp_automute(struct hda_codec *codec)
  654. {
  655. struct conexant_spec *spec = codec->spec;
  656. unsigned int bits;
  657. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  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. case 0x1734:
  1023. /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
  1024. * on NID 0x17. Fix max PCM level to 0 dB
  1025. * (originally it has 0x2b steps with 0dB offset 0x14)
  1026. */
  1027. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1028. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1029. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1030. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1031. (1 << AC_AMPCAP_MUTE_SHIFT));
  1032. break;
  1033. }
  1034. return 0;
  1035. }
  1036. /* Conexant 5047 specific */
  1037. #define CXT5047_SPDIF_OUT 0x11
  1038. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1039. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1040. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1041. static struct hda_channel_mode cxt5047_modes[1] = {
  1042. { 2, NULL },
  1043. };
  1044. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  1045. .num_items = 2,
  1046. .items = {
  1047. { "ExtMic", 0x2 },
  1048. { "Line-In", 0x1 },
  1049. }
  1050. };
  1051. /* turn on/off EAPD (+ mute HP) as a master switch */
  1052. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1053. struct snd_ctl_elem_value *ucontrol)
  1054. {
  1055. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1056. struct conexant_spec *spec = codec->spec;
  1057. unsigned int bits;
  1058. if (!cxt_eapd_put(kcontrol, ucontrol))
  1059. return 0;
  1060. /* toggle internal speakers mute depending of presence of
  1061. * the headphone jack
  1062. */
  1063. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1064. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1065. * pin widgets unlike other codecs. In this case, we need to
  1066. * set index 0x01 for the volume from the mixer amp 0x19.
  1067. */
  1068. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1069. HDA_AMP_MUTE, bits);
  1070. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1071. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1072. HDA_AMP_MUTE, bits);
  1073. return 1;
  1074. }
  1075. /* mute internal speaker if HP is plugged */
  1076. static void cxt5047_hp_automute(struct hda_codec *codec)
  1077. {
  1078. struct conexant_spec *spec = codec->spec;
  1079. unsigned int bits;
  1080. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  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_jack_detect(codec, 0x15);
  1101. if (present)
  1102. snd_hda_sequence_write(codec, mic_jack_on);
  1103. else
  1104. snd_hda_sequence_write(codec, mic_jack_off);
  1105. }
  1106. /* unsolicited event for HP jack sensing */
  1107. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1108. unsigned int res)
  1109. {
  1110. switch (res >> 26) {
  1111. case CONEXANT_HP_EVENT:
  1112. cxt5047_hp_automute(codec);
  1113. break;
  1114. case CONEXANT_MIC_EVENT:
  1115. cxt5047_hp_automic(codec);
  1116. break;
  1117. }
  1118. }
  1119. static struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1120. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1121. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1122. HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
  1123. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1124. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1125. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1126. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1127. {
  1128. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1129. .name = "Master Playback Switch",
  1130. .info = cxt_eapd_info,
  1131. .get = cxt_eapd_get,
  1132. .put = cxt5047_hp_master_sw_put,
  1133. .private_value = 0x13,
  1134. },
  1135. {}
  1136. };
  1137. static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1138. /* See the note in cxt5047_hp_master_sw_put */
  1139. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1140. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1141. {}
  1142. };
  1143. static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1144. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1145. { } /* end */
  1146. };
  1147. static struct hda_verb cxt5047_init_verbs[] = {
  1148. /* Line in, Mic, Built-in Mic */
  1149. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1150. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1151. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1152. /* HP, Speaker */
  1153. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1154. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1155. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1156. /* Record selector: Mic */
  1157. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1158. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1159. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1160. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1161. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1162. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1163. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1164. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1165. /* SPDIF route: PCM */
  1166. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1167. /* Enable unsolicited events */
  1168. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1169. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1170. { } /* end */
  1171. };
  1172. /* configuration for Toshiba Laptops */
  1173. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1174. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1175. {}
  1176. };
  1177. /* Test configuration for debugging, modelled after the ALC260 test
  1178. * configuration.
  1179. */
  1180. #ifdef CONFIG_SND_DEBUG
  1181. static struct hda_input_mux cxt5047_test_capture_source = {
  1182. .num_items = 4,
  1183. .items = {
  1184. { "LINE1 pin", 0x0 },
  1185. { "MIC1 pin", 0x1 },
  1186. { "MIC2 pin", 0x2 },
  1187. { "CD pin", 0x3 },
  1188. },
  1189. };
  1190. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1191. /* Output only controls */
  1192. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1193. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1194. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1195. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1196. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1197. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1198. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1199. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1200. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1201. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1202. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1203. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1204. /* Modes for retasking pin widgets */
  1205. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1206. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1207. /* EAPD Switch Control */
  1208. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1209. /* Loopback mixer controls */
  1210. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1211. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1212. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1213. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1214. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1215. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1216. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1217. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1218. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1219. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1220. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1221. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1222. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1223. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1224. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1225. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1226. {
  1227. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1228. .name = "Input Source",
  1229. .info = conexant_mux_enum_info,
  1230. .get = conexant_mux_enum_get,
  1231. .put = conexant_mux_enum_put,
  1232. },
  1233. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1234. { } /* end */
  1235. };
  1236. static struct hda_verb cxt5047_test_init_verbs[] = {
  1237. /* Enable retasking pins as output, initially without power amp */
  1238. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1239. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1240. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1241. /* Disable digital (SPDIF) pins initially, but users can enable
  1242. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1243. * payload also sets the generation to 0, output to be in "consumer"
  1244. * PCM format, copyright asserted, no pre-emphasis and no validity
  1245. * control.
  1246. */
  1247. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1248. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1249. * OUT1 sum bus when acting as an output.
  1250. */
  1251. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1252. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1253. /* Start with output sum widgets muted and their output gains at min */
  1254. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1255. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1256. /* Unmute retasking pin widget output buffers since the default
  1257. * state appears to be output. As the pin mode is changed by the
  1258. * user the pin mode control will take care of enabling the pin's
  1259. * input/output buffers as needed.
  1260. */
  1261. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1262. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1263. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1264. /* Mute capture amp left and right */
  1265. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1266. /* Set ADC connection select to match default mixer setting (mic1
  1267. * pin)
  1268. */
  1269. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1270. /* Mute all inputs to mixer widget (even unconnected ones) */
  1271. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1272. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1273. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1274. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1275. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1276. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1277. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1278. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1279. { }
  1280. };
  1281. #endif
  1282. /* initialize jack-sensing, too */
  1283. static int cxt5047_hp_init(struct hda_codec *codec)
  1284. {
  1285. conexant_init(codec);
  1286. cxt5047_hp_automute(codec);
  1287. return 0;
  1288. }
  1289. enum {
  1290. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1291. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1292. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1293. #ifdef CONFIG_SND_DEBUG
  1294. CXT5047_TEST,
  1295. #endif
  1296. CXT5047_MODELS
  1297. };
  1298. static const char *cxt5047_models[CXT5047_MODELS] = {
  1299. [CXT5047_LAPTOP] = "laptop",
  1300. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1301. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1302. #ifdef CONFIG_SND_DEBUG
  1303. [CXT5047_TEST] = "test",
  1304. #endif
  1305. };
  1306. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1307. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1308. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1309. CXT5047_LAPTOP),
  1310. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1311. {}
  1312. };
  1313. static int patch_cxt5047(struct hda_codec *codec)
  1314. {
  1315. struct conexant_spec *spec;
  1316. int board_config;
  1317. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1318. if (!spec)
  1319. return -ENOMEM;
  1320. codec->spec = spec;
  1321. codec->pin_amp_workaround = 1;
  1322. spec->multiout.max_channels = 2;
  1323. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1324. spec->multiout.dac_nids = cxt5047_dac_nids;
  1325. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1326. spec->num_adc_nids = 1;
  1327. spec->adc_nids = cxt5047_adc_nids;
  1328. spec->capsrc_nids = cxt5047_capsrc_nids;
  1329. spec->num_mixers = 1;
  1330. spec->mixers[0] = cxt5047_base_mixers;
  1331. spec->num_init_verbs = 1;
  1332. spec->init_verbs[0] = cxt5047_init_verbs;
  1333. spec->spdif_route = 0;
  1334. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1335. spec->channel_mode = cxt5047_modes,
  1336. codec->patch_ops = conexant_patch_ops;
  1337. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1338. cxt5047_models,
  1339. cxt5047_cfg_tbl);
  1340. switch (board_config) {
  1341. case CXT5047_LAPTOP:
  1342. spec->num_mixers = 2;
  1343. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1344. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1345. break;
  1346. case CXT5047_LAPTOP_HP:
  1347. spec->num_mixers = 2;
  1348. spec->mixers[1] = cxt5047_hp_only_mixers;
  1349. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1350. codec->patch_ops.init = cxt5047_hp_init;
  1351. break;
  1352. case CXT5047_LAPTOP_EAPD:
  1353. spec->input_mux = &cxt5047_toshiba_capture_source;
  1354. spec->num_mixers = 2;
  1355. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1356. spec->num_init_verbs = 2;
  1357. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1358. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1359. break;
  1360. #ifdef CONFIG_SND_DEBUG
  1361. case CXT5047_TEST:
  1362. spec->input_mux = &cxt5047_test_capture_source;
  1363. spec->mixers[0] = cxt5047_test_mixer;
  1364. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1365. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1366. #endif
  1367. }
  1368. spec->vmaster_nid = 0x13;
  1369. return 0;
  1370. }
  1371. /* Conexant 5051 specific */
  1372. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1373. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1374. static struct hda_channel_mode cxt5051_modes[1] = {
  1375. { 2, NULL },
  1376. };
  1377. static void cxt5051_update_speaker(struct hda_codec *codec)
  1378. {
  1379. struct conexant_spec *spec = codec->spec;
  1380. unsigned int pinctl;
  1381. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1382. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1383. pinctl);
  1384. }
  1385. /* turn on/off EAPD (+ mute HP) as a master switch */
  1386. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1387. struct snd_ctl_elem_value *ucontrol)
  1388. {
  1389. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1390. if (!cxt_eapd_put(kcontrol, ucontrol))
  1391. return 0;
  1392. cxt5051_update_speaker(codec);
  1393. return 1;
  1394. }
  1395. /* toggle input of built-in and mic jack appropriately */
  1396. static void cxt5051_portb_automic(struct hda_codec *codec)
  1397. {
  1398. struct conexant_spec *spec = codec->spec;
  1399. unsigned int present;
  1400. if (spec->no_auto_mic)
  1401. return;
  1402. present = snd_hda_jack_detect(codec, 0x17);
  1403. snd_hda_codec_write(codec, 0x14, 0,
  1404. AC_VERB_SET_CONNECT_SEL,
  1405. present ? 0x01 : 0x00);
  1406. }
  1407. /* switch the current ADC according to the jack state */
  1408. static void cxt5051_portc_automic(struct hda_codec *codec)
  1409. {
  1410. struct conexant_spec *spec = codec->spec;
  1411. unsigned int present;
  1412. hda_nid_t new_adc;
  1413. if (spec->no_auto_mic)
  1414. return;
  1415. present = snd_hda_jack_detect(codec, 0x18);
  1416. if (present)
  1417. spec->cur_adc_idx = 1;
  1418. else
  1419. spec->cur_adc_idx = 0;
  1420. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1421. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1422. /* stream is running, let's swap the current ADC */
  1423. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1424. spec->cur_adc = new_adc;
  1425. snd_hda_codec_setup_stream(codec, new_adc,
  1426. spec->cur_adc_stream_tag, 0,
  1427. spec->cur_adc_format);
  1428. }
  1429. }
  1430. /* mute internal speaker if HP is plugged */
  1431. static void cxt5051_hp_automute(struct hda_codec *codec)
  1432. {
  1433. struct conexant_spec *spec = codec->spec;
  1434. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1435. cxt5051_update_speaker(codec);
  1436. }
  1437. /* unsolicited event for HP jack sensing */
  1438. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1439. unsigned int res)
  1440. {
  1441. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1442. switch (res >> 26) {
  1443. case CONEXANT_HP_EVENT:
  1444. cxt5051_hp_automute(codec);
  1445. break;
  1446. case CXT5051_PORTB_EVENT:
  1447. cxt5051_portb_automic(codec);
  1448. break;
  1449. case CXT5051_PORTC_EVENT:
  1450. cxt5051_portc_automic(codec);
  1451. break;
  1452. }
  1453. conexant_report_jack(codec, nid);
  1454. }
  1455. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1456. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1457. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1458. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1459. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1460. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1461. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1462. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1463. {
  1464. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1465. .name = "Master Playback Switch",
  1466. .info = cxt_eapd_info,
  1467. .get = cxt_eapd_get,
  1468. .put = cxt5051_hp_master_sw_put,
  1469. .private_value = 0x1a,
  1470. },
  1471. {}
  1472. };
  1473. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1474. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1475. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1476. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1477. HDA_CODEC_MUTE("External 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_dv6736_mixers[] = {
  1490. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
  1491. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
  1492. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1493. {
  1494. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1495. .name = "Master Playback Switch",
  1496. .info = cxt_eapd_info,
  1497. .get = cxt_eapd_get,
  1498. .put = cxt5051_hp_master_sw_put,
  1499. .private_value = 0x1a,
  1500. },
  1501. {}
  1502. };
  1503. static struct hda_verb cxt5051_init_verbs[] = {
  1504. /* Line in, Mic */
  1505. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1506. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1507. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1508. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1509. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1510. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1511. /* SPK */
  1512. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1513. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1514. /* HP, Amp */
  1515. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1516. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1517. /* DAC1 */
  1518. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1519. /* Record selector: Int mic */
  1520. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1521. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1522. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1523. /* SPDIF route: PCM */
  1524. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1525. /* EAPD */
  1526. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1527. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1528. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1529. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1530. { } /* end */
  1531. };
  1532. static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1533. /* Line in, Mic */
  1534. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1535. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1536. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1537. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1538. /* SPK */
  1539. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1540. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1541. /* HP, Amp */
  1542. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1543. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1544. /* DAC1 */
  1545. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1546. /* Record selector: Int mic */
  1547. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1548. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1549. /* SPDIF route: PCM */
  1550. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1551. /* EAPD */
  1552. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1553. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1554. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1555. { } /* end */
  1556. };
  1557. static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1558. /* Line in, Mic */
  1559. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1560. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1561. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1562. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1563. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1564. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1565. /* SPK */
  1566. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1567. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1568. /* HP, Amp */
  1569. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1570. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1571. /* Docking HP */
  1572. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1573. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1574. /* DAC1 */
  1575. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1576. /* Record selector: Int mic */
  1577. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1578. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1579. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1580. /* SPDIF route: PCM */
  1581. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1582. /* EAPD */
  1583. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1584. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1585. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1586. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1587. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1588. { } /* end */
  1589. };
  1590. /* initialize jack-sensing, too */
  1591. static int cxt5051_init(struct hda_codec *codec)
  1592. {
  1593. conexant_init(codec);
  1594. conexant_init_jacks(codec);
  1595. if (codec->patch_ops.unsol_event) {
  1596. cxt5051_hp_automute(codec);
  1597. cxt5051_portb_automic(codec);
  1598. cxt5051_portc_automic(codec);
  1599. }
  1600. return 0;
  1601. }
  1602. enum {
  1603. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1604. CXT5051_HP, /* no docking */
  1605. CXT5051_HP_DV6736, /* HP without mic switch */
  1606. CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
  1607. CXT5051_MODELS
  1608. };
  1609. static const char *cxt5051_models[CXT5051_MODELS] = {
  1610. [CXT5051_LAPTOP] = "laptop",
  1611. [CXT5051_HP] = "hp",
  1612. [CXT5051_HP_DV6736] = "hp-dv6736",
  1613. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1614. };
  1615. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1616. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1617. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1618. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1619. CXT5051_LAPTOP),
  1620. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1621. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1622. {}
  1623. };
  1624. static int patch_cxt5051(struct hda_codec *codec)
  1625. {
  1626. struct conexant_spec *spec;
  1627. int board_config;
  1628. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1629. if (!spec)
  1630. return -ENOMEM;
  1631. codec->spec = spec;
  1632. codec->pin_amp_workaround = 1;
  1633. codec->patch_ops = conexant_patch_ops;
  1634. codec->patch_ops.init = cxt5051_init;
  1635. spec->multiout.max_channels = 2;
  1636. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1637. spec->multiout.dac_nids = cxt5051_dac_nids;
  1638. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1639. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1640. spec->adc_nids = cxt5051_adc_nids;
  1641. spec->num_mixers = 1;
  1642. spec->mixers[0] = cxt5051_mixers;
  1643. spec->num_init_verbs = 1;
  1644. spec->init_verbs[0] = cxt5051_init_verbs;
  1645. spec->spdif_route = 0;
  1646. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1647. spec->channel_mode = cxt5051_modes;
  1648. spec->cur_adc = 0;
  1649. spec->cur_adc_idx = 0;
  1650. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1651. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1652. cxt5051_models,
  1653. cxt5051_cfg_tbl);
  1654. switch (board_config) {
  1655. case CXT5051_HP:
  1656. spec->mixers[0] = cxt5051_hp_mixers;
  1657. break;
  1658. case CXT5051_HP_DV6736:
  1659. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1660. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1661. spec->no_auto_mic = 1;
  1662. break;
  1663. case CXT5051_LENOVO_X200:
  1664. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1665. break;
  1666. }
  1667. return 0;
  1668. }
  1669. /* Conexant 5066 specific */
  1670. static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1671. static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1672. static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1673. #define CXT5066_SPDIF_OUT 0x21
  1674. /* OLPC's microphone port is DC coupled for use with external sensors,
  1675. * therefore we use a 50% mic bias in order to center the input signal with
  1676. * the DC input range of the codec. */
  1677. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1678. static struct hda_channel_mode cxt5066_modes[1] = {
  1679. { 2, NULL },
  1680. };
  1681. static void cxt5066_update_speaker(struct hda_codec *codec)
  1682. {
  1683. struct conexant_spec *spec = codec->spec;
  1684. unsigned int pinctl;
  1685. snd_printdd("CXT5066: update speaker, hp_present=%d\n",
  1686. spec->hp_present);
  1687. /* Port A (HP) */
  1688. pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
  1689. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1690. pinctl);
  1691. /* Port D (HP/LO) */
  1692. pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
  1693. ? spec->port_d_mode : 0;
  1694. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1695. pinctl);
  1696. /* CLASS_D AMP */
  1697. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1698. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1699. pinctl);
  1700. if (spec->dell_automute) {
  1701. /* DELL AIO Port Rule: PortA > PortD > IntSpk */
  1702. pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
  1703. ? PIN_OUT : 0;
  1704. snd_hda_codec_write(codec, 0x1c, 0,
  1705. AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
  1706. }
  1707. }
  1708. /* turn on/off EAPD (+ mute HP) as a master switch */
  1709. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1710. struct snd_ctl_elem_value *ucontrol)
  1711. {
  1712. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1713. if (!cxt_eapd_put(kcontrol, ucontrol))
  1714. return 0;
  1715. cxt5066_update_speaker(codec);
  1716. return 1;
  1717. }
  1718. /* toggle input of built-in and mic jack appropriately */
  1719. static void cxt5066_automic(struct hda_codec *codec)
  1720. {
  1721. struct conexant_spec *spec = codec->spec;
  1722. struct hda_verb ext_mic_present[] = {
  1723. /* enable external mic, port B */
  1724. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
  1725. /* switch to external mic input */
  1726. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1727. /* disable internal mic, port C */
  1728. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1729. {}
  1730. };
  1731. static struct hda_verb ext_mic_absent[] = {
  1732. /* enable internal mic, port C */
  1733. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1734. /* switch to internal mic input */
  1735. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1736. /* disable external mic, port B */
  1737. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1738. {}
  1739. };
  1740. unsigned int present;
  1741. present = snd_hda_jack_detect(codec, 0x1a);
  1742. if (present) {
  1743. snd_printdd("CXT5066: external microphone detected\n");
  1744. snd_hda_sequence_write(codec, ext_mic_present);
  1745. } else {
  1746. snd_printdd("CXT5066: external microphone absent\n");
  1747. snd_hda_sequence_write(codec, ext_mic_absent);
  1748. }
  1749. }
  1750. /* toggle input of built-in digital mic and mic jack appropriately */
  1751. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1752. {
  1753. struct conexant_spec *spec = codec->spec;
  1754. unsigned int present;
  1755. struct hda_verb ext_mic_present[] = {
  1756. /* enable external mic, port B */
  1757. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
  1758. /* switch to external mic input */
  1759. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1760. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1761. /* disable internal digital mic */
  1762. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1763. {}
  1764. };
  1765. static struct hda_verb ext_mic_absent[] = {
  1766. /* enable internal mic, port C */
  1767. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1768. /* switch to internal mic input */
  1769. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1770. /* disable external mic, port B */
  1771. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1772. {}
  1773. };
  1774. present = snd_hda_jack_detect(codec, 0x1a);
  1775. if (present) {
  1776. snd_printdd("CXT5066: external microphone detected\n");
  1777. snd_hda_sequence_write(codec, ext_mic_present);
  1778. } else {
  1779. snd_printdd("CXT5066: external microphone absent\n");
  1780. snd_hda_sequence_write(codec, ext_mic_absent);
  1781. }
  1782. }
  1783. /* mute internal speaker if HP is plugged */
  1784. static void cxt5066_hp_automute(struct hda_codec *codec)
  1785. {
  1786. struct conexant_spec *spec = codec->spec;
  1787. unsigned int portA, portD;
  1788. /* Port A */
  1789. portA = snd_hda_jack_detect(codec, 0x19);
  1790. /* Port D */
  1791. portD = snd_hda_jack_detect(codec, 0x1c);
  1792. spec->hp_present = !!(portA | portD);
  1793. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1794. portA, portD, spec->hp_present);
  1795. cxt5066_update_speaker(codec);
  1796. }
  1797. /* unsolicited event for jack sensing */
  1798. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  1799. {
  1800. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1801. switch (res >> 26) {
  1802. case CONEXANT_HP_EVENT:
  1803. cxt5066_hp_automute(codec);
  1804. break;
  1805. case CONEXANT_MIC_EVENT:
  1806. cxt5066_automic(codec);
  1807. break;
  1808. }
  1809. }
  1810. /* unsolicited event for jack sensing */
  1811. static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
  1812. {
  1813. snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
  1814. switch (res >> 26) {
  1815. case CONEXANT_HP_EVENT:
  1816. cxt5066_hp_automute(codec);
  1817. break;
  1818. case CONEXANT_MIC_EVENT:
  1819. cxt5066_vostro_automic(codec);
  1820. break;
  1821. }
  1822. }
  1823. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  1824. .num_items = 5,
  1825. .items = {
  1826. { "0dB", 0 },
  1827. { "10dB", 1 },
  1828. { "20dB", 2 },
  1829. { "30dB", 3 },
  1830. { "40dB", 4 },
  1831. },
  1832. };
  1833. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  1834. struct snd_ctl_elem_info *uinfo)
  1835. {
  1836. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  1837. }
  1838. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  1839. struct snd_ctl_elem_value *ucontrol)
  1840. {
  1841. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1842. int val;
  1843. hda_nid_t nid = kcontrol->private_value & 0xff;
  1844. int inout = (kcontrol->private_value & 0x100) ?
  1845. AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
  1846. val = snd_hda_codec_read(codec, nid, 0,
  1847. AC_VERB_GET_AMP_GAIN_MUTE, inout);
  1848. ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
  1849. return 0;
  1850. }
  1851. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  1852. struct snd_ctl_elem_value *ucontrol)
  1853. {
  1854. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1855. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  1856. unsigned int idx;
  1857. hda_nid_t nid = kcontrol->private_value & 0xff;
  1858. int inout = (kcontrol->private_value & 0x100) ?
  1859. AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
  1860. if (!imux->num_items)
  1861. return 0;
  1862. idx = ucontrol->value.enumerated.item[0];
  1863. if (idx >= imux->num_items)
  1864. idx = imux->num_items - 1;
  1865. snd_hda_codec_write_cache(codec, nid, 0,
  1866. AC_VERB_SET_AMP_GAIN_MUTE,
  1867. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
  1868. imux->items[idx].index);
  1869. return 1;
  1870. }
  1871. static struct hda_input_mux cxt5066_capture_source = {
  1872. .num_items = 4,
  1873. .items = {
  1874. { "Mic B", 0 },
  1875. { "Mic C", 1 },
  1876. { "Mic E", 2 },
  1877. { "Mic F", 3 },
  1878. },
  1879. };
  1880. static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  1881. .ops = &snd_hda_bind_vol,
  1882. .values = {
  1883. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1884. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1885. 0
  1886. },
  1887. };
  1888. static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  1889. .ops = &snd_hda_bind_sw,
  1890. .values = {
  1891. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1892. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1893. 0
  1894. },
  1895. };
  1896. static struct snd_kcontrol_new cxt5066_mixer_master[] = {
  1897. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1898. {}
  1899. };
  1900. static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  1901. {
  1902. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1903. .name = "Master Playback Volume",
  1904. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  1905. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  1906. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  1907. .subdevice = HDA_SUBDEV_AMP_FLAG,
  1908. .info = snd_hda_mixer_amp_volume_info,
  1909. .get = snd_hda_mixer_amp_volume_get,
  1910. .put = snd_hda_mixer_amp_volume_put,
  1911. .tlv = { .c = snd_hda_mixer_amp_tlv },
  1912. /* offset by 28 volume steps to limit minimum gain to -46dB */
  1913. .private_value =
  1914. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  1915. },
  1916. {}
  1917. };
  1918. static struct snd_kcontrol_new cxt5066_mixers[] = {
  1919. {
  1920. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1921. .name = "Master Playback Switch",
  1922. .info = cxt_eapd_info,
  1923. .get = cxt_eapd_get,
  1924. .put = cxt5066_hp_master_sw_put,
  1925. .private_value = 0x1d,
  1926. },
  1927. {
  1928. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1929. .name = "Ext Mic Boost Capture Enum",
  1930. .info = cxt5066_mic_boost_mux_enum_info,
  1931. .get = cxt5066_mic_boost_mux_enum_get,
  1932. .put = cxt5066_mic_boost_mux_enum_put,
  1933. .private_value = 0x17,
  1934. },
  1935. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  1936. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  1937. {}
  1938. };
  1939. static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  1940. {
  1941. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1942. .name = "Int Mic Boost Capture Enum",
  1943. .info = cxt5066_mic_boost_mux_enum_info,
  1944. .get = cxt5066_mic_boost_mux_enum_get,
  1945. .put = cxt5066_mic_boost_mux_enum_put,
  1946. .private_value = 0x23 | 0x100,
  1947. },
  1948. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  1949. {}
  1950. };
  1951. static struct hda_verb cxt5066_init_verbs[] = {
  1952. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  1953. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  1954. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  1955. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  1956. /* Speakers */
  1957. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1958. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1959. /* HP, Amp */
  1960. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1961. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1962. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1963. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1964. /* DAC1 */
  1965. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1966. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  1967. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  1968. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1969. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  1970. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1971. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1972. /* no digital microphone support yet */
  1973. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1974. /* Audio input selector */
  1975. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  1976. /* SPDIF route: PCM */
  1977. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  1978. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  1979. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1980. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1981. /* EAPD */
  1982. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1983. /* not handling these yet */
  1984. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1985. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1986. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1987. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1988. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1989. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1990. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1991. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  1992. { } /* end */
  1993. };
  1994. static struct hda_verb cxt5066_init_verbs_olpc[] = {
  1995. /* Port A: headphones */
  1996. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1997. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1998. /* Port B: external microphone */
  1999. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
  2000. /* Port C: internal microphone */
  2001. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2002. /* Port D: unused */
  2003. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2004. /* Port E: unused, but has primary EAPD */
  2005. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2006. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2007. /* Port F: unused */
  2008. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2009. /* Port G: internal speakers */
  2010. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2011. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2012. /* DAC1 */
  2013. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2014. /* DAC2: unused */
  2015. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2016. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2017. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2018. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2019. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2020. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2021. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2022. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2023. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2024. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2025. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2026. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2027. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2028. /* Disable digital microphone port */
  2029. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2030. /* Audio input selectors */
  2031. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2032. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2033. /* Disable SPDIF */
  2034. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2035. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2036. /* enable unsolicited events for Port A and B */
  2037. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2038. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2039. { } /* end */
  2040. };
  2041. static struct hda_verb cxt5066_init_verbs_vostro[] = {
  2042. /* Port A: headphones */
  2043. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2044. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2045. /* Port B: external microphone */
  2046. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2047. /* Port C: unused */
  2048. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2049. /* Port D: unused */
  2050. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2051. /* Port E: unused, but has primary EAPD */
  2052. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2053. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2054. /* Port F: unused */
  2055. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2056. /* Port G: internal speakers */
  2057. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2058. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2059. /* DAC1 */
  2060. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2061. /* DAC2: unused */
  2062. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2063. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2064. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2065. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2066. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2067. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2068. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2069. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2070. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2071. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2072. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2073. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2074. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2075. /* Digital microphone port */
  2076. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2077. /* Audio input selectors */
  2078. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2079. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2080. /* Disable SPDIF */
  2081. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2082. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2083. /* enable unsolicited events for Port A and B */
  2084. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2085. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2086. { } /* end */
  2087. };
  2088. static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2089. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2090. { } /* end */
  2091. };
  2092. /* initialize jack-sensing, too */
  2093. static int cxt5066_init(struct hda_codec *codec)
  2094. {
  2095. struct conexant_spec *spec = codec->spec;
  2096. snd_printdd("CXT5066: init\n");
  2097. conexant_init(codec);
  2098. if (codec->patch_ops.unsol_event) {
  2099. cxt5066_hp_automute(codec);
  2100. if (spec->dell_vostro)
  2101. cxt5066_vostro_automic(codec);
  2102. else
  2103. cxt5066_automic(codec);
  2104. }
  2105. return 0;
  2106. }
  2107. enum {
  2108. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2109. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2110. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2111. CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
  2112. CXT5066_MODELS
  2113. };
  2114. static const char *cxt5066_models[CXT5066_MODELS] = {
  2115. [CXT5066_LAPTOP] = "laptop",
  2116. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2117. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2118. [CXT5066_DELL_VOSTO] = "dell-vostro"
  2119. };
  2120. static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2121. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2122. CXT5066_LAPTOP),
  2123. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
  2124. CXT5066_DELL_LAPTOP),
  2125. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2126. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
  2127. {}
  2128. };
  2129. static int patch_cxt5066(struct hda_codec *codec)
  2130. {
  2131. struct conexant_spec *spec;
  2132. int board_config;
  2133. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2134. if (!spec)
  2135. return -ENOMEM;
  2136. codec->spec = spec;
  2137. codec->patch_ops = conexant_patch_ops;
  2138. codec->patch_ops.init = cxt5066_init;
  2139. spec->dell_automute = 0;
  2140. spec->multiout.max_channels = 2;
  2141. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2142. spec->multiout.dac_nids = cxt5066_dac_nids;
  2143. spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
  2144. spec->num_adc_nids = 1;
  2145. spec->adc_nids = cxt5066_adc_nids;
  2146. spec->capsrc_nids = cxt5066_capsrc_nids;
  2147. spec->input_mux = &cxt5066_capture_source;
  2148. spec->port_d_mode = PIN_HP;
  2149. spec->ext_mic_bias = PIN_VREF80;
  2150. spec->num_init_verbs = 1;
  2151. spec->init_verbs[0] = cxt5066_init_verbs;
  2152. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2153. spec->channel_mode = cxt5066_modes;
  2154. spec->cur_adc = 0;
  2155. spec->cur_adc_idx = 0;
  2156. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2157. cxt5066_models, cxt5066_cfg_tbl);
  2158. switch (board_config) {
  2159. default:
  2160. case CXT5066_LAPTOP:
  2161. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2162. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2163. break;
  2164. case CXT5066_DELL_LAPTOP:
  2165. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2166. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2167. spec->port_d_mode = PIN_OUT;
  2168. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2169. spec->num_init_verbs++;
  2170. spec->dell_automute = 1;
  2171. break;
  2172. case CXT5066_OLPC_XO_1_5:
  2173. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2174. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2175. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2176. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2177. spec->port_d_mode = 0;
  2178. spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
  2179. /* no S/PDIF out */
  2180. spec->multiout.dig_out_nid = 0;
  2181. /* input source automatically selected */
  2182. spec->input_mux = NULL;
  2183. break;
  2184. case CXT5066_DELL_VOSTO:
  2185. codec->patch_ops.unsol_event = cxt5066_vostro_event;
  2186. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2187. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2188. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2189. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2190. spec->port_d_mode = 0;
  2191. spec->dell_vostro = 1;
  2192. snd_hda_attach_beep_device(codec, 0x13);
  2193. /* no S/PDIF out */
  2194. spec->multiout.dig_out_nid = 0;
  2195. /* input source automatically selected */
  2196. spec->input_mux = NULL;
  2197. break;
  2198. }
  2199. return 0;
  2200. }
  2201. /*
  2202. */
  2203. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  2204. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  2205. .patch = patch_cxt5045 },
  2206. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  2207. .patch = patch_cxt5047 },
  2208. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  2209. .patch = patch_cxt5051 },
  2210. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  2211. .patch = patch_cxt5066 },
  2212. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  2213. .patch = patch_cxt5066 },
  2214. {} /* terminator */
  2215. };
  2216. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  2217. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  2218. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  2219. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  2220. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  2221. MODULE_LICENSE("GPL");
  2222. MODULE_DESCRIPTION("Conexant HD-audio codec");
  2223. static struct hda_codec_preset_list conexant_list = {
  2224. .preset = snd_hda_preset_conexant,
  2225. .owner = THIS_MODULE,
  2226. };
  2227. static int __init patch_conexant_init(void)
  2228. {
  2229. return snd_hda_add_codec_preset(&conexant_list);
  2230. }
  2231. static void __exit patch_conexant_exit(void)
  2232. {
  2233. snd_hda_delete_codec_preset(&conexant_list);
  2234. }
  2235. module_init(patch_conexant_init)
  2236. module_exit(patch_conexant_exit)