patch_conexant.c 71 KB

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