patch_conexant.c 115 KB

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