patch_conexant.c 42 KB

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