patch_sigmatel.c 66 KB

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