patch_conexant.c 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_beep.h"
  31. #define CXT_PIN_DIR_IN 0x00
  32. #define CXT_PIN_DIR_OUT 0x01
  33. #define CXT_PIN_DIR_INOUT 0x02
  34. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  35. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  36. #define CONEXANT_HP_EVENT 0x37
  37. #define CONEXANT_MIC_EVENT 0x38
  38. #define CONEXANT_LINE_EVENT 0x39
  39. /* Conexant 5051 specific */
  40. #define CXT5051_SPDIF_OUT 0x12
  41. #define CXT5051_PORTB_EVENT 0x38
  42. #define CXT5051_PORTC_EVENT 0x39
  43. #define AUTO_MIC_PORTB (1 << 1)
  44. #define AUTO_MIC_PORTC (1 << 2)
  45. struct pin_dac_pair {
  46. hda_nid_t pin;
  47. hda_nid_t dac;
  48. int type;
  49. };
  50. struct imux_info {
  51. hda_nid_t pin; /* input pin NID */
  52. hda_nid_t adc; /* connected ADC NID */
  53. hda_nid_t boost; /* optional boost volume NID */
  54. int index; /* corresponding to autocfg.input */
  55. };
  56. struct conexant_spec {
  57. const struct snd_kcontrol_new *mixers[5];
  58. int num_mixers;
  59. hda_nid_t vmaster_nid;
  60. const struct hda_verb *init_verbs[5]; /* initialization verbs
  61. * don't forget NULL
  62. * termination!
  63. */
  64. unsigned int num_init_verbs;
  65. /* playback */
  66. struct hda_multi_out multiout; /* playback set-up
  67. * max_channels, dacs must be set
  68. * dig_out_nid and hp_nid are optional
  69. */
  70. unsigned int cur_eapd;
  71. unsigned int hp_present;
  72. unsigned int line_present;
  73. unsigned int auto_mic;
  74. int auto_mic_ext; /* imux_pins[] index for ext mic */
  75. int auto_mic_dock; /* imux_pins[] index for dock mic */
  76. int auto_mic_int; /* imux_pins[] index for int mic */
  77. unsigned int need_dac_fix;
  78. hda_nid_t slave_dig_outs[2];
  79. /* capture */
  80. unsigned int num_adc_nids;
  81. const hda_nid_t *adc_nids;
  82. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  83. unsigned int cur_adc_idx;
  84. hda_nid_t cur_adc;
  85. unsigned int cur_adc_stream_tag;
  86. unsigned int cur_adc_format;
  87. const struct hda_pcm_stream *capture_stream;
  88. /* capture source */
  89. const struct hda_input_mux *input_mux;
  90. const hda_nid_t *capsrc_nids;
  91. unsigned int cur_mux[3];
  92. /* channel model */
  93. const struct hda_channel_mode *channel_mode;
  94. int num_channel_mode;
  95. /* PCM information */
  96. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  97. unsigned int spdif_route;
  98. /* dynamic controls, init_verbs and input_mux */
  99. struct auto_pin_cfg autocfg;
  100. struct hda_input_mux private_imux;
  101. struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
  102. hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
  103. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  104. struct pin_dac_pair dac_info[8];
  105. int dac_info_filled;
  106. unsigned int port_d_mode;
  107. unsigned int auto_mute:1; /* used in auto-parser */
  108. unsigned int detect_line:1; /* Line-out detection enabled */
  109. unsigned int automute_lines:1; /* automute line-out as well */
  110. unsigned int automute_hp_lo:1; /* both HP and LO available */
  111. unsigned int dell_automute:1;
  112. unsigned int dell_vostro:1;
  113. unsigned int ideapad:1;
  114. unsigned int thinkpad:1;
  115. unsigned int hp_laptop:1;
  116. unsigned int asus:1;
  117. unsigned int adc_switching:1;
  118. unsigned int ext_mic_present;
  119. unsigned int recording;
  120. void (*capture_prepare)(struct hda_codec *codec);
  121. void (*capture_cleanup)(struct hda_codec *codec);
  122. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  123. * through the microphone jack.
  124. * When the user enables this through a mixer switch, both internal and
  125. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  126. * we also allow the bias to be configured through a separate mixer
  127. * control. */
  128. unsigned int dc_enable;
  129. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  130. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  131. unsigned int beep_amp;
  132. };
  133. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  134. struct hda_codec *codec,
  135. struct snd_pcm_substream *substream)
  136. {
  137. struct conexant_spec *spec = codec->spec;
  138. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  139. hinfo);
  140. }
  141. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  142. struct hda_codec *codec,
  143. unsigned int stream_tag,
  144. unsigned int format,
  145. struct snd_pcm_substream *substream)
  146. {
  147. struct conexant_spec *spec = codec->spec;
  148. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  149. stream_tag,
  150. format, substream);
  151. }
  152. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  153. struct hda_codec *codec,
  154. struct snd_pcm_substream *substream)
  155. {
  156. struct conexant_spec *spec = codec->spec;
  157. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  158. }
  159. /*
  160. * Digital out
  161. */
  162. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  163. struct hda_codec *codec,
  164. struct snd_pcm_substream *substream)
  165. {
  166. struct conexant_spec *spec = codec->spec;
  167. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  168. }
  169. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  170. struct hda_codec *codec,
  171. struct snd_pcm_substream *substream)
  172. {
  173. struct conexant_spec *spec = codec->spec;
  174. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  175. }
  176. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  177. struct hda_codec *codec,
  178. unsigned int stream_tag,
  179. unsigned int format,
  180. struct snd_pcm_substream *substream)
  181. {
  182. struct conexant_spec *spec = codec->spec;
  183. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  184. stream_tag,
  185. format, substream);
  186. }
  187. /*
  188. * Analog capture
  189. */
  190. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  191. struct hda_codec *codec,
  192. unsigned int stream_tag,
  193. unsigned int format,
  194. struct snd_pcm_substream *substream)
  195. {
  196. struct conexant_spec *spec = codec->spec;
  197. if (spec->capture_prepare)
  198. spec->capture_prepare(codec);
  199. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  200. stream_tag, 0, format);
  201. return 0;
  202. }
  203. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  204. struct hda_codec *codec,
  205. struct snd_pcm_substream *substream)
  206. {
  207. struct conexant_spec *spec = codec->spec;
  208. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  209. if (spec->capture_cleanup)
  210. spec->capture_cleanup(codec);
  211. return 0;
  212. }
  213. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  214. .substreams = 1,
  215. .channels_min = 2,
  216. .channels_max = 2,
  217. .nid = 0, /* fill later */
  218. .ops = {
  219. .open = conexant_playback_pcm_open,
  220. .prepare = conexant_playback_pcm_prepare,
  221. .cleanup = conexant_playback_pcm_cleanup
  222. },
  223. };
  224. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  225. .substreams = 1,
  226. .channels_min = 2,
  227. .channels_max = 2,
  228. .nid = 0, /* fill later */
  229. .ops = {
  230. .prepare = conexant_capture_pcm_prepare,
  231. .cleanup = conexant_capture_pcm_cleanup
  232. },
  233. };
  234. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  235. .substreams = 1,
  236. .channels_min = 2,
  237. .channels_max = 2,
  238. .nid = 0, /* fill later */
  239. .ops = {
  240. .open = conexant_dig_playback_pcm_open,
  241. .close = conexant_dig_playback_pcm_close,
  242. .prepare = conexant_dig_playback_pcm_prepare
  243. },
  244. };
  245. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  246. .substreams = 1,
  247. .channels_min = 2,
  248. .channels_max = 2,
  249. /* NID is set in alc_build_pcms */
  250. };
  251. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  252. struct hda_codec *codec,
  253. unsigned int stream_tag,
  254. unsigned int format,
  255. struct snd_pcm_substream *substream)
  256. {
  257. struct conexant_spec *spec = codec->spec;
  258. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  259. spec->cur_adc_stream_tag = stream_tag;
  260. spec->cur_adc_format = format;
  261. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  262. return 0;
  263. }
  264. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  265. struct hda_codec *codec,
  266. struct snd_pcm_substream *substream)
  267. {
  268. struct conexant_spec *spec = codec->spec;
  269. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  270. spec->cur_adc = 0;
  271. return 0;
  272. }
  273. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  274. .substreams = 1,
  275. .channels_min = 2,
  276. .channels_max = 2,
  277. .nid = 0, /* fill later */
  278. .ops = {
  279. .prepare = cx5051_capture_pcm_prepare,
  280. .cleanup = cx5051_capture_pcm_cleanup
  281. },
  282. };
  283. static int conexant_build_pcms(struct hda_codec *codec)
  284. {
  285. struct conexant_spec *spec = codec->spec;
  286. struct hda_pcm *info = spec->pcm_rec;
  287. codec->num_pcms = 1;
  288. codec->pcm_info = info;
  289. info->name = "CONEXANT Analog";
  290. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  291. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  292. spec->multiout.max_channels;
  293. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  294. spec->multiout.dac_nids[0];
  295. if (spec->capture_stream)
  296. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  297. else {
  298. if (codec->vendor_id == 0x14f15051)
  299. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  300. cx5051_pcm_analog_capture;
  301. else {
  302. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  303. conexant_pcm_analog_capture;
  304. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  305. spec->num_adc_nids;
  306. }
  307. }
  308. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  309. if (spec->multiout.dig_out_nid) {
  310. info++;
  311. codec->num_pcms++;
  312. info->name = "Conexant Digital";
  313. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  314. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  315. conexant_pcm_digital_playback;
  316. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  317. spec->multiout.dig_out_nid;
  318. if (spec->dig_in_nid) {
  319. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  320. conexant_pcm_digital_capture;
  321. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  322. spec->dig_in_nid;
  323. }
  324. if (spec->slave_dig_outs[0])
  325. codec->slave_dig_outs = spec->slave_dig_outs;
  326. }
  327. return 0;
  328. }
  329. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  330. struct snd_ctl_elem_info *uinfo)
  331. {
  332. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  333. struct conexant_spec *spec = codec->spec;
  334. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  335. }
  336. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  337. struct snd_ctl_elem_value *ucontrol)
  338. {
  339. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  340. struct conexant_spec *spec = codec->spec;
  341. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  342. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  343. return 0;
  344. }
  345. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  346. struct snd_ctl_elem_value *ucontrol)
  347. {
  348. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  349. struct conexant_spec *spec = codec->spec;
  350. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  351. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  352. spec->capsrc_nids[adc_idx],
  353. &spec->cur_mux[adc_idx]);
  354. }
  355. static int conexant_init_jacks(struct hda_codec *codec)
  356. {
  357. #ifdef CONFIG_SND_HDA_INPUT_JACK
  358. struct conexant_spec *spec = codec->spec;
  359. int i;
  360. for (i = 0; i < spec->num_init_verbs; i++) {
  361. const struct hda_verb *hv;
  362. hv = spec->init_verbs[i];
  363. while (hv->nid) {
  364. int err = 0;
  365. switch (hv->param ^ AC_USRSP_EN) {
  366. case CONEXANT_HP_EVENT:
  367. err = snd_hda_input_jack_add(codec, hv->nid,
  368. SND_JACK_HEADPHONE, NULL);
  369. snd_hda_input_jack_report(codec, hv->nid);
  370. break;
  371. case CXT5051_PORTC_EVENT:
  372. case CONEXANT_MIC_EVENT:
  373. err = snd_hda_input_jack_add(codec, hv->nid,
  374. SND_JACK_MICROPHONE, NULL);
  375. snd_hda_input_jack_report(codec, hv->nid);
  376. break;
  377. }
  378. if (err < 0)
  379. return err;
  380. ++hv;
  381. }
  382. }
  383. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  384. return 0;
  385. }
  386. static int conexant_init(struct hda_codec *codec)
  387. {
  388. struct conexant_spec *spec = codec->spec;
  389. int i;
  390. for (i = 0; i < spec->num_init_verbs; i++)
  391. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  392. return 0;
  393. }
  394. static void conexant_free(struct hda_codec *codec)
  395. {
  396. snd_hda_input_jack_free(codec);
  397. snd_hda_detach_beep_device(codec);
  398. kfree(codec->spec);
  399. }
  400. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  401. {
  402. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  403. .name = "Capture Source",
  404. .info = conexant_mux_enum_info,
  405. .get = conexant_mux_enum_get,
  406. .put = conexant_mux_enum_put
  407. },
  408. {}
  409. };
  410. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  411. /* additional beep mixers; the actual parameters are overwritten at build */
  412. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  413. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  414. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  415. { } /* end */
  416. };
  417. #endif
  418. static const char * const slave_vols[] = {
  419. "Headphone Playback Volume",
  420. "Speaker Playback Volume",
  421. "Front Playback Volume",
  422. "Surround Playback Volume",
  423. "CLFE Playback Volume",
  424. NULL
  425. };
  426. static const char * const slave_sws[] = {
  427. "Headphone Playback Switch",
  428. "Speaker Playback Switch",
  429. "Front Playback Switch",
  430. "Surround Playback Switch",
  431. "CLFE Playback Switch",
  432. NULL
  433. };
  434. static int conexant_build_controls(struct hda_codec *codec)
  435. {
  436. struct conexant_spec *spec = codec->spec;
  437. unsigned int i;
  438. int err;
  439. for (i = 0; i < spec->num_mixers; i++) {
  440. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  441. if (err < 0)
  442. return err;
  443. }
  444. if (spec->multiout.dig_out_nid) {
  445. err = snd_hda_create_spdif_out_ctls(codec,
  446. spec->multiout.dig_out_nid,
  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. snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
  1694. snd_hda_input_jack_report(codec, nid);
  1695. }
  1696. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1697. /* Subwoofer */
  1698. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1699. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1700. { } /* end */
  1701. };
  1702. /* initialize jack-sensing, too */
  1703. static int cxt5051_init(struct hda_codec *codec)
  1704. {
  1705. struct conexant_spec *spec = codec->spec;
  1706. conexant_init(codec);
  1707. conexant_init_jacks(codec);
  1708. if (spec->auto_mic & AUTO_MIC_PORTB)
  1709. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1710. if (spec->auto_mic & AUTO_MIC_PORTC)
  1711. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1712. if (codec->patch_ops.unsol_event) {
  1713. cxt5051_hp_automute(codec);
  1714. cxt5051_portb_automic(codec);
  1715. cxt5051_portc_automic(codec);
  1716. }
  1717. return 0;
  1718. }
  1719. enum {
  1720. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1721. CXT5051_HP, /* no docking */
  1722. CXT5051_HP_DV6736, /* HP without mic switch */
  1723. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1724. CXT5051_F700, /* HP Compaq Presario F700 */
  1725. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1726. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1727. CXT5051_AUTO, /* auto-parser */
  1728. CXT5051_MODELS
  1729. };
  1730. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1731. [CXT5051_LAPTOP] = "laptop",
  1732. [CXT5051_HP] = "hp",
  1733. [CXT5051_HP_DV6736] = "hp-dv6736",
  1734. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1735. [CXT5051_F700] = "hp-700",
  1736. [CXT5051_TOSHIBA] = "toshiba",
  1737. [CXT5051_IDEAPAD] = "ideapad",
  1738. [CXT5051_AUTO] = "auto",
  1739. };
  1740. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1741. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1742. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1743. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1744. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1745. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1746. CXT5051_LAPTOP),
  1747. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1748. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1749. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1750. {}
  1751. };
  1752. static int patch_cxt5051(struct hda_codec *codec)
  1753. {
  1754. struct conexant_spec *spec;
  1755. int board_config;
  1756. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1757. cxt5051_models,
  1758. cxt5051_cfg_tbl);
  1759. #if 0 /* use the old method just for safety */
  1760. if (board_config < 0)
  1761. board_config = CXT5051_AUTO;
  1762. #endif
  1763. if (board_config == CXT5051_AUTO)
  1764. return patch_conexant_auto(codec);
  1765. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1766. if (!spec)
  1767. return -ENOMEM;
  1768. codec->spec = spec;
  1769. codec->pin_amp_workaround = 1;
  1770. codec->patch_ops = conexant_patch_ops;
  1771. codec->patch_ops.init = cxt5051_init;
  1772. spec->multiout.max_channels = 2;
  1773. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1774. spec->multiout.dac_nids = cxt5051_dac_nids;
  1775. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1776. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1777. spec->adc_nids = cxt5051_adc_nids;
  1778. spec->num_mixers = 2;
  1779. spec->mixers[0] = cxt5051_capture_mixers;
  1780. spec->mixers[1] = cxt5051_playback_mixers;
  1781. spec->num_init_verbs = 1;
  1782. spec->init_verbs[0] = cxt5051_init_verbs;
  1783. spec->spdif_route = 0;
  1784. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1785. spec->channel_mode = cxt5051_modes;
  1786. spec->cur_adc = 0;
  1787. spec->cur_adc_idx = 0;
  1788. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1789. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1790. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1791. switch (board_config) {
  1792. case CXT5051_HP:
  1793. spec->mixers[0] = cxt5051_hp_mixers;
  1794. break;
  1795. case CXT5051_HP_DV6736:
  1796. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1797. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1798. spec->auto_mic = 0;
  1799. break;
  1800. case CXT5051_LENOVO_X200:
  1801. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1802. /* Thinkpad X301 does not have S/PDIF wired and no ability
  1803. to use a docking station. */
  1804. if (codec->subsystem_id == 0x17aa211f)
  1805. spec->multiout.dig_out_nid = 0;
  1806. break;
  1807. case CXT5051_F700:
  1808. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1809. spec->mixers[0] = cxt5051_f700_mixers;
  1810. spec->auto_mic = 0;
  1811. break;
  1812. case CXT5051_TOSHIBA:
  1813. spec->mixers[0] = cxt5051_toshiba_mixers;
  1814. spec->auto_mic = AUTO_MIC_PORTB;
  1815. break;
  1816. case CXT5051_IDEAPAD:
  1817. spec->init_verbs[spec->num_init_verbs++] =
  1818. cxt5051_ideapad_init_verbs;
  1819. spec->ideapad = 1;
  1820. break;
  1821. }
  1822. if (spec->beep_amp)
  1823. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1824. return 0;
  1825. }
  1826. /* Conexant 5066 specific */
  1827. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1828. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1829. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1830. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1831. /* OLPC's microphone port is DC coupled for use with external sensors,
  1832. * therefore we use a 50% mic bias in order to center the input signal with
  1833. * the DC input range of the codec. */
  1834. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1835. static const struct hda_channel_mode cxt5066_modes[1] = {
  1836. { 2, NULL },
  1837. };
  1838. #define HP_PRESENT_PORT_A (1 << 0)
  1839. #define HP_PRESENT_PORT_D (1 << 1)
  1840. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1841. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1842. static void cxt5066_update_speaker(struct hda_codec *codec)
  1843. {
  1844. struct conexant_spec *spec = codec->spec;
  1845. unsigned int pinctl;
  1846. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1847. spec->hp_present, spec->cur_eapd);
  1848. /* Port A (HP) */
  1849. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1850. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1851. pinctl);
  1852. /* Port D (HP/LO) */
  1853. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1854. if (spec->dell_automute || spec->thinkpad) {
  1855. /* Mute if Port A is connected */
  1856. if (hp_port_a_present(spec))
  1857. pinctl = 0;
  1858. } else {
  1859. /* Thinkpad/Dell doesn't give pin-D status */
  1860. if (!hp_port_d_present(spec))
  1861. pinctl = 0;
  1862. }
  1863. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1864. pinctl);
  1865. /* CLASS_D AMP */
  1866. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1867. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1868. pinctl);
  1869. }
  1870. /* turn on/off EAPD (+ mute HP) as a master switch */
  1871. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1872. struct snd_ctl_elem_value *ucontrol)
  1873. {
  1874. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1875. if (!cxt_eapd_put(kcontrol, ucontrol))
  1876. return 0;
  1877. cxt5066_update_speaker(codec);
  1878. return 1;
  1879. }
  1880. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1881. .num_items = 3,
  1882. .items = {
  1883. { "Off", PIN_IN },
  1884. { "50%", PIN_VREF50 },
  1885. { "80%", PIN_VREF80 },
  1886. },
  1887. };
  1888. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1889. {
  1890. struct conexant_spec *spec = codec->spec;
  1891. /* Even though port F is the DC input, the bias is controlled on port B.
  1892. * we also leave that port as an active input (but unselected) in DC mode
  1893. * just in case that is necessary to make the bias setting take effect. */
  1894. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1895. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1896. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1897. }
  1898. /* OLPC defers mic widget control until when capture is started because the
  1899. * microphone LED comes on as soon as these settings are put in place. if we
  1900. * did this before recording, it would give the false indication that recording
  1901. * is happening when it is not. */
  1902. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1903. {
  1904. struct conexant_spec *spec = codec->spec;
  1905. if (!spec->recording)
  1906. return;
  1907. if (spec->dc_enable) {
  1908. /* in DC mode we ignore presence detection and just use the jack
  1909. * through our special DC port */
  1910. const struct hda_verb enable_dc_mode[] = {
  1911. /* disble internal mic, port C */
  1912. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1913. /* enable DC capture, port F */
  1914. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1915. {},
  1916. };
  1917. snd_hda_sequence_write(codec, enable_dc_mode);
  1918. /* port B input disabled (and bias set) through the following call */
  1919. cxt5066_set_olpc_dc_bias(codec);
  1920. return;
  1921. }
  1922. /* disable DC (port F) */
  1923. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1924. /* external mic, port B */
  1925. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1926. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1927. /* internal mic, port C */
  1928. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1929. spec->ext_mic_present ? 0 : PIN_VREF80);
  1930. }
  1931. /* toggle input of built-in and mic jack appropriately */
  1932. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1933. {
  1934. struct conexant_spec *spec = codec->spec;
  1935. unsigned int present;
  1936. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1937. return;
  1938. present = snd_hda_codec_read(codec, 0x1a, 0,
  1939. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1940. if (present)
  1941. snd_printdd("CXT5066: external microphone detected\n");
  1942. else
  1943. snd_printdd("CXT5066: external microphone absent\n");
  1944. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1945. present ? 0 : 1);
  1946. spec->ext_mic_present = !!present;
  1947. cxt5066_olpc_select_mic(codec);
  1948. }
  1949. /* toggle input of built-in digital mic and mic jack appropriately */
  1950. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1951. {
  1952. unsigned int present;
  1953. struct hda_verb ext_mic_present[] = {
  1954. /* enable external mic, port B */
  1955. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1956. /* switch to external mic input */
  1957. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1958. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1959. /* disable internal digital mic */
  1960. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1961. {}
  1962. };
  1963. static const struct hda_verb ext_mic_absent[] = {
  1964. /* enable internal mic, port C */
  1965. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1966. /* switch to internal mic input */
  1967. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1968. /* disable external mic, port B */
  1969. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1970. {}
  1971. };
  1972. present = snd_hda_jack_detect(codec, 0x1a);
  1973. if (present) {
  1974. snd_printdd("CXT5066: external microphone detected\n");
  1975. snd_hda_sequence_write(codec, ext_mic_present);
  1976. } else {
  1977. snd_printdd("CXT5066: external microphone absent\n");
  1978. snd_hda_sequence_write(codec, ext_mic_absent);
  1979. }
  1980. }
  1981. /* toggle input of built-in digital mic and mic jack appropriately */
  1982. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1983. {
  1984. unsigned int present;
  1985. struct hda_verb ext_mic_present[] = {
  1986. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1987. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1988. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1989. {}
  1990. };
  1991. static const struct hda_verb ext_mic_absent[] = {
  1992. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1993. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1994. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1995. {}
  1996. };
  1997. present = snd_hda_jack_detect(codec, 0x1b);
  1998. if (present) {
  1999. snd_printdd("CXT5066: external microphone detected\n");
  2000. snd_hda_sequence_write(codec, ext_mic_present);
  2001. } else {
  2002. snd_printdd("CXT5066: external microphone absent\n");
  2003. snd_hda_sequence_write(codec, ext_mic_absent);
  2004. }
  2005. }
  2006. /* toggle input of built-in digital mic and mic jack appropriately */
  2007. static void cxt5066_asus_automic(struct hda_codec *codec)
  2008. {
  2009. unsigned int present;
  2010. present = snd_hda_jack_detect(codec, 0x1b);
  2011. snd_printdd("CXT5066: external microphone present=%d\n", present);
  2012. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  2013. present ? 1 : 0);
  2014. }
  2015. /* toggle input of built-in digital mic and mic jack appropriately */
  2016. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  2017. {
  2018. unsigned int present;
  2019. present = snd_hda_jack_detect(codec, 0x1b);
  2020. snd_printdd("CXT5066: external microphone present=%d\n", present);
  2021. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  2022. present ? 1 : 3);
  2023. }
  2024. /* toggle input of built-in digital mic and mic jack appropriately
  2025. order is: external mic -> dock mic -> interal mic */
  2026. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  2027. {
  2028. unsigned int ext_present, dock_present;
  2029. static const struct hda_verb ext_mic_present[] = {
  2030. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2031. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  2032. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2033. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2034. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2035. {}
  2036. };
  2037. static const struct hda_verb dock_mic_present[] = {
  2038. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2039. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  2040. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2041. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2042. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2043. {}
  2044. };
  2045. static const struct hda_verb ext_mic_absent[] = {
  2046. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  2047. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2048. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2049. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2050. {}
  2051. };
  2052. ext_present = snd_hda_jack_detect(codec, 0x1b);
  2053. dock_present = snd_hda_jack_detect(codec, 0x1a);
  2054. if (ext_present) {
  2055. snd_printdd("CXT5066: external microphone detected\n");
  2056. snd_hda_sequence_write(codec, ext_mic_present);
  2057. } else if (dock_present) {
  2058. snd_printdd("CXT5066: dock microphone detected\n");
  2059. snd_hda_sequence_write(codec, dock_mic_present);
  2060. } else {
  2061. snd_printdd("CXT5066: external microphone absent\n");
  2062. snd_hda_sequence_write(codec, ext_mic_absent);
  2063. }
  2064. }
  2065. /* mute internal speaker if HP is plugged */
  2066. static void cxt5066_hp_automute(struct hda_codec *codec)
  2067. {
  2068. struct conexant_spec *spec = codec->spec;
  2069. unsigned int portA, portD;
  2070. /* Port A */
  2071. portA = snd_hda_jack_detect(codec, 0x19);
  2072. /* Port D */
  2073. portD = snd_hda_jack_detect(codec, 0x1c);
  2074. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  2075. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  2076. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  2077. portA, portD, spec->hp_present);
  2078. cxt5066_update_speaker(codec);
  2079. }
  2080. /* Dispatch the right mic autoswitch function */
  2081. static void cxt5066_automic(struct hda_codec *codec)
  2082. {
  2083. struct conexant_spec *spec = codec->spec;
  2084. if (spec->dell_vostro)
  2085. cxt5066_vostro_automic(codec);
  2086. else if (spec->ideapad)
  2087. cxt5066_ideapad_automic(codec);
  2088. else if (spec->thinkpad)
  2089. cxt5066_thinkpad_automic(codec);
  2090. else if (spec->hp_laptop)
  2091. cxt5066_hp_laptop_automic(codec);
  2092. else if (spec->asus)
  2093. cxt5066_asus_automic(codec);
  2094. }
  2095. /* unsolicited event for jack sensing */
  2096. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  2097. {
  2098. struct conexant_spec *spec = codec->spec;
  2099. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2100. switch (res >> 26) {
  2101. case CONEXANT_HP_EVENT:
  2102. cxt5066_hp_automute(codec);
  2103. break;
  2104. case CONEXANT_MIC_EVENT:
  2105. /* ignore mic events in DC mode; we're always using the jack */
  2106. if (!spec->dc_enable)
  2107. cxt5066_olpc_automic(codec);
  2108. break;
  2109. }
  2110. }
  2111. /* unsolicited event for jack sensing */
  2112. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  2113. {
  2114. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2115. switch (res >> 26) {
  2116. case CONEXANT_HP_EVENT:
  2117. cxt5066_hp_automute(codec);
  2118. break;
  2119. case CONEXANT_MIC_EVENT:
  2120. cxt5066_automic(codec);
  2121. break;
  2122. }
  2123. }
  2124. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2125. .num_items = 5,
  2126. .items = {
  2127. { "0dB", 0 },
  2128. { "10dB", 1 },
  2129. { "20dB", 2 },
  2130. { "30dB", 3 },
  2131. { "40dB", 4 },
  2132. },
  2133. };
  2134. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2135. {
  2136. struct conexant_spec *spec = codec->spec;
  2137. snd_hda_codec_write_cache(codec, 0x17, 0,
  2138. AC_VERB_SET_AMP_GAIN_MUTE,
  2139. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2140. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2141. if (spec->ideapad || spec->thinkpad) {
  2142. /* adjust the internal mic as well...it is not through 0x17 */
  2143. snd_hda_codec_write_cache(codec, 0x23, 0,
  2144. AC_VERB_SET_AMP_GAIN_MUTE,
  2145. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2146. cxt5066_analog_mic_boost.
  2147. items[spec->mic_boost].index);
  2148. }
  2149. }
  2150. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2151. struct snd_ctl_elem_info *uinfo)
  2152. {
  2153. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2154. }
  2155. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2156. struct snd_ctl_elem_value *ucontrol)
  2157. {
  2158. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2159. struct conexant_spec *spec = codec->spec;
  2160. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2161. return 0;
  2162. }
  2163. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2164. struct snd_ctl_elem_value *ucontrol)
  2165. {
  2166. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2167. struct conexant_spec *spec = codec->spec;
  2168. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2169. unsigned int idx;
  2170. idx = ucontrol->value.enumerated.item[0];
  2171. if (idx >= imux->num_items)
  2172. idx = imux->num_items - 1;
  2173. spec->mic_boost = idx;
  2174. if (!spec->dc_enable)
  2175. cxt5066_set_mic_boost(codec);
  2176. return 1;
  2177. }
  2178. static void cxt5066_enable_dc(struct hda_codec *codec)
  2179. {
  2180. const struct hda_verb enable_dc_mode[] = {
  2181. /* disable gain */
  2182. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2183. /* switch to DC input */
  2184. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2185. {}
  2186. };
  2187. /* configure as input source */
  2188. snd_hda_sequence_write(codec, enable_dc_mode);
  2189. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2190. }
  2191. static void cxt5066_disable_dc(struct hda_codec *codec)
  2192. {
  2193. /* reconfigure input source */
  2194. cxt5066_set_mic_boost(codec);
  2195. /* automic also selects the right mic if we're recording */
  2196. cxt5066_olpc_automic(codec);
  2197. }
  2198. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2199. struct snd_ctl_elem_value *ucontrol)
  2200. {
  2201. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2202. struct conexant_spec *spec = codec->spec;
  2203. ucontrol->value.integer.value[0] = spec->dc_enable;
  2204. return 0;
  2205. }
  2206. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2207. struct snd_ctl_elem_value *ucontrol)
  2208. {
  2209. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2210. struct conexant_spec *spec = codec->spec;
  2211. int dc_enable = !!ucontrol->value.integer.value[0];
  2212. if (dc_enable == spec->dc_enable)
  2213. return 0;
  2214. spec->dc_enable = dc_enable;
  2215. if (dc_enable)
  2216. cxt5066_enable_dc(codec);
  2217. else
  2218. cxt5066_disable_dc(codec);
  2219. return 1;
  2220. }
  2221. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2222. struct snd_ctl_elem_info *uinfo)
  2223. {
  2224. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2225. }
  2226. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2227. struct snd_ctl_elem_value *ucontrol)
  2228. {
  2229. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2230. struct conexant_spec *spec = codec->spec;
  2231. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2232. return 0;
  2233. }
  2234. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2235. struct snd_ctl_elem_value *ucontrol)
  2236. {
  2237. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2238. struct conexant_spec *spec = codec->spec;
  2239. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2240. unsigned int idx;
  2241. idx = ucontrol->value.enumerated.item[0];
  2242. if (idx >= imux->num_items)
  2243. idx = imux->num_items - 1;
  2244. spec->dc_input_bias = idx;
  2245. if (spec->dc_enable)
  2246. cxt5066_set_olpc_dc_bias(codec);
  2247. return 1;
  2248. }
  2249. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2250. {
  2251. struct conexant_spec *spec = codec->spec;
  2252. /* mark as recording and configure the microphone widget so that the
  2253. * recording LED comes on. */
  2254. spec->recording = 1;
  2255. cxt5066_olpc_select_mic(codec);
  2256. }
  2257. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2258. {
  2259. struct conexant_spec *spec = codec->spec;
  2260. const struct hda_verb disable_mics[] = {
  2261. /* disable external mic, port B */
  2262. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2263. /* disble internal mic, port C */
  2264. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2265. /* disable DC capture, port F */
  2266. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2267. {},
  2268. };
  2269. snd_hda_sequence_write(codec, disable_mics);
  2270. spec->recording = 0;
  2271. }
  2272. static void conexant_check_dig_outs(struct hda_codec *codec,
  2273. const hda_nid_t *dig_pins,
  2274. int num_pins)
  2275. {
  2276. struct conexant_spec *spec = codec->spec;
  2277. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  2278. int i;
  2279. for (i = 0; i < num_pins; i++, dig_pins++) {
  2280. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  2281. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  2282. continue;
  2283. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  2284. continue;
  2285. if (spec->slave_dig_outs[0])
  2286. nid_loc++;
  2287. else
  2288. nid_loc = spec->slave_dig_outs;
  2289. }
  2290. }
  2291. static const struct hda_input_mux cxt5066_capture_source = {
  2292. .num_items = 4,
  2293. .items = {
  2294. { "Mic B", 0 },
  2295. { "Mic C", 1 },
  2296. { "Mic E", 2 },
  2297. { "Mic F", 3 },
  2298. },
  2299. };
  2300. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2301. .ops = &snd_hda_bind_vol,
  2302. .values = {
  2303. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2304. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2305. 0
  2306. },
  2307. };
  2308. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2309. .ops = &snd_hda_bind_sw,
  2310. .values = {
  2311. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2312. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2313. 0
  2314. },
  2315. };
  2316. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2317. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2318. {}
  2319. };
  2320. static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2321. {
  2322. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2323. .name = "Master Playback Volume",
  2324. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2325. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2326. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2327. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2328. .info = snd_hda_mixer_amp_volume_info,
  2329. .get = snd_hda_mixer_amp_volume_get,
  2330. .put = snd_hda_mixer_amp_volume_put,
  2331. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2332. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2333. .private_value =
  2334. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2335. },
  2336. {}
  2337. };
  2338. static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2339. {
  2340. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2341. .name = "DC Mode Enable Switch",
  2342. .info = snd_ctl_boolean_mono_info,
  2343. .get = cxt5066_olpc_dc_get,
  2344. .put = cxt5066_olpc_dc_put,
  2345. },
  2346. {
  2347. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2348. .name = "DC Input Bias Enum",
  2349. .info = cxt5066_olpc_dc_bias_enum_info,
  2350. .get = cxt5066_olpc_dc_bias_enum_get,
  2351. .put = cxt5066_olpc_dc_bias_enum_put,
  2352. },
  2353. {}
  2354. };
  2355. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  2356. {
  2357. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2358. .name = "Master Playback Switch",
  2359. .info = cxt_eapd_info,
  2360. .get = cxt_eapd_get,
  2361. .put = cxt5066_hp_master_sw_put,
  2362. .private_value = 0x1d,
  2363. },
  2364. {
  2365. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2366. .name = "Analog Mic Boost Capture Enum",
  2367. .info = cxt5066_mic_boost_mux_enum_info,
  2368. .get = cxt5066_mic_boost_mux_enum_get,
  2369. .put = cxt5066_mic_boost_mux_enum_put,
  2370. },
  2371. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2372. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2373. {}
  2374. };
  2375. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2376. {
  2377. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2378. .name = "Internal Mic Boost Capture Enum",
  2379. .info = cxt5066_mic_boost_mux_enum_info,
  2380. .get = cxt5066_mic_boost_mux_enum_get,
  2381. .put = cxt5066_mic_boost_mux_enum_put,
  2382. .private_value = 0x23 | 0x100,
  2383. },
  2384. {}
  2385. };
  2386. static const struct hda_verb cxt5066_init_verbs[] = {
  2387. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2388. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2389. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2390. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2391. /* Speakers */
  2392. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2393. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2394. /* HP, Amp */
  2395. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2396. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2397. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2398. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2399. /* DAC1 */
  2400. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2401. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2402. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2403. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2404. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2405. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2406. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2407. /* no digital microphone support yet */
  2408. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2409. /* Audio input selector */
  2410. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2411. /* SPDIF route: PCM */
  2412. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2413. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2414. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2415. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2416. /* EAPD */
  2417. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2418. /* not handling these yet */
  2419. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2420. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2421. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2422. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2423. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2424. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2425. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2426. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2427. { } /* end */
  2428. };
  2429. static const struct hda_verb cxt5066_init_verbs_olpc[] = {
  2430. /* Port A: headphones */
  2431. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2432. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2433. /* Port B: external microphone */
  2434. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2435. /* Port C: internal microphone */
  2436. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2437. /* Port D: unused */
  2438. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2439. /* Port E: unused, but has primary EAPD */
  2440. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2441. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2442. /* Port F: external DC input through microphone port */
  2443. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2444. /* Port G: internal speakers */
  2445. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2446. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2447. /* DAC1 */
  2448. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2449. /* DAC2: unused */
  2450. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2451. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2452. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2453. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2454. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2455. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2456. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2457. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2458. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2459. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2460. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2461. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2462. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2463. /* Disable digital microphone port */
  2464. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2465. /* Audio input selectors */
  2466. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2467. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2468. /* Disable SPDIF */
  2469. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2470. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2471. /* enable unsolicited events for Port A and B */
  2472. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2473. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2474. { } /* end */
  2475. };
  2476. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2477. /* Port A: headphones */
  2478. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2479. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2480. /* Port B: external microphone */
  2481. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2482. /* Port C: unused */
  2483. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2484. /* Port D: unused */
  2485. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2486. /* Port E: unused, but has primary EAPD */
  2487. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2488. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2489. /* Port F: unused */
  2490. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2491. /* Port G: internal speakers */
  2492. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2493. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2494. /* DAC1 */
  2495. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2496. /* DAC2: unused */
  2497. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2498. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2499. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2500. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2501. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2502. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2503. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2504. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2505. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2506. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2507. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2508. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2509. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2510. /* Digital microphone port */
  2511. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2512. /* Audio input selectors */
  2513. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2514. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2515. /* Disable SPDIF */
  2516. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2517. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2518. /* enable unsolicited events for Port A and B */
  2519. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2520. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2521. { } /* end */
  2522. };
  2523. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2524. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2525. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2526. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2527. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2528. /* Speakers */
  2529. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2530. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2531. /* HP, Amp */
  2532. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2533. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2534. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2535. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2536. /* DAC1 */
  2537. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2538. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2539. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2540. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2541. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2542. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2543. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2544. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2545. /* Audio input selector */
  2546. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2547. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2548. /* SPDIF route: PCM */
  2549. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2550. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2551. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2552. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2553. /* internal microphone */
  2554. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2555. /* EAPD */
  2556. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2557. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2558. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2559. { } /* end */
  2560. };
  2561. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2562. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2563. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2564. /* Port G: internal speakers */
  2565. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2566. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2567. /* Port A: HP, Amp */
  2568. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2569. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2570. /* Port B: Mic Dock */
  2571. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2572. /* Port C: Mic */
  2573. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2574. /* Port D: HP Dock, Amp */
  2575. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2576. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2577. /* DAC1 */
  2578. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2579. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2580. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2581. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2582. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2583. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2584. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2585. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2586. /* Audio input selector */
  2587. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2588. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2589. /* SPDIF route: PCM */
  2590. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2591. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2592. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2593. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2594. /* internal microphone */
  2595. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2596. /* EAPD */
  2597. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2598. /* enable unsolicited events for Port A, B, C and D */
  2599. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2600. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2601. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2602. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2603. { } /* end */
  2604. };
  2605. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2606. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2607. { } /* end */
  2608. };
  2609. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2610. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2611. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2612. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2613. { } /* end */
  2614. };
  2615. /* initialize jack-sensing, too */
  2616. static int cxt5066_init(struct hda_codec *codec)
  2617. {
  2618. snd_printdd("CXT5066: init\n");
  2619. conexant_init(codec);
  2620. if (codec->patch_ops.unsol_event) {
  2621. cxt5066_hp_automute(codec);
  2622. cxt5066_automic(codec);
  2623. }
  2624. cxt5066_set_mic_boost(codec);
  2625. return 0;
  2626. }
  2627. static int cxt5066_olpc_init(struct hda_codec *codec)
  2628. {
  2629. struct conexant_spec *spec = codec->spec;
  2630. snd_printdd("CXT5066: init\n");
  2631. conexant_init(codec);
  2632. cxt5066_hp_automute(codec);
  2633. if (!spec->dc_enable) {
  2634. cxt5066_set_mic_boost(codec);
  2635. cxt5066_olpc_automic(codec);
  2636. } else {
  2637. cxt5066_enable_dc(codec);
  2638. }
  2639. return 0;
  2640. }
  2641. enum {
  2642. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2643. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2644. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2645. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2646. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2647. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2648. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2649. CXT5066_HP_LAPTOP, /* HP Laptop */
  2650. CXT5066_AUTO, /* BIOS auto-parser */
  2651. CXT5066_MODELS
  2652. };
  2653. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2654. [CXT5066_LAPTOP] = "laptop",
  2655. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2656. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2657. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2658. [CXT5066_IDEAPAD] = "ideapad",
  2659. [CXT5066_THINKPAD] = "thinkpad",
  2660. [CXT5066_ASUS] = "asus",
  2661. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2662. [CXT5066_AUTO] = "auto",
  2663. };
  2664. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2665. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
  2666. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2667. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2668. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2669. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2670. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2671. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2672. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2673. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2674. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2675. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2676. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2677. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2678. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2679. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2680. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2681. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2682. CXT5066_LAPTOP),
  2683. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2684. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2685. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2686. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2687. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2688. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
  2689. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
  2690. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2691. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2692. SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
  2693. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
  2694. SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
  2695. {}
  2696. };
  2697. static int patch_cxt5066(struct hda_codec *codec)
  2698. {
  2699. struct conexant_spec *spec;
  2700. int board_config;
  2701. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2702. cxt5066_models, cxt5066_cfg_tbl);
  2703. #if 0 /* use the old method just for safety */
  2704. if (board_config < 0)
  2705. board_config = CXT5066_AUTO;
  2706. #endif
  2707. if (board_config == CXT5066_AUTO)
  2708. return patch_conexant_auto(codec);
  2709. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2710. if (!spec)
  2711. return -ENOMEM;
  2712. codec->spec = spec;
  2713. codec->patch_ops = conexant_patch_ops;
  2714. codec->patch_ops.init = conexant_init;
  2715. spec->dell_automute = 0;
  2716. spec->multiout.max_channels = 2;
  2717. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2718. spec->multiout.dac_nids = cxt5066_dac_nids;
  2719. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2720. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2721. spec->num_adc_nids = 1;
  2722. spec->adc_nids = cxt5066_adc_nids;
  2723. spec->capsrc_nids = cxt5066_capsrc_nids;
  2724. spec->input_mux = &cxt5066_capture_source;
  2725. spec->port_d_mode = PIN_HP;
  2726. spec->num_init_verbs = 1;
  2727. spec->init_verbs[0] = cxt5066_init_verbs;
  2728. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2729. spec->channel_mode = cxt5066_modes;
  2730. spec->cur_adc = 0;
  2731. spec->cur_adc_idx = 0;
  2732. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2733. switch (board_config) {
  2734. default:
  2735. case CXT5066_LAPTOP:
  2736. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2737. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2738. break;
  2739. case CXT5066_DELL_LAPTOP:
  2740. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2741. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2742. spec->port_d_mode = PIN_OUT;
  2743. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2744. spec->num_init_verbs++;
  2745. spec->dell_automute = 1;
  2746. break;
  2747. case CXT5066_ASUS:
  2748. case CXT5066_HP_LAPTOP:
  2749. codec->patch_ops.init = cxt5066_init;
  2750. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2751. spec->init_verbs[spec->num_init_verbs] =
  2752. cxt5066_init_verbs_hp_laptop;
  2753. spec->num_init_verbs++;
  2754. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2755. spec->asus = board_config == CXT5066_ASUS;
  2756. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2757. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2758. /* no S/PDIF out */
  2759. if (board_config == CXT5066_HP_LAPTOP)
  2760. spec->multiout.dig_out_nid = 0;
  2761. /* input source automatically selected */
  2762. spec->input_mux = NULL;
  2763. spec->port_d_mode = 0;
  2764. spec->mic_boost = 3; /* default 30dB gain */
  2765. break;
  2766. case CXT5066_OLPC_XO_1_5:
  2767. codec->patch_ops.init = cxt5066_olpc_init;
  2768. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2769. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2770. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2771. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2772. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2773. spec->port_d_mode = 0;
  2774. spec->mic_boost = 3; /* default 30dB gain */
  2775. /* no S/PDIF out */
  2776. spec->multiout.dig_out_nid = 0;
  2777. /* input source automatically selected */
  2778. spec->input_mux = NULL;
  2779. /* our capture hooks which allow us to turn on the microphone LED
  2780. * at the right time */
  2781. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2782. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2783. break;
  2784. case CXT5066_DELL_VOSTRO:
  2785. codec->patch_ops.init = cxt5066_init;
  2786. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2787. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2788. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2789. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2790. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2791. spec->port_d_mode = 0;
  2792. spec->dell_vostro = 1;
  2793. spec->mic_boost = 3; /* default 30dB gain */
  2794. /* no S/PDIF out */
  2795. spec->multiout.dig_out_nid = 0;
  2796. /* input source automatically selected */
  2797. spec->input_mux = NULL;
  2798. break;
  2799. case CXT5066_IDEAPAD:
  2800. codec->patch_ops.init = cxt5066_init;
  2801. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2802. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2803. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2804. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2805. spec->port_d_mode = 0;
  2806. spec->ideapad = 1;
  2807. spec->mic_boost = 2; /* default 20dB gain */
  2808. /* no S/PDIF out */
  2809. spec->multiout.dig_out_nid = 0;
  2810. /* input source automatically selected */
  2811. spec->input_mux = NULL;
  2812. break;
  2813. case CXT5066_THINKPAD:
  2814. codec->patch_ops.init = cxt5066_init;
  2815. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2816. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2817. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2818. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2819. spec->thinkpad = 1;
  2820. spec->port_d_mode = PIN_OUT;
  2821. spec->mic_boost = 2; /* default 20dB gain */
  2822. /* no S/PDIF out */
  2823. spec->multiout.dig_out_nid = 0;
  2824. /* input source automatically selected */
  2825. spec->input_mux = NULL;
  2826. break;
  2827. }
  2828. if (spec->beep_amp)
  2829. snd_hda_attach_beep_device(codec, spec->beep_amp);
  2830. return 0;
  2831. }
  2832. /*
  2833. * Automatic parser for CX20641 & co
  2834. */
  2835. static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2836. struct hda_codec *codec,
  2837. unsigned int stream_tag,
  2838. unsigned int format,
  2839. struct snd_pcm_substream *substream)
  2840. {
  2841. struct conexant_spec *spec = codec->spec;
  2842. hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
  2843. if (spec->adc_switching) {
  2844. spec->cur_adc = adc;
  2845. spec->cur_adc_stream_tag = stream_tag;
  2846. spec->cur_adc_format = format;
  2847. }
  2848. snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
  2849. return 0;
  2850. }
  2851. static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2852. struct hda_codec *codec,
  2853. struct snd_pcm_substream *substream)
  2854. {
  2855. struct conexant_spec *spec = codec->spec;
  2856. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  2857. spec->cur_adc = 0;
  2858. return 0;
  2859. }
  2860. static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
  2861. .substreams = 1,
  2862. .channels_min = 2,
  2863. .channels_max = 2,
  2864. .nid = 0, /* fill later */
  2865. .ops = {
  2866. .prepare = cx_auto_capture_pcm_prepare,
  2867. .cleanup = cx_auto_capture_pcm_cleanup
  2868. },
  2869. };
  2870. static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
  2871. #define get_connection_index(codec, mux, nid)\
  2872. snd_hda_get_conn_index(codec, mux, nid, 0)
  2873. /* get an unassigned DAC from the given list.
  2874. * Return the nid if found and reduce the DAC list, or return zero if
  2875. * not found
  2876. */
  2877. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
  2878. hda_nid_t *dacs, int *num_dacs)
  2879. {
  2880. int i, nums = *num_dacs;
  2881. hda_nid_t ret = 0;
  2882. for (i = 0; i < nums; i++) {
  2883. if (get_connection_index(codec, pin, dacs[i]) >= 0) {
  2884. ret = dacs[i];
  2885. break;
  2886. }
  2887. }
  2888. if (!ret)
  2889. return 0;
  2890. if (--nums > 0)
  2891. memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
  2892. *num_dacs = nums;
  2893. return ret;
  2894. }
  2895. #define MAX_AUTO_DACS 5
  2896. /* fill analog DAC list from the widget tree */
  2897. static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  2898. {
  2899. hda_nid_t nid, end_nid;
  2900. int nums = 0;
  2901. end_nid = codec->start_nid + codec->num_nodes;
  2902. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2903. unsigned int wcaps = get_wcaps(codec, nid);
  2904. unsigned int type = get_wcaps_type(wcaps);
  2905. if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
  2906. dacs[nums++] = nid;
  2907. if (nums >= MAX_AUTO_DACS)
  2908. break;
  2909. }
  2910. }
  2911. return nums;
  2912. }
  2913. /* fill pin_dac_pair list from the pin and dac list */
  2914. static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  2915. int num_pins, hda_nid_t *dacs, int *rest,
  2916. struct pin_dac_pair *filled, int type)
  2917. {
  2918. int i, nums;
  2919. nums = 0;
  2920. for (i = 0; i < num_pins; i++) {
  2921. filled[nums].pin = pins[i];
  2922. filled[nums].type = type;
  2923. filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
  2924. nums++;
  2925. }
  2926. return nums;
  2927. }
  2928. /* parse analog output paths */
  2929. static void cx_auto_parse_output(struct hda_codec *codec)
  2930. {
  2931. struct conexant_spec *spec = codec->spec;
  2932. struct auto_pin_cfg *cfg = &spec->autocfg;
  2933. hda_nid_t dacs[MAX_AUTO_DACS];
  2934. int i, j, nums, rest;
  2935. rest = fill_cx_auto_dacs(codec, dacs);
  2936. /* parse all analog output pins */
  2937. nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
  2938. dacs, &rest, spec->dac_info,
  2939. AUTO_PIN_LINE_OUT);
  2940. nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
  2941. dacs, &rest, spec->dac_info + nums,
  2942. AUTO_PIN_HP_OUT);
  2943. nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
  2944. dacs, &rest, spec->dac_info + nums,
  2945. AUTO_PIN_SPEAKER_OUT);
  2946. spec->dac_info_filled = nums;
  2947. /* fill multiout struct */
  2948. for (i = 0; i < nums; i++) {
  2949. hda_nid_t dac = spec->dac_info[i].dac;
  2950. if (!dac)
  2951. continue;
  2952. switch (spec->dac_info[i].type) {
  2953. case AUTO_PIN_LINE_OUT:
  2954. spec->private_dac_nids[spec->multiout.num_dacs] = dac;
  2955. spec->multiout.num_dacs++;
  2956. break;
  2957. case AUTO_PIN_HP_OUT:
  2958. case AUTO_PIN_SPEAKER_OUT:
  2959. if (!spec->multiout.hp_nid) {
  2960. spec->multiout.hp_nid = dac;
  2961. break;
  2962. }
  2963. for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
  2964. if (!spec->multiout.extra_out_nid[j]) {
  2965. spec->multiout.extra_out_nid[j] = dac;
  2966. break;
  2967. }
  2968. break;
  2969. }
  2970. }
  2971. spec->multiout.dac_nids = spec->private_dac_nids;
  2972. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2973. for (i = 0; i < cfg->hp_outs; i++) {
  2974. if (is_jack_detectable(codec, cfg->hp_pins[i])) {
  2975. spec->auto_mute = 1;
  2976. break;
  2977. }
  2978. }
  2979. if (spec->auto_mute &&
  2980. cfg->line_out_pins[0] &&
  2981. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
  2982. cfg->line_out_pins[0] != cfg->hp_pins[0] &&
  2983. cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
  2984. for (i = 0; i < cfg->line_outs; i++) {
  2985. if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
  2986. spec->detect_line = 1;
  2987. break;
  2988. }
  2989. }
  2990. spec->automute_lines = spec->detect_line;
  2991. }
  2992. spec->vmaster_nid = spec->private_dac_nids[0];
  2993. }
  2994. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2995. hda_nid_t *pins, bool on);
  2996. static void do_automute(struct hda_codec *codec, int num_pins,
  2997. hda_nid_t *pins, bool on)
  2998. {
  2999. int i;
  3000. for (i = 0; i < num_pins; i++)
  3001. snd_hda_codec_write(codec, pins[i], 0,
  3002. AC_VERB_SET_PIN_WIDGET_CONTROL,
  3003. on ? PIN_OUT : 0);
  3004. cx_auto_turn_eapd(codec, num_pins, pins, on);
  3005. }
  3006. static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  3007. {
  3008. int i, present = 0;
  3009. for (i = 0; i < num_pins; i++) {
  3010. hda_nid_t nid = pins[i];
  3011. if (!nid || !is_jack_detectable(codec, nid))
  3012. break;
  3013. snd_hda_input_jack_report(codec, nid);
  3014. present |= snd_hda_jack_detect(codec, nid);
  3015. }
  3016. return present;
  3017. }
  3018. /* auto-mute/unmute speaker and line outs according to headphone jack */
  3019. static void cx_auto_update_speakers(struct hda_codec *codec)
  3020. {
  3021. struct conexant_spec *spec = codec->spec;
  3022. struct auto_pin_cfg *cfg = &spec->autocfg;
  3023. int on = 1;
  3024. /* turn on HP EAPD when HP jacks are present */
  3025. if (spec->auto_mute)
  3026. on = spec->hp_present;
  3027. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
  3028. /* mute speakers in auto-mode if HP or LO jacks are plugged */
  3029. if (spec->auto_mute)
  3030. on = !(spec->hp_present ||
  3031. (spec->detect_line && spec->line_present));
  3032. do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
  3033. /* toggle line-out mutes if needed, too */
  3034. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  3035. if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
  3036. cfg->line_out_pins[0] == cfg->speaker_pins[0])
  3037. return;
  3038. if (spec->auto_mute) {
  3039. /* mute LO in auto-mode when HP jack is present */
  3040. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
  3041. spec->automute_lines)
  3042. on = !spec->hp_present;
  3043. else
  3044. on = 1;
  3045. }
  3046. do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
  3047. }
  3048. static void cx_auto_hp_automute(struct hda_codec *codec)
  3049. {
  3050. struct conexant_spec *spec = codec->spec;
  3051. struct auto_pin_cfg *cfg = &spec->autocfg;
  3052. if (!spec->auto_mute)
  3053. return;
  3054. spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
  3055. cx_auto_update_speakers(codec);
  3056. }
  3057. static void cx_auto_line_automute(struct hda_codec *codec)
  3058. {
  3059. struct conexant_spec *spec = codec->spec;
  3060. struct auto_pin_cfg *cfg = &spec->autocfg;
  3061. if (!spec->auto_mute || !spec->detect_line)
  3062. return;
  3063. spec->line_present = detect_jacks(codec, cfg->line_outs,
  3064. cfg->line_out_pins);
  3065. cx_auto_update_speakers(codec);
  3066. }
  3067. static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
  3068. struct snd_ctl_elem_info *uinfo)
  3069. {
  3070. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3071. struct conexant_spec *spec = codec->spec;
  3072. static const char * const texts2[] = {
  3073. "Disabled", "Enabled"
  3074. };
  3075. static const char * const texts3[] = {
  3076. "Disabled", "Speaker Only", "Line-Out+Speaker"
  3077. };
  3078. const char * const *texts;
  3079. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3080. uinfo->count = 1;
  3081. if (spec->automute_hp_lo) {
  3082. uinfo->value.enumerated.items = 3;
  3083. texts = texts3;
  3084. } else {
  3085. uinfo->value.enumerated.items = 2;
  3086. texts = texts2;
  3087. }
  3088. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  3089. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  3090. strcpy(uinfo->value.enumerated.name,
  3091. texts[uinfo->value.enumerated.item]);
  3092. return 0;
  3093. }
  3094. static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
  3095. struct snd_ctl_elem_value *ucontrol)
  3096. {
  3097. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3098. struct conexant_spec *spec = codec->spec;
  3099. unsigned int val;
  3100. if (!spec->auto_mute)
  3101. val = 0;
  3102. else if (!spec->automute_lines)
  3103. val = 1;
  3104. else
  3105. val = 2;
  3106. ucontrol->value.enumerated.item[0] = val;
  3107. return 0;
  3108. }
  3109. static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
  3110. struct snd_ctl_elem_value *ucontrol)
  3111. {
  3112. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3113. struct conexant_spec *spec = codec->spec;
  3114. switch (ucontrol->value.enumerated.item[0]) {
  3115. case 0:
  3116. if (!spec->auto_mute)
  3117. return 0;
  3118. spec->auto_mute = 0;
  3119. break;
  3120. case 1:
  3121. if (spec->auto_mute && !spec->automute_lines)
  3122. return 0;
  3123. spec->auto_mute = 1;
  3124. spec->automute_lines = 0;
  3125. break;
  3126. case 2:
  3127. if (!spec->automute_hp_lo)
  3128. return -EINVAL;
  3129. if (spec->auto_mute && spec->automute_lines)
  3130. return 0;
  3131. spec->auto_mute = 1;
  3132. spec->automute_lines = 1;
  3133. break;
  3134. default:
  3135. return -EINVAL;
  3136. }
  3137. cx_auto_update_speakers(codec);
  3138. return 1;
  3139. }
  3140. static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
  3141. {
  3142. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3143. .name = "Auto-Mute Mode",
  3144. .info = cx_automute_mode_info,
  3145. .get = cx_automute_mode_get,
  3146. .put = cx_automute_mode_put,
  3147. },
  3148. { }
  3149. };
  3150. static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
  3151. struct snd_ctl_elem_info *uinfo)
  3152. {
  3153. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3154. struct conexant_spec *spec = codec->spec;
  3155. return snd_hda_input_mux_info(&spec->private_imux, uinfo);
  3156. }
  3157. static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
  3158. struct snd_ctl_elem_value *ucontrol)
  3159. {
  3160. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3161. struct conexant_spec *spec = codec->spec;
  3162. ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
  3163. return 0;
  3164. }
  3165. /* look for the route the given pin from mux and return the index;
  3166. * if do_select is set, actually select the route.
  3167. */
  3168. static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3169. hda_nid_t pin, hda_nid_t *srcp,
  3170. bool do_select, int depth)
  3171. {
  3172. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3173. int i, nums;
  3174. switch (get_wcaps_type(get_wcaps(codec, mux))) {
  3175. case AC_WID_AUD_IN:
  3176. case AC_WID_AUD_SEL:
  3177. case AC_WID_AUD_MIX:
  3178. break;
  3179. default:
  3180. return -1;
  3181. }
  3182. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3183. for (i = 0; i < nums; i++)
  3184. if (conn[i] == pin) {
  3185. if (do_select)
  3186. snd_hda_codec_write(codec, mux, 0,
  3187. AC_VERB_SET_CONNECT_SEL, i);
  3188. if (srcp)
  3189. *srcp = mux;
  3190. return i;
  3191. }
  3192. depth++;
  3193. if (depth == 2)
  3194. return -1;
  3195. for (i = 0; i < nums; i++) {
  3196. int ret = __select_input_connection(codec, conn[i], pin, srcp,
  3197. do_select, depth);
  3198. if (ret >= 0) {
  3199. if (do_select)
  3200. snd_hda_codec_write(codec, mux, 0,
  3201. AC_VERB_SET_CONNECT_SEL, i);
  3202. return i;
  3203. }
  3204. }
  3205. return -1;
  3206. }
  3207. static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3208. hda_nid_t pin)
  3209. {
  3210. __select_input_connection(codec, mux, pin, NULL, true, 0);
  3211. }
  3212. static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3213. hda_nid_t pin)
  3214. {
  3215. return __select_input_connection(codec, mux, pin, NULL, false, 0);
  3216. }
  3217. static int cx_auto_mux_enum_update(struct hda_codec *codec,
  3218. const struct hda_input_mux *imux,
  3219. unsigned int idx)
  3220. {
  3221. struct conexant_spec *spec = codec->spec;
  3222. hda_nid_t adc;
  3223. int changed = 1;
  3224. if (!imux->num_items)
  3225. return 0;
  3226. if (idx >= imux->num_items)
  3227. idx = imux->num_items - 1;
  3228. if (spec->cur_mux[0] == idx)
  3229. changed = 0;
  3230. adc = spec->imux_info[idx].adc;
  3231. select_input_connection(codec, spec->imux_info[idx].adc,
  3232. spec->imux_info[idx].pin);
  3233. if (spec->cur_adc && spec->cur_adc != adc) {
  3234. /* stream is running, let's swap the current ADC */
  3235. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  3236. spec->cur_adc = adc;
  3237. snd_hda_codec_setup_stream(codec, adc,
  3238. spec->cur_adc_stream_tag, 0,
  3239. spec->cur_adc_format);
  3240. }
  3241. spec->cur_mux[0] = idx;
  3242. return changed;
  3243. }
  3244. static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
  3245. struct snd_ctl_elem_value *ucontrol)
  3246. {
  3247. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3248. struct conexant_spec *spec = codec->spec;
  3249. return cx_auto_mux_enum_update(codec, &spec->private_imux,
  3250. ucontrol->value.enumerated.item[0]);
  3251. }
  3252. static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
  3253. {
  3254. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3255. .name = "Capture Source",
  3256. .info = cx_auto_mux_enum_info,
  3257. .get = cx_auto_mux_enum_get,
  3258. .put = cx_auto_mux_enum_put
  3259. },
  3260. {}
  3261. };
  3262. static bool select_automic(struct hda_codec *codec, int idx, bool detect)
  3263. {
  3264. struct conexant_spec *spec = codec->spec;
  3265. if (idx < 0)
  3266. return false;
  3267. if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
  3268. return false;
  3269. cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
  3270. return true;
  3271. }
  3272. /* automatic switch internal and external mic */
  3273. static void cx_auto_automic(struct hda_codec *codec)
  3274. {
  3275. struct conexant_spec *spec = codec->spec;
  3276. if (!spec->auto_mic)
  3277. return;
  3278. if (!select_automic(codec, spec->auto_mic_ext, true))
  3279. if (!select_automic(codec, spec->auto_mic_dock, true))
  3280. select_automic(codec, spec->auto_mic_int, false);
  3281. }
  3282. static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
  3283. {
  3284. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  3285. switch (res >> 26) {
  3286. case CONEXANT_HP_EVENT:
  3287. cx_auto_hp_automute(codec);
  3288. break;
  3289. case CONEXANT_LINE_EVENT:
  3290. cx_auto_line_automute(codec);
  3291. break;
  3292. case CONEXANT_MIC_EVENT:
  3293. cx_auto_automic(codec);
  3294. snd_hda_input_jack_report(codec, nid);
  3295. break;
  3296. }
  3297. }
  3298. /* check whether the pin config is suitable for auto-mic switching;
  3299. * auto-mic is enabled only when one int-mic and one ext- and/or
  3300. * one dock-mic exist
  3301. */
  3302. static void cx_auto_check_auto_mic(struct hda_codec *codec)
  3303. {
  3304. struct conexant_spec *spec = codec->spec;
  3305. int pset[INPUT_PIN_ATTR_NORMAL + 1];
  3306. int i;
  3307. for (i = 0; i < ARRAY_SIZE(pset); i++)
  3308. pset[i] = -1;
  3309. for (i = 0; i < spec->private_imux.num_items; i++) {
  3310. hda_nid_t pin = spec->imux_info[i].pin;
  3311. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3312. int type, attr;
  3313. attr = snd_hda_get_input_pin_attr(def_conf);
  3314. if (attr == INPUT_PIN_ATTR_UNUSED)
  3315. return; /* invalid entry */
  3316. if (attr > INPUT_PIN_ATTR_NORMAL)
  3317. attr = INPUT_PIN_ATTR_NORMAL;
  3318. if (attr != INPUT_PIN_ATTR_INT &&
  3319. !is_jack_detectable(codec, pin))
  3320. return; /* non-detectable pin */
  3321. type = get_defcfg_device(def_conf);
  3322. if (type != AC_JACK_MIC_IN &&
  3323. (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
  3324. return; /* no valid input type */
  3325. if (pset[attr] >= 0)
  3326. return; /* already occupied */
  3327. pset[attr] = i;
  3328. }
  3329. if (pset[INPUT_PIN_ATTR_INT] < 0 ||
  3330. (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
  3331. return; /* no input to switch*/
  3332. spec->auto_mic = 1;
  3333. spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
  3334. spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
  3335. spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
  3336. }
  3337. static void cx_auto_parse_input(struct hda_codec *codec)
  3338. {
  3339. struct conexant_spec *spec = codec->spec;
  3340. struct auto_pin_cfg *cfg = &spec->autocfg;
  3341. struct hda_input_mux *imux;
  3342. int i, j;
  3343. imux = &spec->private_imux;
  3344. for (i = 0; i < cfg->num_inputs; i++) {
  3345. for (j = 0; j < spec->num_adc_nids; j++) {
  3346. hda_nid_t adc = spec->adc_nids[j];
  3347. int idx = get_input_connection(codec, adc,
  3348. cfg->inputs[i].pin);
  3349. if (idx >= 0) {
  3350. const char *label;
  3351. label = hda_get_autocfg_input_label(codec, cfg, i);
  3352. spec->imux_info[imux->num_items].index = i;
  3353. spec->imux_info[imux->num_items].boost = 0;
  3354. spec->imux_info[imux->num_items].adc = adc;
  3355. spec->imux_info[imux->num_items].pin =
  3356. cfg->inputs[i].pin;
  3357. snd_hda_add_imux_item(imux, label, idx, NULL);
  3358. break;
  3359. }
  3360. }
  3361. }
  3362. if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
  3363. cx_auto_check_auto_mic(codec);
  3364. if (imux->num_items > 1 && !spec->auto_mic) {
  3365. for (i = 1; i < imux->num_items; i++) {
  3366. if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
  3367. spec->adc_switching = 1;
  3368. break;
  3369. }
  3370. }
  3371. }
  3372. }
  3373. /* get digital-input audio widget corresponding to the given pin */
  3374. static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
  3375. {
  3376. hda_nid_t nid, end_nid;
  3377. end_nid = codec->start_nid + codec->num_nodes;
  3378. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3379. unsigned int wcaps = get_wcaps(codec, nid);
  3380. unsigned int type = get_wcaps_type(wcaps);
  3381. if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
  3382. if (get_connection_index(codec, nid, pin) >= 0)
  3383. return nid;
  3384. }
  3385. }
  3386. return 0;
  3387. }
  3388. static void cx_auto_parse_digital(struct hda_codec *codec)
  3389. {
  3390. struct conexant_spec *spec = codec->spec;
  3391. struct auto_pin_cfg *cfg = &spec->autocfg;
  3392. hda_nid_t nid;
  3393. if (cfg->dig_outs &&
  3394. snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
  3395. spec->multiout.dig_out_nid = nid;
  3396. if (cfg->dig_in_pin)
  3397. spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
  3398. }
  3399. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3400. static void cx_auto_parse_beep(struct hda_codec *codec)
  3401. {
  3402. struct conexant_spec *spec = codec->spec;
  3403. hda_nid_t nid, end_nid;
  3404. end_nid = codec->start_nid + codec->num_nodes;
  3405. for (nid = codec->start_nid; nid < end_nid; nid++)
  3406. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  3407. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  3408. break;
  3409. }
  3410. }
  3411. #else
  3412. #define cx_auto_parse_beep(codec)
  3413. #endif
  3414. static int cx_auto_parse_auto_config(struct hda_codec *codec)
  3415. {
  3416. struct conexant_spec *spec = codec->spec;
  3417. int err;
  3418. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3419. if (err < 0)
  3420. return err;
  3421. cx_auto_parse_output(codec);
  3422. cx_auto_parse_input(codec);
  3423. cx_auto_parse_digital(codec);
  3424. cx_auto_parse_beep(codec);
  3425. return 0;
  3426. }
  3427. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3428. hda_nid_t *pins, bool on)
  3429. {
  3430. int i;
  3431. for (i = 0; i < num_pins; i++) {
  3432. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  3433. snd_hda_codec_write(codec, pins[i], 0,
  3434. AC_VERB_SET_EAPD_BTLENABLE,
  3435. on ? 0x02 : 0);
  3436. }
  3437. }
  3438. static void select_connection(struct hda_codec *codec, hda_nid_t pin,
  3439. hda_nid_t src)
  3440. {
  3441. int idx = get_connection_index(codec, pin, src);
  3442. if (idx >= 0)
  3443. snd_hda_codec_write(codec, pin, 0,
  3444. AC_VERB_SET_CONNECT_SEL, idx);
  3445. }
  3446. static void mute_outputs(struct hda_codec *codec, int num_nids,
  3447. const hda_nid_t *nids)
  3448. {
  3449. int i, val;
  3450. for (i = 0; i < num_nids; i++) {
  3451. hda_nid_t nid = nids[i];
  3452. if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
  3453. continue;
  3454. if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
  3455. val = AMP_OUT_MUTE;
  3456. else
  3457. val = AMP_OUT_ZERO;
  3458. snd_hda_codec_write(codec, nid, 0,
  3459. AC_VERB_SET_AMP_GAIN_MUTE, val);
  3460. }
  3461. }
  3462. static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
  3463. hda_nid_t *pins, unsigned int tag)
  3464. {
  3465. int i;
  3466. for (i = 0; i < num_pins; i++)
  3467. snd_hda_codec_write(codec, pins[i], 0,
  3468. AC_VERB_SET_UNSOLICITED_ENABLE,
  3469. AC_USRSP_EN | tag);
  3470. }
  3471. static void cx_auto_init_output(struct hda_codec *codec)
  3472. {
  3473. struct conexant_spec *spec = codec->spec;
  3474. struct auto_pin_cfg *cfg = &spec->autocfg;
  3475. hda_nid_t nid;
  3476. int i;
  3477. mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
  3478. for (i = 0; i < cfg->hp_outs; i++)
  3479. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3480. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
  3481. mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
  3482. mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
  3483. mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
  3484. for (i = 0; i < spec->dac_info_filled; i++) {
  3485. nid = spec->dac_info[i].dac;
  3486. if (!nid)
  3487. nid = spec->multiout.dac_nids[0];
  3488. select_connection(codec, spec->dac_info[i].pin, nid);
  3489. }
  3490. if (spec->auto_mute) {
  3491. enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
  3492. CONEXANT_HP_EVENT);
  3493. spec->hp_present = detect_jacks(codec, cfg->hp_outs,
  3494. cfg->hp_pins);
  3495. if (spec->detect_line) {
  3496. enable_unsol_pins(codec, cfg->line_outs,
  3497. cfg->line_out_pins,
  3498. CONEXANT_LINE_EVENT);
  3499. spec->line_present =
  3500. detect_jacks(codec, cfg->line_outs,
  3501. cfg->line_out_pins);
  3502. }
  3503. }
  3504. cx_auto_update_speakers(codec);
  3505. }
  3506. static void cx_auto_init_input(struct hda_codec *codec)
  3507. {
  3508. struct conexant_spec *spec = codec->spec;
  3509. struct auto_pin_cfg *cfg = &spec->autocfg;
  3510. int i, val;
  3511. for (i = 0; i < spec->num_adc_nids; i++) {
  3512. hda_nid_t nid = spec->adc_nids[i];
  3513. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
  3514. continue;
  3515. if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
  3516. val = AMP_IN_MUTE(0);
  3517. else
  3518. val = AMP_IN_UNMUTE(0);
  3519. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3520. val);
  3521. }
  3522. for (i = 0; i < cfg->num_inputs; i++) {
  3523. unsigned int type;
  3524. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  3525. type = PIN_VREF80;
  3526. else
  3527. type = PIN_IN;
  3528. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  3529. AC_VERB_SET_PIN_WIDGET_CONTROL, type);
  3530. }
  3531. if (spec->auto_mic) {
  3532. if (spec->auto_mic_ext >= 0) {
  3533. snd_hda_codec_write(codec,
  3534. cfg->inputs[spec->auto_mic_ext].pin, 0,
  3535. AC_VERB_SET_UNSOLICITED_ENABLE,
  3536. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3537. }
  3538. if (spec->auto_mic_dock >= 0) {
  3539. snd_hda_codec_write(codec,
  3540. cfg->inputs[spec->auto_mic_dock].pin, 0,
  3541. AC_VERB_SET_UNSOLICITED_ENABLE,
  3542. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3543. }
  3544. cx_auto_automic(codec);
  3545. } else {
  3546. select_input_connection(codec, spec->imux_info[0].adc,
  3547. spec->imux_info[0].pin);
  3548. }
  3549. }
  3550. static void cx_auto_init_digital(struct hda_codec *codec)
  3551. {
  3552. struct conexant_spec *spec = codec->spec;
  3553. struct auto_pin_cfg *cfg = &spec->autocfg;
  3554. if (spec->multiout.dig_out_nid)
  3555. snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
  3556. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3557. if (spec->dig_in_nid)
  3558. snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
  3559. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  3560. }
  3561. static int cx_auto_init(struct hda_codec *codec)
  3562. {
  3563. /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
  3564. cx_auto_init_output(codec);
  3565. cx_auto_init_input(codec);
  3566. cx_auto_init_digital(codec);
  3567. return 0;
  3568. }
  3569. static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
  3570. const char *dir, int cidx,
  3571. hda_nid_t nid, int hda_dir, int amp_idx)
  3572. {
  3573. static char name[32];
  3574. static struct snd_kcontrol_new knew[] = {
  3575. HDA_CODEC_VOLUME(name, 0, 0, 0),
  3576. HDA_CODEC_MUTE(name, 0, 0, 0),
  3577. };
  3578. static const char * const sfx[2] = { "Volume", "Switch" };
  3579. int i, err;
  3580. for (i = 0; i < 2; i++) {
  3581. struct snd_kcontrol *kctl;
  3582. knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
  3583. hda_dir);
  3584. knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
  3585. knew[i].index = cidx;
  3586. snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
  3587. kctl = snd_ctl_new1(&knew[i], codec);
  3588. if (!kctl)
  3589. return -ENOMEM;
  3590. err = snd_hda_ctl_add(codec, nid, kctl);
  3591. if (err < 0)
  3592. return err;
  3593. if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
  3594. break;
  3595. }
  3596. return 0;
  3597. }
  3598. #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
  3599. cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
  3600. #define cx_auto_add_pb_volume(codec, nid, str, idx) \
  3601. cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
  3602. static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
  3603. hda_nid_t pin, const char *name, int idx)
  3604. {
  3605. unsigned int caps;
  3606. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  3607. if (caps & AC_AMPCAP_NUM_STEPS)
  3608. return cx_auto_add_pb_volume(codec, dac, name, idx);
  3609. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  3610. if (caps & AC_AMPCAP_NUM_STEPS)
  3611. return cx_auto_add_pb_volume(codec, pin, name, idx);
  3612. return 0;
  3613. }
  3614. static int cx_auto_build_output_controls(struct hda_codec *codec)
  3615. {
  3616. struct conexant_spec *spec = codec->spec;
  3617. int i, err;
  3618. int num_line = 0, num_hp = 0, num_spk = 0;
  3619. static const char * const texts[3] = { "Front", "Surround", "CLFE" };
  3620. if (spec->dac_info_filled == 1)
  3621. return try_add_pb_volume(codec, spec->dac_info[0].dac,
  3622. spec->dac_info[0].pin,
  3623. "Master", 0);
  3624. for (i = 0; i < spec->dac_info_filled; i++) {
  3625. const char *label;
  3626. int idx, type;
  3627. if (!spec->dac_info[i].dac)
  3628. continue;
  3629. type = spec->dac_info[i].type;
  3630. if (type == AUTO_PIN_LINE_OUT)
  3631. type = spec->autocfg.line_out_type;
  3632. switch (type) {
  3633. case AUTO_PIN_LINE_OUT:
  3634. default:
  3635. label = texts[num_line++];
  3636. idx = 0;
  3637. break;
  3638. case AUTO_PIN_HP_OUT:
  3639. label = "Headphone";
  3640. idx = num_hp++;
  3641. break;
  3642. case AUTO_PIN_SPEAKER_OUT:
  3643. label = "Speaker";
  3644. idx = num_spk++;
  3645. break;
  3646. }
  3647. err = try_add_pb_volume(codec, spec->dac_info[i].dac,
  3648. spec->dac_info[i].pin,
  3649. label, idx);
  3650. if (err < 0)
  3651. return err;
  3652. }
  3653. if (spec->auto_mute) {
  3654. err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
  3655. if (err < 0)
  3656. return err;
  3657. }
  3658. return 0;
  3659. }
  3660. static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
  3661. const char *label, const char *pfx,
  3662. int cidx)
  3663. {
  3664. struct conexant_spec *spec = codec->spec;
  3665. int i;
  3666. for (i = 0; i < spec->num_adc_nids; i++) {
  3667. hda_nid_t adc_nid = spec->adc_nids[i];
  3668. int idx = get_input_connection(codec, adc_nid, nid);
  3669. if (idx < 0)
  3670. continue;
  3671. return cx_auto_add_volume_idx(codec, label, pfx,
  3672. cidx, adc_nid, HDA_INPUT, idx);
  3673. }
  3674. return 0;
  3675. }
  3676. static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
  3677. const char *label, int cidx)
  3678. {
  3679. struct conexant_spec *spec = codec->spec;
  3680. hda_nid_t mux, nid;
  3681. int i, con;
  3682. nid = spec->imux_info[idx].pin;
  3683. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
  3684. return cx_auto_add_volume(codec, label, " Boost", cidx,
  3685. nid, HDA_INPUT);
  3686. con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
  3687. &mux, false, 0);
  3688. if (con < 0)
  3689. return 0;
  3690. for (i = 0; i < idx; i++) {
  3691. if (spec->imux_info[i].boost == mux)
  3692. return 0; /* already present */
  3693. }
  3694. if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
  3695. spec->imux_info[idx].boost = mux;
  3696. return cx_auto_add_volume(codec, label, " Boost", 0,
  3697. mux, HDA_OUTPUT);
  3698. }
  3699. return 0;
  3700. }
  3701. static int cx_auto_build_input_controls(struct hda_codec *codec)
  3702. {
  3703. struct conexant_spec *spec = codec->spec;
  3704. struct hda_input_mux *imux = &spec->private_imux;
  3705. const char *prev_label;
  3706. int input_conn[HDA_MAX_NUM_INPUTS];
  3707. int i, err, cidx;
  3708. int multi_connection;
  3709. multi_connection = 0;
  3710. for (i = 0; i < imux->num_items; i++) {
  3711. cidx = get_input_connection(codec, spec->imux_info[i].adc,
  3712. spec->imux_info[i].pin);
  3713. input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
  3714. if (i > 0 && input_conn[i] != input_conn[0])
  3715. multi_connection = 1;
  3716. }
  3717. prev_label = NULL;
  3718. cidx = 0;
  3719. for (i = 0; i < imux->num_items; i++) {
  3720. hda_nid_t nid = spec->imux_info[i].pin;
  3721. const char *label;
  3722. label = hda_get_autocfg_input_label(codec, &spec->autocfg,
  3723. spec->imux_info[i].index);
  3724. if (label == prev_label)
  3725. cidx++;
  3726. else
  3727. cidx = 0;
  3728. prev_label = label;
  3729. err = cx_auto_add_boost_volume(codec, i, label, cidx);
  3730. if (err < 0)
  3731. return err;
  3732. if (!multi_connection) {
  3733. if (i > 0)
  3734. continue;
  3735. err = cx_auto_add_capture_volume(codec, nid,
  3736. "Capture", "", cidx);
  3737. } else {
  3738. err = cx_auto_add_capture_volume(codec, nid,
  3739. label, " Capture", cidx);
  3740. }
  3741. if (err < 0)
  3742. return err;
  3743. }
  3744. if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
  3745. err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
  3746. if (err < 0)
  3747. return err;
  3748. }
  3749. return 0;
  3750. }
  3751. static int cx_auto_build_controls(struct hda_codec *codec)
  3752. {
  3753. int err;
  3754. err = cx_auto_build_output_controls(codec);
  3755. if (err < 0)
  3756. return err;
  3757. err = cx_auto_build_input_controls(codec);
  3758. if (err < 0)
  3759. return err;
  3760. return conexant_build_controls(codec);
  3761. }
  3762. static int cx_auto_search_adcs(struct hda_codec *codec)
  3763. {
  3764. struct conexant_spec *spec = codec->spec;
  3765. hda_nid_t nid, end_nid;
  3766. end_nid = codec->start_nid + codec->num_nodes;
  3767. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3768. unsigned int caps = get_wcaps(codec, nid);
  3769. if (get_wcaps_type(caps) != AC_WID_AUD_IN)
  3770. continue;
  3771. if (caps & AC_WCAP_DIGITAL)
  3772. continue;
  3773. if (snd_BUG_ON(spec->num_adc_nids >=
  3774. ARRAY_SIZE(spec->private_adc_nids)))
  3775. break;
  3776. spec->private_adc_nids[spec->num_adc_nids++] = nid;
  3777. }
  3778. spec->adc_nids = spec->private_adc_nids;
  3779. return 0;
  3780. }
  3781. static const struct hda_codec_ops cx_auto_patch_ops = {
  3782. .build_controls = cx_auto_build_controls,
  3783. .build_pcms = conexant_build_pcms,
  3784. .init = cx_auto_init,
  3785. .free = conexant_free,
  3786. .unsol_event = cx_auto_unsol_event,
  3787. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3788. .suspend = conexant_suspend,
  3789. #endif
  3790. .reboot_notify = snd_hda_shutup_pins,
  3791. };
  3792. static int patch_conexant_auto(struct hda_codec *codec)
  3793. {
  3794. struct conexant_spec *spec;
  3795. int err;
  3796. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3797. codec->chip_name);
  3798. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3799. if (!spec)
  3800. return -ENOMEM;
  3801. codec->spec = spec;
  3802. codec->pin_amp_workaround = 1;
  3803. err = cx_auto_search_adcs(codec);
  3804. if (err < 0)
  3805. return err;
  3806. err = cx_auto_parse_auto_config(codec);
  3807. if (err < 0) {
  3808. kfree(codec->spec);
  3809. codec->spec = NULL;
  3810. return err;
  3811. }
  3812. spec->capture_stream = &cx_auto_pcm_analog_capture;
  3813. codec->patch_ops = cx_auto_patch_ops;
  3814. if (spec->beep_amp)
  3815. snd_hda_attach_beep_device(codec, spec->beep_amp);
  3816. return 0;
  3817. }
  3818. /*
  3819. */
  3820. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3821. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3822. .patch = patch_cxt5045 },
  3823. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3824. .patch = patch_cxt5047 },
  3825. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3826. .patch = patch_cxt5051 },
  3827. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3828. .patch = patch_cxt5066 },
  3829. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3830. .patch = patch_cxt5066 },
  3831. { .id = 0x14f15068, .name = "CX20584",
  3832. .patch = patch_cxt5066 },
  3833. { .id = 0x14f15069, .name = "CX20585",
  3834. .patch = patch_cxt5066 },
  3835. { .id = 0x14f1506c, .name = "CX20588",
  3836. .patch = patch_cxt5066 },
  3837. { .id = 0x14f1506e, .name = "CX20590",
  3838. .patch = patch_cxt5066 },
  3839. { .id = 0x14f15097, .name = "CX20631",
  3840. .patch = patch_conexant_auto },
  3841. { .id = 0x14f15098, .name = "CX20632",
  3842. .patch = patch_conexant_auto },
  3843. { .id = 0x14f150a1, .name = "CX20641",
  3844. .patch = patch_conexant_auto },
  3845. { .id = 0x14f150a2, .name = "CX20642",
  3846. .patch = patch_conexant_auto },
  3847. { .id = 0x14f150ab, .name = "CX20651",
  3848. .patch = patch_conexant_auto },
  3849. { .id = 0x14f150ac, .name = "CX20652",
  3850. .patch = patch_conexant_auto },
  3851. { .id = 0x14f150b8, .name = "CX20664",
  3852. .patch = patch_conexant_auto },
  3853. { .id = 0x14f150b9, .name = "CX20665",
  3854. .patch = patch_conexant_auto },
  3855. {} /* terminator */
  3856. };
  3857. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3858. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3859. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3860. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3861. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3862. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3863. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3864. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  3865. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3866. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3867. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3868. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3869. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3870. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3871. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3872. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3873. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3874. MODULE_LICENSE("GPL");
  3875. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3876. static struct hda_codec_preset_list conexant_list = {
  3877. .preset = snd_hda_preset_conexant,
  3878. .owner = THIS_MODULE,
  3879. };
  3880. static int __init patch_conexant_init(void)
  3881. {
  3882. return snd_hda_add_codec_preset(&conexant_list);
  3883. }
  3884. static void __exit patch_conexant_exit(void)
  3885. {
  3886. snd_hda_delete_codec_preset(&conexant_list);
  3887. }
  3888. module_init(patch_conexant_init)
  3889. module_exit(patch_conexant_exit)