patch_conexant.c 57 KB

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