patch_conexant.c 134 KB

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