patch_conexant.c 54 KB

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