patch_conexant.c 108 KB

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