patch_sigmatel.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306
  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. 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
  805. 0x408003f1, 0x02111211, 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. if ((err = snd_hda_parse_pin_def_config(codec,
  1873. &spec->autocfg,
  1874. spec->dmic_nids)) < 0)
  1875. return err;
  1876. if (! spec->autocfg.line_outs)
  1877. return 0; /* can't find valid pin config */
  1878. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1879. return err;
  1880. if (spec->multiout.num_dacs == 0)
  1881. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1882. return err;
  1883. err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
  1884. if (err < 0)
  1885. return err;
  1886. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  1887. if (err < 0)
  1888. return err;
  1889. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  1890. if (err < 0)
  1891. return err;
  1892. if (spec->num_dmics > 0)
  1893. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1894. &spec->autocfg)) < 0)
  1895. return err;
  1896. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1897. if (spec->multiout.max_channels > 2)
  1898. spec->surr_switch = 1;
  1899. if (spec->autocfg.dig_out_pin)
  1900. spec->multiout.dig_out_nid = dig_out;
  1901. if (spec->autocfg.dig_in_pin)
  1902. spec->dig_in_nid = dig_in;
  1903. if (spec->kctl_alloc)
  1904. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1905. spec->input_mux = &spec->private_imux;
  1906. spec->dinput_mux = &spec->private_dimux;
  1907. return 1;
  1908. }
  1909. /* add playback controls for HP output */
  1910. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1911. struct auto_pin_cfg *cfg)
  1912. {
  1913. struct sigmatel_spec *spec = codec->spec;
  1914. hda_nid_t pin = cfg->hp_pins[0];
  1915. unsigned int wid_caps;
  1916. if (! pin)
  1917. return 0;
  1918. wid_caps = get_wcaps(codec, pin);
  1919. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1920. spec->hp_detect = 1;
  1921. return 0;
  1922. }
  1923. /* add playback controls for LFE output */
  1924. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1925. struct auto_pin_cfg *cfg)
  1926. {
  1927. struct sigmatel_spec *spec = codec->spec;
  1928. int err;
  1929. hda_nid_t lfe_pin = 0x0;
  1930. int i;
  1931. /*
  1932. * search speaker outs and line outs for a mono speaker pin
  1933. * with an amp. If one is found, add LFE controls
  1934. * for it.
  1935. */
  1936. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1937. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1938. unsigned long wcaps = get_wcaps(codec, pin);
  1939. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1940. if (wcaps == AC_WCAP_OUT_AMP)
  1941. /* found a mono speaker with an amp, must be lfe */
  1942. lfe_pin = pin;
  1943. }
  1944. /* if speaker_outs is 0, then speakers may be in line_outs */
  1945. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1946. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1947. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1948. unsigned long cfg;
  1949. cfg = snd_hda_codec_read(codec, pin, 0,
  1950. AC_VERB_GET_CONFIG_DEFAULT,
  1951. 0x00);
  1952. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1953. unsigned long wcaps = get_wcaps(codec, pin);
  1954. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1955. if (wcaps == AC_WCAP_OUT_AMP)
  1956. /* found a mono speaker with an amp,
  1957. must be lfe */
  1958. lfe_pin = pin;
  1959. }
  1960. }
  1961. }
  1962. if (lfe_pin) {
  1963. err = create_controls(spec, "LFE", lfe_pin, 1);
  1964. if (err < 0)
  1965. return err;
  1966. }
  1967. return 0;
  1968. }
  1969. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1970. {
  1971. struct sigmatel_spec *spec = codec->spec;
  1972. int err;
  1973. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1974. return err;
  1975. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1976. return err;
  1977. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1978. return err;
  1979. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1980. return err;
  1981. if (spec->autocfg.dig_out_pin)
  1982. spec->multiout.dig_out_nid = 0x05;
  1983. if (spec->autocfg.dig_in_pin)
  1984. spec->dig_in_nid = 0x04;
  1985. if (spec->kctl_alloc)
  1986. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1987. spec->input_mux = &spec->private_imux;
  1988. spec->dinput_mux = &spec->private_dimux;
  1989. return 1;
  1990. }
  1991. /*
  1992. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1993. * funky external mute control using GPIO pins.
  1994. */
  1995. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1996. {
  1997. unsigned int gpiostate, gpiomask, gpiodir;
  1998. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1999. AC_VERB_GET_GPIO_DATA, 0);
  2000. if (!muted)
  2001. gpiostate |= (1 << pin);
  2002. else
  2003. gpiostate &= ~(1 << pin);
  2004. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  2005. AC_VERB_GET_GPIO_MASK, 0);
  2006. gpiomask |= (1 << pin);
  2007. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  2008. AC_VERB_GET_GPIO_DIRECTION, 0);
  2009. gpiodir |= (1 << pin);
  2010. /* AppleHDA seems to do this -- WTF is this verb?? */
  2011. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  2012. snd_hda_codec_write(codec, codec->afg, 0,
  2013. AC_VERB_SET_GPIO_MASK, gpiomask);
  2014. snd_hda_codec_write(codec, codec->afg, 0,
  2015. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  2016. msleep(1);
  2017. snd_hda_codec_write(codec, codec->afg, 0,
  2018. AC_VERB_SET_GPIO_DATA, gpiostate);
  2019. }
  2020. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  2021. unsigned int event)
  2022. {
  2023. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  2024. snd_hda_codec_write_cache(codec, nid, 0,
  2025. AC_VERB_SET_UNSOLICITED_ENABLE,
  2026. (AC_USRSP_EN | event));
  2027. }
  2028. static int stac92xx_init(struct hda_codec *codec)
  2029. {
  2030. struct sigmatel_spec *spec = codec->spec;
  2031. struct auto_pin_cfg *cfg = &spec->autocfg;
  2032. int i;
  2033. snd_hda_sequence_write(codec, spec->init);
  2034. /* set up pins */
  2035. if (spec->hp_detect) {
  2036. /* Enable unsolicited responses on the HP widget */
  2037. for (i = 0; i < cfg->hp_outs; i++)
  2038. enable_pin_detect(codec, cfg->hp_pins[i],
  2039. STAC_HP_EVENT);
  2040. /* force to enable the first line-out; the others are set up
  2041. * in unsol_event
  2042. */
  2043. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  2044. AC_PINCTL_OUT_EN);
  2045. stac92xx_auto_init_hp_out(codec);
  2046. /* fake event to set up pins */
  2047. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2048. } else {
  2049. stac92xx_auto_init_multi_out(codec);
  2050. stac92xx_auto_init_hp_out(codec);
  2051. }
  2052. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2053. hda_nid_t nid = cfg->input_pins[i];
  2054. if (nid) {
  2055. unsigned int pinctl = AC_PINCTL_IN_EN;
  2056. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  2057. pinctl |= stac92xx_get_vref(codec, nid);
  2058. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  2059. }
  2060. }
  2061. if (spec->num_dmics > 0)
  2062. for (i = 0; i < spec->num_dmics; i++)
  2063. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  2064. AC_PINCTL_IN_EN);
  2065. if (cfg->dig_out_pin)
  2066. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  2067. AC_PINCTL_OUT_EN);
  2068. if (cfg->dig_in_pin)
  2069. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  2070. AC_PINCTL_IN_EN);
  2071. if (spec->gpio_mute) {
  2072. stac922x_gpio_mute(codec, 0, 0);
  2073. stac922x_gpio_mute(codec, 1, 0);
  2074. }
  2075. return 0;
  2076. }
  2077. static void stac92xx_free(struct hda_codec *codec)
  2078. {
  2079. struct sigmatel_spec *spec = codec->spec;
  2080. int i;
  2081. if (! spec)
  2082. return;
  2083. if (spec->kctl_alloc) {
  2084. for (i = 0; i < spec->num_kctl_used; i++)
  2085. kfree(spec->kctl_alloc[i].name);
  2086. kfree(spec->kctl_alloc);
  2087. }
  2088. if (spec->bios_pin_configs)
  2089. kfree(spec->bios_pin_configs);
  2090. kfree(spec);
  2091. }
  2092. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2093. unsigned int flag)
  2094. {
  2095. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2096. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2097. if (pin_ctl & AC_PINCTL_IN_EN) {
  2098. /*
  2099. * we need to check the current set-up direction of
  2100. * shared input pins since they can be switched via
  2101. * "xxx as Output" mixer switch
  2102. */
  2103. struct sigmatel_spec *spec = codec->spec;
  2104. struct auto_pin_cfg *cfg = &spec->autocfg;
  2105. if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
  2106. spec->line_switch) ||
  2107. (nid == cfg->input_pins[AUTO_PIN_MIC] &&
  2108. spec->mic_switch))
  2109. return;
  2110. }
  2111. /* if setting pin direction bits, clear the current
  2112. direction bits first */
  2113. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  2114. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  2115. snd_hda_codec_write_cache(codec, nid, 0,
  2116. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2117. pin_ctl | flag);
  2118. }
  2119. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2120. unsigned int flag)
  2121. {
  2122. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2123. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2124. snd_hda_codec_write_cache(codec, nid, 0,
  2125. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2126. pin_ctl & ~flag);
  2127. }
  2128. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  2129. {
  2130. if (!nid)
  2131. return 0;
  2132. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  2133. & (1 << 31))
  2134. return 1;
  2135. return 0;
  2136. }
  2137. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  2138. {
  2139. struct sigmatel_spec *spec = codec->spec;
  2140. struct auto_pin_cfg *cfg = &spec->autocfg;
  2141. int i, presence;
  2142. presence = 0;
  2143. for (i = 0; i < cfg->hp_outs; i++) {
  2144. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  2145. if (presence)
  2146. break;
  2147. }
  2148. if (presence) {
  2149. /* disable lineouts, enable hp */
  2150. for (i = 0; i < cfg->line_outs; i++)
  2151. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  2152. AC_PINCTL_OUT_EN);
  2153. for (i = 0; i < cfg->speaker_outs; i++)
  2154. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  2155. AC_PINCTL_OUT_EN);
  2156. } else {
  2157. /* enable lineouts, disable hp */
  2158. for (i = 0; i < cfg->line_outs; i++)
  2159. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  2160. AC_PINCTL_OUT_EN);
  2161. for (i = 0; i < cfg->speaker_outs; i++)
  2162. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  2163. AC_PINCTL_OUT_EN);
  2164. }
  2165. }
  2166. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  2167. {
  2168. switch (res >> 26) {
  2169. case STAC_HP_EVENT:
  2170. stac92xx_hp_detect(codec, res);
  2171. break;
  2172. }
  2173. }
  2174. #ifdef SND_HDA_NEEDS_RESUME
  2175. static int stac92xx_resume(struct hda_codec *codec)
  2176. {
  2177. struct sigmatel_spec *spec = codec->spec;
  2178. stac92xx_set_config_regs(codec);
  2179. snd_hda_sequence_write(codec, spec->init);
  2180. if (spec->gpio_mute) {
  2181. stac922x_gpio_mute(codec, 0, 0);
  2182. stac922x_gpio_mute(codec, 1, 0);
  2183. }
  2184. snd_hda_codec_resume_amp(codec);
  2185. snd_hda_codec_resume_cache(codec);
  2186. /* invoke unsolicited event to reset the HP state */
  2187. if (spec->hp_detect)
  2188. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2189. return 0;
  2190. }
  2191. #endif
  2192. static struct hda_codec_ops stac92xx_patch_ops = {
  2193. .build_controls = stac92xx_build_controls,
  2194. .build_pcms = stac92xx_build_pcms,
  2195. .init = stac92xx_init,
  2196. .free = stac92xx_free,
  2197. .unsol_event = stac92xx_unsol_event,
  2198. #ifdef SND_HDA_NEEDS_RESUME
  2199. .resume = stac92xx_resume,
  2200. #endif
  2201. };
  2202. static int patch_stac9200(struct hda_codec *codec)
  2203. {
  2204. struct sigmatel_spec *spec;
  2205. int err;
  2206. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2207. if (spec == NULL)
  2208. return -ENOMEM;
  2209. codec->spec = spec;
  2210. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  2211. spec->pin_nids = stac9200_pin_nids;
  2212. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  2213. stac9200_models,
  2214. stac9200_cfg_tbl);
  2215. if (spec->board_config < 0) {
  2216. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  2217. err = stac92xx_save_bios_config_regs(codec);
  2218. if (err < 0) {
  2219. stac92xx_free(codec);
  2220. return err;
  2221. }
  2222. spec->pin_configs = spec->bios_pin_configs;
  2223. } else {
  2224. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  2225. stac92xx_set_config_regs(codec);
  2226. }
  2227. spec->multiout.max_channels = 2;
  2228. spec->multiout.num_dacs = 1;
  2229. spec->multiout.dac_nids = stac9200_dac_nids;
  2230. spec->adc_nids = stac9200_adc_nids;
  2231. spec->mux_nids = stac9200_mux_nids;
  2232. spec->num_muxes = 1;
  2233. spec->num_dmics = 0;
  2234. spec->num_adcs = 1;
  2235. if (spec->board_config == STAC_9200_GATEWAY)
  2236. spec->init = stac9200_eapd_init;
  2237. else
  2238. spec->init = stac9200_core_init;
  2239. spec->mixer = stac9200_mixer;
  2240. err = stac9200_parse_auto_config(codec);
  2241. if (err < 0) {
  2242. stac92xx_free(codec);
  2243. return err;
  2244. }
  2245. codec->patch_ops = stac92xx_patch_ops;
  2246. return 0;
  2247. }
  2248. static int patch_stac925x(struct hda_codec *codec)
  2249. {
  2250. struct sigmatel_spec *spec;
  2251. int err;
  2252. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2253. if (spec == NULL)
  2254. return -ENOMEM;
  2255. codec->spec = spec;
  2256. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  2257. spec->pin_nids = stac925x_pin_nids;
  2258. spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
  2259. stac925x_models,
  2260. stac925x_cfg_tbl);
  2261. again:
  2262. if (spec->board_config < 0) {
  2263. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
  2264. "using BIOS defaults\n");
  2265. err = stac92xx_save_bios_config_regs(codec);
  2266. if (err < 0) {
  2267. stac92xx_free(codec);
  2268. return err;
  2269. }
  2270. spec->pin_configs = spec->bios_pin_configs;
  2271. } else if (stac925x_brd_tbl[spec->board_config] != NULL){
  2272. spec->pin_configs = stac925x_brd_tbl[spec->board_config];
  2273. stac92xx_set_config_regs(codec);
  2274. }
  2275. spec->multiout.max_channels = 2;
  2276. spec->multiout.num_dacs = 1;
  2277. spec->multiout.dac_nids = stac925x_dac_nids;
  2278. spec->adc_nids = stac925x_adc_nids;
  2279. spec->mux_nids = stac925x_mux_nids;
  2280. spec->num_muxes = 1;
  2281. spec->num_adcs = 1;
  2282. switch (codec->vendor_id) {
  2283. case 0x83847632: /* STAC9202 */
  2284. case 0x83847633: /* STAC9202D */
  2285. case 0x83847636: /* STAC9251 */
  2286. case 0x83847637: /* STAC9251D */
  2287. spec->num_dmics = STAC925X_NUM_DMICS;
  2288. spec->dmic_nids = stac925x_dmic_nids;
  2289. break;
  2290. default:
  2291. spec->num_dmics = 0;
  2292. break;
  2293. }
  2294. spec->init = stac925x_core_init;
  2295. spec->mixer = stac925x_mixer;
  2296. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  2297. if (!err) {
  2298. if (spec->board_config < 0) {
  2299. printk(KERN_WARNING "hda_codec: No auto-config is "
  2300. "available, default to model=ref\n");
  2301. spec->board_config = STAC_925x_REF;
  2302. goto again;
  2303. }
  2304. err = -EINVAL;
  2305. }
  2306. if (err < 0) {
  2307. stac92xx_free(codec);
  2308. return err;
  2309. }
  2310. codec->patch_ops = stac92xx_patch_ops;
  2311. return 0;
  2312. }
  2313. static int patch_stac92hd71bxx(struct hda_codec *codec)
  2314. {
  2315. struct sigmatel_spec *spec;
  2316. int err = 0;
  2317. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2318. if (spec == NULL)
  2319. return -ENOMEM;
  2320. codec->spec = spec;
  2321. spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
  2322. spec->pin_nids = stac92hd71bxx_pin_nids;
  2323. spec->board_config = snd_hda_check_board_config(codec,
  2324. STAC_92HD71BXX_MODELS,
  2325. stac92hd71bxx_models,
  2326. stac92hd71bxx_cfg_tbl);
  2327. again:
  2328. if (spec->board_config < 0) {
  2329. snd_printdd(KERN_INFO "hda_codec: Unknown model for"
  2330. " STAC92HD71BXX, using BIOS defaults\n");
  2331. err = stac92xx_save_bios_config_regs(codec);
  2332. if (err < 0) {
  2333. stac92xx_free(codec);
  2334. return err;
  2335. }
  2336. spec->pin_configs = spec->bios_pin_configs;
  2337. } else {
  2338. spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
  2339. stac92xx_set_config_regs(codec);
  2340. }
  2341. spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
  2342. stac92xx_enable_gpio_mask(codec);
  2343. spec->init = stac92hd71bxx_core_init;
  2344. spec->mixer = stac92hd71bxx_mixer;
  2345. spec->mux_nids = stac92hd71bxx_mux_nids;
  2346. spec->adc_nids = stac92hd71bxx_adc_nids;
  2347. spec->dmic_nids = stac92hd71bxx_dmic_nids;
  2348. spec->dmux_nid = 0x1c;
  2349. spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
  2350. spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
  2351. spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
  2352. spec->multiout.num_dacs = 2;
  2353. spec->multiout.hp_nid = 0x11;
  2354. spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
  2355. err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
  2356. if (!err) {
  2357. if (spec->board_config < 0) {
  2358. printk(KERN_WARNING "hda_codec: No auto-config is "
  2359. "available, default to model=ref\n");
  2360. spec->board_config = STAC_92HD71BXX_REF;
  2361. goto again;
  2362. }
  2363. err = -EINVAL;
  2364. }
  2365. if (err < 0) {
  2366. stac92xx_free(codec);
  2367. return err;
  2368. }
  2369. codec->patch_ops = stac92xx_patch_ops;
  2370. return 0;
  2371. };
  2372. static int patch_stac922x(struct hda_codec *codec)
  2373. {
  2374. struct sigmatel_spec *spec;
  2375. int err;
  2376. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2377. if (spec == NULL)
  2378. return -ENOMEM;
  2379. codec->spec = spec;
  2380. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  2381. spec->pin_nids = stac922x_pin_nids;
  2382. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  2383. stac922x_models,
  2384. stac922x_cfg_tbl);
  2385. if (spec->board_config == STAC_INTEL_MAC_V3) {
  2386. spec->gpio_mute = 1;
  2387. /* Intel Macs have all same PCI SSID, so we need to check
  2388. * codec SSID to distinguish the exact models
  2389. */
  2390. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  2391. switch (codec->subsystem_id) {
  2392. case 0x106b0800:
  2393. spec->board_config = STAC_INTEL_MAC_V1;
  2394. break;
  2395. case 0x106b0600:
  2396. case 0x106b0700:
  2397. spec->board_config = STAC_INTEL_MAC_V2;
  2398. break;
  2399. case 0x106b0e00:
  2400. case 0x106b0f00:
  2401. case 0x106b1600:
  2402. case 0x106b1700:
  2403. case 0x106b0200:
  2404. case 0x106b1e00:
  2405. spec->board_config = STAC_INTEL_MAC_V3;
  2406. break;
  2407. case 0x106b1a00:
  2408. case 0x00000100:
  2409. spec->board_config = STAC_INTEL_MAC_V4;
  2410. break;
  2411. case 0x106b0a00:
  2412. case 0x106b2200:
  2413. spec->board_config = STAC_INTEL_MAC_V5;
  2414. break;
  2415. }
  2416. }
  2417. again:
  2418. if (spec->board_config < 0) {
  2419. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  2420. "using BIOS defaults\n");
  2421. err = stac92xx_save_bios_config_regs(codec);
  2422. if (err < 0) {
  2423. stac92xx_free(codec);
  2424. return err;
  2425. }
  2426. spec->pin_configs = spec->bios_pin_configs;
  2427. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  2428. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  2429. stac92xx_set_config_regs(codec);
  2430. }
  2431. spec->adc_nids = stac922x_adc_nids;
  2432. spec->mux_nids = stac922x_mux_nids;
  2433. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  2434. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  2435. spec->num_dmics = 0;
  2436. spec->init = stac922x_core_init;
  2437. spec->mixer = stac922x_mixer;
  2438. spec->multiout.dac_nids = spec->dac_nids;
  2439. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  2440. if (!err) {
  2441. if (spec->board_config < 0) {
  2442. printk(KERN_WARNING "hda_codec: No auto-config is "
  2443. "available, default to model=ref\n");
  2444. spec->board_config = STAC_D945_REF;
  2445. goto again;
  2446. }
  2447. err = -EINVAL;
  2448. }
  2449. if (err < 0) {
  2450. stac92xx_free(codec);
  2451. return err;
  2452. }
  2453. codec->patch_ops = stac92xx_patch_ops;
  2454. /* Fix Mux capture level; max to 2 */
  2455. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  2456. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  2457. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2458. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2459. (0 << AC_AMPCAP_MUTE_SHIFT));
  2460. return 0;
  2461. }
  2462. static int patch_stac927x(struct hda_codec *codec)
  2463. {
  2464. struct sigmatel_spec *spec;
  2465. int err;
  2466. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2467. if (spec == NULL)
  2468. return -ENOMEM;
  2469. codec->spec = spec;
  2470. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  2471. spec->pin_nids = stac927x_pin_nids;
  2472. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  2473. stac927x_models,
  2474. stac927x_cfg_tbl);
  2475. again:
  2476. if (spec->board_config < 0) {
  2477. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  2478. err = stac92xx_save_bios_config_regs(codec);
  2479. if (err < 0) {
  2480. stac92xx_free(codec);
  2481. return err;
  2482. }
  2483. spec->pin_configs = spec->bios_pin_configs;
  2484. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  2485. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  2486. stac92xx_set_config_regs(codec);
  2487. }
  2488. switch (spec->board_config) {
  2489. case STAC_D965_3ST:
  2490. spec->adc_nids = stac927x_adc_nids;
  2491. spec->mux_nids = stac927x_mux_nids;
  2492. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2493. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2494. spec->init = d965_core_init;
  2495. spec->mixer = stac927x_mixer;
  2496. break;
  2497. case STAC_D965_5ST:
  2498. spec->adc_nids = stac927x_adc_nids;
  2499. spec->mux_nids = stac927x_mux_nids;
  2500. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2501. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2502. spec->init = d965_core_init;
  2503. spec->mixer = stac927x_mixer;
  2504. break;
  2505. default:
  2506. spec->adc_nids = stac927x_adc_nids;
  2507. spec->mux_nids = stac927x_mux_nids;
  2508. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2509. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2510. spec->init = stac927x_core_init;
  2511. spec->mixer = stac927x_mixer;
  2512. }
  2513. switch (codec->subsystem_id) {
  2514. case 0x10280242: /* STAC 9228 */
  2515. case 0x102801f3:
  2516. case 0x1028020A:
  2517. case 0x10280209:
  2518. spec->dmic_nids = stac927x_dmic_nids;
  2519. spec->num_dmics = STAC927X_NUM_DMICS;
  2520. spec->dmux_nid = 0x1b;
  2521. /* Enable DMIC0 */
  2522. stac92xx_set_config_reg(codec, 0x13, 0x90a60040);
  2523. /* GPIO2 High = Enable EAPD */
  2524. spec->gpio_mask = spec->gpio_data = 0x00000004;
  2525. break;
  2526. default:
  2527. spec->num_dmics = 0;
  2528. /* GPIO0 High = Enable EAPD */
  2529. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2530. }
  2531. spec->multiout.dac_nids = spec->dac_nids;
  2532. stac92xx_enable_gpio_mask(codec);
  2533. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  2534. if (!err) {
  2535. if (spec->board_config < 0) {
  2536. printk(KERN_WARNING "hda_codec: No auto-config is "
  2537. "available, default to model=ref\n");
  2538. spec->board_config = STAC_D965_REF;
  2539. goto again;
  2540. }
  2541. err = -EINVAL;
  2542. }
  2543. if (err < 0) {
  2544. stac92xx_free(codec);
  2545. return err;
  2546. }
  2547. codec->patch_ops = stac92xx_patch_ops;
  2548. return 0;
  2549. }
  2550. static int patch_stac9205(struct hda_codec *codec)
  2551. {
  2552. struct sigmatel_spec *spec;
  2553. int err;
  2554. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2555. if (spec == NULL)
  2556. return -ENOMEM;
  2557. codec->spec = spec;
  2558. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  2559. spec->pin_nids = stac9205_pin_nids;
  2560. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  2561. stac9205_models,
  2562. stac9205_cfg_tbl);
  2563. again:
  2564. if (spec->board_config < 0) {
  2565. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  2566. err = stac92xx_save_bios_config_regs(codec);
  2567. if (err < 0) {
  2568. stac92xx_free(codec);
  2569. return err;
  2570. }
  2571. spec->pin_configs = spec->bios_pin_configs;
  2572. } else {
  2573. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  2574. stac92xx_set_config_regs(codec);
  2575. }
  2576. spec->adc_nids = stac9205_adc_nids;
  2577. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  2578. spec->mux_nids = stac9205_mux_nids;
  2579. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  2580. spec->dmic_nids = stac9205_dmic_nids;
  2581. spec->num_dmics = STAC9205_NUM_DMICS;
  2582. spec->dmux_nid = 0x1d;
  2583. spec->init = stac9205_core_init;
  2584. spec->mixer = stac9205_mixer;
  2585. spec->multiout.dac_nids = spec->dac_nids;
  2586. switch (spec->board_config){
  2587. case STAC_9205_DELL_M43:
  2588. /* Enable SPDIF in/out */
  2589. stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
  2590. stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
  2591. spec->gpio_mask = 0x00000007; /* GPIO0-2 */
  2592. /* GPIO0 High = EAPD, GPIO1 Low = DRM,
  2593. * GPIO2 High = Headphone Mute
  2594. */
  2595. spec->gpio_data = 0x00000005;
  2596. break;
  2597. default:
  2598. /* GPIO0 High = EAPD */
  2599. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2600. break;
  2601. }
  2602. stac92xx_enable_gpio_mask(codec);
  2603. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  2604. if (!err) {
  2605. if (spec->board_config < 0) {
  2606. printk(KERN_WARNING "hda_codec: No auto-config is "
  2607. "available, default to model=ref\n");
  2608. spec->board_config = STAC_9205_REF;
  2609. goto again;
  2610. }
  2611. err = -EINVAL;
  2612. }
  2613. if (err < 0) {
  2614. stac92xx_free(codec);
  2615. return err;
  2616. }
  2617. codec->patch_ops = stac92xx_patch_ops;
  2618. return 0;
  2619. }
  2620. /*
  2621. * STAC9872 hack
  2622. */
  2623. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  2624. static hda_nid_t vaio_dacs[] = { 0x2 };
  2625. #define VAIO_HP_DAC 0x5
  2626. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  2627. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  2628. static struct hda_input_mux vaio_mux = {
  2629. .num_items = 3,
  2630. .items = {
  2631. /* { "HP", 0x0 }, */
  2632. { "Mic Jack", 0x1 },
  2633. { "Internal Mic", 0x2 },
  2634. { "PCM", 0x3 },
  2635. }
  2636. };
  2637. static struct hda_verb vaio_init[] = {
  2638. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2639. {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
  2640. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2641. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2642. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2643. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2644. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2645. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2646. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2647. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2648. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2649. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2650. {}
  2651. };
  2652. static struct hda_verb vaio_ar_init[] = {
  2653. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2654. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2655. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2656. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2657. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  2658. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2659. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2660. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2661. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2662. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  2663. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2664. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2665. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2666. {}
  2667. };
  2668. /* bind volumes of both NID 0x02 and 0x05 */
  2669. static struct hda_bind_ctls vaio_bind_master_vol = {
  2670. .ops = &snd_hda_bind_vol,
  2671. .values = {
  2672. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2673. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2674. 0
  2675. },
  2676. };
  2677. /* bind volumes of both NID 0x02 and 0x05 */
  2678. static struct hda_bind_ctls vaio_bind_master_sw = {
  2679. .ops = &snd_hda_bind_sw,
  2680. .values = {
  2681. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2682. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2683. 0,
  2684. },
  2685. };
  2686. static struct snd_kcontrol_new vaio_mixer[] = {
  2687. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2688. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2689. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2690. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2691. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2692. {
  2693. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2694. .name = "Capture Source",
  2695. .count = 1,
  2696. .info = stac92xx_mux_enum_info,
  2697. .get = stac92xx_mux_enum_get,
  2698. .put = stac92xx_mux_enum_put,
  2699. },
  2700. {}
  2701. };
  2702. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  2703. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2704. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2705. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2706. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2707. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2708. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  2709. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  2710. {
  2711. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2712. .name = "Capture Source",
  2713. .count = 1,
  2714. .info = stac92xx_mux_enum_info,
  2715. .get = stac92xx_mux_enum_get,
  2716. .put = stac92xx_mux_enum_put,
  2717. },
  2718. {}
  2719. };
  2720. static struct hda_codec_ops stac9872_patch_ops = {
  2721. .build_controls = stac92xx_build_controls,
  2722. .build_pcms = stac92xx_build_pcms,
  2723. .init = stac92xx_init,
  2724. .free = stac92xx_free,
  2725. #ifdef SND_HDA_NEEDS_RESUME
  2726. .resume = stac92xx_resume,
  2727. #endif
  2728. };
  2729. static int stac9872_vaio_init(struct hda_codec *codec)
  2730. {
  2731. int err;
  2732. err = stac92xx_init(codec);
  2733. if (err < 0)
  2734. return err;
  2735. if (codec->patch_ops.unsol_event)
  2736. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2737. return 0;
  2738. }
  2739. static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
  2740. {
  2741. if (get_pin_presence(codec, 0x0a)) {
  2742. stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2743. stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2744. } else {
  2745. stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2746. stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2747. }
  2748. }
  2749. static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
  2750. {
  2751. switch (res >> 26) {
  2752. case STAC_HP_EVENT:
  2753. stac9872_vaio_hp_detect(codec, res);
  2754. break;
  2755. }
  2756. }
  2757. static struct hda_codec_ops stac9872_vaio_patch_ops = {
  2758. .build_controls = stac92xx_build_controls,
  2759. .build_pcms = stac92xx_build_pcms,
  2760. .init = stac9872_vaio_init,
  2761. .free = stac92xx_free,
  2762. .unsol_event = stac9872_vaio_unsol_event,
  2763. #ifdef CONFIG_PM
  2764. .resume = stac92xx_resume,
  2765. #endif
  2766. };
  2767. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  2768. CXD9872RD_VAIO,
  2769. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  2770. STAC9872AK_VAIO,
  2771. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  2772. STAC9872K_VAIO,
  2773. /* AR Series. id=0x83847664 and subsys=104D1300 */
  2774. CXD9872AKD_VAIO,
  2775. STAC_9872_MODELS,
  2776. };
  2777. static const char *stac9872_models[STAC_9872_MODELS] = {
  2778. [CXD9872RD_VAIO] = "vaio",
  2779. [CXD9872AKD_VAIO] = "vaio-ar",
  2780. };
  2781. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  2782. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  2783. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  2784. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  2785. SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
  2786. {}
  2787. };
  2788. static int patch_stac9872(struct hda_codec *codec)
  2789. {
  2790. struct sigmatel_spec *spec;
  2791. int board_config;
  2792. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  2793. stac9872_models,
  2794. stac9872_cfg_tbl);
  2795. if (board_config < 0)
  2796. /* unknown config, let generic-parser do its job... */
  2797. return snd_hda_parse_generic_codec(codec);
  2798. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2799. if (spec == NULL)
  2800. return -ENOMEM;
  2801. codec->spec = spec;
  2802. switch (board_config) {
  2803. case CXD9872RD_VAIO:
  2804. case STAC9872AK_VAIO:
  2805. case STAC9872K_VAIO:
  2806. spec->mixer = vaio_mixer;
  2807. spec->init = vaio_init;
  2808. spec->multiout.max_channels = 2;
  2809. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2810. spec->multiout.dac_nids = vaio_dacs;
  2811. spec->multiout.hp_nid = VAIO_HP_DAC;
  2812. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2813. spec->adc_nids = vaio_adcs;
  2814. spec->input_mux = &vaio_mux;
  2815. spec->mux_nids = vaio_mux_nids;
  2816. codec->patch_ops = stac9872_vaio_patch_ops;
  2817. break;
  2818. case CXD9872AKD_VAIO:
  2819. spec->mixer = vaio_ar_mixer;
  2820. spec->init = vaio_ar_init;
  2821. spec->multiout.max_channels = 2;
  2822. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2823. spec->multiout.dac_nids = vaio_dacs;
  2824. spec->multiout.hp_nid = VAIO_HP_DAC;
  2825. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2826. spec->adc_nids = vaio_adcs;
  2827. spec->input_mux = &vaio_mux;
  2828. spec->mux_nids = vaio_mux_nids;
  2829. codec->patch_ops = stac9872_patch_ops;
  2830. break;
  2831. }
  2832. return 0;
  2833. }
  2834. /*
  2835. * patch entries
  2836. */
  2837. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  2838. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  2839. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  2840. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  2841. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  2842. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  2843. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  2844. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  2845. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  2846. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  2847. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  2848. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  2849. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  2850. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  2851. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  2852. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  2853. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  2854. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  2855. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  2856. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  2857. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  2858. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  2859. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  2860. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  2861. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  2862. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  2863. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  2864. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  2865. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  2866. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  2867. /* The following does not take into account .id=0x83847661 when subsys =
  2868. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  2869. * currently not fully supported.
  2870. */
  2871. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  2872. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  2873. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  2874. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  2875. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  2876. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  2877. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  2878. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  2879. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  2880. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  2881. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  2882. { .id = 0x111d76b0, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
  2883. {} /* terminator */
  2884. };