patch_conexant.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  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 <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_patch.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. unsigned int cur_adc_idx;
  58. hda_nid_t cur_adc;
  59. unsigned int cur_adc_stream_tag;
  60. unsigned int cur_adc_format;
  61. /* capture source */
  62. const struct hda_input_mux *input_mux;
  63. hda_nid_t *capsrc_nids;
  64. unsigned int cur_mux[3];
  65. /* channel model */
  66. const struct hda_channel_mode *channel_mode;
  67. int num_channel_mode;
  68. /* PCM information */
  69. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  70. unsigned int spdif_route;
  71. /* dynamic controls, init_verbs and input_mux */
  72. struct auto_pin_cfg autocfg;
  73. unsigned int num_kctl_alloc, num_kctl_used;
  74. struct snd_kcontrol_new *kctl_alloc;
  75. struct hda_input_mux private_imux;
  76. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  77. };
  78. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  79. struct hda_codec *codec,
  80. struct snd_pcm_substream *substream)
  81. {
  82. struct conexant_spec *spec = codec->spec;
  83. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  84. hinfo);
  85. }
  86. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  87. struct hda_codec *codec,
  88. unsigned int stream_tag,
  89. unsigned int format,
  90. struct snd_pcm_substream *substream)
  91. {
  92. struct conexant_spec *spec = codec->spec;
  93. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  94. stream_tag,
  95. format, substream);
  96. }
  97. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  98. struct hda_codec *codec,
  99. struct snd_pcm_substream *substream)
  100. {
  101. struct conexant_spec *spec = codec->spec;
  102. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  103. }
  104. /*
  105. * Digital out
  106. */
  107. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  108. struct hda_codec *codec,
  109. struct snd_pcm_substream *substream)
  110. {
  111. struct conexant_spec *spec = codec->spec;
  112. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  113. }
  114. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  115. struct hda_codec *codec,
  116. struct snd_pcm_substream *substream)
  117. {
  118. struct conexant_spec *spec = codec->spec;
  119. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  120. }
  121. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  122. struct hda_codec *codec,
  123. unsigned int stream_tag,
  124. unsigned int format,
  125. struct snd_pcm_substream *substream)
  126. {
  127. struct conexant_spec *spec = codec->spec;
  128. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  129. stream_tag,
  130. format, substream);
  131. }
  132. /*
  133. * Analog capture
  134. */
  135. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  136. struct hda_codec *codec,
  137. unsigned int stream_tag,
  138. unsigned int format,
  139. struct snd_pcm_substream *substream)
  140. {
  141. struct conexant_spec *spec = codec->spec;
  142. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  143. stream_tag, 0, format);
  144. return 0;
  145. }
  146. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  147. struct hda_codec *codec,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  152. return 0;
  153. }
  154. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  155. .substreams = 1,
  156. .channels_min = 2,
  157. .channels_max = 2,
  158. .nid = 0, /* fill later */
  159. .ops = {
  160. .open = conexant_playback_pcm_open,
  161. .prepare = conexant_playback_pcm_prepare,
  162. .cleanup = conexant_playback_pcm_cleanup
  163. },
  164. };
  165. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  166. .substreams = 1,
  167. .channels_min = 2,
  168. .channels_max = 2,
  169. .nid = 0, /* fill later */
  170. .ops = {
  171. .prepare = conexant_capture_pcm_prepare,
  172. .cleanup = conexant_capture_pcm_cleanup
  173. },
  174. };
  175. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  176. .substreams = 1,
  177. .channels_min = 2,
  178. .channels_max = 2,
  179. .nid = 0, /* fill later */
  180. .ops = {
  181. .open = conexant_dig_playback_pcm_open,
  182. .close = conexant_dig_playback_pcm_close,
  183. .prepare = conexant_dig_playback_pcm_prepare
  184. },
  185. };
  186. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  187. .substreams = 1,
  188. .channels_min = 2,
  189. .channels_max = 2,
  190. /* NID is set in alc_build_pcms */
  191. };
  192. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  193. struct hda_codec *codec,
  194. unsigned int stream_tag,
  195. unsigned int format,
  196. struct snd_pcm_substream *substream)
  197. {
  198. struct conexant_spec *spec = codec->spec;
  199. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  200. spec->cur_adc_stream_tag = stream_tag;
  201. spec->cur_adc_format = format;
  202. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  203. return 0;
  204. }
  205. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  206. struct hda_codec *codec,
  207. struct snd_pcm_substream *substream)
  208. {
  209. struct conexant_spec *spec = codec->spec;
  210. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  211. spec->cur_adc = 0;
  212. return 0;
  213. }
  214. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  215. .substreams = 1,
  216. .channels_min = 2,
  217. .channels_max = 2,
  218. .nid = 0, /* fill later */
  219. .ops = {
  220. .prepare = cx5051_capture_pcm_prepare,
  221. .cleanup = cx5051_capture_pcm_cleanup
  222. },
  223. };
  224. static int conexant_build_pcms(struct hda_codec *codec)
  225. {
  226. struct conexant_spec *spec = codec->spec;
  227. struct hda_pcm *info = spec->pcm_rec;
  228. codec->num_pcms = 1;
  229. codec->pcm_info = info;
  230. info->name = "CONEXANT Analog";
  231. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  232. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  233. spec->multiout.max_channels;
  234. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  235. spec->multiout.dac_nids[0];
  236. if (codec->vendor_id == 0x14f15051)
  237. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  238. cx5051_pcm_analog_capture;
  239. else
  240. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  241. conexant_pcm_analog_capture;
  242. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  243. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  244. if (spec->multiout.dig_out_nid) {
  245. info++;
  246. codec->num_pcms++;
  247. info->name = "Conexant Digital";
  248. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  249. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  250. conexant_pcm_digital_playback;
  251. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  252. spec->multiout.dig_out_nid;
  253. if (spec->dig_in_nid) {
  254. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  255. conexant_pcm_digital_capture;
  256. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  257. spec->dig_in_nid;
  258. }
  259. }
  260. return 0;
  261. }
  262. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  263. struct snd_ctl_elem_info *uinfo)
  264. {
  265. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  266. struct conexant_spec *spec = codec->spec;
  267. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  268. }
  269. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  270. struct snd_ctl_elem_value *ucontrol)
  271. {
  272. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  273. struct conexant_spec *spec = codec->spec;
  274. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  275. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  276. return 0;
  277. }
  278. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  279. struct snd_ctl_elem_value *ucontrol)
  280. {
  281. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  282. struct conexant_spec *spec = codec->spec;
  283. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  284. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  285. spec->capsrc_nids[adc_idx],
  286. &spec->cur_mux[adc_idx]);
  287. }
  288. static int conexant_init(struct hda_codec *codec)
  289. {
  290. struct conexant_spec *spec = codec->spec;
  291. int i;
  292. for (i = 0; i < spec->num_init_verbs; i++)
  293. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  294. return 0;
  295. }
  296. static void conexant_free(struct hda_codec *codec)
  297. {
  298. struct conexant_spec *spec = codec->spec;
  299. unsigned int i;
  300. if (spec->kctl_alloc) {
  301. for (i = 0; i < spec->num_kctl_used; i++)
  302. kfree(spec->kctl_alloc[i].name);
  303. kfree(spec->kctl_alloc);
  304. }
  305. kfree(codec->spec);
  306. }
  307. static int conexant_build_controls(struct hda_codec *codec)
  308. {
  309. struct conexant_spec *spec = codec->spec;
  310. unsigned int i;
  311. int err;
  312. for (i = 0; i < spec->num_mixers; i++) {
  313. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  314. if (err < 0)
  315. return err;
  316. }
  317. if (spec->multiout.dig_out_nid) {
  318. err = snd_hda_create_spdif_out_ctls(codec,
  319. spec->multiout.dig_out_nid);
  320. if (err < 0)
  321. return err;
  322. err = snd_hda_create_spdif_share_sw(codec,
  323. &spec->multiout);
  324. if (err < 0)
  325. return err;
  326. spec->multiout.share_spdif = 1;
  327. }
  328. if (spec->dig_in_nid) {
  329. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  330. if (err < 0)
  331. return err;
  332. }
  333. return 0;
  334. }
  335. static struct hda_codec_ops conexant_patch_ops = {
  336. .build_controls = conexant_build_controls,
  337. .build_pcms = conexant_build_pcms,
  338. .init = conexant_init,
  339. .free = conexant_free,
  340. };
  341. /*
  342. * EAPD control
  343. * the private value = nid | (invert << 8)
  344. */
  345. #define cxt_eapd_info snd_ctl_boolean_mono_info
  346. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  347. struct snd_ctl_elem_value *ucontrol)
  348. {
  349. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  350. struct conexant_spec *spec = codec->spec;
  351. int invert = (kcontrol->private_value >> 8) & 1;
  352. if (invert)
  353. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  354. else
  355. ucontrol->value.integer.value[0] = spec->cur_eapd;
  356. return 0;
  357. }
  358. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  359. struct snd_ctl_elem_value *ucontrol)
  360. {
  361. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  362. struct conexant_spec *spec = codec->spec;
  363. int invert = (kcontrol->private_value >> 8) & 1;
  364. hda_nid_t nid = kcontrol->private_value & 0xff;
  365. unsigned int eapd;
  366. eapd = !!ucontrol->value.integer.value[0];
  367. if (invert)
  368. eapd = !eapd;
  369. if (eapd == spec->cur_eapd)
  370. return 0;
  371. spec->cur_eapd = eapd;
  372. snd_hda_codec_write_cache(codec, nid,
  373. 0, AC_VERB_SET_EAPD_BTLENABLE,
  374. eapd ? 0x02 : 0x00);
  375. return 1;
  376. }
  377. /* controls for test mode */
  378. #ifdef CONFIG_SND_DEBUG
  379. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  380. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  381. .info = cxt_eapd_info, \
  382. .get = cxt_eapd_get, \
  383. .put = cxt_eapd_put, \
  384. .private_value = nid | (mask<<16) }
  385. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  386. struct snd_ctl_elem_info *uinfo)
  387. {
  388. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  389. struct conexant_spec *spec = codec->spec;
  390. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  391. spec->num_channel_mode);
  392. }
  393. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_value *ucontrol)
  395. {
  396. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  397. struct conexant_spec *spec = codec->spec;
  398. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  399. spec->num_channel_mode,
  400. spec->multiout.max_channels);
  401. }
  402. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  403. struct snd_ctl_elem_value *ucontrol)
  404. {
  405. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  406. struct conexant_spec *spec = codec->spec;
  407. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  408. spec->num_channel_mode,
  409. &spec->multiout.max_channels);
  410. if (err >= 0 && spec->need_dac_fix)
  411. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  412. return err;
  413. }
  414. #define CXT_PIN_MODE(xname, nid, dir) \
  415. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  416. .info = conexant_ch_mode_info, \
  417. .get = conexant_ch_mode_get, \
  418. .put = conexant_ch_mode_put, \
  419. .private_value = nid | (dir<<16) }
  420. #endif /* CONFIG_SND_DEBUG */
  421. /* Conexant 5045 specific */
  422. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  423. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  424. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  425. #define CXT5045_SPDIF_OUT 0x18
  426. static struct hda_channel_mode cxt5045_modes[1] = {
  427. { 2, NULL },
  428. };
  429. static struct hda_input_mux cxt5045_capture_source = {
  430. .num_items = 2,
  431. .items = {
  432. { "IntMic", 0x1 },
  433. { "ExtMic", 0x2 },
  434. }
  435. };
  436. static struct hda_input_mux cxt5045_capture_source_benq = {
  437. .num_items = 3,
  438. .items = {
  439. { "IntMic", 0x1 },
  440. { "ExtMic", 0x2 },
  441. { "LineIn", 0x3 },
  442. }
  443. };
  444. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  445. .num_items = 2,
  446. .items = {
  447. { "ExtMic", 0x1 },
  448. { "IntMic", 0x2 },
  449. }
  450. };
  451. /* turn on/off EAPD (+ mute HP) as a master switch */
  452. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  453. struct snd_ctl_elem_value *ucontrol)
  454. {
  455. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  456. struct conexant_spec *spec = codec->spec;
  457. unsigned int bits;
  458. if (!cxt_eapd_put(kcontrol, ucontrol))
  459. return 0;
  460. /* toggle internal speakers mute depending of presence of
  461. * the headphone jack
  462. */
  463. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  464. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  465. HDA_AMP_MUTE, bits);
  466. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  467. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  468. HDA_AMP_MUTE, bits);
  469. return 1;
  470. }
  471. /* bind volumes of both NID 0x10 and 0x11 */
  472. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  473. .ops = &snd_hda_bind_vol,
  474. .values = {
  475. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  476. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  477. 0
  478. },
  479. };
  480. /* toggle input of built-in and mic jack appropriately */
  481. static void cxt5045_hp_automic(struct hda_codec *codec)
  482. {
  483. static struct hda_verb mic_jack_on[] = {
  484. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  485. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  486. {}
  487. };
  488. static struct hda_verb mic_jack_off[] = {
  489. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  490. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  491. {}
  492. };
  493. unsigned int present;
  494. present = snd_hda_codec_read(codec, 0x12, 0,
  495. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  496. if (present)
  497. snd_hda_sequence_write(codec, mic_jack_on);
  498. else
  499. snd_hda_sequence_write(codec, mic_jack_off);
  500. }
  501. /* mute internal speaker if HP is plugged */
  502. static void cxt5045_hp_automute(struct hda_codec *codec)
  503. {
  504. struct conexant_spec *spec = codec->spec;
  505. unsigned int bits;
  506. spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
  507. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  508. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  509. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  510. HDA_AMP_MUTE, bits);
  511. }
  512. /* unsolicited event for HP jack sensing */
  513. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  514. unsigned int res)
  515. {
  516. res >>= 26;
  517. switch (res) {
  518. case CONEXANT_HP_EVENT:
  519. cxt5045_hp_automute(codec);
  520. break;
  521. case CONEXANT_MIC_EVENT:
  522. cxt5045_hp_automic(codec);
  523. break;
  524. }
  525. }
  526. static struct snd_kcontrol_new cxt5045_mixers[] = {
  527. {
  528. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  529. .name = "Capture Source",
  530. .info = conexant_mux_enum_info,
  531. .get = conexant_mux_enum_get,
  532. .put = conexant_mux_enum_put
  533. },
  534. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  535. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  536. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  537. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  538. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  539. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  540. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  541. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  542. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  543. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  544. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  545. {
  546. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  547. .name = "Master Playback Switch",
  548. .info = cxt_eapd_info,
  549. .get = cxt_eapd_get,
  550. .put = cxt5045_hp_master_sw_put,
  551. .private_value = 0x10,
  552. },
  553. {}
  554. };
  555. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  556. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  557. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  558. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  559. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  560. {}
  561. };
  562. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  563. {
  564. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  565. .name = "Capture Source",
  566. .info = conexant_mux_enum_info,
  567. .get = conexant_mux_enum_get,
  568. .put = conexant_mux_enum_put
  569. },
  570. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  571. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  572. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  573. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  574. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  575. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  576. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  577. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  578. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  579. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  580. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  581. {
  582. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  583. .name = "Master Playback Switch",
  584. .info = cxt_eapd_info,
  585. .get = cxt_eapd_get,
  586. .put = cxt5045_hp_master_sw_put,
  587. .private_value = 0x10,
  588. },
  589. {}
  590. };
  591. static struct hda_verb cxt5045_init_verbs[] = {
  592. /* Line in, Mic */
  593. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  594. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  595. /* HP, Amp */
  596. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  597. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  598. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  599. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  600. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  601. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  602. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  603. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  604. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  605. /* Record selector: Int mic */
  606. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  607. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  608. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  609. /* SPDIF route: PCM */
  610. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  611. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  612. /* EAPD */
  613. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  614. { } /* end */
  615. };
  616. static struct hda_verb cxt5045_benq_init_verbs[] = {
  617. /* Int Mic, Mic */
  618. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  619. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  620. /* Line In,HP, Amp */
  621. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  622. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  623. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  624. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  625. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  626. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  627. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  628. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  629. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  630. /* Record selector: Int mic */
  631. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  632. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  633. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  634. /* SPDIF route: PCM */
  635. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  636. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  637. /* EAPD */
  638. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  639. { } /* end */
  640. };
  641. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  642. /* pin sensing on HP jack */
  643. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  644. { } /* end */
  645. };
  646. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  647. /* pin sensing on HP jack */
  648. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  649. { } /* end */
  650. };
  651. #ifdef CONFIG_SND_DEBUG
  652. /* Test configuration for debugging, modelled after the ALC260 test
  653. * configuration.
  654. */
  655. static struct hda_input_mux cxt5045_test_capture_source = {
  656. .num_items = 5,
  657. .items = {
  658. { "MIXER", 0x0 },
  659. { "MIC1 pin", 0x1 },
  660. { "LINE1 pin", 0x2 },
  661. { "HP-OUT pin", 0x3 },
  662. { "CD pin", 0x4 },
  663. },
  664. };
  665. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  666. /* Output controls */
  667. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  668. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  669. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  670. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  671. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  672. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  673. /* Modes for retasking pin widgets */
  674. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  675. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  676. /* EAPD Switch Control */
  677. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  678. /* Loopback mixer controls */
  679. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  680. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  681. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  682. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  683. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  684. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  685. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  686. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  687. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  688. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  689. {
  690. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  691. .name = "Input Source",
  692. .info = conexant_mux_enum_info,
  693. .get = conexant_mux_enum_get,
  694. .put = conexant_mux_enum_put,
  695. },
  696. /* Audio input controls */
  697. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  698. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  699. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  700. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  701. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  702. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  703. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  704. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  706. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  707. { } /* end */
  708. };
  709. static struct hda_verb cxt5045_test_init_verbs[] = {
  710. /* Set connections */
  711. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  712. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  713. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  714. /* Enable retasking pins as output, initially without power amp */
  715. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  716. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  717. /* Disable digital (SPDIF) pins initially, but users can enable
  718. * them via a mixer switch. In the case of SPDIF-out, this initverb
  719. * payload also sets the generation to 0, output to be in "consumer"
  720. * PCM format, copyright asserted, no pre-emphasis and no validity
  721. * control.
  722. */
  723. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  724. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  725. /* Start with output sum widgets muted and their output gains at min */
  726. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  727. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  728. /* Unmute retasking pin widget output buffers since the default
  729. * state appears to be output. As the pin mode is changed by the
  730. * user the pin mode control will take care of enabling the pin's
  731. * input/output buffers as needed.
  732. */
  733. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  734. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  735. /* Mute capture amp left and right */
  736. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  737. /* Set ADC connection select to match default mixer setting (mic1
  738. * pin)
  739. */
  740. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  741. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  742. /* Mute all inputs to mixer widget (even unconnected ones) */
  743. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  744. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  745. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  746. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  747. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  748. { }
  749. };
  750. #endif
  751. /* initialize jack-sensing, too */
  752. static int cxt5045_init(struct hda_codec *codec)
  753. {
  754. conexant_init(codec);
  755. cxt5045_hp_automute(codec);
  756. return 0;
  757. }
  758. enum {
  759. CXT5045_LAPTOP_HPSENSE,
  760. CXT5045_LAPTOP_MICSENSE,
  761. CXT5045_LAPTOP_HPMICSENSE,
  762. CXT5045_BENQ,
  763. CXT5045_LAPTOP_HP530,
  764. #ifdef CONFIG_SND_DEBUG
  765. CXT5045_TEST,
  766. #endif
  767. CXT5045_MODELS
  768. };
  769. static const char *cxt5045_models[CXT5045_MODELS] = {
  770. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  771. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  772. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  773. [CXT5045_BENQ] = "benq",
  774. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  775. #ifdef CONFIG_SND_DEBUG
  776. [CXT5045_TEST] = "test",
  777. #endif
  778. };
  779. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  780. SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
  781. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  782. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
  783. SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
  784. SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
  785. SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
  786. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
  787. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  788. SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
  789. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  790. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  791. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  792. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  793. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  794. CXT5045_LAPTOP_HPMICSENSE),
  795. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  796. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  797. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  798. SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  799. SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
  800. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  801. {}
  802. };
  803. static int patch_cxt5045(struct hda_codec *codec)
  804. {
  805. struct conexant_spec *spec;
  806. int board_config;
  807. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  808. if (!spec)
  809. return -ENOMEM;
  810. codec->spec = spec;
  811. spec->multiout.max_channels = 2;
  812. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  813. spec->multiout.dac_nids = cxt5045_dac_nids;
  814. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  815. spec->num_adc_nids = 1;
  816. spec->adc_nids = cxt5045_adc_nids;
  817. spec->capsrc_nids = cxt5045_capsrc_nids;
  818. spec->input_mux = &cxt5045_capture_source;
  819. spec->num_mixers = 1;
  820. spec->mixers[0] = cxt5045_mixers;
  821. spec->num_init_verbs = 1;
  822. spec->init_verbs[0] = cxt5045_init_verbs;
  823. spec->spdif_route = 0;
  824. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  825. spec->channel_mode = cxt5045_modes,
  826. codec->patch_ops = conexant_patch_ops;
  827. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  828. cxt5045_models,
  829. cxt5045_cfg_tbl);
  830. switch (board_config) {
  831. case CXT5045_LAPTOP_HPSENSE:
  832. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  833. spec->input_mux = &cxt5045_capture_source;
  834. spec->num_init_verbs = 2;
  835. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  836. spec->mixers[0] = cxt5045_mixers;
  837. codec->patch_ops.init = cxt5045_init;
  838. break;
  839. case CXT5045_LAPTOP_MICSENSE:
  840. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  841. spec->input_mux = &cxt5045_capture_source;
  842. spec->num_init_verbs = 2;
  843. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  844. spec->mixers[0] = cxt5045_mixers;
  845. codec->patch_ops.init = cxt5045_init;
  846. break;
  847. default:
  848. case CXT5045_LAPTOP_HPMICSENSE:
  849. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  850. spec->input_mux = &cxt5045_capture_source;
  851. spec->num_init_verbs = 3;
  852. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  853. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  854. spec->mixers[0] = cxt5045_mixers;
  855. codec->patch_ops.init = cxt5045_init;
  856. break;
  857. case CXT5045_BENQ:
  858. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  859. spec->input_mux = &cxt5045_capture_source_benq;
  860. spec->num_init_verbs = 1;
  861. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  862. spec->mixers[0] = cxt5045_mixers;
  863. spec->mixers[1] = cxt5045_benq_mixers;
  864. spec->num_mixers = 2;
  865. codec->patch_ops.init = cxt5045_init;
  866. break;
  867. case CXT5045_LAPTOP_HP530:
  868. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  869. spec->input_mux = &cxt5045_capture_source_hp530;
  870. spec->num_init_verbs = 2;
  871. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  872. spec->mixers[0] = cxt5045_mixers_hp530;
  873. codec->patch_ops.init = cxt5045_init;
  874. break;
  875. #ifdef CONFIG_SND_DEBUG
  876. case CXT5045_TEST:
  877. spec->input_mux = &cxt5045_test_capture_source;
  878. spec->mixers[0] = cxt5045_test_mixer;
  879. spec->init_verbs[0] = cxt5045_test_init_verbs;
  880. break;
  881. #endif
  882. }
  883. switch (codec->subsystem_id >> 16) {
  884. case 0x103c:
  885. /* HP laptop has a really bad sound over 0dB on NID 0x17.
  886. * Fix max PCM level to 0 dB
  887. * (originall it has 0x2b steps with 0dB offset 0x14)
  888. */
  889. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  890. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  891. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  892. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  893. (1 << AC_AMPCAP_MUTE_SHIFT));
  894. break;
  895. }
  896. return 0;
  897. }
  898. /* Conexant 5047 specific */
  899. #define CXT5047_SPDIF_OUT 0x11
  900. static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
  901. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  902. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  903. static struct hda_channel_mode cxt5047_modes[1] = {
  904. { 2, NULL },
  905. };
  906. static struct hda_input_mux cxt5047_capture_source = {
  907. .num_items = 1,
  908. .items = {
  909. { "Mic", 0x2 },
  910. }
  911. };
  912. static struct hda_input_mux cxt5047_hp_capture_source = {
  913. .num_items = 1,
  914. .items = {
  915. { "ExtMic", 0x2 },
  916. }
  917. };
  918. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  919. .num_items = 2,
  920. .items = {
  921. { "ExtMic", 0x2 },
  922. { "Line-In", 0x1 },
  923. }
  924. };
  925. /* turn on/off EAPD (+ mute HP) as a master switch */
  926. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  927. struct snd_ctl_elem_value *ucontrol)
  928. {
  929. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  930. struct conexant_spec *spec = codec->spec;
  931. unsigned int bits;
  932. if (!cxt_eapd_put(kcontrol, ucontrol))
  933. return 0;
  934. /* toggle internal speakers mute depending of presence of
  935. * the headphone jack
  936. */
  937. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  938. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  939. HDA_AMP_MUTE, bits);
  940. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  941. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  942. HDA_AMP_MUTE, bits);
  943. return 1;
  944. }
  945. /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
  946. static struct hda_bind_ctls cxt5047_bind_master_vol = {
  947. .ops = &snd_hda_bind_vol,
  948. .values = {
  949. HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
  950. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  951. 0
  952. },
  953. };
  954. /* mute internal speaker if HP is plugged */
  955. static void cxt5047_hp_automute(struct hda_codec *codec)
  956. {
  957. struct conexant_spec *spec = codec->spec;
  958. unsigned int bits;
  959. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  960. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  961. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  962. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  963. HDA_AMP_MUTE, bits);
  964. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  965. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  966. HDA_AMP_MUTE, bits);
  967. }
  968. /* mute internal speaker if HP is plugged */
  969. static void cxt5047_hp2_automute(struct hda_codec *codec)
  970. {
  971. struct conexant_spec *spec = codec->spec;
  972. unsigned int bits;
  973. spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
  974. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  975. bits = spec->hp_present ? HDA_AMP_MUTE : 0;
  976. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
  977. HDA_AMP_MUTE, bits);
  978. /* Mute/Unmute PCM 2 for good measure - some systems need this */
  979. snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
  980. HDA_AMP_MUTE, bits);
  981. }
  982. /* toggle input of built-in and mic jack appropriately */
  983. static void cxt5047_hp_automic(struct hda_codec *codec)
  984. {
  985. static struct hda_verb mic_jack_on[] = {
  986. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  987. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  988. {}
  989. };
  990. static struct hda_verb mic_jack_off[] = {
  991. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  992. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  993. {}
  994. };
  995. unsigned int present;
  996. present = snd_hda_codec_read(codec, 0x15, 0,
  997. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  998. if (present)
  999. snd_hda_sequence_write(codec, mic_jack_on);
  1000. else
  1001. snd_hda_sequence_write(codec, mic_jack_off);
  1002. }
  1003. /* unsolicited event for HP jack sensing */
  1004. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1005. unsigned int res)
  1006. {
  1007. switch (res >> 26) {
  1008. case CONEXANT_HP_EVENT:
  1009. cxt5047_hp_automute(codec);
  1010. break;
  1011. case CONEXANT_MIC_EVENT:
  1012. cxt5047_hp_automic(codec);
  1013. break;
  1014. }
  1015. }
  1016. /* unsolicited event for HP jack sensing - non-EAPD systems */
  1017. static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
  1018. unsigned int res)
  1019. {
  1020. res >>= 26;
  1021. switch (res) {
  1022. case CONEXANT_HP_EVENT:
  1023. cxt5047_hp2_automute(codec);
  1024. break;
  1025. case CONEXANT_MIC_EVENT:
  1026. cxt5047_hp_automic(codec);
  1027. break;
  1028. }
  1029. }
  1030. static struct snd_kcontrol_new cxt5047_mixers[] = {
  1031. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1032. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1033. HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
  1034. HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
  1035. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1036. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1037. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1038. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1039. HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
  1040. HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
  1041. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
  1042. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
  1043. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1044. HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
  1045. {}
  1046. };
  1047. static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
  1048. {
  1049. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1050. .name = "Capture Source",
  1051. .info = conexant_mux_enum_info,
  1052. .get = conexant_mux_enum_get,
  1053. .put = conexant_mux_enum_put
  1054. },
  1055. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1056. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
  1057. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1058. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1059. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1060. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1061. HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
  1062. {
  1063. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1064. .name = "Master Playback Switch",
  1065. .info = cxt_eapd_info,
  1066. .get = cxt_eapd_get,
  1067. .put = cxt5047_hp_master_sw_put,
  1068. .private_value = 0x13,
  1069. },
  1070. {}
  1071. };
  1072. static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
  1073. {
  1074. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1075. .name = "Capture Source",
  1076. .info = conexant_mux_enum_info,
  1077. .get = conexant_mux_enum_get,
  1078. .put = conexant_mux_enum_put
  1079. },
  1080. HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
  1081. HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
  1082. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1083. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1084. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1085. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1086. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1087. {
  1088. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1089. .name = "Master Playback Switch",
  1090. .info = cxt_eapd_info,
  1091. .get = cxt_eapd_get,
  1092. .put = cxt5047_hp_master_sw_put,
  1093. .private_value = 0x13,
  1094. },
  1095. { } /* end */
  1096. };
  1097. static struct hda_verb cxt5047_init_verbs[] = {
  1098. /* Line in, Mic, Built-in Mic */
  1099. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1100. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1101. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1102. /* HP, Speaker */
  1103. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1104. {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
  1105. {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
  1106. /* Record selector: Mic */
  1107. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1108. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1109. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1110. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1111. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1112. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1113. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1114. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1115. /* SPDIF route: PCM */
  1116. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1117. /* Enable unsolicited events */
  1118. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1119. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1120. { } /* end */
  1121. };
  1122. /* configuration for Toshiba Laptops */
  1123. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1124. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
  1125. /* pin sensing on HP and Mic jacks */
  1126. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1127. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1128. /* Speaker routing */
  1129. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1130. {}
  1131. };
  1132. /* configuration for HP Laptops */
  1133. static struct hda_verb cxt5047_hp_init_verbs[] = {
  1134. /* pin sensing on HP jack */
  1135. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1136. /* 0x13 is actually shared by both HP and speaker;
  1137. * setting the connection to 0 (=0x19) makes the master volume control
  1138. * working mysteriouslly...
  1139. */
  1140. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  1141. /* Record selector: Ext Mic */
  1142. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1143. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1144. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1145. /* Speaker routing */
  1146. {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
  1147. {}
  1148. };
  1149. /* Test configuration for debugging, modelled after the ALC260 test
  1150. * configuration.
  1151. */
  1152. #ifdef CONFIG_SND_DEBUG
  1153. static struct hda_input_mux cxt5047_test_capture_source = {
  1154. .num_items = 4,
  1155. .items = {
  1156. { "LINE1 pin", 0x0 },
  1157. { "MIC1 pin", 0x1 },
  1158. { "MIC2 pin", 0x2 },
  1159. { "CD pin", 0x3 },
  1160. },
  1161. };
  1162. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1163. /* Output only controls */
  1164. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1165. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1166. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1167. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1168. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1169. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1170. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1171. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1172. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1173. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1174. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1175. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1176. /* Modes for retasking pin widgets */
  1177. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1178. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1179. /* EAPD Switch Control */
  1180. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1181. /* Loopback mixer controls */
  1182. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1183. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1184. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1185. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1186. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1187. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1188. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1189. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1190. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1191. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1192. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1193. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1194. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1195. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1196. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1197. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1198. {
  1199. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1200. .name = "Input Source",
  1201. .info = conexant_mux_enum_info,
  1202. .get = conexant_mux_enum_get,
  1203. .put = conexant_mux_enum_put,
  1204. },
  1205. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  1206. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  1207. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  1208. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  1209. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  1210. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  1211. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  1212. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  1213. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  1214. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  1215. { } /* end */
  1216. };
  1217. static struct hda_verb cxt5047_test_init_verbs[] = {
  1218. /* Enable retasking pins as output, initially without power amp */
  1219. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1220. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1221. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1222. /* Disable digital (SPDIF) pins initially, but users can enable
  1223. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1224. * payload also sets the generation to 0, output to be in "consumer"
  1225. * PCM format, copyright asserted, no pre-emphasis and no validity
  1226. * control.
  1227. */
  1228. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1229. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1230. * OUT1 sum bus when acting as an output.
  1231. */
  1232. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1233. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1234. /* Start with output sum widgets muted and their output gains at min */
  1235. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1236. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1237. /* Unmute retasking pin widget output buffers since the default
  1238. * state appears to be output. As the pin mode is changed by the
  1239. * user the pin mode control will take care of enabling the pin's
  1240. * input/output buffers as needed.
  1241. */
  1242. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1243. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1244. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1245. /* Mute capture amp left and right */
  1246. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1247. /* Set ADC connection select to match default mixer setting (mic1
  1248. * pin)
  1249. */
  1250. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1251. /* Mute all inputs to mixer widget (even unconnected ones) */
  1252. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1253. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1254. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1255. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1256. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1257. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1258. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1259. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1260. { }
  1261. };
  1262. #endif
  1263. /* initialize jack-sensing, too */
  1264. static int cxt5047_hp_init(struct hda_codec *codec)
  1265. {
  1266. conexant_init(codec);
  1267. cxt5047_hp_automute(codec);
  1268. return 0;
  1269. }
  1270. enum {
  1271. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1272. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1273. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1274. #ifdef CONFIG_SND_DEBUG
  1275. CXT5047_TEST,
  1276. #endif
  1277. CXT5047_MODELS
  1278. };
  1279. static const char *cxt5047_models[CXT5047_MODELS] = {
  1280. [CXT5047_LAPTOP] = "laptop",
  1281. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1282. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1283. #ifdef CONFIG_SND_DEBUG
  1284. [CXT5047_TEST] = "test",
  1285. #endif
  1286. };
  1287. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1288. SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
  1289. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1290. SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
  1291. SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
  1292. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1293. {}
  1294. };
  1295. static int patch_cxt5047(struct hda_codec *codec)
  1296. {
  1297. struct conexant_spec *spec;
  1298. int board_config;
  1299. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1300. if (!spec)
  1301. return -ENOMEM;
  1302. codec->spec = spec;
  1303. spec->multiout.max_channels = 2;
  1304. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1305. spec->multiout.dac_nids = cxt5047_dac_nids;
  1306. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1307. spec->num_adc_nids = 1;
  1308. spec->adc_nids = cxt5047_adc_nids;
  1309. spec->capsrc_nids = cxt5047_capsrc_nids;
  1310. spec->input_mux = &cxt5047_capture_source;
  1311. spec->num_mixers = 1;
  1312. spec->mixers[0] = cxt5047_mixers;
  1313. spec->num_init_verbs = 1;
  1314. spec->init_verbs[0] = cxt5047_init_verbs;
  1315. spec->spdif_route = 0;
  1316. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1317. spec->channel_mode = cxt5047_modes,
  1318. codec->patch_ops = conexant_patch_ops;
  1319. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1320. cxt5047_models,
  1321. cxt5047_cfg_tbl);
  1322. switch (board_config) {
  1323. case CXT5047_LAPTOP:
  1324. codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
  1325. break;
  1326. case CXT5047_LAPTOP_HP:
  1327. spec->input_mux = &cxt5047_hp_capture_source;
  1328. spec->num_init_verbs = 2;
  1329. spec->init_verbs[1] = cxt5047_hp_init_verbs;
  1330. spec->mixers[0] = cxt5047_hp_mixers;
  1331. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1332. codec->patch_ops.init = cxt5047_hp_init;
  1333. break;
  1334. case CXT5047_LAPTOP_EAPD:
  1335. spec->input_mux = &cxt5047_toshiba_capture_source;
  1336. spec->num_init_verbs = 2;
  1337. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1338. spec->mixers[0] = cxt5047_toshiba_mixers;
  1339. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1340. break;
  1341. #ifdef CONFIG_SND_DEBUG
  1342. case CXT5047_TEST:
  1343. spec->input_mux = &cxt5047_test_capture_source;
  1344. spec->mixers[0] = cxt5047_test_mixer;
  1345. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1346. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1347. #endif
  1348. }
  1349. return 0;
  1350. }
  1351. /* Conexant 5051 specific */
  1352. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1353. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1354. #define CXT5051_SPDIF_OUT 0x1C
  1355. #define CXT5051_PORTB_EVENT 0x38
  1356. #define CXT5051_PORTC_EVENT 0x39
  1357. static struct hda_channel_mode cxt5051_modes[1] = {
  1358. { 2, NULL },
  1359. };
  1360. static void cxt5051_update_speaker(struct hda_codec *codec)
  1361. {
  1362. struct conexant_spec *spec = codec->spec;
  1363. unsigned int pinctl;
  1364. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1365. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1366. pinctl);
  1367. }
  1368. /* turn on/off EAPD (+ mute HP) as a master switch */
  1369. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1370. struct snd_ctl_elem_value *ucontrol)
  1371. {
  1372. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1373. if (!cxt_eapd_put(kcontrol, ucontrol))
  1374. return 0;
  1375. cxt5051_update_speaker(codec);
  1376. return 1;
  1377. }
  1378. /* toggle input of built-in and mic jack appropriately */
  1379. static void cxt5051_portb_automic(struct hda_codec *codec)
  1380. {
  1381. unsigned int present;
  1382. present = snd_hda_codec_read(codec, 0x17, 0,
  1383. AC_VERB_GET_PIN_SENSE, 0) &
  1384. AC_PINSENSE_PRESENCE;
  1385. snd_hda_codec_write(codec, 0x14, 0,
  1386. AC_VERB_SET_CONNECT_SEL,
  1387. present ? 0x01 : 0x00);
  1388. }
  1389. /* switch the current ADC according to the jack state */
  1390. static void cxt5051_portc_automic(struct hda_codec *codec)
  1391. {
  1392. struct conexant_spec *spec = codec->spec;
  1393. unsigned int present;
  1394. hda_nid_t new_adc;
  1395. present = snd_hda_codec_read(codec, 0x18, 0,
  1396. AC_VERB_GET_PIN_SENSE, 0) &
  1397. AC_PINSENSE_PRESENCE;
  1398. if (present)
  1399. spec->cur_adc_idx = 1;
  1400. else
  1401. spec->cur_adc_idx = 0;
  1402. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1403. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1404. /* stream is running, let's swap the current ADC */
  1405. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1406. spec->cur_adc = new_adc;
  1407. snd_hda_codec_setup_stream(codec, new_adc,
  1408. spec->cur_adc_stream_tag, 0,
  1409. spec->cur_adc_format);
  1410. }
  1411. }
  1412. /* mute internal speaker if HP is plugged */
  1413. static void cxt5051_hp_automute(struct hda_codec *codec)
  1414. {
  1415. struct conexant_spec *spec = codec->spec;
  1416. spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
  1417. AC_VERB_GET_PIN_SENSE, 0) &
  1418. AC_PINSENSE_PRESENCE;
  1419. cxt5051_update_speaker(codec);
  1420. }
  1421. /* unsolicited event for HP jack sensing */
  1422. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1423. unsigned int res)
  1424. {
  1425. switch (res >> 26) {
  1426. case CONEXANT_HP_EVENT:
  1427. cxt5051_hp_automute(codec);
  1428. break;
  1429. case CXT5051_PORTB_EVENT:
  1430. cxt5051_portb_automic(codec);
  1431. break;
  1432. case CXT5051_PORTC_EVENT:
  1433. cxt5051_portc_automic(codec);
  1434. break;
  1435. }
  1436. }
  1437. static struct snd_kcontrol_new cxt5051_mixers[] = {
  1438. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1439. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1440. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1441. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1442. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1443. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1444. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1445. {
  1446. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1447. .name = "Master Playback Switch",
  1448. .info = cxt_eapd_info,
  1449. .get = cxt_eapd_get,
  1450. .put = cxt5051_hp_master_sw_put,
  1451. .private_value = 0x1a,
  1452. },
  1453. {}
  1454. };
  1455. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1456. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1457. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1458. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1459. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1460. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1461. {
  1462. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1463. .name = "Master Playback Switch",
  1464. .info = cxt_eapd_info,
  1465. .get = cxt_eapd_get,
  1466. .put = cxt5051_hp_master_sw_put,
  1467. .private_value = 0x1a,
  1468. },
  1469. {}
  1470. };
  1471. static struct hda_verb cxt5051_init_verbs[] = {
  1472. /* Line in, Mic */
  1473. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1474. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1475. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1476. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1477. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1478. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1479. /* SPK */
  1480. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1481. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1482. /* HP, Amp */
  1483. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1484. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1485. /* DAC1 */
  1486. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1487. /* Record selector: Int mic */
  1488. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1489. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1490. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1491. /* SPDIF route: PCM */
  1492. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1493. /* EAPD */
  1494. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1495. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1496. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
  1497. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
  1498. { } /* end */
  1499. };
  1500. /* initialize jack-sensing, too */
  1501. static int cxt5051_init(struct hda_codec *codec)
  1502. {
  1503. conexant_init(codec);
  1504. if (codec->patch_ops.unsol_event) {
  1505. cxt5051_hp_automute(codec);
  1506. cxt5051_portb_automic(codec);
  1507. cxt5051_portc_automic(codec);
  1508. }
  1509. return 0;
  1510. }
  1511. enum {
  1512. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1513. CXT5051_HP, /* no docking */
  1514. CXT5051_MODELS
  1515. };
  1516. static const char *cxt5051_models[CXT5051_MODELS] = {
  1517. [CXT5051_LAPTOP] = "laptop",
  1518. [CXT5051_HP] = "hp",
  1519. };
  1520. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1521. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1522. CXT5051_LAPTOP),
  1523. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1524. {}
  1525. };
  1526. static int patch_cxt5051(struct hda_codec *codec)
  1527. {
  1528. struct conexant_spec *spec;
  1529. int board_config;
  1530. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1531. if (!spec)
  1532. return -ENOMEM;
  1533. codec->spec = spec;
  1534. codec->patch_ops = conexant_patch_ops;
  1535. codec->patch_ops.init = cxt5051_init;
  1536. spec->multiout.max_channels = 2;
  1537. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1538. spec->multiout.dac_nids = cxt5051_dac_nids;
  1539. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1540. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1541. spec->adc_nids = cxt5051_adc_nids;
  1542. spec->num_mixers = 1;
  1543. spec->mixers[0] = cxt5051_mixers;
  1544. spec->num_init_verbs = 1;
  1545. spec->init_verbs[0] = cxt5051_init_verbs;
  1546. spec->spdif_route = 0;
  1547. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1548. spec->channel_mode = cxt5051_modes;
  1549. spec->cur_adc = 0;
  1550. spec->cur_adc_idx = 0;
  1551. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1552. cxt5051_models,
  1553. cxt5051_cfg_tbl);
  1554. switch (board_config) {
  1555. case CXT5051_HP:
  1556. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1557. spec->mixers[0] = cxt5051_hp_mixers;
  1558. break;
  1559. default:
  1560. case CXT5051_LAPTOP:
  1561. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1562. break;
  1563. }
  1564. return 0;
  1565. }
  1566. /*
  1567. */
  1568. struct hda_codec_preset snd_hda_preset_conexant[] = {
  1569. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  1570. .patch = patch_cxt5045 },
  1571. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  1572. .patch = patch_cxt5047 },
  1573. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  1574. .patch = patch_cxt5051 },
  1575. {} /* terminator */
  1576. };