patch_conexant.c 118 KB

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