patch_conexant.c 57 KB

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