patch_conexant.c 55 KB

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