patch_conexant.c 76 KB

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