patch_conexant.c 43 KB

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