patch_sigmatel.c 33 KB

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