patch_sigmatel.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  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. enum {
  38. STAC_REF,
  39. STAC_9200_MODELS
  40. };
  41. enum {
  42. STAC_9205_REF,
  43. STAC_9205_MODELS
  44. };
  45. enum {
  46. STAC_D945_REF,
  47. STAC_D945GTP3,
  48. STAC_D945GTP5,
  49. STAC_MACMINI,
  50. STAC_922X_MODELS
  51. };
  52. enum {
  53. STAC_D965_REF,
  54. STAC_D965_3ST,
  55. STAC_D965_5ST,
  56. STAC_927X_MODELS
  57. };
  58. struct sigmatel_spec {
  59. struct snd_kcontrol_new *mixers[4];
  60. unsigned int num_mixers;
  61. int board_config;
  62. unsigned int surr_switch: 1;
  63. unsigned int line_switch: 1;
  64. unsigned int mic_switch: 1;
  65. unsigned int alt_switch: 1;
  66. unsigned int hp_detect: 1;
  67. unsigned int gpio_mute: 1;
  68. /* playback */
  69. struct hda_multi_out multiout;
  70. hda_nid_t dac_nids[5];
  71. /* capture */
  72. hda_nid_t *adc_nids;
  73. unsigned int num_adcs;
  74. hda_nid_t *mux_nids;
  75. unsigned int num_muxes;
  76. hda_nid_t *dmic_nids;
  77. unsigned int num_dmics;
  78. hda_nid_t dmux_nid;
  79. hda_nid_t dig_in_nid;
  80. /* pin widgets */
  81. hda_nid_t *pin_nids;
  82. unsigned int num_pins;
  83. unsigned int *pin_configs;
  84. unsigned int *bios_pin_configs;
  85. /* codec specific stuff */
  86. struct hda_verb *init;
  87. struct snd_kcontrol_new *mixer;
  88. /* capture source */
  89. struct hda_input_mux *dinput_mux;
  90. unsigned int cur_dmux;
  91. struct hda_input_mux *input_mux;
  92. unsigned int cur_mux[3];
  93. /* i/o switches */
  94. unsigned int io_switch[2];
  95. struct hda_pcm pcm_rec[2]; /* PCM information */
  96. /* dynamic controls and input_mux */
  97. struct auto_pin_cfg autocfg;
  98. unsigned int num_kctl_alloc, num_kctl_used;
  99. struct snd_kcontrol_new *kctl_alloc;
  100. struct hda_input_mux private_dimux;
  101. struct hda_input_mux private_imux;
  102. };
  103. static hda_nid_t stac9200_adc_nids[1] = {
  104. 0x03,
  105. };
  106. static hda_nid_t stac9200_mux_nids[1] = {
  107. 0x0c,
  108. };
  109. static hda_nid_t stac9200_dac_nids[1] = {
  110. 0x02,
  111. };
  112. static hda_nid_t stac922x_adc_nids[2] = {
  113. 0x06, 0x07,
  114. };
  115. static hda_nid_t stac922x_mux_nids[2] = {
  116. 0x12, 0x13,
  117. };
  118. static hda_nid_t stac927x_adc_nids[3] = {
  119. 0x07, 0x08, 0x09
  120. };
  121. static hda_nid_t stac927x_mux_nids[3] = {
  122. 0x15, 0x16, 0x17
  123. };
  124. static hda_nid_t stac9205_adc_nids[2] = {
  125. 0x12, 0x13
  126. };
  127. static hda_nid_t stac9205_mux_nids[2] = {
  128. 0x19, 0x1a
  129. };
  130. static hda_nid_t stac9205_dmic_nids[3] = {
  131. 0x17, 0x18, 0
  132. };
  133. static hda_nid_t stac9200_pin_nids[8] = {
  134. 0x08, 0x09, 0x0d, 0x0e,
  135. 0x0f, 0x10, 0x11, 0x12,
  136. };
  137. static hda_nid_t stac922x_pin_nids[10] = {
  138. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  139. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  140. };
  141. static hda_nid_t stac927x_pin_nids[14] = {
  142. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  143. 0x0f, 0x10, 0x11, 0x12, 0x13,
  144. 0x14, 0x21, 0x22, 0x23,
  145. };
  146. static hda_nid_t stac9205_pin_nids[12] = {
  147. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  148. 0x0f, 0x14, 0x16, 0x17, 0x18,
  149. 0x21, 0x22,
  150. };
  151. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  152. struct snd_ctl_elem_info *uinfo)
  153. {
  154. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  155. struct sigmatel_spec *spec = codec->spec;
  156. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  157. }
  158. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  159. struct snd_ctl_elem_value *ucontrol)
  160. {
  161. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  162. struct sigmatel_spec *spec = codec->spec;
  163. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  164. return 0;
  165. }
  166. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  167. struct snd_ctl_elem_value *ucontrol)
  168. {
  169. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  170. struct sigmatel_spec *spec = codec->spec;
  171. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  172. spec->dmux_nid, &spec->cur_dmux);
  173. }
  174. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  175. {
  176. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  177. struct sigmatel_spec *spec = codec->spec;
  178. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  179. }
  180. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  181. {
  182. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  183. struct sigmatel_spec *spec = codec->spec;
  184. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  185. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  186. return 0;
  187. }
  188. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  189. {
  190. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  191. struct sigmatel_spec *spec = codec->spec;
  192. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  193. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  194. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  195. }
  196. static struct hda_verb stac9200_core_init[] = {
  197. /* set dac0mux for dac converter */
  198. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  199. {}
  200. };
  201. static struct hda_verb stac922x_core_init[] = {
  202. /* set master volume and direct control */
  203. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  204. {}
  205. };
  206. static struct hda_verb d965_core_init[] = {
  207. /* set master volume and direct control */
  208. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  209. /* unmute node 0x1b */
  210. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  211. /* select node 0x03 as DAC */
  212. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  213. {}
  214. };
  215. static struct hda_verb stac927x_core_init[] = {
  216. /* set master volume and direct control */
  217. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  218. {}
  219. };
  220. static struct hda_verb stac9205_core_init[] = {
  221. /* set master volume and direct control */
  222. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  223. {}
  224. };
  225. static struct snd_kcontrol_new stac9200_mixer[] = {
  226. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  227. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  228. {
  229. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  230. .name = "Input Source",
  231. .count = 1,
  232. .info = stac92xx_mux_enum_info,
  233. .get = stac92xx_mux_enum_get,
  234. .put = stac92xx_mux_enum_put,
  235. },
  236. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  237. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  238. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  239. { } /* end */
  240. };
  241. /* This needs to be generated dynamically based on sequence */
  242. static struct snd_kcontrol_new stac922x_mixer[] = {
  243. {
  244. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  245. .name = "Input Source",
  246. .count = 1,
  247. .info = stac92xx_mux_enum_info,
  248. .get = stac92xx_mux_enum_get,
  249. .put = stac92xx_mux_enum_put,
  250. },
  251. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
  252. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
  253. HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  254. { } /* end */
  255. };
  256. /* This needs to be generated dynamically based on sequence */
  257. static struct snd_kcontrol_new stac9227_mixer[] = {
  258. {
  259. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  260. .name = "Input Source",
  261. .count = 1,
  262. .info = stac92xx_mux_enum_info,
  263. .get = stac92xx_mux_enum_get,
  264. .put = stac92xx_mux_enum_put,
  265. },
  266. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  267. HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  268. { } /* end */
  269. };
  270. static struct snd_kcontrol_new stac927x_mixer[] = {
  271. {
  272. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  273. .name = "Input Source",
  274. .count = 1,
  275. .info = stac92xx_mux_enum_info,
  276. .get = stac92xx_mux_enum_get,
  277. .put = stac92xx_mux_enum_put,
  278. },
  279. HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  280. HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
  281. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  282. { } /* end */
  283. };
  284. static struct snd_kcontrol_new stac9205_mixer[] = {
  285. {
  286. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  287. .name = "Digital Input Source",
  288. .count = 1,
  289. .info = stac92xx_dmux_enum_info,
  290. .get = stac92xx_dmux_enum_get,
  291. .put = stac92xx_dmux_enum_put,
  292. },
  293. {
  294. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  295. .name = "Input Source",
  296. .count = 1,
  297. .info = stac92xx_mux_enum_info,
  298. .get = stac92xx_mux_enum_get,
  299. .put = stac92xx_mux_enum_put,
  300. },
  301. HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
  302. HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
  303. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
  304. { } /* end */
  305. };
  306. static int stac92xx_build_controls(struct hda_codec *codec)
  307. {
  308. struct sigmatel_spec *spec = codec->spec;
  309. int err;
  310. int i;
  311. err = snd_hda_add_new_ctls(codec, spec->mixer);
  312. if (err < 0)
  313. return err;
  314. for (i = 0; i < spec->num_mixers; i++) {
  315. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  316. if (err < 0)
  317. return err;
  318. }
  319. if (spec->multiout.dig_out_nid) {
  320. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  321. if (err < 0)
  322. return err;
  323. }
  324. if (spec->dig_in_nid) {
  325. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  326. if (err < 0)
  327. return err;
  328. }
  329. return 0;
  330. }
  331. static unsigned int ref9200_pin_configs[8] = {
  332. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  333. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  334. };
  335. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  336. [STAC_REF] = ref9200_pin_configs,
  337. };
  338. static const char *stac9200_models[STAC_9200_MODELS] = {
  339. [STAC_REF] = "ref",
  340. };
  341. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  342. /* SigmaTel reference board */
  343. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  344. "DFI LanParty", STAC_REF),
  345. /* Dell laptops have BIOS problem */
  346. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  347. "Dell Inspiron 630m", STAC_REF),
  348. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  349. "Dell Latitude D620", STAC_REF),
  350. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  351. "Dell Latitude 120L", STAC_REF),
  352. {} /* terminator */
  353. };
  354. static unsigned int ref922x_pin_configs[10] = {
  355. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  356. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  357. 0x40000100, 0x40000100,
  358. };
  359. static unsigned int d945gtp3_pin_configs[10] = {
  360. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  361. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  362. 0x02a19120, 0x40000100,
  363. };
  364. static unsigned int d945gtp5_pin_configs[10] = {
  365. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  366. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  367. 0x02a19320, 0x40000100,
  368. };
  369. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  370. [STAC_D945_REF] = ref922x_pin_configs,
  371. [STAC_D945GTP3] = d945gtp3_pin_configs,
  372. [STAC_D945GTP5] = d945gtp5_pin_configs,
  373. [STAC_MACMINI] = d945gtp5_pin_configs,
  374. };
  375. static const char *stac922x_models[STAC_922X_MODELS] = {
  376. [STAC_D945_REF] = "ref",
  377. [STAC_D945GTP5] = "5stack",
  378. [STAC_D945GTP3] = "3stack",
  379. [STAC_MACMINI] = "macmini",
  380. };
  381. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  382. /* SigmaTel reference board */
  383. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  384. "DFI LanParty", STAC_D945_REF),
  385. /* Intel 945G based systems */
  386. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  387. "Intel D945G", STAC_D945GTP3),
  388. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  389. "Intel D945G", STAC_D945GTP3),
  390. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  391. "Intel D945G", STAC_D945GTP3),
  392. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  393. "Intel D945G", STAC_D945GTP3),
  394. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  395. "Intel D945G", STAC_D945GTP3),
  396. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  397. "Intel D945G", STAC_D945GTP3),
  398. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  399. "Intel D945G", STAC_D945GTP3),
  400. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  401. "Intel D945G", STAC_D945GTP3),
  402. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  403. "Intel D945G", STAC_D945GTP3),
  404. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  405. "Intel D945G", STAC_D945GTP3),
  406. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  407. "Intel D945G", STAC_D945GTP3),
  408. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  409. "Intel D945G", STAC_D945GTP3),
  410. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  411. "Intel D945G", STAC_D945GTP3),
  412. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  413. "Intel D945G", STAC_D945GTP3),
  414. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  415. "Intel D945G", STAC_D945GTP3),
  416. /* Intel D945G 5-stack systems */
  417. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  418. "Intel D945G", STAC_D945GTP5),
  419. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  420. "Intel D945G", STAC_D945GTP5),
  421. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  422. "Intel D945G", STAC_D945GTP5),
  423. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  424. "Intel D945G", STAC_D945GTP5),
  425. /* Intel 945P based systems */
  426. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  427. "Intel D945P", STAC_D945GTP3),
  428. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  429. "Intel D945P", STAC_D945GTP3),
  430. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  431. "Intel D945P", STAC_D945GTP3),
  432. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  433. "Intel D945P", STAC_D945GTP3),
  434. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  435. "Intel D945P", STAC_D945GTP3),
  436. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  437. "Intel D945P", STAC_D945GTP5),
  438. /* other systems */
  439. /* Apple Mac Mini (early 2006) */
  440. SND_PCI_QUIRK(0x8384, 0x7680,
  441. "Mac Mini", STAC_MACMINI),
  442. {} /* terminator */
  443. };
  444. static unsigned int ref927x_pin_configs[14] = {
  445. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  446. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  447. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  448. 0x01c42190, 0x40000100,
  449. };
  450. static unsigned int d965_3st_pin_configs[14] = {
  451. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  452. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  453. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  454. 0x40000100, 0x40000100
  455. };
  456. static unsigned int d965_5st_pin_configs[14] = {
  457. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  458. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  459. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  460. 0x40000100, 0x40000100
  461. };
  462. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  463. [STAC_D965_REF] = ref927x_pin_configs,
  464. [STAC_D965_3ST] = d965_3st_pin_configs,
  465. [STAC_D965_5ST] = d965_5st_pin_configs,
  466. };
  467. static const char *stac927x_models[STAC_927X_MODELS] = {
  468. [STAC_D965_REF] = "ref",
  469. [STAC_D965_3ST] = "3stack",
  470. [STAC_D965_5ST] = "5stack",
  471. };
  472. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  473. /* SigmaTel reference board */
  474. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  475. "DFI LanParty", STAC_D965_REF),
  476. /* Intel 946 based systems */
  477. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  478. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  479. /* 965 based 3 stack systems */
  480. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
  481. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
  482. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
  483. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
  484. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
  485. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
  486. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
  487. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
  488. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
  489. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
  490. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
  491. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
  492. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
  493. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
  494. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
  495. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
  496. /* 965 based 5 stack systems */
  497. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
  498. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
  499. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
  500. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
  501. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
  502. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
  503. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
  504. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
  505. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
  506. {} /* terminator */
  507. };
  508. static unsigned int ref9205_pin_configs[12] = {
  509. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  510. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  511. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  512. };
  513. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  514. ref9205_pin_configs,
  515. };
  516. static const char *stac9205_models[STAC_9205_MODELS] = {
  517. [STAC_9205_REF] = "ref",
  518. };
  519. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  520. /* SigmaTel reference board */
  521. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  522. "DFI LanParty", STAC_9205_REF),
  523. {} /* terminator */
  524. };
  525. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  526. {
  527. int i;
  528. struct sigmatel_spec *spec = codec->spec;
  529. if (! spec->bios_pin_configs) {
  530. spec->bios_pin_configs = kcalloc(spec->num_pins,
  531. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  532. if (! spec->bios_pin_configs)
  533. return -ENOMEM;
  534. }
  535. for (i = 0; i < spec->num_pins; i++) {
  536. hda_nid_t nid = spec->pin_nids[i];
  537. unsigned int pin_cfg;
  538. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  539. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  540. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  541. nid, pin_cfg);
  542. spec->bios_pin_configs[i] = pin_cfg;
  543. }
  544. return 0;
  545. }
  546. static void stac92xx_set_config_regs(struct hda_codec *codec)
  547. {
  548. int i;
  549. struct sigmatel_spec *spec = codec->spec;
  550. unsigned int pin_cfg;
  551. if (! spec->pin_nids || ! spec->pin_configs)
  552. return;
  553. for (i = 0; i < spec->num_pins; i++) {
  554. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  555. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  556. spec->pin_configs[i] & 0x000000ff);
  557. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  558. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  559. (spec->pin_configs[i] & 0x0000ff00) >> 8);
  560. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  561. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  562. (spec->pin_configs[i] & 0x00ff0000) >> 16);
  563. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  564. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  565. spec->pin_configs[i] >> 24);
  566. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  567. AC_VERB_GET_CONFIG_DEFAULT,
  568. 0x00);
  569. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
  570. }
  571. }
  572. /*
  573. * Analog playback callbacks
  574. */
  575. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  576. struct hda_codec *codec,
  577. struct snd_pcm_substream *substream)
  578. {
  579. struct sigmatel_spec *spec = codec->spec;
  580. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  581. }
  582. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  583. struct hda_codec *codec,
  584. unsigned int stream_tag,
  585. unsigned int format,
  586. struct snd_pcm_substream *substream)
  587. {
  588. struct sigmatel_spec *spec = codec->spec;
  589. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  590. }
  591. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  592. struct hda_codec *codec,
  593. struct snd_pcm_substream *substream)
  594. {
  595. struct sigmatel_spec *spec = codec->spec;
  596. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  597. }
  598. /*
  599. * Digital playback callbacks
  600. */
  601. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  602. struct hda_codec *codec,
  603. struct snd_pcm_substream *substream)
  604. {
  605. struct sigmatel_spec *spec = codec->spec;
  606. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  607. }
  608. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  609. struct hda_codec *codec,
  610. struct snd_pcm_substream *substream)
  611. {
  612. struct sigmatel_spec *spec = codec->spec;
  613. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  614. }
  615. /*
  616. * Analog capture callbacks
  617. */
  618. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  619. struct hda_codec *codec,
  620. unsigned int stream_tag,
  621. unsigned int format,
  622. struct snd_pcm_substream *substream)
  623. {
  624. struct sigmatel_spec *spec = codec->spec;
  625. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  626. stream_tag, 0, format);
  627. return 0;
  628. }
  629. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  630. struct hda_codec *codec,
  631. struct snd_pcm_substream *substream)
  632. {
  633. struct sigmatel_spec *spec = codec->spec;
  634. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  635. return 0;
  636. }
  637. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  638. .substreams = 1,
  639. .channels_min = 2,
  640. .channels_max = 2,
  641. /* NID is set in stac92xx_build_pcms */
  642. .ops = {
  643. .open = stac92xx_dig_playback_pcm_open,
  644. .close = stac92xx_dig_playback_pcm_close
  645. },
  646. };
  647. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  648. .substreams = 1,
  649. .channels_min = 2,
  650. .channels_max = 2,
  651. /* NID is set in stac92xx_build_pcms */
  652. };
  653. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  654. .substreams = 1,
  655. .channels_min = 2,
  656. .channels_max = 8,
  657. .nid = 0x02, /* NID to query formats and rates */
  658. .ops = {
  659. .open = stac92xx_playback_pcm_open,
  660. .prepare = stac92xx_playback_pcm_prepare,
  661. .cleanup = stac92xx_playback_pcm_cleanup
  662. },
  663. };
  664. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  665. .substreams = 1,
  666. .channels_min = 2,
  667. .channels_max = 2,
  668. .nid = 0x06, /* NID to query formats and rates */
  669. .ops = {
  670. .open = stac92xx_playback_pcm_open,
  671. .prepare = stac92xx_playback_pcm_prepare,
  672. .cleanup = stac92xx_playback_pcm_cleanup
  673. },
  674. };
  675. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  676. .substreams = 2,
  677. .channels_min = 2,
  678. .channels_max = 2,
  679. /* NID is set in stac92xx_build_pcms */
  680. .ops = {
  681. .prepare = stac92xx_capture_pcm_prepare,
  682. .cleanup = stac92xx_capture_pcm_cleanup
  683. },
  684. };
  685. static int stac92xx_build_pcms(struct hda_codec *codec)
  686. {
  687. struct sigmatel_spec *spec = codec->spec;
  688. struct hda_pcm *info = spec->pcm_rec;
  689. codec->num_pcms = 1;
  690. codec->pcm_info = info;
  691. info->name = "STAC92xx Analog";
  692. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  693. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  694. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  695. if (spec->alt_switch) {
  696. codec->num_pcms++;
  697. info++;
  698. info->name = "STAC92xx Analog Alt";
  699. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  700. }
  701. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  702. codec->num_pcms++;
  703. info++;
  704. info->name = "STAC92xx Digital";
  705. if (spec->multiout.dig_out_nid) {
  706. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  707. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  708. }
  709. if (spec->dig_in_nid) {
  710. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  711. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  712. }
  713. }
  714. return 0;
  715. }
  716. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  717. {
  718. unsigned int pincap = snd_hda_param_read(codec, nid,
  719. AC_PAR_PIN_CAP);
  720. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  721. if (pincap & AC_PINCAP_VREF_100)
  722. return AC_PINCTL_VREF_100;
  723. if (pincap & AC_PINCAP_VREF_80)
  724. return AC_PINCTL_VREF_80;
  725. if (pincap & AC_PINCAP_VREF_50)
  726. return AC_PINCTL_VREF_50;
  727. if (pincap & AC_PINCAP_VREF_GRD)
  728. return AC_PINCTL_VREF_GRD;
  729. return 0;
  730. }
  731. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  732. {
  733. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  734. }
  735. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  736. {
  737. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  738. uinfo->count = 1;
  739. uinfo->value.integer.min = 0;
  740. uinfo->value.integer.max = 1;
  741. return 0;
  742. }
  743. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  744. {
  745. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  746. struct sigmatel_spec *spec = codec->spec;
  747. int io_idx = kcontrol-> private_value & 0xff;
  748. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  749. return 0;
  750. }
  751. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  752. {
  753. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  754. struct sigmatel_spec *spec = codec->spec;
  755. hda_nid_t nid = kcontrol->private_value >> 8;
  756. int io_idx = kcontrol-> private_value & 0xff;
  757. unsigned short val = ucontrol->value.integer.value[0];
  758. spec->io_switch[io_idx] = val;
  759. if (val)
  760. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  761. else {
  762. unsigned int pinctl = AC_PINCTL_IN_EN;
  763. if (io_idx) /* set VREF for mic */
  764. pinctl |= stac92xx_get_vref(codec, nid);
  765. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  766. }
  767. return 1;
  768. }
  769. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  770. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  771. .name = xname, \
  772. .index = 0, \
  773. .info = stac92xx_io_switch_info, \
  774. .get = stac92xx_io_switch_get, \
  775. .put = stac92xx_io_switch_put, \
  776. .private_value = xpval, \
  777. }
  778. enum {
  779. STAC_CTL_WIDGET_VOL,
  780. STAC_CTL_WIDGET_MUTE,
  781. STAC_CTL_WIDGET_IO_SWITCH,
  782. };
  783. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  784. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  785. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  786. STAC_CODEC_IO_SWITCH(NULL, 0),
  787. };
  788. /* add dynamic controls */
  789. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  790. {
  791. struct snd_kcontrol_new *knew;
  792. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  793. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  794. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  795. if (! knew)
  796. return -ENOMEM;
  797. if (spec->kctl_alloc) {
  798. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  799. kfree(spec->kctl_alloc);
  800. }
  801. spec->kctl_alloc = knew;
  802. spec->num_kctl_alloc = num;
  803. }
  804. knew = &spec->kctl_alloc[spec->num_kctl_used];
  805. *knew = stac92xx_control_templates[type];
  806. knew->name = kstrdup(name, GFP_KERNEL);
  807. if (! knew->name)
  808. return -ENOMEM;
  809. knew->private_value = val;
  810. spec->num_kctl_used++;
  811. return 0;
  812. }
  813. /* flag inputs as additional dynamic lineouts */
  814. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  815. {
  816. struct sigmatel_spec *spec = codec->spec;
  817. switch (cfg->line_outs) {
  818. case 3:
  819. /* add line-in as side */
  820. if (cfg->input_pins[AUTO_PIN_LINE]) {
  821. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
  822. spec->line_switch = 1;
  823. cfg->line_outs++;
  824. }
  825. break;
  826. case 2:
  827. /* add line-in as clfe and mic as side */
  828. if (cfg->input_pins[AUTO_PIN_LINE]) {
  829. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
  830. spec->line_switch = 1;
  831. cfg->line_outs++;
  832. }
  833. if (cfg->input_pins[AUTO_PIN_MIC]) {
  834. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
  835. spec->mic_switch = 1;
  836. cfg->line_outs++;
  837. }
  838. break;
  839. case 1:
  840. /* add line-in as surr and mic as clfe */
  841. if (cfg->input_pins[AUTO_PIN_LINE]) {
  842. cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
  843. spec->line_switch = 1;
  844. cfg->line_outs++;
  845. }
  846. if (cfg->input_pins[AUTO_PIN_MIC]) {
  847. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
  848. spec->mic_switch = 1;
  849. cfg->line_outs++;
  850. }
  851. break;
  852. }
  853. return 0;
  854. }
  855. /*
  856. * XXX The line_out pin widget connection list may not be set to the
  857. * desired DAC nid. This is the case on 927x where ports A and B can
  858. * be routed to several DACs.
  859. *
  860. * This requires an analysis of the line-out/hp pin configuration
  861. * to provide a best fit for pin/DAC configurations that are routable.
  862. * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
  863. * A and B is not supported.
  864. */
  865. /* fill in the dac_nids table from the parsed pin configuration */
  866. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  867. const struct auto_pin_cfg *cfg)
  868. {
  869. struct sigmatel_spec *spec = codec->spec;
  870. hda_nid_t nid;
  871. int i;
  872. /* check the pins hardwired to audio widget */
  873. for (i = 0; i < cfg->line_outs; i++) {
  874. nid = cfg->line_out_pins[i];
  875. spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
  876. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  877. }
  878. spec->multiout.num_dacs = cfg->line_outs;
  879. return 0;
  880. }
  881. /* create volume control/switch for the given prefx type */
  882. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  883. {
  884. char name[32];
  885. int err;
  886. sprintf(name, "%s Playback Volume", pfx);
  887. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  888. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  889. if (err < 0)
  890. return err;
  891. sprintf(name, "%s Playback Switch", pfx);
  892. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  893. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  894. if (err < 0)
  895. return err;
  896. return 0;
  897. }
  898. /* add playback controls from the parsed DAC table */
  899. static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
  900. const struct auto_pin_cfg *cfg)
  901. {
  902. static const char *chname[4] = {
  903. "Front", "Surround", NULL /*CLFE*/, "Side"
  904. };
  905. hda_nid_t nid;
  906. int i, err;
  907. for (i = 0; i < cfg->line_outs; i++) {
  908. if (!spec->multiout.dac_nids[i])
  909. continue;
  910. nid = spec->multiout.dac_nids[i];
  911. if (i == 2) {
  912. /* Center/LFE */
  913. err = create_controls(spec, "Center", nid, 1);
  914. if (err < 0)
  915. return err;
  916. err = create_controls(spec, "LFE", nid, 2);
  917. if (err < 0)
  918. return err;
  919. } else {
  920. err = create_controls(spec, chname[i], nid, 3);
  921. if (err < 0)
  922. return err;
  923. }
  924. }
  925. if (spec->line_switch)
  926. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  927. return err;
  928. if (spec->mic_switch)
  929. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  930. return err;
  931. return 0;
  932. }
  933. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  934. {
  935. int i;
  936. for (i = 0; i < spec->multiout.num_dacs; i++) {
  937. if (spec->multiout.dac_nids[i] == nid)
  938. return 1;
  939. }
  940. if (spec->multiout.hp_nid == nid)
  941. return 1;
  942. return 0;
  943. }
  944. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  945. {
  946. if (!spec->multiout.hp_nid)
  947. spec->multiout.hp_nid = nid;
  948. else if (spec->multiout.num_dacs > 4) {
  949. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  950. return 1;
  951. } else {
  952. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  953. spec->multiout.num_dacs++;
  954. }
  955. return 0;
  956. }
  957. /* add playback controls for Speaker and HP outputs */
  958. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  959. struct auto_pin_cfg *cfg)
  960. {
  961. struct sigmatel_spec *spec = codec->spec;
  962. hda_nid_t nid;
  963. int i, old_num_dacs, err;
  964. old_num_dacs = spec->multiout.num_dacs;
  965. for (i = 0; i < cfg->hp_outs; i++) {
  966. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  967. if (wid_caps & AC_WCAP_UNSOL_CAP)
  968. spec->hp_detect = 1;
  969. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  970. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  971. if (check_in_dac_nids(spec, nid))
  972. nid = 0;
  973. if (! nid)
  974. continue;
  975. add_spec_dacs(spec, nid);
  976. }
  977. for (i = 0; i < cfg->speaker_outs; i++) {
  978. nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
  979. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  980. if (check_in_dac_nids(spec, nid))
  981. nid = 0;
  982. if (check_in_dac_nids(spec, nid))
  983. nid = 0;
  984. if (! nid)
  985. continue;
  986. add_spec_dacs(spec, nid);
  987. }
  988. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  989. static const char *pfxs[] = {
  990. "Speaker", "External Speaker", "Speaker2",
  991. };
  992. err = create_controls(spec, pfxs[i - old_num_dacs],
  993. spec->multiout.dac_nids[i], 3);
  994. if (err < 0)
  995. return err;
  996. }
  997. if (spec->multiout.hp_nid) {
  998. const char *pfx;
  999. if (old_num_dacs == spec->multiout.num_dacs)
  1000. pfx = "Master";
  1001. else
  1002. pfx = "Headphone";
  1003. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1004. if (err < 0)
  1005. return err;
  1006. }
  1007. return 0;
  1008. }
  1009. /* labels for dmic mux inputs */
  1010. static const char *stac92xx_dmic_labels[5] = {
  1011. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1012. "Digital Mic 3", "Digital Mic 4"
  1013. };
  1014. /* create playback/capture controls for input pins on dmic capable codecs */
  1015. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1016. const struct auto_pin_cfg *cfg)
  1017. {
  1018. struct sigmatel_spec *spec = codec->spec;
  1019. struct hda_input_mux *dimux = &spec->private_dimux;
  1020. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1021. int i, j;
  1022. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1023. dimux->items[dimux->num_items].index = 0;
  1024. dimux->num_items++;
  1025. for (i = 0; i < spec->num_dmics; i++) {
  1026. int index;
  1027. int num_cons;
  1028. unsigned int def_conf;
  1029. def_conf = snd_hda_codec_read(codec,
  1030. spec->dmic_nids[i],
  1031. 0,
  1032. AC_VERB_GET_CONFIG_DEFAULT,
  1033. 0);
  1034. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1035. continue;
  1036. num_cons = snd_hda_get_connections(codec,
  1037. spec->dmux_nid,
  1038. con_lst,
  1039. HDA_MAX_NUM_INPUTS);
  1040. for (j = 0; j < num_cons; j++)
  1041. if (con_lst[j] == spec->dmic_nids[i]) {
  1042. index = j;
  1043. goto found;
  1044. }
  1045. continue;
  1046. found:
  1047. dimux->items[dimux->num_items].label =
  1048. stac92xx_dmic_labels[dimux->num_items];
  1049. dimux->items[dimux->num_items].index = index;
  1050. dimux->num_items++;
  1051. }
  1052. return 0;
  1053. }
  1054. /* create playback/capture controls for input pins */
  1055. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1056. {
  1057. struct sigmatel_spec *spec = codec->spec;
  1058. struct hda_input_mux *imux = &spec->private_imux;
  1059. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1060. int i, j, k;
  1061. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1062. int index;
  1063. if (!cfg->input_pins[i])
  1064. continue;
  1065. index = -1;
  1066. for (j = 0; j < spec->num_muxes; j++) {
  1067. int num_cons;
  1068. num_cons = snd_hda_get_connections(codec,
  1069. spec->mux_nids[j],
  1070. con_lst,
  1071. HDA_MAX_NUM_INPUTS);
  1072. for (k = 0; k < num_cons; k++)
  1073. if (con_lst[k] == cfg->input_pins[i]) {
  1074. index = k;
  1075. goto found;
  1076. }
  1077. }
  1078. continue;
  1079. found:
  1080. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1081. imux->items[imux->num_items].index = index;
  1082. imux->num_items++;
  1083. }
  1084. if (imux->num_items == 1) {
  1085. /*
  1086. * Set the current input for the muxes.
  1087. * The STAC9221 has two input muxes with identical source
  1088. * NID lists. Hopefully this won't get confused.
  1089. */
  1090. for (i = 0; i < spec->num_muxes; i++) {
  1091. snd_hda_codec_write(codec, spec->mux_nids[i], 0,
  1092. AC_VERB_SET_CONNECT_SEL,
  1093. imux->items[0].index);
  1094. }
  1095. }
  1096. return 0;
  1097. }
  1098. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1099. {
  1100. struct sigmatel_spec *spec = codec->spec;
  1101. int i;
  1102. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1103. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1104. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1105. }
  1106. }
  1107. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1108. {
  1109. struct sigmatel_spec *spec = codec->spec;
  1110. int i;
  1111. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1112. hda_nid_t pin;
  1113. pin = spec->autocfg.hp_pins[i];
  1114. if (pin) /* connect to front */
  1115. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1116. }
  1117. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1118. hda_nid_t pin;
  1119. pin = spec->autocfg.speaker_pins[i];
  1120. if (pin) /* connect to front */
  1121. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1122. }
  1123. }
  1124. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1125. {
  1126. struct sigmatel_spec *spec = codec->spec;
  1127. int err;
  1128. if ((err = snd_hda_parse_pin_def_config(codec,
  1129. &spec->autocfg,
  1130. spec->dmic_nids)) < 0)
  1131. return err;
  1132. if (! spec->autocfg.line_outs)
  1133. return 0; /* can't find valid pin config */
  1134. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1135. return err;
  1136. if (spec->multiout.num_dacs == 0)
  1137. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1138. return err;
  1139. if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  1140. (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
  1141. (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1142. return err;
  1143. if (spec->num_dmics > 0)
  1144. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1145. &spec->autocfg)) < 0)
  1146. return err;
  1147. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1148. if (spec->multiout.max_channels > 2)
  1149. spec->surr_switch = 1;
  1150. if (spec->autocfg.dig_out_pin)
  1151. spec->multiout.dig_out_nid = dig_out;
  1152. if (spec->autocfg.dig_in_pin)
  1153. spec->dig_in_nid = dig_in;
  1154. if (spec->kctl_alloc)
  1155. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1156. spec->input_mux = &spec->private_imux;
  1157. spec->dinput_mux = &spec->private_dimux;
  1158. return 1;
  1159. }
  1160. /* add playback controls for HP output */
  1161. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1162. struct auto_pin_cfg *cfg)
  1163. {
  1164. struct sigmatel_spec *spec = codec->spec;
  1165. hda_nid_t pin = cfg->hp_pins[0];
  1166. unsigned int wid_caps;
  1167. if (! pin)
  1168. return 0;
  1169. wid_caps = get_wcaps(codec, pin);
  1170. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1171. spec->hp_detect = 1;
  1172. return 0;
  1173. }
  1174. /* add playback controls for LFE output */
  1175. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1176. struct auto_pin_cfg *cfg)
  1177. {
  1178. struct sigmatel_spec *spec = codec->spec;
  1179. int err;
  1180. hda_nid_t lfe_pin = 0x0;
  1181. int i;
  1182. /*
  1183. * search speaker outs and line outs for a mono speaker pin
  1184. * with an amp. If one is found, add LFE controls
  1185. * for it.
  1186. */
  1187. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1188. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1189. unsigned long wcaps = get_wcaps(codec, pin);
  1190. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1191. if (wcaps == AC_WCAP_OUT_AMP)
  1192. /* found a mono speaker with an amp, must be lfe */
  1193. lfe_pin = pin;
  1194. }
  1195. /* if speaker_outs is 0, then speakers may be in line_outs */
  1196. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1197. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1198. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1199. unsigned long cfg;
  1200. cfg = snd_hda_codec_read(codec, pin, 0,
  1201. AC_VERB_GET_CONFIG_DEFAULT,
  1202. 0x00);
  1203. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1204. unsigned long wcaps = get_wcaps(codec, pin);
  1205. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1206. if (wcaps == AC_WCAP_OUT_AMP)
  1207. /* found a mono speaker with an amp,
  1208. must be lfe */
  1209. lfe_pin = pin;
  1210. }
  1211. }
  1212. }
  1213. if (lfe_pin) {
  1214. err = create_controls(spec, "LFE", lfe_pin, 1);
  1215. if (err < 0)
  1216. return err;
  1217. }
  1218. return 0;
  1219. }
  1220. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1221. {
  1222. struct sigmatel_spec *spec = codec->spec;
  1223. int err;
  1224. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1225. return err;
  1226. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1227. return err;
  1228. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1229. return err;
  1230. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1231. return err;
  1232. if (spec->autocfg.dig_out_pin)
  1233. spec->multiout.dig_out_nid = 0x05;
  1234. if (spec->autocfg.dig_in_pin)
  1235. spec->dig_in_nid = 0x04;
  1236. if (spec->kctl_alloc)
  1237. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1238. spec->input_mux = &spec->private_imux;
  1239. spec->dinput_mux = &spec->private_dimux;
  1240. return 1;
  1241. }
  1242. /*
  1243. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1244. * funky external mute control using GPIO pins.
  1245. */
  1246. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1247. {
  1248. unsigned int gpiostate, gpiomask, gpiodir;
  1249. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1250. AC_VERB_GET_GPIO_DATA, 0);
  1251. if (!muted)
  1252. gpiostate |= (1 << pin);
  1253. else
  1254. gpiostate &= ~(1 << pin);
  1255. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  1256. AC_VERB_GET_GPIO_MASK, 0);
  1257. gpiomask |= (1 << pin);
  1258. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  1259. AC_VERB_GET_GPIO_DIRECTION, 0);
  1260. gpiodir |= (1 << pin);
  1261. /* AppleHDA seems to do this -- WTF is this verb?? */
  1262. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  1263. snd_hda_codec_write(codec, codec->afg, 0,
  1264. AC_VERB_SET_GPIO_MASK, gpiomask);
  1265. snd_hda_codec_write(codec, codec->afg, 0,
  1266. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  1267. msleep(1);
  1268. snd_hda_codec_write(codec, codec->afg, 0,
  1269. AC_VERB_SET_GPIO_DATA, gpiostate);
  1270. }
  1271. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  1272. unsigned int event)
  1273. {
  1274. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  1275. snd_hda_codec_write(codec, nid, 0,
  1276. AC_VERB_SET_UNSOLICITED_ENABLE,
  1277. (AC_USRSP_EN | event));
  1278. }
  1279. static int stac92xx_init(struct hda_codec *codec)
  1280. {
  1281. struct sigmatel_spec *spec = codec->spec;
  1282. struct auto_pin_cfg *cfg = &spec->autocfg;
  1283. int i;
  1284. snd_hda_sequence_write(codec, spec->init);
  1285. /* set up pins */
  1286. if (spec->hp_detect) {
  1287. /* Enable unsolicited responses on the HP widget */
  1288. for (i = 0; i < cfg->hp_outs; i++)
  1289. enable_pin_detect(codec, cfg->hp_pins[i],
  1290. STAC_HP_EVENT);
  1291. stac92xx_auto_init_hp_out(codec);
  1292. /* fake event to set up pins */
  1293. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  1294. } else {
  1295. stac92xx_auto_init_multi_out(codec);
  1296. stac92xx_auto_init_hp_out(codec);
  1297. }
  1298. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1299. hda_nid_t nid = cfg->input_pins[i];
  1300. if (nid) {
  1301. unsigned int pinctl = AC_PINCTL_IN_EN;
  1302. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  1303. pinctl |= stac92xx_get_vref(codec, nid);
  1304. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1305. }
  1306. }
  1307. if (spec->num_dmics > 0)
  1308. for (i = 0; i < spec->num_dmics; i++)
  1309. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  1310. AC_PINCTL_IN_EN);
  1311. if (cfg->dig_out_pin)
  1312. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  1313. AC_PINCTL_OUT_EN);
  1314. if (cfg->dig_in_pin)
  1315. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  1316. AC_PINCTL_IN_EN);
  1317. if (spec->gpio_mute) {
  1318. stac922x_gpio_mute(codec, 0, 0);
  1319. stac922x_gpio_mute(codec, 1, 0);
  1320. }
  1321. return 0;
  1322. }
  1323. static void stac92xx_free(struct hda_codec *codec)
  1324. {
  1325. struct sigmatel_spec *spec = codec->spec;
  1326. int i;
  1327. if (! spec)
  1328. return;
  1329. if (spec->kctl_alloc) {
  1330. for (i = 0; i < spec->num_kctl_used; i++)
  1331. kfree(spec->kctl_alloc[i].name);
  1332. kfree(spec->kctl_alloc);
  1333. }
  1334. if (spec->bios_pin_configs)
  1335. kfree(spec->bios_pin_configs);
  1336. kfree(spec);
  1337. }
  1338. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1339. unsigned int flag)
  1340. {
  1341. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1342. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1343. if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
  1344. return;
  1345. snd_hda_codec_write(codec, nid, 0,
  1346. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1347. pin_ctl | flag);
  1348. }
  1349. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1350. unsigned int flag)
  1351. {
  1352. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1353. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1354. snd_hda_codec_write(codec, nid, 0,
  1355. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1356. pin_ctl & ~flag);
  1357. }
  1358. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  1359. {
  1360. if (!nid)
  1361. return 0;
  1362. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  1363. & (1 << 31))
  1364. return 1;
  1365. return 0;
  1366. }
  1367. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  1368. {
  1369. struct sigmatel_spec *spec = codec->spec;
  1370. struct auto_pin_cfg *cfg = &spec->autocfg;
  1371. int i, presence;
  1372. presence = 0;
  1373. for (i = 0; i < cfg->hp_outs; i++) {
  1374. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  1375. if (presence)
  1376. break;
  1377. }
  1378. if (presence) {
  1379. /* disable lineouts, enable hp */
  1380. for (i = 0; i < cfg->line_outs; i++)
  1381. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  1382. AC_PINCTL_OUT_EN);
  1383. for (i = 0; i < cfg->speaker_outs; i++)
  1384. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  1385. AC_PINCTL_OUT_EN);
  1386. } else {
  1387. /* enable lineouts, disable hp */
  1388. for (i = 0; i < cfg->line_outs; i++)
  1389. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  1390. AC_PINCTL_OUT_EN);
  1391. for (i = 0; i < cfg->speaker_outs; i++)
  1392. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  1393. AC_PINCTL_OUT_EN);
  1394. }
  1395. }
  1396. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  1397. {
  1398. switch (res >> 26) {
  1399. case STAC_HP_EVENT:
  1400. stac92xx_hp_detect(codec, res);
  1401. break;
  1402. }
  1403. }
  1404. #ifdef CONFIG_PM
  1405. static int stac92xx_resume(struct hda_codec *codec)
  1406. {
  1407. struct sigmatel_spec *spec = codec->spec;
  1408. int i;
  1409. stac92xx_init(codec);
  1410. stac92xx_set_config_regs(codec);
  1411. for (i = 0; i < spec->num_mixers; i++)
  1412. snd_hda_resume_ctls(codec, spec->mixers[i]);
  1413. if (spec->multiout.dig_out_nid)
  1414. snd_hda_resume_spdif_out(codec);
  1415. if (spec->dig_in_nid)
  1416. snd_hda_resume_spdif_in(codec);
  1417. return 0;
  1418. }
  1419. #endif
  1420. static struct hda_codec_ops stac92xx_patch_ops = {
  1421. .build_controls = stac92xx_build_controls,
  1422. .build_pcms = stac92xx_build_pcms,
  1423. .init = stac92xx_init,
  1424. .free = stac92xx_free,
  1425. .unsol_event = stac92xx_unsol_event,
  1426. #ifdef CONFIG_PM
  1427. .resume = stac92xx_resume,
  1428. #endif
  1429. };
  1430. static int patch_stac9200(struct hda_codec *codec)
  1431. {
  1432. struct sigmatel_spec *spec;
  1433. int err;
  1434. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1435. if (spec == NULL)
  1436. return -ENOMEM;
  1437. codec->spec = spec;
  1438. spec->num_pins = 8;
  1439. spec->pin_nids = stac9200_pin_nids;
  1440. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  1441. stac9200_models,
  1442. stac9200_cfg_tbl);
  1443. if (spec->board_config < 0) {
  1444. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  1445. err = stac92xx_save_bios_config_regs(codec);
  1446. if (err < 0) {
  1447. stac92xx_free(codec);
  1448. return err;
  1449. }
  1450. spec->pin_configs = spec->bios_pin_configs;
  1451. } else {
  1452. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  1453. stac92xx_set_config_regs(codec);
  1454. }
  1455. spec->multiout.max_channels = 2;
  1456. spec->multiout.num_dacs = 1;
  1457. spec->multiout.dac_nids = stac9200_dac_nids;
  1458. spec->adc_nids = stac9200_adc_nids;
  1459. spec->mux_nids = stac9200_mux_nids;
  1460. spec->num_muxes = 1;
  1461. spec->num_dmics = 0;
  1462. spec->init = stac9200_core_init;
  1463. spec->mixer = stac9200_mixer;
  1464. err = stac9200_parse_auto_config(codec);
  1465. if (err < 0) {
  1466. stac92xx_free(codec);
  1467. return err;
  1468. }
  1469. codec->patch_ops = stac92xx_patch_ops;
  1470. return 0;
  1471. }
  1472. static int patch_stac922x(struct hda_codec *codec)
  1473. {
  1474. struct sigmatel_spec *spec;
  1475. int err;
  1476. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1477. if (spec == NULL)
  1478. return -ENOMEM;
  1479. codec->spec = spec;
  1480. spec->num_pins = 10;
  1481. spec->pin_nids = stac922x_pin_nids;
  1482. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  1483. stac922x_models,
  1484. stac922x_cfg_tbl);
  1485. if (spec->board_config < 0) {
  1486. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  1487. "using BIOS defaults\n");
  1488. err = stac92xx_save_bios_config_regs(codec);
  1489. if (err < 0) {
  1490. stac92xx_free(codec);
  1491. return err;
  1492. }
  1493. spec->pin_configs = spec->bios_pin_configs;
  1494. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  1495. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  1496. stac92xx_set_config_regs(codec);
  1497. }
  1498. spec->adc_nids = stac922x_adc_nids;
  1499. spec->mux_nids = stac922x_mux_nids;
  1500. spec->num_muxes = 2;
  1501. spec->num_dmics = 0;
  1502. spec->init = stac922x_core_init;
  1503. spec->mixer = stac922x_mixer;
  1504. spec->multiout.dac_nids = spec->dac_nids;
  1505. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  1506. if (err < 0) {
  1507. stac92xx_free(codec);
  1508. return err;
  1509. }
  1510. if (spec->board_config == STAC_MACMINI)
  1511. spec->gpio_mute = 1;
  1512. codec->patch_ops = stac92xx_patch_ops;
  1513. return 0;
  1514. }
  1515. static int patch_stac927x(struct hda_codec *codec)
  1516. {
  1517. struct sigmatel_spec *spec;
  1518. int err;
  1519. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1520. if (spec == NULL)
  1521. return -ENOMEM;
  1522. codec->spec = spec;
  1523. spec->num_pins = 14;
  1524. spec->pin_nids = stac927x_pin_nids;
  1525. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  1526. stac927x_models,
  1527. stac927x_cfg_tbl);
  1528. if (spec->board_config < 0) {
  1529. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  1530. err = stac92xx_save_bios_config_regs(codec);
  1531. if (err < 0) {
  1532. stac92xx_free(codec);
  1533. return err;
  1534. }
  1535. spec->pin_configs = spec->bios_pin_configs;
  1536. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  1537. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  1538. stac92xx_set_config_regs(codec);
  1539. }
  1540. switch (spec->board_config) {
  1541. case STAC_D965_3ST:
  1542. spec->adc_nids = stac927x_adc_nids;
  1543. spec->mux_nids = stac927x_mux_nids;
  1544. spec->num_muxes = 3;
  1545. spec->num_dmics = 0;
  1546. spec->init = d965_core_init;
  1547. spec->mixer = stac9227_mixer;
  1548. break;
  1549. case STAC_D965_5ST:
  1550. spec->adc_nids = stac927x_adc_nids;
  1551. spec->mux_nids = stac927x_mux_nids;
  1552. spec->num_muxes = 3;
  1553. spec->num_dmics = 0;
  1554. spec->init = d965_core_init;
  1555. spec->mixer = stac9227_mixer;
  1556. break;
  1557. default:
  1558. spec->adc_nids = stac927x_adc_nids;
  1559. spec->mux_nids = stac927x_mux_nids;
  1560. spec->num_muxes = 3;
  1561. spec->num_dmics = 0;
  1562. spec->init = stac927x_core_init;
  1563. spec->mixer = stac927x_mixer;
  1564. }
  1565. spec->multiout.dac_nids = spec->dac_nids;
  1566. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  1567. if (err < 0) {
  1568. stac92xx_free(codec);
  1569. return err;
  1570. }
  1571. codec->patch_ops = stac92xx_patch_ops;
  1572. return 0;
  1573. }
  1574. static int patch_stac9205(struct hda_codec *codec)
  1575. {
  1576. struct sigmatel_spec *spec;
  1577. int err;
  1578. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1579. if (spec == NULL)
  1580. return -ENOMEM;
  1581. codec->spec = spec;
  1582. spec->num_pins = 14;
  1583. spec->pin_nids = stac9205_pin_nids;
  1584. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  1585. stac9205_models,
  1586. stac9205_cfg_tbl);
  1587. if (spec->board_config < 0) {
  1588. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  1589. err = stac92xx_save_bios_config_regs(codec);
  1590. if (err < 0) {
  1591. stac92xx_free(codec);
  1592. return err;
  1593. }
  1594. spec->pin_configs = spec->bios_pin_configs;
  1595. } else {
  1596. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  1597. stac92xx_set_config_regs(codec);
  1598. }
  1599. spec->adc_nids = stac9205_adc_nids;
  1600. spec->mux_nids = stac9205_mux_nids;
  1601. spec->num_muxes = 2;
  1602. spec->dmic_nids = stac9205_dmic_nids;
  1603. spec->num_dmics = 2;
  1604. spec->dmux_nid = 0x1d;
  1605. spec->init = stac9205_core_init;
  1606. spec->mixer = stac9205_mixer;
  1607. spec->multiout.dac_nids = spec->dac_nids;
  1608. /* Configure GPIO0 as EAPD output */
  1609. snd_hda_codec_write(codec, codec->afg, 0,
  1610. AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
  1611. /* Configure GPIO0 as CMOS */
  1612. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
  1613. /* Assert GPIO0 high */
  1614. snd_hda_codec_write(codec, codec->afg, 0,
  1615. AC_VERB_SET_GPIO_DATA, 0x00000001);
  1616. /* Enable GPIO0 */
  1617. snd_hda_codec_write(codec, codec->afg, 0,
  1618. AC_VERB_SET_GPIO_MASK, 0x00000001);
  1619. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  1620. if (err < 0) {
  1621. stac92xx_free(codec);
  1622. return err;
  1623. }
  1624. codec->patch_ops = stac92xx_patch_ops;
  1625. return 0;
  1626. }
  1627. /*
  1628. * STAC9872 hack
  1629. */
  1630. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  1631. static hda_nid_t vaio_dacs[] = { 0x2 };
  1632. #define VAIO_HP_DAC 0x5
  1633. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  1634. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  1635. static struct hda_input_mux vaio_mux = {
  1636. .num_items = 2,
  1637. .items = {
  1638. /* { "HP", 0x0 }, */
  1639. { "Line", 0x1 },
  1640. { "Mic", 0x2 },
  1641. { "PCM", 0x3 },
  1642. }
  1643. };
  1644. static struct hda_verb vaio_init[] = {
  1645. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  1646. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  1647. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  1648. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  1649. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  1650. {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
  1651. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  1652. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  1653. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  1654. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  1655. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  1656. {}
  1657. };
  1658. static struct hda_verb vaio_ar_init[] = {
  1659. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  1660. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  1661. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  1662. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  1663. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  1664. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  1665. {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
  1666. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  1667. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  1668. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  1669. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  1670. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  1671. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  1672. {}
  1673. };
  1674. /* bind volumes of both NID 0x02 and 0x05 */
  1675. static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
  1676. struct snd_ctl_elem_value *ucontrol)
  1677. {
  1678. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1679. long *valp = ucontrol->value.integer.value;
  1680. int change;
  1681. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1682. 0x7f, valp[0] & 0x7f);
  1683. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1684. 0x7f, valp[1] & 0x7f);
  1685. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1686. 0x7f, valp[0] & 0x7f);
  1687. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1688. 0x7f, valp[1] & 0x7f);
  1689. return change;
  1690. }
  1691. /* bind volumes of both NID 0x02 and 0x05 */
  1692. static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
  1693. struct snd_ctl_elem_value *ucontrol)
  1694. {
  1695. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1696. long *valp = ucontrol->value.integer.value;
  1697. int change;
  1698. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1699. 0x80, (valp[0] ? 0 : 0x80));
  1700. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1701. 0x80, (valp[1] ? 0 : 0x80));
  1702. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1703. 0x80, (valp[0] ? 0 : 0x80));
  1704. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1705. 0x80, (valp[1] ? 0 : 0x80));
  1706. return change;
  1707. }
  1708. static struct snd_kcontrol_new vaio_mixer[] = {
  1709. {
  1710. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1711. .name = "Master Playback Volume",
  1712. .info = snd_hda_mixer_amp_volume_info,
  1713. .get = snd_hda_mixer_amp_volume_get,
  1714. .put = vaio_master_vol_put,
  1715. .tlv = { .c = snd_hda_mixer_amp_tlv },
  1716. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1717. },
  1718. {
  1719. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1720. .name = "Master Playback Switch",
  1721. .info = snd_hda_mixer_amp_switch_info,
  1722. .get = snd_hda_mixer_amp_switch_get,
  1723. .put = vaio_master_sw_put,
  1724. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1725. },
  1726. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  1727. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  1728. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  1729. {
  1730. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1731. .name = "Capture Source",
  1732. .count = 1,
  1733. .info = stac92xx_mux_enum_info,
  1734. .get = stac92xx_mux_enum_get,
  1735. .put = stac92xx_mux_enum_put,
  1736. },
  1737. {}
  1738. };
  1739. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  1740. {
  1741. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1742. .name = "Master Playback Volume",
  1743. .info = snd_hda_mixer_amp_volume_info,
  1744. .get = snd_hda_mixer_amp_volume_get,
  1745. .put = vaio_master_vol_put,
  1746. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1747. },
  1748. {
  1749. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1750. .name = "Master Playback Switch",
  1751. .info = snd_hda_mixer_amp_switch_info,
  1752. .get = snd_hda_mixer_amp_switch_get,
  1753. .put = vaio_master_sw_put,
  1754. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1755. },
  1756. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  1757. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  1758. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  1759. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  1760. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  1761. {
  1762. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1763. .name = "Capture Source",
  1764. .count = 1,
  1765. .info = stac92xx_mux_enum_info,
  1766. .get = stac92xx_mux_enum_get,
  1767. .put = stac92xx_mux_enum_put,
  1768. },
  1769. {}
  1770. };
  1771. static struct hda_codec_ops stac9872_patch_ops = {
  1772. .build_controls = stac92xx_build_controls,
  1773. .build_pcms = stac92xx_build_pcms,
  1774. .init = stac92xx_init,
  1775. .free = stac92xx_free,
  1776. #ifdef CONFIG_PM
  1777. .resume = stac92xx_resume,
  1778. #endif
  1779. };
  1780. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  1781. CXD9872RD_VAIO,
  1782. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  1783. STAC9872AK_VAIO,
  1784. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  1785. STAC9872K_VAIO,
  1786. /* AR Series. id=0x83847664 and subsys=104D1300 */
  1787. CXD9872AKD_VAIO,
  1788. STAC_9872_MODELS,
  1789. };
  1790. static const char *stac9872_models[STAC_9872_MODELS] = {
  1791. [CXD9872RD_VAIO] = "vaio",
  1792. [CXD9872AKD_VAIO] = "vaio-ar",
  1793. };
  1794. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  1795. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  1796. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  1797. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  1798. {}
  1799. };
  1800. static int patch_stac9872(struct hda_codec *codec)
  1801. {
  1802. struct sigmatel_spec *spec;
  1803. int board_config;
  1804. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  1805. stac9872_models,
  1806. stac9872_cfg_tbl);
  1807. if (board_config < 0)
  1808. /* unknown config, let generic-parser do its job... */
  1809. return snd_hda_parse_generic_codec(codec);
  1810. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1811. if (spec == NULL)
  1812. return -ENOMEM;
  1813. codec->spec = spec;
  1814. switch (board_config) {
  1815. case CXD9872RD_VAIO:
  1816. case STAC9872AK_VAIO:
  1817. case STAC9872K_VAIO:
  1818. spec->mixer = vaio_mixer;
  1819. spec->init = vaio_init;
  1820. spec->multiout.max_channels = 2;
  1821. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  1822. spec->multiout.dac_nids = vaio_dacs;
  1823. spec->multiout.hp_nid = VAIO_HP_DAC;
  1824. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  1825. spec->adc_nids = vaio_adcs;
  1826. spec->input_mux = &vaio_mux;
  1827. spec->mux_nids = vaio_mux_nids;
  1828. break;
  1829. case CXD9872AKD_VAIO:
  1830. spec->mixer = vaio_ar_mixer;
  1831. spec->init = vaio_ar_init;
  1832. spec->multiout.max_channels = 2;
  1833. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  1834. spec->multiout.dac_nids = vaio_dacs;
  1835. spec->multiout.hp_nid = VAIO_HP_DAC;
  1836. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  1837. spec->adc_nids = vaio_adcs;
  1838. spec->input_mux = &vaio_mux;
  1839. spec->mux_nids = vaio_mux_nids;
  1840. break;
  1841. }
  1842. codec->patch_ops = stac9872_patch_ops;
  1843. return 0;
  1844. }
  1845. /*
  1846. * patch entries
  1847. */
  1848. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  1849. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  1850. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  1851. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  1852. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  1853. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  1854. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  1855. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  1856. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  1857. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  1858. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  1859. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  1860. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  1861. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  1862. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  1863. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  1864. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  1865. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  1866. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  1867. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  1868. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  1869. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  1870. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  1871. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  1872. /* The following does not take into account .id=0x83847661 when subsys =
  1873. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  1874. * currently not fully supported.
  1875. */
  1876. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  1877. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  1878. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  1879. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  1880. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  1881. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  1882. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  1883. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  1884. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  1885. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  1886. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  1887. {} /* terminator */
  1888. };