patch_conexant.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  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. const struct hda_verb *init_verbs[5]; /* initialization verbs
  50. * don't forget NULL
  51. * termination!
  52. */
  53. unsigned int num_init_verbs;
  54. /* playback */
  55. struct hda_multi_out multiout; /* playback set-up
  56. * max_channels, dacs must be set
  57. * dig_out_nid and hp_nid are optional
  58. */
  59. unsigned int cur_eapd;
  60. unsigned int hp_present;
  61. unsigned int need_dac_fix;
  62. /* capture */
  63. unsigned int num_adc_nids;
  64. hda_nid_t *adc_nids;
  65. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  66. unsigned int cur_adc_idx;
  67. hda_nid_t cur_adc;
  68. unsigned int cur_adc_stream_tag;
  69. unsigned int cur_adc_format;
  70. /* capture source */
  71. const struct hda_input_mux *input_mux;
  72. hda_nid_t *capsrc_nids;
  73. unsigned int cur_mux[3];
  74. /* channel model */
  75. const struct hda_channel_mode *channel_mode;
  76. int num_channel_mode;
  77. /* PCM information */
  78. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  79. unsigned int spdif_route;
  80. /* jack detection */
  81. struct snd_array jacks;
  82. /* dynamic controls, init_verbs and input_mux */
  83. struct auto_pin_cfg autocfg;
  84. struct hda_input_mux private_imux;
  85. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  86. };
  87. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  88. struct hda_codec *codec,
  89. struct snd_pcm_substream *substream)
  90. {
  91. struct conexant_spec *spec = codec->spec;
  92. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  93. hinfo);
  94. }
  95. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  96. struct hda_codec *codec,
  97. unsigned int stream_tag,
  98. unsigned int format,
  99. struct snd_pcm_substream *substream)
  100. {
  101. struct conexant_spec *spec = codec->spec;
  102. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  103. stream_tag,
  104. format, substream);
  105. }
  106. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  107. struct hda_codec *codec,
  108. struct snd_pcm_substream *substream)
  109. {
  110. struct conexant_spec *spec = codec->spec;
  111. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  112. }
  113. /*
  114. * Digital out
  115. */
  116. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  117. struct hda_codec *codec,
  118. struct snd_pcm_substream *substream)
  119. {
  120. struct conexant_spec *spec = codec->spec;
  121. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  122. }
  123. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  124. struct hda_codec *codec,
  125. struct snd_pcm_substream *substream)
  126. {
  127. struct conexant_spec *spec = codec->spec;
  128. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  129. }
  130. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  131. struct hda_codec *codec,
  132. unsigned int stream_tag,
  133. unsigned int format,
  134. struct snd_pcm_substream *substream)
  135. {
  136. struct conexant_spec *spec = codec->spec;
  137. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  138. stream_tag,
  139. format, substream);
  140. }
  141. /*
  142. * Analog capture
  143. */
  144. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  145. struct hda_codec *codec,
  146. unsigned int stream_tag,
  147. unsigned int format,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  152. stream_tag, 0, format);
  153. return 0;
  154. }
  155. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  156. struct hda_codec *codec,
  157. struct snd_pcm_substream *substream)
  158. {
  159. struct conexant_spec *spec = codec->spec;
  160. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  161. return 0;
  162. }
  163. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  164. .substreams = 1,
  165. .channels_min = 2,
  166. .channels_max = 2,
  167. .nid = 0, /* fill later */
  168. .ops = {
  169. .open = conexant_playback_pcm_open,
  170. .prepare = conexant_playback_pcm_prepare,
  171. .cleanup = conexant_playback_pcm_cleanup
  172. },
  173. };
  174. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  175. .substreams = 1,
  176. .channels_min = 2,
  177. .channels_max = 2,
  178. .nid = 0, /* fill later */
  179. .ops = {
  180. .prepare = conexant_capture_pcm_prepare,
  181. .cleanup = conexant_capture_pcm_cleanup
  182. },
  183. };
  184. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  185. .substreams = 1,
  186. .channels_min = 2,
  187. .channels_max = 2,
  188. .nid = 0, /* fill later */
  189. .ops = {
  190. .open = conexant_dig_playback_pcm_open,
  191. .close = conexant_dig_playback_pcm_close,
  192. .prepare = conexant_dig_playback_pcm_prepare
  193. },
  194. };
  195. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  196. .substreams = 1,
  197. .channels_min = 2,
  198. .channels_max = 2,
  199. /* NID is set in alc_build_pcms */
  200. };
  201. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  202. struct hda_codec *codec,
  203. unsigned int stream_tag,
  204. unsigned int format,
  205. struct snd_pcm_substream *substream)
  206. {
  207. struct conexant_spec *spec = codec->spec;
  208. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  209. spec->cur_adc_stream_tag = stream_tag;
  210. spec->cur_adc_format = format;
  211. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  212. return 0;
  213. }
  214. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  215. struct hda_codec *codec,
  216. struct snd_pcm_substream *substream)
  217. {
  218. struct conexant_spec *spec = codec->spec;
  219. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  220. spec->cur_adc = 0;
  221. return 0;
  222. }
  223. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  224. .substreams = 1,
  225. .channels_min = 2,
  226. .channels_max = 2,
  227. .nid = 0, /* fill later */
  228. .ops = {
  229. .prepare = cx5051_capture_pcm_prepare,
  230. .cleanup = cx5051_capture_pcm_cleanup
  231. },
  232. };
  233. static int conexant_build_pcms(struct hda_codec *codec)
  234. {
  235. struct conexant_spec *spec = codec->spec;
  236. struct hda_pcm *info = spec->pcm_rec;
  237. codec->num_pcms = 1;
  238. codec->pcm_info = info;
  239. info->name = "CONEXANT Analog";
  240. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  241. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  242. spec->multiout.max_channels;
  243. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  244. spec->multiout.dac_nids[0];
  245. if (codec->vendor_id == 0x14f15051)
  246. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  247. cx5051_pcm_analog_capture;
  248. else
  249. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  250. conexant_pcm_analog_capture;
  251. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  252. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  253. if (spec->multiout.dig_out_nid) {
  254. info++;
  255. codec->num_pcms++;
  256. info->name = "Conexant Digital";
  257. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  258. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  259. conexant_pcm_digital_playback;
  260. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  261. spec->multiout.dig_out_nid;
  262. if (spec->dig_in_nid) {
  263. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  264. conexant_pcm_digital_capture;
  265. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  266. spec->dig_in_nid;
  267. }
  268. }
  269. return 0;
  270. }
  271. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  272. struct snd_ctl_elem_info *uinfo)
  273. {
  274. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  275. struct conexant_spec *spec = codec->spec;
  276. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  277. }
  278. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  279. struct snd_ctl_elem_value *ucontrol)
  280. {
  281. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  282. struct conexant_spec *spec = codec->spec;
  283. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  284. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  285. return 0;
  286. }
  287. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  288. struct snd_ctl_elem_value *ucontrol)
  289. {
  290. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  291. struct conexant_spec *spec = codec->spec;
  292. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  293. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  294. spec->capsrc_nids[adc_idx],
  295. &spec->cur_mux[adc_idx]);
  296. }
  297. static int conexant_add_jack(struct hda_codec *codec,
  298. hda_nid_t nid, int type)
  299. {
  300. struct conexant_spec *spec;
  301. struct conexant_jack *jack;
  302. const char *name;
  303. spec = codec->spec;
  304. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  305. jack = snd_array_new(&spec->jacks);
  306. name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
  307. if (!jack)
  308. return -ENOMEM;
  309. jack->nid = nid;
  310. jack->type = type;
  311. return snd_jack_new(codec->bus->card, name, type, &jack->jack);
  312. }
  313. static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  314. {
  315. struct conexant_spec *spec = codec->spec;
  316. struct conexant_jack *jacks = spec->jacks.list;
  317. if (jacks) {
  318. int i;
  319. for (i = 0; i < spec->jacks.used; i++) {
  320. if (jacks->nid == nid) {
  321. unsigned int present;
  322. present = snd_hda_codec_read(codec, nid, 0,
  323. AC_VERB_GET_PIN_SENSE, 0) &
  324. AC_PINSENSE_PRESENCE;
  325. present = (present) ? jacks->type : 0 ;
  326. snd_jack_report(jacks->jack,
  327. present);
  328. }
  329. jacks++;
  330. }
  331. }
  332. }
  333. static int conexant_init_jacks(struct hda_codec *codec)
  334. {
  335. #ifdef CONFIG_SND_JACK
  336. struct conexant_spec *spec = codec->spec;
  337. int i;
  338. for (i = 0; i < spec->num_init_verbs; i++) {
  339. const struct hda_verb *hv;
  340. hv = spec->init_verbs[i];
  341. while (hv->nid) {
  342. int err = 0;
  343. switch (hv->param ^ AC_USRSP_EN) {
  344. case CONEXANT_HP_EVENT:
  345. err = conexant_add_jack(codec, hv->nid,
  346. SND_JACK_HEADPHONE);
  347. conexant_report_jack(codec, hv->nid);
  348. break;
  349. case CXT5051_PORTC_EVENT:
  350. case CONEXANT_MIC_EVENT:
  351. err = conexant_add_jack(codec, hv->nid,
  352. SND_JACK_MICROPHONE);
  353. conexant_report_jack(codec, hv->nid);
  354. break;
  355. }
  356. if (err < 0)
  357. return err;
  358. ++hv;
  359. }
  360. }
  361. #endif
  362. return 0;
  363. }
  364. static int conexant_init(struct hda_codec *codec)
  365. {
  366. struct conexant_spec *spec = codec->spec;
  367. int i;
  368. for (i = 0; i < spec->num_init_verbs; i++)
  369. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  370. return 0;
  371. }
  372. static void conexant_free(struct hda_codec *codec)
  373. {
  374. #ifdef CONFIG_SND_JACK
  375. struct conexant_spec *spec = codec->spec;
  376. if (spec->jacks.list) {
  377. struct conexant_jack *jacks = spec->jacks.list;
  378. int i;
  379. for (i = 0; i < spec->jacks.used; i++)
  380. snd_device_free(codec->bus->card, &jacks[i].jack);
  381. snd_array_free(&spec->jacks);
  382. }
  383. #endif
  384. kfree(codec->spec);
  385. }
  386. static int conexant_build_controls(struct hda_codec *codec)
  387. {
  388. struct conexant_spec *spec = codec->spec;
  389. unsigned int i;
  390. int err;
  391. for (i = 0; i < spec->num_mixers; i++) {
  392. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  393. if (err < 0)
  394. return err;
  395. }
  396. if (spec->multiout.dig_out_nid) {
  397. err = snd_hda_create_spdif_out_ctls(codec,
  398. spec->multiout.dig_out_nid);
  399. if (err < 0)
  400. return err;
  401. err = snd_hda_create_spdif_share_sw(codec,
  402. &spec->multiout);
  403. if (err < 0)
  404. return err;
  405. spec->multiout.share_spdif = 1;
  406. }
  407. if (spec->dig_in_nid) {
  408. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  409. if (err < 0)
  410. return err;
  411. }
  412. return 0;
  413. }
  414. static struct hda_codec_ops conexant_patch_ops = {
  415. .build_controls = conexant_build_controls,
  416. .build_pcms = conexant_build_pcms,
  417. .init = conexant_init,
  418. .free = conexant_free,
  419. };
  420. /*
  421. * EAPD control
  422. * the private value = nid | (invert << 8)
  423. */
  424. #define cxt_eapd_info snd_ctl_boolean_mono_info
  425. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  426. struct snd_ctl_elem_value *ucontrol)
  427. {
  428. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  429. struct conexant_spec *spec = codec->spec;
  430. int invert = (kcontrol->private_value >> 8) & 1;
  431. if (invert)
  432. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  433. else
  434. ucontrol->value.integer.value[0] = spec->cur_eapd;
  435. return 0;
  436. }
  437. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  438. struct snd_ctl_elem_value *ucontrol)
  439. {
  440. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  441. struct conexant_spec *spec = codec->spec;
  442. int invert = (kcontrol->private_value >> 8) & 1;
  443. hda_nid_t nid = kcontrol->private_value & 0xff;
  444. unsigned int eapd;
  445. eapd = !!ucontrol->value.integer.value[0];
  446. if (invert)
  447. eapd = !eapd;
  448. if (eapd == spec->cur_eapd)
  449. return 0;
  450. spec->cur_eapd = eapd;
  451. snd_hda_codec_write_cache(codec, nid,
  452. 0, AC_VERB_SET_EAPD_BTLENABLE,
  453. eapd ? 0x02 : 0x00);
  454. return 1;
  455. }
  456. /* controls for test mode */
  457. #ifdef CONFIG_SND_DEBUG
  458. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  459. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  460. .info = cxt_eapd_info, \
  461. .get = cxt_eapd_get, \
  462. .put = cxt_eapd_put, \
  463. .private_value = nid | (mask<<16) }
  464. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  465. struct snd_ctl_elem_info *uinfo)
  466. {
  467. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  468. struct conexant_spec *spec = codec->spec;
  469. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  470. spec->num_channel_mode);
  471. }
  472. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  473. struct snd_ctl_elem_value *ucontrol)
  474. {
  475. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  476. struct conexant_spec *spec = codec->spec;
  477. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  478. spec->num_channel_mode,
  479. spec->multiout.max_channels);
  480. }
  481. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  482. struct snd_ctl_elem_value *ucontrol)
  483. {
  484. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  485. struct conexant_spec *spec = codec->spec;
  486. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  487. spec->num_channel_mode,
  488. &spec->multiout.max_channels);
  489. if (err >= 0 && spec->need_dac_fix)
  490. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  491. return err;
  492. }
  493. #define CXT_PIN_MODE(xname, nid, dir) \
  494. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  495. .info = conexant_ch_mode_info, \
  496. .get = conexant_ch_mode_get, \
  497. .put = conexant_ch_mode_put, \
  498. .private_value = nid | (dir<<16) }
  499. #endif /* CONFIG_SND_DEBUG */
  500. /* Conexant 5045 specific */
  501. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  502. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  503. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  504. #define CXT5045_SPDIF_OUT 0x18
  505. static struct hda_channel_mode cxt5045_modes[1] = {
  506. { 2, NULL },
  507. };
  508. static struct hda_input_mux cxt5045_capture_source = {
  509. .num_items = 2,
  510. .items = {
  511. { "IntMic", 0x1 },
  512. { "ExtMic", 0x2 },
  513. }
  514. };
  515. static struct hda_input_mux cxt5045_capture_source_benq = {
  516. .num_items = 3,
  517. .items = {
  518. { "IntMic", 0x1 },
  519. { "ExtMic", 0x2 },
  520. { "LineIn", 0x3 },
  521. }
  522. };
  523. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  524. .num_items = 2,
  525. .items = {
  526. { "ExtMic", 0x1 },
  527. { "IntMic", 0x2 },
  528. }
  529. };
  530. /* turn on/off EAPD (+ mute HP) as a master switch */
  531. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  532. struct snd_ctl_elem_value *ucontrol)
  533. {
  534. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  535. struct conexant_spec *spec = codec->spec;
  536. unsigned int bits;
  537. if (!cxt_eapd_put(kcontrol, ucontrol))
  538. return 0;
  539. /* toggle internal speakers mute depending of presence of
  540. * the headphone jack
  541. */
  542. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  543. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  544. HDA_AMP_MUTE, bits);
  545. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  546. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  547. HDA_AMP_MUTE, bits);
  548. return 1;
  549. }
  550. /* bind volumes of both NID 0x10 and 0x11 */
  551. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  552. .ops = &snd_hda_bind_vol,
  553. .values = {
  554. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  555. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  556. 0
  557. },
  558. };
  559. /* toggle input of built-in and mic jack appropriately */
  560. static void cxt5045_hp_automic(struct hda_codec *codec)
  561. {
  562. static struct hda_verb mic_jack_on[] = {
  563. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  564. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  565. {}
  566. };
  567. static struct hda_verb mic_jack_off[] = {
  568. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  569. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  570. {}
  571. };
  572. unsigned int present;
  573. present = snd_hda_codec_read(codec, 0x12, 0,
  574. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  575. if (present)
  576. snd_hda_sequence_write(codec, mic_jack_on);
  577. else
  578. snd_hda_sequence_write(codec, mic_jack_off);
  579. }
  580. /* mute internal speaker if HP is plugged */
  581. static void cxt5045_hp_automute(struct hda_codec *codec)
  582. {
  583. struct conexant_spec *spec = codec->spec;
  584. unsigned int bits;
  585. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  586. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  587. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  588. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  589. HDA_AMP_MUTE, bits);
  590. }
  591. /* unsolicited event for HP jack sensing */
  592. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  593. unsigned int res)
  594. {
  595. res >>= 26;
  596. switch (res) {
  597. case CONEXANT_HP_EVENT:
  598. cxt5045_hp_automute(codec);
  599. break;
  600. case CONEXANT_MIC_EVENT:
  601. cxt5045_hp_automic(codec);
  602. break;
  603. }
  604. }
  605. static struct snd_kcontrol_new cxt5045_mixers[] = {
  606. {
  607. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  608. .name = "Capture Source",
  609. .info = conexant_mux_enum_info,
  610. .get = conexant_mux_enum_get,
  611. .put = conexant_mux_enum_put
  612. },
  613. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  614. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  615. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  616. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  617. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  618. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  619. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  620. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  621. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  622. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  623. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  624. {
  625. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  626. .name = "Master Playback Switch",
  627. .info = cxt_eapd_info,
  628. .get = cxt_eapd_get,
  629. .put = cxt5045_hp_master_sw_put,
  630. .private_value = 0x10,
  631. },
  632. {}
  633. };
  634. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  635. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  636. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  637. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  638. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  639. {}
  640. };
  641. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  642. {
  643. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  644. .name = "Capture Source",
  645. .info = conexant_mux_enum_info,
  646. .get = conexant_mux_enum_get,
  647. .put = conexant_mux_enum_put
  648. },
  649. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  650. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  651. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  652. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  653. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  654. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  655. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  656. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  657. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  658. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  659. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  660. {
  661. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  662. .name = "Master Playback Switch",
  663. .info = cxt_eapd_info,
  664. .get = cxt_eapd_get,
  665. .put = cxt5045_hp_master_sw_put,
  666. .private_value = 0x10,
  667. },
  668. {}
  669. };
  670. static struct hda_verb cxt5045_init_verbs[] = {
  671. /* Line in, Mic */
  672. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  673. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  674. /* HP, Amp */
  675. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  676. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  677. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  678. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  679. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  680. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  681. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  682. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  683. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  684. /* Record selector: Int mic */
  685. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  686. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  687. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  688. /* SPDIF route: PCM */
  689. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  690. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  691. /* EAPD */
  692. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  693. { } /* end */
  694. };
  695. static struct hda_verb cxt5045_benq_init_verbs[] = {
  696. /* Int Mic, Mic */
  697. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  698. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  699. /* Line In,HP, Amp */
  700. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  701. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  702. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  703. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  704. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  705. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  706. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  707. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  708. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  709. /* Record selector: Int mic */
  710. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  711. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  712. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  713. /* SPDIF route: PCM */
  714. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  715. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  716. /* EAPD */
  717. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  718. { } /* end */
  719. };
  720. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  721. /* pin sensing on HP jack */
  722. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  723. { } /* end */
  724. };
  725. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  726. /* pin sensing on HP jack */
  727. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  728. { } /* end */
  729. };
  730. #ifdef CONFIG_SND_DEBUG
  731. /* Test configuration for debugging, modelled after the ALC260 test
  732. * configuration.
  733. */
  734. static struct hda_input_mux cxt5045_test_capture_source = {
  735. .num_items = 5,
  736. .items = {
  737. { "MIXER", 0x0 },
  738. { "MIC1 pin", 0x1 },
  739. { "LINE1 pin", 0x2 },
  740. { "HP-OUT pin", 0x3 },
  741. { "CD pin", 0x4 },
  742. },
  743. };
  744. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  745. /* Output controls */
  746. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  747. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  748. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  749. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  750. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  751. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  752. /* Modes for retasking pin widgets */
  753. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  754. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  755. /* EAPD Switch Control */
  756. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  757. /* Loopback mixer controls */
  758. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  759. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  760. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  761. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  762. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  763. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  764. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  765. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  766. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  767. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  768. {
  769. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  770. .name = "Input Source",
  771. .info = conexant_mux_enum_info,
  772. .get = conexant_mux_enum_get,
  773. .put = conexant_mux_enum_put,
  774. },
  775. /* Audio input controls */
  776. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  777. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  778. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  779. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  780. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  781. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  782. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  783. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  784. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  785. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  786. { } /* end */
  787. };
  788. static struct hda_verb cxt5045_test_init_verbs[] = {
  789. /* Set connections */
  790. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  791. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  792. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  793. /* Enable retasking pins as output, initially without power amp */
  794. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  795. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  796. /* Disable digital (SPDIF) pins initially, but users can enable
  797. * them via a mixer switch. In the case of SPDIF-out, this initverb
  798. * payload also sets the generation to 0, output to be in "consumer"
  799. * PCM format, copyright asserted, no pre-emphasis and no validity
  800. * control.
  801. */
  802. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  803. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  804. /* Start with output sum widgets muted and their output gains at min */
  805. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  806. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  807. /* Unmute retasking pin widget output buffers since the default
  808. * state appears to be output. As the pin mode is changed by the
  809. * user the pin mode control will take care of enabling the pin's
  810. * input/output buffers as needed.
  811. */
  812. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  813. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  814. /* Mute capture amp left and right */
  815. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  816. /* Set ADC connection select to match default mixer setting (mic1
  817. * pin)
  818. */
  819. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  820. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  821. /* Mute all inputs to mixer widget (even unconnected ones) */
  822. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  823. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  824. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  825. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  826. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  827. { }
  828. };
  829. #endif
  830. /* initialize jack-sensing, too */
  831. static int cxt5045_init(struct hda_codec *codec)
  832. {
  833. conexant_init(codec);
  834. cxt5045_hp_automute(codec);
  835. return 0;
  836. }
  837. enum {
  838. CXT5045_LAPTOP_HPSENSE,
  839. CXT5045_LAPTOP_MICSENSE,
  840. CXT5045_LAPTOP_HPMICSENSE,
  841. CXT5045_BENQ,
  842. CXT5045_LAPTOP_HP530,
  843. #ifdef CONFIG_SND_DEBUG
  844. CXT5045_TEST,
  845. #endif
  846. CXT5045_MODELS
  847. };
  848. static const char *cxt5045_models[CXT5045_MODELS] = {
  849. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  850. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  851. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  852. [CXT5045_BENQ] = "benq",
  853. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  854. #ifdef CONFIG_SND_DEBUG
  855. [CXT5045_TEST] = "test",
  856. #endif
  857. };
  858. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  859. SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
  860. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  861. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
  862. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
  863. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
  864. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  865. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
  866. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  867. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
  868. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  869. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  870. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  871. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  872. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  873. CXT5045_LAPTOP_HPMICSENSE),
  874. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  875. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  876. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  877. SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  878. SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  879. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  880. {}
  881. };
  882. static int patch_cxt5045(struct hda_codec *codec)
  883. {
  884. struct conexant_spec *spec;
  885. int board_config;
  886. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  887. if (!spec)
  888. return -ENOMEM;
  889. codec->spec = spec;
  890. spec->multiout.max_channels = 2;
  891. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  892. spec->multiout.dac_nids = cxt5045_dac_nids;
  893. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  894. spec->num_adc_nids = 1;
  895. spec->adc_nids = cxt5045_adc_nids;
  896. spec->capsrc_nids = cxt5045_capsrc_nids;
  897. spec->input_mux = &cxt5045_capture_source;
  898. spec->num_mixers = 1;
  899. spec->mixers[0] = cxt5045_mixers;
  900. spec->num_init_verbs = 1;
  901. spec->init_verbs[0] = cxt5045_init_verbs;
  902. spec->spdif_route = 0;
  903. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  904. spec->channel_mode = cxt5045_modes,
  905. codec->patch_ops = conexant_patch_ops;
  906. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  907. cxt5045_models,
  908. cxt5045_cfg_tbl);
  909. switch (board_config) {
  910. case CXT5045_LAPTOP_HPSENSE:
  911. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  912. spec->input_mux = &cxt5045_capture_source;
  913. spec->num_init_verbs = 2;
  914. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  915. spec->mixers[0] = cxt5045_mixers;
  916. codec->patch_ops.init = cxt5045_init;
  917. break;
  918. case CXT5045_LAPTOP_MICSENSE:
  919. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  920. spec->input_mux = &cxt5045_capture_source;
  921. spec->num_init_verbs = 2;
  922. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  923. spec->mixers[0] = cxt5045_mixers;
  924. codec->patch_ops.init = cxt5045_init;
  925. break;
  926. default:
  927. case CXT5045_LAPTOP_HPMICSENSE:
  928. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  929. spec->input_mux = &cxt5045_capture_source;
  930. spec->num_init_verbs = 3;
  931. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  932. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  933. spec->mixers[0] = cxt5045_mixers;
  934. codec->patch_ops.init = cxt5045_init;
  935. break;
  936. case CXT5045_BENQ:
  937. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  938. spec->input_mux = &cxt5045_capture_source_benq;
  939. spec->num_init_verbs = 1;
  940. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  941. spec->mixers[0] = cxt5045_mixers;
  942. spec->mixers[1] = cxt5045_benq_mixers;
  943. spec->num_mixers = 2;
  944. codec->patch_ops.init = cxt5045_init;
  945. break;
  946. case CXT5045_LAPTOP_HP530:
  947. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  948. spec->input_mux = &cxt5045_capture_source_hp530;
  949. spec->num_init_verbs = 2;
  950. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  951. spec->mixers[0] = cxt5045_mixers_hp530;
  952. codec->patch_ops.init = cxt5045_init;
  953. break;
  954. #ifdef CONFIG_SND_DEBUG
  955. case CXT5045_TEST:
  956. spec->input_mux = &cxt5045_test_capture_source;
  957. spec->mixers[0] = cxt5045_test_mixer;
  958. spec->init_verbs[0] = cxt5045_test_init_verbs;
  959. break;
  960. #endif
  961. }
  962. switch (codec->subsystem_id >> 16) {
  963. case 0x103c:
  964. /* HP laptop has a really bad sound over 0dB on NID 0x17.
  965. * Fix max PCM level to 0 dB
  966. * (originall it has 0x2b steps with 0dB offset 0x14)
  967. */
  968. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  969. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  970. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  971. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  972. (1 << AC_AMPCAP_MUTE_SHIFT));
  973. break;
  974. }
  975. return 0;
  976. }
  977. /* Conexant 5047 specific */
  978. #define CXT5047_SPDIF_OUT 0x11
  979. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  980. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  981. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  982. static struct hda_channel_mode cxt5047_modes[1] = {
  983. { 2, NULL },
  984. };
  985. static struct hda_input_mux cxt5047_capture_source = {
  986. .num_items = 1,
  987. .items = {
  988. { "Mic", 0x2 },
  989. }
  990. };
  991. static struct hda_input_mux cxt5047_hp_capture_source = {
  992. .num_items = 1,
  993. .items = {
  994. { "ExtMic", 0x2 },
  995. }
  996. };
  997. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  998. .num_items = 2,
  999. .items = {
  1000. { "ExtMic", 0x2 },
  1001. { "Line-In", 0x1 },
  1002. }
  1003. };
  1004. /* turn on/off EAPD (+ mute HP) as a master switch */
  1005. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1006. struct snd_ctl_elem_value *ucontrol)
  1007. {
  1008. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1009. struct conexant_spec *spec = codec->spec;
  1010. unsigned int bits;
  1011. if (!cxt_eapd_put(kcontrol, ucontrol))
  1012. return 0;
  1013. /* toggle internal speakers mute depending of presence of
  1014. * the headphone jack
  1015. */
  1016. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1017. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  1018. HDA_AMP_MUTE, bits);
  1019. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1020. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1021. HDA_AMP_MUTE, bits);
  1022. return 1;
  1023. }
  1024. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  1025. static struct hda_bind_ctls cxt5047_bind_master_vol = {
  1026. .ops = &snd_hda_bind_vol,
  1027. .values = {
  1028. HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  1029. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  1030. 0
  1031. },
  1032. };
  1033. /* mute internal speaker if HP is plugged */
  1034. static void cxt5047_hp_automute(struct hda_codec *codec)
  1035. {
  1036. struct conexant_spec *spec = codec->spec;
  1037. unsigned int bits;
  1038. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  1039. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1040. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1041. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  1042. HDA_AMP_MUTE, bits);
  1043. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  1044. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  1045. HDA_AMP_MUTE, bits);
  1046. }
  1047. /* mute internal speaker if HP is plugged */
  1048. static void cxt5047_hp2_automute(struct hda_codec *codec)
  1049. {
  1050. struct conexant_spec *spec = codec->spec;
  1051. unsigned int bits;
  1052. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  1053. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1054. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  1055. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  1056. HDA_AMP_MUTE, bits);
  1057. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  1058. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  1059. HDA_AMP_MUTE, bits);
  1060. }
  1061. /* toggle input of built-in and mic jack appropriately */
  1062. static void cxt5047_hp_automic(struct hda_codec *codec)
  1063. {
  1064. static struct hda_verb mic_jack_on[] = {
  1065. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1066. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1067. {}
  1068. };
  1069. static struct hda_verb mic_jack_off[] = {
  1070. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1071. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1072. {}
  1073. };
  1074. unsigned int present;
  1075. present = snd_hda_codec_read(codec, 0x15, 0,
  1076. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1077. if (present)
  1078. snd_hda_sequence_write(codec, mic_jack_on);
  1079. else
  1080. snd_hda_sequence_write(codec, mic_jack_off);
  1081. }
  1082. /* unsolicited event for HP jack sensing */
  1083. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1084. unsigned int res)
  1085. {
  1086. switch (res >> 26) {
  1087. case CONEXANT_HP_EVENT:
  1088. cxt5047_hp_automute(codec);
  1089. break;
  1090. case CONEXANT_MIC_EVENT:
  1091. cxt5047_hp_automic(codec);
  1092. break;
  1093. }
  1094. }
  1095. /* unsolicited event for HP jack sensing - non-EAPD systems */
  1096. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  1097. unsigned int res)
  1098. {
  1099. res >>= 26;
  1100. switch (res) {
  1101. case CONEXANT_HP_EVENT:
  1102. cxt5047_hp2_automute(codec);
  1103. break;
  1104. case CONEXANT_MIC_EVENT:
  1105. cxt5047_hp_automic(codec);
  1106. break;
  1107. }
  1108. }
  1109. static struct snd_kcontrol_new cxt5047_mixers[] = {
  1110. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1111. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1112. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  1113. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  1114. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1115. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1116. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1117. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1118. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  1119. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  1120. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  1121. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  1122. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1123. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  1124. {}
  1125. };
  1126. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  1127. {
  1128. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1129. .name = "Capture Source",
  1130. .info = conexant_mux_enum_info,
  1131. .get = conexant_mux_enum_get,
  1132. .put = conexant_mux_enum_put
  1133. },
  1134. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1135. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1136. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1137. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1138. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1139. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1140. HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
  1141. {
  1142. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1143. .name = "Master Playback Switch",
  1144. .info = cxt_eapd_info,
  1145. .get = cxt_eapd_get,
  1146. .put = cxt5047_hp_master_sw_put,
  1147. .private_value = 0x13,
  1148. },
  1149. {}
  1150. };
  1151. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  1152. {
  1153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1154. .name = "Capture Source",
  1155. .info = conexant_mux_enum_info,
  1156. .get = conexant_mux_enum_get,
  1157. .put = conexant_mux_enum_put
  1158. },
  1159. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1160. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  1161. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1162. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1163. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1164. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1165. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1166. {
  1167. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1168. .name = "Master Playback Switch",
  1169. .info = cxt_eapd_info,
  1170. .get = cxt_eapd_get,
  1171. .put = cxt5047_hp_master_sw_put,
  1172. .private_value = 0x13,
  1173. },
  1174. { } /* end */
  1175. };
  1176. static struct hda_verb cxt5047_init_verbs[] = {
  1177. /* Line in, Mic, Built-in Mic */
  1178. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1179. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1180. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1181. /* HP, Speaker */
  1182. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1183. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  1184. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  1185. /* Record selector: Mic */
  1186. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1187. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1188. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1189. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1190. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1191. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1192. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1193. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1194. /* SPDIF route: PCM */
  1195. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1196. /* Enable unsolicited events */
  1197. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1198. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1199. { } /* end */
  1200. };
  1201. /* configuration for Toshiba Laptops */
  1202. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1203. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  1204. /* pin sensing on HP and Mic jacks */
  1205. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1206. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1207. /* Speaker routing */
  1208. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1209. {}
  1210. };
  1211. /* configuration for HP Laptops */
  1212. static struct hda_verb cxt5047_hp_init_verbs[] = {
  1213. /* pin sensing on HP jack */
  1214. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1215. /* 0x13 is actually shared by both HP and speaker;
  1216. * setting the connection to 0 (=0x19) makes the master volume control
  1217. * working mysteriouslly...
  1218. */
  1219. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  1220. /* Record selector: Ext Mic */
  1221. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1222. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1223. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1224. /* Speaker routing */
  1225. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1226. {}
  1227. };
  1228. /* Test configuration for debugging, modelled after the ALC260 test
  1229. * configuration.
  1230. */
  1231. #ifdef CONFIG_SND_DEBUG
  1232. static struct hda_input_mux cxt5047_test_capture_source = {
  1233. .num_items = 4,
  1234. .items = {
  1235. { "LINE1 pin", 0x0 },
  1236. { "MIC1 pin", 0x1 },
  1237. { "MIC2 pin", 0x2 },
  1238. { "CD pin", 0x3 },
  1239. },
  1240. };
  1241. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1242. /* Output only controls */
  1243. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1244. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1245. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1246. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1247. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1248. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1249. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1250. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1251. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1252. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1253. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1254. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1255. /* Modes for retasking pin widgets */
  1256. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1257. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1258. /* EAPD Switch Control */
  1259. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1260. /* Loopback mixer controls */
  1261. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1262. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1263. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1264. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1265. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1266. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1267. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1268. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1269. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1270. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1271. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1272. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1273. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1274. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1275. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1276. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1277. {
  1278. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1279. .name = "Input Source",
  1280. .info = conexant_mux_enum_info,
  1281. .get = conexant_mux_enum_get,
  1282. .put = conexant_mux_enum_put,
  1283. },
  1284. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  1285. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  1286. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  1287. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  1288. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  1289. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  1290. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  1291. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  1292. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  1293. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  1294. { } /* end */
  1295. };
  1296. static struct hda_verb cxt5047_test_init_verbs[] = {
  1297. /* Enable retasking pins as output, initially without power amp */
  1298. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1299. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1300. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1301. /* Disable digital (SPDIF) pins initially, but users can enable
  1302. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1303. * payload also sets the generation to 0, output to be in "consumer"
  1304. * PCM format, copyright asserted, no pre-emphasis and no validity
  1305. * control.
  1306. */
  1307. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1308. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1309. * OUT1 sum bus when acting as an output.
  1310. */
  1311. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1312. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1313. /* Start with output sum widgets muted and their output gains at min */
  1314. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1315. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1316. /* Unmute retasking pin widget output buffers since the default
  1317. * state appears to be output. As the pin mode is changed by the
  1318. * user the pin mode control will take care of enabling the pin's
  1319. * input/output buffers as needed.
  1320. */
  1321. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1322. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1323. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1324. /* Mute capture amp left and right */
  1325. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1326. /* Set ADC connection select to match default mixer setting (mic1
  1327. * pin)
  1328. */
  1329. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1330. /* Mute all inputs to mixer widget (even unconnected ones) */
  1331. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1332. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1333. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1334. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1335. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1336. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1337. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1338. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1339. { }
  1340. };
  1341. #endif
  1342. /* initialize jack-sensing, too */
  1343. static int cxt5047_hp_init(struct hda_codec *codec)
  1344. {
  1345. conexant_init(codec);
  1346. cxt5047_hp_automute(codec);
  1347. return 0;
  1348. }
  1349. enum {
  1350. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1351. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1352. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1353. #ifdef CONFIG_SND_DEBUG
  1354. CXT5047_TEST,
  1355. #endif
  1356. CXT5047_MODELS
  1357. };
  1358. static const char *cxt5047_models[CXT5047_MODELS] = {
  1359. [CXT5047_LAPTOP] = "laptop",
  1360. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1361. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1362. #ifdef CONFIG_SND_DEBUG
  1363. [CXT5047_TEST] = "test",
  1364. #endif
  1365. };
  1366. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1367. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1368. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1369. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1370. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1371. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1372. {}
  1373. };
  1374. static int patch_cxt5047(struct hda_codec *codec)
  1375. {
  1376. struct conexant_spec *spec;
  1377. int board_config;
  1378. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1379. if (!spec)
  1380. return -ENOMEM;
  1381. codec->spec = spec;
  1382. spec->multiout.max_channels = 2;
  1383. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1384. spec->multiout.dac_nids = cxt5047_dac_nids;
  1385. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1386. spec->num_adc_nids = 1;
  1387. spec->adc_nids = cxt5047_adc_nids;
  1388. spec->capsrc_nids = cxt5047_capsrc_nids;
  1389. spec->input_mux = &cxt5047_capture_source;
  1390. spec->num_mixers = 1;
  1391. spec->mixers[0] = cxt5047_mixers;
  1392. spec->num_init_verbs = 1;
  1393. spec->init_verbs[0] = cxt5047_init_verbs;
  1394. spec->spdif_route = 0;
  1395. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1396. spec->channel_mode = cxt5047_modes,
  1397. codec->patch_ops = conexant_patch_ops;
  1398. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1399. cxt5047_models,
  1400. cxt5047_cfg_tbl);
  1401. switch (board_config) {
  1402. case CXT5047_LAPTOP:
  1403. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1404. break;
  1405. case CXT5047_LAPTOP_HP:
  1406. spec->input_mux = &cxt5047_hp_capture_source;
  1407. spec->num_init_verbs = 2;
  1408. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1409. spec->mixers[0] = cxt5047_hp_mixers;
  1410. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1411. codec->patch_ops.init = cxt5047_hp_init;
  1412. break;
  1413. case CXT5047_LAPTOP_EAPD:
  1414. spec->input_mux = &cxt5047_toshiba_capture_source;
  1415. spec->num_init_verbs = 2;
  1416. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1417. spec->mixers[0] = cxt5047_toshiba_mixers;
  1418. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1419. break;
  1420. #ifdef CONFIG_SND_DEBUG
  1421. case CXT5047_TEST:
  1422. spec->input_mux = &cxt5047_test_capture_source;
  1423. spec->mixers[0] = cxt5047_test_mixer;
  1424. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1425. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1426. #endif
  1427. }
  1428. return 0;
  1429. }
  1430. /* Conexant 5051 specific */
  1431. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1432. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1433. static struct hda_channel_mode cxt5051_modes[1] = {
  1434. { 2, NULL },
  1435. };
  1436. static void cxt5051_update_speaker(struct hda_codec *codec)
  1437. {
  1438. struct conexant_spec *spec = codec->spec;
  1439. unsigned int pinctl;
  1440. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1441. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1442. pinctl);
  1443. }
  1444. /* turn on/off EAPD (+ mute HP) as a master switch */
  1445. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1446. struct snd_ctl_elem_value *ucontrol)
  1447. {
  1448. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1449. if (!cxt_eapd_put(kcontrol, ucontrol))
  1450. return 0;
  1451. cxt5051_update_speaker(codec);
  1452. return 1;
  1453. }
  1454. /* toggle input of built-in and mic jack appropriately */
  1455. static void cxt5051_portb_automic(struct hda_codec *codec)
  1456. {
  1457. unsigned int present;
  1458. present = snd_hda_codec_read(codec, 0x17, 0,
  1459. AC_VERB_GET_PIN_SENSE, 0) &
  1460. AC_PINSENSE_PRESENCE;
  1461. snd_hda_codec_write(codec, 0x14, 0,
  1462. AC_VERB_SET_CONNECT_SEL,
  1463. present ? 0x01 : 0x00);
  1464. }
  1465. /* switch the current ADC according to the jack state */
  1466. static void cxt5051_portc_automic(struct hda_codec *codec)
  1467. {
  1468. struct conexant_spec *spec = codec->spec;
  1469. unsigned int present;
  1470. hda_nid_t new_adc;
  1471. present = snd_hda_codec_read(codec, 0x18, 0,
  1472. AC_VERB_GET_PIN_SENSE, 0) &
  1473. AC_PINSENSE_PRESENCE;
  1474. if (present)
  1475. spec->cur_adc_idx = 1;
  1476. else
  1477. spec->cur_adc_idx = 0;
  1478. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1479. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1480. /* stream is running, let's swap the current ADC */
  1481. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1482. spec->cur_adc = new_adc;
  1483. snd_hda_codec_setup_stream(codec, new_adc,
  1484. spec->cur_adc_stream_tag, 0,
  1485. spec->cur_adc_format);
  1486. }
  1487. }
  1488. /* mute internal speaker if HP is plugged */
  1489. static void cxt5051_hp_automute(struct hda_codec *codec)
  1490. {
  1491. struct conexant_spec *spec = codec->spec;
  1492. spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
  1493. AC_VERB_GET_PIN_SENSE, 0) &
  1494. AC_PINSENSE_PRESENCE;
  1495. cxt5051_update_speaker(codec);
  1496. }
  1497. /* unsolicited event for HP jack sensing */
  1498. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1499. unsigned int res)
  1500. {
  1501. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1502. switch (res >> 26) {
  1503. case CONEXANT_HP_EVENT:
  1504. cxt5051_hp_automute(codec);
  1505. break;
  1506. case CXT5051_PORTB_EVENT:
  1507. cxt5051_portb_automic(codec);
  1508. break;
  1509. case CXT5051_PORTC_EVENT:
  1510. cxt5051_portc_automic(codec);
  1511. break;
  1512. }
  1513. conexant_report_jack(codec, nid);
  1514. }
  1515. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1516. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1517. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1518. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1519. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1520. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1521. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1522. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1523. {
  1524. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1525. .name = "Master Playback Switch",
  1526. .info = cxt_eapd_info,
  1527. .get = cxt_eapd_get,
  1528. .put = cxt5051_hp_master_sw_put,
  1529. .private_value = 0x1a,
  1530. },
  1531. {}
  1532. };
  1533. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1534. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1535. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1536. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1537. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1538. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1539. {
  1540. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1541. .name = "Master Playback Switch",
  1542. .info = cxt_eapd_info,
  1543. .get = cxt_eapd_get,
  1544. .put = cxt5051_hp_master_sw_put,
  1545. .private_value = 0x1a,
  1546. },
  1547. {}
  1548. };
  1549. static struct hda_verb cxt5051_init_verbs[] = {
  1550. /* Line in, Mic */
  1551. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1552. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1553. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1554. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1555. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1556. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1557. /* SPK */
  1558. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1559. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1560. /* HP, Amp */
  1561. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1562. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1563. /* DAC1 */
  1564. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1565. /* Record selector: Int mic */
  1566. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1567. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1568. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1569. /* SPDIF route: PCM */
  1570. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1571. /* EAPD */
  1572. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1573. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1574. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1575. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1576. { } /* end */
  1577. };
  1578. /* initialize jack-sensing, too */
  1579. static int cxt5051_init(struct hda_codec *codec)
  1580. {
  1581. conexant_init(codec);
  1582. conexant_init_jacks(codec);
  1583. if (codec->patch_ops.unsol_event) {
  1584. cxt5051_hp_automute(codec);
  1585. cxt5051_portb_automic(codec);
  1586. cxt5051_portc_automic(codec);
  1587. }
  1588. return 0;
  1589. }
  1590. enum {
  1591. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1592. CXT5051_HP, /* no docking */
  1593. CXT5051_MODELS
  1594. };
  1595. static const char *cxt5051_models[CXT5051_MODELS] = {
  1596. [CXT5051_LAPTOP] = "laptop",
  1597. [CXT5051_HP] = "hp",
  1598. };
  1599. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1600. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1601. CXT5051_LAPTOP),
  1602. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1603. {}
  1604. };
  1605. static int patch_cxt5051(struct hda_codec *codec)
  1606. {
  1607. struct conexant_spec *spec;
  1608. int board_config;
  1609. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1610. if (!spec)
  1611. return -ENOMEM;
  1612. codec->spec = spec;
  1613. codec->patch_ops = conexant_patch_ops;
  1614. codec->patch_ops.init = cxt5051_init;
  1615. spec->multiout.max_channels = 2;
  1616. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1617. spec->multiout.dac_nids = cxt5051_dac_nids;
  1618. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1619. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1620. spec->adc_nids = cxt5051_adc_nids;
  1621. spec->num_mixers = 1;
  1622. spec->mixers[0] = cxt5051_mixers;
  1623. spec->num_init_verbs = 1;
  1624. spec->init_verbs[0] = cxt5051_init_verbs;
  1625. spec->spdif_route = 0;
  1626. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1627. spec->channel_mode = cxt5051_modes;
  1628. spec->cur_adc = 0;
  1629. spec->cur_adc_idx = 0;
  1630. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1631. cxt5051_models,
  1632. cxt5051_cfg_tbl);
  1633. switch (board_config) {
  1634. case CXT5051_HP:
  1635. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1636. spec->mixers[0] = cxt5051_hp_mixers;
  1637. break;
  1638. default:
  1639. case CXT5051_LAPTOP:
  1640. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1641. break;
  1642. }
  1643. return 0;
  1644. }
  1645. /*
  1646. */
  1647. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  1648. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1649. .patch = patch_cxt5045 },
  1650. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1651. .patch = patch_cxt5047 },
  1652. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  1653. .patch = patch_cxt5051 },
  1654. {} /* terminator */
  1655. };
  1656. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  1657. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  1658. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  1659. MODULE_LICENSE("GPL");
  1660. MODULE_DESCRIPTION("Conexant HD-audio codec");
  1661. static struct hda_codec_preset_list conexant_list = {
  1662. .preset = snd_hda_preset_conexant,
  1663. .owner = THIS_MODULE,
  1664. };
  1665. static int __init patch_conexant_init(void)
  1666. {
  1667. return snd_hda_add_codec_preset(&conexant_list);
  1668. }
  1669. static void __exit patch_conexant_exit(void)
  1670. {
  1671. snd_hda_delete_codec_preset(&conexant_list);
  1672. }
  1673. module_init(patch_conexant_init)
  1674. module_exit(patch_conexant_exit)