patch_conexant.c 123 KB

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