patch_conexant.c 40 KB

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