patch_conexant.c 55 KB

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