patch_sigmatel.c 75 KB

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