patch_conexant.c 132 KB

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