patch_conexant.c 58 KB

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