patch_conexant.c 42 KB

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