patch_conexant.c 55 KB

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