patch_sigmatel.c 39 KB

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