patch_conexant.c 137 KB

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