patch_conexant.c 94 KB

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