patch_conexant.c 116 KB

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