patch_conexant.c 97 KB

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