patch_conexant.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151
  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 0x12
  40. #define CXT5051_PORTB_EVENT 0x38
  41. #define CXT5051_PORTC_EVENT 0x39
  42. #define AUTO_MIC_PORTB (1 << 1)
  43. #define AUTO_MIC_PORTC (1 << 2)
  44. struct conexant_jack {
  45. hda_nid_t nid;
  46. int type;
  47. struct snd_jack *jack;
  48. };
  49. struct conexant_spec {
  50. struct snd_kcontrol_new *mixers[5];
  51. int num_mixers;
  52. hda_nid_t vmaster_nid;
  53. const struct hda_verb *init_verbs[5]; /* initialization verbs
  54. * don't forget NULL
  55. * termination!
  56. */
  57. unsigned int num_init_verbs;
  58. /* playback */
  59. struct hda_multi_out multiout; /* playback set-up
  60. * max_channels, dacs must be set
  61. * dig_out_nid and hp_nid are optional
  62. */
  63. unsigned int cur_eapd;
  64. unsigned int hp_present;
  65. unsigned int auto_mic;
  66. unsigned int need_dac_fix;
  67. /* capture */
  68. unsigned int num_adc_nids;
  69. hda_nid_t *adc_nids;
  70. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  71. unsigned int cur_adc_idx;
  72. hda_nid_t cur_adc;
  73. unsigned int cur_adc_stream_tag;
  74. unsigned int cur_adc_format;
  75. /* capture source */
  76. const struct hda_input_mux *input_mux;
  77. hda_nid_t *capsrc_nids;
  78. unsigned int cur_mux[3];
  79. /* channel model */
  80. const struct hda_channel_mode *channel_mode;
  81. int num_channel_mode;
  82. /* PCM information */
  83. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  84. unsigned int spdif_route;
  85. /* jack detection */
  86. struct snd_array jacks;
  87. /* dynamic controls, init_verbs and input_mux */
  88. struct auto_pin_cfg autocfg;
  89. struct hda_input_mux private_imux;
  90. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  91. unsigned int dell_automute;
  92. unsigned int port_d_mode;
  93. unsigned int dell_vostro:1;
  94. unsigned int ideapad:1;
  95. unsigned int thinkpad:1;
  96. unsigned int ext_mic_present;
  97. unsigned int recording;
  98. void (*capture_prepare)(struct hda_codec *codec);
  99. void (*capture_cleanup)(struct hda_codec *codec);
  100. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  101. * through the microphone jack.
  102. * When the user enables this through a mixer switch, both internal and
  103. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  104. * we also allow the bias to be configured through a separate mixer
  105. * control. */
  106. unsigned int dc_enable;
  107. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  108. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  109. };
  110. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  111. struct hda_codec *codec,
  112. struct snd_pcm_substream *substream)
  113. {
  114. struct conexant_spec *spec = codec->spec;
  115. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  116. hinfo);
  117. }
  118. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  119. struct hda_codec *codec,
  120. unsigned int stream_tag,
  121. unsigned int format,
  122. struct snd_pcm_substream *substream)
  123. {
  124. struct conexant_spec *spec = codec->spec;
  125. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  126. stream_tag,
  127. format, substream);
  128. }
  129. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  130. struct hda_codec *codec,
  131. struct snd_pcm_substream *substream)
  132. {
  133. struct conexant_spec *spec = codec->spec;
  134. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  135. }
  136. /*
  137. * Digital out
  138. */
  139. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  140. struct hda_codec *codec,
  141. struct snd_pcm_substream *substream)
  142. {
  143. struct conexant_spec *spec = codec->spec;
  144. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  145. }
  146. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  147. struct hda_codec *codec,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  152. }
  153. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  154. struct hda_codec *codec,
  155. unsigned int stream_tag,
  156. unsigned int format,
  157. struct snd_pcm_substream *substream)
  158. {
  159. struct conexant_spec *spec = codec->spec;
  160. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  161. stream_tag,
  162. format, substream);
  163. }
  164. /*
  165. * Analog capture
  166. */
  167. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  168. struct hda_codec *codec,
  169. unsigned int stream_tag,
  170. unsigned int format,
  171. struct snd_pcm_substream *substream)
  172. {
  173. struct conexant_spec *spec = codec->spec;
  174. if (spec->capture_prepare)
  175. spec->capture_prepare(codec);
  176. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  177. stream_tag, 0, format);
  178. return 0;
  179. }
  180. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  181. struct hda_codec *codec,
  182. struct snd_pcm_substream *substream)
  183. {
  184. struct conexant_spec *spec = codec->spec;
  185. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  186. if (spec->capture_cleanup)
  187. spec->capture_cleanup(codec);
  188. return 0;
  189. }
  190. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  191. .substreams = 1,
  192. .channels_min = 2,
  193. .channels_max = 2,
  194. .nid = 0, /* fill later */
  195. .ops = {
  196. .open = conexant_playback_pcm_open,
  197. .prepare = conexant_playback_pcm_prepare,
  198. .cleanup = conexant_playback_pcm_cleanup
  199. },
  200. };
  201. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  202. .substreams = 1,
  203. .channels_min = 2,
  204. .channels_max = 2,
  205. .nid = 0, /* fill later */
  206. .ops = {
  207. .prepare = conexant_capture_pcm_prepare,
  208. .cleanup = conexant_capture_pcm_cleanup
  209. },
  210. };
  211. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  212. .substreams = 1,
  213. .channels_min = 2,
  214. .channels_max = 2,
  215. .nid = 0, /* fill later */
  216. .ops = {
  217. .open = conexant_dig_playback_pcm_open,
  218. .close = conexant_dig_playback_pcm_close,
  219. .prepare = conexant_dig_playback_pcm_prepare
  220. },
  221. };
  222. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  223. .substreams = 1,
  224. .channels_min = 2,
  225. .channels_max = 2,
  226. /* NID is set in alc_build_pcms */
  227. };
  228. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  229. struct hda_codec *codec,
  230. unsigned int stream_tag,
  231. unsigned int format,
  232. struct snd_pcm_substream *substream)
  233. {
  234. struct conexant_spec *spec = codec->spec;
  235. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  236. spec->cur_adc_stream_tag = stream_tag;
  237. spec->cur_adc_format = format;
  238. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  239. return 0;
  240. }
  241. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  242. struct hda_codec *codec,
  243. struct snd_pcm_substream *substream)
  244. {
  245. struct conexant_spec *spec = codec->spec;
  246. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  247. spec->cur_adc = 0;
  248. return 0;
  249. }
  250. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  251. .substreams = 1,
  252. .channels_min = 2,
  253. .channels_max = 2,
  254. .nid = 0, /* fill later */
  255. .ops = {
  256. .prepare = cx5051_capture_pcm_prepare,
  257. .cleanup = cx5051_capture_pcm_cleanup
  258. },
  259. };
  260. static int conexant_build_pcms(struct hda_codec *codec)
  261. {
  262. struct conexant_spec *spec = codec->spec;
  263. struct hda_pcm *info = spec->pcm_rec;
  264. codec->num_pcms = 1;
  265. codec->pcm_info = info;
  266. info->name = "CONEXANT Analog";
  267. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  268. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  269. spec->multiout.max_channels;
  270. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  271. spec->multiout.dac_nids[0];
  272. if (codec->vendor_id == 0x14f15051)
  273. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  274. cx5051_pcm_analog_capture;
  275. else
  276. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  277. conexant_pcm_analog_capture;
  278. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  279. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  280. if (spec->multiout.dig_out_nid) {
  281. info++;
  282. codec->num_pcms++;
  283. info->name = "Conexant Digital";
  284. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  285. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  286. conexant_pcm_digital_playback;
  287. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  288. spec->multiout.dig_out_nid;
  289. if (spec->dig_in_nid) {
  290. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  291. conexant_pcm_digital_capture;
  292. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  293. spec->dig_in_nid;
  294. }
  295. }
  296. return 0;
  297. }
  298. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  299. struct snd_ctl_elem_info *uinfo)
  300. {
  301. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  302. struct conexant_spec *spec = codec->spec;
  303. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  304. }
  305. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  306. struct snd_ctl_elem_value *ucontrol)
  307. {
  308. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  309. struct conexant_spec *spec = codec->spec;
  310. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  311. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  312. return 0;
  313. }
  314. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  315. struct snd_ctl_elem_value *ucontrol)
  316. {
  317. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  318. struct conexant_spec *spec = codec->spec;
  319. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  320. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  321. spec->capsrc_nids[adc_idx],
  322. &spec->cur_mux[adc_idx]);
  323. }
  324. #ifdef CONFIG_SND_HDA_INPUT_JACK
  325. static void conexant_free_jack_priv(struct snd_jack *jack)
  326. {
  327. struct conexant_jack *jacks = jack->private_data;
  328. jacks->nid = 0;
  329. jacks->jack = NULL;
  330. }
  331. static int conexant_add_jack(struct hda_codec *codec,
  332. hda_nid_t nid, int type)
  333. {
  334. struct conexant_spec *spec;
  335. struct conexant_jack *jack;
  336. const char *name;
  337. int err;
  338. spec = codec->spec;
  339. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  340. jack = snd_array_new(&spec->jacks);
  341. name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
  342. if (!jack)
  343. return -ENOMEM;
  344. jack->nid = nid;
  345. jack->type = type;
  346. err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
  347. if (err < 0)
  348. return err;
  349. jack->jack->private_data = jack;
  350. jack->jack->private_free = conexant_free_jack_priv;
  351. return 0;
  352. }
  353. static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  354. {
  355. struct conexant_spec *spec = codec->spec;
  356. struct conexant_jack *jacks = spec->jacks.list;
  357. if (jacks) {
  358. int i;
  359. for (i = 0; i < spec->jacks.used; i++) {
  360. if (jacks->nid == nid) {
  361. unsigned int present;
  362. present = snd_hda_jack_detect(codec, nid);
  363. present = (present) ? jacks->type : 0 ;
  364. snd_jack_report(jacks->jack,
  365. present);
  366. }
  367. jacks++;
  368. }
  369. }
  370. }
  371. static int conexant_init_jacks(struct hda_codec *codec)
  372. {
  373. struct conexant_spec *spec = codec->spec;
  374. int i;
  375. for (i = 0; i < spec->num_init_verbs; i++) {
  376. const struct hda_verb *hv;
  377. hv = spec->init_verbs[i];
  378. while (hv->nid) {
  379. int err = 0;
  380. switch (hv->param ^ AC_USRSP_EN) {
  381. case CONEXANT_HP_EVENT:
  382. err = conexant_add_jack(codec, hv->nid,
  383. SND_JACK_HEADPHONE);
  384. conexant_report_jack(codec, hv->nid);
  385. break;
  386. case CXT5051_PORTC_EVENT:
  387. case CONEXANT_MIC_EVENT:
  388. err = conexant_add_jack(codec, hv->nid,
  389. SND_JACK_MICROPHONE);
  390. conexant_report_jack(codec, hv->nid);
  391. break;
  392. }
  393. if (err < 0)
  394. return err;
  395. ++hv;
  396. }
  397. }
  398. return 0;
  399. }
  400. #else
  401. static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  402. {
  403. }
  404. static inline int conexant_init_jacks(struct hda_codec *codec)
  405. {
  406. return 0;
  407. }
  408. #endif
  409. static int conexant_init(struct hda_codec *codec)
  410. {
  411. struct conexant_spec *spec = codec->spec;
  412. int i;
  413. for (i = 0; i < spec->num_init_verbs; i++)
  414. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  415. return 0;
  416. }
  417. static void conexant_free(struct hda_codec *codec)
  418. {
  419. #ifdef CONFIG_SND_HDA_INPUT_JACK
  420. struct conexant_spec *spec = codec->spec;
  421. if (spec->jacks.list) {
  422. struct conexant_jack *jacks = spec->jacks.list;
  423. int i;
  424. for (i = 0; i < spec->jacks.used; i++, jacks++) {
  425. if (jacks->jack)
  426. snd_device_free(codec->bus->card, jacks->jack);
  427. }
  428. snd_array_free(&spec->jacks);
  429. }
  430. #endif
  431. snd_hda_detach_beep_device(codec);
  432. kfree(codec->spec);
  433. }
  434. static struct snd_kcontrol_new cxt_capture_mixers[] = {
  435. {
  436. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  437. .name = "Capture Source",
  438. .info = conexant_mux_enum_info,
  439. .get = conexant_mux_enum_get,
  440. .put = conexant_mux_enum_put
  441. },
  442. {}
  443. };
  444. static const char *slave_vols[] = {
  445. "Headphone Playback Volume",
  446. "Speaker Playback Volume",
  447. NULL
  448. };
  449. static const char *slave_sws[] = {
  450. "Headphone Playback Switch",
  451. "Speaker Playback Switch",
  452. NULL
  453. };
  454. static int conexant_build_controls(struct hda_codec *codec)
  455. {
  456. struct conexant_spec *spec = codec->spec;
  457. unsigned int i;
  458. int err;
  459. for (i = 0; i < spec->num_mixers; i++) {
  460. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  461. if (err < 0)
  462. return err;
  463. }
  464. if (spec->multiout.dig_out_nid) {
  465. err = snd_hda_create_spdif_out_ctls(codec,
  466. spec->multiout.dig_out_nid);
  467. if (err < 0)
  468. return err;
  469. err = snd_hda_create_spdif_share_sw(codec,
  470. &spec->multiout);
  471. if (err < 0)
  472. return err;
  473. spec->multiout.share_spdif = 1;
  474. }
  475. if (spec->dig_in_nid) {
  476. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  477. if (err < 0)
  478. return err;
  479. }
  480. /* if we have no master control, let's create it */
  481. if (spec->vmaster_nid &&
  482. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  483. unsigned int vmaster_tlv[4];
  484. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  485. HDA_OUTPUT, vmaster_tlv);
  486. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  487. vmaster_tlv, slave_vols);
  488. if (err < 0)
  489. return err;
  490. }
  491. if (spec->vmaster_nid &&
  492. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  493. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  494. NULL, slave_sws);
  495. if (err < 0)
  496. return err;
  497. }
  498. if (spec->input_mux) {
  499. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  500. if (err < 0)
  501. return err;
  502. }
  503. return 0;
  504. }
  505. static struct hda_codec_ops conexant_patch_ops = {
  506. .build_controls = conexant_build_controls,
  507. .build_pcms = conexant_build_pcms,
  508. .init = conexant_init,
  509. .free = conexant_free,
  510. };
  511. /*
  512. * EAPD control
  513. * the private value = nid | (invert << 8)
  514. */
  515. #define cxt_eapd_info snd_ctl_boolean_mono_info
  516. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  517. struct snd_ctl_elem_value *ucontrol)
  518. {
  519. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  520. struct conexant_spec *spec = codec->spec;
  521. int invert = (kcontrol->private_value >> 8) & 1;
  522. if (invert)
  523. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  524. else
  525. ucontrol->value.integer.value[0] = spec->cur_eapd;
  526. return 0;
  527. }
  528. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  529. struct snd_ctl_elem_value *ucontrol)
  530. {
  531. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  532. struct conexant_spec *spec = codec->spec;
  533. int invert = (kcontrol->private_value >> 8) & 1;
  534. hda_nid_t nid = kcontrol->private_value & 0xff;
  535. unsigned int eapd;
  536. eapd = !!ucontrol->value.integer.value[0];
  537. if (invert)
  538. eapd = !eapd;
  539. if (eapd == spec->cur_eapd)
  540. return 0;
  541. spec->cur_eapd = eapd;
  542. snd_hda_codec_write_cache(codec, nid,
  543. 0, AC_VERB_SET_EAPD_BTLENABLE,
  544. eapd ? 0x02 : 0x00);
  545. return 1;
  546. }
  547. /* controls for test mode */
  548. #ifdef CONFIG_SND_DEBUG
  549. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  550. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  551. .info = cxt_eapd_info, \
  552. .get = cxt_eapd_get, \
  553. .put = cxt_eapd_put, \
  554. .private_value = nid | (mask<<16) }
  555. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  556. struct snd_ctl_elem_info *uinfo)
  557. {
  558. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  559. struct conexant_spec *spec = codec->spec;
  560. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  561. spec->num_channel_mode);
  562. }
  563. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  564. struct snd_ctl_elem_value *ucontrol)
  565. {
  566. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  567. struct conexant_spec *spec = codec->spec;
  568. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  569. spec->num_channel_mode,
  570. spec->multiout.max_channels);
  571. }
  572. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  573. struct snd_ctl_elem_value *ucontrol)
  574. {
  575. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  576. struct conexant_spec *spec = codec->spec;
  577. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  578. spec->num_channel_mode,
  579. &spec->multiout.max_channels);
  580. if (err >= 0 && spec->need_dac_fix)
  581. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  582. return err;
  583. }
  584. #define CXT_PIN_MODE(xname, nid, dir) \
  585. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  586. .info = conexant_ch_mode_info, \
  587. .get = conexant_ch_mode_get, \
  588. .put = conexant_ch_mode_put, \
  589. .private_value = nid | (dir<<16) }
  590. #endif /* CONFIG_SND_DEBUG */
  591. /* Conexant 5045 specific */
  592. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  593. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  594. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  595. #define CXT5045_SPDIF_OUT 0x18
  596. static struct hda_channel_mode cxt5045_modes[1] = {
  597. { 2, NULL },
  598. };
  599. static struct hda_input_mux cxt5045_capture_source = {
  600. .num_items = 2,
  601. .items = {
  602. { "IntMic", 0x1 },
  603. { "ExtMic", 0x2 },
  604. }
  605. };
  606. static struct hda_input_mux cxt5045_capture_source_benq = {
  607. .num_items = 5,
  608. .items = {
  609. { "IntMic", 0x1 },
  610. { "ExtMic", 0x2 },
  611. { "LineIn", 0x3 },
  612. { "CD", 0x4 },
  613. { "Mixer", 0x0 },
  614. }
  615. };
  616. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  617. .num_items = 2,
  618. .items = {
  619. { "ExtMic", 0x1 },
  620. { "IntMic", 0x2 },
  621. }
  622. };
  623. /* turn on/off EAPD (+ mute HP) as a master switch */
  624. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  625. struct snd_ctl_elem_value *ucontrol)
  626. {
  627. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  628. struct conexant_spec *spec = codec->spec;
  629. unsigned int bits;
  630. if (!cxt_eapd_put(kcontrol, ucontrol))
  631. return 0;
  632. /* toggle internal speakers mute depending of presence of
  633. * the headphone jack
  634. */
  635. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  636. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  637. HDA_AMP_MUTE, bits);
  638. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  639. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  640. HDA_AMP_MUTE, bits);
  641. return 1;
  642. }
  643. /* bind volumes of both NID 0x10 and 0x11 */
  644. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  645. .ops = &snd_hda_bind_vol,
  646. .values = {
  647. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  648. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  649. 0
  650. },
  651. };
  652. /* toggle input of built-in and mic jack appropriately */
  653. static void cxt5045_hp_automic(struct hda_codec *codec)
  654. {
  655. static struct hda_verb mic_jack_on[] = {
  656. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  657. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  658. {}
  659. };
  660. static struct hda_verb mic_jack_off[] = {
  661. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  662. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  663. {}
  664. };
  665. unsigned int present;
  666. present = snd_hda_jack_detect(codec, 0x12);
  667. if (present)
  668. snd_hda_sequence_write(codec, mic_jack_on);
  669. else
  670. snd_hda_sequence_write(codec, mic_jack_off);
  671. }
  672. /* mute internal speaker if HP is plugged */
  673. static void cxt5045_hp_automute(struct hda_codec *codec)
  674. {
  675. struct conexant_spec *spec = codec->spec;
  676. unsigned int bits;
  677. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  678. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  679. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  680. HDA_AMP_MUTE, bits);
  681. }
  682. /* unsolicited event for HP jack sensing */
  683. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  684. unsigned int res)
  685. {
  686. res >>= 26;
  687. switch (res) {
  688. case CONEXANT_HP_EVENT:
  689. cxt5045_hp_automute(codec);
  690. break;
  691. case CONEXANT_MIC_EVENT:
  692. cxt5045_hp_automic(codec);
  693. break;
  694. }
  695. }
  696. static struct snd_kcontrol_new cxt5045_mixers[] = {
  697. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  698. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  699. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  700. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  701. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  702. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  703. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  704. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  706. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  707. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  708. {
  709. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  710. .name = "Master Playback Switch",
  711. .info = cxt_eapd_info,
  712. .get = cxt_eapd_get,
  713. .put = cxt5045_hp_master_sw_put,
  714. .private_value = 0x10,
  715. },
  716. {}
  717. };
  718. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  719. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  720. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  721. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  722. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  723. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  724. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  725. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  726. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  727. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  728. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  729. {}
  730. };
  731. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  732. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  733. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  734. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  735. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  736. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  737. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  738. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  739. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  740. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  741. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  742. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  743. {
  744. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  745. .name = "Master Playback Switch",
  746. .info = cxt_eapd_info,
  747. .get = cxt_eapd_get,
  748. .put = cxt5045_hp_master_sw_put,
  749. .private_value = 0x10,
  750. },
  751. {}
  752. };
  753. static struct hda_verb cxt5045_init_verbs[] = {
  754. /* Line in, Mic */
  755. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  756. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  757. /* HP, Amp */
  758. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  759. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  760. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  761. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  762. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  763. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  764. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  765. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  766. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  767. /* Record selector: Int mic */
  768. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  769. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  770. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  771. /* SPDIF route: PCM */
  772. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  773. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  774. /* EAPD */
  775. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  776. { } /* end */
  777. };
  778. static struct hda_verb cxt5045_benq_init_verbs[] = {
  779. /* Int Mic, Mic */
  780. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  781. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  782. /* Line In,HP, Amp */
  783. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  784. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  785. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  786. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  787. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  788. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  789. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  790. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  791. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  792. /* Record selector: Int mic */
  793. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  794. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  795. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  796. /* SPDIF route: PCM */
  797. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  798. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  799. /* EAPD */
  800. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  801. { } /* end */
  802. };
  803. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  804. /* pin sensing on HP jack */
  805. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  806. { } /* end */
  807. };
  808. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  809. /* pin sensing on HP jack */
  810. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  811. { } /* end */
  812. };
  813. #ifdef CONFIG_SND_DEBUG
  814. /* Test configuration for debugging, modelled after the ALC260 test
  815. * configuration.
  816. */
  817. static struct hda_input_mux cxt5045_test_capture_source = {
  818. .num_items = 5,
  819. .items = {
  820. { "MIXER", 0x0 },
  821. { "MIC1 pin", 0x1 },
  822. { "LINE1 pin", 0x2 },
  823. { "HP-OUT pin", 0x3 },
  824. { "CD pin", 0x4 },
  825. },
  826. };
  827. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  828. /* Output controls */
  829. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  830. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  831. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  832. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  833. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  834. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  835. /* Modes for retasking pin widgets */
  836. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  837. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  838. /* EAPD Switch Control */
  839. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  840. /* Loopback mixer controls */
  841. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  842. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  843. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  844. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  845. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  846. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  847. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  848. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  849. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  850. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  851. {
  852. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  853. .name = "Input Source",
  854. .info = conexant_mux_enum_info,
  855. .get = conexant_mux_enum_get,
  856. .put = conexant_mux_enum_put,
  857. },
  858. /* Audio input controls */
  859. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  860. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  861. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  862. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  863. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  864. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  865. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  866. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  867. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  868. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  869. { } /* end */
  870. };
  871. static struct hda_verb cxt5045_test_init_verbs[] = {
  872. /* Set connections */
  873. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  874. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  875. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  876. /* Enable retasking pins as output, initially without power amp */
  877. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  878. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  879. /* Disable digital (SPDIF) pins initially, but users can enable
  880. * them via a mixer switch. In the case of SPDIF-out, this initverb
  881. * payload also sets the generation to 0, output to be in "consumer"
  882. * PCM format, copyright asserted, no pre-emphasis and no validity
  883. * control.
  884. */
  885. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  886. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  887. /* Start with output sum widgets muted and their output gains at min */
  888. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  889. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  890. /* Unmute retasking pin widget output buffers since the default
  891. * state appears to be output. As the pin mode is changed by the
  892. * user the pin mode control will take care of enabling the pin's
  893. * input/output buffers as needed.
  894. */
  895. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  896. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  897. /* Mute capture amp left and right */
  898. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  899. /* Set ADC connection select to match default mixer setting (mic1
  900. * pin)
  901. */
  902. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  903. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  904. /* Mute all inputs to mixer widget (even unconnected ones) */
  905. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  906. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  907. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  908. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  909. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  910. { }
  911. };
  912. #endif
  913. /* initialize jack-sensing, too */
  914. static int cxt5045_init(struct hda_codec *codec)
  915. {
  916. conexant_init(codec);
  917. cxt5045_hp_automute(codec);
  918. return 0;
  919. }
  920. enum {
  921. CXT5045_LAPTOP_HPSENSE,
  922. CXT5045_LAPTOP_MICSENSE,
  923. CXT5045_LAPTOP_HPMICSENSE,
  924. CXT5045_BENQ,
  925. CXT5045_LAPTOP_HP530,
  926. #ifdef CONFIG_SND_DEBUG
  927. CXT5045_TEST,
  928. #endif
  929. CXT5045_MODELS
  930. };
  931. static const char *cxt5045_models[CXT5045_MODELS] = {
  932. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  933. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  934. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  935. [CXT5045_BENQ] = "benq",
  936. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  937. #ifdef CONFIG_SND_DEBUG
  938. [CXT5045_TEST] = "test",
  939. #endif
  940. };
  941. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  942. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  943. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  944. CXT5045_LAPTOP_HPSENSE),
  945. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  946. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  947. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  948. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  949. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  950. CXT5045_LAPTOP_HPMICSENSE),
  951. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  952. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  953. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  954. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  955. CXT5045_LAPTOP_HPMICSENSE),
  956. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  957. {}
  958. };
  959. static int patch_cxt5045(struct hda_codec *codec)
  960. {
  961. struct conexant_spec *spec;
  962. int board_config;
  963. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  964. if (!spec)
  965. return -ENOMEM;
  966. codec->spec = spec;
  967. codec->pin_amp_workaround = 1;
  968. spec->multiout.max_channels = 2;
  969. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  970. spec->multiout.dac_nids = cxt5045_dac_nids;
  971. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  972. spec->num_adc_nids = 1;
  973. spec->adc_nids = cxt5045_adc_nids;
  974. spec->capsrc_nids = cxt5045_capsrc_nids;
  975. spec->input_mux = &cxt5045_capture_source;
  976. spec->num_mixers = 1;
  977. spec->mixers[0] = cxt5045_mixers;
  978. spec->num_init_verbs = 1;
  979. spec->init_verbs[0] = cxt5045_init_verbs;
  980. spec->spdif_route = 0;
  981. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  982. spec->channel_mode = cxt5045_modes,
  983. codec->patch_ops = conexant_patch_ops;
  984. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  985. cxt5045_models,
  986. cxt5045_cfg_tbl);
  987. switch (board_config) {
  988. case CXT5045_LAPTOP_HPSENSE:
  989. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  990. spec->input_mux = &cxt5045_capture_source;
  991. spec->num_init_verbs = 2;
  992. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  993. spec->mixers[0] = cxt5045_mixers;
  994. codec->patch_ops.init = cxt5045_init;
  995. break;
  996. case CXT5045_LAPTOP_MICSENSE:
  997. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  998. spec->input_mux = &cxt5045_capture_source;
  999. spec->num_init_verbs = 2;
  1000. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  1001. spec->mixers[0] = cxt5045_mixers;
  1002. codec->patch_ops.init = cxt5045_init;
  1003. break;
  1004. default:
  1005. case CXT5045_LAPTOP_HPMICSENSE:
  1006. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1007. spec->input_mux = &cxt5045_capture_source;
  1008. spec->num_init_verbs = 3;
  1009. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1010. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  1011. spec->mixers[0] = cxt5045_mixers;
  1012. codec->patch_ops.init = cxt5045_init;
  1013. break;
  1014. case CXT5045_BENQ:
  1015. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1016. spec->input_mux = &cxt5045_capture_source_benq;
  1017. spec->num_init_verbs = 1;
  1018. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  1019. spec->mixers[0] = cxt5045_mixers;
  1020. spec->mixers[1] = cxt5045_benq_mixers;
  1021. spec->num_mixers = 2;
  1022. codec->patch_ops.init = cxt5045_init;
  1023. break;
  1024. case CXT5045_LAPTOP_HP530:
  1025. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1026. spec->input_mux = &cxt5045_capture_source_hp530;
  1027. spec->num_init_verbs = 2;
  1028. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1029. spec->mixers[0] = cxt5045_mixers_hp530;
  1030. codec->patch_ops.init = cxt5045_init;
  1031. break;
  1032. #ifdef CONFIG_SND_DEBUG
  1033. case CXT5045_TEST:
  1034. spec->input_mux = &cxt5045_test_capture_source;
  1035. spec->mixers[0] = cxt5045_test_mixer;
  1036. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1037. break;
  1038. #endif
  1039. }
  1040. switch (codec->subsystem_id >> 16) {
  1041. case 0x103c:
  1042. case 0x1631:
  1043. case 0x1734:
  1044. /* HP, Packard Bell, & Fujitsu-Siemens laptops have really bad
  1045. * sound over 0dB on NID 0x17. Fix max PCM level to 0 dB
  1046. * (originally it has 0x2b steps with 0dB offset 0x14)
  1047. */
  1048. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1049. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1050. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1051. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1052. (1 << AC_AMPCAP_MUTE_SHIFT));
  1053. break;
  1054. }
  1055. return 0;
  1056. }
  1057. /* Conexant 5047 specific */
  1058. #define CXT5047_SPDIF_OUT 0x11
  1059. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1060. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1061. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1062. static struct hda_channel_mode cxt5047_modes[1] = {
  1063. { 2, NULL },
  1064. };
  1065. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  1066. .num_items = 2,
  1067. .items = {
  1068. { "ExtMic", 0x2 },
  1069. { "Line-In", 0x1 },
  1070. }
  1071. };
  1072. /* turn on/off EAPD (+ mute HP) as a master switch */
  1073. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1074. struct snd_ctl_elem_value *ucontrol)
  1075. {
  1076. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1077. struct conexant_spec *spec = codec->spec;
  1078. unsigned int bits;
  1079. if (!cxt_eapd_put(kcontrol, ucontrol))
  1080. return 0;
  1081. /* toggle internal speakers mute depending of presence of
  1082. * the headphone jack
  1083. */
  1084. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1085. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1086. * pin widgets unlike other codecs. In this case, we need to
  1087. * set index 0x01 for the volume from the mixer amp 0x19.
  1088. */
  1089. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1090. HDA_AMP_MUTE, bits);
  1091. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1092. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1093. HDA_AMP_MUTE, bits);
  1094. return 1;
  1095. }
  1096. /* mute internal speaker if HP is plugged */
  1097. static void cxt5047_hp_automute(struct hda_codec *codec)
  1098. {
  1099. struct conexant_spec *spec = codec->spec;
  1100. unsigned int bits;
  1101. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1102. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1103. /* See the note in cxt5047_hp_master_sw_put */
  1104. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1105. HDA_AMP_MUTE, bits);
  1106. }
  1107. /* toggle input of built-in and mic jack appropriately */
  1108. static void cxt5047_hp_automic(struct hda_codec *codec)
  1109. {
  1110. static struct hda_verb mic_jack_on[] = {
  1111. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1112. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1113. {}
  1114. };
  1115. static struct hda_verb mic_jack_off[] = {
  1116. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1117. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1118. {}
  1119. };
  1120. unsigned int present;
  1121. present = snd_hda_jack_detect(codec, 0x15);
  1122. if (present)
  1123. snd_hda_sequence_write(codec, mic_jack_on);
  1124. else
  1125. snd_hda_sequence_write(codec, mic_jack_off);
  1126. }
  1127. /* unsolicited event for HP jack sensing */
  1128. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1129. unsigned int res)
  1130. {
  1131. switch (res >> 26) {
  1132. case CONEXANT_HP_EVENT:
  1133. cxt5047_hp_automute(codec);
  1134. break;
  1135. case CONEXANT_MIC_EVENT:
  1136. cxt5047_hp_automic(codec);
  1137. break;
  1138. }
  1139. }
  1140. static struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1141. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1142. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1143. HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
  1144. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1145. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1146. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1147. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1148. {
  1149. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1150. .name = "Master Playback Switch",
  1151. .info = cxt_eapd_info,
  1152. .get = cxt_eapd_get,
  1153. .put = cxt5047_hp_master_sw_put,
  1154. .private_value = 0x13,
  1155. },
  1156. {}
  1157. };
  1158. static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1159. /* See the note in cxt5047_hp_master_sw_put */
  1160. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1161. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1162. {}
  1163. };
  1164. static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1165. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1166. { } /* end */
  1167. };
  1168. static struct hda_verb cxt5047_init_verbs[] = {
  1169. /* Line in, Mic, Built-in Mic */
  1170. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1171. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1172. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1173. /* HP, Speaker */
  1174. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1175. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1176. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1177. /* Record selector: Mic */
  1178. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1179. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1180. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1181. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1182. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1183. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1184. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1185. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1186. /* SPDIF route: PCM */
  1187. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1188. /* Enable unsolicited events */
  1189. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1190. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1191. { } /* end */
  1192. };
  1193. /* configuration for Toshiba Laptops */
  1194. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1195. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1196. {}
  1197. };
  1198. /* Test configuration for debugging, modelled after the ALC260 test
  1199. * configuration.
  1200. */
  1201. #ifdef CONFIG_SND_DEBUG
  1202. static struct hda_input_mux cxt5047_test_capture_source = {
  1203. .num_items = 4,
  1204. .items = {
  1205. { "LINE1 pin", 0x0 },
  1206. { "MIC1 pin", 0x1 },
  1207. { "MIC2 pin", 0x2 },
  1208. { "CD pin", 0x3 },
  1209. },
  1210. };
  1211. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1212. /* Output only controls */
  1213. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1214. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1215. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1216. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1217. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1218. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1219. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1220. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1221. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1222. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1223. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1224. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1225. /* Modes for retasking pin widgets */
  1226. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1227. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1228. /* EAPD Switch Control */
  1229. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1230. /* Loopback mixer controls */
  1231. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1232. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1233. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1234. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1235. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1236. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1237. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1238. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1239. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1240. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1241. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1242. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1243. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1244. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1245. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1246. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1247. {
  1248. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1249. .name = "Input Source",
  1250. .info = conexant_mux_enum_info,
  1251. .get = conexant_mux_enum_get,
  1252. .put = conexant_mux_enum_put,
  1253. },
  1254. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1255. { } /* end */
  1256. };
  1257. static struct hda_verb cxt5047_test_init_verbs[] = {
  1258. /* Enable retasking pins as output, initially without power amp */
  1259. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1260. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1261. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1262. /* Disable digital (SPDIF) pins initially, but users can enable
  1263. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1264. * payload also sets the generation to 0, output to be in "consumer"
  1265. * PCM format, copyright asserted, no pre-emphasis and no validity
  1266. * control.
  1267. */
  1268. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1269. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1270. * OUT1 sum bus when acting as an output.
  1271. */
  1272. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1273. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1274. /* Start with output sum widgets muted and their output gains at min */
  1275. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1276. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1277. /* Unmute retasking pin widget output buffers since the default
  1278. * state appears to be output. As the pin mode is changed by the
  1279. * user the pin mode control will take care of enabling the pin's
  1280. * input/output buffers as needed.
  1281. */
  1282. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1283. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1284. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1285. /* Mute capture amp left and right */
  1286. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1287. /* Set ADC connection select to match default mixer setting (mic1
  1288. * pin)
  1289. */
  1290. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1291. /* Mute all inputs to mixer widget (even unconnected ones) */
  1292. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1293. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1294. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1295. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1296. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1297. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1298. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1299. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1300. { }
  1301. };
  1302. #endif
  1303. /* initialize jack-sensing, too */
  1304. static int cxt5047_hp_init(struct hda_codec *codec)
  1305. {
  1306. conexant_init(codec);
  1307. cxt5047_hp_automute(codec);
  1308. return 0;
  1309. }
  1310. enum {
  1311. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1312. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1313. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1314. #ifdef CONFIG_SND_DEBUG
  1315. CXT5047_TEST,
  1316. #endif
  1317. CXT5047_MODELS
  1318. };
  1319. static const char *cxt5047_models[CXT5047_MODELS] = {
  1320. [CXT5047_LAPTOP] = "laptop",
  1321. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1322. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1323. #ifdef CONFIG_SND_DEBUG
  1324. [CXT5047_TEST] = "test",
  1325. #endif
  1326. };
  1327. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1328. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1329. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1330. CXT5047_LAPTOP),
  1331. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1332. {}
  1333. };
  1334. static int patch_cxt5047(struct hda_codec *codec)
  1335. {
  1336. struct conexant_spec *spec;
  1337. int board_config;
  1338. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1339. if (!spec)
  1340. return -ENOMEM;
  1341. codec->spec = spec;
  1342. codec->pin_amp_workaround = 1;
  1343. spec->multiout.max_channels = 2;
  1344. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1345. spec->multiout.dac_nids = cxt5047_dac_nids;
  1346. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1347. spec->num_adc_nids = 1;
  1348. spec->adc_nids = cxt5047_adc_nids;
  1349. spec->capsrc_nids = cxt5047_capsrc_nids;
  1350. spec->num_mixers = 1;
  1351. spec->mixers[0] = cxt5047_base_mixers;
  1352. spec->num_init_verbs = 1;
  1353. spec->init_verbs[0] = cxt5047_init_verbs;
  1354. spec->spdif_route = 0;
  1355. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1356. spec->channel_mode = cxt5047_modes,
  1357. codec->patch_ops = conexant_patch_ops;
  1358. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1359. cxt5047_models,
  1360. cxt5047_cfg_tbl);
  1361. switch (board_config) {
  1362. case CXT5047_LAPTOP:
  1363. spec->num_mixers = 2;
  1364. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1365. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1366. break;
  1367. case CXT5047_LAPTOP_HP:
  1368. spec->num_mixers = 2;
  1369. spec->mixers[1] = cxt5047_hp_only_mixers;
  1370. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1371. codec->patch_ops.init = cxt5047_hp_init;
  1372. break;
  1373. case CXT5047_LAPTOP_EAPD:
  1374. spec->input_mux = &cxt5047_toshiba_capture_source;
  1375. spec->num_mixers = 2;
  1376. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1377. spec->num_init_verbs = 2;
  1378. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1379. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1380. break;
  1381. #ifdef CONFIG_SND_DEBUG
  1382. case CXT5047_TEST:
  1383. spec->input_mux = &cxt5047_test_capture_source;
  1384. spec->mixers[0] = cxt5047_test_mixer;
  1385. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1386. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1387. #endif
  1388. }
  1389. spec->vmaster_nid = 0x13;
  1390. switch (codec->subsystem_id >> 16) {
  1391. case 0x103c:
  1392. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1393. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1394. * with 0 dB offset 0x17)
  1395. */
  1396. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1397. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1398. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1399. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1400. (1 << AC_AMPCAP_MUTE_SHIFT));
  1401. break;
  1402. }
  1403. return 0;
  1404. }
  1405. /* Conexant 5051 specific */
  1406. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1407. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1408. static struct hda_channel_mode cxt5051_modes[1] = {
  1409. { 2, NULL },
  1410. };
  1411. static void cxt5051_update_speaker(struct hda_codec *codec)
  1412. {
  1413. struct conexant_spec *spec = codec->spec;
  1414. unsigned int pinctl;
  1415. /* headphone pin */
  1416. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1417. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1418. pinctl);
  1419. /* speaker pin */
  1420. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1421. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1422. pinctl);
  1423. }
  1424. /* turn on/off EAPD (+ mute HP) as a master switch */
  1425. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1426. struct snd_ctl_elem_value *ucontrol)
  1427. {
  1428. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1429. if (!cxt_eapd_put(kcontrol, ucontrol))
  1430. return 0;
  1431. cxt5051_update_speaker(codec);
  1432. return 1;
  1433. }
  1434. /* toggle input of built-in and mic jack appropriately */
  1435. static void cxt5051_portb_automic(struct hda_codec *codec)
  1436. {
  1437. struct conexant_spec *spec = codec->spec;
  1438. unsigned int present;
  1439. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1440. return;
  1441. present = snd_hda_jack_detect(codec, 0x17);
  1442. snd_hda_codec_write(codec, 0x14, 0,
  1443. AC_VERB_SET_CONNECT_SEL,
  1444. present ? 0x01 : 0x00);
  1445. }
  1446. /* switch the current ADC according to the jack state */
  1447. static void cxt5051_portc_automic(struct hda_codec *codec)
  1448. {
  1449. struct conexant_spec *spec = codec->spec;
  1450. unsigned int present;
  1451. hda_nid_t new_adc;
  1452. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1453. return;
  1454. present = snd_hda_jack_detect(codec, 0x18);
  1455. if (present)
  1456. spec->cur_adc_idx = 1;
  1457. else
  1458. spec->cur_adc_idx = 0;
  1459. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1460. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1461. /* stream is running, let's swap the current ADC */
  1462. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1463. spec->cur_adc = new_adc;
  1464. snd_hda_codec_setup_stream(codec, new_adc,
  1465. spec->cur_adc_stream_tag, 0,
  1466. spec->cur_adc_format);
  1467. }
  1468. }
  1469. /* mute internal speaker if HP is plugged */
  1470. static void cxt5051_hp_automute(struct hda_codec *codec)
  1471. {
  1472. struct conexant_spec *spec = codec->spec;
  1473. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1474. cxt5051_update_speaker(codec);
  1475. }
  1476. /* unsolicited event for HP jack sensing */
  1477. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1478. unsigned int res)
  1479. {
  1480. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1481. switch (res >> 26) {
  1482. case CONEXANT_HP_EVENT:
  1483. cxt5051_hp_automute(codec);
  1484. break;
  1485. case CXT5051_PORTB_EVENT:
  1486. cxt5051_portb_automic(codec);
  1487. break;
  1488. case CXT5051_PORTC_EVENT:
  1489. cxt5051_portc_automic(codec);
  1490. break;
  1491. }
  1492. conexant_report_jack(codec, nid);
  1493. }
  1494. static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1495. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1496. {
  1497. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1498. .name = "Master Playback Switch",
  1499. .info = cxt_eapd_info,
  1500. .get = cxt_eapd_get,
  1501. .put = cxt5051_hp_master_sw_put,
  1502. .private_value = 0x1a,
  1503. },
  1504. {}
  1505. };
  1506. static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1507. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1508. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1509. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1510. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1511. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1512. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1513. {}
  1514. };
  1515. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1516. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1517. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1518. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1519. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1520. {}
  1521. };
  1522. static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1523. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1524. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1525. {}
  1526. };
  1527. static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1528. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1529. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1530. {}
  1531. };
  1532. static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1533. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1534. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1535. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1536. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1537. {}
  1538. };
  1539. static struct hda_verb cxt5051_init_verbs[] = {
  1540. /* Line in, Mic */
  1541. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1542. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1543. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1544. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1545. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1546. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1547. /* SPK */
  1548. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1549. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1550. /* HP, Amp */
  1551. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1552. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1553. /* DAC1 */
  1554. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1555. /* Record selector: Int mic */
  1556. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1557. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1558. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1559. /* SPDIF route: PCM */
  1560. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1561. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1562. /* EAPD */
  1563. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1564. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1565. { } /* end */
  1566. };
  1567. static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1568. /* Line in, Mic */
  1569. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1570. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1571. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1572. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1573. /* SPK */
  1574. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1575. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1576. /* HP, Amp */
  1577. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1578. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1579. /* DAC1 */
  1580. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1581. /* Record selector: Int mic */
  1582. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1583. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1584. /* SPDIF route: PCM */
  1585. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1586. /* EAPD */
  1587. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1588. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1589. { } /* end */
  1590. };
  1591. static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1592. /* Line in, Mic */
  1593. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1594. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1595. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1596. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1597. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1598. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1599. /* SPK */
  1600. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1601. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1602. /* HP, Amp */
  1603. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1604. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1605. /* Docking HP */
  1606. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1607. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1608. /* DAC1 */
  1609. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1610. /* Record selector: Int mic */
  1611. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1612. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1613. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1614. /* SPDIF route: PCM */
  1615. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
  1616. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1617. /* EAPD */
  1618. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1619. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1620. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1621. { } /* end */
  1622. };
  1623. static struct hda_verb cxt5051_f700_init_verbs[] = {
  1624. /* Line in, Mic */
  1625. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1626. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1627. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1628. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1629. /* SPK */
  1630. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1631. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1632. /* HP, Amp */
  1633. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1634. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1635. /* DAC1 */
  1636. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1637. /* Record selector: Int mic */
  1638. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1639. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1640. /* SPDIF route: PCM */
  1641. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1642. /* EAPD */
  1643. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1644. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1645. { } /* end */
  1646. };
  1647. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1648. unsigned int event)
  1649. {
  1650. snd_hda_codec_write(codec, nid, 0,
  1651. AC_VERB_SET_UNSOLICITED_ENABLE,
  1652. AC_USRSP_EN | event);
  1653. #ifdef CONFIG_SND_HDA_INPUT_JACK
  1654. conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
  1655. conexant_report_jack(codec, nid);
  1656. #endif
  1657. }
  1658. /* initialize jack-sensing, too */
  1659. static int cxt5051_init(struct hda_codec *codec)
  1660. {
  1661. struct conexant_spec *spec = codec->spec;
  1662. conexant_init(codec);
  1663. conexant_init_jacks(codec);
  1664. if (spec->auto_mic & AUTO_MIC_PORTB)
  1665. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1666. if (spec->auto_mic & AUTO_MIC_PORTC)
  1667. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1668. if (codec->patch_ops.unsol_event) {
  1669. cxt5051_hp_automute(codec);
  1670. cxt5051_portb_automic(codec);
  1671. cxt5051_portc_automic(codec);
  1672. }
  1673. return 0;
  1674. }
  1675. enum {
  1676. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1677. CXT5051_HP, /* no docking */
  1678. CXT5051_HP_DV6736, /* HP without mic switch */
  1679. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1680. CXT5051_F700, /* HP Compaq Presario F700 */
  1681. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1682. CXT5051_MODELS
  1683. };
  1684. static const char *cxt5051_models[CXT5051_MODELS] = {
  1685. [CXT5051_LAPTOP] = "laptop",
  1686. [CXT5051_HP] = "hp",
  1687. [CXT5051_HP_DV6736] = "hp-dv6736",
  1688. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1689. [CXT5051_F700] = "hp-700",
  1690. [CXT5051_TOSHIBA] = "toshiba",
  1691. };
  1692. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1693. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1694. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1695. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1696. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1697. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1698. CXT5051_LAPTOP),
  1699. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1700. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1701. {}
  1702. };
  1703. static int patch_cxt5051(struct hda_codec *codec)
  1704. {
  1705. struct conexant_spec *spec;
  1706. int board_config;
  1707. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1708. if (!spec)
  1709. return -ENOMEM;
  1710. codec->spec = spec;
  1711. codec->pin_amp_workaround = 1;
  1712. codec->patch_ops = conexant_patch_ops;
  1713. codec->patch_ops.init = cxt5051_init;
  1714. spec->multiout.max_channels = 2;
  1715. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1716. spec->multiout.dac_nids = cxt5051_dac_nids;
  1717. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1718. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1719. spec->adc_nids = cxt5051_adc_nids;
  1720. spec->num_mixers = 2;
  1721. spec->mixers[0] = cxt5051_capture_mixers;
  1722. spec->mixers[1] = cxt5051_playback_mixers;
  1723. spec->num_init_verbs = 1;
  1724. spec->init_verbs[0] = cxt5051_init_verbs;
  1725. spec->spdif_route = 0;
  1726. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1727. spec->channel_mode = cxt5051_modes;
  1728. spec->cur_adc = 0;
  1729. spec->cur_adc_idx = 0;
  1730. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1731. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1732. cxt5051_models,
  1733. cxt5051_cfg_tbl);
  1734. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1735. switch (board_config) {
  1736. case CXT5051_HP:
  1737. spec->mixers[0] = cxt5051_hp_mixers;
  1738. break;
  1739. case CXT5051_HP_DV6736:
  1740. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1741. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1742. spec->auto_mic = 0;
  1743. break;
  1744. case CXT5051_LENOVO_X200:
  1745. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1746. break;
  1747. case CXT5051_F700:
  1748. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1749. spec->mixers[0] = cxt5051_f700_mixers;
  1750. spec->auto_mic = 0;
  1751. break;
  1752. case CXT5051_TOSHIBA:
  1753. spec->mixers[0] = cxt5051_toshiba_mixers;
  1754. spec->auto_mic = AUTO_MIC_PORTB;
  1755. break;
  1756. }
  1757. return 0;
  1758. }
  1759. /* Conexant 5066 specific */
  1760. static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1761. static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1762. static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1763. #define CXT5066_SPDIF_OUT 0x21
  1764. /* OLPC's microphone port is DC coupled for use with external sensors,
  1765. * therefore we use a 50% mic bias in order to center the input signal with
  1766. * the DC input range of the codec. */
  1767. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1768. static struct hda_channel_mode cxt5066_modes[1] = {
  1769. { 2, NULL },
  1770. };
  1771. static void cxt5066_update_speaker(struct hda_codec *codec)
  1772. {
  1773. struct conexant_spec *spec = codec->spec;
  1774. unsigned int pinctl;
  1775. snd_printdd("CXT5066: update speaker, hp_present=%d\n",
  1776. spec->hp_present);
  1777. /* Port A (HP) */
  1778. pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
  1779. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1780. pinctl);
  1781. /* Port D (HP/LO) */
  1782. pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
  1783. ? spec->port_d_mode : 0;
  1784. /* Mute if Port A is connected on Thinkpad */
  1785. if (spec->thinkpad && (spec->hp_present & 1))
  1786. pinctl = 0;
  1787. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1788. pinctl);
  1789. /* CLASS_D AMP */
  1790. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1791. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1792. pinctl);
  1793. if (spec->dell_automute) {
  1794. /* DELL AIO Port Rule: PortA > PortD > IntSpk */
  1795. pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
  1796. ? PIN_OUT : 0;
  1797. snd_hda_codec_write(codec, 0x1c, 0,
  1798. AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
  1799. }
  1800. }
  1801. /* turn on/off EAPD (+ mute HP) as a master switch */
  1802. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1803. struct snd_ctl_elem_value *ucontrol)
  1804. {
  1805. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1806. if (!cxt_eapd_put(kcontrol, ucontrol))
  1807. return 0;
  1808. cxt5066_update_speaker(codec);
  1809. return 1;
  1810. }
  1811. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1812. .num_items = 3,
  1813. .items = {
  1814. { "Off", PIN_IN },
  1815. { "50%", PIN_VREF50 },
  1816. { "80%", PIN_VREF80 },
  1817. },
  1818. };
  1819. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1820. {
  1821. struct conexant_spec *spec = codec->spec;
  1822. /* Even though port F is the DC input, the bias is controlled on port B.
  1823. * we also leave that port as an active input (but unselected) in DC mode
  1824. * just in case that is necessary to make the bias setting take effect. */
  1825. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1826. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1827. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1828. }
  1829. /* OLPC defers mic widget control until when capture is started because the
  1830. * microphone LED comes on as soon as these settings are put in place. if we
  1831. * did this before recording, it would give the false indication that recording
  1832. * is happening when it is not. */
  1833. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1834. {
  1835. struct conexant_spec *spec = codec->spec;
  1836. if (!spec->recording)
  1837. return;
  1838. if (spec->dc_enable) {
  1839. /* in DC mode we ignore presence detection and just use the jack
  1840. * through our special DC port */
  1841. const struct hda_verb enable_dc_mode[] = {
  1842. /* disble internal mic, port C */
  1843. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1844. /* enable DC capture, port F */
  1845. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1846. {},
  1847. };
  1848. snd_hda_sequence_write(codec, enable_dc_mode);
  1849. /* port B input disabled (and bias set) through the following call */
  1850. cxt5066_set_olpc_dc_bias(codec);
  1851. return;
  1852. }
  1853. /* disable DC (port F) */
  1854. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1855. /* external mic, port B */
  1856. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1857. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1858. /* internal mic, port C */
  1859. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1860. spec->ext_mic_present ? 0 : PIN_VREF80);
  1861. }
  1862. /* toggle input of built-in and mic jack appropriately */
  1863. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1864. {
  1865. struct conexant_spec *spec = codec->spec;
  1866. unsigned int present;
  1867. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1868. return;
  1869. present = snd_hda_codec_read(codec, 0x1a, 0,
  1870. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1871. if (present)
  1872. snd_printdd("CXT5066: external microphone detected\n");
  1873. else
  1874. snd_printdd("CXT5066: external microphone absent\n");
  1875. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1876. present ? 0 : 1);
  1877. spec->ext_mic_present = !!present;
  1878. cxt5066_olpc_select_mic(codec);
  1879. }
  1880. /* toggle input of built-in digital mic and mic jack appropriately */
  1881. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1882. {
  1883. unsigned int present;
  1884. struct hda_verb ext_mic_present[] = {
  1885. /* enable external mic, port B */
  1886. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1887. /* switch to external mic input */
  1888. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1889. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1890. /* disable internal digital mic */
  1891. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1892. {}
  1893. };
  1894. static struct hda_verb ext_mic_absent[] = {
  1895. /* enable internal mic, port C */
  1896. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1897. /* switch to internal mic input */
  1898. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1899. /* disable external mic, port B */
  1900. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1901. {}
  1902. };
  1903. present = snd_hda_jack_detect(codec, 0x1a);
  1904. if (present) {
  1905. snd_printdd("CXT5066: external microphone detected\n");
  1906. snd_hda_sequence_write(codec, ext_mic_present);
  1907. } else {
  1908. snd_printdd("CXT5066: external microphone absent\n");
  1909. snd_hda_sequence_write(codec, ext_mic_absent);
  1910. }
  1911. }
  1912. /* toggle input of built-in digital mic and mic jack appropriately */
  1913. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1914. {
  1915. unsigned int present;
  1916. struct hda_verb ext_mic_present[] = {
  1917. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1918. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1919. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1920. {}
  1921. };
  1922. static struct hda_verb ext_mic_absent[] = {
  1923. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1924. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1925. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1926. {}
  1927. };
  1928. present = snd_hda_jack_detect(codec, 0x1b);
  1929. if (present) {
  1930. snd_printdd("CXT5066: external microphone detected\n");
  1931. snd_hda_sequence_write(codec, ext_mic_present);
  1932. } else {
  1933. snd_printdd("CXT5066: external microphone absent\n");
  1934. snd_hda_sequence_write(codec, ext_mic_absent);
  1935. }
  1936. }
  1937. /* toggle input of built-in digital mic and mic jack appropriately
  1938. order is: external mic -> dock mic -> interal mic */
  1939. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1940. {
  1941. unsigned int ext_present, dock_present;
  1942. static struct hda_verb ext_mic_present[] = {
  1943. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1944. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1945. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1946. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1947. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1948. {}
  1949. };
  1950. static struct hda_verb dock_mic_present[] = {
  1951. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1952. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1953. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1954. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1955. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1956. {}
  1957. };
  1958. static struct hda_verb ext_mic_absent[] = {
  1959. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1960. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1961. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1962. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1963. {}
  1964. };
  1965. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1966. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1967. if (ext_present) {
  1968. snd_printdd("CXT5066: external microphone detected\n");
  1969. snd_hda_sequence_write(codec, ext_mic_present);
  1970. } else if (dock_present) {
  1971. snd_printdd("CXT5066: dock microphone detected\n");
  1972. snd_hda_sequence_write(codec, dock_mic_present);
  1973. } else {
  1974. snd_printdd("CXT5066: external microphone absent\n");
  1975. snd_hda_sequence_write(codec, ext_mic_absent);
  1976. }
  1977. }
  1978. /* mute internal speaker if HP is plugged */
  1979. static void cxt5066_hp_automute(struct hda_codec *codec)
  1980. {
  1981. struct conexant_spec *spec = codec->spec;
  1982. unsigned int portA, portD;
  1983. /* Port A */
  1984. portA = snd_hda_jack_detect(codec, 0x19);
  1985. /* Port D */
  1986. portD = snd_hda_jack_detect(codec, 0x1c);
  1987. spec->hp_present = !!(portA);
  1988. spec->hp_present |= portD ? 2 : 0;
  1989. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1990. portA, portD, spec->hp_present);
  1991. cxt5066_update_speaker(codec);
  1992. }
  1993. /* unsolicited event for jack sensing */
  1994. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  1995. {
  1996. struct conexant_spec *spec = codec->spec;
  1997. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1998. switch (res >> 26) {
  1999. case CONEXANT_HP_EVENT:
  2000. cxt5066_hp_automute(codec);
  2001. break;
  2002. case CONEXANT_MIC_EVENT:
  2003. /* ignore mic events in DC mode; we're always using the jack */
  2004. if (!spec->dc_enable)
  2005. cxt5066_olpc_automic(codec);
  2006. break;
  2007. }
  2008. }
  2009. /* unsolicited event for jack sensing */
  2010. static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
  2011. {
  2012. snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
  2013. switch (res >> 26) {
  2014. case CONEXANT_HP_EVENT:
  2015. cxt5066_hp_automute(codec);
  2016. break;
  2017. case CONEXANT_MIC_EVENT:
  2018. cxt5066_vostro_automic(codec);
  2019. break;
  2020. }
  2021. }
  2022. /* unsolicited event for jack sensing */
  2023. static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
  2024. {
  2025. snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
  2026. switch (res >> 26) {
  2027. case CONEXANT_HP_EVENT:
  2028. cxt5066_hp_automute(codec);
  2029. break;
  2030. case CONEXANT_MIC_EVENT:
  2031. cxt5066_ideapad_automic(codec);
  2032. break;
  2033. }
  2034. }
  2035. /* unsolicited event for jack sensing */
  2036. static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
  2037. {
  2038. snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
  2039. switch (res >> 26) {
  2040. case CONEXANT_HP_EVENT:
  2041. cxt5066_hp_automute(codec);
  2042. break;
  2043. case CONEXANT_MIC_EVENT:
  2044. cxt5066_thinkpad_automic(codec);
  2045. break;
  2046. }
  2047. }
  2048. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2049. .num_items = 5,
  2050. .items = {
  2051. { "0dB", 0 },
  2052. { "10dB", 1 },
  2053. { "20dB", 2 },
  2054. { "30dB", 3 },
  2055. { "40dB", 4 },
  2056. },
  2057. };
  2058. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2059. {
  2060. struct conexant_spec *spec = codec->spec;
  2061. snd_hda_codec_write_cache(codec, 0x17, 0,
  2062. AC_VERB_SET_AMP_GAIN_MUTE,
  2063. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2064. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2065. if (spec->ideapad || spec->thinkpad) {
  2066. /* adjust the internal mic as well...it is not through 0x17 */
  2067. snd_hda_codec_write_cache(codec, 0x23, 0,
  2068. AC_VERB_SET_AMP_GAIN_MUTE,
  2069. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2070. cxt5066_analog_mic_boost.
  2071. items[spec->mic_boost].index);
  2072. }
  2073. }
  2074. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2075. struct snd_ctl_elem_info *uinfo)
  2076. {
  2077. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2078. }
  2079. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2080. struct snd_ctl_elem_value *ucontrol)
  2081. {
  2082. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2083. struct conexant_spec *spec = codec->spec;
  2084. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2085. return 0;
  2086. }
  2087. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2088. struct snd_ctl_elem_value *ucontrol)
  2089. {
  2090. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2091. struct conexant_spec *spec = codec->spec;
  2092. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2093. unsigned int idx;
  2094. idx = ucontrol->value.enumerated.item[0];
  2095. if (idx >= imux->num_items)
  2096. idx = imux->num_items - 1;
  2097. spec->mic_boost = idx;
  2098. if (!spec->dc_enable)
  2099. cxt5066_set_mic_boost(codec);
  2100. return 1;
  2101. }
  2102. static void cxt5066_enable_dc(struct hda_codec *codec)
  2103. {
  2104. const struct hda_verb enable_dc_mode[] = {
  2105. /* disable gain */
  2106. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2107. /* switch to DC input */
  2108. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2109. {}
  2110. };
  2111. /* configure as input source */
  2112. snd_hda_sequence_write(codec, enable_dc_mode);
  2113. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2114. }
  2115. static void cxt5066_disable_dc(struct hda_codec *codec)
  2116. {
  2117. /* reconfigure input source */
  2118. cxt5066_set_mic_boost(codec);
  2119. /* automic also selects the right mic if we're recording */
  2120. cxt5066_olpc_automic(codec);
  2121. }
  2122. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2123. struct snd_ctl_elem_value *ucontrol)
  2124. {
  2125. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2126. struct conexant_spec *spec = codec->spec;
  2127. ucontrol->value.integer.value[0] = spec->dc_enable;
  2128. return 0;
  2129. }
  2130. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2131. struct snd_ctl_elem_value *ucontrol)
  2132. {
  2133. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2134. struct conexant_spec *spec = codec->spec;
  2135. int dc_enable = !!ucontrol->value.integer.value[0];
  2136. if (dc_enable == spec->dc_enable)
  2137. return 0;
  2138. spec->dc_enable = dc_enable;
  2139. if (dc_enable)
  2140. cxt5066_enable_dc(codec);
  2141. else
  2142. cxt5066_disable_dc(codec);
  2143. return 1;
  2144. }
  2145. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2146. struct snd_ctl_elem_info *uinfo)
  2147. {
  2148. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2149. }
  2150. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2151. struct snd_ctl_elem_value *ucontrol)
  2152. {
  2153. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2154. struct conexant_spec *spec = codec->spec;
  2155. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2156. return 0;
  2157. }
  2158. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2159. struct snd_ctl_elem_value *ucontrol)
  2160. {
  2161. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2162. struct conexant_spec *spec = codec->spec;
  2163. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2164. unsigned int idx;
  2165. idx = ucontrol->value.enumerated.item[0];
  2166. if (idx >= imux->num_items)
  2167. idx = imux->num_items - 1;
  2168. spec->dc_input_bias = idx;
  2169. if (spec->dc_enable)
  2170. cxt5066_set_olpc_dc_bias(codec);
  2171. return 1;
  2172. }
  2173. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2174. {
  2175. struct conexant_spec *spec = codec->spec;
  2176. /* mark as recording and configure the microphone widget so that the
  2177. * recording LED comes on. */
  2178. spec->recording = 1;
  2179. cxt5066_olpc_select_mic(codec);
  2180. }
  2181. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2182. {
  2183. struct conexant_spec *spec = codec->spec;
  2184. const struct hda_verb disable_mics[] = {
  2185. /* disable external mic, port B */
  2186. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2187. /* disble internal mic, port C */
  2188. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2189. /* disable DC capture, port F */
  2190. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2191. {},
  2192. };
  2193. snd_hda_sequence_write(codec, disable_mics);
  2194. spec->recording = 0;
  2195. }
  2196. static struct hda_input_mux cxt5066_capture_source = {
  2197. .num_items = 4,
  2198. .items = {
  2199. { "Mic B", 0 },
  2200. { "Mic C", 1 },
  2201. { "Mic E", 2 },
  2202. { "Mic F", 3 },
  2203. },
  2204. };
  2205. static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2206. .ops = &snd_hda_bind_vol,
  2207. .values = {
  2208. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2209. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2210. 0
  2211. },
  2212. };
  2213. static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2214. .ops = &snd_hda_bind_sw,
  2215. .values = {
  2216. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2217. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2218. 0
  2219. },
  2220. };
  2221. static struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2222. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2223. {}
  2224. };
  2225. static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2226. {
  2227. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2228. .name = "Master Playback Volume",
  2229. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2230. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2231. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2232. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2233. .info = snd_hda_mixer_amp_volume_info,
  2234. .get = snd_hda_mixer_amp_volume_get,
  2235. .put = snd_hda_mixer_amp_volume_put,
  2236. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2237. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2238. .private_value =
  2239. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2240. },
  2241. {}
  2242. };
  2243. static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2244. {
  2245. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2246. .name = "DC Mode Enable Switch",
  2247. .info = snd_ctl_boolean_mono_info,
  2248. .get = cxt5066_olpc_dc_get,
  2249. .put = cxt5066_olpc_dc_put,
  2250. },
  2251. {
  2252. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2253. .name = "DC Input Bias Enum",
  2254. .info = cxt5066_olpc_dc_bias_enum_info,
  2255. .get = cxt5066_olpc_dc_bias_enum_get,
  2256. .put = cxt5066_olpc_dc_bias_enum_put,
  2257. },
  2258. {}
  2259. };
  2260. static struct snd_kcontrol_new cxt5066_mixers[] = {
  2261. {
  2262. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2263. .name = "Master Playback Switch",
  2264. .info = cxt_eapd_info,
  2265. .get = cxt_eapd_get,
  2266. .put = cxt5066_hp_master_sw_put,
  2267. .private_value = 0x1d,
  2268. },
  2269. {
  2270. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2271. .name = "Analog Mic Boost Capture Enum",
  2272. .info = cxt5066_mic_boost_mux_enum_info,
  2273. .get = cxt5066_mic_boost_mux_enum_get,
  2274. .put = cxt5066_mic_boost_mux_enum_put,
  2275. },
  2276. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2277. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2278. {}
  2279. };
  2280. static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2281. {
  2282. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2283. .name = "Int Mic Boost Capture Enum",
  2284. .info = cxt5066_mic_boost_mux_enum_info,
  2285. .get = cxt5066_mic_boost_mux_enum_get,
  2286. .put = cxt5066_mic_boost_mux_enum_put,
  2287. .private_value = 0x23 | 0x100,
  2288. },
  2289. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  2290. {}
  2291. };
  2292. static struct hda_verb cxt5066_init_verbs[] = {
  2293. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2294. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2295. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2296. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2297. /* Speakers */
  2298. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2299. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2300. /* HP, Amp */
  2301. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2302. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2303. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2304. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2305. /* DAC1 */
  2306. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2307. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2308. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2309. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2310. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2311. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2312. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2313. /* no digital microphone support yet */
  2314. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2315. /* Audio input selector */
  2316. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2317. /* SPDIF route: PCM */
  2318. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2319. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2320. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2321. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2322. /* EAPD */
  2323. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2324. /* not handling these yet */
  2325. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2326. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2327. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2328. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2329. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2330. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2331. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2332. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2333. { } /* end */
  2334. };
  2335. static struct hda_verb cxt5066_init_verbs_olpc[] = {
  2336. /* Port A: headphones */
  2337. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2338. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2339. /* Port B: external microphone */
  2340. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2341. /* Port C: internal microphone */
  2342. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2343. /* Port D: unused */
  2344. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2345. /* Port E: unused, but has primary EAPD */
  2346. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2347. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2348. /* Port F: external DC input through microphone port */
  2349. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2350. /* Port G: internal speakers */
  2351. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2352. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2353. /* DAC1 */
  2354. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2355. /* DAC2: unused */
  2356. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2357. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2358. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2359. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2360. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2361. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2362. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2363. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2364. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2365. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2366. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2367. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2368. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2369. /* Disable digital microphone port */
  2370. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2371. /* Audio input selectors */
  2372. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2373. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2374. /* Disable SPDIF */
  2375. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2376. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2377. /* enable unsolicited events for Port A and B */
  2378. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2379. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2380. { } /* end */
  2381. };
  2382. static struct hda_verb cxt5066_init_verbs_vostro[] = {
  2383. /* Port A: headphones */
  2384. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2385. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2386. /* Port B: external microphone */
  2387. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2388. /* Port C: unused */
  2389. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2390. /* Port D: unused */
  2391. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2392. /* Port E: unused, but has primary EAPD */
  2393. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2394. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2395. /* Port F: unused */
  2396. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2397. /* Port G: internal speakers */
  2398. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2399. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2400. /* DAC1 */
  2401. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2402. /* DAC2: unused */
  2403. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2404. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2405. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2406. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2407. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2408. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2409. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2410. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2411. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2412. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2413. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2414. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2415. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2416. /* Digital microphone port */
  2417. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2418. /* Audio input selectors */
  2419. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2420. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2421. /* Disable SPDIF */
  2422. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2423. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2424. /* enable unsolicited events for Port A and B */
  2425. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2426. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2427. { } /* end */
  2428. };
  2429. static struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2430. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2431. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2432. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2433. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2434. /* Speakers */
  2435. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2436. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2437. /* HP, Amp */
  2438. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2439. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2440. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2441. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2442. /* DAC1 */
  2443. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2444. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2445. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2446. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2447. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2448. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2449. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2450. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2451. /* Audio input selector */
  2452. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2453. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2454. /* SPDIF route: PCM */
  2455. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2456. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2457. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2458. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2459. /* internal microphone */
  2460. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2461. /* EAPD */
  2462. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2463. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2464. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2465. { } /* end */
  2466. };
  2467. static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2468. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2469. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2470. /* Port G: internal speakers */
  2471. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2472. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2473. /* Port A: HP, Amp */
  2474. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2475. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2476. /* Port B: Mic Dock */
  2477. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2478. /* Port C: Mic */
  2479. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2480. /* Port D: HP Dock, Amp */
  2481. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2482. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2483. /* DAC1 */
  2484. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2485. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2486. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2487. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2488. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2489. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2490. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2491. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2492. /* Audio input selector */
  2493. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2494. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2495. /* SPDIF route: PCM */
  2496. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2497. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2498. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2499. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2500. /* internal microphone */
  2501. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2502. /* EAPD */
  2503. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2504. /* enable unsolicited events for Port A, B, C and D */
  2505. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2506. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2507. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2508. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2509. { } /* end */
  2510. };
  2511. static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2512. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2513. { } /* end */
  2514. };
  2515. /* initialize jack-sensing, too */
  2516. static int cxt5066_init(struct hda_codec *codec)
  2517. {
  2518. struct conexant_spec *spec = codec->spec;
  2519. snd_printdd("CXT5066: init\n");
  2520. conexant_init(codec);
  2521. if (codec->patch_ops.unsol_event) {
  2522. cxt5066_hp_automute(codec);
  2523. if (spec->dell_vostro)
  2524. cxt5066_vostro_automic(codec);
  2525. else if (spec->ideapad)
  2526. cxt5066_ideapad_automic(codec);
  2527. else if (spec->thinkpad)
  2528. cxt5066_thinkpad_automic(codec);
  2529. }
  2530. cxt5066_set_mic_boost(codec);
  2531. return 0;
  2532. }
  2533. static int cxt5066_olpc_init(struct hda_codec *codec)
  2534. {
  2535. struct conexant_spec *spec = codec->spec;
  2536. snd_printdd("CXT5066: init\n");
  2537. conexant_init(codec);
  2538. cxt5066_hp_automute(codec);
  2539. if (!spec->dc_enable) {
  2540. cxt5066_set_mic_boost(codec);
  2541. cxt5066_olpc_automic(codec);
  2542. } else {
  2543. cxt5066_enable_dc(codec);
  2544. }
  2545. return 0;
  2546. }
  2547. enum {
  2548. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2549. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2550. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2551. CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
  2552. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2553. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2554. CXT5066_MODELS
  2555. };
  2556. static const char *cxt5066_models[CXT5066_MODELS] = {
  2557. [CXT5066_LAPTOP] = "laptop",
  2558. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2559. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2560. [CXT5066_DELL_VOSTO] = "dell-vostro",
  2561. [CXT5066_IDEAPAD] = "ideapad",
  2562. [CXT5066_THINKPAD] = "thinkpad",
  2563. };
  2564. static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2565. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2566. CXT5066_LAPTOP),
  2567. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
  2568. CXT5066_DELL_LAPTOP),
  2569. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2570. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
  2571. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2572. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2573. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2574. SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
  2575. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2576. {}
  2577. };
  2578. static int patch_cxt5066(struct hda_codec *codec)
  2579. {
  2580. struct conexant_spec *spec;
  2581. int board_config;
  2582. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2583. if (!spec)
  2584. return -ENOMEM;
  2585. codec->spec = spec;
  2586. codec->patch_ops = conexant_patch_ops;
  2587. codec->patch_ops.init = conexant_init;
  2588. spec->dell_automute = 0;
  2589. spec->multiout.max_channels = 2;
  2590. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2591. spec->multiout.dac_nids = cxt5066_dac_nids;
  2592. spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
  2593. spec->num_adc_nids = 1;
  2594. spec->adc_nids = cxt5066_adc_nids;
  2595. spec->capsrc_nids = cxt5066_capsrc_nids;
  2596. spec->input_mux = &cxt5066_capture_source;
  2597. spec->port_d_mode = PIN_HP;
  2598. spec->num_init_verbs = 1;
  2599. spec->init_verbs[0] = cxt5066_init_verbs;
  2600. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2601. spec->channel_mode = cxt5066_modes;
  2602. spec->cur_adc = 0;
  2603. spec->cur_adc_idx = 0;
  2604. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2605. cxt5066_models, cxt5066_cfg_tbl);
  2606. switch (board_config) {
  2607. default:
  2608. case CXT5066_LAPTOP:
  2609. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2610. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2611. break;
  2612. case CXT5066_DELL_LAPTOP:
  2613. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2614. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2615. spec->port_d_mode = PIN_OUT;
  2616. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2617. spec->num_init_verbs++;
  2618. spec->dell_automute = 1;
  2619. break;
  2620. case CXT5066_OLPC_XO_1_5:
  2621. codec->patch_ops.init = cxt5066_olpc_init;
  2622. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2623. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2624. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2625. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2626. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2627. spec->port_d_mode = 0;
  2628. spec->mic_boost = 3; /* default 30dB gain */
  2629. /* no S/PDIF out */
  2630. spec->multiout.dig_out_nid = 0;
  2631. /* input source automatically selected */
  2632. spec->input_mux = NULL;
  2633. /* our capture hooks which allow us to turn on the microphone LED
  2634. * at the right time */
  2635. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2636. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2637. break;
  2638. case CXT5066_DELL_VOSTO:
  2639. codec->patch_ops.init = cxt5066_init;
  2640. codec->patch_ops.unsol_event = cxt5066_vostro_event;
  2641. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2642. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2643. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2644. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2645. spec->port_d_mode = 0;
  2646. spec->dell_vostro = 1;
  2647. spec->mic_boost = 3; /* default 30dB gain */
  2648. snd_hda_attach_beep_device(codec, 0x13);
  2649. /* no S/PDIF out */
  2650. spec->multiout.dig_out_nid = 0;
  2651. /* input source automatically selected */
  2652. spec->input_mux = NULL;
  2653. break;
  2654. case CXT5066_IDEAPAD:
  2655. codec->patch_ops.init = cxt5066_init;
  2656. codec->patch_ops.unsol_event = cxt5066_ideapad_event;
  2657. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2658. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2659. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2660. spec->port_d_mode = 0;
  2661. spec->ideapad = 1;
  2662. spec->mic_boost = 2; /* default 20dB gain */
  2663. /* no S/PDIF out */
  2664. spec->multiout.dig_out_nid = 0;
  2665. /* input source automatically selected */
  2666. spec->input_mux = NULL;
  2667. break;
  2668. case CXT5066_THINKPAD:
  2669. codec->patch_ops.init = cxt5066_init;
  2670. codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
  2671. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2672. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2673. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2674. spec->thinkpad = 1;
  2675. spec->port_d_mode = PIN_OUT;
  2676. spec->mic_boost = 2; /* default 20dB gain */
  2677. /* no S/PDIF out */
  2678. spec->multiout.dig_out_nid = 0;
  2679. /* input source automatically selected */
  2680. spec->input_mux = NULL;
  2681. break;
  2682. }
  2683. return 0;
  2684. }
  2685. /*
  2686. */
  2687. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  2688. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  2689. .patch = patch_cxt5045 },
  2690. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  2691. .patch = patch_cxt5047 },
  2692. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  2693. .patch = patch_cxt5051 },
  2694. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  2695. .patch = patch_cxt5066 },
  2696. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  2697. .patch = patch_cxt5066 },
  2698. { .id = 0x14f15069, .name = "CX20585",
  2699. .patch = patch_cxt5066 },
  2700. {} /* terminator */
  2701. };
  2702. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  2703. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  2704. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  2705. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  2706. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  2707. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  2708. MODULE_LICENSE("GPL");
  2709. MODULE_DESCRIPTION("Conexant HD-audio codec");
  2710. static struct hda_codec_preset_list conexant_list = {
  2711. .preset = snd_hda_preset_conexant,
  2712. .owner = THIS_MODULE,
  2713. };
  2714. static int __init patch_conexant_init(void)
  2715. {
  2716. return snd_hda_add_codec_preset(&conexant_list);
  2717. }
  2718. static void __exit patch_conexant_exit(void)
  2719. {
  2720. snd_hda_delete_codec_preset(&conexant_list);
  2721. }
  2722. module_init(patch_conexant_init)
  2723. module_exit(patch_conexant_exit)