patch_conexant.c 99 KB

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