patch_sigmatel.c 89 KB

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