patch_conexant.c 41 KB

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