patch_conexant.c 133 KB

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