patch_conexant.c 84 KB

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