patch_sigmatel.c 41 KB

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