patch_conexant.c 136 KB

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