patch_sigmatel.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for SigmaTel STAC92xx
  5. *
  6. * Copyright (c) 2005 Embedded Alley Solutions, Inc.
  7. * <matt@embeddedalley.com>
  8. *
  9. * Based on patch_cmedia.c and patch_realtek.c
  10. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  11. *
  12. * This driver is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This driver is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <sound/driver.h>
  27. #include <linux/init.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <sound/core.h>
  32. #include "hda_codec.h"
  33. #include "hda_local.h"
  34. #undef STAC_TEST
  35. struct sigmatel_spec {
  36. /* playback */
  37. struct hda_multi_out multiout;
  38. hda_nid_t playback_nid;
  39. /* capture */
  40. hda_nid_t *adc_nids;
  41. unsigned int num_adcs;
  42. hda_nid_t *mux_nids;
  43. unsigned int num_muxes;
  44. hda_nid_t capture_nid;
  45. hda_nid_t dig_in_nid;
  46. /* power management*/
  47. hda_nid_t *pstate_nids;
  48. unsigned int num_pstates;
  49. /* pin widgets */
  50. hda_nid_t *pin_nids;
  51. unsigned int num_pins;
  52. #ifdef STAC_TEST
  53. unsigned int *pin_configs;
  54. #endif
  55. /* codec specific stuff */
  56. struct hda_verb *init;
  57. snd_kcontrol_new_t *mixer;
  58. /* capture source */
  59. struct hda_input_mux input_mux;
  60. char input_labels[HDA_MAX_NUM_INPUTS][16];
  61. unsigned int cur_mux[2];
  62. /* channel mode */
  63. unsigned int num_ch_modes;
  64. unsigned int cur_ch_mode;
  65. const struct sigmatel_channel_mode *channel_modes;
  66. struct hda_pcm pcm_rec[1]; /* PCM information */
  67. };
  68. static hda_nid_t stac9200_adc_nids[1] = {
  69. 0x03,
  70. };
  71. static hda_nid_t stac9200_mux_nids[1] = {
  72. 0x0c,
  73. };
  74. static hda_nid_t stac9200_dac_nids[1] = {
  75. 0x02,
  76. };
  77. static hda_nid_t stac9200_pstate_nids[3] = {
  78. 0x01, 0x02, 0x03,
  79. };
  80. static hda_nid_t stac9200_pin_nids[8] = {
  81. 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
  82. };
  83. static hda_nid_t stac922x_adc_nids[2] = {
  84. 0x06, 0x07,
  85. };
  86. static hda_nid_t stac922x_mux_nids[2] = {
  87. 0x12, 0x13,
  88. };
  89. static hda_nid_t stac922x_dac_nids[4] = {
  90. 0x02, 0x03, 0x04, 0x05,
  91. };
  92. static hda_nid_t stac922x_pstate_nids[8] = {
  93. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x11,
  94. };
  95. static hda_nid_t stac922x_pin_nids[10] = {
  96. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  97. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  98. };
  99. static int stac92xx_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  100. {
  101. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  102. struct sigmatel_spec *spec = codec->spec;
  103. return snd_hda_input_mux_info(&spec->input_mux, uinfo);
  104. }
  105. static int stac92xx_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  106. {
  107. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  108. struct sigmatel_spec *spec = codec->spec;
  109. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  110. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  111. return 0;
  112. }
  113. static int stac92xx_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  114. {
  115. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  116. struct sigmatel_spec *spec = codec->spec;
  117. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  118. return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol,
  119. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  120. }
  121. static struct hda_verb stac9200_ch2_init[] = {
  122. /* set dac0mux for dac converter */
  123. { 0x07, 0x701, 0x00},
  124. {}
  125. };
  126. static struct hda_verb stac922x_ch2_init[] = {
  127. /* set master volume and direct control */
  128. { 0x16, 0x70f, 0xff},
  129. {}
  130. };
  131. struct sigmatel_channel_mode {
  132. unsigned int channels;
  133. const struct hda_verb *sequence;
  134. };
  135. static snd_kcontrol_new_t stac9200_mixer[] = {
  136. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  137. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  138. {
  139. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  140. .name = "Input Source",
  141. .count = 1,
  142. .info = stac92xx_mux_enum_info,
  143. .get = stac92xx_mux_enum_get,
  144. .put = stac92xx_mux_enum_put,
  145. },
  146. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  147. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  148. HDA_CODEC_VOLUME("Input Mux Volume", 0x0c, 0, HDA_OUTPUT),
  149. { } /* end */
  150. };
  151. static snd_kcontrol_new_t stac922x_mixer[] = {
  152. HDA_CODEC_VOLUME("PCM Playback Volume", 0x2, 0x0, HDA_OUTPUT),
  153. HDA_CODEC_MUTE("PCM Playback Switch", 0x2, 0x0, HDA_OUTPUT),
  154. {
  155. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  156. .name = "Input Source",
  157. .count = 1,
  158. .info = stac92xx_mux_enum_info,
  159. .get = stac92xx_mux_enum_get,
  160. .put = stac92xx_mux_enum_put,
  161. },
  162. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
  163. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
  164. HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  165. { } /* end */
  166. };
  167. static int stac92xx_build_controls(struct hda_codec *codec)
  168. {
  169. struct sigmatel_spec *spec = codec->spec;
  170. int err;
  171. err = snd_hda_add_new_ctls(codec, spec->mixer);
  172. if (err < 0)
  173. return err;
  174. if (spec->multiout.dig_out_nid) {
  175. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  176. if (err < 0)
  177. return err;
  178. }
  179. if (spec->dig_in_nid) {
  180. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  181. if (err < 0)
  182. return err;
  183. }
  184. return 0;
  185. }
  186. #ifdef STAC_TEST
  187. static unsigned int stac9200_pin_configs[8] = {
  188. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  189. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  190. };
  191. static unsigned int stac922x_pin_configs[14] = {
  192. 0x40000100, 0x40000100, 0x40000100, 0x01114010,
  193. 0x01813122, 0x40000100, 0x01447010, 0x01c47010,
  194. 0x40000100, 0x40000100,
  195. };
  196. static void stac92xx_set_config_regs(struct hda_codec *codec)
  197. {
  198. int i;
  199. struct sigmatel_spec *spec = codec->spec;
  200. unsigned int pin_cfg;
  201. for (i=0; i < spec->num_pins; i++) {
  202. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  203. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  204. spec->pin_configs[i] & 0x000000ff);
  205. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  206. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  207. (spec->pin_configs[i] & 0x0000ff00) >> 8);
  208. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  209. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  210. (spec->pin_configs[i] & 0x00ff0000) >> 16);
  211. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  212. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  213. spec->pin_configs[i] >> 24);
  214. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  215. AC_VERB_GET_CONFIG_DEFAULT,
  216. 0x00);
  217. printk("pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
  218. }
  219. }
  220. #endif
  221. static int stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, unsigned int value)
  222. {
  223. unsigned int pin_ctl;
  224. pin_ctl = snd_hda_codec_read(codec, nid, 0,
  225. AC_VERB_GET_PIN_WIDGET_CONTROL,
  226. 0x00);
  227. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  228. pin_ctl | value);
  229. return 0;
  230. }
  231. static int stac92xx_set_vref(struct hda_codec *codec, hda_nid_t nid)
  232. {
  233. unsigned int vref_caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) >> AC_PINCAP_VREF_SHIFT;
  234. unsigned int vref_ctl = AC_PINCTL_VREF_HIZ;
  235. if (vref_caps & AC_PINCAP_VREF_100)
  236. vref_ctl = AC_PINCTL_VREF_100;
  237. else if (vref_caps & AC_PINCAP_VREF_80)
  238. vref_ctl = AC_PINCTL_VREF_80;
  239. else if (vref_caps & AC_PINCAP_VREF_50)
  240. vref_ctl = AC_PINCTL_VREF_50;
  241. else if (vref_caps & AC_PINCAP_VREF_GRD)
  242. vref_ctl = AC_PINCTL_VREF_GRD;
  243. stac92xx_set_pinctl(codec, nid, vref_ctl);
  244. return 0;
  245. }
  246. /*
  247. * retrieve the default device type from the default config value
  248. */
  249. #define get_defcfg_type(cfg) ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  250. #define get_defcfg_location(cfg) ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  251. static int stac92xx_config_pin(struct hda_codec *codec, hda_nid_t nid, unsigned int pin_cfg)
  252. {
  253. struct sigmatel_spec *spec = codec->spec;
  254. u32 location = get_defcfg_location(pin_cfg);
  255. char *label;
  256. const char *type = NULL;
  257. int ainput = 0;
  258. switch(get_defcfg_type(pin_cfg)) {
  259. case AC_JACK_HP_OUT:
  260. /* Enable HP amp */
  261. stac92xx_set_pinctl(codec, nid, AC_PINCTL_HP_EN);
  262. /* Fall through */
  263. case AC_JACK_SPDIF_OUT:
  264. case AC_JACK_LINE_OUT:
  265. case AC_JACK_SPEAKER:
  266. /* Enable output */
  267. stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  268. break;
  269. case AC_JACK_SPDIF_IN:
  270. stac92xx_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  271. break;
  272. case AC_JACK_MIC_IN:
  273. if ((location & 0x0f) == AC_JACK_LOC_FRONT)
  274. type = "Front Mic";
  275. else
  276. type = "Mic";
  277. ainput = 1;
  278. /* Set vref */
  279. stac92xx_set_vref(codec, nid);
  280. stac92xx_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  281. break;
  282. case AC_JACK_CD:
  283. type = "CD";
  284. ainput = 1;
  285. stac92xx_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  286. break;
  287. case AC_JACK_LINE_IN:
  288. if ((location & 0x0f) == AC_JACK_LOC_FRONT)
  289. type = "Front Line";
  290. else
  291. type = "Line";
  292. ainput = 1;
  293. stac92xx_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  294. break;
  295. case AC_JACK_AUX:
  296. if ((location & 0x0f) == AC_JACK_LOC_FRONT)
  297. type = "Front Aux";
  298. else
  299. type = "Aux";
  300. ainput = 1;
  301. stac92xx_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  302. break;
  303. }
  304. if (ainput) {
  305. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  306. int i, j, num_cons, index = -1;
  307. if (!type)
  308. type = "Input";
  309. label = spec->input_labels[spec->input_mux.num_items];
  310. strcpy(label, type);
  311. spec->input_mux.items[spec->input_mux.num_items].label = label;
  312. for (i=0; i<spec->num_muxes; i++) {
  313. num_cons = snd_hda_get_connections(codec, spec->mux_nids[i], con_lst, HDA_MAX_NUM_INPUTS);
  314. for (j=0; j<num_cons; j++)
  315. if (con_lst[j] == nid) {
  316. index = j;
  317. break;
  318. }
  319. if (index >= 0)
  320. break;
  321. }
  322. spec->input_mux.items[spec->input_mux.num_items].index = index;
  323. spec->input_mux.num_items++;
  324. }
  325. return 0;
  326. }
  327. static int stac92xx_config_pins(struct hda_codec *codec)
  328. {
  329. struct sigmatel_spec *spec = codec->spec;
  330. int i;
  331. unsigned int pin_cfg;
  332. for (i=0; i < spec->num_pins; i++) {
  333. /* Default to disabled */
  334. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  335. AC_VERB_SET_PIN_WIDGET_CONTROL,
  336. 0x00);
  337. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  338. AC_VERB_GET_CONFIG_DEFAULT,
  339. 0x00);
  340. if (((pin_cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) == AC_JACK_PORT_NONE)
  341. continue; /* Move on */
  342. stac92xx_config_pin(codec, spec->pin_nids[i], pin_cfg);
  343. }
  344. return 0;
  345. }
  346. static int stac92xx_init(struct hda_codec *codec)
  347. {
  348. struct sigmatel_spec *spec = codec->spec;
  349. int i;
  350. for (i=0; i < spec->num_pstates; i++)
  351. snd_hda_codec_write(codec, spec->pstate_nids[i], 0,
  352. AC_VERB_SET_POWER_STATE, 0x00);
  353. mdelay(100);
  354. snd_hda_sequence_write(codec, spec->init);
  355. #ifdef STAC_TEST
  356. stac92xx_set_config_regs(codec);
  357. #endif
  358. stac92xx_config_pins(codec);
  359. return 0;
  360. }
  361. /*
  362. * Analog playback callbacks
  363. */
  364. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  365. struct hda_codec *codec,
  366. snd_pcm_substream_t *substream)
  367. {
  368. struct sigmatel_spec *spec = codec->spec;
  369. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  370. }
  371. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  372. struct hda_codec *codec,
  373. unsigned int stream_tag,
  374. unsigned int format,
  375. snd_pcm_substream_t *substream)
  376. {
  377. struct sigmatel_spec *spec = codec->spec;
  378. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  379. format, substream);
  380. }
  381. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  382. struct hda_codec *codec,
  383. snd_pcm_substream_t *substream)
  384. {
  385. struct sigmatel_spec *spec = codec->spec;
  386. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  387. }
  388. /*
  389. * Digital playback callbacks
  390. */
  391. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  392. struct hda_codec *codec,
  393. snd_pcm_substream_t *substream)
  394. {
  395. struct sigmatel_spec *spec = codec->spec;
  396. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  397. }
  398. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  399. struct hda_codec *codec,
  400. snd_pcm_substream_t *substream)
  401. {
  402. struct sigmatel_spec *spec = codec->spec;
  403. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  404. }
  405. /*
  406. * Analog capture callbacks
  407. */
  408. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  409. struct hda_codec *codec,
  410. unsigned int stream_tag,
  411. unsigned int format,
  412. snd_pcm_substream_t *substream)
  413. {
  414. struct sigmatel_spec *spec = codec->spec;
  415. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  416. stream_tag, 0, format);
  417. return 0;
  418. }
  419. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  420. struct hda_codec *codec,
  421. snd_pcm_substream_t *substream)
  422. {
  423. struct sigmatel_spec *spec = codec->spec;
  424. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  425. return 0;
  426. }
  427. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  428. .substreams = 1,
  429. .channels_min = 2,
  430. .channels_max = 2,
  431. /* NID is set in stac92xx_build_pcms */
  432. .ops = {
  433. .open = stac92xx_dig_playback_pcm_open,
  434. .close = stac92xx_dig_playback_pcm_close
  435. },
  436. };
  437. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  438. .substreams = 1,
  439. .channels_min = 2,
  440. .channels_max = 2,
  441. /* NID is set in stac92xx_build_pcms */
  442. };
  443. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  444. .substreams = 1,
  445. .channels_min = 2,
  446. .channels_max = 2,
  447. .nid = 0x02, /* NID to query formats and rates */
  448. .ops = {
  449. .open = stac92xx_playback_pcm_open,
  450. .prepare = stac92xx_playback_pcm_prepare,
  451. .cleanup = stac92xx_playback_pcm_cleanup
  452. },
  453. };
  454. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  455. .substreams = 2,
  456. .channels_min = 2,
  457. .channels_max = 2,
  458. .nid = 0x06, /* NID to query formats and rates */
  459. .ops = {
  460. .prepare = stac92xx_capture_pcm_prepare,
  461. .cleanup = stac92xx_capture_pcm_cleanup
  462. },
  463. };
  464. static int stac92xx_build_pcms(struct hda_codec *codec)
  465. {
  466. struct sigmatel_spec *spec = codec->spec;
  467. struct hda_pcm *info = spec->pcm_rec;
  468. codec->num_pcms = 1;
  469. codec->pcm_info = info;
  470. info->name = "STAC92xx";
  471. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  472. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->playback_nid;
  473. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  474. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->capture_nid;
  475. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  476. codec->num_pcms++;
  477. info++;
  478. info->name = "STAC92xx Digital";
  479. if (spec->multiout.dig_out_nid) {
  480. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  481. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  482. }
  483. if (spec->dig_in_nid) {
  484. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  485. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  486. }
  487. }
  488. return 0;
  489. }
  490. static void stac92xx_free(struct hda_codec *codec)
  491. {
  492. kfree(codec->spec);
  493. }
  494. static struct hda_codec_ops stac92xx_patch_ops = {
  495. .build_controls = stac92xx_build_controls,
  496. .build_pcms = stac92xx_build_pcms,
  497. .init = stac92xx_init,
  498. .free = stac92xx_free,
  499. };
  500. static int patch_stac9200(struct hda_codec *codec)
  501. {
  502. struct sigmatel_spec *spec;
  503. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  504. if (spec == NULL)
  505. return -ENOMEM;
  506. codec->spec = spec;
  507. spec->multiout.max_channels = 2;
  508. spec->multiout.num_dacs = 1;
  509. spec->multiout.dac_nids = stac9200_dac_nids;
  510. spec->multiout.dig_out_nid = 0x05;
  511. spec->dig_in_nid = 0x04;
  512. spec->adc_nids = stac9200_adc_nids;
  513. spec->mux_nids = stac9200_mux_nids;
  514. spec->num_muxes = 1;
  515. spec->input_mux.num_items = 0;
  516. spec->pstate_nids = stac9200_pstate_nids;
  517. spec->num_pstates = 3;
  518. spec->pin_nids = stac9200_pin_nids;
  519. #ifdef STAC_TEST
  520. spec->pin_configs = stac9200_pin_configs;
  521. #endif
  522. spec->num_pins = 8;
  523. spec->init = stac9200_ch2_init;
  524. spec->mixer = stac9200_mixer;
  525. spec->playback_nid = 0x02;
  526. spec->capture_nid = 0x03;
  527. codec->patch_ops = stac92xx_patch_ops;
  528. return 0;
  529. }
  530. static int patch_stac922x(struct hda_codec *codec)
  531. {
  532. struct sigmatel_spec *spec;
  533. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  534. if (spec == NULL)
  535. return -ENOMEM;
  536. codec->spec = spec;
  537. spec->multiout.max_channels = 2;
  538. spec->multiout.num_dacs = 4;
  539. spec->multiout.dac_nids = stac922x_dac_nids;
  540. spec->multiout.dig_out_nid = 0x08;
  541. spec->dig_in_nid = 0x09;
  542. spec->adc_nids = stac922x_adc_nids;
  543. spec->mux_nids = stac922x_mux_nids;
  544. spec->num_muxes = 2;
  545. spec->input_mux.num_items = 0;
  546. spec->pstate_nids = stac922x_pstate_nids;
  547. spec->num_pstates = 8;
  548. spec->pin_nids = stac922x_pin_nids;
  549. #ifdef STAC_TEST
  550. spec->pin_configs = stac922x_pin_configs;
  551. #endif
  552. spec->num_pins = 10;
  553. spec->init = stac922x_ch2_init;
  554. spec->mixer = stac922x_mixer;
  555. spec->playback_nid = 0x02;
  556. spec->capture_nid = 0x06;
  557. codec->patch_ops = stac92xx_patch_ops;
  558. return 0;
  559. }
  560. /*
  561. * patch entries
  562. */
  563. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  564. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  565. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  566. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  567. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  568. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  569. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  570. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  571. {} /* terminator */
  572. };