patch_sigmatel.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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 Porter <mporter@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 <sound/asoundef.h>
  33. #include "hda_codec.h"
  34. #include "hda_local.h"
  35. #define NUM_CONTROL_ALLOC 32
  36. #define STAC_HP_EVENT 0x37
  37. #define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
  38. #define STAC_REF 0
  39. #define STAC_D945GTP3 1
  40. #define STAC_D945GTP5 2
  41. struct sigmatel_spec {
  42. struct snd_kcontrol_new *mixers[4];
  43. unsigned int num_mixers;
  44. int board_config;
  45. unsigned int surr_switch: 1;
  46. unsigned int line_switch: 1;
  47. unsigned int mic_switch: 1;
  48. unsigned int alt_switch: 1;
  49. unsigned int hp_detect: 1;
  50. /* playback */
  51. struct hda_multi_out multiout;
  52. hda_nid_t dac_nids[5];
  53. /* capture */
  54. hda_nid_t *adc_nids;
  55. unsigned int num_adcs;
  56. hda_nid_t *mux_nids;
  57. unsigned int num_muxes;
  58. hda_nid_t dig_in_nid;
  59. /* pin widgets */
  60. hda_nid_t *pin_nids;
  61. unsigned int num_pins;
  62. unsigned int *pin_configs;
  63. /* codec specific stuff */
  64. struct hda_verb *init;
  65. struct snd_kcontrol_new *mixer;
  66. /* capture source */
  67. struct hda_input_mux *input_mux;
  68. unsigned int cur_mux[3];
  69. /* i/o switches */
  70. unsigned int io_switch[2];
  71. struct hda_pcm pcm_rec[2]; /* PCM information */
  72. /* dynamic controls and input_mux */
  73. struct auto_pin_cfg autocfg;
  74. unsigned int num_kctl_alloc, num_kctl_used;
  75. struct snd_kcontrol_new *kctl_alloc;
  76. struct hda_input_mux private_imux;
  77. };
  78. static hda_nid_t stac9200_adc_nids[1] = {
  79. 0x03,
  80. };
  81. static hda_nid_t stac9200_mux_nids[1] = {
  82. 0x0c,
  83. };
  84. static hda_nid_t stac9200_dac_nids[1] = {
  85. 0x02,
  86. };
  87. static hda_nid_t stac922x_adc_nids[2] = {
  88. 0x06, 0x07,
  89. };
  90. static hda_nid_t stac922x_mux_nids[2] = {
  91. 0x12, 0x13,
  92. };
  93. static hda_nid_t stac927x_adc_nids[3] = {
  94. 0x07, 0x08, 0x09
  95. };
  96. static hda_nid_t stac927x_mux_nids[3] = {
  97. 0x15, 0x16, 0x17
  98. };
  99. static hda_nid_t stac9200_pin_nids[8] = {
  100. 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
  101. };
  102. static hda_nid_t stac922x_pin_nids[10] = {
  103. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  104. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  105. };
  106. static hda_nid_t stac927x_pin_nids[14] = {
  107. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  108. 0x0f, 0x10, 0x11, 0x12, 0x13,
  109. 0x14, 0x21, 0x22, 0x23,
  110. };
  111. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  112. {
  113. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  114. struct sigmatel_spec *spec = codec->spec;
  115. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  116. }
  117. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  118. {
  119. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  120. struct sigmatel_spec *spec = codec->spec;
  121. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  122. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  123. return 0;
  124. }
  125. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  126. {
  127. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  128. struct sigmatel_spec *spec = codec->spec;
  129. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  130. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  131. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  132. }
  133. static struct hda_verb stac9200_core_init[] = {
  134. /* set dac0mux for dac converter */
  135. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  136. {}
  137. };
  138. static struct hda_verb stac922x_core_init[] = {
  139. /* set master volume and direct control */
  140. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  141. {}
  142. };
  143. static struct hda_verb stac927x_core_init[] = {
  144. /* set master volume and direct control */
  145. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  146. {}
  147. };
  148. static struct snd_kcontrol_new stac9200_mixer[] = {
  149. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  150. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  151. {
  152. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  153. .name = "Input Source",
  154. .count = 1,
  155. .info = stac92xx_mux_enum_info,
  156. .get = stac92xx_mux_enum_get,
  157. .put = stac92xx_mux_enum_put,
  158. },
  159. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  160. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  161. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  162. { } /* end */
  163. };
  164. /* This needs to be generated dynamically based on sequence */
  165. static struct snd_kcontrol_new stac922x_mixer[] = {
  166. {
  167. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  168. .name = "Input Source",
  169. .count = 1,
  170. .info = stac92xx_mux_enum_info,
  171. .get = stac92xx_mux_enum_get,
  172. .put = stac92xx_mux_enum_put,
  173. },
  174. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
  175. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
  176. HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  177. { } /* end */
  178. };
  179. static snd_kcontrol_new_t stac927x_mixer[] = {
  180. {
  181. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  182. .name = "Input Source",
  183. .count = 1,
  184. .info = stac92xx_mux_enum_info,
  185. .get = stac92xx_mux_enum_get,
  186. .put = stac92xx_mux_enum_put,
  187. },
  188. HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  189. HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
  190. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  191. { } /* end */
  192. };
  193. static int stac92xx_build_controls(struct hda_codec *codec)
  194. {
  195. struct sigmatel_spec *spec = codec->spec;
  196. int err;
  197. int i;
  198. err = snd_hda_add_new_ctls(codec, spec->mixer);
  199. if (err < 0)
  200. return err;
  201. for (i = 0; i < spec->num_mixers; i++) {
  202. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  203. if (err < 0)
  204. return err;
  205. }
  206. if (spec->multiout.dig_out_nid) {
  207. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  208. if (err < 0)
  209. return err;
  210. }
  211. if (spec->dig_in_nid) {
  212. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  213. if (err < 0)
  214. return err;
  215. }
  216. return 0;
  217. }
  218. static unsigned int ref9200_pin_configs[8] = {
  219. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  220. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  221. };
  222. static unsigned int *stac9200_brd_tbl[] = {
  223. ref9200_pin_configs,
  224. };
  225. static struct hda_board_config stac9200_cfg_tbl[] = {
  226. { .modelname = "ref",
  227. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  228. .pci_subdevice = 0x2668, /* DFI LanParty */
  229. .config = STAC_REF },
  230. {} /* terminator */
  231. };
  232. static unsigned int ref922x_pin_configs[10] = {
  233. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  234. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  235. 0x40000100, 0x40000100,
  236. };
  237. static unsigned int d945gtp3_pin_configs[10] = {
  238. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  239. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  240. 0x02a19120, 0x40000100,
  241. };
  242. static unsigned int d945gtp5_pin_configs[10] = {
  243. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  244. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  245. 0x02a19320, 0x40000100,
  246. };
  247. static unsigned int *stac922x_brd_tbl[] = {
  248. ref922x_pin_configs,
  249. d945gtp3_pin_configs,
  250. d945gtp5_pin_configs,
  251. };
  252. static struct hda_board_config stac922x_cfg_tbl[] = {
  253. { .modelname = "ref",
  254. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  255. .pci_subdevice = 0x2668, /* DFI LanParty */
  256. .config = STAC_REF }, /* SigmaTel reference board */
  257. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  258. .pci_subdevice = 0x0101,
  259. .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
  260. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  261. .pci_subdevice = 0x0202,
  262. .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
  263. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  264. .pci_subdevice = 0x0b0b,
  265. .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
  266. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  267. .pci_subdevice = 0x0404,
  268. .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
  269. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  270. .pci_subdevice = 0x0303,
  271. .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
  272. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  273. .pci_subdevice = 0x0013,
  274. .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
  275. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  276. .pci_subdevice = 0x0417,
  277. .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
  278. {} /* terminator */
  279. };
  280. static unsigned int ref927x_pin_configs[14] = {
  281. 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
  282. 0x01012012, 0x01011014, 0x40000100, 0x40000100,
  283. 0x40000100, 0x40000100, 0x40000100, 0x01441030,
  284. 0x01c41030, 0x40000100,
  285. };
  286. static unsigned int *stac927x_brd_tbl[] = {
  287. ref927x_pin_configs,
  288. };
  289. static struct hda_board_config stac927x_cfg_tbl[] = {
  290. { .modelname = "ref",
  291. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  292. .pci_subdevice = 0x2668, /* DFI LanParty */
  293. .config = STAC_REF }, /* SigmaTel reference board */
  294. {} /* terminator */
  295. };
  296. static void stac92xx_set_config_regs(struct hda_codec *codec)
  297. {
  298. int i;
  299. struct sigmatel_spec *spec = codec->spec;
  300. unsigned int pin_cfg;
  301. for (i=0; i < spec->num_pins; i++) {
  302. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  303. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  304. spec->pin_configs[i] & 0x000000ff);
  305. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  306. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  307. (spec->pin_configs[i] & 0x0000ff00) >> 8);
  308. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  309. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  310. (spec->pin_configs[i] & 0x00ff0000) >> 16);
  311. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  312. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  313. spec->pin_configs[i] >> 24);
  314. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  315. AC_VERB_GET_CONFIG_DEFAULT,
  316. 0x00);
  317. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
  318. }
  319. }
  320. /*
  321. * Analog playback callbacks
  322. */
  323. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  324. struct hda_codec *codec,
  325. struct snd_pcm_substream *substream)
  326. {
  327. struct sigmatel_spec *spec = codec->spec;
  328. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  329. }
  330. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  331. struct hda_codec *codec,
  332. unsigned int stream_tag,
  333. unsigned int format,
  334. struct snd_pcm_substream *substream)
  335. {
  336. struct sigmatel_spec *spec = codec->spec;
  337. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  338. }
  339. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  340. struct hda_codec *codec,
  341. struct snd_pcm_substream *substream)
  342. {
  343. struct sigmatel_spec *spec = codec->spec;
  344. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  345. }
  346. /*
  347. * Digital playback callbacks
  348. */
  349. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  350. struct hda_codec *codec,
  351. struct snd_pcm_substream *substream)
  352. {
  353. struct sigmatel_spec *spec = codec->spec;
  354. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  355. }
  356. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  357. struct hda_codec *codec,
  358. struct snd_pcm_substream *substream)
  359. {
  360. struct sigmatel_spec *spec = codec->spec;
  361. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  362. }
  363. /*
  364. * Analog capture callbacks
  365. */
  366. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  367. struct hda_codec *codec,
  368. unsigned int stream_tag,
  369. unsigned int format,
  370. struct snd_pcm_substream *substream)
  371. {
  372. struct sigmatel_spec *spec = codec->spec;
  373. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  374. stream_tag, 0, format);
  375. return 0;
  376. }
  377. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  378. struct hda_codec *codec,
  379. struct snd_pcm_substream *substream)
  380. {
  381. struct sigmatel_spec *spec = codec->spec;
  382. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  383. return 0;
  384. }
  385. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  386. .substreams = 1,
  387. .channels_min = 2,
  388. .channels_max = 2,
  389. /* NID is set in stac92xx_build_pcms */
  390. .ops = {
  391. .open = stac92xx_dig_playback_pcm_open,
  392. .close = stac92xx_dig_playback_pcm_close
  393. },
  394. };
  395. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  396. .substreams = 1,
  397. .channels_min = 2,
  398. .channels_max = 2,
  399. /* NID is set in stac92xx_build_pcms */
  400. };
  401. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  402. .substreams = 1,
  403. .channels_min = 2,
  404. .channels_max = 8,
  405. .nid = 0x02, /* NID to query formats and rates */
  406. .ops = {
  407. .open = stac92xx_playback_pcm_open,
  408. .prepare = stac92xx_playback_pcm_prepare,
  409. .cleanup = stac92xx_playback_pcm_cleanup
  410. },
  411. };
  412. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  413. .substreams = 1,
  414. .channels_min = 2,
  415. .channels_max = 2,
  416. .nid = 0x06, /* NID to query formats and rates */
  417. .ops = {
  418. .open = stac92xx_playback_pcm_open,
  419. .prepare = stac92xx_playback_pcm_prepare,
  420. .cleanup = stac92xx_playback_pcm_cleanup
  421. },
  422. };
  423. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  424. .substreams = 2,
  425. .channels_min = 2,
  426. .channels_max = 2,
  427. /* NID is set in stac92xx_build_pcms */
  428. .ops = {
  429. .prepare = stac92xx_capture_pcm_prepare,
  430. .cleanup = stac92xx_capture_pcm_cleanup
  431. },
  432. };
  433. static int stac92xx_build_pcms(struct hda_codec *codec)
  434. {
  435. struct sigmatel_spec *spec = codec->spec;
  436. struct hda_pcm *info = spec->pcm_rec;
  437. codec->num_pcms = 1;
  438. codec->pcm_info = info;
  439. info->name = "STAC92xx Analog";
  440. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  441. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  442. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  443. if (spec->alt_switch) {
  444. codec->num_pcms++;
  445. info++;
  446. info->name = "STAC92xx Analog Alt";
  447. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  448. }
  449. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  450. codec->num_pcms++;
  451. info++;
  452. info->name = "STAC92xx Digital";
  453. if (spec->multiout.dig_out_nid) {
  454. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  455. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  456. }
  457. if (spec->dig_in_nid) {
  458. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  459. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  460. }
  461. }
  462. return 0;
  463. }
  464. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  465. {
  466. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  467. }
  468. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  469. {
  470. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  471. uinfo->count = 1;
  472. uinfo->value.integer.min = 0;
  473. uinfo->value.integer.max = 1;
  474. return 0;
  475. }
  476. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  477. {
  478. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  479. struct sigmatel_spec *spec = codec->spec;
  480. int io_idx = kcontrol-> private_value & 0xff;
  481. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  482. return 0;
  483. }
  484. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  485. {
  486. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  487. struct sigmatel_spec *spec = codec->spec;
  488. hda_nid_t nid = kcontrol->private_value >> 8;
  489. int io_idx = kcontrol-> private_value & 0xff;
  490. unsigned short val = ucontrol->value.integer.value[0];
  491. spec->io_switch[io_idx] = val;
  492. if (val)
  493. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  494. else
  495. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  496. return 1;
  497. }
  498. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  499. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  500. .name = xname, \
  501. .index = 0, \
  502. .info = stac92xx_io_switch_info, \
  503. .get = stac92xx_io_switch_get, \
  504. .put = stac92xx_io_switch_put, \
  505. .private_value = xpval, \
  506. }
  507. enum {
  508. STAC_CTL_WIDGET_VOL,
  509. STAC_CTL_WIDGET_MUTE,
  510. STAC_CTL_WIDGET_IO_SWITCH,
  511. };
  512. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  513. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  514. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  515. STAC_CODEC_IO_SWITCH(NULL, 0),
  516. };
  517. /* add dynamic controls */
  518. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  519. {
  520. struct snd_kcontrol_new *knew;
  521. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  522. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  523. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  524. if (! knew)
  525. return -ENOMEM;
  526. if (spec->kctl_alloc) {
  527. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  528. kfree(spec->kctl_alloc);
  529. }
  530. spec->kctl_alloc = knew;
  531. spec->num_kctl_alloc = num;
  532. }
  533. knew = &spec->kctl_alloc[spec->num_kctl_used];
  534. *knew = stac92xx_control_templates[type];
  535. knew->name = kstrdup(name, GFP_KERNEL);
  536. if (! knew->name)
  537. return -ENOMEM;
  538. knew->private_value = val;
  539. spec->num_kctl_used++;
  540. return 0;
  541. }
  542. /* flag inputs as additional dynamic lineouts */
  543. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  544. {
  545. struct sigmatel_spec *spec = codec->spec;
  546. switch (cfg->line_outs) {
  547. case 3:
  548. /* add line-in as side */
  549. if (cfg->input_pins[AUTO_PIN_LINE]) {
  550. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
  551. spec->line_switch = 1;
  552. cfg->line_outs++;
  553. }
  554. break;
  555. case 2:
  556. /* add line-in as clfe and mic as side */
  557. if (cfg->input_pins[AUTO_PIN_LINE]) {
  558. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
  559. spec->line_switch = 1;
  560. cfg->line_outs++;
  561. }
  562. if (cfg->input_pins[AUTO_PIN_MIC]) {
  563. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
  564. spec->mic_switch = 1;
  565. cfg->line_outs++;
  566. }
  567. break;
  568. case 1:
  569. /* add line-in as surr and mic as clfe */
  570. if (cfg->input_pins[AUTO_PIN_LINE]) {
  571. cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
  572. spec->line_switch = 1;
  573. cfg->line_outs++;
  574. }
  575. if (cfg->input_pins[AUTO_PIN_MIC]) {
  576. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
  577. spec->mic_switch = 1;
  578. cfg->line_outs++;
  579. }
  580. break;
  581. }
  582. return 0;
  583. }
  584. /*
  585. * XXX The line_out pin widget connection list may not be set to the
  586. * desired DAC nid. This is the case on 927x where ports A and B can
  587. * be routed to several DACs.
  588. *
  589. * This requires an analysis of the line-out/hp pin configuration
  590. * to provide a best fit for pin/DAC configurations that are routable.
  591. * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
  592. * A and B is not supported.
  593. */
  594. /* fill in the dac_nids table from the parsed pin configuration */
  595. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  596. {
  597. struct sigmatel_spec *spec = codec->spec;
  598. hda_nid_t nid;
  599. int i;
  600. /* check the pins hardwired to audio widget */
  601. for (i = 0; i < cfg->line_outs; i++) {
  602. nid = cfg->line_out_pins[i];
  603. spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
  604. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  605. }
  606. spec->multiout.num_dacs = cfg->line_outs;
  607. return 0;
  608. }
  609. /* add playback controls from the parsed DAC table */
  610. static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
  611. {
  612. char name[32];
  613. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  614. hda_nid_t nid;
  615. int i, err;
  616. for (i = 0; i < cfg->line_outs; i++) {
  617. if (!spec->multiout.dac_nids[i])
  618. continue;
  619. nid = spec->multiout.dac_nids[i];
  620. if (i == 2) {
  621. /* Center/LFE */
  622. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
  623. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  624. return err;
  625. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
  626. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  627. return err;
  628. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
  629. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  630. return err;
  631. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
  632. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  633. return err;
  634. } else {
  635. sprintf(name, "%s Playback Volume", chname[i]);
  636. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  637. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  638. return err;
  639. sprintf(name, "%s Playback Switch", chname[i]);
  640. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  641. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  642. return err;
  643. }
  644. }
  645. if (spec->line_switch)
  646. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  647. return err;
  648. if (spec->mic_switch)
  649. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  650. return err;
  651. return 0;
  652. }
  653. /* add playback controls for HP output */
  654. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  655. {
  656. struct sigmatel_spec *spec = codec->spec;
  657. hda_nid_t pin = cfg->hp_pin;
  658. hda_nid_t nid;
  659. int i, err;
  660. unsigned int wid_caps;
  661. if (! pin)
  662. return 0;
  663. wid_caps = get_wcaps(codec, pin);
  664. if (wid_caps & AC_WCAP_UNSOL_CAP) {
  665. /* Enable unsolicited responses on the HP widget */
  666. snd_hda_codec_write(codec, pin, 0,
  667. AC_VERB_SET_UNSOLICITED_ENABLE,
  668. STAC_UNSOL_ENABLE);
  669. spec->hp_detect = 1;
  670. }
  671. nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  672. for (i = 0; i < cfg->line_outs; i++) {
  673. if (! spec->multiout.dac_nids[i])
  674. continue;
  675. if (spec->multiout.dac_nids[i] == nid)
  676. return 0;
  677. }
  678. spec->multiout.hp_nid = nid;
  679. /* control HP volume/switch on the output mixer amp */
  680. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
  681. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  682. return err;
  683. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  684. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  685. return err;
  686. return 0;
  687. }
  688. /* create playback/capture controls for input pins */
  689. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  690. {
  691. struct sigmatel_spec *spec = codec->spec;
  692. struct hda_input_mux *imux = &spec->private_imux;
  693. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  694. int i, j, k;
  695. for (i = 0; i < AUTO_PIN_LAST; i++) {
  696. int index = -1;
  697. if (cfg->input_pins[i]) {
  698. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  699. for (j=0; j<spec->num_muxes; j++) {
  700. int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
  701. for (k=0; k<num_cons; k++)
  702. if (con_lst[k] == cfg->input_pins[i]) {
  703. index = k;
  704. break;
  705. }
  706. if (index >= 0)
  707. break;
  708. }
  709. imux->items[imux->num_items].index = index;
  710. imux->num_items++;
  711. }
  712. }
  713. return 0;
  714. }
  715. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  716. {
  717. struct sigmatel_spec *spec = codec->spec;
  718. int i;
  719. for (i = 0; i < spec->autocfg.line_outs; i++) {
  720. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  721. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  722. }
  723. }
  724. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  725. {
  726. struct sigmatel_spec *spec = codec->spec;
  727. hda_nid_t pin;
  728. pin = spec->autocfg.hp_pin;
  729. if (pin) /* connect to front */
  730. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  731. }
  732. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  733. {
  734. struct sigmatel_spec *spec = codec->spec;
  735. int err;
  736. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  737. return err;
  738. if (! spec->autocfg.line_outs)
  739. return 0; /* can't find valid pin config */
  740. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  741. return err;
  742. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  743. return err;
  744. if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  745. (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
  746. (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  747. return err;
  748. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  749. if (spec->multiout.max_channels > 2)
  750. spec->surr_switch = 1;
  751. if (spec->autocfg.dig_out_pin)
  752. spec->multiout.dig_out_nid = dig_out;
  753. if (spec->autocfg.dig_in_pin)
  754. spec->dig_in_nid = dig_in;
  755. if (spec->kctl_alloc)
  756. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  757. spec->input_mux = &spec->private_imux;
  758. return 1;
  759. }
  760. /* add playback controls for HP output */
  761. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  762. struct auto_pin_cfg *cfg)
  763. {
  764. struct sigmatel_spec *spec = codec->spec;
  765. hda_nid_t pin = cfg->hp_pin;
  766. unsigned int wid_caps;
  767. if (! pin)
  768. return 0;
  769. wid_caps = get_wcaps(codec, pin);
  770. if (wid_caps & AC_WCAP_UNSOL_CAP) {
  771. /* Enable unsolicited responses on the HP widget */
  772. snd_hda_codec_write(codec, pin, 0,
  773. AC_VERB_SET_UNSOLICITED_ENABLE,
  774. STAC_UNSOL_ENABLE);
  775. spec->hp_detect = 1;
  776. }
  777. return 0;
  778. }
  779. static int stac9200_parse_auto_config(struct hda_codec *codec)
  780. {
  781. struct sigmatel_spec *spec = codec->spec;
  782. int err;
  783. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  784. return err;
  785. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  786. return err;
  787. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  788. return err;
  789. if (spec->autocfg.dig_out_pin)
  790. spec->multiout.dig_out_nid = 0x05;
  791. if (spec->autocfg.dig_in_pin)
  792. spec->dig_in_nid = 0x04;
  793. if (spec->kctl_alloc)
  794. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  795. spec->input_mux = &spec->private_imux;
  796. return 1;
  797. }
  798. static int stac92xx_init(struct hda_codec *codec)
  799. {
  800. struct sigmatel_spec *spec = codec->spec;
  801. struct auto_pin_cfg *cfg = &spec->autocfg;
  802. int i;
  803. snd_hda_sequence_write(codec, spec->init);
  804. /* set up pins */
  805. if (spec->hp_detect) {
  806. /* fake event to set up pins */
  807. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  808. } else {
  809. stac92xx_auto_init_multi_out(codec);
  810. stac92xx_auto_init_hp_out(codec);
  811. }
  812. for (i = 0; i < AUTO_PIN_LAST; i++) {
  813. if (cfg->input_pins[i])
  814. stac92xx_auto_set_pinctl(codec, cfg->input_pins[i],
  815. AC_PINCTL_IN_EN);
  816. }
  817. if (cfg->dig_out_pin)
  818. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  819. AC_PINCTL_OUT_EN);
  820. if (cfg->dig_in_pin)
  821. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  822. AC_PINCTL_IN_EN);
  823. return 0;
  824. }
  825. static void stac92xx_free(struct hda_codec *codec)
  826. {
  827. struct sigmatel_spec *spec = codec->spec;
  828. int i;
  829. if (! spec)
  830. return;
  831. if (spec->kctl_alloc) {
  832. for (i = 0; i < spec->num_kctl_used; i++)
  833. kfree(spec->kctl_alloc[i].name);
  834. kfree(spec->kctl_alloc);
  835. }
  836. kfree(spec);
  837. }
  838. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  839. unsigned int flag)
  840. {
  841. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  842. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  843. snd_hda_codec_write(codec, nid, 0,
  844. AC_VERB_SET_PIN_WIDGET_CONTROL,
  845. pin_ctl | flag);
  846. }
  847. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  848. unsigned int flag)
  849. {
  850. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  851. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  852. snd_hda_codec_write(codec, nid, 0,
  853. AC_VERB_SET_PIN_WIDGET_CONTROL,
  854. pin_ctl & ~flag);
  855. }
  856. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  857. {
  858. struct sigmatel_spec *spec = codec->spec;
  859. struct auto_pin_cfg *cfg = &spec->autocfg;
  860. int i, presence;
  861. if ((res >> 26) != STAC_HP_EVENT)
  862. return;
  863. presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
  864. AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
  865. if (presence) {
  866. /* disable lineouts, enable hp */
  867. for (i = 0; i < cfg->line_outs; i++)
  868. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  869. AC_PINCTL_OUT_EN);
  870. stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
  871. } else {
  872. /* enable lineouts, disable hp */
  873. for (i = 0; i < cfg->line_outs; i++)
  874. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  875. AC_PINCTL_OUT_EN);
  876. stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
  877. }
  878. }
  879. #ifdef CONFIG_PM
  880. static int stac92xx_resume(struct hda_codec *codec)
  881. {
  882. struct sigmatel_spec *spec = codec->spec;
  883. int i;
  884. stac92xx_init(codec);
  885. for (i = 0; i < spec->num_mixers; i++)
  886. snd_hda_resume_ctls(codec, spec->mixers[i]);
  887. if (spec->multiout.dig_out_nid)
  888. snd_hda_resume_spdif_out(codec);
  889. if (spec->dig_in_nid)
  890. snd_hda_resume_spdif_in(codec);
  891. return 0;
  892. }
  893. #endif
  894. static struct hda_codec_ops stac92xx_patch_ops = {
  895. .build_controls = stac92xx_build_controls,
  896. .build_pcms = stac92xx_build_pcms,
  897. .init = stac92xx_init,
  898. .free = stac92xx_free,
  899. .unsol_event = stac92xx_unsol_event,
  900. #ifdef CONFIG_PM
  901. .resume = stac92xx_resume,
  902. #endif
  903. };
  904. static int patch_stac9200(struct hda_codec *codec)
  905. {
  906. struct sigmatel_spec *spec;
  907. int err;
  908. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  909. if (spec == NULL)
  910. return -ENOMEM;
  911. codec->spec = spec;
  912. spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
  913. if (spec->board_config < 0)
  914. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  915. else {
  916. spec->num_pins = 8;
  917. spec->pin_nids = stac9200_pin_nids;
  918. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  919. stac92xx_set_config_regs(codec);
  920. }
  921. spec->multiout.max_channels = 2;
  922. spec->multiout.num_dacs = 1;
  923. spec->multiout.dac_nids = stac9200_dac_nids;
  924. spec->adc_nids = stac9200_adc_nids;
  925. spec->mux_nids = stac9200_mux_nids;
  926. spec->num_muxes = 1;
  927. spec->init = stac9200_core_init;
  928. spec->mixer = stac9200_mixer;
  929. err = stac9200_parse_auto_config(codec);
  930. if (err < 0) {
  931. stac92xx_free(codec);
  932. return err;
  933. }
  934. codec->patch_ops = stac92xx_patch_ops;
  935. return 0;
  936. }
  937. static int patch_stac922x(struct hda_codec *codec)
  938. {
  939. struct sigmatel_spec *spec;
  940. int err;
  941. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  942. if (spec == NULL)
  943. return -ENOMEM;
  944. codec->spec = spec;
  945. spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
  946. if (spec->board_config < 0)
  947. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
  948. else {
  949. spec->num_pins = 10;
  950. spec->pin_nids = stac922x_pin_nids;
  951. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  952. stac92xx_set_config_regs(codec);
  953. }
  954. spec->adc_nids = stac922x_adc_nids;
  955. spec->mux_nids = stac922x_mux_nids;
  956. spec->num_muxes = 2;
  957. spec->init = stac922x_core_init;
  958. spec->mixer = stac922x_mixer;
  959. spec->multiout.dac_nids = spec->dac_nids;
  960. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  961. if (err < 0) {
  962. stac92xx_free(codec);
  963. return err;
  964. }
  965. codec->patch_ops = stac92xx_patch_ops;
  966. return 0;
  967. }
  968. static int patch_stac927x(struct hda_codec *codec)
  969. {
  970. struct sigmatel_spec *spec;
  971. int err;
  972. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  973. if (spec == NULL)
  974. return -ENOMEM;
  975. codec->spec = spec;
  976. spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
  977. if (spec->board_config < 0)
  978. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  979. else {
  980. spec->num_pins = 14;
  981. spec->pin_nids = stac927x_pin_nids;
  982. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  983. stac92xx_set_config_regs(codec);
  984. }
  985. spec->adc_nids = stac927x_adc_nids;
  986. spec->mux_nids = stac927x_mux_nids;
  987. spec->num_muxes = 3;
  988. spec->init = stac927x_core_init;
  989. spec->mixer = stac927x_mixer;
  990. spec->multiout.dac_nids = spec->dac_nids;
  991. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  992. if (err < 0) {
  993. stac92xx_free(codec);
  994. return err;
  995. }
  996. codec->patch_ops = stac92xx_patch_ops;
  997. return 0;
  998. }
  999. /*
  1000. * STAC 7661(?) hack
  1001. */
  1002. /* static config for Sony VAIO FE550G */
  1003. static hda_nid_t vaio_dacs[] = { 0x2 };
  1004. #define VAIO_HP_DAC 0x5
  1005. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  1006. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  1007. static struct hda_input_mux vaio_mux = {
  1008. .num_items = 2,
  1009. .items = {
  1010. /* { "HP", 0x0 },
  1011. { "Unknown", 0x1 }, */
  1012. { "Mic", 0x2 },
  1013. { "PCM", 0x3 },
  1014. }
  1015. };
  1016. static struct hda_verb vaio_init[] = {
  1017. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  1018. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  1019. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  1020. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  1021. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  1022. {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
  1023. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  1024. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  1025. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  1026. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  1027. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  1028. {}
  1029. };
  1030. /* bind volumes of both NID 0x02 and 0x05 */
  1031. static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
  1032. struct snd_ctl_elem_value *ucontrol)
  1033. {
  1034. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1035. long *valp = ucontrol->value.integer.value;
  1036. int change;
  1037. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1038. 0x7f, valp[0] & 0x7f);
  1039. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1040. 0x7f, valp[1] & 0x7f);
  1041. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1042. 0x7f, valp[0] & 0x7f);
  1043. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1044. 0x7f, valp[1] & 0x7f);
  1045. return change;
  1046. }
  1047. /* bind volumes of both NID 0x02 and 0x05 */
  1048. static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
  1049. struct snd_ctl_elem_value *ucontrol)
  1050. {
  1051. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1052. long *valp = ucontrol->value.integer.value;
  1053. int change;
  1054. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1055. 0x80, valp[0] & 0x80);
  1056. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1057. 0x80, valp[1] & 0x80);
  1058. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1059. 0x80, valp[0] & 0x80);
  1060. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1061. 0x80, valp[1] & 0x80);
  1062. return change;
  1063. }
  1064. static struct snd_kcontrol_new vaio_mixer[] = {
  1065. {
  1066. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1067. .name = "Master Playback Volume",
  1068. .info = snd_hda_mixer_amp_volume_info,
  1069. .get = snd_hda_mixer_amp_volume_get,
  1070. .put = vaio_master_vol_put,
  1071. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1072. },
  1073. {
  1074. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1075. .name = "Master Playback Switch",
  1076. .info = snd_hda_mixer_amp_switch_info,
  1077. .get = snd_hda_mixer_amp_switch_get,
  1078. .put = vaio_master_sw_put,
  1079. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1080. },
  1081. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  1082. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  1083. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  1084. {
  1085. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1086. .name = "Capture Source",
  1087. .count = 1,
  1088. .info = stac92xx_mux_enum_info,
  1089. .get = stac92xx_mux_enum_get,
  1090. .put = stac92xx_mux_enum_put,
  1091. },
  1092. {}
  1093. };
  1094. static struct hda_codec_ops stac7661_patch_ops = {
  1095. .build_controls = stac92xx_build_controls,
  1096. .build_pcms = stac92xx_build_pcms,
  1097. .init = stac92xx_init,
  1098. .free = stac92xx_free,
  1099. #ifdef CONFIG_PM
  1100. .resume = stac92xx_resume,
  1101. #endif
  1102. };
  1103. enum { STAC7661_VAIO };
  1104. static struct hda_board_config stac7661_cfg_tbl[] = {
  1105. { .modelname = "vaio", .config = STAC7661_VAIO },
  1106. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
  1107. .config = STAC7661_VAIO },
  1108. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
  1109. .config = STAC7661_VAIO },
  1110. {}
  1111. };
  1112. static int patch_stac7661(struct hda_codec *codec)
  1113. {
  1114. struct sigmatel_spec *spec;
  1115. int board_config;
  1116. board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
  1117. if (board_config < 0)
  1118. /* unknown config, let generic-parser do its job... */
  1119. return snd_hda_parse_generic_codec(codec);
  1120. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1121. if (spec == NULL)
  1122. return -ENOMEM;
  1123. codec->spec = spec;
  1124. switch (board_config) {
  1125. case STAC7661_VAIO:
  1126. spec->mixer = vaio_mixer;
  1127. spec->init = vaio_init;
  1128. spec->multiout.max_channels = 2;
  1129. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  1130. spec->multiout.dac_nids = vaio_dacs;
  1131. spec->multiout.hp_nid = VAIO_HP_DAC;
  1132. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  1133. spec->adc_nids = vaio_adcs;
  1134. spec->input_mux = &vaio_mux;
  1135. spec->mux_nids = vaio_mux_nids;
  1136. break;
  1137. }
  1138. codec->patch_ops = stac7661_patch_ops;
  1139. return 0;
  1140. }
  1141. /*
  1142. * patch entries
  1143. */
  1144. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  1145. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  1146. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  1147. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  1148. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  1149. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  1150. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  1151. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  1152. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  1153. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  1154. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  1155. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  1156. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  1157. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  1158. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  1159. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  1160. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  1161. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  1162. { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
  1163. {} /* terminator */
  1164. };