patch_conexant.c 133 KB

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