patch_sigmatel.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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 = 0x0404,
  261. .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
  262. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  263. .pci_subdevice = 0x0303,
  264. .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
  265. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  266. .pci_subdevice = 0x0013,
  267. .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
  268. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  269. .pci_subdevice = 0x0417,
  270. .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
  271. {} /* terminator */
  272. };
  273. static unsigned int ref927x_pin_configs[14] = {
  274. 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
  275. 0x01012012, 0x01011014, 0x40000100, 0x40000100,
  276. 0x40000100, 0x40000100, 0x40000100, 0x01441030,
  277. 0x01c41030, 0x40000100,
  278. };
  279. static unsigned int *stac927x_brd_tbl[] = {
  280. ref927x_pin_configs,
  281. };
  282. static struct hda_board_config stac927x_cfg_tbl[] = {
  283. { .modelname = "ref",
  284. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  285. .pci_subdevice = 0x2668, /* DFI LanParty */
  286. .config = STAC_REF }, /* SigmaTel reference board */
  287. {} /* terminator */
  288. };
  289. static void stac92xx_set_config_regs(struct hda_codec *codec)
  290. {
  291. int i;
  292. struct sigmatel_spec *spec = codec->spec;
  293. unsigned int pin_cfg;
  294. for (i=0; i < spec->num_pins; i++) {
  295. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  296. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  297. spec->pin_configs[i] & 0x000000ff);
  298. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  299. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  300. (spec->pin_configs[i] & 0x0000ff00) >> 8);
  301. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  302. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  303. (spec->pin_configs[i] & 0x00ff0000) >> 16);
  304. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  305. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  306. spec->pin_configs[i] >> 24);
  307. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  308. AC_VERB_GET_CONFIG_DEFAULT,
  309. 0x00);
  310. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
  311. }
  312. }
  313. /*
  314. * Analog playback callbacks
  315. */
  316. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  317. struct hda_codec *codec,
  318. struct snd_pcm_substream *substream)
  319. {
  320. struct sigmatel_spec *spec = codec->spec;
  321. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  322. }
  323. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  324. struct hda_codec *codec,
  325. unsigned int stream_tag,
  326. unsigned int format,
  327. struct snd_pcm_substream *substream)
  328. {
  329. struct sigmatel_spec *spec = codec->spec;
  330. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  331. }
  332. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  333. struct hda_codec *codec,
  334. struct snd_pcm_substream *substream)
  335. {
  336. struct sigmatel_spec *spec = codec->spec;
  337. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  338. }
  339. /*
  340. * Digital playback callbacks
  341. */
  342. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  343. struct hda_codec *codec,
  344. struct snd_pcm_substream *substream)
  345. {
  346. struct sigmatel_spec *spec = codec->spec;
  347. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  348. }
  349. static int stac92xx_dig_playback_pcm_close(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_close(codec, &spec->multiout);
  355. }
  356. /*
  357. * Analog capture callbacks
  358. */
  359. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  360. struct hda_codec *codec,
  361. unsigned int stream_tag,
  362. unsigned int format,
  363. struct snd_pcm_substream *substream)
  364. {
  365. struct sigmatel_spec *spec = codec->spec;
  366. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  367. stream_tag, 0, format);
  368. return 0;
  369. }
  370. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  371. struct hda_codec *codec,
  372. struct snd_pcm_substream *substream)
  373. {
  374. struct sigmatel_spec *spec = codec->spec;
  375. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  376. return 0;
  377. }
  378. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  379. .substreams = 1,
  380. .channels_min = 2,
  381. .channels_max = 2,
  382. /* NID is set in stac92xx_build_pcms */
  383. .ops = {
  384. .open = stac92xx_dig_playback_pcm_open,
  385. .close = stac92xx_dig_playback_pcm_close
  386. },
  387. };
  388. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  389. .substreams = 1,
  390. .channels_min = 2,
  391. .channels_max = 2,
  392. /* NID is set in stac92xx_build_pcms */
  393. };
  394. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  395. .substreams = 1,
  396. .channels_min = 2,
  397. .channels_max = 8,
  398. .nid = 0x02, /* NID to query formats and rates */
  399. .ops = {
  400. .open = stac92xx_playback_pcm_open,
  401. .prepare = stac92xx_playback_pcm_prepare,
  402. .cleanup = stac92xx_playback_pcm_cleanup
  403. },
  404. };
  405. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  406. .substreams = 1,
  407. .channels_min = 2,
  408. .channels_max = 2,
  409. .nid = 0x06, /* NID to query formats and rates */
  410. .ops = {
  411. .open = stac92xx_playback_pcm_open,
  412. .prepare = stac92xx_playback_pcm_prepare,
  413. .cleanup = stac92xx_playback_pcm_cleanup
  414. },
  415. };
  416. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  417. .substreams = 2,
  418. .channels_min = 2,
  419. .channels_max = 2,
  420. /* NID is set in stac92xx_build_pcms */
  421. .ops = {
  422. .prepare = stac92xx_capture_pcm_prepare,
  423. .cleanup = stac92xx_capture_pcm_cleanup
  424. },
  425. };
  426. static int stac92xx_build_pcms(struct hda_codec *codec)
  427. {
  428. struct sigmatel_spec *spec = codec->spec;
  429. struct hda_pcm *info = spec->pcm_rec;
  430. codec->num_pcms = 1;
  431. codec->pcm_info = info;
  432. info->name = "STAC92xx Analog";
  433. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  434. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  435. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  436. if (spec->alt_switch) {
  437. codec->num_pcms++;
  438. info++;
  439. info->name = "STAC92xx Analog Alt";
  440. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  441. }
  442. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  443. codec->num_pcms++;
  444. info++;
  445. info->name = "STAC92xx Digital";
  446. if (spec->multiout.dig_out_nid) {
  447. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  448. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  449. }
  450. if (spec->dig_in_nid) {
  451. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  452. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  453. }
  454. }
  455. return 0;
  456. }
  457. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  458. {
  459. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  460. }
  461. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  462. {
  463. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  464. uinfo->count = 1;
  465. uinfo->value.integer.min = 0;
  466. uinfo->value.integer.max = 1;
  467. return 0;
  468. }
  469. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  470. {
  471. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  472. struct sigmatel_spec *spec = codec->spec;
  473. int io_idx = kcontrol-> private_value & 0xff;
  474. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  475. return 0;
  476. }
  477. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  478. {
  479. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  480. struct sigmatel_spec *spec = codec->spec;
  481. hda_nid_t nid = kcontrol->private_value >> 8;
  482. int io_idx = kcontrol-> private_value & 0xff;
  483. unsigned short val = ucontrol->value.integer.value[0];
  484. spec->io_switch[io_idx] = val;
  485. if (val)
  486. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  487. else
  488. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
  489. return 1;
  490. }
  491. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  492. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  493. .name = xname, \
  494. .index = 0, \
  495. .info = stac92xx_io_switch_info, \
  496. .get = stac92xx_io_switch_get, \
  497. .put = stac92xx_io_switch_put, \
  498. .private_value = xpval, \
  499. }
  500. enum {
  501. STAC_CTL_WIDGET_VOL,
  502. STAC_CTL_WIDGET_MUTE,
  503. STAC_CTL_WIDGET_IO_SWITCH,
  504. };
  505. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  506. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  507. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  508. STAC_CODEC_IO_SWITCH(NULL, 0),
  509. };
  510. /* add dynamic controls */
  511. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  512. {
  513. struct snd_kcontrol_new *knew;
  514. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  515. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  516. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  517. if (! knew)
  518. return -ENOMEM;
  519. if (spec->kctl_alloc) {
  520. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  521. kfree(spec->kctl_alloc);
  522. }
  523. spec->kctl_alloc = knew;
  524. spec->num_kctl_alloc = num;
  525. }
  526. knew = &spec->kctl_alloc[spec->num_kctl_used];
  527. *knew = stac92xx_control_templates[type];
  528. knew->name = kstrdup(name, GFP_KERNEL);
  529. if (! knew->name)
  530. return -ENOMEM;
  531. knew->private_value = val;
  532. spec->num_kctl_used++;
  533. return 0;
  534. }
  535. /* flag inputs as additional dynamic lineouts */
  536. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  537. {
  538. struct sigmatel_spec *spec = codec->spec;
  539. switch (cfg->line_outs) {
  540. case 3:
  541. /* add line-in as side */
  542. if (cfg->input_pins[AUTO_PIN_LINE]) {
  543. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
  544. spec->line_switch = 1;
  545. cfg->line_outs++;
  546. }
  547. break;
  548. case 2:
  549. /* add line-in as clfe and mic as side */
  550. if (cfg->input_pins[AUTO_PIN_LINE]) {
  551. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
  552. spec->line_switch = 1;
  553. cfg->line_outs++;
  554. }
  555. if (cfg->input_pins[AUTO_PIN_MIC]) {
  556. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
  557. spec->mic_switch = 1;
  558. cfg->line_outs++;
  559. }
  560. break;
  561. case 1:
  562. /* add line-in as surr and mic as clfe */
  563. if (cfg->input_pins[AUTO_PIN_LINE]) {
  564. cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
  565. spec->line_switch = 1;
  566. cfg->line_outs++;
  567. }
  568. if (cfg->input_pins[AUTO_PIN_MIC]) {
  569. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
  570. spec->mic_switch = 1;
  571. cfg->line_outs++;
  572. }
  573. break;
  574. }
  575. return 0;
  576. }
  577. /*
  578. * XXX The line_out pin widget connection list may not be set to the
  579. * desired DAC nid. This is the case on 927x where ports A and B can
  580. * be routed to several DACs.
  581. *
  582. * This requires an analysis of the line-out/hp pin configuration
  583. * to provide a best fit for pin/DAC configurations that are routable.
  584. * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
  585. * A and B is not supported.
  586. */
  587. /* fill in the dac_nids table from the parsed pin configuration */
  588. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  589. {
  590. struct sigmatel_spec *spec = codec->spec;
  591. hda_nid_t nid;
  592. int i;
  593. /* check the pins hardwired to audio widget */
  594. for (i = 0; i < cfg->line_outs; i++) {
  595. nid = cfg->line_out_pins[i];
  596. spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
  597. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  598. }
  599. if (cfg->line_outs)
  600. spec->multiout.num_dacs = cfg->line_outs;
  601. else if (cfg->hp_pin) {
  602. spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
  603. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  604. spec->multiout.num_dacs = 1;
  605. }
  606. return 0;
  607. }
  608. /* add playback controls from the parsed DAC table */
  609. static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
  610. {
  611. char name[32];
  612. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  613. hda_nid_t nid;
  614. int i, err;
  615. for (i = 0; i < cfg->line_outs; i++) {
  616. if (!spec->multiout.dac_nids[i])
  617. continue;
  618. nid = spec->multiout.dac_nids[i];
  619. if (i == 2) {
  620. /* Center/LFE */
  621. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
  622. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  623. return err;
  624. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
  625. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  626. return err;
  627. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
  628. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  629. return err;
  630. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
  631. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  632. return err;
  633. } else {
  634. sprintf(name, "%s Playback Volume", chname[i]);
  635. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  636. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  637. return err;
  638. sprintf(name, "%s Playback Switch", chname[i]);
  639. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  640. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  641. return err;
  642. }
  643. }
  644. if (spec->line_switch)
  645. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  646. return err;
  647. if (spec->mic_switch)
  648. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  649. return err;
  650. return 0;
  651. }
  652. /* add playback controls for HP output */
  653. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  654. {
  655. struct sigmatel_spec *spec = codec->spec;
  656. hda_nid_t pin = cfg->hp_pin;
  657. hda_nid_t nid;
  658. int i, err;
  659. unsigned int wid_caps;
  660. if (! pin)
  661. return 0;
  662. wid_caps = get_wcaps(codec, pin);
  663. if (wid_caps & AC_WCAP_UNSOL_CAP)
  664. /* Enable unsolicited responses on the HP widget */
  665. snd_hda_codec_write(codec, pin, 0,
  666. AC_VERB_SET_UNSOLICITED_ENABLE,
  667. STAC_UNSOL_ENABLE);
  668. nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  669. for (i = 0; i < cfg->line_outs; i++) {
  670. if (! spec->multiout.dac_nids[i])
  671. continue;
  672. if (spec->multiout.dac_nids[i] == nid)
  673. return 0;
  674. }
  675. spec->multiout.hp_nid = nid;
  676. /* control HP volume/switch on the output mixer amp */
  677. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
  678. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  679. return err;
  680. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  681. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  682. return err;
  683. return 0;
  684. }
  685. /* create playback/capture controls for input pins */
  686. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  687. {
  688. struct sigmatel_spec *spec = codec->spec;
  689. struct hda_input_mux *imux = &spec->private_imux;
  690. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  691. int i, j, k;
  692. for (i = 0; i < AUTO_PIN_LAST; i++) {
  693. int index = -1;
  694. if (cfg->input_pins[i]) {
  695. /* Enable active pin widget as an input */
  696. stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
  697. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  698. for (j=0; j<spec->num_muxes; j++) {
  699. int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
  700. for (k=0; k<num_cons; k++)
  701. if (con_lst[k] == cfg->input_pins[i]) {
  702. index = k;
  703. break;
  704. }
  705. if (index >= 0)
  706. break;
  707. }
  708. imux->items[imux->num_items].index = index;
  709. imux->num_items++;
  710. }
  711. }
  712. return 0;
  713. }
  714. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  715. {
  716. struct sigmatel_spec *spec = codec->spec;
  717. int i;
  718. for (i = 0; i < spec->autocfg.line_outs; i++) {
  719. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  720. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  721. }
  722. }
  723. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  724. {
  725. struct sigmatel_spec *spec = codec->spec;
  726. hda_nid_t pin;
  727. pin = spec->autocfg.hp_pin;
  728. if (pin) /* connect to front */
  729. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  730. }
  731. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  732. {
  733. struct sigmatel_spec *spec = codec->spec;
  734. int err;
  735. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  736. return err;
  737. if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
  738. return 0; /* can't find valid pin config */
  739. stac92xx_auto_init_multi_out(codec);
  740. stac92xx_auto_init_hp_out(codec);
  741. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  742. return err;
  743. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  744. return err;
  745. if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  746. (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
  747. (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  748. return err;
  749. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  750. if (spec->multiout.max_channels > 2)
  751. spec->surr_switch = 1;
  752. if (spec->autocfg.dig_out_pin) {
  753. spec->multiout.dig_out_nid = dig_out;
  754. stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
  755. }
  756. if (spec->autocfg.dig_in_pin) {
  757. spec->dig_in_nid = dig_in;
  758. stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
  759. }
  760. if (spec->kctl_alloc)
  761. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  762. spec->input_mux = &spec->private_imux;
  763. return 1;
  764. }
  765. static int stac9200_parse_auto_config(struct hda_codec *codec)
  766. {
  767. struct sigmatel_spec *spec = codec->spec;
  768. int err;
  769. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  770. return err;
  771. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  772. return err;
  773. if (spec->autocfg.dig_out_pin) {
  774. spec->multiout.dig_out_nid = 0x05;
  775. stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
  776. }
  777. if (spec->autocfg.dig_in_pin) {
  778. spec->dig_in_nid = 0x04;
  779. stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
  780. }
  781. if (spec->kctl_alloc)
  782. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  783. spec->input_mux = &spec->private_imux;
  784. return 1;
  785. }
  786. static int stac92xx_init(struct hda_codec *codec)
  787. {
  788. struct sigmatel_spec *spec = codec->spec;
  789. snd_hda_sequence_write(codec, spec->init);
  790. return 0;
  791. }
  792. static void stac92xx_free(struct hda_codec *codec)
  793. {
  794. struct sigmatel_spec *spec = codec->spec;
  795. int i;
  796. if (! spec)
  797. return;
  798. if (spec->kctl_alloc) {
  799. for (i = 0; i < spec->num_kctl_used; i++)
  800. kfree(spec->kctl_alloc[i].name);
  801. kfree(spec->kctl_alloc);
  802. }
  803. kfree(spec);
  804. }
  805. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  806. unsigned int flag)
  807. {
  808. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  809. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  810. snd_hda_codec_write(codec, nid, 0,
  811. AC_VERB_SET_PIN_WIDGET_CONTROL,
  812. pin_ctl | flag);
  813. }
  814. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  815. unsigned int flag)
  816. {
  817. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  818. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  819. snd_hda_codec_write(codec, nid, 0,
  820. AC_VERB_SET_PIN_WIDGET_CONTROL,
  821. pin_ctl & ~flag);
  822. }
  823. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  824. {
  825. struct sigmatel_spec *spec = codec->spec;
  826. struct auto_pin_cfg *cfg = &spec->autocfg;
  827. int i, presence;
  828. if ((res >> 26) != STAC_HP_EVENT)
  829. return;
  830. presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
  831. AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
  832. if (presence) {
  833. /* disable lineouts, enable hp */
  834. for (i = 0; i < cfg->line_outs; i++)
  835. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  836. AC_PINCTL_OUT_EN);
  837. stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
  838. } else {
  839. /* enable lineouts, disable hp */
  840. for (i = 0; i < cfg->line_outs; i++)
  841. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  842. AC_PINCTL_OUT_EN);
  843. stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
  844. }
  845. }
  846. #ifdef CONFIG_PM
  847. static int stac92xx_resume(struct hda_codec *codec)
  848. {
  849. struct sigmatel_spec *spec = codec->spec;
  850. int i;
  851. stac92xx_init(codec);
  852. for (i = 0; i < spec->num_mixers; i++)
  853. snd_hda_resume_ctls(codec, spec->mixers[i]);
  854. if (spec->multiout.dig_out_nid)
  855. snd_hda_resume_spdif_out(codec);
  856. if (spec->dig_in_nid)
  857. snd_hda_resume_spdif_in(codec);
  858. return 0;
  859. }
  860. #endif
  861. static struct hda_codec_ops stac92xx_patch_ops = {
  862. .build_controls = stac92xx_build_controls,
  863. .build_pcms = stac92xx_build_pcms,
  864. .init = stac92xx_init,
  865. .free = stac92xx_free,
  866. .unsol_event = stac92xx_unsol_event,
  867. #ifdef CONFIG_PM
  868. .resume = stac92xx_resume,
  869. #endif
  870. };
  871. static int patch_stac9200(struct hda_codec *codec)
  872. {
  873. struct sigmatel_spec *spec;
  874. int err;
  875. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  876. if (spec == NULL)
  877. return -ENOMEM;
  878. codec->spec = spec;
  879. spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
  880. if (spec->board_config < 0)
  881. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  882. else {
  883. spec->num_pins = 8;
  884. spec->pin_nids = stac9200_pin_nids;
  885. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  886. stac92xx_set_config_regs(codec);
  887. }
  888. spec->multiout.max_channels = 2;
  889. spec->multiout.num_dacs = 1;
  890. spec->multiout.dac_nids = stac9200_dac_nids;
  891. spec->adc_nids = stac9200_adc_nids;
  892. spec->mux_nids = stac9200_mux_nids;
  893. spec->num_muxes = 1;
  894. spec->init = stac9200_core_init;
  895. spec->mixer = stac9200_mixer;
  896. err = stac9200_parse_auto_config(codec);
  897. if (err < 0) {
  898. stac92xx_free(codec);
  899. return err;
  900. }
  901. codec->patch_ops = stac92xx_patch_ops;
  902. return 0;
  903. }
  904. static int patch_stac922x(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, stac922x_cfg_tbl);
  913. if (spec->board_config < 0)
  914. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
  915. else {
  916. spec->num_pins = 10;
  917. spec->pin_nids = stac922x_pin_nids;
  918. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  919. stac92xx_set_config_regs(codec);
  920. }
  921. spec->adc_nids = stac922x_adc_nids;
  922. spec->mux_nids = stac922x_mux_nids;
  923. spec->num_muxes = 2;
  924. spec->init = stac922x_core_init;
  925. spec->mixer = stac922x_mixer;
  926. spec->multiout.dac_nids = spec->dac_nids;
  927. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  928. if (err < 0) {
  929. stac92xx_free(codec);
  930. return err;
  931. }
  932. codec->patch_ops = stac92xx_patch_ops;
  933. return 0;
  934. }
  935. static int patch_stac927x(struct hda_codec *codec)
  936. {
  937. struct sigmatel_spec *spec;
  938. int err;
  939. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  940. if (spec == NULL)
  941. return -ENOMEM;
  942. codec->spec = spec;
  943. spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
  944. if (spec->board_config < 0)
  945. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  946. else {
  947. spec->num_pins = 14;
  948. spec->pin_nids = stac927x_pin_nids;
  949. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  950. stac92xx_set_config_regs(codec);
  951. }
  952. spec->adc_nids = stac927x_adc_nids;
  953. spec->mux_nids = stac927x_mux_nids;
  954. spec->num_muxes = 3;
  955. spec->init = stac927x_core_init;
  956. spec->mixer = stac927x_mixer;
  957. spec->multiout.dac_nids = spec->dac_nids;
  958. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  959. if (err < 0) {
  960. stac92xx_free(codec);
  961. return err;
  962. }
  963. codec->patch_ops = stac92xx_patch_ops;
  964. return 0;
  965. }
  966. /*
  967. * patch entries
  968. */
  969. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  970. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  971. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  972. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  973. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  974. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  975. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  976. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  977. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  978. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  979. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  980. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  981. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  982. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  983. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  984. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  985. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  986. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  987. {} /* terminator */
  988. };