patch_conexant.c 133 KB

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