patch_sigmatel.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338
  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_DELL_D21,
  40. STAC_9200_DELL_D22,
  41. STAC_9200_DELL_D23,
  42. STAC_9200_DELL_M21,
  43. STAC_9200_DELL_M22,
  44. STAC_9200_DELL_M23,
  45. STAC_9200_DELL_M24,
  46. STAC_9200_DELL_M25,
  47. STAC_9200_DELL_M26,
  48. STAC_9200_DELL_M27,
  49. STAC_9200_GATEWAY,
  50. STAC_9200_MODELS
  51. };
  52. enum {
  53. STAC_9205_REF,
  54. STAC_9205_DELL_M42,
  55. STAC_9205_DELL_M43,
  56. STAC_9205_DELL_M44,
  57. STAC_9205_MODELS
  58. };
  59. enum {
  60. STAC_92HD71BXX_REF,
  61. STAC_92HD71BXX_MODELS
  62. };
  63. enum {
  64. STAC_925x_REF,
  65. STAC_M2_2,
  66. STAC_MA6,
  67. STAC_PA6,
  68. STAC_925x_MODELS
  69. };
  70. enum {
  71. STAC_D945_REF,
  72. STAC_D945GTP3,
  73. STAC_D945GTP5,
  74. STAC_INTEL_MAC_V1,
  75. STAC_INTEL_MAC_V2,
  76. STAC_INTEL_MAC_V3,
  77. STAC_INTEL_MAC_V4,
  78. STAC_INTEL_MAC_V5,
  79. /* for backward compatibility */
  80. STAC_MACMINI,
  81. STAC_MACBOOK,
  82. STAC_MACBOOK_PRO_V1,
  83. STAC_MACBOOK_PRO_V2,
  84. STAC_IMAC_INTEL,
  85. STAC_IMAC_INTEL_20,
  86. STAC_922X_DELL_D81,
  87. STAC_922X_DELL_D82,
  88. STAC_922X_DELL_M81,
  89. STAC_922X_DELL_M82,
  90. STAC_922X_MODELS
  91. };
  92. enum {
  93. STAC_D965_REF,
  94. STAC_D965_3ST,
  95. STAC_D965_5ST,
  96. STAC_DELL_3ST,
  97. STAC_927X_MODELS
  98. };
  99. struct sigmatel_spec {
  100. struct snd_kcontrol_new *mixers[4];
  101. unsigned int num_mixers;
  102. int board_config;
  103. unsigned int surr_switch: 1;
  104. unsigned int line_switch: 1;
  105. unsigned int mic_switch: 1;
  106. unsigned int alt_switch: 1;
  107. unsigned int hp_detect: 1;
  108. unsigned int gpio_mute: 1;
  109. unsigned int gpio_mask, gpio_data;
  110. /* playback */
  111. struct hda_multi_out multiout;
  112. hda_nid_t dac_nids[5];
  113. /* capture */
  114. hda_nid_t *adc_nids;
  115. unsigned int num_adcs;
  116. hda_nid_t *mux_nids;
  117. unsigned int num_muxes;
  118. hda_nid_t *dmic_nids;
  119. unsigned int num_dmics;
  120. hda_nid_t dmux_nid;
  121. hda_nid_t dig_in_nid;
  122. /* pin widgets */
  123. hda_nid_t *pin_nids;
  124. unsigned int num_pins;
  125. unsigned int *pin_configs;
  126. unsigned int *bios_pin_configs;
  127. /* codec specific stuff */
  128. struct hda_verb *init;
  129. struct snd_kcontrol_new *mixer;
  130. /* capture source */
  131. struct hda_input_mux *dinput_mux;
  132. unsigned int cur_dmux;
  133. struct hda_input_mux *input_mux;
  134. unsigned int cur_mux[3];
  135. /* i/o switches */
  136. unsigned int io_switch[2];
  137. unsigned int clfe_swap;
  138. unsigned int aloopback;
  139. struct hda_pcm pcm_rec[2]; /* PCM information */
  140. /* dynamic controls and input_mux */
  141. struct auto_pin_cfg autocfg;
  142. unsigned int num_kctl_alloc, num_kctl_used;
  143. struct snd_kcontrol_new *kctl_alloc;
  144. struct hda_input_mux private_dimux;
  145. struct hda_input_mux private_imux;
  146. };
  147. static hda_nid_t stac9200_adc_nids[1] = {
  148. 0x03,
  149. };
  150. static hda_nid_t stac9200_mux_nids[1] = {
  151. 0x0c,
  152. };
  153. static hda_nid_t stac9200_dac_nids[1] = {
  154. 0x02,
  155. };
  156. static hda_nid_t stac92hd71bxx_adc_nids[2] = {
  157. 0x12, 0x13,
  158. };
  159. static hda_nid_t stac92hd71bxx_mux_nids[2] = {
  160. 0x1a, 0x1b
  161. };
  162. static hda_nid_t stac92hd71bxx_dac_nids[2] = {
  163. 0x10, /*0x11, */
  164. };
  165. #define STAC92HD71BXX_NUM_DMICS 2
  166. static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
  167. 0x18, 0x19, 0
  168. };
  169. static hda_nid_t stac925x_adc_nids[1] = {
  170. 0x03,
  171. };
  172. static hda_nid_t stac925x_mux_nids[1] = {
  173. 0x0f,
  174. };
  175. static hda_nid_t stac925x_dac_nids[1] = {
  176. 0x02,
  177. };
  178. #define STAC925X_NUM_DMICS 1
  179. static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
  180. 0x15, 0
  181. };
  182. static hda_nid_t stac922x_adc_nids[2] = {
  183. 0x06, 0x07,
  184. };
  185. static hda_nid_t stac922x_mux_nids[2] = {
  186. 0x12, 0x13,
  187. };
  188. static hda_nid_t stac927x_adc_nids[3] = {
  189. 0x07, 0x08, 0x09
  190. };
  191. static hda_nid_t stac927x_mux_nids[3] = {
  192. 0x15, 0x16, 0x17
  193. };
  194. #define STAC927X_NUM_DMICS 2
  195. static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
  196. 0x13, 0x14, 0
  197. };
  198. static hda_nid_t stac9205_adc_nids[2] = {
  199. 0x12, 0x13
  200. };
  201. static hda_nid_t stac9205_mux_nids[2] = {
  202. 0x19, 0x1a
  203. };
  204. #define STAC9205_NUM_DMICS 2
  205. static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
  206. 0x17, 0x18, 0
  207. };
  208. static hda_nid_t stac9200_pin_nids[8] = {
  209. 0x08, 0x09, 0x0d, 0x0e,
  210. 0x0f, 0x10, 0x11, 0x12,
  211. };
  212. static hda_nid_t stac925x_pin_nids[8] = {
  213. 0x07, 0x08, 0x0a, 0x0b,
  214. 0x0c, 0x0d, 0x10, 0x11,
  215. };
  216. static hda_nid_t stac922x_pin_nids[10] = {
  217. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  218. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  219. };
  220. static hda_nid_t stac92hd71bxx_pin_nids[10] = {
  221. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  222. 0x0f, 0x14, 0x18, 0x19, 0x1e,
  223. };
  224. static hda_nid_t stac927x_pin_nids[14] = {
  225. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  226. 0x0f, 0x10, 0x11, 0x12, 0x13,
  227. 0x14, 0x21, 0x22, 0x23,
  228. };
  229. static hda_nid_t stac9205_pin_nids[12] = {
  230. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  231. 0x0f, 0x14, 0x16, 0x17, 0x18,
  232. 0x21, 0x22,
  233. };
  234. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  235. struct snd_ctl_elem_info *uinfo)
  236. {
  237. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  238. struct sigmatel_spec *spec = codec->spec;
  239. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  240. }
  241. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  242. struct snd_ctl_elem_value *ucontrol)
  243. {
  244. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  245. struct sigmatel_spec *spec = codec->spec;
  246. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  247. return 0;
  248. }
  249. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  250. struct snd_ctl_elem_value *ucontrol)
  251. {
  252. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  253. struct sigmatel_spec *spec = codec->spec;
  254. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  255. spec->dmux_nid, &spec->cur_dmux);
  256. }
  257. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  258. {
  259. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  260. struct sigmatel_spec *spec = codec->spec;
  261. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  262. }
  263. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  264. {
  265. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  266. struct sigmatel_spec *spec = codec->spec;
  267. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  268. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  269. return 0;
  270. }
  271. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  272. {
  273. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  274. struct sigmatel_spec *spec = codec->spec;
  275. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  276. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  277. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  278. }
  279. #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
  280. static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
  281. struct snd_ctl_elem_value *ucontrol)
  282. {
  283. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  284. struct sigmatel_spec *spec = codec->spec;
  285. ucontrol->value.integer.value[0] = spec->aloopback;
  286. return 0;
  287. }
  288. static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
  289. struct snd_ctl_elem_value *ucontrol)
  290. {
  291. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  292. struct sigmatel_spec *spec = codec->spec;
  293. unsigned int dac_mode;
  294. if (spec->aloopback == ucontrol->value.integer.value[0])
  295. return 0;
  296. spec->aloopback = ucontrol->value.integer.value[0];
  297. dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
  298. kcontrol->private_value & 0xFFFF, 0x0);
  299. if (spec->aloopback) {
  300. snd_hda_power_up(codec);
  301. dac_mode |= 0x40;
  302. } else {
  303. snd_hda_power_down(codec);
  304. dac_mode &= ~0x40;
  305. }
  306. snd_hda_codec_write_cache(codec, codec->afg, 0,
  307. kcontrol->private_value >> 16, dac_mode);
  308. return 1;
  309. }
  310. static struct hda_verb stac9200_core_init[] = {
  311. /* set dac0mux for dac converter */
  312. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  313. {}
  314. };
  315. static struct hda_verb stac9200_eapd_init[] = {
  316. /* set dac0mux for dac converter */
  317. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  318. {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  319. {}
  320. };
  321. static struct hda_verb stac92hd71bxx_core_init[] = {
  322. /* set master volume and direct control */
  323. { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  324. /* connect headphone jack to dac1 */
  325. { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
  326. /* connect ports 0d and 0f to audio mixer */
  327. { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
  328. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
  329. /* unmute dac0 input in audio mixer */
  330. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
  331. /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
  332. { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  333. { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  334. { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  335. /* unmute mono out node */
  336. { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  337. {}
  338. };
  339. static struct hda_verb stac925x_core_init[] = {
  340. /* set dac0mux for dac converter */
  341. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  342. {}
  343. };
  344. static struct hda_verb stac922x_core_init[] = {
  345. /* set master volume and direct control */
  346. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  347. {}
  348. };
  349. static struct hda_verb d965_core_init[] = {
  350. /* set master volume and direct control */
  351. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  352. /* unmute node 0x1b */
  353. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  354. /* select node 0x03 as DAC */
  355. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  356. {}
  357. };
  358. static struct hda_verb stac927x_core_init[] = {
  359. /* set master volume and direct control */
  360. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  361. {}
  362. };
  363. static struct hda_verb stac9205_core_init[] = {
  364. /* set master volume and direct control */
  365. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  366. {}
  367. };
  368. #define STAC_DIGITAL_INPUT_SOURCE(cnt) \
  369. { \
  370. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  371. .name = "Digital Input Source", \
  372. .count = cnt, \
  373. .info = stac92xx_dmux_enum_info, \
  374. .get = stac92xx_dmux_enum_get, \
  375. .put = stac92xx_dmux_enum_put,\
  376. }
  377. #define STAC_INPUT_SOURCE(cnt) \
  378. { \
  379. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  380. .name = "Input Source", \
  381. .count = cnt, \
  382. .info = stac92xx_mux_enum_info, \
  383. .get = stac92xx_mux_enum_get, \
  384. .put = stac92xx_mux_enum_put, \
  385. }
  386. #define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
  387. { \
  388. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  389. .name = "Analog Loopback", \
  390. .count = 1, \
  391. .info = stac92xx_aloopback_info, \
  392. .get = stac92xx_aloopback_get, \
  393. .put = stac92xx_aloopback_put, \
  394. .private_value = verb_read | (verb_write << 16), \
  395. }
  396. #define STAC_VOLKNOB(knob_nid) \
  397. { \
  398. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  399. .name = "Master Playback Volume", \
  400. .count = 1, \
  401. .info = stac92xx_volknob_info, \
  402. .get = stac92xx_volknob_get, \
  403. .put = stac92xx_volknob_put, \
  404. .private_value = 127 | (knob_nid << 16), \
  405. }
  406. static struct snd_kcontrol_new stac9200_mixer[] = {
  407. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  408. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  409. STAC_INPUT_SOURCE(1),
  410. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  411. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  412. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  413. { } /* end */
  414. };
  415. static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
  416. STAC_DIGITAL_INPUT_SOURCE(1),
  417. STAC_INPUT_SOURCE(2),
  418. STAC_VOLKNOB(0x28),
  419. /* hardware gain controls */
  420. HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
  421. HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
  422. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
  423. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
  424. HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
  425. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
  426. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
  427. HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
  428. HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
  429. HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
  430. { } /* end */
  431. };
  432. static struct snd_kcontrol_new stac925x_mixer[] = {
  433. STAC_INPUT_SOURCE(1),
  434. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
  435. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
  436. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
  437. { } /* end */
  438. };
  439. static struct snd_kcontrol_new stac9205_mixer[] = {
  440. STAC_DIGITAL_INPUT_SOURCE(1),
  441. STAC_INPUT_SOURCE(2),
  442. STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
  443. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
  444. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
  445. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
  446. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
  447. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
  448. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
  449. { } /* end */
  450. };
  451. /* This needs to be generated dynamically based on sequence */
  452. static struct snd_kcontrol_new stac922x_mixer[] = {
  453. STAC_INPUT_SOURCE(2),
  454. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
  455. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
  456. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
  457. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
  458. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
  459. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
  460. { } /* end */
  461. };
  462. static struct snd_kcontrol_new stac927x_mixer[] = {
  463. STAC_DIGITAL_INPUT_SOURCE(1),
  464. STAC_INPUT_SOURCE(3),
  465. STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
  466. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
  467. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
  468. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
  469. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
  470. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
  471. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
  472. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
  473. HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
  474. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
  475. { } /* end */
  476. };
  477. static int stac92xx_build_controls(struct hda_codec *codec)
  478. {
  479. struct sigmatel_spec *spec = codec->spec;
  480. int err;
  481. int i;
  482. err = snd_hda_add_new_ctls(codec, spec->mixer);
  483. if (err < 0)
  484. return err;
  485. for (i = 0; i < spec->num_mixers; i++) {
  486. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  487. if (err < 0)
  488. return err;
  489. }
  490. if (spec->multiout.dig_out_nid) {
  491. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  492. if (err < 0)
  493. return err;
  494. }
  495. if (spec->dig_in_nid) {
  496. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  497. if (err < 0)
  498. return err;
  499. }
  500. return 0;
  501. }
  502. static unsigned int ref9200_pin_configs[8] = {
  503. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  504. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  505. };
  506. /*
  507. STAC 9200 pin configs for
  508. 102801A8
  509. 102801DE
  510. 102801E8
  511. */
  512. static unsigned int dell9200_d21_pin_configs[8] = {
  513. 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
  514. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  515. };
  516. /*
  517. STAC 9200 pin configs for
  518. 102801C0
  519. 102801C1
  520. */
  521. static unsigned int dell9200_d22_pin_configs[8] = {
  522. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  523. 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
  524. };
  525. /*
  526. STAC 9200 pin configs for
  527. 102801C4 (Dell Dimension E310)
  528. 102801C5
  529. 102801C7
  530. 102801D9
  531. 102801DA
  532. 102801E3
  533. */
  534. static unsigned int dell9200_d23_pin_configs[8] = {
  535. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  536. 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
  537. };
  538. /*
  539. STAC 9200-32 pin configs for
  540. 102801B5 (Dell Inspiron 630m)
  541. 102801D8 (Dell Inspiron 640m)
  542. */
  543. static unsigned int dell9200_m21_pin_configs[8] = {
  544. 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
  545. 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
  546. };
  547. /*
  548. STAC 9200-32 pin configs for
  549. 102801C2 (Dell Latitude D620)
  550. 102801C8
  551. 102801CC (Dell Latitude D820)
  552. 102801D4
  553. 102801D6
  554. */
  555. static unsigned int dell9200_m22_pin_configs[8] = {
  556. 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
  557. 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
  558. };
  559. /*
  560. STAC 9200-32 pin configs for
  561. 102801CE (Dell XPS M1710)
  562. 102801CF (Dell Precision M90)
  563. */
  564. static unsigned int dell9200_m23_pin_configs[8] = {
  565. 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
  566. 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
  567. };
  568. /*
  569. STAC 9200-32 pin configs for
  570. 102801C9
  571. 102801CA
  572. 102801CB (Dell Latitude 120L)
  573. 102801D3
  574. */
  575. static unsigned int dell9200_m24_pin_configs[8] = {
  576. 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
  577. 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
  578. };
  579. /*
  580. STAC 9200-32 pin configs for
  581. 102801BD (Dell Inspiron E1505n)
  582. 102801EE
  583. 102801EF
  584. */
  585. static unsigned int dell9200_m25_pin_configs[8] = {
  586. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  587. 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
  588. };
  589. /*
  590. STAC 9200-32 pin configs for
  591. 102801F5 (Dell Inspiron 1501)
  592. 102801F6
  593. */
  594. static unsigned int dell9200_m26_pin_configs[8] = {
  595. 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
  596. 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
  597. };
  598. /*
  599. STAC 9200-32
  600. 102801CD (Dell Inspiron E1705/9400)
  601. */
  602. static unsigned int dell9200_m27_pin_configs[8] = {
  603. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  604. 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
  605. };
  606. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  607. [STAC_REF] = ref9200_pin_configs,
  608. [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
  609. [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
  610. [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
  611. [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
  612. [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
  613. [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
  614. [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
  615. [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
  616. [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
  617. [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
  618. };
  619. static const char *stac9200_models[STAC_9200_MODELS] = {
  620. [STAC_REF] = "ref",
  621. [STAC_9200_DELL_D21] = "dell-d21",
  622. [STAC_9200_DELL_D22] = "dell-d22",
  623. [STAC_9200_DELL_D23] = "dell-d23",
  624. [STAC_9200_DELL_M21] = "dell-m21",
  625. [STAC_9200_DELL_M22] = "dell-m22",
  626. [STAC_9200_DELL_M23] = "dell-m23",
  627. [STAC_9200_DELL_M24] = "dell-m24",
  628. [STAC_9200_DELL_M25] = "dell-m25",
  629. [STAC_9200_DELL_M26] = "dell-m26",
  630. [STAC_9200_DELL_M27] = "dell-m27",
  631. [STAC_9200_GATEWAY] = "gateway",
  632. };
  633. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  634. /* SigmaTel reference board */
  635. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  636. "DFI LanParty", STAC_REF),
  637. /* Dell laptops have BIOS problem */
  638. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
  639. "unknown Dell", STAC_9200_DELL_D21),
  640. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  641. "Dell Inspiron 630m", STAC_9200_DELL_M21),
  642. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
  643. "Dell Inspiron E1505n", STAC_9200_DELL_M25),
  644. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
  645. "unknown Dell", STAC_9200_DELL_D22),
  646. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
  647. "unknown Dell", STAC_9200_DELL_D22),
  648. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  649. "Dell Latitude D620", STAC_9200_DELL_M22),
  650. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
  651. "unknown Dell", STAC_9200_DELL_D23),
  652. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
  653. "unknown Dell", STAC_9200_DELL_D23),
  654. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
  655. "unknown Dell", STAC_9200_DELL_M22),
  656. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
  657. "unknown Dell", STAC_9200_DELL_M24),
  658. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
  659. "unknown Dell", STAC_9200_DELL_M24),
  660. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  661. "Dell Latitude 120L", STAC_9200_DELL_M24),
  662. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  663. "Dell Latitude D820", STAC_9200_DELL_M22),
  664. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  665. "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
  666. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  667. "Dell XPS M1710", STAC_9200_DELL_M23),
  668. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  669. "Dell Precision M90", STAC_9200_DELL_M23),
  670. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
  671. "unknown Dell", STAC_9200_DELL_M22),
  672. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
  673. "unknown Dell", STAC_9200_DELL_M22),
  674. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  675. "unknown Dell", STAC_9200_DELL_M22),
  676. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  677. "Dell Inspiron 640m", STAC_9200_DELL_M21),
  678. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
  679. "unknown Dell", STAC_9200_DELL_D23),
  680. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
  681. "unknown Dell", STAC_9200_DELL_D23),
  682. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
  683. "unknown Dell", STAC_9200_DELL_D21),
  684. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
  685. "unknown Dell", STAC_9200_DELL_D23),
  686. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
  687. "unknown Dell", STAC_9200_DELL_D21),
  688. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
  689. "unknown Dell", STAC_9200_DELL_M25),
  690. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
  691. "unknown Dell", STAC_9200_DELL_M25),
  692. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  693. "Dell Inspiron 1501", STAC_9200_DELL_M26),
  694. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
  695. "unknown Dell", STAC_9200_DELL_M26),
  696. /* Panasonic */
  697. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
  698. /* Gateway machines needs EAPD to be set on resume */
  699. SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
  700. SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
  701. STAC_9200_GATEWAY),
  702. SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
  703. STAC_9200_GATEWAY),
  704. {} /* terminator */
  705. };
  706. static unsigned int ref925x_pin_configs[8] = {
  707. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  708. 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
  709. };
  710. static unsigned int stac925x_MA6_pin_configs[8] = {
  711. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  712. 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
  713. };
  714. static unsigned int stac925x_PA6_pin_configs[8] = {
  715. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  716. 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
  717. };
  718. static unsigned int stac925xM2_2_pin_configs[8] = {
  719. 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
  720. 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
  721. };
  722. static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  723. [STAC_REF] = ref925x_pin_configs,
  724. [STAC_M2_2] = stac925xM2_2_pin_configs,
  725. [STAC_MA6] = stac925x_MA6_pin_configs,
  726. [STAC_PA6] = stac925x_PA6_pin_configs,
  727. };
  728. static const char *stac925x_models[STAC_925x_MODELS] = {
  729. [STAC_REF] = "ref",
  730. [STAC_M2_2] = "m2-2",
  731. [STAC_MA6] = "m6",
  732. [STAC_PA6] = "pa6",
  733. };
  734. static struct snd_pci_quirk stac925x_cfg_tbl[] = {
  735. /* SigmaTel reference board */
  736. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  737. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  738. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
  739. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
  740. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
  741. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
  742. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
  743. {} /* terminator */
  744. };
  745. static unsigned int ref92hd71bxx_pin_configs[10] = {
  746. 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
  747. 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
  748. 0x90a000f0, 0x01452050,
  749. };
  750. static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
  751. [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
  752. };
  753. static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
  754. [STAC_92HD71BXX_REF] = "ref",
  755. };
  756. static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
  757. /* SigmaTel reference board */
  758. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  759. "DFI LanParty", STAC_92HD71BXX_REF),
  760. {} /* terminator */
  761. };
  762. static unsigned int ref922x_pin_configs[10] = {
  763. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  764. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  765. 0x40000100, 0x40000100,
  766. };
  767. /*
  768. STAC 922X pin configs for
  769. 102801A7
  770. 102801AB
  771. 102801A9
  772. 102801D1
  773. 102801D2
  774. */
  775. static unsigned int dell_922x_d81_pin_configs[10] = {
  776. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  777. 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
  778. 0x01813122, 0x400001f2,
  779. };
  780. /*
  781. STAC 922X pin configs for
  782. 102801AC
  783. 102801D0
  784. */
  785. static unsigned int dell_922x_d82_pin_configs[10] = {
  786. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  787. 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
  788. 0x01813122, 0x400001f1,
  789. };
  790. /*
  791. STAC 922X pin configs for
  792. 102801BF
  793. */
  794. static unsigned int dell_922x_m81_pin_configs[10] = {
  795. 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
  796. 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
  797. 0x40C003f1, 0x405003f0,
  798. };
  799. /*
  800. STAC 9221 A1 pin configs for
  801. 102801D7 (Dell XPS M1210)
  802. */
  803. static unsigned int dell_922x_m82_pin_configs[10] = {
  804. 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
  805. 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
  806. 0x508003f3, 0x405003f4,
  807. };
  808. static unsigned int d945gtp3_pin_configs[10] = {
  809. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  810. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  811. 0x02a19120, 0x40000100,
  812. };
  813. static unsigned int d945gtp5_pin_configs[10] = {
  814. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  815. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  816. 0x02a19320, 0x40000100,
  817. };
  818. static unsigned int intel_mac_v1_pin_configs[10] = {
  819. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  820. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  821. 0x400000fc, 0x400000fb,
  822. };
  823. static unsigned int intel_mac_v2_pin_configs[10] = {
  824. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  825. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  826. 0x400000fc, 0x400000fb,
  827. };
  828. static unsigned int intel_mac_v3_pin_configs[10] = {
  829. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  830. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  831. 0x400000fc, 0x400000fb,
  832. };
  833. static unsigned int intel_mac_v4_pin_configs[10] = {
  834. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  835. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  836. 0x400000fc, 0x400000fb,
  837. };
  838. static unsigned int intel_mac_v5_pin_configs[10] = {
  839. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  840. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  841. 0x400000fc, 0x400000fb,
  842. };
  843. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  844. [STAC_D945_REF] = ref922x_pin_configs,
  845. [STAC_D945GTP3] = d945gtp3_pin_configs,
  846. [STAC_D945GTP5] = d945gtp5_pin_configs,
  847. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  848. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  849. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  850. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  851. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  852. /* for backward compatibility */
  853. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  854. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  855. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  856. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  857. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  858. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  859. [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
  860. [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
  861. [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
  862. [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
  863. };
  864. static const char *stac922x_models[STAC_922X_MODELS] = {
  865. [STAC_D945_REF] = "ref",
  866. [STAC_D945GTP5] = "5stack",
  867. [STAC_D945GTP3] = "3stack",
  868. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  869. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  870. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  871. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  872. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  873. /* for backward compatibility */
  874. [STAC_MACMINI] = "macmini",
  875. [STAC_MACBOOK] = "macbook",
  876. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  877. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  878. [STAC_IMAC_INTEL] = "imac-intel",
  879. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  880. [STAC_922X_DELL_D81] = "dell-d81",
  881. [STAC_922X_DELL_D82] = "dell-d82",
  882. [STAC_922X_DELL_M81] = "dell-m81",
  883. [STAC_922X_DELL_M82] = "dell-m82",
  884. };
  885. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  886. /* SigmaTel reference board */
  887. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  888. "DFI LanParty", STAC_D945_REF),
  889. /* Intel 945G based systems */
  890. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  891. "Intel D945G", STAC_D945GTP3),
  892. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  893. "Intel D945G", STAC_D945GTP3),
  894. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  895. "Intel D945G", STAC_D945GTP3),
  896. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  897. "Intel D945G", STAC_D945GTP3),
  898. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  899. "Intel D945G", STAC_D945GTP3),
  900. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  901. "Intel D945G", STAC_D945GTP3),
  902. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  903. "Intel D945G", STAC_D945GTP3),
  904. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  905. "Intel D945G", STAC_D945GTP3),
  906. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  907. "Intel D945G", STAC_D945GTP3),
  908. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  909. "Intel D945G", STAC_D945GTP3),
  910. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  911. "Intel D945G", STAC_D945GTP3),
  912. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  913. "Intel D945G", STAC_D945GTP3),
  914. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  915. "Intel D945G", STAC_D945GTP3),
  916. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  917. "Intel D945G", STAC_D945GTP3),
  918. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  919. "Intel D945G", STAC_D945GTP3),
  920. /* Intel D945G 5-stack systems */
  921. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  922. "Intel D945G", STAC_D945GTP5),
  923. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  924. "Intel D945G", STAC_D945GTP5),
  925. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  926. "Intel D945G", STAC_D945GTP5),
  927. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  928. "Intel D945G", STAC_D945GTP5),
  929. /* Intel 945P based systems */
  930. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  931. "Intel D945P", STAC_D945GTP3),
  932. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  933. "Intel D945P", STAC_D945GTP3),
  934. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  935. "Intel D945P", STAC_D945GTP3),
  936. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  937. "Intel D945P", STAC_D945GTP3),
  938. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  939. "Intel D945P", STAC_D945GTP3),
  940. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  941. "Intel D945P", STAC_D945GTP5),
  942. /* other systems */
  943. /* Apple Mac Mini (early 2006) */
  944. SND_PCI_QUIRK(0x8384, 0x7680,
  945. "Mac Mini", STAC_INTEL_MAC_V3),
  946. /* Dell systems */
  947. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
  948. "unknown Dell", STAC_922X_DELL_D81),
  949. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
  950. "unknown Dell", STAC_922X_DELL_D81),
  951. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
  952. "unknown Dell", STAC_922X_DELL_D81),
  953. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
  954. "unknown Dell", STAC_922X_DELL_D82),
  955. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
  956. "unknown Dell", STAC_922X_DELL_M81),
  957. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
  958. "unknown Dell", STAC_922X_DELL_D82),
  959. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
  960. "unknown Dell", STAC_922X_DELL_D81),
  961. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
  962. "unknown Dell", STAC_922X_DELL_D81),
  963. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
  964. "Dell XPS M1210", STAC_922X_DELL_M82),
  965. {} /* terminator */
  966. };
  967. static unsigned int ref927x_pin_configs[14] = {
  968. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  969. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  970. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  971. 0x01c42190, 0x40000100,
  972. };
  973. static unsigned int d965_3st_pin_configs[14] = {
  974. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  975. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  976. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  977. 0x40000100, 0x40000100
  978. };
  979. static unsigned int d965_5st_pin_configs[14] = {
  980. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  981. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  982. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  983. 0x40000100, 0x40000100
  984. };
  985. static unsigned int dell_3st_pin_configs[14] = {
  986. 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
  987. 0x01111212, 0x01116211, 0x01813050, 0x01112214,
  988. 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
  989. 0x40c003fc, 0x40000100
  990. };
  991. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  992. [STAC_D965_REF] = ref927x_pin_configs,
  993. [STAC_D965_3ST] = d965_3st_pin_configs,
  994. [STAC_D965_5ST] = d965_5st_pin_configs,
  995. [STAC_DELL_3ST] = dell_3st_pin_configs,
  996. };
  997. static const char *stac927x_models[STAC_927X_MODELS] = {
  998. [STAC_D965_REF] = "ref",
  999. [STAC_D965_3ST] = "3stack",
  1000. [STAC_D965_5ST] = "5stack",
  1001. [STAC_DELL_3ST] = "dell-3stack",
  1002. };
  1003. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  1004. /* SigmaTel reference board */
  1005. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1006. "DFI LanParty", STAC_D965_REF),
  1007. /* Intel 946 based systems */
  1008. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  1009. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  1010. /* 965 based 3 stack systems */
  1011. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
  1012. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
  1013. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
  1014. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
  1015. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
  1016. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
  1017. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
  1018. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
  1019. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
  1020. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
  1021. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
  1022. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
  1023. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
  1024. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
  1025. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
  1026. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
  1027. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
  1028. /* Dell 3 stack systems */
  1029. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
  1030. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
  1031. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
  1032. /* 965 based 5 stack systems */
  1033. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
  1034. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
  1035. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
  1036. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
  1037. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
  1038. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
  1039. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
  1040. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
  1041. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
  1042. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
  1043. {} /* terminator */
  1044. };
  1045. static unsigned int ref9205_pin_configs[12] = {
  1046. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  1047. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  1048. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  1049. };
  1050. /*
  1051. STAC 9205 pin configs for
  1052. 102801F1
  1053. 102801F2
  1054. 102801FC
  1055. 102801FD
  1056. 10280204
  1057. 1028021F
  1058. */
  1059. static unsigned int dell_9205_m42_pin_configs[12] = {
  1060. 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
  1061. 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
  1062. 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
  1063. };
  1064. /*
  1065. STAC 9205 pin configs for
  1066. 102801F9
  1067. 102801FA
  1068. 102801FE
  1069. 102801FF (Dell Precision M4300)
  1070. 10280206
  1071. 10280200
  1072. 10280201
  1073. */
  1074. static unsigned int dell_9205_m43_pin_configs[12] = {
  1075. 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
  1076. 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
  1077. 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
  1078. };
  1079. static unsigned int dell_9205_m44_pin_configs[12] = {
  1080. 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
  1081. 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
  1082. 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
  1083. };
  1084. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  1085. [STAC_9205_REF] = ref9205_pin_configs,
  1086. [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
  1087. [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
  1088. [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
  1089. };
  1090. static const char *stac9205_models[STAC_9205_MODELS] = {
  1091. [STAC_9205_REF] = "ref",
  1092. [STAC_9205_DELL_M42] = "dell-m42",
  1093. [STAC_9205_DELL_M43] = "dell-m43",
  1094. [STAC_9205_DELL_M44] = "dell-m44",
  1095. };
  1096. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  1097. /* SigmaTel reference board */
  1098. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1099. "DFI LanParty", STAC_9205_REF),
  1100. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1101. "unknown Dell", STAC_9205_DELL_M42),
  1102. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1103. "unknown Dell", STAC_9205_DELL_M42),
  1104. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
  1105. "Dell Precision", STAC_9205_DELL_M43),
  1106. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
  1107. "Dell Precision", STAC_9205_DELL_M43),
  1108. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
  1109. "Dell Precision", STAC_9205_DELL_M43),
  1110. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
  1111. "Dell Precision", STAC_9205_DELL_M43),
  1112. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
  1113. "Dell Precision", STAC_9205_DELL_M43),
  1114. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1115. "unknown Dell", STAC_9205_DELL_M42),
  1116. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1117. "unknown Dell", STAC_9205_DELL_M42),
  1118. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
  1119. "Dell Precision", STAC_9205_DELL_M43),
  1120. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
  1121. "Dell Precision M4300", STAC_9205_DELL_M43),
  1122. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
  1123. "Dell Precision", STAC_9205_DELL_M43),
  1124. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1125. "Dell Inspiron", STAC_9205_DELL_M44),
  1126. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1127. "Dell Inspiron", STAC_9205_DELL_M44),
  1128. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1129. "Dell Inspiron", STAC_9205_DELL_M44),
  1130. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1131. "Dell Inspiron", STAC_9205_DELL_M44),
  1132. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
  1133. "unknown Dell", STAC_9205_DELL_M42),
  1134. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
  1135. "Dell Inspiron", STAC_9205_DELL_M44),
  1136. {} /* terminator */
  1137. };
  1138. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  1139. {
  1140. int i;
  1141. struct sigmatel_spec *spec = codec->spec;
  1142. if (! spec->bios_pin_configs) {
  1143. spec->bios_pin_configs = kcalloc(spec->num_pins,
  1144. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  1145. if (! spec->bios_pin_configs)
  1146. return -ENOMEM;
  1147. }
  1148. for (i = 0; i < spec->num_pins; i++) {
  1149. hda_nid_t nid = spec->pin_nids[i];
  1150. unsigned int pin_cfg;
  1151. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  1152. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  1153. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  1154. nid, pin_cfg);
  1155. spec->bios_pin_configs[i] = pin_cfg;
  1156. }
  1157. return 0;
  1158. }
  1159. static void stac92xx_set_config_reg(struct hda_codec *codec,
  1160. hda_nid_t pin_nid, unsigned int pin_config)
  1161. {
  1162. int i;
  1163. snd_hda_codec_write(codec, pin_nid, 0,
  1164. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  1165. pin_config & 0x000000ff);
  1166. snd_hda_codec_write(codec, pin_nid, 0,
  1167. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  1168. (pin_config & 0x0000ff00) >> 8);
  1169. snd_hda_codec_write(codec, pin_nid, 0,
  1170. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  1171. (pin_config & 0x00ff0000) >> 16);
  1172. snd_hda_codec_write(codec, pin_nid, 0,
  1173. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  1174. pin_config >> 24);
  1175. i = snd_hda_codec_read(codec, pin_nid, 0,
  1176. AC_VERB_GET_CONFIG_DEFAULT,
  1177. 0x00);
  1178. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
  1179. pin_nid, i);
  1180. }
  1181. static void stac92xx_set_config_regs(struct hda_codec *codec)
  1182. {
  1183. int i;
  1184. struct sigmatel_spec *spec = codec->spec;
  1185. if (!spec->pin_configs)
  1186. return;
  1187. for (i = 0; i < spec->num_pins; i++)
  1188. stac92xx_set_config_reg(codec, spec->pin_nids[i],
  1189. spec->pin_configs[i]);
  1190. }
  1191. static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
  1192. {
  1193. struct sigmatel_spec *spec = codec->spec;
  1194. /* Configure GPIOx as output */
  1195. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1196. AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
  1197. /* Configure GPIOx as CMOS */
  1198. snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
  1199. /* Assert GPIOx */
  1200. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1201. AC_VERB_SET_GPIO_DATA, spec->gpio_data);
  1202. /* Enable GPIOx */
  1203. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1204. AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
  1205. }
  1206. /*
  1207. * Analog playback callbacks
  1208. */
  1209. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1210. struct hda_codec *codec,
  1211. struct snd_pcm_substream *substream)
  1212. {
  1213. struct sigmatel_spec *spec = codec->spec;
  1214. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  1215. }
  1216. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1217. struct hda_codec *codec,
  1218. unsigned int stream_tag,
  1219. unsigned int format,
  1220. struct snd_pcm_substream *substream)
  1221. {
  1222. struct sigmatel_spec *spec = codec->spec;
  1223. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  1224. }
  1225. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1226. struct hda_codec *codec,
  1227. struct snd_pcm_substream *substream)
  1228. {
  1229. struct sigmatel_spec *spec = codec->spec;
  1230. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1231. }
  1232. /*
  1233. * Digital playback callbacks
  1234. */
  1235. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1236. struct hda_codec *codec,
  1237. struct snd_pcm_substream *substream)
  1238. {
  1239. struct sigmatel_spec *spec = codec->spec;
  1240. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1241. }
  1242. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1243. struct hda_codec *codec,
  1244. struct snd_pcm_substream *substream)
  1245. {
  1246. struct sigmatel_spec *spec = codec->spec;
  1247. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1248. }
  1249. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1250. struct hda_codec *codec,
  1251. unsigned int stream_tag,
  1252. unsigned int format,
  1253. struct snd_pcm_substream *substream)
  1254. {
  1255. struct sigmatel_spec *spec = codec->spec;
  1256. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1257. stream_tag, format, substream);
  1258. }
  1259. /*
  1260. * Analog capture callbacks
  1261. */
  1262. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1263. struct hda_codec *codec,
  1264. unsigned int stream_tag,
  1265. unsigned int format,
  1266. struct snd_pcm_substream *substream)
  1267. {
  1268. struct sigmatel_spec *spec = codec->spec;
  1269. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1270. stream_tag, 0, format);
  1271. return 0;
  1272. }
  1273. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1274. struct hda_codec *codec,
  1275. struct snd_pcm_substream *substream)
  1276. {
  1277. struct sigmatel_spec *spec = codec->spec;
  1278. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  1279. return 0;
  1280. }
  1281. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  1282. .substreams = 1,
  1283. .channels_min = 2,
  1284. .channels_max = 2,
  1285. /* NID is set in stac92xx_build_pcms */
  1286. .ops = {
  1287. .open = stac92xx_dig_playback_pcm_open,
  1288. .close = stac92xx_dig_playback_pcm_close,
  1289. .prepare = stac92xx_dig_playback_pcm_prepare
  1290. },
  1291. };
  1292. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  1293. .substreams = 1,
  1294. .channels_min = 2,
  1295. .channels_max = 2,
  1296. /* NID is set in stac92xx_build_pcms */
  1297. };
  1298. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  1299. .substreams = 1,
  1300. .channels_min = 2,
  1301. .channels_max = 8,
  1302. .nid = 0x02, /* NID to query formats and rates */
  1303. .ops = {
  1304. .open = stac92xx_playback_pcm_open,
  1305. .prepare = stac92xx_playback_pcm_prepare,
  1306. .cleanup = stac92xx_playback_pcm_cleanup
  1307. },
  1308. };
  1309. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  1310. .substreams = 1,
  1311. .channels_min = 2,
  1312. .channels_max = 2,
  1313. .nid = 0x06, /* NID to query formats and rates */
  1314. .ops = {
  1315. .open = stac92xx_playback_pcm_open,
  1316. .prepare = stac92xx_playback_pcm_prepare,
  1317. .cleanup = stac92xx_playback_pcm_cleanup
  1318. },
  1319. };
  1320. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  1321. .channels_min = 2,
  1322. .channels_max = 2,
  1323. /* NID + .substreams is set in stac92xx_build_pcms */
  1324. .ops = {
  1325. .prepare = stac92xx_capture_pcm_prepare,
  1326. .cleanup = stac92xx_capture_pcm_cleanup
  1327. },
  1328. };
  1329. static int stac92xx_build_pcms(struct hda_codec *codec)
  1330. {
  1331. struct sigmatel_spec *spec = codec->spec;
  1332. struct hda_pcm *info = spec->pcm_rec;
  1333. codec->num_pcms = 1;
  1334. codec->pcm_info = info;
  1335. info->name = "STAC92xx Analog";
  1336. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  1337. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  1338. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1339. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
  1340. if (spec->alt_switch) {
  1341. codec->num_pcms++;
  1342. info++;
  1343. info->name = "STAC92xx Analog Alt";
  1344. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  1345. }
  1346. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1347. codec->num_pcms++;
  1348. info++;
  1349. info->name = "STAC92xx Digital";
  1350. if (spec->multiout.dig_out_nid) {
  1351. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  1352. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  1353. }
  1354. if (spec->dig_in_nid) {
  1355. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  1356. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  1357. }
  1358. }
  1359. return 0;
  1360. }
  1361. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  1362. {
  1363. unsigned int pincap = snd_hda_param_read(codec, nid,
  1364. AC_PAR_PIN_CAP);
  1365. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  1366. if (pincap & AC_PINCAP_VREF_100)
  1367. return AC_PINCTL_VREF_100;
  1368. if (pincap & AC_PINCAP_VREF_80)
  1369. return AC_PINCTL_VREF_80;
  1370. if (pincap & AC_PINCAP_VREF_50)
  1371. return AC_PINCTL_VREF_50;
  1372. if (pincap & AC_PINCAP_VREF_GRD)
  1373. return AC_PINCTL_VREF_GRD;
  1374. return 0;
  1375. }
  1376. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  1377. {
  1378. snd_hda_codec_write_cache(codec, nid, 0,
  1379. AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  1380. }
  1381. #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
  1382. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1383. {
  1384. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1385. struct sigmatel_spec *spec = codec->spec;
  1386. int io_idx = kcontrol-> private_value & 0xff;
  1387. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  1388. return 0;
  1389. }
  1390. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1391. {
  1392. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1393. struct sigmatel_spec *spec = codec->spec;
  1394. hda_nid_t nid = kcontrol->private_value >> 8;
  1395. int io_idx = kcontrol-> private_value & 0xff;
  1396. unsigned short val = ucontrol->value.integer.value[0];
  1397. spec->io_switch[io_idx] = val;
  1398. if (val)
  1399. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1400. else {
  1401. unsigned int pinctl = AC_PINCTL_IN_EN;
  1402. if (io_idx) /* set VREF for mic */
  1403. pinctl |= stac92xx_get_vref(codec, nid);
  1404. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1405. }
  1406. return 1;
  1407. }
  1408. #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
  1409. static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
  1410. struct snd_ctl_elem_value *ucontrol)
  1411. {
  1412. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1413. struct sigmatel_spec *spec = codec->spec;
  1414. ucontrol->value.integer.value[0] = spec->clfe_swap;
  1415. return 0;
  1416. }
  1417. static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
  1418. struct snd_ctl_elem_value *ucontrol)
  1419. {
  1420. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1421. struct sigmatel_spec *spec = codec->spec;
  1422. hda_nid_t nid = kcontrol->private_value & 0xff;
  1423. if (spec->clfe_swap == ucontrol->value.integer.value[0])
  1424. return 0;
  1425. spec->clfe_swap = ucontrol->value.integer.value[0];
  1426. snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  1427. spec->clfe_swap ? 0x4 : 0x0);
  1428. return 1;
  1429. }
  1430. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  1431. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1432. .name = xname, \
  1433. .index = 0, \
  1434. .info = stac92xx_io_switch_info, \
  1435. .get = stac92xx_io_switch_get, \
  1436. .put = stac92xx_io_switch_put, \
  1437. .private_value = xpval, \
  1438. }
  1439. #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
  1440. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1441. .name = xname, \
  1442. .index = 0, \
  1443. .info = stac92xx_clfe_switch_info, \
  1444. .get = stac92xx_clfe_switch_get, \
  1445. .put = stac92xx_clfe_switch_put, \
  1446. .private_value = xpval, \
  1447. }
  1448. enum {
  1449. STAC_CTL_WIDGET_VOL,
  1450. STAC_CTL_WIDGET_MUTE,
  1451. STAC_CTL_WIDGET_IO_SWITCH,
  1452. STAC_CTL_WIDGET_CLFE_SWITCH
  1453. };
  1454. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  1455. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1456. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1457. STAC_CODEC_IO_SWITCH(NULL, 0),
  1458. STAC_CODEC_CLFE_SWITCH(NULL, 0),
  1459. };
  1460. /* add dynamic controls */
  1461. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  1462. {
  1463. struct snd_kcontrol_new *knew;
  1464. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1465. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1466. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1467. if (! knew)
  1468. return -ENOMEM;
  1469. if (spec->kctl_alloc) {
  1470. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1471. kfree(spec->kctl_alloc);
  1472. }
  1473. spec->kctl_alloc = knew;
  1474. spec->num_kctl_alloc = num;
  1475. }
  1476. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1477. *knew = stac92xx_control_templates[type];
  1478. knew->name = kstrdup(name, GFP_KERNEL);
  1479. if (! knew->name)
  1480. return -ENOMEM;
  1481. knew->private_value = val;
  1482. spec->num_kctl_used++;
  1483. return 0;
  1484. }
  1485. /* flag inputs as additional dynamic lineouts */
  1486. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  1487. {
  1488. struct sigmatel_spec *spec = codec->spec;
  1489. unsigned int wcaps, wtype;
  1490. int i, num_dacs = 0;
  1491. /* use the wcaps cache to count all DACs available for line-outs */
  1492. for (i = 0; i < codec->num_nodes; i++) {
  1493. wcaps = codec->wcaps[i];
  1494. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1495. if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
  1496. num_dacs++;
  1497. }
  1498. snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
  1499. switch (cfg->line_outs) {
  1500. case 3:
  1501. /* add line-in as side */
  1502. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
  1503. cfg->line_out_pins[cfg->line_outs] =
  1504. cfg->input_pins[AUTO_PIN_LINE];
  1505. spec->line_switch = 1;
  1506. cfg->line_outs++;
  1507. }
  1508. break;
  1509. case 2:
  1510. /* add line-in as clfe and mic as side */
  1511. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
  1512. cfg->line_out_pins[cfg->line_outs] =
  1513. cfg->input_pins[AUTO_PIN_LINE];
  1514. spec->line_switch = 1;
  1515. cfg->line_outs++;
  1516. }
  1517. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
  1518. cfg->line_out_pins[cfg->line_outs] =
  1519. cfg->input_pins[AUTO_PIN_MIC];
  1520. spec->mic_switch = 1;
  1521. cfg->line_outs++;
  1522. }
  1523. break;
  1524. case 1:
  1525. /* add line-in as surr and mic as clfe */
  1526. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
  1527. cfg->line_out_pins[cfg->line_outs] =
  1528. cfg->input_pins[AUTO_PIN_LINE];
  1529. spec->line_switch = 1;
  1530. cfg->line_outs++;
  1531. }
  1532. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
  1533. cfg->line_out_pins[cfg->line_outs] =
  1534. cfg->input_pins[AUTO_PIN_MIC];
  1535. spec->mic_switch = 1;
  1536. cfg->line_outs++;
  1537. }
  1538. break;
  1539. }
  1540. return 0;
  1541. }
  1542. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1543. {
  1544. int i;
  1545. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1546. if (spec->multiout.dac_nids[i] == nid)
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. /*
  1552. * Fill in the dac_nids table from the parsed pin configuration
  1553. * This function only works when every pin in line_out_pins[]
  1554. * contains atleast one DAC in its connection list. Some 92xx
  1555. * codecs are not connected directly to a DAC, such as the 9200
  1556. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  1557. */
  1558. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  1559. struct auto_pin_cfg *cfg)
  1560. {
  1561. struct sigmatel_spec *spec = codec->spec;
  1562. int i, j, conn_len = 0;
  1563. hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
  1564. unsigned int wcaps, wtype;
  1565. for (i = 0; i < cfg->line_outs; i++) {
  1566. nid = cfg->line_out_pins[i];
  1567. conn_len = snd_hda_get_connections(codec, nid, conn,
  1568. HDA_MAX_CONNECTIONS);
  1569. for (j = 0; j < conn_len; j++) {
  1570. wcaps = snd_hda_param_read(codec, conn[j],
  1571. AC_PAR_AUDIO_WIDGET_CAP);
  1572. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1573. if (wtype != AC_WID_AUD_OUT ||
  1574. (wcaps & AC_WCAP_DIGITAL))
  1575. continue;
  1576. /* conn[j] is a DAC routed to this line-out */
  1577. if (!is_in_dac_nids(spec, conn[j]))
  1578. break;
  1579. }
  1580. if (j == conn_len) {
  1581. if (spec->multiout.num_dacs > 0) {
  1582. /* we have already working output pins,
  1583. * so let's drop the broken ones again
  1584. */
  1585. cfg->line_outs = spec->multiout.num_dacs;
  1586. break;
  1587. }
  1588. /* error out, no available DAC found */
  1589. snd_printk(KERN_ERR
  1590. "%s: No available DAC for pin 0x%x\n",
  1591. __func__, nid);
  1592. return -ENODEV;
  1593. }
  1594. spec->multiout.dac_nids[i] = conn[j];
  1595. spec->multiout.num_dacs++;
  1596. if (conn_len > 1) {
  1597. /* select this DAC in the pin's input mux */
  1598. snd_hda_codec_write_cache(codec, nid, 0,
  1599. AC_VERB_SET_CONNECT_SEL, j);
  1600. }
  1601. }
  1602. snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1603. spec->multiout.num_dacs,
  1604. spec->multiout.dac_nids[0],
  1605. spec->multiout.dac_nids[1],
  1606. spec->multiout.dac_nids[2],
  1607. spec->multiout.dac_nids[3],
  1608. spec->multiout.dac_nids[4]);
  1609. return 0;
  1610. }
  1611. /* create volume control/switch for the given prefx type */
  1612. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  1613. {
  1614. char name[32];
  1615. int err;
  1616. sprintf(name, "%s Playback Volume", pfx);
  1617. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  1618. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1619. if (err < 0)
  1620. return err;
  1621. sprintf(name, "%s Playback Switch", pfx);
  1622. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  1623. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1624. if (err < 0)
  1625. return err;
  1626. return 0;
  1627. }
  1628. /* add playback controls from the parsed DAC table */
  1629. static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
  1630. const struct auto_pin_cfg *cfg)
  1631. {
  1632. static const char *chname[4] = {
  1633. "Front", "Surround", NULL /*CLFE*/, "Side"
  1634. };
  1635. hda_nid_t nid;
  1636. int i, err;
  1637. struct sigmatel_spec *spec = codec->spec;
  1638. unsigned int wid_caps;
  1639. for (i = 0; i < cfg->line_outs; i++) {
  1640. if (!spec->multiout.dac_nids[i])
  1641. continue;
  1642. nid = spec->multiout.dac_nids[i];
  1643. if (i == 2) {
  1644. /* Center/LFE */
  1645. err = create_controls(spec, "Center", nid, 1);
  1646. if (err < 0)
  1647. return err;
  1648. err = create_controls(spec, "LFE", nid, 2);
  1649. if (err < 0)
  1650. return err;
  1651. wid_caps = get_wcaps(codec, nid);
  1652. if (wid_caps & AC_WCAP_LR_SWAP) {
  1653. err = stac92xx_add_control(spec,
  1654. STAC_CTL_WIDGET_CLFE_SWITCH,
  1655. "Swap Center/LFE Playback Switch", nid);
  1656. if (err < 0)
  1657. return err;
  1658. }
  1659. } else {
  1660. err = create_controls(spec, chname[i], nid, 3);
  1661. if (err < 0)
  1662. return err;
  1663. }
  1664. }
  1665. if (spec->line_switch)
  1666. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  1667. return err;
  1668. if (spec->mic_switch)
  1669. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  1670. return err;
  1671. return 0;
  1672. }
  1673. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1674. {
  1675. if (is_in_dac_nids(spec, nid))
  1676. return 1;
  1677. if (spec->multiout.hp_nid == nid)
  1678. return 1;
  1679. return 0;
  1680. }
  1681. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  1682. {
  1683. if (!spec->multiout.hp_nid)
  1684. spec->multiout.hp_nid = nid;
  1685. else if (spec->multiout.num_dacs > 4) {
  1686. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  1687. return 1;
  1688. } else {
  1689. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  1690. spec->multiout.num_dacs++;
  1691. }
  1692. return 0;
  1693. }
  1694. /* add playback controls for Speaker and HP outputs */
  1695. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  1696. struct auto_pin_cfg *cfg)
  1697. {
  1698. struct sigmatel_spec *spec = codec->spec;
  1699. hda_nid_t nid;
  1700. int i, old_num_dacs, err;
  1701. old_num_dacs = spec->multiout.num_dacs;
  1702. for (i = 0; i < cfg->hp_outs; i++) {
  1703. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  1704. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1705. spec->hp_detect = 1;
  1706. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  1707. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1708. if (check_in_dac_nids(spec, nid))
  1709. nid = 0;
  1710. if (! nid)
  1711. continue;
  1712. add_spec_dacs(spec, nid);
  1713. }
  1714. for (i = 0; i < cfg->speaker_outs; i++) {
  1715. nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
  1716. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1717. if (check_in_dac_nids(spec, nid))
  1718. nid = 0;
  1719. if (! nid)
  1720. continue;
  1721. add_spec_dacs(spec, nid);
  1722. }
  1723. for (i = 0; i < cfg->line_outs; i++) {
  1724. nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
  1725. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1726. if (check_in_dac_nids(spec, nid))
  1727. nid = 0;
  1728. if (! nid)
  1729. continue;
  1730. add_spec_dacs(spec, nid);
  1731. }
  1732. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  1733. static const char *pfxs[] = {
  1734. "Speaker", "External Speaker", "Speaker2",
  1735. };
  1736. err = create_controls(spec, pfxs[i - old_num_dacs],
  1737. spec->multiout.dac_nids[i], 3);
  1738. if (err < 0)
  1739. return err;
  1740. }
  1741. if (spec->multiout.hp_nid) {
  1742. const char *pfx;
  1743. if (old_num_dacs == spec->multiout.num_dacs)
  1744. pfx = "Master";
  1745. else
  1746. pfx = "Headphone";
  1747. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1748. if (err < 0)
  1749. return err;
  1750. }
  1751. return 0;
  1752. }
  1753. /* labels for dmic mux inputs */
  1754. static const char *stac92xx_dmic_labels[5] = {
  1755. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1756. "Digital Mic 3", "Digital Mic 4"
  1757. };
  1758. /* create playback/capture controls for input pins on dmic capable codecs */
  1759. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1760. const struct auto_pin_cfg *cfg)
  1761. {
  1762. struct sigmatel_spec *spec = codec->spec;
  1763. struct hda_input_mux *dimux = &spec->private_dimux;
  1764. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1765. int i, j;
  1766. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1767. dimux->items[dimux->num_items].index = 0;
  1768. dimux->num_items++;
  1769. for (i = 0; i < spec->num_dmics; i++) {
  1770. int index;
  1771. int num_cons;
  1772. unsigned int def_conf;
  1773. def_conf = snd_hda_codec_read(codec,
  1774. spec->dmic_nids[i],
  1775. 0,
  1776. AC_VERB_GET_CONFIG_DEFAULT,
  1777. 0);
  1778. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1779. continue;
  1780. num_cons = snd_hda_get_connections(codec,
  1781. spec->dmux_nid,
  1782. con_lst,
  1783. HDA_MAX_NUM_INPUTS);
  1784. for (j = 0; j < num_cons; j++)
  1785. if (con_lst[j] == spec->dmic_nids[i]) {
  1786. index = j;
  1787. goto found;
  1788. }
  1789. continue;
  1790. found:
  1791. dimux->items[dimux->num_items].label =
  1792. stac92xx_dmic_labels[dimux->num_items];
  1793. dimux->items[dimux->num_items].index = index;
  1794. dimux->num_items++;
  1795. }
  1796. return 0;
  1797. }
  1798. /* create playback/capture controls for input pins */
  1799. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1800. {
  1801. struct sigmatel_spec *spec = codec->spec;
  1802. struct hda_input_mux *imux = &spec->private_imux;
  1803. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1804. int i, j, k;
  1805. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1806. int index;
  1807. if (!cfg->input_pins[i])
  1808. continue;
  1809. index = -1;
  1810. for (j = 0; j < spec->num_muxes; j++) {
  1811. int num_cons;
  1812. num_cons = snd_hda_get_connections(codec,
  1813. spec->mux_nids[j],
  1814. con_lst,
  1815. HDA_MAX_NUM_INPUTS);
  1816. for (k = 0; k < num_cons; k++)
  1817. if (con_lst[k] == cfg->input_pins[i]) {
  1818. index = k;
  1819. goto found;
  1820. }
  1821. }
  1822. continue;
  1823. found:
  1824. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1825. imux->items[imux->num_items].index = index;
  1826. imux->num_items++;
  1827. }
  1828. if (imux->num_items) {
  1829. /*
  1830. * Set the current input for the muxes.
  1831. * The STAC9221 has two input muxes with identical source
  1832. * NID lists. Hopefully this won't get confused.
  1833. */
  1834. for (i = 0; i < spec->num_muxes; i++) {
  1835. snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
  1836. AC_VERB_SET_CONNECT_SEL,
  1837. imux->items[0].index);
  1838. }
  1839. }
  1840. return 0;
  1841. }
  1842. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1843. {
  1844. struct sigmatel_spec *spec = codec->spec;
  1845. int i;
  1846. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1847. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1848. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1849. }
  1850. }
  1851. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1852. {
  1853. struct sigmatel_spec *spec = codec->spec;
  1854. int i;
  1855. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1856. hda_nid_t pin;
  1857. pin = spec->autocfg.hp_pins[i];
  1858. if (pin) /* connect to front */
  1859. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1860. }
  1861. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1862. hda_nid_t pin;
  1863. pin = spec->autocfg.speaker_pins[i];
  1864. if (pin) /* connect to front */
  1865. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1866. }
  1867. }
  1868. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1869. {
  1870. struct sigmatel_spec *spec = codec->spec;
  1871. int err;
  1872. int hp_speaker_swap = 0;
  1873. if ((err = snd_hda_parse_pin_def_config(codec,
  1874. &spec->autocfg,
  1875. spec->dmic_nids)) < 0)
  1876. return err;
  1877. if (! spec->autocfg.line_outs)
  1878. return 0; /* can't find valid pin config */
  1879. /* If we have no real line-out pin and multiple hp-outs, HPs should
  1880. * be set up as multi-channel outputs.
  1881. */
  1882. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
  1883. spec->autocfg.hp_outs > 1) {
  1884. /* Copy hp_outs to line_outs, backup line_outs in
  1885. * speaker_outs so that the following routines can handle
  1886. * HP pins as primary outputs.
  1887. */
  1888. memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
  1889. sizeof(spec->autocfg.line_out_pins));
  1890. spec->autocfg.speaker_outs = spec->autocfg.line_outs;
  1891. memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
  1892. sizeof(spec->autocfg.hp_pins));
  1893. spec->autocfg.line_outs = spec->autocfg.hp_outs;
  1894. hp_speaker_swap = 1;
  1895. }
  1896. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1897. return err;
  1898. if (spec->multiout.num_dacs == 0)
  1899. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1900. return err;
  1901. err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
  1902. if (err < 0)
  1903. return err;
  1904. if (hp_speaker_swap == 1) {
  1905. /* Restore the hp_outs and line_outs */
  1906. memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
  1907. sizeof(spec->autocfg.line_out_pins));
  1908. spec->autocfg.hp_outs = spec->autocfg.line_outs;
  1909. memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
  1910. sizeof(spec->autocfg.speaker_pins));
  1911. spec->autocfg.line_outs = spec->autocfg.speaker_outs;
  1912. memset(spec->autocfg.speaker_pins, 0,
  1913. sizeof(spec->autocfg.speaker_pins));
  1914. spec->autocfg.speaker_outs = 0;
  1915. }
  1916. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  1917. if (err < 0)
  1918. return err;
  1919. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  1920. if (err < 0)
  1921. return err;
  1922. if (spec->num_dmics > 0)
  1923. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1924. &spec->autocfg)) < 0)
  1925. return err;
  1926. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1927. if (spec->multiout.max_channels > 2)
  1928. spec->surr_switch = 1;
  1929. if (spec->autocfg.dig_out_pin)
  1930. spec->multiout.dig_out_nid = dig_out;
  1931. if (spec->autocfg.dig_in_pin)
  1932. spec->dig_in_nid = dig_in;
  1933. if (spec->kctl_alloc)
  1934. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1935. spec->input_mux = &spec->private_imux;
  1936. spec->dinput_mux = &spec->private_dimux;
  1937. return 1;
  1938. }
  1939. /* add playback controls for HP output */
  1940. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1941. struct auto_pin_cfg *cfg)
  1942. {
  1943. struct sigmatel_spec *spec = codec->spec;
  1944. hda_nid_t pin = cfg->hp_pins[0];
  1945. unsigned int wid_caps;
  1946. if (! pin)
  1947. return 0;
  1948. wid_caps = get_wcaps(codec, pin);
  1949. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1950. spec->hp_detect = 1;
  1951. return 0;
  1952. }
  1953. /* add playback controls for LFE output */
  1954. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1955. struct auto_pin_cfg *cfg)
  1956. {
  1957. struct sigmatel_spec *spec = codec->spec;
  1958. int err;
  1959. hda_nid_t lfe_pin = 0x0;
  1960. int i;
  1961. /*
  1962. * search speaker outs and line outs for a mono speaker pin
  1963. * with an amp. If one is found, add LFE controls
  1964. * for it.
  1965. */
  1966. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1967. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1968. unsigned long wcaps = get_wcaps(codec, pin);
  1969. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1970. if (wcaps == AC_WCAP_OUT_AMP)
  1971. /* found a mono speaker with an amp, must be lfe */
  1972. lfe_pin = pin;
  1973. }
  1974. /* if speaker_outs is 0, then speakers may be in line_outs */
  1975. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1976. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1977. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1978. unsigned long cfg;
  1979. cfg = snd_hda_codec_read(codec, pin, 0,
  1980. AC_VERB_GET_CONFIG_DEFAULT,
  1981. 0x00);
  1982. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1983. unsigned long wcaps = get_wcaps(codec, pin);
  1984. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1985. if (wcaps == AC_WCAP_OUT_AMP)
  1986. /* found a mono speaker with an amp,
  1987. must be lfe */
  1988. lfe_pin = pin;
  1989. }
  1990. }
  1991. }
  1992. if (lfe_pin) {
  1993. err = create_controls(spec, "LFE", lfe_pin, 1);
  1994. if (err < 0)
  1995. return err;
  1996. }
  1997. return 0;
  1998. }
  1999. static int stac9200_parse_auto_config(struct hda_codec *codec)
  2000. {
  2001. struct sigmatel_spec *spec = codec->spec;
  2002. int err;
  2003. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  2004. return err;
  2005. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  2006. return err;
  2007. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  2008. return err;
  2009. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  2010. return err;
  2011. if (spec->autocfg.dig_out_pin)
  2012. spec->multiout.dig_out_nid = 0x05;
  2013. if (spec->autocfg.dig_in_pin)
  2014. spec->dig_in_nid = 0x04;
  2015. if (spec->kctl_alloc)
  2016. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  2017. spec->input_mux = &spec->private_imux;
  2018. spec->dinput_mux = &spec->private_dimux;
  2019. return 1;
  2020. }
  2021. /*
  2022. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  2023. * funky external mute control using GPIO pins.
  2024. */
  2025. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  2026. {
  2027. unsigned int gpiostate, gpiomask, gpiodir;
  2028. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  2029. AC_VERB_GET_GPIO_DATA, 0);
  2030. if (!muted)
  2031. gpiostate |= (1 << pin);
  2032. else
  2033. gpiostate &= ~(1 << pin);
  2034. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  2035. AC_VERB_GET_GPIO_MASK, 0);
  2036. gpiomask |= (1 << pin);
  2037. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  2038. AC_VERB_GET_GPIO_DIRECTION, 0);
  2039. gpiodir |= (1 << pin);
  2040. /* AppleHDA seems to do this -- WTF is this verb?? */
  2041. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  2042. snd_hda_codec_write(codec, codec->afg, 0,
  2043. AC_VERB_SET_GPIO_MASK, gpiomask);
  2044. snd_hda_codec_write(codec, codec->afg, 0,
  2045. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  2046. msleep(1);
  2047. snd_hda_codec_write(codec, codec->afg, 0,
  2048. AC_VERB_SET_GPIO_DATA, gpiostate);
  2049. }
  2050. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  2051. unsigned int event)
  2052. {
  2053. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  2054. snd_hda_codec_write_cache(codec, nid, 0,
  2055. AC_VERB_SET_UNSOLICITED_ENABLE,
  2056. (AC_USRSP_EN | event));
  2057. }
  2058. static int stac92xx_init(struct hda_codec *codec)
  2059. {
  2060. struct sigmatel_spec *spec = codec->spec;
  2061. struct auto_pin_cfg *cfg = &spec->autocfg;
  2062. int i;
  2063. snd_hda_sequence_write(codec, spec->init);
  2064. /* set up pins */
  2065. if (spec->hp_detect) {
  2066. /* Enable unsolicited responses on the HP widget */
  2067. for (i = 0; i < cfg->hp_outs; i++)
  2068. enable_pin_detect(codec, cfg->hp_pins[i],
  2069. STAC_HP_EVENT);
  2070. /* force to enable the first line-out; the others are set up
  2071. * in unsol_event
  2072. */
  2073. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  2074. AC_PINCTL_OUT_EN);
  2075. stac92xx_auto_init_hp_out(codec);
  2076. /* fake event to set up pins */
  2077. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2078. } else {
  2079. stac92xx_auto_init_multi_out(codec);
  2080. stac92xx_auto_init_hp_out(codec);
  2081. }
  2082. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2083. hda_nid_t nid = cfg->input_pins[i];
  2084. if (nid) {
  2085. unsigned int pinctl = AC_PINCTL_IN_EN;
  2086. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  2087. pinctl |= stac92xx_get_vref(codec, nid);
  2088. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  2089. }
  2090. }
  2091. if (spec->num_dmics > 0)
  2092. for (i = 0; i < spec->num_dmics; i++)
  2093. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  2094. AC_PINCTL_IN_EN);
  2095. if (cfg->dig_out_pin)
  2096. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  2097. AC_PINCTL_OUT_EN);
  2098. if (cfg->dig_in_pin)
  2099. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  2100. AC_PINCTL_IN_EN);
  2101. if (spec->gpio_mute) {
  2102. stac922x_gpio_mute(codec, 0, 0);
  2103. stac922x_gpio_mute(codec, 1, 0);
  2104. }
  2105. return 0;
  2106. }
  2107. static void stac92xx_free(struct hda_codec *codec)
  2108. {
  2109. struct sigmatel_spec *spec = codec->spec;
  2110. int i;
  2111. if (! spec)
  2112. return;
  2113. if (spec->kctl_alloc) {
  2114. for (i = 0; i < spec->num_kctl_used; i++)
  2115. kfree(spec->kctl_alloc[i].name);
  2116. kfree(spec->kctl_alloc);
  2117. }
  2118. if (spec->bios_pin_configs)
  2119. kfree(spec->bios_pin_configs);
  2120. kfree(spec);
  2121. }
  2122. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2123. unsigned int flag)
  2124. {
  2125. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2126. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2127. if (pin_ctl & AC_PINCTL_IN_EN) {
  2128. /*
  2129. * we need to check the current set-up direction of
  2130. * shared input pins since they can be switched via
  2131. * "xxx as Output" mixer switch
  2132. */
  2133. struct sigmatel_spec *spec = codec->spec;
  2134. struct auto_pin_cfg *cfg = &spec->autocfg;
  2135. if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
  2136. spec->line_switch) ||
  2137. (nid == cfg->input_pins[AUTO_PIN_MIC] &&
  2138. spec->mic_switch))
  2139. return;
  2140. }
  2141. /* if setting pin direction bits, clear the current
  2142. direction bits first */
  2143. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  2144. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  2145. snd_hda_codec_write_cache(codec, nid, 0,
  2146. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2147. pin_ctl | flag);
  2148. }
  2149. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2150. unsigned int flag)
  2151. {
  2152. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2153. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2154. snd_hda_codec_write_cache(codec, nid, 0,
  2155. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2156. pin_ctl & ~flag);
  2157. }
  2158. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  2159. {
  2160. if (!nid)
  2161. return 0;
  2162. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  2163. & (1 << 31))
  2164. return 1;
  2165. return 0;
  2166. }
  2167. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  2168. {
  2169. struct sigmatel_spec *spec = codec->spec;
  2170. struct auto_pin_cfg *cfg = &spec->autocfg;
  2171. int i, presence;
  2172. presence = 0;
  2173. for (i = 0; i < cfg->hp_outs; i++) {
  2174. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  2175. if (presence)
  2176. break;
  2177. }
  2178. if (presence) {
  2179. /* disable lineouts, enable hp */
  2180. for (i = 0; i < cfg->line_outs; i++)
  2181. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  2182. AC_PINCTL_OUT_EN);
  2183. for (i = 0; i < cfg->speaker_outs; i++)
  2184. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  2185. AC_PINCTL_OUT_EN);
  2186. } else {
  2187. /* enable lineouts, disable hp */
  2188. for (i = 0; i < cfg->line_outs; i++)
  2189. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  2190. AC_PINCTL_OUT_EN);
  2191. for (i = 0; i < cfg->speaker_outs; i++)
  2192. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  2193. AC_PINCTL_OUT_EN);
  2194. }
  2195. }
  2196. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  2197. {
  2198. switch (res >> 26) {
  2199. case STAC_HP_EVENT:
  2200. stac92xx_hp_detect(codec, res);
  2201. break;
  2202. }
  2203. }
  2204. #ifdef SND_HDA_NEEDS_RESUME
  2205. static int stac92xx_resume(struct hda_codec *codec)
  2206. {
  2207. struct sigmatel_spec *spec = codec->spec;
  2208. stac92xx_set_config_regs(codec);
  2209. snd_hda_sequence_write(codec, spec->init);
  2210. if (spec->gpio_mute) {
  2211. stac922x_gpio_mute(codec, 0, 0);
  2212. stac922x_gpio_mute(codec, 1, 0);
  2213. }
  2214. snd_hda_codec_resume_amp(codec);
  2215. snd_hda_codec_resume_cache(codec);
  2216. /* invoke unsolicited event to reset the HP state */
  2217. if (spec->hp_detect)
  2218. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2219. return 0;
  2220. }
  2221. #endif
  2222. static struct hda_codec_ops stac92xx_patch_ops = {
  2223. .build_controls = stac92xx_build_controls,
  2224. .build_pcms = stac92xx_build_pcms,
  2225. .init = stac92xx_init,
  2226. .free = stac92xx_free,
  2227. .unsol_event = stac92xx_unsol_event,
  2228. #ifdef SND_HDA_NEEDS_RESUME
  2229. .resume = stac92xx_resume,
  2230. #endif
  2231. };
  2232. static int patch_stac9200(struct hda_codec *codec)
  2233. {
  2234. struct sigmatel_spec *spec;
  2235. int err;
  2236. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2237. if (spec == NULL)
  2238. return -ENOMEM;
  2239. codec->spec = spec;
  2240. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  2241. spec->pin_nids = stac9200_pin_nids;
  2242. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  2243. stac9200_models,
  2244. stac9200_cfg_tbl);
  2245. if (spec->board_config < 0) {
  2246. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  2247. err = stac92xx_save_bios_config_regs(codec);
  2248. if (err < 0) {
  2249. stac92xx_free(codec);
  2250. return err;
  2251. }
  2252. spec->pin_configs = spec->bios_pin_configs;
  2253. } else {
  2254. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  2255. stac92xx_set_config_regs(codec);
  2256. }
  2257. spec->multiout.max_channels = 2;
  2258. spec->multiout.num_dacs = 1;
  2259. spec->multiout.dac_nids = stac9200_dac_nids;
  2260. spec->adc_nids = stac9200_adc_nids;
  2261. spec->mux_nids = stac9200_mux_nids;
  2262. spec->num_muxes = 1;
  2263. spec->num_dmics = 0;
  2264. spec->num_adcs = 1;
  2265. if (spec->board_config == STAC_9200_GATEWAY)
  2266. spec->init = stac9200_eapd_init;
  2267. else
  2268. spec->init = stac9200_core_init;
  2269. spec->mixer = stac9200_mixer;
  2270. err = stac9200_parse_auto_config(codec);
  2271. if (err < 0) {
  2272. stac92xx_free(codec);
  2273. return err;
  2274. }
  2275. codec->patch_ops = stac92xx_patch_ops;
  2276. return 0;
  2277. }
  2278. static int patch_stac925x(struct hda_codec *codec)
  2279. {
  2280. struct sigmatel_spec *spec;
  2281. int err;
  2282. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2283. if (spec == NULL)
  2284. return -ENOMEM;
  2285. codec->spec = spec;
  2286. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  2287. spec->pin_nids = stac925x_pin_nids;
  2288. spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
  2289. stac925x_models,
  2290. stac925x_cfg_tbl);
  2291. again:
  2292. if (spec->board_config < 0) {
  2293. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
  2294. "using BIOS defaults\n");
  2295. err = stac92xx_save_bios_config_regs(codec);
  2296. if (err < 0) {
  2297. stac92xx_free(codec);
  2298. return err;
  2299. }
  2300. spec->pin_configs = spec->bios_pin_configs;
  2301. } else if (stac925x_brd_tbl[spec->board_config] != NULL){
  2302. spec->pin_configs = stac925x_brd_tbl[spec->board_config];
  2303. stac92xx_set_config_regs(codec);
  2304. }
  2305. spec->multiout.max_channels = 2;
  2306. spec->multiout.num_dacs = 1;
  2307. spec->multiout.dac_nids = stac925x_dac_nids;
  2308. spec->adc_nids = stac925x_adc_nids;
  2309. spec->mux_nids = stac925x_mux_nids;
  2310. spec->num_muxes = 1;
  2311. spec->num_adcs = 1;
  2312. switch (codec->vendor_id) {
  2313. case 0x83847632: /* STAC9202 */
  2314. case 0x83847633: /* STAC9202D */
  2315. case 0x83847636: /* STAC9251 */
  2316. case 0x83847637: /* STAC9251D */
  2317. spec->num_dmics = STAC925X_NUM_DMICS;
  2318. spec->dmic_nids = stac925x_dmic_nids;
  2319. break;
  2320. default:
  2321. spec->num_dmics = 0;
  2322. break;
  2323. }
  2324. spec->init = stac925x_core_init;
  2325. spec->mixer = stac925x_mixer;
  2326. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  2327. if (!err) {
  2328. if (spec->board_config < 0) {
  2329. printk(KERN_WARNING "hda_codec: No auto-config is "
  2330. "available, default to model=ref\n");
  2331. spec->board_config = STAC_925x_REF;
  2332. goto again;
  2333. }
  2334. err = -EINVAL;
  2335. }
  2336. if (err < 0) {
  2337. stac92xx_free(codec);
  2338. return err;
  2339. }
  2340. codec->patch_ops = stac92xx_patch_ops;
  2341. return 0;
  2342. }
  2343. static int patch_stac92hd71bxx(struct hda_codec *codec)
  2344. {
  2345. struct sigmatel_spec *spec;
  2346. int err = 0;
  2347. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2348. if (spec == NULL)
  2349. return -ENOMEM;
  2350. codec->spec = spec;
  2351. spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
  2352. spec->pin_nids = stac92hd71bxx_pin_nids;
  2353. spec->board_config = snd_hda_check_board_config(codec,
  2354. STAC_92HD71BXX_MODELS,
  2355. stac92hd71bxx_models,
  2356. stac92hd71bxx_cfg_tbl);
  2357. again:
  2358. if (spec->board_config < 0) {
  2359. snd_printdd(KERN_INFO "hda_codec: Unknown model for"
  2360. " STAC92HD71BXX, using BIOS defaults\n");
  2361. err = stac92xx_save_bios_config_regs(codec);
  2362. if (err < 0) {
  2363. stac92xx_free(codec);
  2364. return err;
  2365. }
  2366. spec->pin_configs = spec->bios_pin_configs;
  2367. } else {
  2368. spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
  2369. stac92xx_set_config_regs(codec);
  2370. }
  2371. spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
  2372. stac92xx_enable_gpio_mask(codec);
  2373. spec->init = stac92hd71bxx_core_init;
  2374. spec->mixer = stac92hd71bxx_mixer;
  2375. spec->mux_nids = stac92hd71bxx_mux_nids;
  2376. spec->adc_nids = stac92hd71bxx_adc_nids;
  2377. spec->dmic_nids = stac92hd71bxx_dmic_nids;
  2378. spec->dmux_nid = 0x1c;
  2379. spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
  2380. spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
  2381. spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
  2382. spec->multiout.num_dacs = 2;
  2383. spec->multiout.hp_nid = 0x11;
  2384. spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
  2385. err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
  2386. if (!err) {
  2387. if (spec->board_config < 0) {
  2388. printk(KERN_WARNING "hda_codec: No auto-config is "
  2389. "available, default to model=ref\n");
  2390. spec->board_config = STAC_92HD71BXX_REF;
  2391. goto again;
  2392. }
  2393. err = -EINVAL;
  2394. }
  2395. if (err < 0) {
  2396. stac92xx_free(codec);
  2397. return err;
  2398. }
  2399. codec->patch_ops = stac92xx_patch_ops;
  2400. return 0;
  2401. };
  2402. static int patch_stac922x(struct hda_codec *codec)
  2403. {
  2404. struct sigmatel_spec *spec;
  2405. int err;
  2406. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2407. if (spec == NULL)
  2408. return -ENOMEM;
  2409. codec->spec = spec;
  2410. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  2411. spec->pin_nids = stac922x_pin_nids;
  2412. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  2413. stac922x_models,
  2414. stac922x_cfg_tbl);
  2415. if (spec->board_config == STAC_INTEL_MAC_V3) {
  2416. spec->gpio_mute = 1;
  2417. /* Intel Macs have all same PCI SSID, so we need to check
  2418. * codec SSID to distinguish the exact models
  2419. */
  2420. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  2421. switch (codec->subsystem_id) {
  2422. case 0x106b0800:
  2423. spec->board_config = STAC_INTEL_MAC_V1;
  2424. break;
  2425. case 0x106b0600:
  2426. case 0x106b0700:
  2427. spec->board_config = STAC_INTEL_MAC_V2;
  2428. break;
  2429. case 0x106b0e00:
  2430. case 0x106b0f00:
  2431. case 0x106b1600:
  2432. case 0x106b1700:
  2433. case 0x106b0200:
  2434. case 0x106b1e00:
  2435. spec->board_config = STAC_INTEL_MAC_V3;
  2436. break;
  2437. case 0x106b1a00:
  2438. case 0x00000100:
  2439. spec->board_config = STAC_INTEL_MAC_V4;
  2440. break;
  2441. case 0x106b0a00:
  2442. case 0x106b2200:
  2443. spec->board_config = STAC_INTEL_MAC_V5;
  2444. break;
  2445. }
  2446. }
  2447. again:
  2448. if (spec->board_config < 0) {
  2449. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  2450. "using BIOS defaults\n");
  2451. err = stac92xx_save_bios_config_regs(codec);
  2452. if (err < 0) {
  2453. stac92xx_free(codec);
  2454. return err;
  2455. }
  2456. spec->pin_configs = spec->bios_pin_configs;
  2457. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  2458. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  2459. stac92xx_set_config_regs(codec);
  2460. }
  2461. spec->adc_nids = stac922x_adc_nids;
  2462. spec->mux_nids = stac922x_mux_nids;
  2463. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  2464. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  2465. spec->num_dmics = 0;
  2466. spec->init = stac922x_core_init;
  2467. spec->mixer = stac922x_mixer;
  2468. spec->multiout.dac_nids = spec->dac_nids;
  2469. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  2470. if (!err) {
  2471. if (spec->board_config < 0) {
  2472. printk(KERN_WARNING "hda_codec: No auto-config is "
  2473. "available, default to model=ref\n");
  2474. spec->board_config = STAC_D945_REF;
  2475. goto again;
  2476. }
  2477. err = -EINVAL;
  2478. }
  2479. if (err < 0) {
  2480. stac92xx_free(codec);
  2481. return err;
  2482. }
  2483. codec->patch_ops = stac92xx_patch_ops;
  2484. /* Fix Mux capture level; max to 2 */
  2485. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  2486. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  2487. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2488. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2489. (0 << AC_AMPCAP_MUTE_SHIFT));
  2490. return 0;
  2491. }
  2492. static int patch_stac927x(struct hda_codec *codec)
  2493. {
  2494. struct sigmatel_spec *spec;
  2495. int err;
  2496. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2497. if (spec == NULL)
  2498. return -ENOMEM;
  2499. codec->spec = spec;
  2500. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  2501. spec->pin_nids = stac927x_pin_nids;
  2502. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  2503. stac927x_models,
  2504. stac927x_cfg_tbl);
  2505. again:
  2506. if (spec->board_config < 0) {
  2507. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  2508. err = stac92xx_save_bios_config_regs(codec);
  2509. if (err < 0) {
  2510. stac92xx_free(codec);
  2511. return err;
  2512. }
  2513. spec->pin_configs = spec->bios_pin_configs;
  2514. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  2515. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  2516. stac92xx_set_config_regs(codec);
  2517. }
  2518. switch (spec->board_config) {
  2519. case STAC_D965_3ST:
  2520. spec->adc_nids = stac927x_adc_nids;
  2521. spec->mux_nids = stac927x_mux_nids;
  2522. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2523. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2524. spec->init = d965_core_init;
  2525. spec->mixer = stac927x_mixer;
  2526. break;
  2527. case STAC_D965_5ST:
  2528. spec->adc_nids = stac927x_adc_nids;
  2529. spec->mux_nids = stac927x_mux_nids;
  2530. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2531. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2532. spec->init = d965_core_init;
  2533. spec->mixer = stac927x_mixer;
  2534. break;
  2535. default:
  2536. spec->adc_nids = stac927x_adc_nids;
  2537. spec->mux_nids = stac927x_mux_nids;
  2538. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2539. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2540. spec->init = stac927x_core_init;
  2541. spec->mixer = stac927x_mixer;
  2542. }
  2543. switch (codec->subsystem_id) {
  2544. case 0x10280242: /* STAC 9228 */
  2545. case 0x102801f3:
  2546. case 0x1028020A:
  2547. case 0x10280209:
  2548. spec->dmic_nids = stac927x_dmic_nids;
  2549. spec->num_dmics = STAC927X_NUM_DMICS;
  2550. spec->dmux_nid = 0x1b;
  2551. /* Enable DMIC0 */
  2552. stac92xx_set_config_reg(codec, 0x13, 0x90a60040);
  2553. /* GPIO2 High = Enable EAPD */
  2554. spec->gpio_mask = spec->gpio_data = 0x00000004;
  2555. break;
  2556. default:
  2557. spec->num_dmics = 0;
  2558. /* GPIO0 High = Enable EAPD */
  2559. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2560. }
  2561. spec->multiout.dac_nids = spec->dac_nids;
  2562. stac92xx_enable_gpio_mask(codec);
  2563. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  2564. if (!err) {
  2565. if (spec->board_config < 0) {
  2566. printk(KERN_WARNING "hda_codec: No auto-config is "
  2567. "available, default to model=ref\n");
  2568. spec->board_config = STAC_D965_REF;
  2569. goto again;
  2570. }
  2571. err = -EINVAL;
  2572. }
  2573. if (err < 0) {
  2574. stac92xx_free(codec);
  2575. return err;
  2576. }
  2577. codec->patch_ops = stac92xx_patch_ops;
  2578. return 0;
  2579. }
  2580. static int patch_stac9205(struct hda_codec *codec)
  2581. {
  2582. struct sigmatel_spec *spec;
  2583. int err;
  2584. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2585. if (spec == NULL)
  2586. return -ENOMEM;
  2587. codec->spec = spec;
  2588. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  2589. spec->pin_nids = stac9205_pin_nids;
  2590. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  2591. stac9205_models,
  2592. stac9205_cfg_tbl);
  2593. again:
  2594. if (spec->board_config < 0) {
  2595. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  2596. err = stac92xx_save_bios_config_regs(codec);
  2597. if (err < 0) {
  2598. stac92xx_free(codec);
  2599. return err;
  2600. }
  2601. spec->pin_configs = spec->bios_pin_configs;
  2602. } else {
  2603. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  2604. stac92xx_set_config_regs(codec);
  2605. }
  2606. spec->adc_nids = stac9205_adc_nids;
  2607. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  2608. spec->mux_nids = stac9205_mux_nids;
  2609. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  2610. spec->dmic_nids = stac9205_dmic_nids;
  2611. spec->num_dmics = STAC9205_NUM_DMICS;
  2612. spec->dmux_nid = 0x1d;
  2613. spec->init = stac9205_core_init;
  2614. spec->mixer = stac9205_mixer;
  2615. spec->multiout.dac_nids = spec->dac_nids;
  2616. switch (spec->board_config){
  2617. case STAC_9205_DELL_M43:
  2618. /* Enable SPDIF in/out */
  2619. stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
  2620. stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
  2621. spec->gpio_mask = 0x00000007; /* GPIO0-2 */
  2622. /* GPIO0 High = EAPD, GPIO1 Low = DRM,
  2623. * GPIO2 High = Headphone Mute
  2624. */
  2625. spec->gpio_data = 0x00000005;
  2626. break;
  2627. default:
  2628. /* GPIO0 High = EAPD */
  2629. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2630. break;
  2631. }
  2632. stac92xx_enable_gpio_mask(codec);
  2633. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  2634. if (!err) {
  2635. if (spec->board_config < 0) {
  2636. printk(KERN_WARNING "hda_codec: No auto-config is "
  2637. "available, default to model=ref\n");
  2638. spec->board_config = STAC_9205_REF;
  2639. goto again;
  2640. }
  2641. err = -EINVAL;
  2642. }
  2643. if (err < 0) {
  2644. stac92xx_free(codec);
  2645. return err;
  2646. }
  2647. codec->patch_ops = stac92xx_patch_ops;
  2648. return 0;
  2649. }
  2650. /*
  2651. * STAC9872 hack
  2652. */
  2653. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  2654. static hda_nid_t vaio_dacs[] = { 0x2 };
  2655. #define VAIO_HP_DAC 0x5
  2656. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  2657. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  2658. static struct hda_input_mux vaio_mux = {
  2659. .num_items = 3,
  2660. .items = {
  2661. /* { "HP", 0x0 }, */
  2662. { "Mic Jack", 0x1 },
  2663. { "Internal Mic", 0x2 },
  2664. { "PCM", 0x3 },
  2665. }
  2666. };
  2667. static struct hda_verb vaio_init[] = {
  2668. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2669. {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
  2670. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2671. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2672. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2673. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2674. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2675. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2676. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2677. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2678. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2679. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2680. {}
  2681. };
  2682. static struct hda_verb vaio_ar_init[] = {
  2683. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2684. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2685. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2686. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2687. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  2688. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2689. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2690. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2691. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2692. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  2693. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2694. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2695. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2696. {}
  2697. };
  2698. /* bind volumes of both NID 0x02 and 0x05 */
  2699. static struct hda_bind_ctls vaio_bind_master_vol = {
  2700. .ops = &snd_hda_bind_vol,
  2701. .values = {
  2702. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2703. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2704. 0
  2705. },
  2706. };
  2707. /* bind volumes of both NID 0x02 and 0x05 */
  2708. static struct hda_bind_ctls vaio_bind_master_sw = {
  2709. .ops = &snd_hda_bind_sw,
  2710. .values = {
  2711. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2712. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2713. 0,
  2714. },
  2715. };
  2716. static struct snd_kcontrol_new vaio_mixer[] = {
  2717. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2718. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2719. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2720. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2721. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2722. {
  2723. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2724. .name = "Capture Source",
  2725. .count = 1,
  2726. .info = stac92xx_mux_enum_info,
  2727. .get = stac92xx_mux_enum_get,
  2728. .put = stac92xx_mux_enum_put,
  2729. },
  2730. {}
  2731. };
  2732. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  2733. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2734. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2735. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2736. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2737. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2738. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  2739. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  2740. {
  2741. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2742. .name = "Capture Source",
  2743. .count = 1,
  2744. .info = stac92xx_mux_enum_info,
  2745. .get = stac92xx_mux_enum_get,
  2746. .put = stac92xx_mux_enum_put,
  2747. },
  2748. {}
  2749. };
  2750. static struct hda_codec_ops stac9872_patch_ops = {
  2751. .build_controls = stac92xx_build_controls,
  2752. .build_pcms = stac92xx_build_pcms,
  2753. .init = stac92xx_init,
  2754. .free = stac92xx_free,
  2755. #ifdef SND_HDA_NEEDS_RESUME
  2756. .resume = stac92xx_resume,
  2757. #endif
  2758. };
  2759. static int stac9872_vaio_init(struct hda_codec *codec)
  2760. {
  2761. int err;
  2762. err = stac92xx_init(codec);
  2763. if (err < 0)
  2764. return err;
  2765. if (codec->patch_ops.unsol_event)
  2766. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2767. return 0;
  2768. }
  2769. static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
  2770. {
  2771. if (get_pin_presence(codec, 0x0a)) {
  2772. stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2773. stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2774. } else {
  2775. stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2776. stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2777. }
  2778. }
  2779. static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
  2780. {
  2781. switch (res >> 26) {
  2782. case STAC_HP_EVENT:
  2783. stac9872_vaio_hp_detect(codec, res);
  2784. break;
  2785. }
  2786. }
  2787. static struct hda_codec_ops stac9872_vaio_patch_ops = {
  2788. .build_controls = stac92xx_build_controls,
  2789. .build_pcms = stac92xx_build_pcms,
  2790. .init = stac9872_vaio_init,
  2791. .free = stac92xx_free,
  2792. .unsol_event = stac9872_vaio_unsol_event,
  2793. #ifdef CONFIG_PM
  2794. .resume = stac92xx_resume,
  2795. #endif
  2796. };
  2797. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  2798. CXD9872RD_VAIO,
  2799. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  2800. STAC9872AK_VAIO,
  2801. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  2802. STAC9872K_VAIO,
  2803. /* AR Series. id=0x83847664 and subsys=104D1300 */
  2804. CXD9872AKD_VAIO,
  2805. STAC_9872_MODELS,
  2806. };
  2807. static const char *stac9872_models[STAC_9872_MODELS] = {
  2808. [CXD9872RD_VAIO] = "vaio",
  2809. [CXD9872AKD_VAIO] = "vaio-ar",
  2810. };
  2811. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  2812. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  2813. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  2814. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  2815. SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
  2816. {}
  2817. };
  2818. static int patch_stac9872(struct hda_codec *codec)
  2819. {
  2820. struct sigmatel_spec *spec;
  2821. int board_config;
  2822. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  2823. stac9872_models,
  2824. stac9872_cfg_tbl);
  2825. if (board_config < 0)
  2826. /* unknown config, let generic-parser do its job... */
  2827. return snd_hda_parse_generic_codec(codec);
  2828. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2829. if (spec == NULL)
  2830. return -ENOMEM;
  2831. codec->spec = spec;
  2832. switch (board_config) {
  2833. case CXD9872RD_VAIO:
  2834. case STAC9872AK_VAIO:
  2835. case STAC9872K_VAIO:
  2836. spec->mixer = vaio_mixer;
  2837. spec->init = vaio_init;
  2838. spec->multiout.max_channels = 2;
  2839. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2840. spec->multiout.dac_nids = vaio_dacs;
  2841. spec->multiout.hp_nid = VAIO_HP_DAC;
  2842. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2843. spec->adc_nids = vaio_adcs;
  2844. spec->input_mux = &vaio_mux;
  2845. spec->mux_nids = vaio_mux_nids;
  2846. codec->patch_ops = stac9872_vaio_patch_ops;
  2847. break;
  2848. case CXD9872AKD_VAIO:
  2849. spec->mixer = vaio_ar_mixer;
  2850. spec->init = vaio_ar_init;
  2851. spec->multiout.max_channels = 2;
  2852. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2853. spec->multiout.dac_nids = vaio_dacs;
  2854. spec->multiout.hp_nid = VAIO_HP_DAC;
  2855. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2856. spec->adc_nids = vaio_adcs;
  2857. spec->input_mux = &vaio_mux;
  2858. spec->mux_nids = vaio_mux_nids;
  2859. codec->patch_ops = stac9872_patch_ops;
  2860. break;
  2861. }
  2862. return 0;
  2863. }
  2864. /*
  2865. * patch entries
  2866. */
  2867. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  2868. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  2869. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  2870. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  2871. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  2872. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  2873. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  2874. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  2875. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  2876. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  2877. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  2878. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  2879. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  2880. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  2881. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  2882. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  2883. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  2884. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  2885. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  2886. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  2887. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  2888. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  2889. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  2890. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  2891. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  2892. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  2893. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  2894. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  2895. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  2896. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  2897. /* The following does not take into account .id=0x83847661 when subsys =
  2898. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  2899. * currently not fully supported.
  2900. */
  2901. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  2902. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  2903. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  2904. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  2905. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  2906. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  2907. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  2908. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  2909. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  2910. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  2911. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  2912. { .id = 0x111d76b0, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
  2913. {} /* terminator */
  2914. };