patch_conexant.c 53 KB

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