patch_conexant.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683
  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 <linux/module.h>
  27. #include <sound/core.h>
  28. #include <sound/jack.h>
  29. #include "hda_codec.h"
  30. #include "hda_local.h"
  31. #include "hda_beep.h"
  32. #include "hda_jack.h"
  33. #define CXT_PIN_DIR_IN 0x00
  34. #define CXT_PIN_DIR_OUT 0x01
  35. #define CXT_PIN_DIR_INOUT 0x02
  36. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  37. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  38. #define CONEXANT_HP_EVENT 0x37
  39. #define CONEXANT_MIC_EVENT 0x38
  40. #define CONEXANT_LINE_EVENT 0x39
  41. /* Conexant 5051 specific */
  42. #define CXT5051_SPDIF_OUT 0x12
  43. #define CXT5051_PORTB_EVENT 0x38
  44. #define CXT5051_PORTC_EVENT 0x39
  45. #define AUTO_MIC_PORTB (1 << 1)
  46. #define AUTO_MIC_PORTC (1 << 2)
  47. struct pin_dac_pair {
  48. hda_nid_t pin;
  49. hda_nid_t dac;
  50. int type;
  51. };
  52. struct imux_info {
  53. hda_nid_t pin; /* input pin NID */
  54. hda_nid_t adc; /* connected ADC NID */
  55. hda_nid_t boost; /* optional boost volume NID */
  56. int index; /* corresponding to autocfg.input */
  57. };
  58. struct conexant_spec {
  59. const struct snd_kcontrol_new *mixers[5];
  60. int num_mixers;
  61. hda_nid_t vmaster_nid;
  62. struct hda_vmaster_mute_hook vmaster_mute;
  63. bool vmaster_mute_led;
  64. const struct hda_verb *init_verbs[5]; /* initialization verbs
  65. * don't forget NULL
  66. * termination!
  67. */
  68. unsigned int num_init_verbs;
  69. /* playback */
  70. struct hda_multi_out multiout; /* playback set-up
  71. * max_channels, dacs must be set
  72. * dig_out_nid and hp_nid are optional
  73. */
  74. unsigned int cur_eapd;
  75. unsigned int hp_present;
  76. unsigned int line_present;
  77. unsigned int auto_mic;
  78. int auto_mic_ext; /* imux_pins[] index for ext mic */
  79. int auto_mic_dock; /* imux_pins[] index for dock mic */
  80. int auto_mic_int; /* imux_pins[] index for int mic */
  81. unsigned int need_dac_fix;
  82. hda_nid_t slave_dig_outs[2];
  83. /* capture */
  84. unsigned int num_adc_nids;
  85. const hda_nid_t *adc_nids;
  86. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  87. unsigned int cur_adc_idx;
  88. hda_nid_t cur_adc;
  89. unsigned int cur_adc_stream_tag;
  90. unsigned int cur_adc_format;
  91. const struct hda_pcm_stream *capture_stream;
  92. /* capture source */
  93. const struct hda_input_mux *input_mux;
  94. const hda_nid_t *capsrc_nids;
  95. unsigned int cur_mux[3];
  96. /* channel model */
  97. const struct hda_channel_mode *channel_mode;
  98. int num_channel_mode;
  99. /* PCM information */
  100. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  101. unsigned int spdif_route;
  102. /* dynamic controls, init_verbs and input_mux */
  103. struct auto_pin_cfg autocfg;
  104. struct hda_input_mux private_imux;
  105. struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
  106. hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
  107. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  108. struct pin_dac_pair dac_info[8];
  109. int dac_info_filled;
  110. unsigned int port_d_mode;
  111. unsigned int auto_mute:1; /* used in auto-parser */
  112. unsigned int detect_line:1; /* Line-out detection enabled */
  113. unsigned int automute_lines:1; /* automute line-out as well */
  114. unsigned int automute_hp_lo:1; /* both HP and LO available */
  115. unsigned int dell_automute:1;
  116. unsigned int dell_vostro:1;
  117. unsigned int ideapad:1;
  118. unsigned int thinkpad:1;
  119. unsigned int hp_laptop:1;
  120. unsigned int asus:1;
  121. unsigned int pin_eapd_ctrls:1;
  122. unsigned int fixup_stereo_dmic:1;
  123. unsigned int adc_switching:1;
  124. unsigned int ext_mic_present;
  125. unsigned int recording;
  126. void (*capture_prepare)(struct hda_codec *codec);
  127. void (*capture_cleanup)(struct hda_codec *codec);
  128. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  129. * through the microphone jack.
  130. * When the user enables this through a mixer switch, both internal and
  131. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  132. * we also allow the bias to be configured through a separate mixer
  133. * control. */
  134. unsigned int dc_enable;
  135. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  136. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  137. unsigned int beep_amp;
  138. /* extra EAPD pins */
  139. unsigned int num_eapds;
  140. hda_nid_t eapds[4];
  141. };
  142. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  143. struct hda_codec *codec,
  144. struct snd_pcm_substream *substream)
  145. {
  146. struct conexant_spec *spec = codec->spec;
  147. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  148. hinfo);
  149. }
  150. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  151. struct hda_codec *codec,
  152. unsigned int stream_tag,
  153. unsigned int format,
  154. struct snd_pcm_substream *substream)
  155. {
  156. struct conexant_spec *spec = codec->spec;
  157. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  158. stream_tag,
  159. format, substream);
  160. }
  161. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  162. struct hda_codec *codec,
  163. struct snd_pcm_substream *substream)
  164. {
  165. struct conexant_spec *spec = codec->spec;
  166. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  167. }
  168. /*
  169. * Digital out
  170. */
  171. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  172. struct hda_codec *codec,
  173. struct snd_pcm_substream *substream)
  174. {
  175. struct conexant_spec *spec = codec->spec;
  176. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  177. }
  178. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  179. struct hda_codec *codec,
  180. struct snd_pcm_substream *substream)
  181. {
  182. struct conexant_spec *spec = codec->spec;
  183. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  184. }
  185. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  186. struct hda_codec *codec,
  187. unsigned int stream_tag,
  188. unsigned int format,
  189. struct snd_pcm_substream *substream)
  190. {
  191. struct conexant_spec *spec = codec->spec;
  192. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  193. stream_tag,
  194. format, substream);
  195. }
  196. /*
  197. * Analog capture
  198. */
  199. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  200. struct hda_codec *codec,
  201. unsigned int stream_tag,
  202. unsigned int format,
  203. struct snd_pcm_substream *substream)
  204. {
  205. struct conexant_spec *spec = codec->spec;
  206. if (spec->capture_prepare)
  207. spec->capture_prepare(codec);
  208. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  209. stream_tag, 0, format);
  210. return 0;
  211. }
  212. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  213. struct hda_codec *codec,
  214. struct snd_pcm_substream *substream)
  215. {
  216. struct conexant_spec *spec = codec->spec;
  217. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  218. if (spec->capture_cleanup)
  219. spec->capture_cleanup(codec);
  220. return 0;
  221. }
  222. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  223. .substreams = 1,
  224. .channels_min = 2,
  225. .channels_max = 2,
  226. .nid = 0, /* fill later */
  227. .ops = {
  228. .open = conexant_playback_pcm_open,
  229. .prepare = conexant_playback_pcm_prepare,
  230. .cleanup = conexant_playback_pcm_cleanup
  231. },
  232. };
  233. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  234. .substreams = 1,
  235. .channels_min = 2,
  236. .channels_max = 2,
  237. .nid = 0, /* fill later */
  238. .ops = {
  239. .prepare = conexant_capture_pcm_prepare,
  240. .cleanup = conexant_capture_pcm_cleanup
  241. },
  242. };
  243. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  244. .substreams = 1,
  245. .channels_min = 2,
  246. .channels_max = 2,
  247. .nid = 0, /* fill later */
  248. .ops = {
  249. .open = conexant_dig_playback_pcm_open,
  250. .close = conexant_dig_playback_pcm_close,
  251. .prepare = conexant_dig_playback_pcm_prepare
  252. },
  253. };
  254. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  255. .substreams = 1,
  256. .channels_min = 2,
  257. .channels_max = 2,
  258. /* NID is set in alc_build_pcms */
  259. };
  260. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  261. struct hda_codec *codec,
  262. unsigned int stream_tag,
  263. unsigned int format,
  264. struct snd_pcm_substream *substream)
  265. {
  266. struct conexant_spec *spec = codec->spec;
  267. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  268. spec->cur_adc_stream_tag = stream_tag;
  269. spec->cur_adc_format = format;
  270. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  271. return 0;
  272. }
  273. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  274. struct hda_codec *codec,
  275. struct snd_pcm_substream *substream)
  276. {
  277. struct conexant_spec *spec = codec->spec;
  278. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  279. spec->cur_adc = 0;
  280. return 0;
  281. }
  282. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  283. .substreams = 1,
  284. .channels_min = 2,
  285. .channels_max = 2,
  286. .nid = 0, /* fill later */
  287. .ops = {
  288. .prepare = cx5051_capture_pcm_prepare,
  289. .cleanup = cx5051_capture_pcm_cleanup
  290. },
  291. };
  292. static int conexant_build_pcms(struct hda_codec *codec)
  293. {
  294. struct conexant_spec *spec = codec->spec;
  295. struct hda_pcm *info = spec->pcm_rec;
  296. codec->num_pcms = 1;
  297. codec->pcm_info = info;
  298. info->name = "CONEXANT Analog";
  299. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  300. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  301. spec->multiout.max_channels;
  302. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  303. spec->multiout.dac_nids[0];
  304. if (spec->capture_stream)
  305. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  306. else {
  307. if (codec->vendor_id == 0x14f15051)
  308. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  309. cx5051_pcm_analog_capture;
  310. else {
  311. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  312. conexant_pcm_analog_capture;
  313. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  314. spec->num_adc_nids;
  315. }
  316. }
  317. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  318. if (spec->multiout.dig_out_nid) {
  319. info++;
  320. codec->num_pcms++;
  321. info->name = "Conexant Digital";
  322. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  323. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  324. conexant_pcm_digital_playback;
  325. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  326. spec->multiout.dig_out_nid;
  327. if (spec->dig_in_nid) {
  328. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  329. conexant_pcm_digital_capture;
  330. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  331. spec->dig_in_nid;
  332. }
  333. if (spec->slave_dig_outs[0])
  334. codec->slave_dig_outs = spec->slave_dig_outs;
  335. }
  336. return 0;
  337. }
  338. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  339. struct snd_ctl_elem_info *uinfo)
  340. {
  341. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  342. struct conexant_spec *spec = codec->spec;
  343. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  344. }
  345. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  346. struct snd_ctl_elem_value *ucontrol)
  347. {
  348. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  349. struct conexant_spec *spec = codec->spec;
  350. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  351. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  352. return 0;
  353. }
  354. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  355. struct snd_ctl_elem_value *ucontrol)
  356. {
  357. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  358. struct conexant_spec *spec = codec->spec;
  359. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  360. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  361. spec->capsrc_nids[adc_idx],
  362. &spec->cur_mux[adc_idx]);
  363. }
  364. static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
  365. unsigned int power_state)
  366. {
  367. if (power_state == AC_PWRST_D3)
  368. msleep(100);
  369. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  370. power_state);
  371. /* partial workaround for "azx_get_response timeout" */
  372. if (power_state == AC_PWRST_D0)
  373. msleep(10);
  374. snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
  375. }
  376. static int conexant_init(struct hda_codec *codec)
  377. {
  378. struct conexant_spec *spec = codec->spec;
  379. int i;
  380. for (i = 0; i < spec->num_init_verbs; i++)
  381. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  382. return 0;
  383. }
  384. static void conexant_free(struct hda_codec *codec)
  385. {
  386. snd_hda_detach_beep_device(codec);
  387. kfree(codec->spec);
  388. }
  389. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  390. {
  391. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  392. .name = "Capture Source",
  393. .info = conexant_mux_enum_info,
  394. .get = conexant_mux_enum_get,
  395. .put = conexant_mux_enum_put
  396. },
  397. {}
  398. };
  399. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  400. /* additional beep mixers; the actual parameters are overwritten at build */
  401. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  402. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  403. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  404. { } /* end */
  405. };
  406. #endif
  407. static const char * const slave_pfxs[] = {
  408. "Headphone", "Speaker", "Front", "Surround", "CLFE",
  409. NULL
  410. };
  411. static int conexant_build_controls(struct hda_codec *codec)
  412. {
  413. struct conexant_spec *spec = codec->spec;
  414. unsigned int i;
  415. int err;
  416. for (i = 0; i < spec->num_mixers; i++) {
  417. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  418. if (err < 0)
  419. return err;
  420. }
  421. if (spec->multiout.dig_out_nid) {
  422. err = snd_hda_create_spdif_out_ctls(codec,
  423. spec->multiout.dig_out_nid,
  424. spec->multiout.dig_out_nid);
  425. if (err < 0)
  426. return err;
  427. err = snd_hda_create_spdif_share_sw(codec,
  428. &spec->multiout);
  429. if (err < 0)
  430. return err;
  431. spec->multiout.share_spdif = 1;
  432. }
  433. if (spec->dig_in_nid) {
  434. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  435. if (err < 0)
  436. return err;
  437. }
  438. /* if we have no master control, let's create it */
  439. if (spec->vmaster_nid &&
  440. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  441. unsigned int vmaster_tlv[4];
  442. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  443. HDA_OUTPUT, vmaster_tlv);
  444. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  445. vmaster_tlv, slave_pfxs,
  446. "Playback Volume");
  447. if (err < 0)
  448. return err;
  449. }
  450. if (spec->vmaster_nid &&
  451. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  452. err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
  453. NULL, slave_pfxs,
  454. "Playback Switch", true,
  455. &spec->vmaster_mute.sw_kctl);
  456. if (err < 0)
  457. return err;
  458. }
  459. if (spec->input_mux) {
  460. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  461. if (err < 0)
  462. return err;
  463. }
  464. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  465. /* create beep controls if needed */
  466. if (spec->beep_amp) {
  467. const struct snd_kcontrol_new *knew;
  468. for (knew = cxt_beep_mixer; knew->name; knew++) {
  469. struct snd_kcontrol *kctl;
  470. kctl = snd_ctl_new1(knew, codec);
  471. if (!kctl)
  472. return -ENOMEM;
  473. kctl->private_value = spec->beep_amp;
  474. err = snd_hda_ctl_add(codec, 0, kctl);
  475. if (err < 0)
  476. return err;
  477. }
  478. }
  479. #endif
  480. return 0;
  481. }
  482. static const struct hda_codec_ops conexant_patch_ops = {
  483. .build_controls = conexant_build_controls,
  484. .build_pcms = conexant_build_pcms,
  485. .init = conexant_init,
  486. .free = conexant_free,
  487. .set_power_state = conexant_set_power,
  488. };
  489. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  490. #define set_beep_amp(spec, nid, idx, dir) \
  491. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
  492. #else
  493. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  494. #endif
  495. static int patch_conexant_auto(struct hda_codec *codec);
  496. /*
  497. * EAPD control
  498. * the private value = nid | (invert << 8)
  499. */
  500. #define cxt_eapd_info snd_ctl_boolean_mono_info
  501. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_value *ucontrol)
  503. {
  504. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  505. struct conexant_spec *spec = codec->spec;
  506. int invert = (kcontrol->private_value >> 8) & 1;
  507. if (invert)
  508. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  509. else
  510. ucontrol->value.integer.value[0] = spec->cur_eapd;
  511. return 0;
  512. }
  513. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  514. struct snd_ctl_elem_value *ucontrol)
  515. {
  516. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  517. struct conexant_spec *spec = codec->spec;
  518. int invert = (kcontrol->private_value >> 8) & 1;
  519. hda_nid_t nid = kcontrol->private_value & 0xff;
  520. unsigned int eapd;
  521. eapd = !!ucontrol->value.integer.value[0];
  522. if (invert)
  523. eapd = !eapd;
  524. if (eapd == spec->cur_eapd)
  525. return 0;
  526. spec->cur_eapd = eapd;
  527. snd_hda_codec_write_cache(codec, nid,
  528. 0, AC_VERB_SET_EAPD_BTLENABLE,
  529. eapd ? 0x02 : 0x00);
  530. return 1;
  531. }
  532. /* controls for test mode */
  533. #ifdef CONFIG_SND_DEBUG
  534. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  535. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  536. .info = cxt_eapd_info, \
  537. .get = cxt_eapd_get, \
  538. .put = cxt_eapd_put, \
  539. .private_value = nid | (mask<<16) }
  540. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  541. struct snd_ctl_elem_info *uinfo)
  542. {
  543. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  544. struct conexant_spec *spec = codec->spec;
  545. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  546. spec->num_channel_mode);
  547. }
  548. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  549. struct snd_ctl_elem_value *ucontrol)
  550. {
  551. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  552. struct conexant_spec *spec = codec->spec;
  553. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  554. spec->num_channel_mode,
  555. spec->multiout.max_channels);
  556. }
  557. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  558. struct snd_ctl_elem_value *ucontrol)
  559. {
  560. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  561. struct conexant_spec *spec = codec->spec;
  562. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  563. spec->num_channel_mode,
  564. &spec->multiout.max_channels);
  565. if (err >= 0 && spec->need_dac_fix)
  566. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  567. return err;
  568. }
  569. #define CXT_PIN_MODE(xname, nid, dir) \
  570. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  571. .info = conexant_ch_mode_info, \
  572. .get = conexant_ch_mode_get, \
  573. .put = conexant_ch_mode_put, \
  574. .private_value = nid | (dir<<16) }
  575. #endif /* CONFIG_SND_DEBUG */
  576. /* Conexant 5045 specific */
  577. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  578. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  579. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  580. #define CXT5045_SPDIF_OUT 0x18
  581. static const struct hda_channel_mode cxt5045_modes[1] = {
  582. { 2, NULL },
  583. };
  584. static const struct hda_input_mux cxt5045_capture_source = {
  585. .num_items = 2,
  586. .items = {
  587. { "Internal Mic", 0x1 },
  588. { "Mic", 0x2 },
  589. }
  590. };
  591. static const struct hda_input_mux cxt5045_capture_source_benq = {
  592. .num_items = 4,
  593. .items = {
  594. { "Internal Mic", 0x1 },
  595. { "Mic", 0x2 },
  596. { "Line", 0x3 },
  597. { "Mixer", 0x0 },
  598. }
  599. };
  600. static const struct hda_input_mux cxt5045_capture_source_hp530 = {
  601. .num_items = 2,
  602. .items = {
  603. { "Mic", 0x1 },
  604. { "Internal Mic", 0x2 },
  605. }
  606. };
  607. /* turn on/off EAPD (+ mute HP) as a master switch */
  608. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  609. struct snd_ctl_elem_value *ucontrol)
  610. {
  611. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  612. struct conexant_spec *spec = codec->spec;
  613. unsigned int bits;
  614. if (!cxt_eapd_put(kcontrol, ucontrol))
  615. return 0;
  616. /* toggle internal speakers mute depending of presence of
  617. * the headphone jack
  618. */
  619. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  620. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  621. HDA_AMP_MUTE, bits);
  622. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  623. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  624. HDA_AMP_MUTE, bits);
  625. return 1;
  626. }
  627. /* bind volumes of both NID 0x10 and 0x11 */
  628. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  629. .ops = &snd_hda_bind_vol,
  630. .values = {
  631. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  632. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  633. 0
  634. },
  635. };
  636. /* toggle input of built-in and mic jack appropriately */
  637. static void cxt5045_hp_automic(struct hda_codec *codec)
  638. {
  639. static const struct hda_verb mic_jack_on[] = {
  640. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  641. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  642. {}
  643. };
  644. static const struct hda_verb mic_jack_off[] = {
  645. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  646. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  647. {}
  648. };
  649. unsigned int present;
  650. present = snd_hda_jack_detect(codec, 0x12);
  651. if (present)
  652. snd_hda_sequence_write(codec, mic_jack_on);
  653. else
  654. snd_hda_sequence_write(codec, mic_jack_off);
  655. }
  656. /* mute internal speaker if HP is plugged */
  657. static void cxt5045_hp_automute(struct hda_codec *codec)
  658. {
  659. struct conexant_spec *spec = codec->spec;
  660. unsigned int bits;
  661. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  662. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  663. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  664. HDA_AMP_MUTE, bits);
  665. }
  666. /* unsolicited event for HP jack sensing */
  667. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  668. unsigned int res)
  669. {
  670. res >>= 26;
  671. switch (res) {
  672. case CONEXANT_HP_EVENT:
  673. cxt5045_hp_automute(codec);
  674. break;
  675. case CONEXANT_MIC_EVENT:
  676. cxt5045_hp_automic(codec);
  677. break;
  678. }
  679. }
  680. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  681. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
  682. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  683. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  684. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  685. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  686. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  687. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  688. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  689. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  690. {
  691. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  692. .name = "Master Playback Switch",
  693. .info = cxt_eapd_info,
  694. .get = cxt_eapd_get,
  695. .put = cxt5045_hp_master_sw_put,
  696. .private_value = 0x10,
  697. },
  698. {}
  699. };
  700. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  701. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
  702. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
  703. {}
  704. };
  705. static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  706. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
  707. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  708. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  709. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  710. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  711. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  712. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  713. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  714. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  715. {
  716. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  717. .name = "Master Playback Switch",
  718. .info = cxt_eapd_info,
  719. .get = cxt_eapd_get,
  720. .put = cxt5045_hp_master_sw_put,
  721. .private_value = 0x10,
  722. },
  723. {}
  724. };
  725. static const struct hda_verb cxt5045_init_verbs[] = {
  726. /* Line in, Mic */
  727. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  728. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  729. /* HP, Amp */
  730. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  731. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  732. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  733. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  734. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  735. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  736. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  737. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  738. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  739. /* Record selector: Internal mic */
  740. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  741. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  742. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  743. /* SPDIF route: PCM */
  744. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  745. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  746. /* EAPD */
  747. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  748. { } /* end */
  749. };
  750. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  751. /* Internal Mic, Mic */
  752. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  753. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  754. /* Line In,HP, Amp */
  755. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  756. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  757. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  758. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  759. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  760. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  761. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  762. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  763. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  764. /* Record selector: Internal mic */
  765. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  766. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  767. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  768. /* SPDIF route: PCM */
  769. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  770. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  771. /* EAPD */
  772. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  773. { } /* end */
  774. };
  775. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  776. /* pin sensing on HP jack */
  777. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  778. { } /* end */
  779. };
  780. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  781. /* pin sensing on HP jack */
  782. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  783. { } /* end */
  784. };
  785. #ifdef CONFIG_SND_DEBUG
  786. /* Test configuration for debugging, modelled after the ALC260 test
  787. * configuration.
  788. */
  789. static const struct hda_input_mux cxt5045_test_capture_source = {
  790. .num_items = 5,
  791. .items = {
  792. { "MIXER", 0x0 },
  793. { "MIC1 pin", 0x1 },
  794. { "LINE1 pin", 0x2 },
  795. { "HP-OUT pin", 0x3 },
  796. { "CD pin", 0x4 },
  797. },
  798. };
  799. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  800. /* Output controls */
  801. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  802. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  803. HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  804. HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  805. HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  806. HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  807. /* Modes for retasking pin widgets */
  808. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  809. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  810. /* EAPD Switch Control */
  811. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  812. /* Loopback mixer controls */
  813. HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
  814. HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
  815. HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
  816. HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
  817. HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
  818. HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
  819. HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
  820. HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
  821. HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
  822. HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
  823. {
  824. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  825. .name = "Input Source",
  826. .info = conexant_mux_enum_info,
  827. .get = conexant_mux_enum_get,
  828. .put = conexant_mux_enum_put,
  829. },
  830. /* Audio input controls */
  831. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
  832. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  833. { } /* end */
  834. };
  835. static const struct hda_verb cxt5045_test_init_verbs[] = {
  836. /* Set connections */
  837. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  838. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  839. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  840. /* Enable retasking pins as output, initially without power amp */
  841. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  842. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  843. /* Disable digital (SPDIF) pins initially, but users can enable
  844. * them via a mixer switch. In the case of SPDIF-out, this initverb
  845. * payload also sets the generation to 0, output to be in "consumer"
  846. * PCM format, copyright asserted, no pre-emphasis and no validity
  847. * control.
  848. */
  849. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  850. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  851. /* Unmute retasking pin widget output buffers since the default
  852. * state appears to be output. As the pin mode is changed by the
  853. * user the pin mode control will take care of enabling the pin's
  854. * input/output buffers as needed.
  855. */
  856. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  857. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  858. /* Mute capture amp left and right */
  859. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  860. /* Set ADC connection select to match default mixer setting (mic1
  861. * pin)
  862. */
  863. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
  864. {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
  865. /* Mute all inputs to mixer widget (even unconnected ones) */
  866. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
  867. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  868. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  869. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  870. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  871. { }
  872. };
  873. #endif
  874. /* initialize jack-sensing, too */
  875. static int cxt5045_init(struct hda_codec *codec)
  876. {
  877. conexant_init(codec);
  878. cxt5045_hp_automute(codec);
  879. return 0;
  880. }
  881. enum {
  882. CXT5045_LAPTOP_HPSENSE,
  883. CXT5045_LAPTOP_MICSENSE,
  884. CXT5045_LAPTOP_HPMICSENSE,
  885. CXT5045_BENQ,
  886. CXT5045_LAPTOP_HP530,
  887. #ifdef CONFIG_SND_DEBUG
  888. CXT5045_TEST,
  889. #endif
  890. CXT5045_AUTO,
  891. CXT5045_MODELS
  892. };
  893. static const char * const cxt5045_models[CXT5045_MODELS] = {
  894. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  895. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  896. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  897. [CXT5045_BENQ] = "benq",
  898. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  899. #ifdef CONFIG_SND_DEBUG
  900. [CXT5045_TEST] = "test",
  901. #endif
  902. [CXT5045_AUTO] = "auto",
  903. };
  904. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  905. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  906. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  907. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  908. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  909. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  910. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  911. CXT5045_LAPTOP_HPMICSENSE),
  912. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  913. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  914. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  915. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  916. CXT5045_LAPTOP_HPMICSENSE),
  917. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  918. {}
  919. };
  920. static int patch_cxt5045(struct hda_codec *codec)
  921. {
  922. struct conexant_spec *spec;
  923. int board_config;
  924. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  925. cxt5045_models,
  926. cxt5045_cfg_tbl);
  927. if (board_config < 0)
  928. board_config = CXT5045_AUTO; /* model=auto as default */
  929. if (board_config == CXT5045_AUTO)
  930. return patch_conexant_auto(codec);
  931. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  932. if (!spec)
  933. return -ENOMEM;
  934. codec->spec = spec;
  935. codec->single_adc_amp = 1;
  936. spec->multiout.max_channels = 2;
  937. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  938. spec->multiout.dac_nids = cxt5045_dac_nids;
  939. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  940. spec->num_adc_nids = 1;
  941. spec->adc_nids = cxt5045_adc_nids;
  942. spec->capsrc_nids = cxt5045_capsrc_nids;
  943. spec->input_mux = &cxt5045_capture_source;
  944. spec->num_mixers = 1;
  945. spec->mixers[0] = cxt5045_mixers;
  946. spec->num_init_verbs = 1;
  947. spec->init_verbs[0] = cxt5045_init_verbs;
  948. spec->spdif_route = 0;
  949. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  950. spec->channel_mode = cxt5045_modes;
  951. set_beep_amp(spec, 0x16, 0, 1);
  952. codec->patch_ops = conexant_patch_ops;
  953. switch (board_config) {
  954. case CXT5045_LAPTOP_HPSENSE:
  955. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  956. spec->input_mux = &cxt5045_capture_source;
  957. spec->num_init_verbs = 2;
  958. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  959. spec->mixers[0] = cxt5045_mixers;
  960. codec->patch_ops.init = cxt5045_init;
  961. break;
  962. case CXT5045_LAPTOP_MICSENSE:
  963. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  964. spec->input_mux = &cxt5045_capture_source;
  965. spec->num_init_verbs = 2;
  966. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  967. spec->mixers[0] = cxt5045_mixers;
  968. codec->patch_ops.init = cxt5045_init;
  969. break;
  970. default:
  971. case CXT5045_LAPTOP_HPMICSENSE:
  972. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  973. spec->input_mux = &cxt5045_capture_source;
  974. spec->num_init_verbs = 3;
  975. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  976. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  977. spec->mixers[0] = cxt5045_mixers;
  978. codec->patch_ops.init = cxt5045_init;
  979. break;
  980. case CXT5045_BENQ:
  981. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  982. spec->input_mux = &cxt5045_capture_source_benq;
  983. spec->num_init_verbs = 1;
  984. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  985. spec->mixers[0] = cxt5045_mixers;
  986. spec->mixers[1] = cxt5045_benq_mixers;
  987. spec->num_mixers = 2;
  988. codec->patch_ops.init = cxt5045_init;
  989. break;
  990. case CXT5045_LAPTOP_HP530:
  991. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  992. spec->input_mux = &cxt5045_capture_source_hp530;
  993. spec->num_init_verbs = 2;
  994. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  995. spec->mixers[0] = cxt5045_mixers_hp530;
  996. codec->patch_ops.init = cxt5045_init;
  997. break;
  998. #ifdef CONFIG_SND_DEBUG
  999. case CXT5045_TEST:
  1000. spec->input_mux = &cxt5045_test_capture_source;
  1001. spec->mixers[0] = cxt5045_test_mixer;
  1002. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1003. break;
  1004. #endif
  1005. }
  1006. switch (codec->subsystem_id >> 16) {
  1007. case 0x103c:
  1008. case 0x1631:
  1009. case 0x1734:
  1010. case 0x17aa:
  1011. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  1012. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  1013. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  1014. */
  1015. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1016. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1017. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1018. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1019. (1 << AC_AMPCAP_MUTE_SHIFT));
  1020. break;
  1021. }
  1022. if (spec->beep_amp)
  1023. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  1024. return 0;
  1025. }
  1026. /* Conexant 5047 specific */
  1027. #define CXT5047_SPDIF_OUT 0x11
  1028. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1029. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1030. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1031. static const struct hda_channel_mode cxt5047_modes[1] = {
  1032. { 2, NULL },
  1033. };
  1034. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  1035. .num_items = 2,
  1036. .items = {
  1037. { "ExtMic", 0x2 },
  1038. { "Line-In", 0x1 },
  1039. }
  1040. };
  1041. /* turn on/off EAPD (+ mute HP) as a master switch */
  1042. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1043. struct snd_ctl_elem_value *ucontrol)
  1044. {
  1045. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1046. struct conexant_spec *spec = codec->spec;
  1047. unsigned int bits;
  1048. if (!cxt_eapd_put(kcontrol, ucontrol))
  1049. return 0;
  1050. /* toggle internal speakers mute depending of presence of
  1051. * the headphone jack
  1052. */
  1053. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1054. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1055. * pin widgets unlike other codecs. In this case, we need to
  1056. * set index 0x01 for the volume from the mixer amp 0x19.
  1057. */
  1058. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1059. HDA_AMP_MUTE, bits);
  1060. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1061. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1062. HDA_AMP_MUTE, bits);
  1063. return 1;
  1064. }
  1065. /* mute internal speaker if HP is plugged */
  1066. static void cxt5047_hp_automute(struct hda_codec *codec)
  1067. {
  1068. struct conexant_spec *spec = codec->spec;
  1069. unsigned int bits;
  1070. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1071. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1072. /* See the note in cxt5047_hp_master_sw_put */
  1073. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1074. HDA_AMP_MUTE, bits);
  1075. }
  1076. /* toggle input of built-in and mic jack appropriately */
  1077. static void cxt5047_hp_automic(struct hda_codec *codec)
  1078. {
  1079. static const struct hda_verb mic_jack_on[] = {
  1080. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1081. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1082. {}
  1083. };
  1084. static const struct hda_verb mic_jack_off[] = {
  1085. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1086. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1087. {}
  1088. };
  1089. unsigned int present;
  1090. present = snd_hda_jack_detect(codec, 0x15);
  1091. if (present)
  1092. snd_hda_sequence_write(codec, mic_jack_on);
  1093. else
  1094. snd_hda_sequence_write(codec, mic_jack_off);
  1095. }
  1096. /* unsolicited event for HP jack sensing */
  1097. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1098. unsigned int res)
  1099. {
  1100. switch (res >> 26) {
  1101. case CONEXANT_HP_EVENT:
  1102. cxt5047_hp_automute(codec);
  1103. break;
  1104. case CONEXANT_MIC_EVENT:
  1105. cxt5047_hp_automic(codec);
  1106. break;
  1107. }
  1108. }
  1109. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1110. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1111. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1112. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1113. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1114. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1115. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1116. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1117. {
  1118. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1119. .name = "Master Playback Switch",
  1120. .info = cxt_eapd_info,
  1121. .get = cxt_eapd_get,
  1122. .put = cxt5047_hp_master_sw_put,
  1123. .private_value = 0x13,
  1124. },
  1125. {}
  1126. };
  1127. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1128. /* See the note in cxt5047_hp_master_sw_put */
  1129. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1130. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1131. {}
  1132. };
  1133. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1134. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1135. { } /* end */
  1136. };
  1137. static const struct hda_verb cxt5047_init_verbs[] = {
  1138. /* Line in, Mic, Built-in Mic */
  1139. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1140. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1141. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1142. /* HP, Speaker */
  1143. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1144. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1145. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1146. /* Record selector: Mic */
  1147. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1148. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1149. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1150. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1151. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1152. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1153. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1154. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1155. /* SPDIF route: PCM */
  1156. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1157. /* Enable unsolicited events */
  1158. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1159. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1160. { } /* end */
  1161. };
  1162. /* configuration for Toshiba Laptops */
  1163. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1164. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1165. {}
  1166. };
  1167. /* Test configuration for debugging, modelled after the ALC260 test
  1168. * configuration.
  1169. */
  1170. #ifdef CONFIG_SND_DEBUG
  1171. static const struct hda_input_mux cxt5047_test_capture_source = {
  1172. .num_items = 4,
  1173. .items = {
  1174. { "LINE1 pin", 0x0 },
  1175. { "MIC1 pin", 0x1 },
  1176. { "MIC2 pin", 0x2 },
  1177. { "CD pin", 0x3 },
  1178. },
  1179. };
  1180. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1181. /* Output only controls */
  1182. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1183. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1184. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1185. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1186. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1187. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1188. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1189. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1190. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1191. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1192. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1193. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1194. /* Modes for retasking pin widgets */
  1195. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1196. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1197. /* EAPD Switch Control */
  1198. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1199. /* Loopback mixer controls */
  1200. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1201. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1202. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1203. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1204. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1205. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1206. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1207. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1208. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1209. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1210. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1211. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1212. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1213. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1214. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1215. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1216. {
  1217. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1218. .name = "Input Source",
  1219. .info = conexant_mux_enum_info,
  1220. .get = conexant_mux_enum_get,
  1221. .put = conexant_mux_enum_put,
  1222. },
  1223. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1224. { } /* end */
  1225. };
  1226. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1227. /* Enable retasking pins as output, initially without power amp */
  1228. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1229. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1230. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1231. /* Disable digital (SPDIF) pins initially, but users can enable
  1232. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1233. * payload also sets the generation to 0, output to be in "consumer"
  1234. * PCM format, copyright asserted, no pre-emphasis and no validity
  1235. * control.
  1236. */
  1237. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1238. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1239. * OUT1 sum bus when acting as an output.
  1240. */
  1241. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1242. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1243. /* Start with output sum widgets muted and their output gains at min */
  1244. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1245. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1246. /* Unmute retasking pin widget output buffers since the default
  1247. * state appears to be output. As the pin mode is changed by the
  1248. * user the pin mode control will take care of enabling the pin's
  1249. * input/output buffers as needed.
  1250. */
  1251. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1252. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1253. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1254. /* Mute capture amp left and right */
  1255. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1256. /* Set ADC connection select to match default mixer setting (mic1
  1257. * pin)
  1258. */
  1259. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1260. /* Mute all inputs to mixer widget (even unconnected ones) */
  1261. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1262. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1263. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1264. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1265. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1266. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1267. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1268. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1269. { }
  1270. };
  1271. #endif
  1272. /* initialize jack-sensing, too */
  1273. static int cxt5047_hp_init(struct hda_codec *codec)
  1274. {
  1275. conexant_init(codec);
  1276. cxt5047_hp_automute(codec);
  1277. return 0;
  1278. }
  1279. enum {
  1280. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1281. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1282. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1283. #ifdef CONFIG_SND_DEBUG
  1284. CXT5047_TEST,
  1285. #endif
  1286. CXT5047_AUTO,
  1287. CXT5047_MODELS
  1288. };
  1289. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1290. [CXT5047_LAPTOP] = "laptop",
  1291. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1292. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1293. #ifdef CONFIG_SND_DEBUG
  1294. [CXT5047_TEST] = "test",
  1295. #endif
  1296. [CXT5047_AUTO] = "auto",
  1297. };
  1298. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1299. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1300. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1301. CXT5047_LAPTOP),
  1302. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1303. {}
  1304. };
  1305. static int patch_cxt5047(struct hda_codec *codec)
  1306. {
  1307. struct conexant_spec *spec;
  1308. int board_config;
  1309. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1310. cxt5047_models,
  1311. cxt5047_cfg_tbl);
  1312. if (board_config < 0)
  1313. board_config = CXT5047_AUTO; /* model=auto as default */
  1314. if (board_config == CXT5047_AUTO)
  1315. return patch_conexant_auto(codec);
  1316. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1317. if (!spec)
  1318. return -ENOMEM;
  1319. codec->spec = spec;
  1320. codec->pin_amp_workaround = 1;
  1321. spec->multiout.max_channels = 2;
  1322. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1323. spec->multiout.dac_nids = cxt5047_dac_nids;
  1324. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1325. spec->num_adc_nids = 1;
  1326. spec->adc_nids = cxt5047_adc_nids;
  1327. spec->capsrc_nids = cxt5047_capsrc_nids;
  1328. spec->num_mixers = 1;
  1329. spec->mixers[0] = cxt5047_base_mixers;
  1330. spec->num_init_verbs = 1;
  1331. spec->init_verbs[0] = cxt5047_init_verbs;
  1332. spec->spdif_route = 0;
  1333. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1334. spec->channel_mode = cxt5047_modes,
  1335. codec->patch_ops = conexant_patch_ops;
  1336. switch (board_config) {
  1337. case CXT5047_LAPTOP:
  1338. spec->num_mixers = 2;
  1339. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1340. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1341. break;
  1342. case CXT5047_LAPTOP_HP:
  1343. spec->num_mixers = 2;
  1344. spec->mixers[1] = cxt5047_hp_only_mixers;
  1345. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1346. codec->patch_ops.init = cxt5047_hp_init;
  1347. break;
  1348. case CXT5047_LAPTOP_EAPD:
  1349. spec->input_mux = &cxt5047_toshiba_capture_source;
  1350. spec->num_mixers = 2;
  1351. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1352. spec->num_init_verbs = 2;
  1353. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1354. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1355. break;
  1356. #ifdef CONFIG_SND_DEBUG
  1357. case CXT5047_TEST:
  1358. spec->input_mux = &cxt5047_test_capture_source;
  1359. spec->mixers[0] = cxt5047_test_mixer;
  1360. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1361. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1362. #endif
  1363. }
  1364. spec->vmaster_nid = 0x13;
  1365. switch (codec->subsystem_id >> 16) {
  1366. case 0x103c:
  1367. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1368. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1369. * with 0 dB offset 0x17)
  1370. */
  1371. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1372. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1373. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1374. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1375. (1 << AC_AMPCAP_MUTE_SHIFT));
  1376. break;
  1377. }
  1378. return 0;
  1379. }
  1380. /* Conexant 5051 specific */
  1381. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1382. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1383. static const struct hda_channel_mode cxt5051_modes[1] = {
  1384. { 2, NULL },
  1385. };
  1386. static void cxt5051_update_speaker(struct hda_codec *codec)
  1387. {
  1388. struct conexant_spec *spec = codec->spec;
  1389. unsigned int pinctl;
  1390. /* headphone pin */
  1391. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1392. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1393. pinctl);
  1394. /* speaker pin */
  1395. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1396. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1397. pinctl);
  1398. /* on ideapad there is an additional speaker (subwoofer) to mute */
  1399. if (spec->ideapad)
  1400. snd_hda_codec_write(codec, 0x1b, 0,
  1401. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1402. pinctl);
  1403. }
  1404. /* turn on/off EAPD (+ mute HP) as a master switch */
  1405. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1406. struct snd_ctl_elem_value *ucontrol)
  1407. {
  1408. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1409. if (!cxt_eapd_put(kcontrol, ucontrol))
  1410. return 0;
  1411. cxt5051_update_speaker(codec);
  1412. return 1;
  1413. }
  1414. /* toggle input of built-in and mic jack appropriately */
  1415. static void cxt5051_portb_automic(struct hda_codec *codec)
  1416. {
  1417. struct conexant_spec *spec = codec->spec;
  1418. unsigned int present;
  1419. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1420. return;
  1421. present = snd_hda_jack_detect(codec, 0x17);
  1422. snd_hda_codec_write(codec, 0x14, 0,
  1423. AC_VERB_SET_CONNECT_SEL,
  1424. present ? 0x01 : 0x00);
  1425. }
  1426. /* switch the current ADC according to the jack state */
  1427. static void cxt5051_portc_automic(struct hda_codec *codec)
  1428. {
  1429. struct conexant_spec *spec = codec->spec;
  1430. unsigned int present;
  1431. hda_nid_t new_adc;
  1432. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1433. return;
  1434. present = snd_hda_jack_detect(codec, 0x18);
  1435. if (present)
  1436. spec->cur_adc_idx = 1;
  1437. else
  1438. spec->cur_adc_idx = 0;
  1439. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1440. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1441. /* stream is running, let's swap the current ADC */
  1442. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1443. spec->cur_adc = new_adc;
  1444. snd_hda_codec_setup_stream(codec, new_adc,
  1445. spec->cur_adc_stream_tag, 0,
  1446. spec->cur_adc_format);
  1447. }
  1448. }
  1449. /* mute internal speaker if HP is plugged */
  1450. static void cxt5051_hp_automute(struct hda_codec *codec)
  1451. {
  1452. struct conexant_spec *spec = codec->spec;
  1453. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1454. cxt5051_update_speaker(codec);
  1455. }
  1456. /* unsolicited event for HP jack sensing */
  1457. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1458. unsigned int res)
  1459. {
  1460. switch (res >> 26) {
  1461. case CONEXANT_HP_EVENT:
  1462. cxt5051_hp_automute(codec);
  1463. break;
  1464. case CXT5051_PORTB_EVENT:
  1465. cxt5051_portb_automic(codec);
  1466. break;
  1467. case CXT5051_PORTC_EVENT:
  1468. cxt5051_portc_automic(codec);
  1469. break;
  1470. }
  1471. }
  1472. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1473. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1474. {
  1475. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1476. .name = "Master Playback Switch",
  1477. .info = cxt_eapd_info,
  1478. .get = cxt_eapd_get,
  1479. .put = cxt5051_hp_master_sw_put,
  1480. .private_value = 0x1a,
  1481. },
  1482. {}
  1483. };
  1484. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1485. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1486. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1487. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1488. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1489. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1490. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1491. {}
  1492. };
  1493. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1494. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1495. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1496. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1497. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1498. {}
  1499. };
  1500. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1501. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1502. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1503. {}
  1504. };
  1505. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1506. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1507. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1508. {}
  1509. };
  1510. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1511. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1512. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1513. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1514. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1515. {}
  1516. };
  1517. static const struct hda_verb cxt5051_init_verbs[] = {
  1518. /* Line in, Mic */
  1519. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1520. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1521. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1522. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1523. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1524. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1525. /* SPK */
  1526. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1527. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1528. /* HP, Amp */
  1529. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1530. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1531. /* DAC1 */
  1532. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1533. /* Record selector: Internal mic */
  1534. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1535. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1536. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1537. /* SPDIF route: PCM */
  1538. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1539. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1540. /* EAPD */
  1541. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1542. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1543. { } /* end */
  1544. };
  1545. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1546. /* Line in, Mic */
  1547. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1548. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1549. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1550. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1551. /* SPK */
  1552. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1553. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1554. /* HP, Amp */
  1555. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1556. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1557. /* DAC1 */
  1558. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1559. /* Record selector: Internal mic */
  1560. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1561. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1562. /* SPDIF route: PCM */
  1563. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1564. /* EAPD */
  1565. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1566. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1567. { } /* end */
  1568. };
  1569. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1570. /* Line in, Mic */
  1571. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1572. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1573. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1574. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1575. /* SPK */
  1576. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1577. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1578. /* HP, Amp */
  1579. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1580. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1581. /* DAC1 */
  1582. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1583. /* Record selector: Internal mic */
  1584. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1585. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1586. /* SPDIF route: PCM */
  1587. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1588. /* EAPD */
  1589. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1590. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1591. { } /* end */
  1592. };
  1593. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1594. unsigned int event)
  1595. {
  1596. snd_hda_codec_write(codec, nid, 0,
  1597. AC_VERB_SET_UNSOLICITED_ENABLE,
  1598. AC_USRSP_EN | event);
  1599. }
  1600. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1601. /* Subwoofer */
  1602. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1603. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1604. { } /* end */
  1605. };
  1606. /* initialize jack-sensing, too */
  1607. static int cxt5051_init(struct hda_codec *codec)
  1608. {
  1609. struct conexant_spec *spec = codec->spec;
  1610. conexant_init(codec);
  1611. if (spec->auto_mic & AUTO_MIC_PORTB)
  1612. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1613. if (spec->auto_mic & AUTO_MIC_PORTC)
  1614. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1615. if (codec->patch_ops.unsol_event) {
  1616. cxt5051_hp_automute(codec);
  1617. cxt5051_portb_automic(codec);
  1618. cxt5051_portc_automic(codec);
  1619. }
  1620. return 0;
  1621. }
  1622. enum {
  1623. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1624. CXT5051_HP, /* no docking */
  1625. CXT5051_HP_DV6736, /* HP without mic switch */
  1626. CXT5051_F700, /* HP Compaq Presario F700 */
  1627. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1628. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1629. CXT5051_AUTO, /* auto-parser */
  1630. CXT5051_MODELS
  1631. };
  1632. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1633. [CXT5051_LAPTOP] = "laptop",
  1634. [CXT5051_HP] = "hp",
  1635. [CXT5051_HP_DV6736] = "hp-dv6736",
  1636. [CXT5051_F700] = "hp-700",
  1637. [CXT5051_TOSHIBA] = "toshiba",
  1638. [CXT5051_IDEAPAD] = "ideapad",
  1639. [CXT5051_AUTO] = "auto",
  1640. };
  1641. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1642. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1643. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1644. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1645. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1646. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1647. CXT5051_LAPTOP),
  1648. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1649. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1650. {}
  1651. };
  1652. static int patch_cxt5051(struct hda_codec *codec)
  1653. {
  1654. struct conexant_spec *spec;
  1655. int board_config;
  1656. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1657. cxt5051_models,
  1658. cxt5051_cfg_tbl);
  1659. if (board_config < 0)
  1660. board_config = CXT5051_AUTO; /* model=auto as default */
  1661. if (board_config == CXT5051_AUTO)
  1662. return patch_conexant_auto(codec);
  1663. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1664. if (!spec)
  1665. return -ENOMEM;
  1666. codec->spec = spec;
  1667. codec->pin_amp_workaround = 1;
  1668. codec->patch_ops = conexant_patch_ops;
  1669. codec->patch_ops.init = cxt5051_init;
  1670. spec->multiout.max_channels = 2;
  1671. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1672. spec->multiout.dac_nids = cxt5051_dac_nids;
  1673. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1674. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1675. spec->adc_nids = cxt5051_adc_nids;
  1676. spec->num_mixers = 2;
  1677. spec->mixers[0] = cxt5051_capture_mixers;
  1678. spec->mixers[1] = cxt5051_playback_mixers;
  1679. spec->num_init_verbs = 1;
  1680. spec->init_verbs[0] = cxt5051_init_verbs;
  1681. spec->spdif_route = 0;
  1682. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1683. spec->channel_mode = cxt5051_modes;
  1684. spec->cur_adc = 0;
  1685. spec->cur_adc_idx = 0;
  1686. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1687. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1688. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1689. switch (board_config) {
  1690. case CXT5051_HP:
  1691. spec->mixers[0] = cxt5051_hp_mixers;
  1692. break;
  1693. case CXT5051_HP_DV6736:
  1694. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1695. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1696. spec->auto_mic = 0;
  1697. break;
  1698. case CXT5051_F700:
  1699. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1700. spec->mixers[0] = cxt5051_f700_mixers;
  1701. spec->auto_mic = 0;
  1702. break;
  1703. case CXT5051_TOSHIBA:
  1704. spec->mixers[0] = cxt5051_toshiba_mixers;
  1705. spec->auto_mic = AUTO_MIC_PORTB;
  1706. break;
  1707. case CXT5051_IDEAPAD:
  1708. spec->init_verbs[spec->num_init_verbs++] =
  1709. cxt5051_ideapad_init_verbs;
  1710. spec->ideapad = 1;
  1711. break;
  1712. }
  1713. if (spec->beep_amp)
  1714. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  1715. return 0;
  1716. }
  1717. /* Conexant 5066 specific */
  1718. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1719. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1720. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1721. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1722. /* OLPC's microphone port is DC coupled for use with external sensors,
  1723. * therefore we use a 50% mic bias in order to center the input signal with
  1724. * the DC input range of the codec. */
  1725. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1726. static const struct hda_channel_mode cxt5066_modes[1] = {
  1727. { 2, NULL },
  1728. };
  1729. #define HP_PRESENT_PORT_A (1 << 0)
  1730. #define HP_PRESENT_PORT_D (1 << 1)
  1731. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1732. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1733. static void cxt5066_update_speaker(struct hda_codec *codec)
  1734. {
  1735. struct conexant_spec *spec = codec->spec;
  1736. unsigned int pinctl;
  1737. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1738. spec->hp_present, spec->cur_eapd);
  1739. /* Port A (HP) */
  1740. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1741. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1742. pinctl);
  1743. /* Port D (HP/LO) */
  1744. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1745. if (spec->dell_automute || spec->thinkpad) {
  1746. /* Mute if Port A is connected */
  1747. if (hp_port_a_present(spec))
  1748. pinctl = 0;
  1749. } else {
  1750. /* Thinkpad/Dell doesn't give pin-D status */
  1751. if (!hp_port_d_present(spec))
  1752. pinctl = 0;
  1753. }
  1754. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1755. pinctl);
  1756. /* CLASS_D AMP */
  1757. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1758. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1759. pinctl);
  1760. }
  1761. /* turn on/off EAPD (+ mute HP) as a master switch */
  1762. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1763. struct snd_ctl_elem_value *ucontrol)
  1764. {
  1765. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1766. if (!cxt_eapd_put(kcontrol, ucontrol))
  1767. return 0;
  1768. cxt5066_update_speaker(codec);
  1769. return 1;
  1770. }
  1771. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1772. .num_items = 3,
  1773. .items = {
  1774. { "Off", PIN_IN },
  1775. { "50%", PIN_VREF50 },
  1776. { "80%", PIN_VREF80 },
  1777. },
  1778. };
  1779. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1780. {
  1781. struct conexant_spec *spec = codec->spec;
  1782. /* Even though port F is the DC input, the bias is controlled on port B.
  1783. * we also leave that port as an active input (but unselected) in DC mode
  1784. * just in case that is necessary to make the bias setting take effect. */
  1785. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1786. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1787. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1788. }
  1789. /* OLPC defers mic widget control until when capture is started because the
  1790. * microphone LED comes on as soon as these settings are put in place. if we
  1791. * did this before recording, it would give the false indication that recording
  1792. * is happening when it is not. */
  1793. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1794. {
  1795. struct conexant_spec *spec = codec->spec;
  1796. if (!spec->recording)
  1797. return;
  1798. if (spec->dc_enable) {
  1799. /* in DC mode we ignore presence detection and just use the jack
  1800. * through our special DC port */
  1801. const struct hda_verb enable_dc_mode[] = {
  1802. /* disble internal mic, port C */
  1803. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1804. /* enable DC capture, port F */
  1805. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1806. {},
  1807. };
  1808. snd_hda_sequence_write(codec, enable_dc_mode);
  1809. /* port B input disabled (and bias set) through the following call */
  1810. cxt5066_set_olpc_dc_bias(codec);
  1811. return;
  1812. }
  1813. /* disable DC (port F) */
  1814. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1815. /* external mic, port B */
  1816. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1817. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1818. /* internal mic, port C */
  1819. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1820. spec->ext_mic_present ? 0 : PIN_VREF80);
  1821. }
  1822. /* toggle input of built-in and mic jack appropriately */
  1823. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1824. {
  1825. struct conexant_spec *spec = codec->spec;
  1826. unsigned int present;
  1827. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1828. return;
  1829. present = snd_hda_codec_read(codec, 0x1a, 0,
  1830. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1831. if (present)
  1832. snd_printdd("CXT5066: external microphone detected\n");
  1833. else
  1834. snd_printdd("CXT5066: external microphone absent\n");
  1835. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1836. present ? 0 : 1);
  1837. spec->ext_mic_present = !!present;
  1838. cxt5066_olpc_select_mic(codec);
  1839. }
  1840. /* toggle input of built-in digital mic and mic jack appropriately */
  1841. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1842. {
  1843. unsigned int present;
  1844. struct hda_verb ext_mic_present[] = {
  1845. /* enable external mic, port B */
  1846. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1847. /* switch to external mic input */
  1848. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1849. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1850. /* disable internal digital mic */
  1851. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1852. {}
  1853. };
  1854. static const struct hda_verb ext_mic_absent[] = {
  1855. /* enable internal mic, port C */
  1856. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1857. /* switch to internal mic input */
  1858. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1859. /* disable external mic, port B */
  1860. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1861. {}
  1862. };
  1863. present = snd_hda_jack_detect(codec, 0x1a);
  1864. if (present) {
  1865. snd_printdd("CXT5066: external microphone detected\n");
  1866. snd_hda_sequence_write(codec, ext_mic_present);
  1867. } else {
  1868. snd_printdd("CXT5066: external microphone absent\n");
  1869. snd_hda_sequence_write(codec, ext_mic_absent);
  1870. }
  1871. }
  1872. /* toggle input of built-in digital mic and mic jack appropriately */
  1873. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1874. {
  1875. unsigned int present;
  1876. struct hda_verb ext_mic_present[] = {
  1877. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1878. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1879. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1880. {}
  1881. };
  1882. static const struct hda_verb ext_mic_absent[] = {
  1883. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1884. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1885. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1886. {}
  1887. };
  1888. present = snd_hda_jack_detect(codec, 0x1b);
  1889. if (present) {
  1890. snd_printdd("CXT5066: external microphone detected\n");
  1891. snd_hda_sequence_write(codec, ext_mic_present);
  1892. } else {
  1893. snd_printdd("CXT5066: external microphone absent\n");
  1894. snd_hda_sequence_write(codec, ext_mic_absent);
  1895. }
  1896. }
  1897. /* toggle input of built-in digital mic and mic jack appropriately */
  1898. static void cxt5066_asus_automic(struct hda_codec *codec)
  1899. {
  1900. unsigned int present;
  1901. present = snd_hda_jack_detect(codec, 0x1b);
  1902. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1903. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1904. present ? 1 : 0);
  1905. }
  1906. /* toggle input of built-in digital mic and mic jack appropriately */
  1907. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  1908. {
  1909. unsigned int present;
  1910. present = snd_hda_jack_detect(codec, 0x1b);
  1911. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1912. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1913. present ? 1 : 3);
  1914. }
  1915. /* toggle input of built-in digital mic and mic jack appropriately
  1916. order is: external mic -> dock mic -> interal mic */
  1917. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1918. {
  1919. unsigned int ext_present, dock_present;
  1920. static const struct hda_verb ext_mic_present[] = {
  1921. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1922. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1923. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1924. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1925. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1926. {}
  1927. };
  1928. static const struct hda_verb dock_mic_present[] = {
  1929. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1930. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1931. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1932. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1933. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1934. {}
  1935. };
  1936. static const struct hda_verb ext_mic_absent[] = {
  1937. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1938. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1939. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1940. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1941. {}
  1942. };
  1943. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1944. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1945. if (ext_present) {
  1946. snd_printdd("CXT5066: external microphone detected\n");
  1947. snd_hda_sequence_write(codec, ext_mic_present);
  1948. } else if (dock_present) {
  1949. snd_printdd("CXT5066: dock microphone detected\n");
  1950. snd_hda_sequence_write(codec, dock_mic_present);
  1951. } else {
  1952. snd_printdd("CXT5066: external microphone absent\n");
  1953. snd_hda_sequence_write(codec, ext_mic_absent);
  1954. }
  1955. }
  1956. /* mute internal speaker if HP is plugged */
  1957. static void cxt5066_hp_automute(struct hda_codec *codec)
  1958. {
  1959. struct conexant_spec *spec = codec->spec;
  1960. unsigned int portA, portD;
  1961. /* Port A */
  1962. portA = snd_hda_jack_detect(codec, 0x19);
  1963. /* Port D */
  1964. portD = snd_hda_jack_detect(codec, 0x1c);
  1965. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  1966. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  1967. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1968. portA, portD, spec->hp_present);
  1969. cxt5066_update_speaker(codec);
  1970. }
  1971. /* Dispatch the right mic autoswitch function */
  1972. static void cxt5066_automic(struct hda_codec *codec)
  1973. {
  1974. struct conexant_spec *spec = codec->spec;
  1975. if (spec->dell_vostro)
  1976. cxt5066_vostro_automic(codec);
  1977. else if (spec->ideapad)
  1978. cxt5066_ideapad_automic(codec);
  1979. else if (spec->thinkpad)
  1980. cxt5066_thinkpad_automic(codec);
  1981. else if (spec->hp_laptop)
  1982. cxt5066_hp_laptop_automic(codec);
  1983. else if (spec->asus)
  1984. cxt5066_asus_automic(codec);
  1985. }
  1986. /* unsolicited event for jack sensing */
  1987. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  1988. {
  1989. struct conexant_spec *spec = codec->spec;
  1990. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1991. switch (res >> 26) {
  1992. case CONEXANT_HP_EVENT:
  1993. cxt5066_hp_automute(codec);
  1994. break;
  1995. case CONEXANT_MIC_EVENT:
  1996. /* ignore mic events in DC mode; we're always using the jack */
  1997. if (!spec->dc_enable)
  1998. cxt5066_olpc_automic(codec);
  1999. break;
  2000. }
  2001. }
  2002. /* unsolicited event for jack sensing */
  2003. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  2004. {
  2005. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2006. switch (res >> 26) {
  2007. case CONEXANT_HP_EVENT:
  2008. cxt5066_hp_automute(codec);
  2009. break;
  2010. case CONEXANT_MIC_EVENT:
  2011. cxt5066_automic(codec);
  2012. break;
  2013. }
  2014. }
  2015. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2016. .num_items = 5,
  2017. .items = {
  2018. { "0dB", 0 },
  2019. { "10dB", 1 },
  2020. { "20dB", 2 },
  2021. { "30dB", 3 },
  2022. { "40dB", 4 },
  2023. },
  2024. };
  2025. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2026. {
  2027. struct conexant_spec *spec = codec->spec;
  2028. snd_hda_codec_write_cache(codec, 0x17, 0,
  2029. AC_VERB_SET_AMP_GAIN_MUTE,
  2030. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2031. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2032. if (spec->ideapad || spec->thinkpad) {
  2033. /* adjust the internal mic as well...it is not through 0x17 */
  2034. snd_hda_codec_write_cache(codec, 0x23, 0,
  2035. AC_VERB_SET_AMP_GAIN_MUTE,
  2036. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2037. cxt5066_analog_mic_boost.
  2038. items[spec->mic_boost].index);
  2039. }
  2040. }
  2041. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2042. struct snd_ctl_elem_info *uinfo)
  2043. {
  2044. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2045. }
  2046. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2047. struct snd_ctl_elem_value *ucontrol)
  2048. {
  2049. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2050. struct conexant_spec *spec = codec->spec;
  2051. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2052. return 0;
  2053. }
  2054. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2055. struct snd_ctl_elem_value *ucontrol)
  2056. {
  2057. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2058. struct conexant_spec *spec = codec->spec;
  2059. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2060. unsigned int idx;
  2061. idx = ucontrol->value.enumerated.item[0];
  2062. if (idx >= imux->num_items)
  2063. idx = imux->num_items - 1;
  2064. spec->mic_boost = idx;
  2065. if (!spec->dc_enable)
  2066. cxt5066_set_mic_boost(codec);
  2067. return 1;
  2068. }
  2069. static void cxt5066_enable_dc(struct hda_codec *codec)
  2070. {
  2071. const struct hda_verb enable_dc_mode[] = {
  2072. /* disable gain */
  2073. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2074. /* switch to DC input */
  2075. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2076. {}
  2077. };
  2078. /* configure as input source */
  2079. snd_hda_sequence_write(codec, enable_dc_mode);
  2080. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2081. }
  2082. static void cxt5066_disable_dc(struct hda_codec *codec)
  2083. {
  2084. /* reconfigure input source */
  2085. cxt5066_set_mic_boost(codec);
  2086. /* automic also selects the right mic if we're recording */
  2087. cxt5066_olpc_automic(codec);
  2088. }
  2089. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2090. struct snd_ctl_elem_value *ucontrol)
  2091. {
  2092. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2093. struct conexant_spec *spec = codec->spec;
  2094. ucontrol->value.integer.value[0] = spec->dc_enable;
  2095. return 0;
  2096. }
  2097. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2098. struct snd_ctl_elem_value *ucontrol)
  2099. {
  2100. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2101. struct conexant_spec *spec = codec->spec;
  2102. int dc_enable = !!ucontrol->value.integer.value[0];
  2103. if (dc_enable == spec->dc_enable)
  2104. return 0;
  2105. spec->dc_enable = dc_enable;
  2106. if (dc_enable)
  2107. cxt5066_enable_dc(codec);
  2108. else
  2109. cxt5066_disable_dc(codec);
  2110. return 1;
  2111. }
  2112. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2113. struct snd_ctl_elem_info *uinfo)
  2114. {
  2115. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2116. }
  2117. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2118. struct snd_ctl_elem_value *ucontrol)
  2119. {
  2120. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2121. struct conexant_spec *spec = codec->spec;
  2122. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2123. return 0;
  2124. }
  2125. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2126. struct snd_ctl_elem_value *ucontrol)
  2127. {
  2128. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2129. struct conexant_spec *spec = codec->spec;
  2130. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2131. unsigned int idx;
  2132. idx = ucontrol->value.enumerated.item[0];
  2133. if (idx >= imux->num_items)
  2134. idx = imux->num_items - 1;
  2135. spec->dc_input_bias = idx;
  2136. if (spec->dc_enable)
  2137. cxt5066_set_olpc_dc_bias(codec);
  2138. return 1;
  2139. }
  2140. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2141. {
  2142. struct conexant_spec *spec = codec->spec;
  2143. /* mark as recording and configure the microphone widget so that the
  2144. * recording LED comes on. */
  2145. spec->recording = 1;
  2146. cxt5066_olpc_select_mic(codec);
  2147. }
  2148. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2149. {
  2150. struct conexant_spec *spec = codec->spec;
  2151. const struct hda_verb disable_mics[] = {
  2152. /* disable external mic, port B */
  2153. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2154. /* disble internal mic, port C */
  2155. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2156. /* disable DC capture, port F */
  2157. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2158. {},
  2159. };
  2160. snd_hda_sequence_write(codec, disable_mics);
  2161. spec->recording = 0;
  2162. }
  2163. static void conexant_check_dig_outs(struct hda_codec *codec,
  2164. const hda_nid_t *dig_pins,
  2165. int num_pins)
  2166. {
  2167. struct conexant_spec *spec = codec->spec;
  2168. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  2169. int i;
  2170. for (i = 0; i < num_pins; i++, dig_pins++) {
  2171. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  2172. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  2173. continue;
  2174. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  2175. continue;
  2176. if (spec->slave_dig_outs[0])
  2177. nid_loc++;
  2178. else
  2179. nid_loc = spec->slave_dig_outs;
  2180. }
  2181. }
  2182. static const struct hda_input_mux cxt5066_capture_source = {
  2183. .num_items = 4,
  2184. .items = {
  2185. { "Mic B", 0 },
  2186. { "Mic C", 1 },
  2187. { "Mic E", 2 },
  2188. { "Mic F", 3 },
  2189. },
  2190. };
  2191. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2192. .ops = &snd_hda_bind_vol,
  2193. .values = {
  2194. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2195. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2196. 0
  2197. },
  2198. };
  2199. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2200. .ops = &snd_hda_bind_sw,
  2201. .values = {
  2202. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2203. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2204. 0
  2205. },
  2206. };
  2207. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2208. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2209. {}
  2210. };
  2211. static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2212. {
  2213. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2214. .name = "Master Playback Volume",
  2215. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2216. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2217. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2218. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2219. .info = snd_hda_mixer_amp_volume_info,
  2220. .get = snd_hda_mixer_amp_volume_get,
  2221. .put = snd_hda_mixer_amp_volume_put,
  2222. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2223. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2224. .private_value =
  2225. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2226. },
  2227. {}
  2228. };
  2229. static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2230. {
  2231. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2232. .name = "DC Mode Enable Switch",
  2233. .info = snd_ctl_boolean_mono_info,
  2234. .get = cxt5066_olpc_dc_get,
  2235. .put = cxt5066_olpc_dc_put,
  2236. },
  2237. {
  2238. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2239. .name = "DC Input Bias Enum",
  2240. .info = cxt5066_olpc_dc_bias_enum_info,
  2241. .get = cxt5066_olpc_dc_bias_enum_get,
  2242. .put = cxt5066_olpc_dc_bias_enum_put,
  2243. },
  2244. {}
  2245. };
  2246. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  2247. {
  2248. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2249. .name = "Master Playback Switch",
  2250. .info = cxt_eapd_info,
  2251. .get = cxt_eapd_get,
  2252. .put = cxt5066_hp_master_sw_put,
  2253. .private_value = 0x1d,
  2254. },
  2255. {
  2256. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2257. .name = "Analog Mic Boost Capture Enum",
  2258. .info = cxt5066_mic_boost_mux_enum_info,
  2259. .get = cxt5066_mic_boost_mux_enum_get,
  2260. .put = cxt5066_mic_boost_mux_enum_put,
  2261. },
  2262. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2263. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2264. {}
  2265. };
  2266. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2267. {
  2268. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2269. .name = "Internal Mic Boost Capture Enum",
  2270. .info = cxt5066_mic_boost_mux_enum_info,
  2271. .get = cxt5066_mic_boost_mux_enum_get,
  2272. .put = cxt5066_mic_boost_mux_enum_put,
  2273. .private_value = 0x23 | 0x100,
  2274. },
  2275. {}
  2276. };
  2277. static const struct hda_verb cxt5066_init_verbs[] = {
  2278. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2279. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2280. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2281. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2282. /* Speakers */
  2283. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2284. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2285. /* HP, Amp */
  2286. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2287. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2288. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2289. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2290. /* DAC1 */
  2291. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2292. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2293. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2294. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2295. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2296. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2297. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2298. /* no digital microphone support yet */
  2299. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2300. /* Audio input selector */
  2301. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2302. /* SPDIF route: PCM */
  2303. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2304. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2305. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2306. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2307. /* EAPD */
  2308. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2309. /* not handling these yet */
  2310. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2311. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2312. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2313. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2314. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2315. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2316. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2317. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2318. { } /* end */
  2319. };
  2320. static const struct hda_verb cxt5066_init_verbs_olpc[] = {
  2321. /* Port A: headphones */
  2322. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2323. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2324. /* Port B: external microphone */
  2325. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2326. /* Port C: internal microphone */
  2327. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2328. /* Port D: unused */
  2329. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2330. /* Port E: unused, but has primary EAPD */
  2331. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2332. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2333. /* Port F: external DC input through microphone port */
  2334. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2335. /* Port G: internal speakers */
  2336. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2337. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2338. /* DAC1 */
  2339. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2340. /* DAC2: unused */
  2341. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2342. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2343. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2344. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2345. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2346. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2347. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2348. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2349. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2350. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2351. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2352. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2353. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2354. /* Disable digital microphone port */
  2355. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2356. /* Audio input selectors */
  2357. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2358. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2359. /* Disable SPDIF */
  2360. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2361. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2362. /* enable unsolicited events for Port A and B */
  2363. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2364. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2365. { } /* end */
  2366. };
  2367. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2368. /* Port A: headphones */
  2369. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2370. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2371. /* Port B: external microphone */
  2372. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2373. /* Port C: unused */
  2374. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2375. /* Port D: unused */
  2376. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2377. /* Port E: unused, but has primary EAPD */
  2378. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2379. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2380. /* Port F: unused */
  2381. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2382. /* Port G: internal speakers */
  2383. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2384. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2385. /* DAC1 */
  2386. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2387. /* DAC2: unused */
  2388. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2389. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2390. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2391. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2392. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2393. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2394. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2395. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2396. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2397. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2398. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2399. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2400. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2401. /* Digital microphone port */
  2402. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2403. /* Audio input selectors */
  2404. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2405. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2406. /* Disable SPDIF */
  2407. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2408. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2409. /* enable unsolicited events for Port A and B */
  2410. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2411. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2412. { } /* end */
  2413. };
  2414. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2415. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2416. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2417. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2418. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2419. /* Speakers */
  2420. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2421. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2422. /* HP, Amp */
  2423. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2424. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2425. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2426. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2427. /* DAC1 */
  2428. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2429. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2430. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2431. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2432. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2433. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2434. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2435. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2436. /* Audio input selector */
  2437. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2438. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2439. /* SPDIF route: PCM */
  2440. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2441. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2442. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2443. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2444. /* internal microphone */
  2445. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2446. /* EAPD */
  2447. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2448. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2449. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2450. { } /* end */
  2451. };
  2452. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2453. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2454. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2455. /* Port G: internal speakers */
  2456. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2457. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2458. /* Port A: HP, Amp */
  2459. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2460. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2461. /* Port B: Mic Dock */
  2462. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2463. /* Port C: Mic */
  2464. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2465. /* Port D: HP Dock, Amp */
  2466. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2467. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2468. /* DAC1 */
  2469. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2470. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2471. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2472. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2473. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2474. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2475. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2476. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2477. /* Audio input selector */
  2478. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2479. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2480. /* SPDIF route: PCM */
  2481. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2482. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2483. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2484. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2485. /* internal microphone */
  2486. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2487. /* EAPD */
  2488. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2489. /* enable unsolicited events for Port A, B, C and D */
  2490. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2491. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2492. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2493. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2494. { } /* end */
  2495. };
  2496. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2497. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2498. { } /* end */
  2499. };
  2500. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2501. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2502. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2503. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2504. { } /* end */
  2505. };
  2506. /* initialize jack-sensing, too */
  2507. static int cxt5066_init(struct hda_codec *codec)
  2508. {
  2509. snd_printdd("CXT5066: init\n");
  2510. conexant_init(codec);
  2511. if (codec->patch_ops.unsol_event) {
  2512. cxt5066_hp_automute(codec);
  2513. cxt5066_automic(codec);
  2514. }
  2515. cxt5066_set_mic_boost(codec);
  2516. return 0;
  2517. }
  2518. static int cxt5066_olpc_init(struct hda_codec *codec)
  2519. {
  2520. struct conexant_spec *spec = codec->spec;
  2521. snd_printdd("CXT5066: init\n");
  2522. conexant_init(codec);
  2523. cxt5066_hp_automute(codec);
  2524. if (!spec->dc_enable) {
  2525. cxt5066_set_mic_boost(codec);
  2526. cxt5066_olpc_automic(codec);
  2527. } else {
  2528. cxt5066_enable_dc(codec);
  2529. }
  2530. return 0;
  2531. }
  2532. enum {
  2533. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2534. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2535. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2536. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2537. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2538. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2539. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2540. CXT5066_HP_LAPTOP, /* HP Laptop */
  2541. CXT5066_AUTO, /* BIOS auto-parser */
  2542. CXT5066_MODELS
  2543. };
  2544. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2545. [CXT5066_LAPTOP] = "laptop",
  2546. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2547. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2548. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2549. [CXT5066_IDEAPAD] = "ideapad",
  2550. [CXT5066_THINKPAD] = "thinkpad",
  2551. [CXT5066_ASUS] = "asus",
  2552. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2553. [CXT5066_AUTO] = "auto",
  2554. };
  2555. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2556. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
  2557. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2558. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2559. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2560. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2561. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2562. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2563. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2564. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2565. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2566. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2567. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2568. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2569. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2570. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2571. CXT5066_LAPTOP),
  2572. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2573. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2574. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2575. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2576. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
  2577. SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
  2578. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
  2579. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
  2580. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2581. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2582. SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
  2583. SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
  2584. {}
  2585. };
  2586. static int patch_cxt5066(struct hda_codec *codec)
  2587. {
  2588. struct conexant_spec *spec;
  2589. int board_config;
  2590. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2591. cxt5066_models, cxt5066_cfg_tbl);
  2592. if (board_config < 0)
  2593. board_config = CXT5066_AUTO; /* model=auto as default */
  2594. if (board_config == CXT5066_AUTO)
  2595. return patch_conexant_auto(codec);
  2596. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2597. if (!spec)
  2598. return -ENOMEM;
  2599. codec->spec = spec;
  2600. codec->patch_ops = conexant_patch_ops;
  2601. codec->patch_ops.init = conexant_init;
  2602. spec->dell_automute = 0;
  2603. spec->multiout.max_channels = 2;
  2604. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2605. spec->multiout.dac_nids = cxt5066_dac_nids;
  2606. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2607. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2608. spec->num_adc_nids = 1;
  2609. spec->adc_nids = cxt5066_adc_nids;
  2610. spec->capsrc_nids = cxt5066_capsrc_nids;
  2611. spec->input_mux = &cxt5066_capture_source;
  2612. spec->port_d_mode = PIN_HP;
  2613. spec->num_init_verbs = 1;
  2614. spec->init_verbs[0] = cxt5066_init_verbs;
  2615. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2616. spec->channel_mode = cxt5066_modes;
  2617. spec->cur_adc = 0;
  2618. spec->cur_adc_idx = 0;
  2619. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2620. switch (board_config) {
  2621. default:
  2622. case CXT5066_LAPTOP:
  2623. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2624. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2625. break;
  2626. case CXT5066_DELL_LAPTOP:
  2627. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2628. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2629. spec->port_d_mode = PIN_OUT;
  2630. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2631. spec->num_init_verbs++;
  2632. spec->dell_automute = 1;
  2633. break;
  2634. case CXT5066_ASUS:
  2635. case CXT5066_HP_LAPTOP:
  2636. codec->patch_ops.init = cxt5066_init;
  2637. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2638. spec->init_verbs[spec->num_init_verbs] =
  2639. cxt5066_init_verbs_hp_laptop;
  2640. spec->num_init_verbs++;
  2641. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2642. spec->asus = board_config == CXT5066_ASUS;
  2643. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2644. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2645. /* no S/PDIF out */
  2646. if (board_config == CXT5066_HP_LAPTOP)
  2647. spec->multiout.dig_out_nid = 0;
  2648. /* input source automatically selected */
  2649. spec->input_mux = NULL;
  2650. spec->port_d_mode = 0;
  2651. spec->mic_boost = 3; /* default 30dB gain */
  2652. break;
  2653. case CXT5066_OLPC_XO_1_5:
  2654. codec->patch_ops.init = cxt5066_olpc_init;
  2655. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2656. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2657. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2658. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2659. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2660. spec->port_d_mode = 0;
  2661. spec->mic_boost = 3; /* default 30dB gain */
  2662. /* no S/PDIF out */
  2663. spec->multiout.dig_out_nid = 0;
  2664. /* input source automatically selected */
  2665. spec->input_mux = NULL;
  2666. /* our capture hooks which allow us to turn on the microphone LED
  2667. * at the right time */
  2668. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2669. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2670. break;
  2671. case CXT5066_DELL_VOSTRO:
  2672. codec->patch_ops.init = cxt5066_init;
  2673. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2674. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2675. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2676. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2677. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2678. spec->port_d_mode = 0;
  2679. spec->dell_vostro = 1;
  2680. spec->mic_boost = 3; /* default 30dB gain */
  2681. /* no S/PDIF out */
  2682. spec->multiout.dig_out_nid = 0;
  2683. /* input source automatically selected */
  2684. spec->input_mux = NULL;
  2685. break;
  2686. case CXT5066_IDEAPAD:
  2687. codec->patch_ops.init = cxt5066_init;
  2688. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2689. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2690. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2691. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2692. spec->port_d_mode = 0;
  2693. spec->ideapad = 1;
  2694. spec->mic_boost = 2; /* default 20dB gain */
  2695. /* no S/PDIF out */
  2696. spec->multiout.dig_out_nid = 0;
  2697. /* input source automatically selected */
  2698. spec->input_mux = NULL;
  2699. break;
  2700. case CXT5066_THINKPAD:
  2701. codec->patch_ops.init = cxt5066_init;
  2702. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2703. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2704. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2705. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2706. spec->thinkpad = 1;
  2707. spec->port_d_mode = PIN_OUT;
  2708. spec->mic_boost = 2; /* default 20dB gain */
  2709. /* no S/PDIF out */
  2710. spec->multiout.dig_out_nid = 0;
  2711. /* input source automatically selected */
  2712. spec->input_mux = NULL;
  2713. break;
  2714. }
  2715. if (spec->beep_amp)
  2716. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  2717. return 0;
  2718. }
  2719. /*
  2720. * Automatic parser for CX20641 & co
  2721. */
  2722. static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2723. struct hda_codec *codec,
  2724. unsigned int stream_tag,
  2725. unsigned int format,
  2726. struct snd_pcm_substream *substream)
  2727. {
  2728. struct conexant_spec *spec = codec->spec;
  2729. hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
  2730. if (spec->adc_switching) {
  2731. spec->cur_adc = adc;
  2732. spec->cur_adc_stream_tag = stream_tag;
  2733. spec->cur_adc_format = format;
  2734. }
  2735. snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
  2736. return 0;
  2737. }
  2738. static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2739. struct hda_codec *codec,
  2740. struct snd_pcm_substream *substream)
  2741. {
  2742. struct conexant_spec *spec = codec->spec;
  2743. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  2744. spec->cur_adc = 0;
  2745. return 0;
  2746. }
  2747. static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
  2748. .substreams = 1,
  2749. .channels_min = 2,
  2750. .channels_max = 2,
  2751. .nid = 0, /* fill later */
  2752. .ops = {
  2753. .prepare = cx_auto_capture_pcm_prepare,
  2754. .cleanup = cx_auto_capture_pcm_cleanup
  2755. },
  2756. };
  2757. static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
  2758. #define get_connection_index(codec, mux, nid)\
  2759. snd_hda_get_conn_index(codec, mux, nid, 0)
  2760. /* get an unassigned DAC from the given list.
  2761. * Return the nid if found and reduce the DAC list, or return zero if
  2762. * not found
  2763. */
  2764. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
  2765. hda_nid_t *dacs, int *num_dacs)
  2766. {
  2767. int i, nums = *num_dacs;
  2768. hda_nid_t ret = 0;
  2769. for (i = 0; i < nums; i++) {
  2770. if (get_connection_index(codec, pin, dacs[i]) >= 0) {
  2771. ret = dacs[i];
  2772. break;
  2773. }
  2774. }
  2775. if (!ret)
  2776. return 0;
  2777. if (--nums > 0)
  2778. memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
  2779. *num_dacs = nums;
  2780. return ret;
  2781. }
  2782. #define MAX_AUTO_DACS 5
  2783. #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
  2784. /* fill analog DAC list from the widget tree */
  2785. static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  2786. {
  2787. hda_nid_t nid, end_nid;
  2788. int nums = 0;
  2789. end_nid = codec->start_nid + codec->num_nodes;
  2790. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2791. unsigned int wcaps = get_wcaps(codec, nid);
  2792. unsigned int type = get_wcaps_type(wcaps);
  2793. if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
  2794. dacs[nums++] = nid;
  2795. if (nums >= MAX_AUTO_DACS)
  2796. break;
  2797. }
  2798. }
  2799. return nums;
  2800. }
  2801. /* fill pin_dac_pair list from the pin and dac list */
  2802. static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  2803. int num_pins, hda_nid_t *dacs, int *rest,
  2804. struct pin_dac_pair *filled, int nums,
  2805. int type)
  2806. {
  2807. int i, start = nums;
  2808. for (i = 0; i < num_pins; i++, nums++) {
  2809. filled[nums].pin = pins[i];
  2810. filled[nums].type = type;
  2811. filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
  2812. if (filled[nums].dac)
  2813. continue;
  2814. if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
  2815. filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
  2816. continue;
  2817. }
  2818. if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
  2819. filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
  2820. continue;
  2821. }
  2822. snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
  2823. }
  2824. return nums;
  2825. }
  2826. /* parse analog output paths */
  2827. static void cx_auto_parse_output(struct hda_codec *codec)
  2828. {
  2829. struct conexant_spec *spec = codec->spec;
  2830. struct auto_pin_cfg *cfg = &spec->autocfg;
  2831. hda_nid_t dacs[MAX_AUTO_DACS];
  2832. int i, j, nums, rest;
  2833. rest = fill_cx_auto_dacs(codec, dacs);
  2834. /* parse all analog output pins */
  2835. nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
  2836. dacs, &rest, spec->dac_info, 0,
  2837. AUTO_PIN_LINE_OUT);
  2838. nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
  2839. dacs, &rest, spec->dac_info, nums,
  2840. AUTO_PIN_HP_OUT);
  2841. nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
  2842. dacs, &rest, spec->dac_info, nums,
  2843. AUTO_PIN_SPEAKER_OUT);
  2844. spec->dac_info_filled = nums;
  2845. /* fill multiout struct */
  2846. for (i = 0; i < nums; i++) {
  2847. hda_nid_t dac = spec->dac_info[i].dac;
  2848. if (!dac || (dac & DAC_SLAVE_FLAG))
  2849. continue;
  2850. switch (spec->dac_info[i].type) {
  2851. case AUTO_PIN_LINE_OUT:
  2852. spec->private_dac_nids[spec->multiout.num_dacs] = dac;
  2853. spec->multiout.num_dacs++;
  2854. break;
  2855. case AUTO_PIN_HP_OUT:
  2856. case AUTO_PIN_SPEAKER_OUT:
  2857. if (!spec->multiout.hp_nid) {
  2858. spec->multiout.hp_nid = dac;
  2859. break;
  2860. }
  2861. for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
  2862. if (!spec->multiout.extra_out_nid[j]) {
  2863. spec->multiout.extra_out_nid[j] = dac;
  2864. break;
  2865. }
  2866. break;
  2867. }
  2868. }
  2869. spec->multiout.dac_nids = spec->private_dac_nids;
  2870. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2871. for (i = 0; i < cfg->hp_outs; i++) {
  2872. if (is_jack_detectable(codec, cfg->hp_pins[i])) {
  2873. spec->auto_mute = 1;
  2874. break;
  2875. }
  2876. }
  2877. if (spec->auto_mute &&
  2878. cfg->line_out_pins[0] &&
  2879. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
  2880. cfg->line_out_pins[0] != cfg->hp_pins[0] &&
  2881. cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
  2882. for (i = 0; i < cfg->line_outs; i++) {
  2883. if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
  2884. spec->detect_line = 1;
  2885. break;
  2886. }
  2887. }
  2888. spec->automute_lines = spec->detect_line;
  2889. }
  2890. spec->vmaster_nid = spec->private_dac_nids[0];
  2891. }
  2892. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2893. hda_nid_t *pins, bool on);
  2894. static void do_automute(struct hda_codec *codec, int num_pins,
  2895. hda_nid_t *pins, bool on)
  2896. {
  2897. struct conexant_spec *spec = codec->spec;
  2898. int i;
  2899. for (i = 0; i < num_pins; i++)
  2900. snd_hda_codec_write(codec, pins[i], 0,
  2901. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2902. on ? PIN_OUT : 0);
  2903. if (spec->pin_eapd_ctrls)
  2904. cx_auto_turn_eapd(codec, num_pins, pins, on);
  2905. }
  2906. static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  2907. {
  2908. int i, present = 0;
  2909. for (i = 0; i < num_pins; i++) {
  2910. hda_nid_t nid = pins[i];
  2911. if (!nid || !is_jack_detectable(codec, nid))
  2912. break;
  2913. present |= snd_hda_jack_detect(codec, nid);
  2914. }
  2915. return present;
  2916. }
  2917. /* auto-mute/unmute speaker and line outs according to headphone jack */
  2918. static void cx_auto_update_speakers(struct hda_codec *codec)
  2919. {
  2920. struct conexant_spec *spec = codec->spec;
  2921. struct auto_pin_cfg *cfg = &spec->autocfg;
  2922. int on = 1;
  2923. /* turn on HP EAPD when HP jacks are present */
  2924. if (spec->pin_eapd_ctrls) {
  2925. if (spec->auto_mute)
  2926. on = spec->hp_present;
  2927. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
  2928. }
  2929. /* mute speakers in auto-mode if HP or LO jacks are plugged */
  2930. if (spec->auto_mute)
  2931. on = !(spec->hp_present ||
  2932. (spec->detect_line && spec->line_present));
  2933. do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
  2934. /* toggle line-out mutes if needed, too */
  2935. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  2936. if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
  2937. cfg->line_out_pins[0] == cfg->speaker_pins[0])
  2938. return;
  2939. if (spec->auto_mute) {
  2940. /* mute LO in auto-mode when HP jack is present */
  2941. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
  2942. spec->automute_lines)
  2943. on = !spec->hp_present;
  2944. else
  2945. on = 1;
  2946. }
  2947. do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
  2948. }
  2949. static void cx_auto_hp_automute(struct hda_codec *codec)
  2950. {
  2951. struct conexant_spec *spec = codec->spec;
  2952. struct auto_pin_cfg *cfg = &spec->autocfg;
  2953. if (!spec->auto_mute)
  2954. return;
  2955. spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
  2956. cx_auto_update_speakers(codec);
  2957. }
  2958. static void cx_auto_line_automute(struct hda_codec *codec)
  2959. {
  2960. struct conexant_spec *spec = codec->spec;
  2961. struct auto_pin_cfg *cfg = &spec->autocfg;
  2962. if (!spec->auto_mute || !spec->detect_line)
  2963. return;
  2964. spec->line_present = detect_jacks(codec, cfg->line_outs,
  2965. cfg->line_out_pins);
  2966. cx_auto_update_speakers(codec);
  2967. }
  2968. static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
  2969. struct snd_ctl_elem_info *uinfo)
  2970. {
  2971. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2972. struct conexant_spec *spec = codec->spec;
  2973. static const char * const texts2[] = {
  2974. "Disabled", "Enabled"
  2975. };
  2976. static const char * const texts3[] = {
  2977. "Disabled", "Speaker Only", "Line Out+Speaker"
  2978. };
  2979. const char * const *texts;
  2980. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2981. uinfo->count = 1;
  2982. if (spec->automute_hp_lo) {
  2983. uinfo->value.enumerated.items = 3;
  2984. texts = texts3;
  2985. } else {
  2986. uinfo->value.enumerated.items = 2;
  2987. texts = texts2;
  2988. }
  2989. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2990. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2991. strcpy(uinfo->value.enumerated.name,
  2992. texts[uinfo->value.enumerated.item]);
  2993. return 0;
  2994. }
  2995. static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
  2996. struct snd_ctl_elem_value *ucontrol)
  2997. {
  2998. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2999. struct conexant_spec *spec = codec->spec;
  3000. unsigned int val;
  3001. if (!spec->auto_mute)
  3002. val = 0;
  3003. else if (!spec->automute_lines)
  3004. val = 1;
  3005. else
  3006. val = 2;
  3007. ucontrol->value.enumerated.item[0] = val;
  3008. return 0;
  3009. }
  3010. static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
  3011. struct snd_ctl_elem_value *ucontrol)
  3012. {
  3013. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3014. struct conexant_spec *spec = codec->spec;
  3015. switch (ucontrol->value.enumerated.item[0]) {
  3016. case 0:
  3017. if (!spec->auto_mute)
  3018. return 0;
  3019. spec->auto_mute = 0;
  3020. break;
  3021. case 1:
  3022. if (spec->auto_mute && !spec->automute_lines)
  3023. return 0;
  3024. spec->auto_mute = 1;
  3025. spec->automute_lines = 0;
  3026. break;
  3027. case 2:
  3028. if (!spec->automute_hp_lo)
  3029. return -EINVAL;
  3030. if (spec->auto_mute && spec->automute_lines)
  3031. return 0;
  3032. spec->auto_mute = 1;
  3033. spec->automute_lines = 1;
  3034. break;
  3035. default:
  3036. return -EINVAL;
  3037. }
  3038. cx_auto_update_speakers(codec);
  3039. return 1;
  3040. }
  3041. static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
  3042. {
  3043. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3044. .name = "Auto-Mute Mode",
  3045. .info = cx_automute_mode_info,
  3046. .get = cx_automute_mode_get,
  3047. .put = cx_automute_mode_put,
  3048. },
  3049. { }
  3050. };
  3051. static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
  3052. struct snd_ctl_elem_info *uinfo)
  3053. {
  3054. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3055. struct conexant_spec *spec = codec->spec;
  3056. return snd_hda_input_mux_info(&spec->private_imux, uinfo);
  3057. }
  3058. static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
  3059. struct snd_ctl_elem_value *ucontrol)
  3060. {
  3061. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3062. struct conexant_spec *spec = codec->spec;
  3063. ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
  3064. return 0;
  3065. }
  3066. /* look for the route the given pin from mux and return the index;
  3067. * if do_select is set, actually select the route.
  3068. */
  3069. static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3070. hda_nid_t pin, hda_nid_t *srcp,
  3071. bool do_select, int depth)
  3072. {
  3073. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3074. int i, nums;
  3075. switch (get_wcaps_type(get_wcaps(codec, mux))) {
  3076. case AC_WID_AUD_IN:
  3077. case AC_WID_AUD_SEL:
  3078. case AC_WID_AUD_MIX:
  3079. break;
  3080. default:
  3081. return -1;
  3082. }
  3083. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3084. for (i = 0; i < nums; i++)
  3085. if (conn[i] == pin) {
  3086. if (do_select)
  3087. snd_hda_codec_write(codec, mux, 0,
  3088. AC_VERB_SET_CONNECT_SEL, i);
  3089. if (srcp)
  3090. *srcp = mux;
  3091. return i;
  3092. }
  3093. depth++;
  3094. if (depth == 2)
  3095. return -1;
  3096. for (i = 0; i < nums; i++) {
  3097. int ret = __select_input_connection(codec, conn[i], pin, srcp,
  3098. do_select, depth);
  3099. if (ret >= 0) {
  3100. if (do_select)
  3101. snd_hda_codec_write(codec, mux, 0,
  3102. AC_VERB_SET_CONNECT_SEL, i);
  3103. return i;
  3104. }
  3105. }
  3106. return -1;
  3107. }
  3108. static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3109. hda_nid_t pin)
  3110. {
  3111. __select_input_connection(codec, mux, pin, NULL, true, 0);
  3112. }
  3113. static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3114. hda_nid_t pin)
  3115. {
  3116. return __select_input_connection(codec, mux, pin, NULL, false, 0);
  3117. }
  3118. static int cx_auto_mux_enum_update(struct hda_codec *codec,
  3119. const struct hda_input_mux *imux,
  3120. unsigned int idx)
  3121. {
  3122. struct conexant_spec *spec = codec->spec;
  3123. hda_nid_t adc;
  3124. int changed = 1;
  3125. if (!imux->num_items)
  3126. return 0;
  3127. if (idx >= imux->num_items)
  3128. idx = imux->num_items - 1;
  3129. if (spec->cur_mux[0] == idx)
  3130. changed = 0;
  3131. adc = spec->imux_info[idx].adc;
  3132. select_input_connection(codec, spec->imux_info[idx].adc,
  3133. spec->imux_info[idx].pin);
  3134. if (spec->cur_adc && spec->cur_adc != adc) {
  3135. /* stream is running, let's swap the current ADC */
  3136. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  3137. spec->cur_adc = adc;
  3138. snd_hda_codec_setup_stream(codec, adc,
  3139. spec->cur_adc_stream_tag, 0,
  3140. spec->cur_adc_format);
  3141. }
  3142. spec->cur_mux[0] = idx;
  3143. return changed;
  3144. }
  3145. static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
  3146. struct snd_ctl_elem_value *ucontrol)
  3147. {
  3148. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3149. struct conexant_spec *spec = codec->spec;
  3150. return cx_auto_mux_enum_update(codec, &spec->private_imux,
  3151. ucontrol->value.enumerated.item[0]);
  3152. }
  3153. static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
  3154. {
  3155. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3156. .name = "Capture Source",
  3157. .info = cx_auto_mux_enum_info,
  3158. .get = cx_auto_mux_enum_get,
  3159. .put = cx_auto_mux_enum_put
  3160. },
  3161. {}
  3162. };
  3163. static bool select_automic(struct hda_codec *codec, int idx, bool detect)
  3164. {
  3165. struct conexant_spec *spec = codec->spec;
  3166. if (idx < 0)
  3167. return false;
  3168. if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
  3169. return false;
  3170. cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
  3171. return true;
  3172. }
  3173. /* automatic switch internal and external mic */
  3174. static void cx_auto_automic(struct hda_codec *codec)
  3175. {
  3176. struct conexant_spec *spec = codec->spec;
  3177. if (!spec->auto_mic)
  3178. return;
  3179. if (!select_automic(codec, spec->auto_mic_ext, true))
  3180. if (!select_automic(codec, spec->auto_mic_dock, true))
  3181. select_automic(codec, spec->auto_mic_int, false);
  3182. }
  3183. static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
  3184. {
  3185. switch (snd_hda_jack_get_action(codec, res >> 26)) {
  3186. case CONEXANT_HP_EVENT:
  3187. cx_auto_hp_automute(codec);
  3188. break;
  3189. case CONEXANT_LINE_EVENT:
  3190. cx_auto_line_automute(codec);
  3191. break;
  3192. case CONEXANT_MIC_EVENT:
  3193. cx_auto_automic(codec);
  3194. break;
  3195. }
  3196. snd_hda_jack_report_sync(codec);
  3197. }
  3198. /* check whether the pin config is suitable for auto-mic switching;
  3199. * auto-mic is enabled only when one int-mic and one ext- and/or
  3200. * one dock-mic exist
  3201. */
  3202. static void cx_auto_check_auto_mic(struct hda_codec *codec)
  3203. {
  3204. struct conexant_spec *spec = codec->spec;
  3205. int pset[INPUT_PIN_ATTR_NORMAL + 1];
  3206. int i;
  3207. for (i = 0; i < ARRAY_SIZE(pset); i++)
  3208. pset[i] = -1;
  3209. for (i = 0; i < spec->private_imux.num_items; i++) {
  3210. hda_nid_t pin = spec->imux_info[i].pin;
  3211. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3212. int type, attr;
  3213. attr = snd_hda_get_input_pin_attr(def_conf);
  3214. if (attr == INPUT_PIN_ATTR_UNUSED)
  3215. return; /* invalid entry */
  3216. if (attr > INPUT_PIN_ATTR_NORMAL)
  3217. attr = INPUT_PIN_ATTR_NORMAL;
  3218. if (attr != INPUT_PIN_ATTR_INT &&
  3219. !is_jack_detectable(codec, pin))
  3220. return; /* non-detectable pin */
  3221. type = get_defcfg_device(def_conf);
  3222. if (type != AC_JACK_MIC_IN &&
  3223. (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
  3224. return; /* no valid input type */
  3225. if (pset[attr] >= 0)
  3226. return; /* already occupied */
  3227. pset[attr] = i;
  3228. }
  3229. if (pset[INPUT_PIN_ATTR_INT] < 0 ||
  3230. (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
  3231. return; /* no input to switch*/
  3232. spec->auto_mic = 1;
  3233. spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
  3234. spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
  3235. spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
  3236. }
  3237. static void cx_auto_parse_input(struct hda_codec *codec)
  3238. {
  3239. struct conexant_spec *spec = codec->spec;
  3240. struct auto_pin_cfg *cfg = &spec->autocfg;
  3241. struct hda_input_mux *imux;
  3242. int i, j;
  3243. imux = &spec->private_imux;
  3244. for (i = 0; i < cfg->num_inputs; i++) {
  3245. for (j = 0; j < spec->num_adc_nids; j++) {
  3246. hda_nid_t adc = spec->adc_nids[j];
  3247. int idx = get_input_connection(codec, adc,
  3248. cfg->inputs[i].pin);
  3249. if (idx >= 0) {
  3250. const char *label;
  3251. label = hda_get_autocfg_input_label(codec, cfg, i);
  3252. spec->imux_info[imux->num_items].index = i;
  3253. spec->imux_info[imux->num_items].boost = 0;
  3254. spec->imux_info[imux->num_items].adc = adc;
  3255. spec->imux_info[imux->num_items].pin =
  3256. cfg->inputs[i].pin;
  3257. snd_hda_add_imux_item(imux, label, idx, NULL);
  3258. break;
  3259. }
  3260. }
  3261. }
  3262. if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
  3263. cx_auto_check_auto_mic(codec);
  3264. if (imux->num_items > 1) {
  3265. for (i = 1; i < imux->num_items; i++) {
  3266. if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
  3267. spec->adc_switching = 1;
  3268. break;
  3269. }
  3270. }
  3271. }
  3272. }
  3273. /* get digital-input audio widget corresponding to the given pin */
  3274. static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
  3275. {
  3276. hda_nid_t nid, end_nid;
  3277. end_nid = codec->start_nid + codec->num_nodes;
  3278. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3279. unsigned int wcaps = get_wcaps(codec, nid);
  3280. unsigned int type = get_wcaps_type(wcaps);
  3281. if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
  3282. if (get_connection_index(codec, nid, pin) >= 0)
  3283. return nid;
  3284. }
  3285. }
  3286. return 0;
  3287. }
  3288. static void cx_auto_parse_digital(struct hda_codec *codec)
  3289. {
  3290. struct conexant_spec *spec = codec->spec;
  3291. struct auto_pin_cfg *cfg = &spec->autocfg;
  3292. hda_nid_t nid;
  3293. if (cfg->dig_outs &&
  3294. snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
  3295. spec->multiout.dig_out_nid = nid;
  3296. if (cfg->dig_in_pin)
  3297. spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
  3298. }
  3299. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3300. static void cx_auto_parse_beep(struct hda_codec *codec)
  3301. {
  3302. struct conexant_spec *spec = codec->spec;
  3303. hda_nid_t nid, end_nid;
  3304. end_nid = codec->start_nid + codec->num_nodes;
  3305. for (nid = codec->start_nid; nid < end_nid; nid++)
  3306. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  3307. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  3308. break;
  3309. }
  3310. }
  3311. #else
  3312. #define cx_auto_parse_beep(codec)
  3313. #endif
  3314. /* parse EAPDs */
  3315. static void cx_auto_parse_eapd(struct hda_codec *codec)
  3316. {
  3317. struct conexant_spec *spec = codec->spec;
  3318. hda_nid_t nid, end_nid;
  3319. end_nid = codec->start_nid + codec->num_nodes;
  3320. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3321. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  3322. continue;
  3323. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  3324. continue;
  3325. spec->eapds[spec->num_eapds++] = nid;
  3326. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  3327. break;
  3328. }
  3329. /* NOTE: below is a wild guess; if we have more than two EAPDs,
  3330. * it's a new chip, where EAPDs are supposed to be associated to
  3331. * pins, and we can control EAPD per pin.
  3332. * OTOH, if only one or two EAPDs are found, it's an old chip,
  3333. * thus it might control over all pins.
  3334. */
  3335. spec->pin_eapd_ctrls = spec->num_eapds > 2;
  3336. }
  3337. static int cx_auto_parse_auto_config(struct hda_codec *codec)
  3338. {
  3339. struct conexant_spec *spec = codec->spec;
  3340. int err;
  3341. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3342. if (err < 0)
  3343. return err;
  3344. cx_auto_parse_output(codec);
  3345. cx_auto_parse_input(codec);
  3346. cx_auto_parse_digital(codec);
  3347. cx_auto_parse_beep(codec);
  3348. cx_auto_parse_eapd(codec);
  3349. return 0;
  3350. }
  3351. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3352. hda_nid_t *pins, bool on)
  3353. {
  3354. int i;
  3355. for (i = 0; i < num_pins; i++) {
  3356. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  3357. snd_hda_codec_write(codec, pins[i], 0,
  3358. AC_VERB_SET_EAPD_BTLENABLE,
  3359. on ? 0x02 : 0);
  3360. }
  3361. }
  3362. static void select_connection(struct hda_codec *codec, hda_nid_t pin,
  3363. hda_nid_t src)
  3364. {
  3365. int idx = get_connection_index(codec, pin, src);
  3366. if (idx >= 0)
  3367. snd_hda_codec_write(codec, pin, 0,
  3368. AC_VERB_SET_CONNECT_SEL, idx);
  3369. }
  3370. static void mute_outputs(struct hda_codec *codec, int num_nids,
  3371. const hda_nid_t *nids)
  3372. {
  3373. int i, val;
  3374. for (i = 0; i < num_nids; i++) {
  3375. hda_nid_t nid = nids[i];
  3376. if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
  3377. continue;
  3378. if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
  3379. val = AMP_OUT_MUTE;
  3380. else
  3381. val = AMP_OUT_ZERO;
  3382. snd_hda_codec_write(codec, nid, 0,
  3383. AC_VERB_SET_AMP_GAIN_MUTE, val);
  3384. }
  3385. }
  3386. static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
  3387. hda_nid_t *pins, unsigned int action)
  3388. {
  3389. int i;
  3390. for (i = 0; i < num_pins; i++)
  3391. snd_hda_jack_detect_enable(codec, pins[i], action);
  3392. }
  3393. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  3394. {
  3395. int i;
  3396. for (i = 0; i < nums; i++)
  3397. if (list[i] == nid)
  3398. return true;
  3399. return false;
  3400. }
  3401. /* is the given NID found in any of autocfg items? */
  3402. static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
  3403. {
  3404. int i;
  3405. if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
  3406. found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
  3407. found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
  3408. found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
  3409. return true;
  3410. for (i = 0; i < cfg->num_inputs; i++)
  3411. if (cfg->inputs[i].pin == nid)
  3412. return true;
  3413. if (cfg->dig_in_pin == nid)
  3414. return true;
  3415. return false;
  3416. }
  3417. /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
  3418. * invalid unsol tags by some reason
  3419. */
  3420. static void clear_unsol_on_unused_pins(struct hda_codec *codec)
  3421. {
  3422. struct conexant_spec *spec = codec->spec;
  3423. struct auto_pin_cfg *cfg = &spec->autocfg;
  3424. int i;
  3425. for (i = 0; i < codec->init_pins.used; i++) {
  3426. struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
  3427. if (!found_in_autocfg(cfg, pin->nid))
  3428. snd_hda_codec_write(codec, pin->nid, 0,
  3429. AC_VERB_SET_UNSOLICITED_ENABLE, 0);
  3430. }
  3431. }
  3432. /* turn on/off EAPD according to Master switch */
  3433. static void cx_auto_vmaster_hook(void *private_data, int enabled)
  3434. {
  3435. struct hda_codec *codec = private_data;
  3436. struct conexant_spec *spec = codec->spec;
  3437. if (enabled && spec->pin_eapd_ctrls) {
  3438. cx_auto_update_speakers(codec);
  3439. return;
  3440. }
  3441. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
  3442. }
  3443. static void cx_auto_init_output(struct hda_codec *codec)
  3444. {
  3445. struct conexant_spec *spec = codec->spec;
  3446. struct auto_pin_cfg *cfg = &spec->autocfg;
  3447. hda_nid_t nid;
  3448. int i;
  3449. mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
  3450. for (i = 0; i < cfg->hp_outs; i++) {
  3451. unsigned int val = PIN_OUT;
  3452. if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
  3453. AC_PINCAP_HP_DRV)
  3454. val |= AC_PINCTL_HP_EN;
  3455. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3456. AC_VERB_SET_PIN_WIDGET_CONTROL, val);
  3457. }
  3458. mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
  3459. mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
  3460. mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
  3461. for (i = 0; i < spec->dac_info_filled; i++) {
  3462. nid = spec->dac_info[i].dac;
  3463. if (!nid)
  3464. nid = spec->multiout.dac_nids[0];
  3465. else if (nid & DAC_SLAVE_FLAG)
  3466. nid &= ~DAC_SLAVE_FLAG;
  3467. select_connection(codec, spec->dac_info[i].pin, nid);
  3468. }
  3469. if (spec->auto_mute) {
  3470. enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
  3471. CONEXANT_HP_EVENT);
  3472. spec->hp_present = detect_jacks(codec, cfg->hp_outs,
  3473. cfg->hp_pins);
  3474. if (spec->detect_line) {
  3475. enable_unsol_pins(codec, cfg->line_outs,
  3476. cfg->line_out_pins,
  3477. CONEXANT_LINE_EVENT);
  3478. spec->line_present =
  3479. detect_jacks(codec, cfg->line_outs,
  3480. cfg->line_out_pins);
  3481. }
  3482. }
  3483. cx_auto_update_speakers(codec);
  3484. /* turn on all EAPDs if no individual EAPD control is available */
  3485. if (!spec->pin_eapd_ctrls)
  3486. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  3487. clear_unsol_on_unused_pins(codec);
  3488. }
  3489. static void cx_auto_init_input(struct hda_codec *codec)
  3490. {
  3491. struct conexant_spec *spec = codec->spec;
  3492. struct auto_pin_cfg *cfg = &spec->autocfg;
  3493. int i, val;
  3494. for (i = 0; i < spec->num_adc_nids; i++) {
  3495. hda_nid_t nid = spec->adc_nids[i];
  3496. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
  3497. continue;
  3498. if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
  3499. val = AMP_IN_MUTE(0);
  3500. else
  3501. val = AMP_IN_UNMUTE(0);
  3502. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3503. val);
  3504. }
  3505. for (i = 0; i < cfg->num_inputs; i++) {
  3506. unsigned int type;
  3507. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  3508. type = PIN_VREF80;
  3509. else
  3510. type = PIN_IN;
  3511. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  3512. AC_VERB_SET_PIN_WIDGET_CONTROL, type);
  3513. }
  3514. if (spec->auto_mic) {
  3515. if (spec->auto_mic_ext >= 0) {
  3516. snd_hda_jack_detect_enable(codec,
  3517. cfg->inputs[spec->auto_mic_ext].pin,
  3518. CONEXANT_MIC_EVENT);
  3519. }
  3520. if (spec->auto_mic_dock >= 0) {
  3521. snd_hda_jack_detect_enable(codec,
  3522. cfg->inputs[spec->auto_mic_dock].pin,
  3523. CONEXANT_MIC_EVENT);
  3524. }
  3525. cx_auto_automic(codec);
  3526. } else {
  3527. select_input_connection(codec, spec->imux_info[0].adc,
  3528. spec->imux_info[0].pin);
  3529. }
  3530. }
  3531. static void cx_auto_init_digital(struct hda_codec *codec)
  3532. {
  3533. struct conexant_spec *spec = codec->spec;
  3534. struct auto_pin_cfg *cfg = &spec->autocfg;
  3535. if (spec->multiout.dig_out_nid)
  3536. snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
  3537. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3538. if (spec->dig_in_nid)
  3539. snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
  3540. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  3541. }
  3542. static int cx_auto_init(struct hda_codec *codec)
  3543. {
  3544. struct conexant_spec *spec = codec->spec;
  3545. /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
  3546. cx_auto_init_output(codec);
  3547. cx_auto_init_input(codec);
  3548. cx_auto_init_digital(codec);
  3549. snd_hda_jack_report_sync(codec);
  3550. snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
  3551. return 0;
  3552. }
  3553. static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
  3554. const char *dir, int cidx,
  3555. hda_nid_t nid, int hda_dir, int amp_idx, int chs)
  3556. {
  3557. static char name[44];
  3558. static struct snd_kcontrol_new knew[] = {
  3559. HDA_CODEC_VOLUME(name, 0, 0, 0),
  3560. HDA_CODEC_MUTE(name, 0, 0, 0),
  3561. };
  3562. static const char * const sfx[2] = { "Volume", "Switch" };
  3563. int i, err;
  3564. for (i = 0; i < 2; i++) {
  3565. struct snd_kcontrol *kctl;
  3566. knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
  3567. hda_dir);
  3568. knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
  3569. knew[i].index = cidx;
  3570. snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
  3571. kctl = snd_ctl_new1(&knew[i], codec);
  3572. if (!kctl)
  3573. return -ENOMEM;
  3574. err = snd_hda_ctl_add(codec, nid, kctl);
  3575. if (err < 0)
  3576. return err;
  3577. if (!(query_amp_caps(codec, nid, hda_dir) &
  3578. (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
  3579. break;
  3580. }
  3581. return 0;
  3582. }
  3583. #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
  3584. cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
  3585. #define cx_auto_add_pb_volume(codec, nid, str, idx) \
  3586. cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
  3587. static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
  3588. hda_nid_t pin, const char *name, int idx)
  3589. {
  3590. unsigned int caps;
  3591. if (dac && !(dac & DAC_SLAVE_FLAG)) {
  3592. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  3593. if (caps & AC_AMPCAP_NUM_STEPS)
  3594. return cx_auto_add_pb_volume(codec, dac, name, idx);
  3595. }
  3596. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  3597. if (caps & AC_AMPCAP_NUM_STEPS)
  3598. return cx_auto_add_pb_volume(codec, pin, name, idx);
  3599. return 0;
  3600. }
  3601. static int cx_auto_build_output_controls(struct hda_codec *codec)
  3602. {
  3603. struct conexant_spec *spec = codec->spec;
  3604. int i, err;
  3605. int num_line = 0, num_hp = 0, num_spk = 0;
  3606. static const char * const texts[3] = { "Front", "Surround", "CLFE" };
  3607. if (spec->dac_info_filled == 1)
  3608. return try_add_pb_volume(codec, spec->dac_info[0].dac,
  3609. spec->dac_info[0].pin,
  3610. "Master", 0);
  3611. for (i = 0; i < spec->dac_info_filled; i++) {
  3612. const char *label;
  3613. int idx, type;
  3614. hda_nid_t dac = spec->dac_info[i].dac;
  3615. type = spec->dac_info[i].type;
  3616. if (type == AUTO_PIN_LINE_OUT)
  3617. type = spec->autocfg.line_out_type;
  3618. switch (type) {
  3619. case AUTO_PIN_LINE_OUT:
  3620. default:
  3621. label = texts[num_line++];
  3622. idx = 0;
  3623. break;
  3624. case AUTO_PIN_HP_OUT:
  3625. label = "Headphone";
  3626. idx = num_hp++;
  3627. break;
  3628. case AUTO_PIN_SPEAKER_OUT:
  3629. label = "Speaker";
  3630. idx = num_spk++;
  3631. break;
  3632. }
  3633. err = try_add_pb_volume(codec, dac,
  3634. spec->dac_info[i].pin,
  3635. label, idx);
  3636. if (err < 0)
  3637. return err;
  3638. }
  3639. if (spec->auto_mute) {
  3640. err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
  3641. if (err < 0)
  3642. return err;
  3643. }
  3644. return 0;
  3645. }
  3646. /* Returns zero if this is a normal stereo channel, and non-zero if it should
  3647. be split in two independent channels.
  3648. dest_label must be at least 44 characters. */
  3649. static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
  3650. char *dest_label, int nid)
  3651. {
  3652. struct conexant_spec *spec = codec->spec;
  3653. int i;
  3654. if (!spec->fixup_stereo_dmic)
  3655. return 0;
  3656. for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
  3657. int def_conf;
  3658. if (spec->autocfg.inputs[i].pin != nid)
  3659. continue;
  3660. if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
  3661. return 0;
  3662. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3663. if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
  3664. return 0;
  3665. /* Finally found the inverted internal mic! */
  3666. snprintf(dest_label, 44, "Inverted %s", label);
  3667. return 1;
  3668. }
  3669. return 0;
  3670. }
  3671. static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
  3672. const char *label, const char *pfx,
  3673. int cidx)
  3674. {
  3675. struct conexant_spec *spec = codec->spec;
  3676. int i;
  3677. for (i = 0; i < spec->num_adc_nids; i++) {
  3678. char rightch_label[44];
  3679. hda_nid_t adc_nid = spec->adc_nids[i];
  3680. int idx = get_input_connection(codec, adc_nid, nid);
  3681. if (idx < 0)
  3682. continue;
  3683. if (codec->single_adc_amp)
  3684. idx = 0;
  3685. if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
  3686. /* Make two independent kcontrols for left and right */
  3687. int err = cx_auto_add_volume_idx(codec, label, pfx,
  3688. cidx, adc_nid, HDA_INPUT, idx, 1);
  3689. if (err < 0)
  3690. return err;
  3691. return cx_auto_add_volume_idx(codec, rightch_label, pfx,
  3692. cidx, adc_nid, HDA_INPUT, idx, 2);
  3693. }
  3694. return cx_auto_add_volume_idx(codec, label, pfx,
  3695. cidx, adc_nid, HDA_INPUT, idx, 3);
  3696. }
  3697. return 0;
  3698. }
  3699. static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
  3700. const char *label, int cidx)
  3701. {
  3702. struct conexant_spec *spec = codec->spec;
  3703. hda_nid_t mux, nid;
  3704. int i, con;
  3705. nid = spec->imux_info[idx].pin;
  3706. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
  3707. char rightch_label[44];
  3708. if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
  3709. int err = cx_auto_add_volume_idx(codec, label, " Boost",
  3710. cidx, nid, HDA_INPUT, 0, 1);
  3711. if (err < 0)
  3712. return err;
  3713. return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
  3714. cidx, nid, HDA_INPUT, 0, 2);
  3715. }
  3716. return cx_auto_add_volume(codec, label, " Boost", cidx,
  3717. nid, HDA_INPUT);
  3718. }
  3719. con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
  3720. &mux, false, 0);
  3721. if (con < 0)
  3722. return 0;
  3723. for (i = 0; i < idx; i++) {
  3724. if (spec->imux_info[i].boost == mux)
  3725. return 0; /* already present */
  3726. }
  3727. if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
  3728. spec->imux_info[idx].boost = mux;
  3729. return cx_auto_add_volume(codec, label, " Boost", 0,
  3730. mux, HDA_OUTPUT);
  3731. }
  3732. return 0;
  3733. }
  3734. static int cx_auto_build_input_controls(struct hda_codec *codec)
  3735. {
  3736. struct conexant_spec *spec = codec->spec;
  3737. struct hda_input_mux *imux = &spec->private_imux;
  3738. const char *prev_label;
  3739. int input_conn[HDA_MAX_NUM_INPUTS];
  3740. int i, j, err, cidx;
  3741. int multi_connection;
  3742. if (!imux->num_items)
  3743. return 0;
  3744. multi_connection = 0;
  3745. for (i = 0; i < imux->num_items; i++) {
  3746. cidx = get_input_connection(codec, spec->imux_info[i].adc,
  3747. spec->imux_info[i].pin);
  3748. if (cidx < 0)
  3749. continue;
  3750. input_conn[i] = spec->imux_info[i].adc;
  3751. if (!codec->single_adc_amp)
  3752. input_conn[i] |= cidx << 8;
  3753. if (i > 0 && input_conn[i] != input_conn[0])
  3754. multi_connection = 1;
  3755. }
  3756. prev_label = NULL;
  3757. cidx = 0;
  3758. for (i = 0; i < imux->num_items; i++) {
  3759. hda_nid_t nid = spec->imux_info[i].pin;
  3760. const char *label;
  3761. label = hda_get_autocfg_input_label(codec, &spec->autocfg,
  3762. spec->imux_info[i].index);
  3763. if (label == prev_label)
  3764. cidx++;
  3765. else
  3766. cidx = 0;
  3767. prev_label = label;
  3768. err = cx_auto_add_boost_volume(codec, i, label, cidx);
  3769. if (err < 0)
  3770. return err;
  3771. if (!multi_connection) {
  3772. if (i > 0)
  3773. continue;
  3774. err = cx_auto_add_capture_volume(codec, nid,
  3775. "Capture", "", cidx);
  3776. } else {
  3777. bool dup_found = false;
  3778. for (j = 0; j < i; j++) {
  3779. if (input_conn[j] == input_conn[i]) {
  3780. dup_found = true;
  3781. break;
  3782. }
  3783. }
  3784. if (dup_found)
  3785. continue;
  3786. err = cx_auto_add_capture_volume(codec, nid,
  3787. label, " Capture", cidx);
  3788. }
  3789. if (err < 0)
  3790. return err;
  3791. }
  3792. if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
  3793. err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
  3794. if (err < 0)
  3795. return err;
  3796. }
  3797. return 0;
  3798. }
  3799. static int cx_auto_build_controls(struct hda_codec *codec)
  3800. {
  3801. struct conexant_spec *spec = codec->spec;
  3802. int err;
  3803. err = cx_auto_build_output_controls(codec);
  3804. if (err < 0)
  3805. return err;
  3806. err = cx_auto_build_input_controls(codec);
  3807. if (err < 0)
  3808. return err;
  3809. err = conexant_build_controls(codec);
  3810. if (err < 0)
  3811. return err;
  3812. err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
  3813. if (err < 0)
  3814. return err;
  3815. if (spec->vmaster_mute.sw_kctl) {
  3816. spec->vmaster_mute.hook = cx_auto_vmaster_hook;
  3817. err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
  3818. spec->vmaster_mute_led);
  3819. if (err < 0)
  3820. return err;
  3821. }
  3822. return 0;
  3823. }
  3824. static int cx_auto_search_adcs(struct hda_codec *codec)
  3825. {
  3826. struct conexant_spec *spec = codec->spec;
  3827. hda_nid_t nid, end_nid;
  3828. end_nid = codec->start_nid + codec->num_nodes;
  3829. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3830. unsigned int caps = get_wcaps(codec, nid);
  3831. if (get_wcaps_type(caps) != AC_WID_AUD_IN)
  3832. continue;
  3833. if (caps & AC_WCAP_DIGITAL)
  3834. continue;
  3835. if (snd_BUG_ON(spec->num_adc_nids >=
  3836. ARRAY_SIZE(spec->private_adc_nids)))
  3837. break;
  3838. spec->private_adc_nids[spec->num_adc_nids++] = nid;
  3839. }
  3840. spec->adc_nids = spec->private_adc_nids;
  3841. return 0;
  3842. }
  3843. static const struct hda_codec_ops cx_auto_patch_ops = {
  3844. .build_controls = cx_auto_build_controls,
  3845. .build_pcms = conexant_build_pcms,
  3846. .init = cx_auto_init,
  3847. .free = conexant_free,
  3848. .unsol_event = cx_auto_unsol_event,
  3849. };
  3850. /*
  3851. * pin fix-up
  3852. */
  3853. struct cxt_pincfg {
  3854. hda_nid_t nid;
  3855. u32 val;
  3856. };
  3857. static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
  3858. {
  3859. for (; cfg->nid; cfg++)
  3860. snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
  3861. }
  3862. enum {
  3863. CXT_PINCFG_LENOVO_X200,
  3864. CXT_PINCFG_LENOVO_TP410,
  3865. CXT_FIXUP_STEREO_DMIC
  3866. };
  3867. static void apply_fixup(struct hda_codec *codec,
  3868. const struct snd_pci_quirk *quirk,
  3869. const struct cxt_pincfg **table)
  3870. {
  3871. struct conexant_spec *spec = codec->spec;
  3872. quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
  3873. if (!quirk)
  3874. return;
  3875. if (table[quirk->value]) {
  3876. snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
  3877. quirk->name);
  3878. apply_pincfg(codec, table[quirk->value]);
  3879. }
  3880. if (quirk->value == CXT_FIXUP_STEREO_DMIC) {
  3881. snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n",
  3882. quirk->name);
  3883. spec->fixup_stereo_dmic = 1;
  3884. }
  3885. }
  3886. /* ThinkPad X200 & co with cxt5051 */
  3887. static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
  3888. { 0x16, 0x042140ff }, /* HP (seq# overridden) */
  3889. { 0x17, 0x21a11000 }, /* dock-mic */
  3890. { 0x19, 0x2121103f }, /* dock-HP */
  3891. { 0x1c, 0x21440100 }, /* dock SPDIF out */
  3892. {}
  3893. };
  3894. /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
  3895. static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
  3896. { 0x19, 0x042110ff }, /* HP (seq# overridden) */
  3897. { 0x1a, 0x21a190f0 }, /* dock-mic */
  3898. { 0x1c, 0x212140ff }, /* dock-HP */
  3899. {}
  3900. };
  3901. static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
  3902. [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
  3903. [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
  3904. [CXT_FIXUP_STEREO_DMIC] = NULL,
  3905. };
  3906. static const struct snd_pci_quirk cxt5051_fixups[] = {
  3907. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
  3908. {}
  3909. };
  3910. static const struct snd_pci_quirk cxt5066_fixups[] = {
  3911. SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
  3912. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
  3913. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
  3914. SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
  3915. SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
  3916. SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
  3917. SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
  3918. SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
  3919. SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
  3920. {}
  3921. };
  3922. /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
  3923. * can be created (bko#42825)
  3924. */
  3925. static void add_cx5051_fake_mutes(struct hda_codec *codec)
  3926. {
  3927. static hda_nid_t out_nids[] = {
  3928. 0x10, 0x11, 0
  3929. };
  3930. hda_nid_t *p;
  3931. for (p = out_nids; *p; p++)
  3932. snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
  3933. AC_AMPCAP_MIN_MUTE |
  3934. query_amp_caps(codec, *p, HDA_OUTPUT));
  3935. }
  3936. static int patch_conexant_auto(struct hda_codec *codec)
  3937. {
  3938. struct conexant_spec *spec;
  3939. int err;
  3940. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3941. codec->chip_name);
  3942. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3943. if (!spec)
  3944. return -ENOMEM;
  3945. codec->spec = spec;
  3946. switch (codec->vendor_id) {
  3947. case 0x14f15045:
  3948. codec->single_adc_amp = 1;
  3949. break;
  3950. case 0x14f15051:
  3951. add_cx5051_fake_mutes(codec);
  3952. codec->pin_amp_workaround = 1;
  3953. apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
  3954. break;
  3955. default:
  3956. codec->pin_amp_workaround = 1;
  3957. apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
  3958. }
  3959. /* Show mute-led control only on HP laptops
  3960. * This is a sort of white-list: on HP laptops, EAPD corresponds
  3961. * only to the mute-LED without actualy amp function. Meanwhile,
  3962. * others may use EAPD really as an amp switch, so it might be
  3963. * not good to expose it blindly.
  3964. */
  3965. switch (codec->subsystem_id >> 16) {
  3966. case 0x103c:
  3967. spec->vmaster_mute_led = 1;
  3968. break;
  3969. }
  3970. err = cx_auto_search_adcs(codec);
  3971. if (err < 0)
  3972. return err;
  3973. err = cx_auto_parse_auto_config(codec);
  3974. if (err < 0) {
  3975. kfree(codec->spec);
  3976. codec->spec = NULL;
  3977. return err;
  3978. }
  3979. spec->capture_stream = &cx_auto_pcm_analog_capture;
  3980. codec->patch_ops = cx_auto_patch_ops;
  3981. if (spec->beep_amp)
  3982. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  3983. /* Some laptops with Conexant chips show stalls in S3 resume,
  3984. * which falls into the single-cmd mode.
  3985. * Better to make reset, then.
  3986. */
  3987. if (!codec->bus->sync_write) {
  3988. snd_printd("hda_codec: "
  3989. "Enable sync_write for stable communication\n");
  3990. codec->bus->sync_write = 1;
  3991. codec->bus->allow_bus_reset = 1;
  3992. }
  3993. return 0;
  3994. }
  3995. /*
  3996. */
  3997. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3998. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3999. .patch = patch_cxt5045 },
  4000. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  4001. .patch = patch_cxt5047 },
  4002. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  4003. .patch = patch_cxt5051 },
  4004. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  4005. .patch = patch_cxt5066 },
  4006. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  4007. .patch = patch_cxt5066 },
  4008. { .id = 0x14f15068, .name = "CX20584",
  4009. .patch = patch_cxt5066 },
  4010. { .id = 0x14f15069, .name = "CX20585",
  4011. .patch = patch_cxt5066 },
  4012. { .id = 0x14f1506c, .name = "CX20588",
  4013. .patch = patch_cxt5066 },
  4014. { .id = 0x14f1506e, .name = "CX20590",
  4015. .patch = patch_cxt5066 },
  4016. { .id = 0x14f15097, .name = "CX20631",
  4017. .patch = patch_conexant_auto },
  4018. { .id = 0x14f15098, .name = "CX20632",
  4019. .patch = patch_conexant_auto },
  4020. { .id = 0x14f150a1, .name = "CX20641",
  4021. .patch = patch_conexant_auto },
  4022. { .id = 0x14f150a2, .name = "CX20642",
  4023. .patch = patch_conexant_auto },
  4024. { .id = 0x14f150ab, .name = "CX20651",
  4025. .patch = patch_conexant_auto },
  4026. { .id = 0x14f150ac, .name = "CX20652",
  4027. .patch = patch_conexant_auto },
  4028. { .id = 0x14f150b8, .name = "CX20664",
  4029. .patch = patch_conexant_auto },
  4030. { .id = 0x14f150b9, .name = "CX20665",
  4031. .patch = patch_conexant_auto },
  4032. { .id = 0x14f150f1, .name = "CX20721",
  4033. .patch = patch_conexant_auto },
  4034. { .id = 0x14f150f2, .name = "CX20722",
  4035. .patch = patch_conexant_auto },
  4036. { .id = 0x14f150f3, .name = "CX20723",
  4037. .patch = patch_conexant_auto },
  4038. { .id = 0x14f150f4, .name = "CX20724",
  4039. .patch = patch_conexant_auto },
  4040. { .id = 0x14f1510f, .name = "CX20751/2",
  4041. .patch = patch_conexant_auto },
  4042. { .id = 0x14f15110, .name = "CX20751/2",
  4043. .patch = patch_conexant_auto },
  4044. { .id = 0x14f15111, .name = "CX20753/4",
  4045. .patch = patch_conexant_auto },
  4046. { .id = 0x14f15113, .name = "CX20755",
  4047. .patch = patch_conexant_auto },
  4048. { .id = 0x14f15114, .name = "CX20756",
  4049. .patch = patch_conexant_auto },
  4050. { .id = 0x14f15115, .name = "CX20757",
  4051. .patch = patch_conexant_auto },
  4052. { .id = 0x14f151d7, .name = "CX20952",
  4053. .patch = patch_conexant_auto },
  4054. {} /* terminator */
  4055. };
  4056. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  4057. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  4058. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  4059. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  4060. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  4061. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  4062. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  4063. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  4064. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  4065. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  4066. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  4067. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  4068. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  4069. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  4070. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  4071. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  4072. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  4073. MODULE_ALIAS("snd-hda-codec-id:14f150f1");
  4074. MODULE_ALIAS("snd-hda-codec-id:14f150f2");
  4075. MODULE_ALIAS("snd-hda-codec-id:14f150f3");
  4076. MODULE_ALIAS("snd-hda-codec-id:14f150f4");
  4077. MODULE_ALIAS("snd-hda-codec-id:14f1510f");
  4078. MODULE_ALIAS("snd-hda-codec-id:14f15110");
  4079. MODULE_ALIAS("snd-hda-codec-id:14f15111");
  4080. MODULE_ALIAS("snd-hda-codec-id:14f15113");
  4081. MODULE_ALIAS("snd-hda-codec-id:14f15114");
  4082. MODULE_ALIAS("snd-hda-codec-id:14f15115");
  4083. MODULE_ALIAS("snd-hda-codec-id:14f151d7");
  4084. MODULE_LICENSE("GPL");
  4085. MODULE_DESCRIPTION("Conexant HD-audio codec");
  4086. static struct hda_codec_preset_list conexant_list = {
  4087. .preset = snd_hda_preset_conexant,
  4088. .owner = THIS_MODULE,
  4089. };
  4090. static int __init patch_conexant_init(void)
  4091. {
  4092. return snd_hda_add_codec_preset(&conexant_list);
  4093. }
  4094. static void __exit patch_conexant_exit(void)
  4095. {
  4096. snd_hda_delete_codec_preset(&conexant_list);
  4097. }
  4098. module_init(patch_conexant_init)
  4099. module_exit(patch_conexant_exit)