patch_sigmatel.c 89 KB

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