patch_conexant.c 131 KB

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