patch_conexant.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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. { } /* end */
  610. };
  611. static struct hda_verb cxt5045_test_init_verbs[] = {
  612. /* Set connections */
  613. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  614. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  615. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  616. /* Enable retasking pins as output, initially without power amp */
  617. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  618. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  619. /* Disable digital (SPDIF) pins initially, but users can enable
  620. * them via a mixer switch. In the case of SPDIF-out, this initverb
  621. * payload also sets the generation to 0, output to be in "consumer"
  622. * PCM format, copyright asserted, no pre-emphasis and no validity
  623. * control.
  624. */
  625. {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
  626. /* Start with output sum widgets muted and their output gains at min */
  627. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  628. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  629. /* Unmute retasking pin widget output buffers since the default
  630. * state appears to be output. As the pin mode is changed by the
  631. * user the pin mode control will take care of enabling the pin's
  632. * input/output buffers as needed.
  633. */
  634. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  635. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  636. /* Mute capture amp left and right */
  637. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  638. /* Set ADC connection select to match default mixer setting (mic1
  639. * pin)
  640. */
  641. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  642. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  643. /* Mute all inputs to mixer widget (even unconnected ones) */
  644. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  645. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  646. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  647. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  648. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  649. { }
  650. };
  651. #endif
  652. /* initialize jack-sensing, too */
  653. static int cxt5045_init(struct hda_codec *codec)
  654. {
  655. conexant_init(codec);
  656. cxt5045_hp_automute(codec);
  657. return 0;
  658. }
  659. enum {
  660. CXT5045_LAPTOP, /* Laptops w/ EAPD support */
  661. CXT5045_FUJITSU, /* Laptops w/ EAPD support */
  662. #ifdef CONFIG_SND_DEBUG
  663. CXT5045_TEST,
  664. #endif
  665. CXT5045_MODELS
  666. };
  667. static const char *cxt5045_models[CXT5045_MODELS] = {
  668. [CXT5045_LAPTOP] = "laptop",
  669. [CXT5045_FUJITSU] = "fujitsu",
  670. #ifdef CONFIG_SND_DEBUG
  671. [CXT5045_TEST] = "test",
  672. #endif
  673. };
  674. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  675. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
  676. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
  677. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
  678. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
  679. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
  680. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
  681. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
  682. {}
  683. };
  684. static int patch_cxt5045(struct hda_codec *codec)
  685. {
  686. struct conexant_spec *spec;
  687. int board_config;
  688. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  689. if (!spec)
  690. return -ENOMEM;
  691. mutex_init(&spec->amp_mutex);
  692. codec->spec = spec;
  693. spec->multiout.max_channels = 2;
  694. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  695. spec->multiout.dac_nids = cxt5045_dac_nids;
  696. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  697. spec->num_adc_nids = 1;
  698. spec->adc_nids = cxt5045_adc_nids;
  699. spec->capsrc_nids = cxt5045_capsrc_nids;
  700. spec->input_mux = &cxt5045_capture_source;
  701. spec->num_mixers = 1;
  702. spec->mixers[0] = cxt5045_mixers;
  703. spec->num_init_verbs = 1;
  704. spec->init_verbs[0] = cxt5045_init_verbs;
  705. spec->spdif_route = 0;
  706. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  707. spec->channel_mode = cxt5045_modes,
  708. codec->patch_ops = conexant_patch_ops;
  709. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  710. cxt5045_models,
  711. cxt5045_cfg_tbl);
  712. switch (board_config) {
  713. case CXT5045_LAPTOP:
  714. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  715. spec->input_mux = &cxt5045_capture_source;
  716. spec->num_init_verbs = 2;
  717. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  718. spec->mixers[0] = cxt5045_mixers;
  719. codec->patch_ops.init = cxt5045_init;
  720. break;
  721. case CXT5045_FUJITSU:
  722. spec->input_mux = &cxt5045_capture_source;
  723. spec->num_init_verbs = 2;
  724. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  725. spec->mixers[0] = cxt5045_mixers;
  726. codec->patch_ops.init = cxt5045_init;
  727. break;
  728. #ifdef CONFIG_SND_DEBUG
  729. case CXT5045_TEST:
  730. spec->input_mux = &cxt5045_test_capture_source;
  731. spec->mixers[0] = cxt5045_test_mixer;
  732. spec->init_verbs[0] = cxt5045_test_init_verbs;
  733. #endif
  734. }
  735. return 0;
  736. }
  737. /* Conexant 5047 specific */
  738. #define CXT5047_SPDIF_OUT 0x11
  739. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  740. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  741. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  742. static struct hda_channel_mode cxt5047_modes[1] = {
  743. { 2, NULL },
  744. };
  745. static struct hda_input_mux cxt5047_capture_source = {
  746. .num_items = 1,
  747. .items = {
  748. { "Mic", 0x2 },
  749. }
  750. };
  751. static struct hda_input_mux cxt5047_hp_capture_source = {
  752. .num_items = 1,
  753. .items = {
  754. { "ExtMic", 0x2 },
  755. }
  756. };
  757. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  758. .num_items = 2,
  759. .items = {
  760. { "ExtMic", 0x2 },
  761. { "Line-In", 0x1 },
  762. }
  763. };
  764. /* turn on/off EAPD (+ mute HP) as a master switch */
  765. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  766. struct snd_ctl_elem_value *ucontrol)
  767. {
  768. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  769. struct conexant_spec *spec = codec->spec;
  770. unsigned int bits;
  771. if (!cxt_eapd_put(kcontrol, ucontrol))
  772. return 0;
  773. /* toggle internal speakers mute depending of presence of
  774. * the headphone jack
  775. */
  776. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
  777. snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
  778. snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
  779. bits = spec->cur_eapd ? 0 : 0x80;
  780. snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 0x80, bits);
  781. snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 0x80, bits);
  782. return 1;
  783. }
  784. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  785. static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  786. struct snd_ctl_elem_value *ucontrol)
  787. {
  788. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  789. long *valp = ucontrol->value.integer.value;
  790. int change;
  791. change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
  792. 0x7f, valp[0] & 0x7f);
  793. change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
  794. 0x7f, valp[1] & 0x7f);
  795. snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
  796. 0x7f, valp[0] & 0x7f);
  797. snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
  798. 0x7f, valp[1] & 0x7f);
  799. return change;
  800. }
  801. /* mute internal speaker if HP is plugged */
  802. static void cxt5047_hp_automute(struct hda_codec *codec)
  803. {
  804. struct conexant_spec *spec = codec->spec;
  805. unsigned int bits;
  806. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  807. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  808. bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
  809. snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
  810. snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
  811. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  812. snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
  813. snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
  814. }
  815. /* toggle input of built-in and mic jack appropriately */
  816. static void cxt5047_hp_automic(struct hda_codec *codec)
  817. {
  818. static struct hda_verb mic_jack_on[] = {
  819. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  820. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  821. {}
  822. };
  823. static struct hda_verb mic_jack_off[] = {
  824. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  825. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  826. {}
  827. };
  828. unsigned int present;
  829. present = snd_hda_codec_read(codec, 0x15, 0,
  830. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  831. if (present)
  832. snd_hda_sequence_write(codec, mic_jack_on);
  833. else
  834. snd_hda_sequence_write(codec, mic_jack_off);
  835. }
  836. /* unsolicited event for HP jack sensing */
  837. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  838. unsigned int res)
  839. {
  840. res >>= 26;
  841. switch (res) {
  842. case CONEXANT_HP_EVENT:
  843. cxt5047_hp_automute(codec);
  844. break;
  845. case CONEXANT_MIC_EVENT:
  846. cxt5047_hp_automic(codec);
  847. break;
  848. }
  849. }
  850. static struct snd_kcontrol_new cxt5047_mixers[] = {
  851. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  852. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  853. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  854. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  855. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  856. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  857. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  858. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  859. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  860. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  861. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  862. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  863. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  864. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  865. {}
  866. };
  867. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  868. {
  869. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  870. .name = "Capture Source",
  871. .info = conexant_mux_enum_info,
  872. .get = conexant_mux_enum_get,
  873. .put = conexant_mux_enum_put
  874. },
  875. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  876. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  877. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  878. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  879. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  880. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  881. {
  882. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  883. .name = "Master Playback Volume",
  884. .info = snd_hda_mixer_amp_volume_info,
  885. .get = snd_hda_mixer_amp_volume_get,
  886. .put = cxt5047_hp_master_vol_put,
  887. .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  888. },
  889. {
  890. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  891. .name = "Master Playback Switch",
  892. .info = cxt_eapd_info,
  893. .get = cxt_eapd_get,
  894. .put = cxt5047_hp_master_sw_put,
  895. .private_value = 0x13,
  896. },
  897. {}
  898. };
  899. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  900. {
  901. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  902. .name = "Capture Source",
  903. .info = conexant_mux_enum_info,
  904. .get = conexant_mux_enum_get,
  905. .put = conexant_mux_enum_put
  906. },
  907. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  908. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  909. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  910. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  911. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  912. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  913. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  914. {
  915. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  916. .name = "Master Playback Switch",
  917. .info = cxt_eapd_info,
  918. .get = cxt_eapd_get,
  919. .put = cxt5047_hp_master_sw_put,
  920. .private_value = 0x13,
  921. },
  922. { } /* end */
  923. };
  924. static struct hda_verb cxt5047_init_verbs[] = {
  925. /* Line in, Mic, Built-in Mic */
  926. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  927. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  928. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  929. /* HP, Speaker */
  930. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  931. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  932. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  933. /* Record selector: Mic */
  934. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  935. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  936. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  937. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  938. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  939. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  940. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  941. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  942. /* SPDIF route: PCM */
  943. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  944. /* Enable unsolicited events */
  945. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  946. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  947. { } /* end */
  948. };
  949. /* configuration for Toshiba Laptops */
  950. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  951. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  952. /* pin sensing on HP and Mic jacks */
  953. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  954. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  955. /* Speaker routing */
  956. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  957. {}
  958. };
  959. /* configuration for HP Laptops */
  960. static struct hda_verb cxt5047_hp_init_verbs[] = {
  961. /* pin sensing on HP jack */
  962. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  963. /* Record selector: Ext Mic */
  964. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  965. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  966. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  967. /* Speaker routing */
  968. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  969. {}
  970. };
  971. /* Test configuration for debugging, modelled after the ALC260 test
  972. * configuration.
  973. */
  974. #ifdef CONFIG_SND_DEBUG
  975. static struct hda_input_mux cxt5047_test_capture_source = {
  976. .num_items = 4,
  977. .items = {
  978. { "LINE1 pin", 0x0 },
  979. { "MIC1 pin", 0x1 },
  980. { "MIC2 pin", 0x2 },
  981. { "CD pin", 0x3 },
  982. },
  983. };
  984. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  985. /* Output only controls */
  986. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  987. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  988. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  989. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  990. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  991. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  992. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  993. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  994. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  995. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  996. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  997. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  998. /* Modes for retasking pin widgets */
  999. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1000. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1001. /* EAPD Switch Control */
  1002. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1003. /* Loopback mixer controls */
  1004. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1005. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1006. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1007. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1008. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1009. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1010. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1011. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1012. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1013. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1014. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1015. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1016. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1017. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1018. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1019. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1020. {
  1021. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1022. .name = "Input Source",
  1023. .info = conexant_mux_enum_info,
  1024. .get = conexant_mux_enum_get,
  1025. .put = conexant_mux_enum_put,
  1026. },
  1027. { } /* end */
  1028. };
  1029. static struct hda_verb cxt5047_test_init_verbs[] = {
  1030. /* Enable retasking pins as output, initially without power amp */
  1031. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1032. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1033. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1034. /* Disable digital (SPDIF) pins initially, but users can enable
  1035. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1036. * payload also sets the generation to 0, output to be in "consumer"
  1037. * PCM format, copyright asserted, no pre-emphasis and no validity
  1038. * control.
  1039. */
  1040. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1041. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1042. * OUT1 sum bus when acting as an output.
  1043. */
  1044. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1045. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1046. /* Start with output sum widgets muted and their output gains at min */
  1047. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1048. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1049. /* Unmute retasking pin widget output buffers since the default
  1050. * state appears to be output. As the pin mode is changed by the
  1051. * user the pin mode control will take care of enabling the pin's
  1052. * input/output buffers as needed.
  1053. */
  1054. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1055. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1056. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1057. /* Mute capture amp left and right */
  1058. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1059. /* Set ADC connection select to match default mixer setting (mic1
  1060. * pin)
  1061. */
  1062. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1063. /* Mute all inputs to mixer widget (even unconnected ones) */
  1064. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1065. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1066. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1067. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1068. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1069. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1070. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1071. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1072. { }
  1073. };
  1074. #endif
  1075. /* initialize jack-sensing, too */
  1076. static int cxt5047_hp_init(struct hda_codec *codec)
  1077. {
  1078. conexant_init(codec);
  1079. cxt5047_hp_automute(codec);
  1080. return 0;
  1081. }
  1082. enum {
  1083. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1084. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1085. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1086. #ifdef CONFIG_SND_DEBUG
  1087. CXT5047_TEST,
  1088. #endif
  1089. CXT5047_MODELS
  1090. };
  1091. static const char *cxt5047_models[CXT5047_MODELS] = {
  1092. [CXT5047_LAPTOP] = "laptop",
  1093. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1094. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1095. #ifdef CONFIG_SND_DEBUG
  1096. [CXT5047_TEST] = "test",
  1097. #endif
  1098. };
  1099. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1100. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1101. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1102. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1103. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1104. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1105. {}
  1106. };
  1107. static int patch_cxt5047(struct hda_codec *codec)
  1108. {
  1109. struct conexant_spec *spec;
  1110. int board_config;
  1111. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1112. if (!spec)
  1113. return -ENOMEM;
  1114. mutex_init(&spec->amp_mutex);
  1115. codec->spec = spec;
  1116. spec->multiout.max_channels = 2;
  1117. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1118. spec->multiout.dac_nids = cxt5047_dac_nids;
  1119. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1120. spec->num_adc_nids = 1;
  1121. spec->adc_nids = cxt5047_adc_nids;
  1122. spec->capsrc_nids = cxt5047_capsrc_nids;
  1123. spec->input_mux = &cxt5047_capture_source;
  1124. spec->num_mixers = 1;
  1125. spec->mixers[0] = cxt5047_mixers;
  1126. spec->num_init_verbs = 1;
  1127. spec->init_verbs[0] = cxt5047_init_verbs;
  1128. spec->spdif_route = 0;
  1129. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1130. spec->channel_mode = cxt5047_modes,
  1131. codec->patch_ops = conexant_patch_ops;
  1132. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1133. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1134. cxt5047_models,
  1135. cxt5047_cfg_tbl);
  1136. switch (board_config) {
  1137. case CXT5047_LAPTOP:
  1138. break;
  1139. case CXT5047_LAPTOP_HP:
  1140. spec->input_mux = &cxt5047_hp_capture_source;
  1141. spec->num_init_verbs = 2;
  1142. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1143. spec->mixers[0] = cxt5047_hp_mixers;
  1144. codec->patch_ops.init = cxt5047_hp_init;
  1145. break;
  1146. case CXT5047_LAPTOP_EAPD:
  1147. spec->input_mux = &cxt5047_toshiba_capture_source;
  1148. spec->num_init_verbs = 2;
  1149. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1150. spec->mixers[0] = cxt5047_toshiba_mixers;
  1151. break;
  1152. #ifdef CONFIG_SND_DEBUG
  1153. case CXT5047_TEST:
  1154. spec->input_mux = &cxt5047_test_capture_source;
  1155. spec->mixers[0] = cxt5047_test_mixer;
  1156. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1157. #endif
  1158. }
  1159. return 0;
  1160. }
  1161. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1162. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1163. .patch = patch_cxt5045 },
  1164. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1165. .patch = patch_cxt5047 },
  1166. {} /* terminator */
  1167. };