patch_conexant.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  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 <sound/driver.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <linux/pci.h>
  27. #include <sound/core.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. struct conexant_spec {
  38. struct snd_kcontrol_new *mixers[5];
  39. int num_mixers;
  40. const struct hda_verb *init_verbs[5]; /* initialization verbs
  41. * don't forget NULL
  42. * termination!
  43. */
  44. unsigned int num_init_verbs;
  45. /* playback */
  46. struct hda_multi_out multiout; /* playback set-up
  47. * max_channels, dacs must be set
  48. * dig_out_nid and hp_nid are optional
  49. */
  50. unsigned int cur_eapd;
  51. unsigned int need_dac_fix;
  52. /* capture */
  53. unsigned int num_adc_nids;
  54. hda_nid_t *adc_nids;
  55. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  56. /* capture source */
  57. const struct hda_input_mux *input_mux;
  58. hda_nid_t *capsrc_nids;
  59. unsigned int cur_mux[3];
  60. /* channel model */
  61. const struct hda_channel_mode *channel_mode;
  62. int num_channel_mode;
  63. /* PCM information */
  64. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  65. struct mutex amp_mutex; /* PCM volume/mute control mutex */
  66. unsigned int spdif_route;
  67. /* dynamic controls, init_verbs and input_mux */
  68. struct auto_pin_cfg autocfg;
  69. unsigned int num_kctl_alloc, num_kctl_used;
  70. struct snd_kcontrol_new *kctl_alloc;
  71. struct hda_input_mux private_imux;
  72. hda_nid_t private_dac_nids[4];
  73. };
  74. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  75. struct hda_codec *codec,
  76. struct snd_pcm_substream *substream)
  77. {
  78. struct conexant_spec *spec = codec->spec;
  79. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  80. }
  81. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  82. struct hda_codec *codec,
  83. unsigned int stream_tag,
  84. unsigned int format,
  85. struct snd_pcm_substream *substream)
  86. {
  87. struct conexant_spec *spec = codec->spec;
  88. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  89. stream_tag,
  90. format, substream);
  91. }
  92. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  93. struct hda_codec *codec,
  94. struct snd_pcm_substream *substream)
  95. {
  96. struct conexant_spec *spec = codec->spec;
  97. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  98. }
  99. /*
  100. * Digital out
  101. */
  102. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  103. struct hda_codec *codec,
  104. struct snd_pcm_substream *substream)
  105. {
  106. struct conexant_spec *spec = codec->spec;
  107. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  108. }
  109. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  110. struct hda_codec *codec,
  111. struct snd_pcm_substream *substream)
  112. {
  113. struct conexant_spec *spec = codec->spec;
  114. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  115. }
  116. /*
  117. * Analog capture
  118. */
  119. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  120. struct hda_codec *codec,
  121. unsigned int stream_tag,
  122. unsigned int format,
  123. struct snd_pcm_substream *substream)
  124. {
  125. struct conexant_spec *spec = codec->spec;
  126. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  127. stream_tag, 0, format);
  128. return 0;
  129. }
  130. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  131. struct hda_codec *codec,
  132. struct snd_pcm_substream *substream)
  133. {
  134. struct conexant_spec *spec = codec->spec;
  135. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  136. 0, 0, 0);
  137. return 0;
  138. }
  139. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  140. .substreams = 1,
  141. .channels_min = 2,
  142. .channels_max = 2,
  143. .nid = 0, /* fill later */
  144. .ops = {
  145. .open = conexant_playback_pcm_open,
  146. .prepare = conexant_playback_pcm_prepare,
  147. .cleanup = conexant_playback_pcm_cleanup
  148. },
  149. };
  150. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  151. .substreams = 1,
  152. .channels_min = 2,
  153. .channels_max = 2,
  154. .nid = 0, /* fill later */
  155. .ops = {
  156. .prepare = conexant_capture_pcm_prepare,
  157. .cleanup = conexant_capture_pcm_cleanup
  158. },
  159. };
  160. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  161. .substreams = 1,
  162. .channels_min = 2,
  163. .channels_max = 2,
  164. .nid = 0, /* fill later */
  165. .ops = {
  166. .open = conexant_dig_playback_pcm_open,
  167. .close = conexant_dig_playback_pcm_close
  168. },
  169. };
  170. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  171. .substreams = 1,
  172. .channels_min = 2,
  173. .channels_max = 2,
  174. /* NID is set in alc_build_pcms */
  175. };
  176. static int conexant_build_pcms(struct hda_codec *codec)
  177. {
  178. struct conexant_spec *spec = codec->spec;
  179. struct hda_pcm *info = spec->pcm_rec;
  180. codec->num_pcms = 1;
  181. codec->pcm_info = info;
  182. info->name = "CONEXANT Analog";
  183. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  184. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  185. spec->multiout.max_channels;
  186. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  187. spec->multiout.dac_nids[0];
  188. info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
  189. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  190. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  191. if (spec->multiout.dig_out_nid) {
  192. info++;
  193. codec->num_pcms++;
  194. info->name = "Conexant Digital";
  195. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  196. conexant_pcm_digital_playback;
  197. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  198. spec->multiout.dig_out_nid;
  199. if (spec->dig_in_nid) {
  200. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  201. conexant_pcm_digital_capture;
  202. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  203. spec->dig_in_nid;
  204. }
  205. }
  206. return 0;
  207. }
  208. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  209. struct snd_ctl_elem_info *uinfo)
  210. {
  211. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  212. struct conexant_spec *spec = codec->spec;
  213. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  214. }
  215. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  216. struct snd_ctl_elem_value *ucontrol)
  217. {
  218. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  219. struct conexant_spec *spec = codec->spec;
  220. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  221. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  222. return 0;
  223. }
  224. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  225. struct snd_ctl_elem_value *ucontrol)
  226. {
  227. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  228. struct conexant_spec *spec = codec->spec;
  229. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  230. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  231. spec->capsrc_nids[adc_idx],
  232. &spec->cur_mux[adc_idx]);
  233. }
  234. static int conexant_init(struct hda_codec *codec)
  235. {
  236. struct conexant_spec *spec = codec->spec;
  237. int i;
  238. for (i = 0; i < spec->num_init_verbs; i++)
  239. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  240. return 0;
  241. }
  242. static void conexant_free(struct hda_codec *codec)
  243. {
  244. struct conexant_spec *spec = codec->spec;
  245. unsigned int i;
  246. if (spec->kctl_alloc) {
  247. for (i = 0; i < spec->num_kctl_used; i++)
  248. kfree(spec->kctl_alloc[i].name);
  249. kfree(spec->kctl_alloc);
  250. }
  251. kfree(codec->spec);
  252. }
  253. #ifdef CONFIG_PM
  254. static int conexant_resume(struct hda_codec *codec)
  255. {
  256. struct conexant_spec *spec = codec->spec;
  257. int i;
  258. codec->patch_ops.init(codec);
  259. for (i = 0; i < spec->num_mixers; i++)
  260. snd_hda_resume_ctls(codec, spec->mixers[i]);
  261. if (spec->multiout.dig_out_nid)
  262. snd_hda_resume_spdif_out(codec);
  263. if (spec->dig_in_nid)
  264. snd_hda_resume_spdif_in(codec);
  265. return 0;
  266. }
  267. #endif
  268. static int conexant_build_controls(struct hda_codec *codec)
  269. {
  270. struct conexant_spec *spec = codec->spec;
  271. unsigned int i;
  272. int err;
  273. for (i = 0; i < spec->num_mixers; i++) {
  274. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  275. if (err < 0)
  276. return err;
  277. }
  278. if (spec->multiout.dig_out_nid) {
  279. err = snd_hda_create_spdif_out_ctls(codec,
  280. spec->multiout.dig_out_nid);
  281. if (err < 0)
  282. return err;
  283. }
  284. if (spec->dig_in_nid) {
  285. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  286. if (err < 0)
  287. return err;
  288. }
  289. return 0;
  290. }
  291. static struct hda_codec_ops conexant_patch_ops = {
  292. .build_controls = conexant_build_controls,
  293. .build_pcms = conexant_build_pcms,
  294. .init = conexant_init,
  295. .free = conexant_free,
  296. #ifdef CONFIG_PM
  297. .resume = conexant_resume,
  298. #endif
  299. };
  300. /*
  301. * EAPD control
  302. * the private value = nid | (invert << 8)
  303. */
  304. static int conexant_eapd_info(struct snd_kcontrol *kcontrol,
  305. struct snd_ctl_elem_info *uinfo)
  306. {
  307. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  308. uinfo->count = 1;
  309. uinfo->value.integer.min = 0;
  310. uinfo->value.integer.max = 1;
  311. return 0;
  312. }
  313. static int conexant_eapd_get(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_value *ucontrol)
  315. {
  316. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  317. struct conexant_spec *spec = codec->spec;
  318. int invert = (kcontrol->private_value >> 8) & 1;
  319. if (invert)
  320. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  321. else
  322. ucontrol->value.integer.value[0] = spec->cur_eapd;
  323. return 0;
  324. }
  325. static int conexant_eapd_put(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_value *ucontrol)
  327. {
  328. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  329. struct conexant_spec *spec = codec->spec;
  330. int invert = (kcontrol->private_value >> 8) & 1;
  331. hda_nid_t nid = kcontrol->private_value & 0xff;
  332. unsigned int eapd;
  333. eapd = ucontrol->value.integer.value[0];
  334. if (invert)
  335. eapd = !eapd;
  336. if (eapd == spec->cur_eapd && !codec->in_resume)
  337. return 0;
  338. spec->cur_eapd = eapd;
  339. snd_hda_codec_write(codec, nid,
  340. 0, AC_VERB_SET_EAPD_BTLENABLE,
  341. eapd ? 0x02 : 0x00);
  342. return 1;
  343. }
  344. /* controls for test mode */
  345. #ifdef CONFIG_SND_DEBUG
  346. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  347. struct snd_ctl_elem_info *uinfo)
  348. {
  349. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  350. struct conexant_spec *spec = codec->spec;
  351. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  352. spec->num_channel_mode);
  353. }
  354. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  355. struct snd_ctl_elem_value *ucontrol)
  356. {
  357. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  358. struct conexant_spec *spec = codec->spec;
  359. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  360. spec->num_channel_mode,
  361. spec->multiout.max_channels);
  362. }
  363. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_value *ucontrol)
  365. {
  366. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  367. struct conexant_spec *spec = codec->spec;
  368. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  369. spec->num_channel_mode,
  370. &spec->multiout.max_channels);
  371. if (err >= 0 && spec->need_dac_fix)
  372. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  373. return err;
  374. }
  375. #define CXT_PIN_MODE(xname, nid, dir) \
  376. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  377. .info = conexant_ch_mode_info, \
  378. .get = conexant_ch_mode_get, \
  379. .put = conexant_ch_mode_put, \
  380. .private_value = nid | (dir<<16) }
  381. static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol,
  382. struct snd_ctl_elem_info *uinfo)
  383. {
  384. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  385. uinfo->count = 1;
  386. uinfo->value.integer.min = 0;
  387. uinfo->value.integer.max = 1;
  388. return 0;
  389. }
  390. static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol,
  391. struct snd_ctl_elem_value *ucontrol)
  392. {
  393. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  394. hda_nid_t nid = kcontrol->private_value & 0xffff;
  395. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  396. long *valp = ucontrol->value.integer.value;
  397. unsigned int val = snd_hda_codec_read(codec, nid, 0,
  398. AC_VERB_GET_GPIO_DATA, 0x00);
  399. *valp = (val & mask) != 0;
  400. return 0;
  401. }
  402. static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol,
  403. struct snd_ctl_elem_value *ucontrol)
  404. {
  405. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  406. hda_nid_t nid = kcontrol->private_value & 0xffff;
  407. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  408. long val = *ucontrol->value.integer.value;
  409. unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
  410. AC_VERB_GET_GPIO_DATA,
  411. 0x00);
  412. unsigned int old_data = gpio_data;
  413. /* Set/unset the masked GPIO bit(s) as needed */
  414. if (val == 0)
  415. gpio_data &= ~mask;
  416. else
  417. gpio_data |= mask;
  418. if (gpio_data == old_data && !codec->in_resume)
  419. return 0;
  420. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
  421. return 1;
  422. }
  423. #define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \
  424. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  425. .info = cxt_gpio_data_info, \
  426. .get = cxt_gpio_data_get, \
  427. .put = cxt_gpio_data_put, \
  428. .private_value = nid | (mask<<16) }
  429. static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
  430. struct snd_ctl_elem_info *uinfo)
  431. {
  432. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  433. uinfo->count = 1;
  434. uinfo->value.integer.min = 0;
  435. uinfo->value.integer.max = 1;
  436. return 0;
  437. }
  438. static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
  439. struct snd_ctl_elem_value *ucontrol)
  440. {
  441. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  442. hda_nid_t nid = kcontrol->private_value & 0xffff;
  443. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  444. long *valp = ucontrol->value.integer.value;
  445. unsigned int val = snd_hda_codec_read(codec, nid, 0,
  446. AC_VERB_GET_DIGI_CONVERT, 0x00);
  447. *valp = (val & mask) != 0;
  448. return 0;
  449. }
  450. static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
  451. struct snd_ctl_elem_value *ucontrol)
  452. {
  453. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  454. hda_nid_t nid = kcontrol->private_value & 0xffff;
  455. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  456. long val = *ucontrol->value.integer.value;
  457. unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
  458. AC_VERB_GET_DIGI_CONVERT,
  459. 0x00);
  460. unsigned int old_data = ctrl_data;
  461. /* Set/unset the masked control bit(s) as needed */
  462. if (val == 0)
  463. ctrl_data &= ~mask;
  464. else
  465. ctrl_data |= mask;
  466. if (ctrl_data == old_data && !codec->in_resume)
  467. return 0;
  468. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
  469. ctrl_data);
  470. return 1;
  471. }
  472. #define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \
  473. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  474. .info = cxt_spdif_ctrl_info, \
  475. .get = cxt_spdif_ctrl_get, \
  476. .put = cxt_spdif_ctrl_put, \
  477. .private_value = nid | (mask<<16) }
  478. #endif /* CONFIG_SND_DEBUG */
  479. /* Conexant 5045 specific */
  480. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  481. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  482. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  483. #define CXT5045_SPDIF_OUT 0x13
  484. static struct hda_channel_mode cxt5045_modes[1] = {
  485. { 2, NULL },
  486. };
  487. static struct hda_input_mux cxt5045_capture_source = {
  488. .num_items = 2,
  489. .items = {
  490. { "ExtMic", 0x1 },
  491. { "LineIn", 0x2 },
  492. }
  493. };
  494. /* turn on/off EAPD (+ mute HP) as a master switch */
  495. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  496. struct snd_ctl_elem_value *ucontrol)
  497. {
  498. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  499. struct conexant_spec *spec = codec->spec;
  500. if (!conexant_eapd_put(kcontrol, ucontrol))
  501. return 0;
  502. /* toggle HP mute appropriately */
  503. snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
  504. 0x80, spec->cur_eapd ? 0 : 0x80);
  505. snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
  506. 0x80, spec->cur_eapd ? 0 : 0x80);
  507. return 1;
  508. }
  509. /* bind volumes of both NID 0x10 and 0x11 */
  510. static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  511. struct snd_ctl_elem_value *ucontrol)
  512. {
  513. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  514. long *valp = ucontrol->value.integer.value;
  515. int change;
  516. change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
  517. 0x7f, valp[0] & 0x7f);
  518. change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
  519. 0x7f, valp[1] & 0x7f);
  520. snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
  521. 0x7f, valp[0] & 0x7f);
  522. snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
  523. 0x7f, valp[1] & 0x7f);
  524. return change;
  525. }
  526. /* mute internal speaker if HP is plugged */
  527. static void cxt5045_hp_automute(struct hda_codec *codec)
  528. {
  529. unsigned int present;
  530. present = snd_hda_codec_read(codec, 0x11, 0,
  531. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  532. snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
  533. 0x80, present ? 0x80 : 0);
  534. snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
  535. 0x80, present ? 0x80 : 0);
  536. }
  537. /* unsolicited event for HP jack sensing */
  538. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  539. unsigned int res)
  540. {
  541. res >>= 26;
  542. switch (res) {
  543. case CONEXANT_HP_EVENT:
  544. cxt5045_hp_automute(codec);
  545. break;
  546. }
  547. }
  548. static struct snd_kcontrol_new cxt5045_mixers[] = {
  549. {
  550. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  551. .name = "Capture Source",
  552. .info = conexant_mux_enum_info,
  553. .get = conexant_mux_enum_get,
  554. .put = conexant_mux_enum_put
  555. },
  556. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x17, 0x02, HDA_INPUT),
  557. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x17, 0x02, HDA_INPUT),
  558. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x02, HDA_INPUT),
  559. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x02, HDA_INPUT),
  560. {
  561. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  562. .name = "Master Playback Volume",
  563. .info = snd_hda_mixer_amp_volume_info,
  564. .get = snd_hda_mixer_amp_volume_get,
  565. .put = cxt5045_hp_master_vol_put,
  566. .private_value = HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  567. },
  568. {
  569. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  570. .name = "Master Playback Switch",
  571. .info = conexant_eapd_info,
  572. .get = conexant_eapd_get,
  573. .put = cxt5045_hp_master_sw_put,
  574. .private_value = 0x11,
  575. },
  576. {}
  577. };
  578. static struct hda_verb cxt5045_init_verbs[] = {
  579. /* Line in, Mic */
  580. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  581. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  582. /* HP, Amp */
  583. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  584. {0x1A, AC_VERB_SET_CONNECT_SEL,0x01},
  585. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  586. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  587. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  588. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  589. /* Record selector: Front mic */
  590. {0x14, AC_VERB_SET_CONNECT_SEL,0x03},
  591. {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
  592. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  593. /* SPDIF route: PCM */
  594. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  595. /* pin sensing on HP and Mic jacks */
  596. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  597. /* EAPD */
  598. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  599. { } /* end */
  600. };
  601. #ifdef CONFIG_SND_DEBUG
  602. /* Test configuration for debugging, modelled after the ALC260 test
  603. * configuration.
  604. */
  605. static struct hda_input_mux cxt5045_test_capture_source = {
  606. .num_items = 5,
  607. .items = {
  608. { "MIXER", 0x0 },
  609. { "MIC1 pin", 0x1 },
  610. { "LINE1 pin", 0x2 },
  611. { "HP-OUT pin", 0x3 },
  612. { "CD pin", 0x4 },
  613. },
  614. };
  615. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  616. /* Output controls */
  617. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x19, 0x00, HDA_OUTPUT),
  618. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x19,0x00, HDA_OUTPUT),
  619. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  620. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  621. /* Modes for retasking pin widgets */
  622. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  623. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  624. /* Loopback mixer controls */
  625. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT),
  626. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT),
  627. HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT),
  628. HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT),
  629. HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT),
  630. HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT),
  631. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT),
  632. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT),
  633. /* Controls for GPIO pins, assuming they exist and are configured as outputs */
  634. CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
  635. #if 0 /* limit this to one GPIO pin for now */
  636. CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
  637. CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
  638. CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
  639. #endif
  640. CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x13, 0x01),
  641. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_OUTPUT),
  642. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_OUTPUT),
  643. {
  644. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  645. .name = "Input Source",
  646. .info = conexant_mux_enum_info,
  647. .get = conexant_mux_enum_get,
  648. .put = conexant_mux_enum_put,
  649. },
  650. { } /* end */
  651. };
  652. static struct hda_verb cxt5045_test_init_verbs[] = {
  653. /* Enable all GPIOs as outputs with an initial value of 0 */
  654. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
  655. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  656. {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
  657. /* Enable retasking pins as output, initially without power amp */
  658. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  659. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  660. /* Disable digital (SPDIF) pins initially, but users can enable
  661. * them via a mixer switch. In the case of SPDIF-out, this initverb
  662. * payload also sets the generation to 0, output to be in "consumer"
  663. * PCM format, copyright asserted, no pre-emphasis and no validity
  664. * control.
  665. */
  666. {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
  667. /* Start with output sum widgets muted and their output gains at min */
  668. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  669. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  670. /* Unmute retasking pin widget output buffers since the default
  671. * state appears to be output. As the pin mode is changed by the
  672. * user the pin mode control will take care of enabling the pin's
  673. * input/output buffers as needed.
  674. */
  675. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  676. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  677. /* Mute capture amp left and right */
  678. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  679. /* Set ADC connection select to match default mixer setting (mic1
  680. * pin)
  681. */
  682. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  683. /* Mute all inputs to mixer widget (even unconnected ones) */
  684. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  685. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  686. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  687. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  688. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  689. { }
  690. };
  691. #endif
  692. /* initialize jack-sensing, too */
  693. static int cxt5045_init(struct hda_codec *codec)
  694. {
  695. conexant_init(codec);
  696. cxt5045_hp_automute(codec);
  697. return 0;
  698. }
  699. enum {
  700. CXT5045_LAPTOP, /* Laptops w/ EAPD support */
  701. #ifdef CONFIG_SND_DEBUG
  702. CXT5045_TEST,
  703. #endif
  704. CXT5045_MODELS
  705. };
  706. static const char *cxt5045_models[CXT5045_MODELS] = {
  707. [CXT5045_LAPTOP] = "laptop",
  708. #ifdef CONFIG_SND_DEBUG
  709. [CXT5045_TEST] = "test",
  710. #endif
  711. };
  712. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  713. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
  714. {}
  715. };
  716. static int patch_cxt5045(struct hda_codec *codec)
  717. {
  718. struct conexant_spec *spec;
  719. int board_config;
  720. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  721. if (!spec)
  722. return -ENOMEM;
  723. mutex_init(&spec->amp_mutex);
  724. codec->spec = spec;
  725. spec->multiout.max_channels = 2;
  726. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  727. spec->multiout.dac_nids = cxt5045_dac_nids;
  728. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  729. spec->num_adc_nids = 1;
  730. spec->adc_nids = cxt5045_adc_nids;
  731. spec->capsrc_nids = cxt5045_capsrc_nids;
  732. spec->input_mux = &cxt5045_capture_source;
  733. spec->num_mixers = 1;
  734. spec->mixers[0] = cxt5045_mixers;
  735. spec->num_init_verbs = 1;
  736. spec->init_verbs[0] = cxt5045_init_verbs;
  737. spec->spdif_route = 0;
  738. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  739. spec->channel_mode = cxt5045_modes,
  740. codec->patch_ops = conexant_patch_ops;
  741. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  742. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  743. cxt5045_models,
  744. cxt5045_cfg_tbl);
  745. switch (board_config) {
  746. case CXT5045_LAPTOP:
  747. spec->input_mux = &cxt5045_capture_source;
  748. spec->num_init_verbs = 2;
  749. spec->init_verbs[1] = cxt5045_init_verbs;
  750. spec->mixers[0] = cxt5045_mixers;
  751. codec->patch_ops.init = cxt5045_init;
  752. break;
  753. #ifdef CONFIG_SND_DEBUG
  754. case CXT5045_TEST:
  755. spec->input_mux = &cxt5045_test_capture_source;
  756. spec->mixers[0] = cxt5045_test_mixer;
  757. spec->init_verbs[0] = cxt5045_test_init_verbs;
  758. #endif
  759. }
  760. return 0;
  761. }
  762. /* Conexant 5047 specific */
  763. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 };
  764. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  765. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  766. #define CXT5047_SPDIF_OUT 0x11
  767. static struct hda_channel_mode cxt5047_modes[1] = {
  768. { 2, NULL },
  769. };
  770. static struct hda_input_mux cxt5047_capture_source = {
  771. .num_items = 2,
  772. .items = {
  773. { "ExtMic", 0x1 },
  774. { "IntMic", 0x2 },
  775. }
  776. };
  777. static struct hda_input_mux cxt5047_hp_capture_source = {
  778. .num_items = 1,
  779. .items = {
  780. { "ExtMic", 0x1 },
  781. }
  782. };
  783. /* turn on/off EAPD (+ mute HP) as a master switch */
  784. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  785. struct snd_ctl_elem_value *ucontrol)
  786. {
  787. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  788. struct conexant_spec *spec = codec->spec;
  789. if (!conexant_eapd_put(kcontrol, ucontrol))
  790. return 0;
  791. /* toggle HP mute appropriately */
  792. snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
  793. 0x80, spec->cur_eapd ? 0 : 0x80);
  794. snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
  795. 0x80, spec->cur_eapd ? 0 : 0x80);
  796. return 1;
  797. }
  798. #if 0
  799. /* bind volumes of both NID 0x13 and 0x1d */
  800. static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  801. struct snd_ctl_elem_value *ucontrol)
  802. {
  803. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  804. long *valp = ucontrol->value.integer.value;
  805. int change;
  806. change = snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0,
  807. 0x7f, valp[0] & 0x7f);
  808. change |= snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0,
  809. 0x7f, valp[1] & 0x7f);
  810. snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
  811. 0x7f, valp[0] & 0x7f);
  812. snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
  813. 0x7f, valp[1] & 0x7f);
  814. return change;
  815. }
  816. #endif
  817. /* mute internal speaker if HP is plugged */
  818. static void cxt5047_hp_automute(struct hda_codec *codec)
  819. {
  820. unsigned int present;
  821. present = snd_hda_codec_read(codec, 0x13, 0,
  822. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  823. snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0,
  824. 0x80, present ? 0x80 : 0);
  825. snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0,
  826. 0x80, present ? 0x80 : 0);
  827. }
  828. /* toggle input of built-in and mic jack appropriately */
  829. static void cxt5047_hp_automic(struct hda_codec *codec)
  830. {
  831. static struct hda_verb mic_jack_on[] = {
  832. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  833. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  834. {}
  835. };
  836. static struct hda_verb mic_jack_off[] = {
  837. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  838. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  839. {}
  840. };
  841. unsigned int present;
  842. present = snd_hda_codec_read(codec, 0x08, 0,
  843. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  844. if (present)
  845. snd_hda_sequence_write(codec, mic_jack_on);
  846. else
  847. snd_hda_sequence_write(codec, mic_jack_off);
  848. }
  849. /* unsolicited event for HP jack sensing */
  850. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  851. unsigned int res)
  852. {
  853. res >>= 26;
  854. switch (res) {
  855. case CONEXANT_HP_EVENT:
  856. cxt5047_hp_automute(codec);
  857. break;
  858. case CONEXANT_MIC_EVENT:
  859. cxt5047_hp_automic(codec);
  860. break;
  861. }
  862. }
  863. static struct snd_kcontrol_new cxt5047_mixers[] = {
  864. {
  865. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  866. .name = "Capture Source",
  867. .info = conexant_mux_enum_info,
  868. .get = conexant_mux_enum_get,
  869. .put = conexant_mux_enum_put
  870. },
  871. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  872. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  873. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  874. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  875. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  876. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  877. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  878. {
  879. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  880. .name = "Master Playback Switch",
  881. .info = conexant_eapd_info,
  882. .get = conexant_eapd_get,
  883. .put = cxt5047_hp_master_sw_put,
  884. .private_value = 0x13,
  885. },
  886. {}
  887. };
  888. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  889. {
  890. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  891. .name = "Capture Source",
  892. .info = conexant_mux_enum_info,
  893. .get = conexant_mux_enum_get,
  894. .put = conexant_mux_enum_put
  895. },
  896. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  897. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  898. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  899. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  900. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  901. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  902. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  903. {
  904. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  905. .name = "Master Playback Switch",
  906. .info = conexant_eapd_info,
  907. .get = conexant_eapd_get,
  908. .put = cxt5047_hp_master_sw_put,
  909. .private_value = 0x13,
  910. },
  911. { } /* end */
  912. };
  913. static struct hda_verb cxt5047_init_verbs[] = {
  914. /* Line in, Mic, Built-in Mic */
  915. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  916. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  917. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  918. /* HP, Amp */
  919. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  920. {0x1A, AC_VERB_SET_CONNECT_SEL,0x03},
  921. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  922. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  923. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  924. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  925. /* Record selector: Front mic */
  926. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  927. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  928. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  929. /* SPDIF route: PCM */
  930. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  931. { } /* end */
  932. };
  933. /* configuration for Toshiba Laptops */
  934. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  935. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  936. /* pin sensing on HP and Mic jacks */
  937. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  938. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  939. {}
  940. };
  941. /* configuration for HP Laptops */
  942. static struct hda_verb cxt5047_hp_init_verbs[] = {
  943. /* pin sensing on HP and Mic jacks */
  944. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  945. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  946. {}
  947. };
  948. /* Test configuration for debugging, modelled after the ALC260 test
  949. * configuration.
  950. */
  951. #ifdef CONFIG_SND_DEBUG
  952. static struct hda_input_mux cxt5047_test_capture_source = {
  953. .num_items = 5,
  954. .items = {
  955. { "MIXER", 0x0 },
  956. { "LINE1 pin", 0x1 },
  957. { "MIC1 pin", 0x2 },
  958. { "MIC2 pin", 0x3 },
  959. { "CD pin", 0x4 },
  960. },
  961. };
  962. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  963. /* Output only controls */
  964. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x00, HDA_OUTPUT),
  965. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x00, HDA_OUTPUT),
  966. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  967. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  968. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  969. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  970. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  971. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  972. /* Modes for retasking pin widgets */
  973. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  974. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  975. /* Loopback mixer controls */
  976. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x19, 0x02, HDA_INPUT),
  977. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x19, 0x02, HDA_INPUT),
  978. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x19, 0x03, HDA_INPUT),
  979. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x19, 0x03, HDA_INPUT),
  980. HDA_CODEC_VOLUME("LINE Playback Volume", 0x19, 0x01, HDA_INPUT),
  981. HDA_CODEC_MUTE("LINE Playback Switch", 0x19, 0x01, HDA_INPUT),
  982. HDA_CODEC_VOLUME("CD Playback Volume", 0x19, 0x04, HDA_INPUT),
  983. HDA_CODEC_MUTE("CD Playback Switch", 0x19, 0x04, HDA_INPUT),
  984. #if 0
  985. /* Controls for GPIO pins, assuming they exist and are configured as outputs */
  986. CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
  987. CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
  988. CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
  989. CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
  990. #endif
  991. CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x18, 0x01),
  992. HDA_CODEC_VOLUME("Capture Volume", 0x19, 0x0, HDA_OUTPUT),
  993. HDA_CODEC_MUTE("Capture Switch", 0x19, 0x0, HDA_OUTPUT),
  994. {
  995. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  996. .name = "Input Source",
  997. .info = conexant_mux_enum_info,
  998. .get = conexant_mux_enum_get,
  999. .put = conexant_mux_enum_put,
  1000. },
  1001. { } /* end */
  1002. };
  1003. static struct hda_verb cxt5047_test_init_verbs[] = {
  1004. /* Enable all GPIOs as outputs with an initial value of 0 */
  1005. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
  1006. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  1007. {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
  1008. /* Enable retasking pins as output, initially without power amp */
  1009. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1010. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1011. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1012. /* Disable digital (SPDIF) pins initially, but users can enable
  1013. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1014. * payload also sets the generation to 0, output to be in "consumer"
  1015. * PCM format, copyright asserted, no pre-emphasis and no validity
  1016. * control.
  1017. */
  1018. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1019. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1020. * OUT1 sum bus when acting as an output.
  1021. */
  1022. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1023. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1024. /* Start with output sum widgets muted and their output gains at min */
  1025. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1026. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1027. /* Unmute retasking pin widget output buffers since the default
  1028. * state appears to be output. As the pin mode is changed by the
  1029. * user the pin mode control will take care of enabling the pin's
  1030. * input/output buffers as needed.
  1031. */
  1032. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1033. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1034. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1035. /* Mute capture amp left and right */
  1036. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1037. /* Set ADC connection select to match default mixer setting (mic1
  1038. * pin)
  1039. */
  1040. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1041. /* Mute all inputs to mixer widget (even unconnected ones) */
  1042. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1043. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1044. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1045. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1046. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1047. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1048. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1049. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1050. { }
  1051. };
  1052. #endif
  1053. /* initialize jack-sensing, too */
  1054. static int cxt5047_hp_init(struct hda_codec *codec)
  1055. {
  1056. conexant_init(codec);
  1057. cxt5047_hp_automute(codec);
  1058. cxt5047_hp_automic(codec);
  1059. return 0;
  1060. }
  1061. enum {
  1062. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1063. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1064. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1065. #ifdef CONFIG_SND_DEBUG
  1066. CXT5047_TEST,
  1067. #endif
  1068. CXT5047_MODELS
  1069. };
  1070. static const char *cxt5047_models[CXT5047_MODELS] = {
  1071. [CXT5047_LAPTOP] = "laptop",
  1072. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1073. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1074. #ifdef CONFIG_SND_DEBUG
  1075. [CXT5047_TEST] = "test",
  1076. #endif
  1077. };
  1078. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1079. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1080. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1081. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1082. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1083. {}
  1084. };
  1085. static int patch_cxt5047(struct hda_codec *codec)
  1086. {
  1087. struct conexant_spec *spec;
  1088. int board_config;
  1089. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1090. if (!spec)
  1091. return -ENOMEM;
  1092. mutex_init(&spec->amp_mutex);
  1093. codec->spec = spec;
  1094. spec->multiout.max_channels = 2;
  1095. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1096. spec->multiout.dac_nids = cxt5047_dac_nids;
  1097. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1098. spec->num_adc_nids = 1;
  1099. spec->adc_nids = cxt5047_adc_nids;
  1100. spec->capsrc_nids = cxt5047_capsrc_nids;
  1101. spec->input_mux = &cxt5047_capture_source;
  1102. spec->num_mixers = 1;
  1103. spec->mixers[0] = cxt5047_mixers;
  1104. spec->num_init_verbs = 1;
  1105. spec->init_verbs[0] = cxt5047_init_verbs;
  1106. spec->spdif_route = 0;
  1107. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1108. spec->channel_mode = cxt5047_modes,
  1109. codec->patch_ops = conexant_patch_ops;
  1110. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1111. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1112. cxt5047_models,
  1113. cxt5047_cfg_tbl);
  1114. switch (board_config) {
  1115. case CXT5047_LAPTOP:
  1116. break;
  1117. case CXT5047_LAPTOP_HP:
  1118. spec->input_mux = &cxt5047_hp_capture_source;
  1119. spec->num_init_verbs = 2;
  1120. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1121. spec->mixers[0] = cxt5047_hp_mixers;
  1122. codec->patch_ops.init = cxt5047_hp_init;
  1123. break;
  1124. case CXT5047_LAPTOP_EAPD:
  1125. spec->num_init_verbs = 2;
  1126. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1127. break;
  1128. #ifdef CONFIG_SND_DEBUG
  1129. case CXT5047_TEST:
  1130. spec->input_mux = &cxt5047_test_capture_source;
  1131. spec->mixers[0] = cxt5047_test_mixer;
  1132. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1133. #endif
  1134. }
  1135. return 0;
  1136. }
  1137. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1138. { .id = 0x14f15045, .name = "CXT5045", .patch = patch_cxt5045 },
  1139. { .id = 0x14f15047, .name = "CXT5047", .patch = patch_cxt5047 },
  1140. {} /* terminator */
  1141. };