intel8x0.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291
  1. /*
  2. * ALSA driver for Intel ICH (i8x0) chipsets
  3. *
  4. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  5. *
  6. *
  7. * This code also contains alpha support for SiS 735 chipsets provided
  8. * by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
  9. * for SiS735, so the code is not fully functional.
  10. *
  11. *
  12. * This program 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 program 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. */
  27. #include <linux/io.h>
  28. #include <linux/delay.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/init.h>
  31. #include <linux/pci.h>
  32. #include <linux/slab.h>
  33. #include <linux/module.h>
  34. #include <sound/core.h>
  35. #include <sound/pcm.h>
  36. #include <sound/ac97_codec.h>
  37. #include <sound/info.h>
  38. #include <sound/initval.h>
  39. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  40. MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
  41. MODULE_LICENSE("GPL");
  42. MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
  43. "{Intel,82901AB-ICH0},"
  44. "{Intel,82801BA-ICH2},"
  45. "{Intel,82801CA-ICH3},"
  46. "{Intel,82801DB-ICH4},"
  47. "{Intel,ICH5},"
  48. "{Intel,ICH6},"
  49. "{Intel,ICH7},"
  50. "{Intel,6300ESB},"
  51. "{Intel,ESB2},"
  52. "{Intel,MX440},"
  53. "{SiS,SI7012},"
  54. "{NVidia,nForce Audio},"
  55. "{NVidia,nForce2 Audio},"
  56. "{NVidia,nForce3 Audio},"
  57. "{NVidia,MCP04},"
  58. "{NVidia,MCP501},"
  59. "{NVidia,CK804},"
  60. "{NVidia,CK8},"
  61. "{NVidia,CK8S},"
  62. "{AMD,AMD768},"
  63. "{AMD,AMD8111},"
  64. "{ALI,M5455}}");
  65. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  66. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  67. static int ac97_clock;
  68. static char *ac97_quirk;
  69. static bool buggy_semaphore;
  70. static int buggy_irq = -1; /* auto-check */
  71. static bool xbox;
  72. static int spdif_aclink = -1;
  73. static int inside_vm = -1;
  74. module_param(index, int, 0444);
  75. MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
  76. module_param(id, charp, 0444);
  77. MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
  78. module_param(ac97_clock, int, 0444);
  79. MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = whitelist + auto-detect, 1 = force autodetect).");
  80. module_param(ac97_quirk, charp, 0444);
  81. MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
  82. module_param(buggy_semaphore, bool, 0444);
  83. MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
  84. module_param(buggy_irq, bint, 0444);
  85. MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
  86. module_param(xbox, bool, 0444);
  87. MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
  88. module_param(spdif_aclink, int, 0444);
  89. MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
  90. module_param(inside_vm, bint, 0444);
  91. MODULE_PARM_DESC(inside_vm, "KVM/Parallels optimization.");
  92. /* just for backward compatibility */
  93. static bool enable;
  94. module_param(enable, bool, 0444);
  95. static int joystick;
  96. module_param(joystick, int, 0444);
  97. /*
  98. * Direct registers
  99. */
  100. enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
  101. #define ICHREG(x) ICH_REG_##x
  102. #define DEFINE_REGSET(name,base) \
  103. enum { \
  104. ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
  105. ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
  106. ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
  107. ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
  108. ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
  109. ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
  110. ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
  111. };
  112. /* busmaster blocks */
  113. DEFINE_REGSET(OFF, 0); /* offset */
  114. DEFINE_REGSET(PI, 0x00); /* PCM in */
  115. DEFINE_REGSET(PO, 0x10); /* PCM out */
  116. DEFINE_REGSET(MC, 0x20); /* Mic in */
  117. /* ICH4 busmaster blocks */
  118. DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
  119. DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
  120. DEFINE_REGSET(SP, 0x60); /* SPDIF out */
  121. /* values for each busmaster block */
  122. /* LVI */
  123. #define ICH_REG_LVI_MASK 0x1f
  124. /* SR */
  125. #define ICH_FIFOE 0x10 /* FIFO error */
  126. #define ICH_BCIS 0x08 /* buffer completion interrupt status */
  127. #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
  128. #define ICH_CELV 0x02 /* current equals last valid */
  129. #define ICH_DCH 0x01 /* DMA controller halted */
  130. /* PIV */
  131. #define ICH_REG_PIV_MASK 0x1f /* mask */
  132. /* CR */
  133. #define ICH_IOCE 0x10 /* interrupt on completion enable */
  134. #define ICH_FEIE 0x08 /* fifo error interrupt enable */
  135. #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
  136. #define ICH_RESETREGS 0x02 /* reset busmaster registers */
  137. #define ICH_STARTBM 0x01 /* start busmaster operation */
  138. /* global block */
  139. #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
  140. #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
  141. #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
  142. #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
  143. #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
  144. #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
  145. #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
  146. #define ICH_PCM_246_MASK 0x00300000 /* chan mask (not all chips) */
  147. #define ICH_PCM_8 0x00300000 /* 8 channels (not all chips) */
  148. #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
  149. #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
  150. #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
  151. #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
  152. #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
  153. #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
  154. #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
  155. #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
  156. #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
  157. #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
  158. #define ICH_ACLINK 0x00000008 /* AClink shut off */
  159. #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
  160. #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
  161. #define ICH_GIE 0x00000001 /* GPI interrupt enable */
  162. #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
  163. #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
  164. #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
  165. #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
  166. #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
  167. #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
  168. #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
  169. #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
  170. #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
  171. #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
  172. #define ICH_SIS_TRI 0x00080000 /* SIS: tertiary resume irq */
  173. #define ICH_SIS_TCR 0x00040000 /* SIS: tertiary codec ready */
  174. #define ICH_MD3 0x00020000 /* modem power down semaphore */
  175. #define ICH_AD3 0x00010000 /* audio power down semaphore */
  176. #define ICH_RCS 0x00008000 /* read completion status */
  177. #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
  178. #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
  179. #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
  180. #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
  181. #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
  182. #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
  183. #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
  184. #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
  185. #define ICH_POINT 0x00000040 /* playback interrupt */
  186. #define ICH_PIINT 0x00000020 /* capture interrupt */
  187. #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
  188. #define ICH_MOINT 0x00000004 /* modem playback interrupt */
  189. #define ICH_MIINT 0x00000002 /* modem capture interrupt */
  190. #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
  191. #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
  192. #define ICH_CAS 0x01 /* codec access semaphore */
  193. #define ICH_REG_SDM 0x80
  194. #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
  195. #define ICH_DI2L_SHIFT 6
  196. #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
  197. #define ICH_DI1L_SHIFT 4
  198. #define ICH_SE 0x00000008 /* steer enable */
  199. #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
  200. #define ICH_MAX_FRAGS 32 /* max hw frags */
  201. /*
  202. * registers for Ali5455
  203. */
  204. /* ALi 5455 busmaster blocks */
  205. DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
  206. DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
  207. DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
  208. DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
  209. DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
  210. DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
  211. DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
  212. DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
  213. DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
  214. DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
  215. DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
  216. enum {
  217. ICH_REG_ALI_SCR = 0x00, /* System Control Register */
  218. ICH_REG_ALI_SSR = 0x04, /* System Status Register */
  219. ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
  220. ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
  221. ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
  222. ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
  223. ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
  224. ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
  225. ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
  226. ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
  227. ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
  228. ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
  229. ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
  230. ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
  231. ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
  232. ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
  233. ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
  234. ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
  235. ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
  236. ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
  237. ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
  238. };
  239. #define ALI_CAS_SEM_BUSY 0x80000000
  240. #define ALI_CPR_ADDR_SECONDARY 0x100
  241. #define ALI_CPR_ADDR_READ 0x80
  242. #define ALI_CSPSR_CODEC_READY 0x08
  243. #define ALI_CSPSR_READ_OK 0x02
  244. #define ALI_CSPSR_WRITE_OK 0x01
  245. /* interrupts for the whole chip by interrupt status register finish */
  246. #define ALI_INT_MICIN2 (1<<26)
  247. #define ALI_INT_PCMIN2 (1<<25)
  248. #define ALI_INT_I2SIN (1<<24)
  249. #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
  250. #define ALI_INT_SPDIFIN (1<<22)
  251. #define ALI_INT_LFEOUT (1<<21)
  252. #define ALI_INT_CENTEROUT (1<<20)
  253. #define ALI_INT_CODECSPDIFOUT (1<<19)
  254. #define ALI_INT_MICIN (1<<18)
  255. #define ALI_INT_PCMOUT (1<<17)
  256. #define ALI_INT_PCMIN (1<<16)
  257. #define ALI_INT_CPRAIS (1<<7) /* command port available */
  258. #define ALI_INT_SPRAIS (1<<5) /* status port available */
  259. #define ALI_INT_GPIO (1<<1)
  260. #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|\
  261. ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
  262. #define ICH_ALI_SC_RESET (1<<31) /* master reset */
  263. #define ICH_ALI_SC_AC97_DBL (1<<30)
  264. #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
  265. #define ICH_ALI_SC_IN_BITS (3<<18)
  266. #define ICH_ALI_SC_OUT_BITS (3<<16)
  267. #define ICH_ALI_SC_6CH_CFG (3<<14)
  268. #define ICH_ALI_SC_PCM_4 (1<<8)
  269. #define ICH_ALI_SC_PCM_6 (2<<8)
  270. #define ICH_ALI_SC_PCM_246_MASK (3<<8)
  271. #define ICH_ALI_SS_SEC_ID (3<<5)
  272. #define ICH_ALI_SS_PRI_ID (3<<3)
  273. #define ICH_ALI_IF_AC97SP (1<<21)
  274. #define ICH_ALI_IF_MC (1<<20)
  275. #define ICH_ALI_IF_PI (1<<19)
  276. #define ICH_ALI_IF_MC2 (1<<18)
  277. #define ICH_ALI_IF_PI2 (1<<17)
  278. #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
  279. #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
  280. #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
  281. #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
  282. #define ICH_ALI_IF_PO_SPDF (1<<3)
  283. #define ICH_ALI_IF_PO (1<<1)
  284. /*
  285. *
  286. */
  287. enum {
  288. ICHD_PCMIN,
  289. ICHD_PCMOUT,
  290. ICHD_MIC,
  291. ICHD_MIC2,
  292. ICHD_PCM2IN,
  293. ICHD_SPBAR,
  294. ICHD_LAST = ICHD_SPBAR
  295. };
  296. enum {
  297. NVD_PCMIN,
  298. NVD_PCMOUT,
  299. NVD_MIC,
  300. NVD_SPBAR,
  301. NVD_LAST = NVD_SPBAR
  302. };
  303. enum {
  304. ALID_PCMIN,
  305. ALID_PCMOUT,
  306. ALID_MIC,
  307. ALID_AC97SPDIFOUT,
  308. ALID_SPDIFIN,
  309. ALID_SPDIFOUT,
  310. ALID_LAST = ALID_SPDIFOUT
  311. };
  312. #define get_ichdev(substream) (substream->runtime->private_data)
  313. struct ichdev {
  314. unsigned int ichd; /* ich device number */
  315. unsigned long reg_offset; /* offset to bmaddr */
  316. __le32 *bdbar; /* CPU address (32bit) */
  317. unsigned int bdbar_addr; /* PCI bus address (32bit) */
  318. struct snd_pcm_substream *substream;
  319. unsigned int physbuf; /* physical address (32bit) */
  320. unsigned int size;
  321. unsigned int fragsize;
  322. unsigned int fragsize1;
  323. unsigned int position;
  324. unsigned int pos_shift;
  325. unsigned int last_pos;
  326. int frags;
  327. int lvi;
  328. int lvi_frag;
  329. int civ;
  330. int ack;
  331. int ack_reload;
  332. unsigned int ack_bit;
  333. unsigned int roff_sr;
  334. unsigned int roff_picb;
  335. unsigned int int_sta_mask; /* interrupt status mask */
  336. unsigned int ali_slot; /* ALI DMA slot */
  337. struct ac97_pcm *pcm;
  338. int pcm_open_flag;
  339. unsigned int suspended: 1;
  340. };
  341. struct intel8x0 {
  342. unsigned int device_type;
  343. int irq;
  344. void __iomem *addr;
  345. void __iomem *bmaddr;
  346. struct pci_dev *pci;
  347. struct snd_card *card;
  348. int pcm_devs;
  349. struct snd_pcm *pcm[6];
  350. struct ichdev ichd[6];
  351. unsigned multi4: 1,
  352. multi6: 1,
  353. multi8 :1,
  354. dra: 1,
  355. smp20bit: 1;
  356. unsigned in_ac97_init: 1,
  357. in_sdin_init: 1;
  358. unsigned in_measurement: 1; /* during ac97 clock measurement */
  359. unsigned fix_nocache: 1; /* workaround for 440MX */
  360. unsigned buggy_irq: 1; /* workaround for buggy mobos */
  361. unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
  362. unsigned buggy_semaphore: 1; /* workaround for buggy codec semaphore */
  363. unsigned inside_vm: 1; /* enable VM optimization */
  364. int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
  365. unsigned int sdm_saved; /* SDM reg value */
  366. struct snd_ac97_bus *ac97_bus;
  367. struct snd_ac97 *ac97[3];
  368. unsigned int ac97_sdin[3];
  369. unsigned int max_codecs, ncodecs;
  370. unsigned int *codec_bit;
  371. unsigned int codec_isr_bits;
  372. unsigned int codec_ready_bits;
  373. spinlock_t reg_lock;
  374. u32 bdbars_count;
  375. struct snd_dma_buffer bdbars;
  376. u32 int_sta_reg; /* interrupt status register */
  377. u32 int_sta_mask; /* interrupt status mask */
  378. };
  379. static const struct pci_device_id snd_intel8x0_ids[] = {
  380. { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */
  381. { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */
  382. { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */
  383. { PCI_VDEVICE(INTEL, 0x2485), DEVICE_INTEL }, /* ICH3 */
  384. { PCI_VDEVICE(INTEL, 0x24c5), DEVICE_INTEL_ICH4 }, /* ICH4 */
  385. { PCI_VDEVICE(INTEL, 0x24d5), DEVICE_INTEL_ICH4 }, /* ICH5 */
  386. { PCI_VDEVICE(INTEL, 0x25a6), DEVICE_INTEL_ICH4 }, /* ESB */
  387. { PCI_VDEVICE(INTEL, 0x266e), DEVICE_INTEL_ICH4 }, /* ICH6 */
  388. { PCI_VDEVICE(INTEL, 0x27de), DEVICE_INTEL_ICH4 }, /* ICH7 */
  389. { PCI_VDEVICE(INTEL, 0x2698), DEVICE_INTEL_ICH4 }, /* ESB2 */
  390. { PCI_VDEVICE(INTEL, 0x7195), DEVICE_INTEL }, /* 440MX */
  391. { PCI_VDEVICE(SI, 0x7012), DEVICE_SIS }, /* SI7012 */
  392. { PCI_VDEVICE(NVIDIA, 0x01b1), DEVICE_NFORCE }, /* NFORCE */
  393. { PCI_VDEVICE(NVIDIA, 0x003a), DEVICE_NFORCE }, /* MCP04 */
  394. { PCI_VDEVICE(NVIDIA, 0x006a), DEVICE_NFORCE }, /* NFORCE2 */
  395. { PCI_VDEVICE(NVIDIA, 0x0059), DEVICE_NFORCE }, /* CK804 */
  396. { PCI_VDEVICE(NVIDIA, 0x008a), DEVICE_NFORCE }, /* CK8 */
  397. { PCI_VDEVICE(NVIDIA, 0x00da), DEVICE_NFORCE }, /* NFORCE3 */
  398. { PCI_VDEVICE(NVIDIA, 0x00ea), DEVICE_NFORCE }, /* CK8S */
  399. { PCI_VDEVICE(NVIDIA, 0x026b), DEVICE_NFORCE }, /* MCP51 */
  400. { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
  401. { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
  402. { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
  403. { 0, }
  404. };
  405. MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
  406. /*
  407. * Lowlevel I/O - busmaster
  408. */
  409. static inline u8 igetbyte(struct intel8x0 *chip, u32 offset)
  410. {
  411. return ioread8(chip->bmaddr + offset);
  412. }
  413. static inline u16 igetword(struct intel8x0 *chip, u32 offset)
  414. {
  415. return ioread16(chip->bmaddr + offset);
  416. }
  417. static inline u32 igetdword(struct intel8x0 *chip, u32 offset)
  418. {
  419. return ioread32(chip->bmaddr + offset);
  420. }
  421. static inline void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
  422. {
  423. iowrite8(val, chip->bmaddr + offset);
  424. }
  425. static inline void iputword(struct intel8x0 *chip, u32 offset, u16 val)
  426. {
  427. iowrite16(val, chip->bmaddr + offset);
  428. }
  429. static inline void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
  430. {
  431. iowrite32(val, chip->bmaddr + offset);
  432. }
  433. /*
  434. * Lowlevel I/O - AC'97 registers
  435. */
  436. static inline u16 iagetword(struct intel8x0 *chip, u32 offset)
  437. {
  438. return ioread16(chip->addr + offset);
  439. }
  440. static inline void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
  441. {
  442. iowrite16(val, chip->addr + offset);
  443. }
  444. /*
  445. * Basic I/O
  446. */
  447. /*
  448. * access to AC97 codec via normal i/o (for ICH and SIS7012)
  449. */
  450. static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int codec)
  451. {
  452. int time;
  453. if (codec > 2)
  454. return -EIO;
  455. if (chip->in_sdin_init) {
  456. /* we don't know the ready bit assignment at the moment */
  457. /* so we check any */
  458. codec = chip->codec_isr_bits;
  459. } else {
  460. codec = chip->codec_bit[chip->ac97_sdin[codec]];
  461. }
  462. /* codec ready ? */
  463. if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
  464. return -EIO;
  465. if (chip->buggy_semaphore)
  466. return 0; /* just ignore ... */
  467. /* Anyone holding a semaphore for 1 msec should be shot... */
  468. time = 100;
  469. do {
  470. if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
  471. return 0;
  472. udelay(10);
  473. } while (time--);
  474. /* access to some forbidden (non existent) ac97 registers will not
  475. * reset the semaphore. So even if you don't get the semaphore, still
  476. * continue the access. We don't need the semaphore anyway. */
  477. dev_err(chip->card->dev,
  478. "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
  479. igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
  480. iagetword(chip, 0); /* clear semaphore flag */
  481. /* I don't care about the semaphore */
  482. return -EBUSY;
  483. }
  484. static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
  485. unsigned short reg,
  486. unsigned short val)
  487. {
  488. struct intel8x0 *chip = ac97->private_data;
  489. if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  490. if (! chip->in_ac97_init)
  491. dev_err(chip->card->dev,
  492. "codec_write %d: semaphore is not ready for register 0x%x\n",
  493. ac97->num, reg);
  494. }
  495. iaputword(chip, reg + ac97->num * 0x80, val);
  496. }
  497. static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
  498. unsigned short reg)
  499. {
  500. struct intel8x0 *chip = ac97->private_data;
  501. unsigned short res;
  502. unsigned int tmp;
  503. if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  504. if (! chip->in_ac97_init)
  505. dev_err(chip->card->dev,
  506. "codec_read %d: semaphore is not ready for register 0x%x\n",
  507. ac97->num, reg);
  508. res = 0xffff;
  509. } else {
  510. res = iagetword(chip, reg + ac97->num * 0x80);
  511. if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  512. /* reset RCS and preserve other R/WC bits */
  513. iputdword(chip, ICHREG(GLOB_STA), tmp &
  514. ~(chip->codec_ready_bits | ICH_GSCI));
  515. if (! chip->in_ac97_init)
  516. dev_err(chip->card->dev,
  517. "codec_read %d: read timeout for register 0x%x\n",
  518. ac97->num, reg);
  519. res = 0xffff;
  520. }
  521. }
  522. return res;
  523. }
  524. static void snd_intel8x0_codec_read_test(struct intel8x0 *chip,
  525. unsigned int codec)
  526. {
  527. unsigned int tmp;
  528. if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
  529. iagetword(chip, codec * 0x80);
  530. if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  531. /* reset RCS and preserve other R/WC bits */
  532. iputdword(chip, ICHREG(GLOB_STA), tmp &
  533. ~(chip->codec_ready_bits | ICH_GSCI));
  534. }
  535. }
  536. }
  537. /*
  538. * access to AC97 for Ali5455
  539. */
  540. static int snd_intel8x0_ali_codec_ready(struct intel8x0 *chip, int mask)
  541. {
  542. int count = 0;
  543. for (count = 0; count < 0x7f; count++) {
  544. int val = igetbyte(chip, ICHREG(ALI_CSPSR));
  545. if (val & mask)
  546. return 0;
  547. }
  548. if (! chip->in_ac97_init)
  549. dev_warn(chip->card->dev, "AC97 codec ready timeout.\n");
  550. return -EBUSY;
  551. }
  552. static int snd_intel8x0_ali_codec_semaphore(struct intel8x0 *chip)
  553. {
  554. int time = 100;
  555. if (chip->buggy_semaphore)
  556. return 0; /* just ignore ... */
  557. while (--time && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
  558. udelay(1);
  559. if (! time && ! chip->in_ac97_init)
  560. dev_warn(chip->card->dev, "ali_codec_semaphore timeout\n");
  561. return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
  562. }
  563. static unsigned short snd_intel8x0_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg)
  564. {
  565. struct intel8x0 *chip = ac97->private_data;
  566. unsigned short data = 0xffff;
  567. if (snd_intel8x0_ali_codec_semaphore(chip))
  568. goto __err;
  569. reg |= ALI_CPR_ADDR_READ;
  570. if (ac97->num)
  571. reg |= ALI_CPR_ADDR_SECONDARY;
  572. iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  573. if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
  574. goto __err;
  575. data = igetword(chip, ICHREG(ALI_SPR));
  576. __err:
  577. return data;
  578. }
  579. static void snd_intel8x0_ali_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  580. unsigned short val)
  581. {
  582. struct intel8x0 *chip = ac97->private_data;
  583. if (snd_intel8x0_ali_codec_semaphore(chip))
  584. return;
  585. iputword(chip, ICHREG(ALI_CPR), val);
  586. if (ac97->num)
  587. reg |= ALI_CPR_ADDR_SECONDARY;
  588. iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  589. snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
  590. }
  591. /*
  592. * DMA I/O
  593. */
  594. static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ichdev)
  595. {
  596. int idx;
  597. __le32 *bdbar = ichdev->bdbar;
  598. unsigned long port = ichdev->reg_offset;
  599. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  600. if (ichdev->size == ichdev->fragsize) {
  601. ichdev->ack_reload = ichdev->ack = 2;
  602. ichdev->fragsize1 = ichdev->fragsize >> 1;
  603. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
  604. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
  605. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  606. ichdev->fragsize1 >> ichdev->pos_shift);
  607. bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
  608. bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  609. ichdev->fragsize1 >> ichdev->pos_shift);
  610. }
  611. ichdev->frags = 2;
  612. } else {
  613. ichdev->ack_reload = ichdev->ack = 1;
  614. ichdev->fragsize1 = ichdev->fragsize;
  615. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
  616. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf +
  617. (((idx >> 1) * ichdev->fragsize) %
  618. ichdev->size));
  619. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  620. ichdev->fragsize >> ichdev->pos_shift);
  621. #if 0
  622. dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
  623. idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
  624. #endif
  625. }
  626. ichdev->frags = ichdev->size / ichdev->fragsize;
  627. }
  628. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
  629. ichdev->civ = 0;
  630. iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
  631. ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
  632. ichdev->position = 0;
  633. #if 0
  634. dev_dbg(chip->card->dev,
  635. "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
  636. ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
  637. ichdev->fragsize1);
  638. #endif
  639. /* clear interrupts */
  640. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  641. }
  642. /*
  643. * Interrupt handler
  644. */
  645. static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ichdev)
  646. {
  647. unsigned long port = ichdev->reg_offset;
  648. unsigned long flags;
  649. int status, civ, i, step;
  650. int ack = 0;
  651. spin_lock_irqsave(&chip->reg_lock, flags);
  652. status = igetbyte(chip, port + ichdev->roff_sr);
  653. civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
  654. if (!(status & ICH_BCIS)) {
  655. step = 0;
  656. } else if (civ == ichdev->civ) {
  657. // snd_printd("civ same %d\n", civ);
  658. step = 1;
  659. ichdev->civ++;
  660. ichdev->civ &= ICH_REG_LVI_MASK;
  661. } else {
  662. step = civ - ichdev->civ;
  663. if (step < 0)
  664. step += ICH_REG_LVI_MASK + 1;
  665. // if (step != 1)
  666. // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
  667. ichdev->civ = civ;
  668. }
  669. ichdev->position += step * ichdev->fragsize1;
  670. if (! chip->in_measurement)
  671. ichdev->position %= ichdev->size;
  672. ichdev->lvi += step;
  673. ichdev->lvi &= ICH_REG_LVI_MASK;
  674. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  675. for (i = 0; i < step; i++) {
  676. ichdev->lvi_frag++;
  677. ichdev->lvi_frag %= ichdev->frags;
  678. ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
  679. #if 0
  680. dev_dbg(chip->card->dev,
  681. "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
  682. ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
  683. ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
  684. inl(port + 4), inb(port + ICH_REG_OFF_CR));
  685. #endif
  686. if (--ichdev->ack == 0) {
  687. ichdev->ack = ichdev->ack_reload;
  688. ack = 1;
  689. }
  690. }
  691. spin_unlock_irqrestore(&chip->reg_lock, flags);
  692. if (ack && ichdev->substream) {
  693. snd_pcm_period_elapsed(ichdev->substream);
  694. }
  695. iputbyte(chip, port + ichdev->roff_sr,
  696. status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
  697. }
  698. static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id)
  699. {
  700. struct intel8x0 *chip = dev_id;
  701. struct ichdev *ichdev;
  702. unsigned int status;
  703. unsigned int i;
  704. status = igetdword(chip, chip->int_sta_reg);
  705. if (status == 0xffffffff) /* we are not yet resumed */
  706. return IRQ_NONE;
  707. if ((status & chip->int_sta_mask) == 0) {
  708. if (status) {
  709. /* ack */
  710. iputdword(chip, chip->int_sta_reg, status);
  711. if (! chip->buggy_irq)
  712. status = 0;
  713. }
  714. return IRQ_RETVAL(status);
  715. }
  716. for (i = 0; i < chip->bdbars_count; i++) {
  717. ichdev = &chip->ichd[i];
  718. if (status & ichdev->int_sta_mask)
  719. snd_intel8x0_update(chip, ichdev);
  720. }
  721. /* ack them */
  722. iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  723. return IRQ_HANDLED;
  724. }
  725. /*
  726. * PCM part
  727. */
  728. static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  729. {
  730. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  731. struct ichdev *ichdev = get_ichdev(substream);
  732. unsigned char val = 0;
  733. unsigned long port = ichdev->reg_offset;
  734. switch (cmd) {
  735. case SNDRV_PCM_TRIGGER_RESUME:
  736. ichdev->suspended = 0;
  737. /* fall through */
  738. case SNDRV_PCM_TRIGGER_START:
  739. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  740. val = ICH_IOCE | ICH_STARTBM;
  741. ichdev->last_pos = ichdev->position;
  742. break;
  743. case SNDRV_PCM_TRIGGER_SUSPEND:
  744. ichdev->suspended = 1;
  745. /* fall through */
  746. case SNDRV_PCM_TRIGGER_STOP:
  747. val = 0;
  748. break;
  749. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  750. val = ICH_IOCE;
  751. break;
  752. default:
  753. return -EINVAL;
  754. }
  755. iputbyte(chip, port + ICH_REG_OFF_CR, val);
  756. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  757. /* wait until DMA stopped */
  758. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  759. /* reset whole DMA things */
  760. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  761. }
  762. return 0;
  763. }
  764. static int snd_intel8x0_ali_trigger(struct snd_pcm_substream *substream, int cmd)
  765. {
  766. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  767. struct ichdev *ichdev = get_ichdev(substream);
  768. unsigned long port = ichdev->reg_offset;
  769. static int fiforeg[] = {
  770. ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3)
  771. };
  772. unsigned int val, fifo;
  773. val = igetdword(chip, ICHREG(ALI_DMACR));
  774. switch (cmd) {
  775. case SNDRV_PCM_TRIGGER_RESUME:
  776. ichdev->suspended = 0;
  777. /* fall through */
  778. case SNDRV_PCM_TRIGGER_START:
  779. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  780. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  781. /* clear FIFO for synchronization of channels */
  782. fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
  783. fifo &= ~(0xff << (ichdev->ali_slot % 4));
  784. fifo |= 0x83 << (ichdev->ali_slot % 4);
  785. iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
  786. }
  787. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  788. val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
  789. /* start DMA */
  790. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot));
  791. break;
  792. case SNDRV_PCM_TRIGGER_SUSPEND:
  793. ichdev->suspended = 1;
  794. /* fall through */
  795. case SNDRV_PCM_TRIGGER_STOP:
  796. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  797. /* pause */
  798. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16)));
  799. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  800. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  801. ;
  802. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  803. break;
  804. /* reset whole DMA things */
  805. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  806. /* clear interrupts */
  807. iputbyte(chip, port + ICH_REG_OFF_SR,
  808. igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
  809. iputdword(chip, ICHREG(ALI_INTERRUPTSR),
  810. igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
  811. break;
  812. default:
  813. return -EINVAL;
  814. }
  815. return 0;
  816. }
  817. static int snd_intel8x0_hw_params(struct snd_pcm_substream *substream,
  818. struct snd_pcm_hw_params *hw_params)
  819. {
  820. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  821. struct ichdev *ichdev = get_ichdev(substream);
  822. int dbl = params_rate(hw_params) > 48000;
  823. int err;
  824. err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  825. if (err < 0)
  826. return err;
  827. if (ichdev->pcm_open_flag) {
  828. snd_ac97_pcm_close(ichdev->pcm);
  829. ichdev->pcm_open_flag = 0;
  830. }
  831. err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
  832. params_channels(hw_params),
  833. ichdev->pcm->r[dbl].slots);
  834. if (err >= 0) {
  835. ichdev->pcm_open_flag = 1;
  836. /* Force SPDIF setting */
  837. if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
  838. snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF,
  839. params_rate(hw_params));
  840. }
  841. return err;
  842. }
  843. static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
  844. {
  845. struct ichdev *ichdev = get_ichdev(substream);
  846. if (ichdev->pcm_open_flag) {
  847. snd_ac97_pcm_close(ichdev->pcm);
  848. ichdev->pcm_open_flag = 0;
  849. }
  850. return snd_pcm_lib_free_pages(substream);
  851. }
  852. static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
  853. struct snd_pcm_runtime *runtime)
  854. {
  855. unsigned int cnt;
  856. int dbl = runtime->rate > 48000;
  857. spin_lock_irq(&chip->reg_lock);
  858. switch (chip->device_type) {
  859. case DEVICE_ALI:
  860. cnt = igetdword(chip, ICHREG(ALI_SCR));
  861. cnt &= ~ICH_ALI_SC_PCM_246_MASK;
  862. if (runtime->channels == 4 || dbl)
  863. cnt |= ICH_ALI_SC_PCM_4;
  864. else if (runtime->channels == 6)
  865. cnt |= ICH_ALI_SC_PCM_6;
  866. iputdword(chip, ICHREG(ALI_SCR), cnt);
  867. break;
  868. case DEVICE_SIS:
  869. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  870. cnt &= ~ICH_SIS_PCM_246_MASK;
  871. if (runtime->channels == 4 || dbl)
  872. cnt |= ICH_SIS_PCM_4;
  873. else if (runtime->channels == 6)
  874. cnt |= ICH_SIS_PCM_6;
  875. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  876. break;
  877. default:
  878. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  879. cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
  880. if (runtime->channels == 4 || dbl)
  881. cnt |= ICH_PCM_4;
  882. else if (runtime->channels == 6)
  883. cnt |= ICH_PCM_6;
  884. else if (runtime->channels == 8)
  885. cnt |= ICH_PCM_8;
  886. if (chip->device_type == DEVICE_NFORCE) {
  887. /* reset to 2ch once to keep the 6 channel data in alignment,
  888. * to start from Front Left always
  889. */
  890. if (cnt & ICH_PCM_246_MASK) {
  891. iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
  892. spin_unlock_irq(&chip->reg_lock);
  893. msleep(50); /* grrr... */
  894. spin_lock_irq(&chip->reg_lock);
  895. }
  896. } else if (chip->device_type == DEVICE_INTEL_ICH4) {
  897. if (runtime->sample_bits > 16)
  898. cnt |= ICH_PCM_20BIT;
  899. }
  900. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  901. break;
  902. }
  903. spin_unlock_irq(&chip->reg_lock);
  904. }
  905. static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
  906. {
  907. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  908. struct snd_pcm_runtime *runtime = substream->runtime;
  909. struct ichdev *ichdev = get_ichdev(substream);
  910. ichdev->physbuf = runtime->dma_addr;
  911. ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  912. ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
  913. if (ichdev->ichd == ICHD_PCMOUT) {
  914. snd_intel8x0_setup_pcm_out(chip, runtime);
  915. if (chip->device_type == DEVICE_INTEL_ICH4)
  916. ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
  917. }
  918. snd_intel8x0_setup_periods(chip, ichdev);
  919. return 0;
  920. }
  921. static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *substream)
  922. {
  923. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  924. struct ichdev *ichdev = get_ichdev(substream);
  925. size_t ptr1, ptr;
  926. int civ, timeout = 10;
  927. unsigned int position;
  928. spin_lock(&chip->reg_lock);
  929. do {
  930. civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  931. ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  932. position = ichdev->position;
  933. if (ptr1 == 0) {
  934. udelay(10);
  935. continue;
  936. }
  937. if (civ != igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV))
  938. continue;
  939. /* IO read operation is very expensive inside virtual machine
  940. * as it is emulated. The probability that subsequent PICB read
  941. * will return different result is high enough to loop till
  942. * timeout here.
  943. * Same CIV is strict enough condition to be sure that PICB
  944. * is valid inside VM on emulated card. */
  945. if (chip->inside_vm)
  946. break;
  947. if (ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  948. break;
  949. } while (timeout--);
  950. ptr = ichdev->last_pos;
  951. if (ptr1 != 0) {
  952. ptr1 <<= ichdev->pos_shift;
  953. ptr = ichdev->fragsize1 - ptr1;
  954. ptr += position;
  955. if (ptr < ichdev->last_pos) {
  956. unsigned int pos_base, last_base;
  957. pos_base = position / ichdev->fragsize1;
  958. last_base = ichdev->last_pos / ichdev->fragsize1;
  959. /* another sanity check; ptr1 can go back to full
  960. * before the base position is updated
  961. */
  962. if (pos_base == last_base)
  963. ptr = ichdev->last_pos;
  964. }
  965. }
  966. ichdev->last_pos = ptr;
  967. spin_unlock(&chip->reg_lock);
  968. if (ptr >= ichdev->size)
  969. return 0;
  970. return bytes_to_frames(substream->runtime, ptr);
  971. }
  972. static const struct snd_pcm_hardware snd_intel8x0_stream =
  973. {
  974. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  975. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  976. SNDRV_PCM_INFO_MMAP_VALID |
  977. SNDRV_PCM_INFO_PAUSE |
  978. SNDRV_PCM_INFO_RESUME),
  979. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  980. .rates = SNDRV_PCM_RATE_48000,
  981. .rate_min = 48000,
  982. .rate_max = 48000,
  983. .channels_min = 2,
  984. .channels_max = 2,
  985. .buffer_bytes_max = 128 * 1024,
  986. .period_bytes_min = 32,
  987. .period_bytes_max = 128 * 1024,
  988. .periods_min = 1,
  989. .periods_max = 1024,
  990. .fifo_size = 0,
  991. };
  992. static const unsigned int channels4[] = {
  993. 2, 4,
  994. };
  995. static const struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
  996. .count = ARRAY_SIZE(channels4),
  997. .list = channels4,
  998. .mask = 0,
  999. };
  1000. static const unsigned int channels6[] = {
  1001. 2, 4, 6,
  1002. };
  1003. static const struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
  1004. .count = ARRAY_SIZE(channels6),
  1005. .list = channels6,
  1006. .mask = 0,
  1007. };
  1008. static const unsigned int channels8[] = {
  1009. 2, 4, 6, 8,
  1010. };
  1011. static const struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
  1012. .count = ARRAY_SIZE(channels8),
  1013. .list = channels8,
  1014. .mask = 0,
  1015. };
  1016. static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
  1017. {
  1018. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1019. struct snd_pcm_runtime *runtime = substream->runtime;
  1020. int err;
  1021. ichdev->substream = substream;
  1022. runtime->hw = snd_intel8x0_stream;
  1023. runtime->hw.rates = ichdev->pcm->rates;
  1024. snd_pcm_limit_hw_rates(runtime);
  1025. if (chip->device_type == DEVICE_SIS) {
  1026. runtime->hw.buffer_bytes_max = 64*1024;
  1027. runtime->hw.period_bytes_max = 64*1024;
  1028. }
  1029. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  1030. return err;
  1031. runtime->private_data = ichdev;
  1032. return 0;
  1033. }
  1034. static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
  1035. {
  1036. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1037. struct snd_pcm_runtime *runtime = substream->runtime;
  1038. int err;
  1039. err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
  1040. if (err < 0)
  1041. return err;
  1042. if (chip->multi8) {
  1043. runtime->hw.channels_max = 8;
  1044. snd_pcm_hw_constraint_list(runtime, 0,
  1045. SNDRV_PCM_HW_PARAM_CHANNELS,
  1046. &hw_constraints_channels8);
  1047. } else if (chip->multi6) {
  1048. runtime->hw.channels_max = 6;
  1049. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  1050. &hw_constraints_channels6);
  1051. } else if (chip->multi4) {
  1052. runtime->hw.channels_max = 4;
  1053. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  1054. &hw_constraints_channels4);
  1055. }
  1056. if (chip->dra) {
  1057. snd_ac97_pcm_double_rate_rules(runtime);
  1058. }
  1059. if (chip->smp20bit) {
  1060. runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
  1061. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
  1062. }
  1063. return 0;
  1064. }
  1065. static int snd_intel8x0_playback_close(struct snd_pcm_substream *substream)
  1066. {
  1067. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1068. chip->ichd[ICHD_PCMOUT].substream = NULL;
  1069. return 0;
  1070. }
  1071. static int snd_intel8x0_capture_open(struct snd_pcm_substream *substream)
  1072. {
  1073. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1074. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
  1075. }
  1076. static int snd_intel8x0_capture_close(struct snd_pcm_substream *substream)
  1077. {
  1078. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1079. chip->ichd[ICHD_PCMIN].substream = NULL;
  1080. return 0;
  1081. }
  1082. static int snd_intel8x0_mic_open(struct snd_pcm_substream *substream)
  1083. {
  1084. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1085. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
  1086. }
  1087. static int snd_intel8x0_mic_close(struct snd_pcm_substream *substream)
  1088. {
  1089. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1090. chip->ichd[ICHD_MIC].substream = NULL;
  1091. return 0;
  1092. }
  1093. static int snd_intel8x0_mic2_open(struct snd_pcm_substream *substream)
  1094. {
  1095. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1096. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
  1097. }
  1098. static int snd_intel8x0_mic2_close(struct snd_pcm_substream *substream)
  1099. {
  1100. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1101. chip->ichd[ICHD_MIC2].substream = NULL;
  1102. return 0;
  1103. }
  1104. static int snd_intel8x0_capture2_open(struct snd_pcm_substream *substream)
  1105. {
  1106. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1107. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
  1108. }
  1109. static int snd_intel8x0_capture2_close(struct snd_pcm_substream *substream)
  1110. {
  1111. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1112. chip->ichd[ICHD_PCM2IN].substream = NULL;
  1113. return 0;
  1114. }
  1115. static int snd_intel8x0_spdif_open(struct snd_pcm_substream *substream)
  1116. {
  1117. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1118. int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  1119. return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
  1120. }
  1121. static int snd_intel8x0_spdif_close(struct snd_pcm_substream *substream)
  1122. {
  1123. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1124. int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  1125. chip->ichd[idx].substream = NULL;
  1126. return 0;
  1127. }
  1128. static int snd_intel8x0_ali_ac97spdifout_open(struct snd_pcm_substream *substream)
  1129. {
  1130. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1131. unsigned int val;
  1132. spin_lock_irq(&chip->reg_lock);
  1133. val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  1134. val |= ICH_ALI_IF_AC97SP;
  1135. iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  1136. /* also needs to set ALI_SC_CODEC_SPDF correctly */
  1137. spin_unlock_irq(&chip->reg_lock);
  1138. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
  1139. }
  1140. static int snd_intel8x0_ali_ac97spdifout_close(struct snd_pcm_substream *substream)
  1141. {
  1142. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1143. unsigned int val;
  1144. chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
  1145. spin_lock_irq(&chip->reg_lock);
  1146. val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  1147. val &= ~ICH_ALI_IF_AC97SP;
  1148. iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  1149. spin_unlock_irq(&chip->reg_lock);
  1150. return 0;
  1151. }
  1152. #if 0 // NYI
  1153. static int snd_intel8x0_ali_spdifin_open(struct snd_pcm_substream *substream)
  1154. {
  1155. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1156. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
  1157. }
  1158. static int snd_intel8x0_ali_spdifin_close(struct snd_pcm_substream *substream)
  1159. {
  1160. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1161. chip->ichd[ALID_SPDIFIN].substream = NULL;
  1162. return 0;
  1163. }
  1164. static int snd_intel8x0_ali_spdifout_open(struct snd_pcm_substream *substream)
  1165. {
  1166. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1167. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
  1168. }
  1169. static int snd_intel8x0_ali_spdifout_close(struct snd_pcm_substream *substream)
  1170. {
  1171. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1172. chip->ichd[ALID_SPDIFOUT].substream = NULL;
  1173. return 0;
  1174. }
  1175. #endif
  1176. static const struct snd_pcm_ops snd_intel8x0_playback_ops = {
  1177. .open = snd_intel8x0_playback_open,
  1178. .close = snd_intel8x0_playback_close,
  1179. .ioctl = snd_pcm_lib_ioctl,
  1180. .hw_params = snd_intel8x0_hw_params,
  1181. .hw_free = snd_intel8x0_hw_free,
  1182. .prepare = snd_intel8x0_pcm_prepare,
  1183. .trigger = snd_intel8x0_pcm_trigger,
  1184. .pointer = snd_intel8x0_pcm_pointer,
  1185. };
  1186. static const struct snd_pcm_ops snd_intel8x0_capture_ops = {
  1187. .open = snd_intel8x0_capture_open,
  1188. .close = snd_intel8x0_capture_close,
  1189. .ioctl = snd_pcm_lib_ioctl,
  1190. .hw_params = snd_intel8x0_hw_params,
  1191. .hw_free = snd_intel8x0_hw_free,
  1192. .prepare = snd_intel8x0_pcm_prepare,
  1193. .trigger = snd_intel8x0_pcm_trigger,
  1194. .pointer = snd_intel8x0_pcm_pointer,
  1195. };
  1196. static const struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
  1197. .open = snd_intel8x0_mic_open,
  1198. .close = snd_intel8x0_mic_close,
  1199. .ioctl = snd_pcm_lib_ioctl,
  1200. .hw_params = snd_intel8x0_hw_params,
  1201. .hw_free = snd_intel8x0_hw_free,
  1202. .prepare = snd_intel8x0_pcm_prepare,
  1203. .trigger = snd_intel8x0_pcm_trigger,
  1204. .pointer = snd_intel8x0_pcm_pointer,
  1205. };
  1206. static const struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
  1207. .open = snd_intel8x0_mic2_open,
  1208. .close = snd_intel8x0_mic2_close,
  1209. .ioctl = snd_pcm_lib_ioctl,
  1210. .hw_params = snd_intel8x0_hw_params,
  1211. .hw_free = snd_intel8x0_hw_free,
  1212. .prepare = snd_intel8x0_pcm_prepare,
  1213. .trigger = snd_intel8x0_pcm_trigger,
  1214. .pointer = snd_intel8x0_pcm_pointer,
  1215. };
  1216. static const struct snd_pcm_ops snd_intel8x0_capture2_ops = {
  1217. .open = snd_intel8x0_capture2_open,
  1218. .close = snd_intel8x0_capture2_close,
  1219. .ioctl = snd_pcm_lib_ioctl,
  1220. .hw_params = snd_intel8x0_hw_params,
  1221. .hw_free = snd_intel8x0_hw_free,
  1222. .prepare = snd_intel8x0_pcm_prepare,
  1223. .trigger = snd_intel8x0_pcm_trigger,
  1224. .pointer = snd_intel8x0_pcm_pointer,
  1225. };
  1226. static const struct snd_pcm_ops snd_intel8x0_spdif_ops = {
  1227. .open = snd_intel8x0_spdif_open,
  1228. .close = snd_intel8x0_spdif_close,
  1229. .ioctl = snd_pcm_lib_ioctl,
  1230. .hw_params = snd_intel8x0_hw_params,
  1231. .hw_free = snd_intel8x0_hw_free,
  1232. .prepare = snd_intel8x0_pcm_prepare,
  1233. .trigger = snd_intel8x0_pcm_trigger,
  1234. .pointer = snd_intel8x0_pcm_pointer,
  1235. };
  1236. static const struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
  1237. .open = snd_intel8x0_playback_open,
  1238. .close = snd_intel8x0_playback_close,
  1239. .ioctl = snd_pcm_lib_ioctl,
  1240. .hw_params = snd_intel8x0_hw_params,
  1241. .hw_free = snd_intel8x0_hw_free,
  1242. .prepare = snd_intel8x0_pcm_prepare,
  1243. .trigger = snd_intel8x0_ali_trigger,
  1244. .pointer = snd_intel8x0_pcm_pointer,
  1245. };
  1246. static const struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
  1247. .open = snd_intel8x0_capture_open,
  1248. .close = snd_intel8x0_capture_close,
  1249. .ioctl = snd_pcm_lib_ioctl,
  1250. .hw_params = snd_intel8x0_hw_params,
  1251. .hw_free = snd_intel8x0_hw_free,
  1252. .prepare = snd_intel8x0_pcm_prepare,
  1253. .trigger = snd_intel8x0_ali_trigger,
  1254. .pointer = snd_intel8x0_pcm_pointer,
  1255. };
  1256. static const struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
  1257. .open = snd_intel8x0_mic_open,
  1258. .close = snd_intel8x0_mic_close,
  1259. .ioctl = snd_pcm_lib_ioctl,
  1260. .hw_params = snd_intel8x0_hw_params,
  1261. .hw_free = snd_intel8x0_hw_free,
  1262. .prepare = snd_intel8x0_pcm_prepare,
  1263. .trigger = snd_intel8x0_ali_trigger,
  1264. .pointer = snd_intel8x0_pcm_pointer,
  1265. };
  1266. static const struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
  1267. .open = snd_intel8x0_ali_ac97spdifout_open,
  1268. .close = snd_intel8x0_ali_ac97spdifout_close,
  1269. .ioctl = snd_pcm_lib_ioctl,
  1270. .hw_params = snd_intel8x0_hw_params,
  1271. .hw_free = snd_intel8x0_hw_free,
  1272. .prepare = snd_intel8x0_pcm_prepare,
  1273. .trigger = snd_intel8x0_ali_trigger,
  1274. .pointer = snd_intel8x0_pcm_pointer,
  1275. };
  1276. #if 0 // NYI
  1277. static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
  1278. .open = snd_intel8x0_ali_spdifin_open,
  1279. .close = snd_intel8x0_ali_spdifin_close,
  1280. .ioctl = snd_pcm_lib_ioctl,
  1281. .hw_params = snd_intel8x0_hw_params,
  1282. .hw_free = snd_intel8x0_hw_free,
  1283. .prepare = snd_intel8x0_pcm_prepare,
  1284. .trigger = snd_intel8x0_pcm_trigger,
  1285. .pointer = snd_intel8x0_pcm_pointer,
  1286. };
  1287. static struct snd_pcm_ops snd_intel8x0_ali_spdifout_ops = {
  1288. .open = snd_intel8x0_ali_spdifout_open,
  1289. .close = snd_intel8x0_ali_spdifout_close,
  1290. .ioctl = snd_pcm_lib_ioctl,
  1291. .hw_params = snd_intel8x0_hw_params,
  1292. .hw_free = snd_intel8x0_hw_free,
  1293. .prepare = snd_intel8x0_pcm_prepare,
  1294. .trigger = snd_intel8x0_pcm_trigger,
  1295. .pointer = snd_intel8x0_pcm_pointer,
  1296. };
  1297. #endif // NYI
  1298. struct ich_pcm_table {
  1299. char *suffix;
  1300. const struct snd_pcm_ops *playback_ops;
  1301. const struct snd_pcm_ops *capture_ops;
  1302. size_t prealloc_size;
  1303. size_t prealloc_max_size;
  1304. int ac97_idx;
  1305. };
  1306. #define intel8x0_dma_type(chip) \
  1307. ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_UC : SNDRV_DMA_TYPE_DEV)
  1308. static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
  1309. struct ich_pcm_table *rec)
  1310. {
  1311. struct snd_pcm *pcm;
  1312. int err;
  1313. char name[32];
  1314. if (rec->suffix)
  1315. sprintf(name, "Intel ICH - %s", rec->suffix);
  1316. else
  1317. strcpy(name, "Intel ICH");
  1318. err = snd_pcm_new(chip->card, name, device,
  1319. rec->playback_ops ? 1 : 0,
  1320. rec->capture_ops ? 1 : 0, &pcm);
  1321. if (err < 0)
  1322. return err;
  1323. if (rec->playback_ops)
  1324. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
  1325. if (rec->capture_ops)
  1326. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
  1327. pcm->private_data = chip;
  1328. pcm->info_flags = 0;
  1329. if (rec->suffix)
  1330. sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
  1331. else
  1332. strcpy(pcm->name, chip->card->shortname);
  1333. chip->pcm[device] = pcm;
  1334. snd_pcm_lib_preallocate_pages_for_all(pcm, intel8x0_dma_type(chip),
  1335. snd_dma_pci_data(chip->pci),
  1336. rec->prealloc_size, rec->prealloc_max_size);
  1337. if (rec->playback_ops &&
  1338. rec->playback_ops->open == snd_intel8x0_playback_open) {
  1339. struct snd_pcm_chmap *chmap;
  1340. int chs = 2;
  1341. if (chip->multi8)
  1342. chs = 8;
  1343. else if (chip->multi6)
  1344. chs = 6;
  1345. else if (chip->multi4)
  1346. chs = 4;
  1347. err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1348. snd_pcm_alt_chmaps, chs, 0,
  1349. &chmap);
  1350. if (err < 0)
  1351. return err;
  1352. chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
  1353. chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
  1354. }
  1355. return 0;
  1356. }
  1357. static struct ich_pcm_table intel_pcms[] = {
  1358. {
  1359. .playback_ops = &snd_intel8x0_playback_ops,
  1360. .capture_ops = &snd_intel8x0_capture_ops,
  1361. .prealloc_size = 64 * 1024,
  1362. .prealloc_max_size = 128 * 1024,
  1363. },
  1364. {
  1365. .suffix = "MIC ADC",
  1366. .capture_ops = &snd_intel8x0_capture_mic_ops,
  1367. .prealloc_size = 0,
  1368. .prealloc_max_size = 128 * 1024,
  1369. .ac97_idx = ICHD_MIC,
  1370. },
  1371. {
  1372. .suffix = "MIC2 ADC",
  1373. .capture_ops = &snd_intel8x0_capture_mic2_ops,
  1374. .prealloc_size = 0,
  1375. .prealloc_max_size = 128 * 1024,
  1376. .ac97_idx = ICHD_MIC2,
  1377. },
  1378. {
  1379. .suffix = "ADC2",
  1380. .capture_ops = &snd_intel8x0_capture2_ops,
  1381. .prealloc_size = 0,
  1382. .prealloc_max_size = 128 * 1024,
  1383. .ac97_idx = ICHD_PCM2IN,
  1384. },
  1385. {
  1386. .suffix = "IEC958",
  1387. .playback_ops = &snd_intel8x0_spdif_ops,
  1388. .prealloc_size = 64 * 1024,
  1389. .prealloc_max_size = 128 * 1024,
  1390. .ac97_idx = ICHD_SPBAR,
  1391. },
  1392. };
  1393. static struct ich_pcm_table nforce_pcms[] = {
  1394. {
  1395. .playback_ops = &snd_intel8x0_playback_ops,
  1396. .capture_ops = &snd_intel8x0_capture_ops,
  1397. .prealloc_size = 64 * 1024,
  1398. .prealloc_max_size = 128 * 1024,
  1399. },
  1400. {
  1401. .suffix = "MIC ADC",
  1402. .capture_ops = &snd_intel8x0_capture_mic_ops,
  1403. .prealloc_size = 0,
  1404. .prealloc_max_size = 128 * 1024,
  1405. .ac97_idx = NVD_MIC,
  1406. },
  1407. {
  1408. .suffix = "IEC958",
  1409. .playback_ops = &snd_intel8x0_spdif_ops,
  1410. .prealloc_size = 64 * 1024,
  1411. .prealloc_max_size = 128 * 1024,
  1412. .ac97_idx = NVD_SPBAR,
  1413. },
  1414. };
  1415. static struct ich_pcm_table ali_pcms[] = {
  1416. {
  1417. .playback_ops = &snd_intel8x0_ali_playback_ops,
  1418. .capture_ops = &snd_intel8x0_ali_capture_ops,
  1419. .prealloc_size = 64 * 1024,
  1420. .prealloc_max_size = 128 * 1024,
  1421. },
  1422. {
  1423. .suffix = "MIC ADC",
  1424. .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
  1425. .prealloc_size = 0,
  1426. .prealloc_max_size = 128 * 1024,
  1427. .ac97_idx = ALID_MIC,
  1428. },
  1429. {
  1430. .suffix = "IEC958",
  1431. .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
  1432. /* .capture_ops = &snd_intel8x0_ali_spdifin_ops, */
  1433. .prealloc_size = 64 * 1024,
  1434. .prealloc_max_size = 128 * 1024,
  1435. .ac97_idx = ALID_AC97SPDIFOUT,
  1436. },
  1437. #if 0 // NYI
  1438. {
  1439. .suffix = "HW IEC958",
  1440. .playback_ops = &snd_intel8x0_ali_spdifout_ops,
  1441. .prealloc_size = 64 * 1024,
  1442. .prealloc_max_size = 128 * 1024,
  1443. },
  1444. #endif
  1445. };
  1446. static int snd_intel8x0_pcm(struct intel8x0 *chip)
  1447. {
  1448. int i, tblsize, device, err;
  1449. struct ich_pcm_table *tbl, *rec;
  1450. switch (chip->device_type) {
  1451. case DEVICE_INTEL_ICH4:
  1452. tbl = intel_pcms;
  1453. tblsize = ARRAY_SIZE(intel_pcms);
  1454. if (spdif_aclink)
  1455. tblsize--;
  1456. break;
  1457. case DEVICE_NFORCE:
  1458. tbl = nforce_pcms;
  1459. tblsize = ARRAY_SIZE(nforce_pcms);
  1460. if (spdif_aclink)
  1461. tblsize--;
  1462. break;
  1463. case DEVICE_ALI:
  1464. tbl = ali_pcms;
  1465. tblsize = ARRAY_SIZE(ali_pcms);
  1466. break;
  1467. default:
  1468. tbl = intel_pcms;
  1469. tblsize = 2;
  1470. break;
  1471. }
  1472. device = 0;
  1473. for (i = 0; i < tblsize; i++) {
  1474. rec = tbl + i;
  1475. if (i > 0 && rec->ac97_idx) {
  1476. /* activate PCM only when associated AC'97 codec */
  1477. if (! chip->ichd[rec->ac97_idx].pcm)
  1478. continue;
  1479. }
  1480. err = snd_intel8x0_pcm1(chip, device, rec);
  1481. if (err < 0)
  1482. return err;
  1483. device++;
  1484. }
  1485. chip->pcm_devs = device;
  1486. return 0;
  1487. }
  1488. /*
  1489. * Mixer part
  1490. */
  1491. static void snd_intel8x0_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  1492. {
  1493. struct intel8x0 *chip = bus->private_data;
  1494. chip->ac97_bus = NULL;
  1495. }
  1496. static void snd_intel8x0_mixer_free_ac97(struct snd_ac97 *ac97)
  1497. {
  1498. struct intel8x0 *chip = ac97->private_data;
  1499. chip->ac97[ac97->num] = NULL;
  1500. }
  1501. static const struct ac97_pcm ac97_pcm_defs[] = {
  1502. /* front PCM */
  1503. {
  1504. .exclusive = 1,
  1505. .r = { {
  1506. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1507. (1 << AC97_SLOT_PCM_RIGHT) |
  1508. (1 << AC97_SLOT_PCM_CENTER) |
  1509. (1 << AC97_SLOT_PCM_SLEFT) |
  1510. (1 << AC97_SLOT_PCM_SRIGHT) |
  1511. (1 << AC97_SLOT_LFE)
  1512. },
  1513. {
  1514. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1515. (1 << AC97_SLOT_PCM_RIGHT) |
  1516. (1 << AC97_SLOT_PCM_LEFT_0) |
  1517. (1 << AC97_SLOT_PCM_RIGHT_0)
  1518. }
  1519. }
  1520. },
  1521. /* PCM IN #1 */
  1522. {
  1523. .stream = 1,
  1524. .exclusive = 1,
  1525. .r = { {
  1526. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1527. (1 << AC97_SLOT_PCM_RIGHT)
  1528. }
  1529. }
  1530. },
  1531. /* MIC IN #1 */
  1532. {
  1533. .stream = 1,
  1534. .exclusive = 1,
  1535. .r = { {
  1536. .slots = (1 << AC97_SLOT_MIC)
  1537. }
  1538. }
  1539. },
  1540. /* S/PDIF PCM */
  1541. {
  1542. .exclusive = 1,
  1543. .spdif = 1,
  1544. .r = { {
  1545. .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
  1546. (1 << AC97_SLOT_SPDIF_RIGHT2)
  1547. }
  1548. }
  1549. },
  1550. /* PCM IN #2 */
  1551. {
  1552. .stream = 1,
  1553. .exclusive = 1,
  1554. .r = { {
  1555. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1556. (1 << AC97_SLOT_PCM_RIGHT)
  1557. }
  1558. }
  1559. },
  1560. /* MIC IN #2 */
  1561. {
  1562. .stream = 1,
  1563. .exclusive = 1,
  1564. .r = { {
  1565. .slots = (1 << AC97_SLOT_MIC)
  1566. }
  1567. }
  1568. },
  1569. };
  1570. static const struct ac97_quirk ac97_quirks[] = {
  1571. {
  1572. .subvendor = 0x0e11,
  1573. .subdevice = 0x000e,
  1574. .name = "Compaq Deskpro EN", /* AD1885 */
  1575. .type = AC97_TUNE_HP_ONLY
  1576. },
  1577. {
  1578. .subvendor = 0x0e11,
  1579. .subdevice = 0x008a,
  1580. .name = "Compaq Evo W4000", /* AD1885 */
  1581. .type = AC97_TUNE_HP_ONLY
  1582. },
  1583. {
  1584. .subvendor = 0x0e11,
  1585. .subdevice = 0x00b8,
  1586. .name = "Compaq Evo D510C",
  1587. .type = AC97_TUNE_HP_ONLY
  1588. },
  1589. {
  1590. .subvendor = 0x0e11,
  1591. .subdevice = 0x0860,
  1592. .name = "HP/Compaq nx7010",
  1593. .type = AC97_TUNE_MUTE_LED
  1594. },
  1595. {
  1596. .subvendor = 0x1014,
  1597. .subdevice = 0x0534,
  1598. .name = "ThinkPad X31",
  1599. .type = AC97_TUNE_INV_EAPD
  1600. },
  1601. {
  1602. .subvendor = 0x1014,
  1603. .subdevice = 0x1f00,
  1604. .name = "MS-9128",
  1605. .type = AC97_TUNE_ALC_JACK
  1606. },
  1607. {
  1608. .subvendor = 0x1014,
  1609. .subdevice = 0x0267,
  1610. .name = "IBM NetVista A30p", /* AD1981B */
  1611. .type = AC97_TUNE_HP_ONLY
  1612. },
  1613. {
  1614. .subvendor = 0x1025,
  1615. .subdevice = 0x0082,
  1616. .name = "Acer Travelmate 2310",
  1617. .type = AC97_TUNE_HP_ONLY
  1618. },
  1619. {
  1620. .subvendor = 0x1025,
  1621. .subdevice = 0x0083,
  1622. .name = "Acer Aspire 3003LCi",
  1623. .type = AC97_TUNE_HP_ONLY
  1624. },
  1625. {
  1626. .subvendor = 0x1028,
  1627. .subdevice = 0x00d8,
  1628. .name = "Dell Precision 530", /* AD1885 */
  1629. .type = AC97_TUNE_HP_ONLY
  1630. },
  1631. {
  1632. .subvendor = 0x1028,
  1633. .subdevice = 0x010d,
  1634. .name = "Dell", /* which model? AD1885 */
  1635. .type = AC97_TUNE_HP_ONLY
  1636. },
  1637. {
  1638. .subvendor = 0x1028,
  1639. .subdevice = 0x0126,
  1640. .name = "Dell Optiplex GX260", /* AD1981A */
  1641. .type = AC97_TUNE_HP_ONLY
  1642. },
  1643. {
  1644. .subvendor = 0x1028,
  1645. .subdevice = 0x012c,
  1646. .name = "Dell Precision 650", /* AD1981A */
  1647. .type = AC97_TUNE_HP_ONLY
  1648. },
  1649. {
  1650. .subvendor = 0x1028,
  1651. .subdevice = 0x012d,
  1652. .name = "Dell Precision 450", /* AD1981B*/
  1653. .type = AC97_TUNE_HP_ONLY
  1654. },
  1655. {
  1656. .subvendor = 0x1028,
  1657. .subdevice = 0x0147,
  1658. .name = "Dell", /* which model? AD1981B*/
  1659. .type = AC97_TUNE_HP_ONLY
  1660. },
  1661. {
  1662. .subvendor = 0x1028,
  1663. .subdevice = 0x0151,
  1664. .name = "Dell Optiplex GX270", /* AD1981B */
  1665. .type = AC97_TUNE_HP_ONLY
  1666. },
  1667. {
  1668. .subvendor = 0x1028,
  1669. .subdevice = 0x014e,
  1670. .name = "Dell D800", /* STAC9750/51 */
  1671. .type = AC97_TUNE_HP_ONLY
  1672. },
  1673. {
  1674. .subvendor = 0x1028,
  1675. .subdevice = 0x0163,
  1676. .name = "Dell Unknown", /* STAC9750/51 */
  1677. .type = AC97_TUNE_HP_ONLY
  1678. },
  1679. {
  1680. .subvendor = 0x1028,
  1681. .subdevice = 0x016a,
  1682. .name = "Dell Inspiron 8600", /* STAC9750/51 */
  1683. .type = AC97_TUNE_HP_ONLY
  1684. },
  1685. {
  1686. .subvendor = 0x1028,
  1687. .subdevice = 0x0182,
  1688. .name = "Dell Latitude D610", /* STAC9750/51 */
  1689. .type = AC97_TUNE_HP_ONLY
  1690. },
  1691. {
  1692. .subvendor = 0x1028,
  1693. .subdevice = 0x0186,
  1694. .name = "Dell Latitude D810", /* cf. Malone #41015 */
  1695. .type = AC97_TUNE_HP_MUTE_LED
  1696. },
  1697. {
  1698. .subvendor = 0x1028,
  1699. .subdevice = 0x0188,
  1700. .name = "Dell Inspiron 6000",
  1701. .type = AC97_TUNE_HP_MUTE_LED /* cf. Malone #41015 */
  1702. },
  1703. {
  1704. .subvendor = 0x1028,
  1705. .subdevice = 0x0189,
  1706. .name = "Dell Inspiron 9300",
  1707. .type = AC97_TUNE_HP_MUTE_LED
  1708. },
  1709. {
  1710. .subvendor = 0x1028,
  1711. .subdevice = 0x0191,
  1712. .name = "Dell Inspiron 8600",
  1713. .type = AC97_TUNE_HP_ONLY
  1714. },
  1715. {
  1716. .subvendor = 0x103c,
  1717. .subdevice = 0x006d,
  1718. .name = "HP zv5000",
  1719. .type = AC97_TUNE_MUTE_LED /*AD1981B*/
  1720. },
  1721. { /* FIXME: which codec? */
  1722. .subvendor = 0x103c,
  1723. .subdevice = 0x00c3,
  1724. .name = "HP xw6000",
  1725. .type = AC97_TUNE_HP_ONLY
  1726. },
  1727. {
  1728. .subvendor = 0x103c,
  1729. .subdevice = 0x088c,
  1730. .name = "HP nc8000",
  1731. .type = AC97_TUNE_HP_MUTE_LED
  1732. },
  1733. {
  1734. .subvendor = 0x103c,
  1735. .subdevice = 0x0890,
  1736. .name = "HP nc6000",
  1737. .type = AC97_TUNE_MUTE_LED
  1738. },
  1739. {
  1740. .subvendor = 0x103c,
  1741. .subdevice = 0x129d,
  1742. .name = "HP xw8000",
  1743. .type = AC97_TUNE_HP_ONLY
  1744. },
  1745. {
  1746. .subvendor = 0x103c,
  1747. .subdevice = 0x0938,
  1748. .name = "HP nc4200",
  1749. .type = AC97_TUNE_HP_MUTE_LED
  1750. },
  1751. {
  1752. .subvendor = 0x103c,
  1753. .subdevice = 0x099c,
  1754. .name = "HP nx6110/nc6120",
  1755. .type = AC97_TUNE_HP_MUTE_LED
  1756. },
  1757. {
  1758. .subvendor = 0x103c,
  1759. .subdevice = 0x0944,
  1760. .name = "HP nc6220",
  1761. .type = AC97_TUNE_HP_MUTE_LED
  1762. },
  1763. {
  1764. .subvendor = 0x103c,
  1765. .subdevice = 0x0934,
  1766. .name = "HP nc8220",
  1767. .type = AC97_TUNE_HP_MUTE_LED
  1768. },
  1769. {
  1770. .subvendor = 0x103c,
  1771. .subdevice = 0x12f1,
  1772. .name = "HP xw8200", /* AD1981B*/
  1773. .type = AC97_TUNE_HP_ONLY
  1774. },
  1775. {
  1776. .subvendor = 0x103c,
  1777. .subdevice = 0x12f2,
  1778. .name = "HP xw6200",
  1779. .type = AC97_TUNE_HP_ONLY
  1780. },
  1781. {
  1782. .subvendor = 0x103c,
  1783. .subdevice = 0x3008,
  1784. .name = "HP xw4200", /* AD1981B*/
  1785. .type = AC97_TUNE_HP_ONLY
  1786. },
  1787. {
  1788. .subvendor = 0x104d,
  1789. .subdevice = 0x8144,
  1790. .name = "Sony",
  1791. .type = AC97_TUNE_INV_EAPD
  1792. },
  1793. {
  1794. .subvendor = 0x104d,
  1795. .subdevice = 0x8197,
  1796. .name = "Sony S1XP",
  1797. .type = AC97_TUNE_INV_EAPD
  1798. },
  1799. {
  1800. .subvendor = 0x104d,
  1801. .subdevice = 0x81c0,
  1802. .name = "Sony VAIO VGN-T350P", /*AD1981B*/
  1803. .type = AC97_TUNE_INV_EAPD
  1804. },
  1805. {
  1806. .subvendor = 0x104d,
  1807. .subdevice = 0x81c5,
  1808. .name = "Sony VAIO VGN-B1VP", /*AD1981B*/
  1809. .type = AC97_TUNE_INV_EAPD
  1810. },
  1811. {
  1812. .subvendor = 0x1043,
  1813. .subdevice = 0x80f3,
  1814. .name = "ASUS ICH5/AD1985",
  1815. .type = AC97_TUNE_AD_SHARING
  1816. },
  1817. {
  1818. .subvendor = 0x10cf,
  1819. .subdevice = 0x11c3,
  1820. .name = "Fujitsu-Siemens E4010",
  1821. .type = AC97_TUNE_HP_ONLY
  1822. },
  1823. {
  1824. .subvendor = 0x10cf,
  1825. .subdevice = 0x1225,
  1826. .name = "Fujitsu-Siemens T3010",
  1827. .type = AC97_TUNE_HP_ONLY
  1828. },
  1829. {
  1830. .subvendor = 0x10cf,
  1831. .subdevice = 0x1253,
  1832. .name = "Fujitsu S6210", /* STAC9750/51 */
  1833. .type = AC97_TUNE_HP_ONLY
  1834. },
  1835. {
  1836. .subvendor = 0x10cf,
  1837. .subdevice = 0x127d,
  1838. .name = "Fujitsu Lifebook P7010",
  1839. .type = AC97_TUNE_HP_ONLY
  1840. },
  1841. {
  1842. .subvendor = 0x10cf,
  1843. .subdevice = 0x127e,
  1844. .name = "Fujitsu Lifebook C1211D",
  1845. .type = AC97_TUNE_HP_ONLY
  1846. },
  1847. {
  1848. .subvendor = 0x10cf,
  1849. .subdevice = 0x12ec,
  1850. .name = "Fujitsu-Siemens 4010",
  1851. .type = AC97_TUNE_HP_ONLY
  1852. },
  1853. {
  1854. .subvendor = 0x10cf,
  1855. .subdevice = 0x12f2,
  1856. .name = "Fujitsu-Siemens Celsius H320",
  1857. .type = AC97_TUNE_SWAP_HP
  1858. },
  1859. {
  1860. .subvendor = 0x10f1,
  1861. .subdevice = 0x2665,
  1862. .name = "Fujitsu-Siemens Celsius", /* AD1981? */
  1863. .type = AC97_TUNE_HP_ONLY
  1864. },
  1865. {
  1866. .subvendor = 0x10f1,
  1867. .subdevice = 0x2885,
  1868. .name = "AMD64 Mobo", /* ALC650 */
  1869. .type = AC97_TUNE_HP_ONLY
  1870. },
  1871. {
  1872. .subvendor = 0x10f1,
  1873. .subdevice = 0x2895,
  1874. .name = "Tyan Thunder K8WE",
  1875. .type = AC97_TUNE_HP_ONLY
  1876. },
  1877. {
  1878. .subvendor = 0x10f7,
  1879. .subdevice = 0x834c,
  1880. .name = "Panasonic CF-R4",
  1881. .type = AC97_TUNE_HP_ONLY,
  1882. },
  1883. {
  1884. .subvendor = 0x110a,
  1885. .subdevice = 0x0056,
  1886. .name = "Fujitsu-Siemens Scenic", /* AD1981? */
  1887. .type = AC97_TUNE_HP_ONLY
  1888. },
  1889. {
  1890. .subvendor = 0x11d4,
  1891. .subdevice = 0x5375,
  1892. .name = "ADI AD1985 (discrete)",
  1893. .type = AC97_TUNE_HP_ONLY
  1894. },
  1895. {
  1896. .subvendor = 0x1462,
  1897. .subdevice = 0x5470,
  1898. .name = "MSI P4 ATX 645 Ultra",
  1899. .type = AC97_TUNE_HP_ONLY
  1900. },
  1901. {
  1902. .subvendor = 0x161f,
  1903. .subdevice = 0x202f,
  1904. .name = "Gateway M520",
  1905. .type = AC97_TUNE_INV_EAPD
  1906. },
  1907. {
  1908. .subvendor = 0x161f,
  1909. .subdevice = 0x203a,
  1910. .name = "Gateway 4525GZ", /* AD1981B */
  1911. .type = AC97_TUNE_INV_EAPD
  1912. },
  1913. {
  1914. .subvendor = 0x1734,
  1915. .subdevice = 0x0088,
  1916. .name = "Fujitsu-Siemens D1522", /* AD1981 */
  1917. .type = AC97_TUNE_HP_ONLY
  1918. },
  1919. {
  1920. .subvendor = 0x8086,
  1921. .subdevice = 0x2000,
  1922. .mask = 0xfff0,
  1923. .name = "Intel ICH5/AD1985",
  1924. .type = AC97_TUNE_AD_SHARING
  1925. },
  1926. {
  1927. .subvendor = 0x8086,
  1928. .subdevice = 0x4000,
  1929. .mask = 0xfff0,
  1930. .name = "Intel ICH5/AD1985",
  1931. .type = AC97_TUNE_AD_SHARING
  1932. },
  1933. {
  1934. .subvendor = 0x8086,
  1935. .subdevice = 0x4856,
  1936. .name = "Intel D845WN (82801BA)",
  1937. .type = AC97_TUNE_SWAP_HP
  1938. },
  1939. {
  1940. .subvendor = 0x8086,
  1941. .subdevice = 0x4d44,
  1942. .name = "Intel D850EMV2", /* AD1885 */
  1943. .type = AC97_TUNE_HP_ONLY
  1944. },
  1945. {
  1946. .subvendor = 0x8086,
  1947. .subdevice = 0x4d56,
  1948. .name = "Intel ICH/AD1885",
  1949. .type = AC97_TUNE_HP_ONLY
  1950. },
  1951. {
  1952. .subvendor = 0x8086,
  1953. .subdevice = 0x6000,
  1954. .mask = 0xfff0,
  1955. .name = "Intel ICH5/AD1985",
  1956. .type = AC97_TUNE_AD_SHARING
  1957. },
  1958. {
  1959. .subvendor = 0x8086,
  1960. .subdevice = 0xe000,
  1961. .mask = 0xfff0,
  1962. .name = "Intel ICH5/AD1985",
  1963. .type = AC97_TUNE_AD_SHARING
  1964. },
  1965. #if 0 /* FIXME: this seems wrong on most boards */
  1966. {
  1967. .subvendor = 0x8086,
  1968. .subdevice = 0xa000,
  1969. .mask = 0xfff0,
  1970. .name = "Intel ICH5/AD1985",
  1971. .type = AC97_TUNE_HP_ONLY
  1972. },
  1973. #endif
  1974. { } /* terminator */
  1975. };
  1976. static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
  1977. const char *quirk_override)
  1978. {
  1979. struct snd_ac97_bus *pbus;
  1980. struct snd_ac97_template ac97;
  1981. int err;
  1982. unsigned int i, codecs;
  1983. unsigned int glob_sta = 0;
  1984. struct snd_ac97_bus_ops *ops;
  1985. static struct snd_ac97_bus_ops standard_bus_ops = {
  1986. .write = snd_intel8x0_codec_write,
  1987. .read = snd_intel8x0_codec_read,
  1988. };
  1989. static struct snd_ac97_bus_ops ali_bus_ops = {
  1990. .write = snd_intel8x0_ali_codec_write,
  1991. .read = snd_intel8x0_ali_codec_read,
  1992. };
  1993. chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
  1994. if (!spdif_aclink) {
  1995. switch (chip->device_type) {
  1996. case DEVICE_NFORCE:
  1997. chip->spdif_idx = NVD_SPBAR;
  1998. break;
  1999. case DEVICE_ALI:
  2000. chip->spdif_idx = ALID_AC97SPDIFOUT;
  2001. break;
  2002. case DEVICE_INTEL_ICH4:
  2003. chip->spdif_idx = ICHD_SPBAR;
  2004. break;
  2005. }
  2006. }
  2007. chip->in_ac97_init = 1;
  2008. memset(&ac97, 0, sizeof(ac97));
  2009. ac97.private_data = chip;
  2010. ac97.private_free = snd_intel8x0_mixer_free_ac97;
  2011. ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
  2012. if (chip->xbox)
  2013. ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
  2014. if (chip->device_type != DEVICE_ALI) {
  2015. glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  2016. ops = &standard_bus_ops;
  2017. chip->in_sdin_init = 1;
  2018. codecs = 0;
  2019. for (i = 0; i < chip->max_codecs; i++) {
  2020. if (! (glob_sta & chip->codec_bit[i]))
  2021. continue;
  2022. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2023. snd_intel8x0_codec_read_test(chip, codecs);
  2024. chip->ac97_sdin[codecs] =
  2025. igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
  2026. if (snd_BUG_ON(chip->ac97_sdin[codecs] >= 3))
  2027. chip->ac97_sdin[codecs] = 0;
  2028. } else
  2029. chip->ac97_sdin[codecs] = i;
  2030. codecs++;
  2031. }
  2032. chip->in_sdin_init = 0;
  2033. if (! codecs)
  2034. codecs = 1;
  2035. } else {
  2036. ops = &ali_bus_ops;
  2037. codecs = 1;
  2038. /* detect the secondary codec */
  2039. for (i = 0; i < 100; i++) {
  2040. unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
  2041. if (reg & 0x40) {
  2042. codecs = 2;
  2043. break;
  2044. }
  2045. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
  2046. udelay(1);
  2047. }
  2048. }
  2049. if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
  2050. goto __err;
  2051. pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
  2052. if (ac97_clock >= 8000 && ac97_clock <= 48000)
  2053. pbus->clock = ac97_clock;
  2054. /* FIXME: my test board doesn't work well with VRA... */
  2055. if (chip->device_type == DEVICE_ALI)
  2056. pbus->no_vra = 1;
  2057. else
  2058. pbus->dra = 1;
  2059. chip->ac97_bus = pbus;
  2060. chip->ncodecs = codecs;
  2061. ac97.pci = chip->pci;
  2062. for (i = 0; i < codecs; i++) {
  2063. ac97.num = i;
  2064. if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
  2065. if (err != -EACCES)
  2066. dev_err(chip->card->dev,
  2067. "Unable to initialize codec #%d\n", i);
  2068. if (i == 0)
  2069. goto __err;
  2070. }
  2071. }
  2072. /* tune up the primary codec */
  2073. snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
  2074. /* enable separate SDINs for ICH4 */
  2075. if (chip->device_type == DEVICE_INTEL_ICH4)
  2076. pbus->isdin = 1;
  2077. /* find the available PCM streams */
  2078. i = ARRAY_SIZE(ac97_pcm_defs);
  2079. if (chip->device_type != DEVICE_INTEL_ICH4)
  2080. i -= 2; /* do not allocate PCM2IN and MIC2 */
  2081. if (chip->spdif_idx < 0)
  2082. i--; /* do not allocate S/PDIF */
  2083. err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
  2084. if (err < 0)
  2085. goto __err;
  2086. chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
  2087. chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
  2088. chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
  2089. if (chip->spdif_idx >= 0)
  2090. chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
  2091. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2092. chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
  2093. chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
  2094. }
  2095. /* enable separate SDINs for ICH4 */
  2096. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2097. struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
  2098. u8 tmp = igetbyte(chip, ICHREG(SDM));
  2099. tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
  2100. if (pcm) {
  2101. tmp |= ICH_SE; /* steer enable for multiple SDINs */
  2102. tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
  2103. for (i = 1; i < 4; i++) {
  2104. if (pcm->r[0].codec[i]) {
  2105. tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
  2106. break;
  2107. }
  2108. }
  2109. } else {
  2110. tmp &= ~ICH_SE; /* steer disable */
  2111. }
  2112. iputbyte(chip, ICHREG(SDM), tmp);
  2113. }
  2114. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
  2115. chip->multi4 = 1;
  2116. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
  2117. chip->multi6 = 1;
  2118. if (chip->ac97[0]->flags & AC97_HAS_8CH)
  2119. chip->multi8 = 1;
  2120. }
  2121. }
  2122. if (pbus->pcms[0].r[1].rslots[0]) {
  2123. chip->dra = 1;
  2124. }
  2125. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2126. if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
  2127. chip->smp20bit = 1;
  2128. }
  2129. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2130. /* 48kHz only */
  2131. chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
  2132. }
  2133. if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
  2134. /* use slot 10/11 for SPDIF */
  2135. u32 val;
  2136. val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
  2137. val |= ICH_PCM_SPDIF_1011;
  2138. iputdword(chip, ICHREG(GLOB_CNT), val);
  2139. snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
  2140. }
  2141. chip->in_ac97_init = 0;
  2142. return 0;
  2143. __err:
  2144. /* clear the cold-reset bit for the next chance */
  2145. if (chip->device_type != DEVICE_ALI)
  2146. iputdword(chip, ICHREG(GLOB_CNT),
  2147. igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
  2148. return err;
  2149. }
  2150. /*
  2151. *
  2152. */
  2153. static void do_ali_reset(struct intel8x0 *chip)
  2154. {
  2155. iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
  2156. iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
  2157. iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
  2158. iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
  2159. iputdword(chip, ICHREG(ALI_INTERFACECR),
  2160. ICH_ALI_IF_PI|ICH_ALI_IF_PO);
  2161. iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
  2162. iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
  2163. }
  2164. #ifdef CONFIG_SND_AC97_POWER_SAVE
  2165. static struct snd_pci_quirk ich_chip_reset_mode[] = {
  2166. SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
  2167. { } /* end */
  2168. };
  2169. static int snd_intel8x0_ich_chip_cold_reset(struct intel8x0 *chip)
  2170. {
  2171. unsigned int cnt;
  2172. /* ACLink on, 2 channels */
  2173. if (snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
  2174. return -EIO;
  2175. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2176. cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
  2177. /* do cold reset - the full ac97 powerdown may leave the controller
  2178. * in a warm state but actually it cannot communicate with the codec.
  2179. */
  2180. iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_AC97COLD);
  2181. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2182. udelay(10);
  2183. iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD);
  2184. msleep(1);
  2185. return 0;
  2186. }
  2187. #define snd_intel8x0_ich_chip_can_cold_reset(chip) \
  2188. (!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
  2189. #else
  2190. #define snd_intel8x0_ich_chip_cold_reset(chip) 0
  2191. #define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
  2192. #endif
  2193. static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
  2194. {
  2195. unsigned long end_time;
  2196. unsigned int cnt;
  2197. /* ACLink on, 2 channels */
  2198. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2199. cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
  2200. /* finish cold or do warm reset */
  2201. cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  2202. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  2203. end_time = (jiffies + (HZ / 4)) + 1;
  2204. do {
  2205. if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
  2206. return 0;
  2207. schedule_timeout_uninterruptible(1);
  2208. } while (time_after_eq(end_time, jiffies));
  2209. dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
  2210. igetdword(chip, ICHREG(GLOB_CNT)));
  2211. return -EIO;
  2212. }
  2213. static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
  2214. {
  2215. unsigned long end_time;
  2216. unsigned int status, nstatus;
  2217. unsigned int cnt;
  2218. int err;
  2219. /* put logic to right state */
  2220. /* first clear status bits */
  2221. status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
  2222. if (chip->device_type == DEVICE_NFORCE)
  2223. status |= ICH_NVSPINT;
  2224. cnt = igetdword(chip, ICHREG(GLOB_STA));
  2225. iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  2226. if (snd_intel8x0_ich_chip_can_cold_reset(chip))
  2227. err = snd_intel8x0_ich_chip_cold_reset(chip);
  2228. else
  2229. err = snd_intel8x0_ich_chip_reset(chip);
  2230. if (err < 0)
  2231. return err;
  2232. if (probing) {
  2233. /* wait for any codec ready status.
  2234. * Once it becomes ready it should remain ready
  2235. * as long as we do not disable the ac97 link.
  2236. */
  2237. end_time = jiffies + HZ;
  2238. do {
  2239. status = igetdword(chip, ICHREG(GLOB_STA)) &
  2240. chip->codec_isr_bits;
  2241. if (status)
  2242. break;
  2243. schedule_timeout_uninterruptible(1);
  2244. } while (time_after_eq(end_time, jiffies));
  2245. if (! status) {
  2246. /* no codec is found */
  2247. dev_err(chip->card->dev,
  2248. "codec_ready: codec is not ready [0x%x]\n",
  2249. igetdword(chip, ICHREG(GLOB_STA)));
  2250. return -EIO;
  2251. }
  2252. /* wait for other codecs ready status. */
  2253. end_time = jiffies + HZ / 4;
  2254. while (status != chip->codec_isr_bits &&
  2255. time_after_eq(end_time, jiffies)) {
  2256. schedule_timeout_uninterruptible(1);
  2257. status |= igetdword(chip, ICHREG(GLOB_STA)) &
  2258. chip->codec_isr_bits;
  2259. }
  2260. } else {
  2261. /* resume phase */
  2262. int i;
  2263. status = 0;
  2264. for (i = 0; i < chip->ncodecs; i++)
  2265. if (chip->ac97[i])
  2266. status |= chip->codec_bit[chip->ac97_sdin[i]];
  2267. /* wait until all the probed codecs are ready */
  2268. end_time = jiffies + HZ;
  2269. do {
  2270. nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
  2271. chip->codec_isr_bits;
  2272. if (status == nstatus)
  2273. break;
  2274. schedule_timeout_uninterruptible(1);
  2275. } while (time_after_eq(end_time, jiffies));
  2276. }
  2277. if (chip->device_type == DEVICE_SIS) {
  2278. /* unmute the output on SIS7012 */
  2279. iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  2280. }
  2281. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2282. /* enable SPDIF interrupt */
  2283. unsigned int val;
  2284. pci_read_config_dword(chip->pci, 0x4c, &val);
  2285. val |= 0x1000000;
  2286. pci_write_config_dword(chip->pci, 0x4c, val);
  2287. }
  2288. return 0;
  2289. }
  2290. static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
  2291. {
  2292. u32 reg;
  2293. int i = 0;
  2294. reg = igetdword(chip, ICHREG(ALI_SCR));
  2295. if ((reg & 2) == 0) /* Cold required */
  2296. reg |= 2;
  2297. else
  2298. reg |= 1; /* Warm */
  2299. reg &= ~0x80000000; /* ACLink on */
  2300. iputdword(chip, ICHREG(ALI_SCR), reg);
  2301. for (i = 0; i < HZ / 2; i++) {
  2302. if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
  2303. goto __ok;
  2304. schedule_timeout_uninterruptible(1);
  2305. }
  2306. dev_err(chip->card->dev, "AC'97 reset failed.\n");
  2307. if (probing)
  2308. return -EIO;
  2309. __ok:
  2310. for (i = 0; i < HZ / 2; i++) {
  2311. reg = igetdword(chip, ICHREG(ALI_RTSR));
  2312. if (reg & 0x80) /* primary codec */
  2313. break;
  2314. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
  2315. schedule_timeout_uninterruptible(1);
  2316. }
  2317. do_ali_reset(chip);
  2318. return 0;
  2319. }
  2320. static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
  2321. {
  2322. unsigned int i, timeout;
  2323. int err;
  2324. if (chip->device_type != DEVICE_ALI) {
  2325. if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
  2326. return err;
  2327. iagetword(chip, 0); /* clear semaphore flag */
  2328. } else {
  2329. if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
  2330. return err;
  2331. }
  2332. /* disable interrupts */
  2333. for (i = 0; i < chip->bdbars_count; i++)
  2334. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2335. /* reset channels */
  2336. for (i = 0; i < chip->bdbars_count; i++)
  2337. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2338. for (i = 0; i < chip->bdbars_count; i++) {
  2339. timeout = 100000;
  2340. while (--timeout != 0) {
  2341. if ((igetbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset) & ICH_RESETREGS) == 0)
  2342. break;
  2343. }
  2344. if (timeout == 0)
  2345. dev_err(chip->card->dev, "reset of registers failed?\n");
  2346. }
  2347. /* initialize Buffer Descriptor Lists */
  2348. for (i = 0; i < chip->bdbars_count; i++)
  2349. iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset,
  2350. chip->ichd[i].bdbar_addr);
  2351. return 0;
  2352. }
  2353. static int snd_intel8x0_free(struct intel8x0 *chip)
  2354. {
  2355. unsigned int i;
  2356. if (chip->irq < 0)
  2357. goto __hw_end;
  2358. /* disable interrupts */
  2359. for (i = 0; i < chip->bdbars_count; i++)
  2360. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2361. /* reset channels */
  2362. for (i = 0; i < chip->bdbars_count; i++)
  2363. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2364. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2365. /* stop the spdif interrupt */
  2366. unsigned int val;
  2367. pci_read_config_dword(chip->pci, 0x4c, &val);
  2368. val &= ~0x1000000;
  2369. pci_write_config_dword(chip->pci, 0x4c, val);
  2370. }
  2371. /* --- */
  2372. __hw_end:
  2373. if (chip->irq >= 0)
  2374. free_irq(chip->irq, chip);
  2375. if (chip->bdbars.area)
  2376. snd_dma_free_pages(&chip->bdbars);
  2377. if (chip->addr)
  2378. pci_iounmap(chip->pci, chip->addr);
  2379. if (chip->bmaddr)
  2380. pci_iounmap(chip->pci, chip->bmaddr);
  2381. pci_release_regions(chip->pci);
  2382. pci_disable_device(chip->pci);
  2383. kfree(chip);
  2384. return 0;
  2385. }
  2386. #ifdef CONFIG_PM_SLEEP
  2387. /*
  2388. * power management
  2389. */
  2390. static int intel8x0_suspend(struct device *dev)
  2391. {
  2392. struct snd_card *card = dev_get_drvdata(dev);
  2393. struct intel8x0 *chip = card->private_data;
  2394. int i;
  2395. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  2396. for (i = 0; i < chip->pcm_devs; i++)
  2397. snd_pcm_suspend_all(chip->pcm[i]);
  2398. for (i = 0; i < chip->ncodecs; i++)
  2399. snd_ac97_suspend(chip->ac97[i]);
  2400. if (chip->device_type == DEVICE_INTEL_ICH4)
  2401. chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
  2402. if (chip->irq >= 0) {
  2403. free_irq(chip->irq, chip);
  2404. chip->irq = -1;
  2405. }
  2406. return 0;
  2407. }
  2408. static int intel8x0_resume(struct device *dev)
  2409. {
  2410. struct pci_dev *pci = to_pci_dev(dev);
  2411. struct snd_card *card = dev_get_drvdata(dev);
  2412. struct intel8x0 *chip = card->private_data;
  2413. int i;
  2414. snd_intel8x0_chip_init(chip, 0);
  2415. if (request_irq(pci->irq, snd_intel8x0_interrupt,
  2416. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  2417. dev_err(dev, "unable to grab IRQ %d, disabling device\n",
  2418. pci->irq);
  2419. snd_card_disconnect(card);
  2420. return -EIO;
  2421. }
  2422. chip->irq = pci->irq;
  2423. synchronize_irq(chip->irq);
  2424. /* re-initialize mixer stuff */
  2425. if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
  2426. /* enable separate SDINs for ICH4 */
  2427. iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
  2428. /* use slot 10/11 for SPDIF */
  2429. iputdword(chip, ICHREG(GLOB_CNT),
  2430. (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
  2431. ICH_PCM_SPDIF_1011);
  2432. }
  2433. for (i = 0; i < chip->ncodecs; i++)
  2434. snd_ac97_resume(chip->ac97[i]);
  2435. /* resume status */
  2436. for (i = 0; i < chip->bdbars_count; i++) {
  2437. struct ichdev *ichdev = &chip->ichd[i];
  2438. unsigned long port = ichdev->reg_offset;
  2439. if (! ichdev->substream || ! ichdev->suspended)
  2440. continue;
  2441. if (ichdev->ichd == ICHD_PCMOUT)
  2442. snd_intel8x0_setup_pcm_out(chip, ichdev->substream->runtime);
  2443. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  2444. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  2445. iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->civ);
  2446. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  2447. }
  2448. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  2449. return 0;
  2450. }
  2451. static SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume);
  2452. #define INTEL8X0_PM_OPS &intel8x0_pm
  2453. #else
  2454. #define INTEL8X0_PM_OPS NULL
  2455. #endif /* CONFIG_PM_SLEEP */
  2456. #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
  2457. static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
  2458. {
  2459. struct snd_pcm_substream *subs;
  2460. struct ichdev *ichdev;
  2461. unsigned long port;
  2462. unsigned long pos, pos1, t;
  2463. int civ, timeout = 1000, attempt = 1;
  2464. ktime_t start_time, stop_time;
  2465. if (chip->ac97_bus->clock != 48000)
  2466. return; /* specified in module option */
  2467. __again:
  2468. subs = chip->pcm[0]->streams[0].substream;
  2469. if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
  2470. dev_warn(chip->card->dev,
  2471. "no playback buffer allocated - aborting measure ac97 clock\n");
  2472. return;
  2473. }
  2474. ichdev = &chip->ichd[ICHD_PCMOUT];
  2475. ichdev->physbuf = subs->dma_buffer.addr;
  2476. ichdev->size = ichdev->fragsize = INTEL8X0_TESTBUF_SIZE;
  2477. ichdev->substream = NULL; /* don't process interrupts */
  2478. /* set rate */
  2479. if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
  2480. dev_err(chip->card->dev, "cannot set ac97 rate: clock = %d\n",
  2481. chip->ac97_bus->clock);
  2482. return;
  2483. }
  2484. snd_intel8x0_setup_periods(chip, ichdev);
  2485. port = ichdev->reg_offset;
  2486. spin_lock_irq(&chip->reg_lock);
  2487. chip->in_measurement = 1;
  2488. /* trigger */
  2489. if (chip->device_type != DEVICE_ALI)
  2490. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
  2491. else {
  2492. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  2493. iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
  2494. }
  2495. start_time = ktime_get();
  2496. spin_unlock_irq(&chip->reg_lock);
  2497. msleep(50);
  2498. spin_lock_irq(&chip->reg_lock);
  2499. /* check the position */
  2500. do {
  2501. civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  2502. pos1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  2503. if (pos1 == 0) {
  2504. udelay(10);
  2505. continue;
  2506. }
  2507. if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
  2508. pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  2509. break;
  2510. } while (timeout--);
  2511. if (pos1 == 0) { /* oops, this value is not reliable */
  2512. pos = 0;
  2513. } else {
  2514. pos = ichdev->fragsize1;
  2515. pos -= pos1 << ichdev->pos_shift;
  2516. pos += ichdev->position;
  2517. }
  2518. chip->in_measurement = 0;
  2519. stop_time = ktime_get();
  2520. /* stop */
  2521. if (chip->device_type == DEVICE_ALI) {
  2522. iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
  2523. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2524. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  2525. ;
  2526. } else {
  2527. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2528. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
  2529. ;
  2530. }
  2531. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  2532. spin_unlock_irq(&chip->reg_lock);
  2533. if (pos == 0) {
  2534. dev_err(chip->card->dev,
  2535. "measure - unreliable DMA position..\n");
  2536. __retry:
  2537. if (attempt < 3) {
  2538. msleep(300);
  2539. attempt++;
  2540. goto __again;
  2541. }
  2542. goto __end;
  2543. }
  2544. pos /= 4;
  2545. t = ktime_us_delta(stop_time, start_time);
  2546. dev_info(chip->card->dev,
  2547. "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
  2548. if (t == 0) {
  2549. dev_err(chip->card->dev, "?? calculation error..\n");
  2550. goto __retry;
  2551. }
  2552. pos *= 1000;
  2553. pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
  2554. if (pos < 40000 || pos >= 60000) {
  2555. /* abnormal value. hw problem? */
  2556. dev_info(chip->card->dev, "measured clock %ld rejected\n", pos);
  2557. goto __retry;
  2558. } else if (pos > 40500 && pos < 41500)
  2559. /* first exception - 41000Hz reference clock */
  2560. chip->ac97_bus->clock = 41000;
  2561. else if (pos > 43600 && pos < 44600)
  2562. /* second exception - 44100HZ reference clock */
  2563. chip->ac97_bus->clock = 44100;
  2564. else if (pos < 47500 || pos > 48500)
  2565. /* not 48000Hz, tuning the clock.. */
  2566. chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
  2567. __end:
  2568. dev_info(chip->card->dev, "clocking to %d\n", chip->ac97_bus->clock);
  2569. snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
  2570. }
  2571. static struct snd_pci_quirk intel8x0_clock_list[] = {
  2572. SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
  2573. SND_PCI_QUIRK(0x1014, 0x0581, "AD1981B", 48000),
  2574. SND_PCI_QUIRK(0x1028, 0x00be, "AD1885", 44100),
  2575. SND_PCI_QUIRK(0x1028, 0x0177, "AD1980", 48000),
  2576. SND_PCI_QUIRK(0x1028, 0x01ad, "AD1981B", 48000),
  2577. SND_PCI_QUIRK(0x1043, 0x80f3, "AD1985", 48000),
  2578. { } /* terminator */
  2579. };
  2580. static int intel8x0_in_clock_list(struct intel8x0 *chip)
  2581. {
  2582. struct pci_dev *pci = chip->pci;
  2583. const struct snd_pci_quirk *wl;
  2584. wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
  2585. if (!wl)
  2586. return 0;
  2587. dev_info(chip->card->dev, "white list rate for %04x:%04x is %i\n",
  2588. pci->subsystem_vendor, pci->subsystem_device, wl->value);
  2589. chip->ac97_bus->clock = wl->value;
  2590. return 1;
  2591. }
  2592. static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
  2593. struct snd_info_buffer *buffer)
  2594. {
  2595. struct intel8x0 *chip = entry->private_data;
  2596. unsigned int tmp;
  2597. snd_iprintf(buffer, "Intel8x0\n\n");
  2598. if (chip->device_type == DEVICE_ALI)
  2599. return;
  2600. tmp = igetdword(chip, ICHREG(GLOB_STA));
  2601. snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
  2602. snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
  2603. if (chip->device_type == DEVICE_INTEL_ICH4)
  2604. snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
  2605. snd_iprintf(buffer, "AC'97 codecs ready :");
  2606. if (tmp & chip->codec_isr_bits) {
  2607. int i;
  2608. static const char *codecs[3] = {
  2609. "primary", "secondary", "tertiary"
  2610. };
  2611. for (i = 0; i < chip->max_codecs; i++)
  2612. if (tmp & chip->codec_bit[i])
  2613. snd_iprintf(buffer, " %s", codecs[i]);
  2614. } else
  2615. snd_iprintf(buffer, " none");
  2616. snd_iprintf(buffer, "\n");
  2617. if (chip->device_type == DEVICE_INTEL_ICH4 ||
  2618. chip->device_type == DEVICE_SIS)
  2619. snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
  2620. chip->ac97_sdin[0],
  2621. chip->ac97_sdin[1],
  2622. chip->ac97_sdin[2]);
  2623. }
  2624. static void snd_intel8x0_proc_init(struct intel8x0 *chip)
  2625. {
  2626. struct snd_info_entry *entry;
  2627. if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
  2628. snd_info_set_text_ops(entry, chip, snd_intel8x0_proc_read);
  2629. }
  2630. static int snd_intel8x0_dev_free(struct snd_device *device)
  2631. {
  2632. struct intel8x0 *chip = device->device_data;
  2633. return snd_intel8x0_free(chip);
  2634. }
  2635. struct ich_reg_info {
  2636. unsigned int int_sta_mask;
  2637. unsigned int offset;
  2638. };
  2639. static unsigned int ich_codec_bits[3] = {
  2640. ICH_PCR, ICH_SCR, ICH_TCR
  2641. };
  2642. static unsigned int sis_codec_bits[3] = {
  2643. ICH_PCR, ICH_SCR, ICH_SIS_TCR
  2644. };
  2645. static int snd_intel8x0_inside_vm(struct pci_dev *pci)
  2646. {
  2647. int result = inside_vm;
  2648. char *msg = NULL;
  2649. /* check module parameter first (override detection) */
  2650. if (result >= 0) {
  2651. msg = result ? "enable (forced) VM" : "disable (forced) VM";
  2652. goto fini;
  2653. }
  2654. /* check for known (emulated) devices */
  2655. result = 0;
  2656. if (pci->subsystem_vendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
  2657. pci->subsystem_device == PCI_SUBDEVICE_ID_QEMU) {
  2658. /* KVM emulated sound, PCI SSID: 1af4:1100 */
  2659. msg = "enable KVM";
  2660. result = 1;
  2661. } else if (pci->subsystem_vendor == 0x1ab8) {
  2662. /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */
  2663. msg = "enable Parallels VM";
  2664. result = 1;
  2665. }
  2666. fini:
  2667. if (msg != NULL)
  2668. dev_info(&pci->dev, "%s optimization\n", msg);
  2669. return result;
  2670. }
  2671. static int snd_intel8x0_create(struct snd_card *card,
  2672. struct pci_dev *pci,
  2673. unsigned long device_type,
  2674. struct intel8x0 **r_intel8x0)
  2675. {
  2676. struct intel8x0 *chip;
  2677. int err;
  2678. unsigned int i;
  2679. unsigned int int_sta_masks;
  2680. struct ichdev *ichdev;
  2681. static struct snd_device_ops ops = {
  2682. .dev_free = snd_intel8x0_dev_free,
  2683. };
  2684. static unsigned int bdbars[] = {
  2685. 3, /* DEVICE_INTEL */
  2686. 6, /* DEVICE_INTEL_ICH4 */
  2687. 3, /* DEVICE_SIS */
  2688. 6, /* DEVICE_ALI */
  2689. 4, /* DEVICE_NFORCE */
  2690. };
  2691. static struct ich_reg_info intel_regs[6] = {
  2692. { ICH_PIINT, 0 },
  2693. { ICH_POINT, 0x10 },
  2694. { ICH_MCINT, 0x20 },
  2695. { ICH_M2INT, 0x40 },
  2696. { ICH_P2INT, 0x50 },
  2697. { ICH_SPINT, 0x60 },
  2698. };
  2699. static struct ich_reg_info nforce_regs[4] = {
  2700. { ICH_PIINT, 0 },
  2701. { ICH_POINT, 0x10 },
  2702. { ICH_MCINT, 0x20 },
  2703. { ICH_NVSPINT, 0x70 },
  2704. };
  2705. static struct ich_reg_info ali_regs[6] = {
  2706. { ALI_INT_PCMIN, 0x40 },
  2707. { ALI_INT_PCMOUT, 0x50 },
  2708. { ALI_INT_MICIN, 0x60 },
  2709. { ALI_INT_CODECSPDIFOUT, 0x70 },
  2710. { ALI_INT_SPDIFIN, 0xa0 },
  2711. { ALI_INT_SPDIFOUT, 0xb0 },
  2712. };
  2713. struct ich_reg_info *tbl;
  2714. *r_intel8x0 = NULL;
  2715. if ((err = pci_enable_device(pci)) < 0)
  2716. return err;
  2717. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2718. if (chip == NULL) {
  2719. pci_disable_device(pci);
  2720. return -ENOMEM;
  2721. }
  2722. spin_lock_init(&chip->reg_lock);
  2723. chip->device_type = device_type;
  2724. chip->card = card;
  2725. chip->pci = pci;
  2726. chip->irq = -1;
  2727. /* module parameters */
  2728. chip->buggy_irq = buggy_irq;
  2729. chip->buggy_semaphore = buggy_semaphore;
  2730. if (xbox)
  2731. chip->xbox = 1;
  2732. chip->inside_vm = snd_intel8x0_inside_vm(pci);
  2733. /*
  2734. * Intel 82443MX running a 100MHz processor system bus has a hardware
  2735. * bug, which aborts PCI busmaster for audio transfer. A workaround
  2736. * is to set the pages as non-cached. For details, see the errata in
  2737. * http://download.intel.com/design/chipsets/specupdt/24505108.pdf
  2738. */
  2739. if (pci->vendor == PCI_VENDOR_ID_INTEL &&
  2740. pci->device == PCI_DEVICE_ID_INTEL_440MX)
  2741. chip->fix_nocache = 1; /* enable workaround */
  2742. if ((err = pci_request_regions(pci, card->shortname)) < 0) {
  2743. kfree(chip);
  2744. pci_disable_device(pci);
  2745. return err;
  2746. }
  2747. if (device_type == DEVICE_ALI) {
  2748. /* ALI5455 has no ac97 region */
  2749. chip->bmaddr = pci_iomap(pci, 0, 0);
  2750. goto port_inited;
  2751. }
  2752. if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
  2753. chip->addr = pci_iomap(pci, 2, 0);
  2754. else
  2755. chip->addr = pci_iomap(pci, 0, 0);
  2756. if (!chip->addr) {
  2757. dev_err(card->dev, "AC'97 space ioremap problem\n");
  2758. snd_intel8x0_free(chip);
  2759. return -EIO;
  2760. }
  2761. if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
  2762. chip->bmaddr = pci_iomap(pci, 3, 0);
  2763. else
  2764. chip->bmaddr = pci_iomap(pci, 1, 0);
  2765. port_inited:
  2766. if (!chip->bmaddr) {
  2767. dev_err(card->dev, "Controller space ioremap problem\n");
  2768. snd_intel8x0_free(chip);
  2769. return -EIO;
  2770. }
  2771. chip->bdbars_count = bdbars[device_type];
  2772. /* initialize offsets */
  2773. switch (device_type) {
  2774. case DEVICE_NFORCE:
  2775. tbl = nforce_regs;
  2776. break;
  2777. case DEVICE_ALI:
  2778. tbl = ali_regs;
  2779. break;
  2780. default:
  2781. tbl = intel_regs;
  2782. break;
  2783. }
  2784. for (i = 0; i < chip->bdbars_count; i++) {
  2785. ichdev = &chip->ichd[i];
  2786. ichdev->ichd = i;
  2787. ichdev->reg_offset = tbl[i].offset;
  2788. ichdev->int_sta_mask = tbl[i].int_sta_mask;
  2789. if (device_type == DEVICE_SIS) {
  2790. /* SiS 7012 swaps the registers */
  2791. ichdev->roff_sr = ICH_REG_OFF_PICB;
  2792. ichdev->roff_picb = ICH_REG_OFF_SR;
  2793. } else {
  2794. ichdev->roff_sr = ICH_REG_OFF_SR;
  2795. ichdev->roff_picb = ICH_REG_OFF_PICB;
  2796. }
  2797. if (device_type == DEVICE_ALI)
  2798. ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  2799. /* SIS7012 handles the pcm data in bytes, others are in samples */
  2800. ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  2801. }
  2802. /* allocate buffer descriptor lists */
  2803. /* the start of each lists must be aligned to 8 bytes */
  2804. if (snd_dma_alloc_pages(intel8x0_dma_type(chip), snd_dma_pci_data(pci),
  2805. chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
  2806. &chip->bdbars) < 0) {
  2807. snd_intel8x0_free(chip);
  2808. dev_err(card->dev, "cannot allocate buffer descriptors\n");
  2809. return -ENOMEM;
  2810. }
  2811. /* tables must be aligned to 8 bytes here, but the kernel pages
  2812. are much bigger, so we don't care (on i386) */
  2813. int_sta_masks = 0;
  2814. for (i = 0; i < chip->bdbars_count; i++) {
  2815. ichdev = &chip->ichd[i];
  2816. ichdev->bdbar = ((__le32 *)chip->bdbars.area) +
  2817. (i * ICH_MAX_FRAGS * 2);
  2818. ichdev->bdbar_addr = chip->bdbars.addr +
  2819. (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
  2820. int_sta_masks |= ichdev->int_sta_mask;
  2821. }
  2822. chip->int_sta_reg = device_type == DEVICE_ALI ?
  2823. ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
  2824. chip->int_sta_mask = int_sta_masks;
  2825. pci_set_master(pci);
  2826. switch(chip->device_type) {
  2827. case DEVICE_INTEL_ICH4:
  2828. /* ICH4 can have three codecs */
  2829. chip->max_codecs = 3;
  2830. chip->codec_bit = ich_codec_bits;
  2831. chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_TRI;
  2832. break;
  2833. case DEVICE_SIS:
  2834. /* recent SIS7012 can have three codecs */
  2835. chip->max_codecs = 3;
  2836. chip->codec_bit = sis_codec_bits;
  2837. chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_SIS_TRI;
  2838. break;
  2839. default:
  2840. /* others up to two codecs */
  2841. chip->max_codecs = 2;
  2842. chip->codec_bit = ich_codec_bits;
  2843. chip->codec_ready_bits = ICH_PRI | ICH_SRI;
  2844. break;
  2845. }
  2846. for (i = 0; i < chip->max_codecs; i++)
  2847. chip->codec_isr_bits |= chip->codec_bit[i];
  2848. if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
  2849. snd_intel8x0_free(chip);
  2850. return err;
  2851. }
  2852. /* request irq after initializaing int_sta_mask, etc */
  2853. if (request_irq(pci->irq, snd_intel8x0_interrupt,
  2854. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  2855. dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
  2856. snd_intel8x0_free(chip);
  2857. return -EBUSY;
  2858. }
  2859. chip->irq = pci->irq;
  2860. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  2861. snd_intel8x0_free(chip);
  2862. return err;
  2863. }
  2864. *r_intel8x0 = chip;
  2865. return 0;
  2866. }
  2867. static struct shortname_table {
  2868. unsigned int id;
  2869. const char *s;
  2870. } shortnames[] = {
  2871. { PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
  2872. { PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
  2873. { PCI_DEVICE_ID_INTEL_82801BA_4, "Intel 82801BA-ICH2" },
  2874. { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
  2875. { PCI_DEVICE_ID_INTEL_82801CA_5, "Intel 82801CA-ICH3" },
  2876. { PCI_DEVICE_ID_INTEL_82801DB_5, "Intel 82801DB-ICH4" },
  2877. { PCI_DEVICE_ID_INTEL_82801EB_5, "Intel ICH5" },
  2878. { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
  2879. { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
  2880. { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
  2881. { PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
  2882. { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
  2883. { PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO, "NVidia nForce" },
  2884. { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
  2885. { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
  2886. { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
  2887. { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
  2888. { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
  2889. { 0x003a, "NVidia MCP04" },
  2890. { 0x746d, "AMD AMD8111" },
  2891. { 0x7445, "AMD AMD768" },
  2892. { 0x5455, "ALi M5455" },
  2893. { 0, NULL },
  2894. };
  2895. static struct snd_pci_quirk spdif_aclink_defaults[] = {
  2896. SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
  2897. { } /* end */
  2898. };
  2899. /* look up white/black list for SPDIF over ac-link */
  2900. static int check_default_spdif_aclink(struct pci_dev *pci)
  2901. {
  2902. const struct snd_pci_quirk *w;
  2903. w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
  2904. if (w) {
  2905. if (w->value)
  2906. dev_dbg(&pci->dev,
  2907. "Using SPDIF over AC-Link for %s\n",
  2908. snd_pci_quirk_name(w));
  2909. else
  2910. dev_dbg(&pci->dev,
  2911. "Using integrated SPDIF DMA for %s\n",
  2912. snd_pci_quirk_name(w));
  2913. return w->value;
  2914. }
  2915. return 0;
  2916. }
  2917. static int snd_intel8x0_probe(struct pci_dev *pci,
  2918. const struct pci_device_id *pci_id)
  2919. {
  2920. struct snd_card *card;
  2921. struct intel8x0 *chip;
  2922. int err;
  2923. struct shortname_table *name;
  2924. err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
  2925. if (err < 0)
  2926. return err;
  2927. if (spdif_aclink < 0)
  2928. spdif_aclink = check_default_spdif_aclink(pci);
  2929. strcpy(card->driver, "ICH");
  2930. if (!spdif_aclink) {
  2931. switch (pci_id->driver_data) {
  2932. case DEVICE_NFORCE:
  2933. strcpy(card->driver, "NFORCE");
  2934. break;
  2935. case DEVICE_INTEL_ICH4:
  2936. strcpy(card->driver, "ICH4");
  2937. }
  2938. }
  2939. strcpy(card->shortname, "Intel ICH");
  2940. for (name = shortnames; name->id; name++) {
  2941. if (pci->device == name->id) {
  2942. strcpy(card->shortname, name->s);
  2943. break;
  2944. }
  2945. }
  2946. if (buggy_irq < 0) {
  2947. /* some Nforce[2] and ICH boards have problems with IRQ handling.
  2948. * Needs to return IRQ_HANDLED for unknown irqs.
  2949. */
  2950. if (pci_id->driver_data == DEVICE_NFORCE)
  2951. buggy_irq = 1;
  2952. else
  2953. buggy_irq = 0;
  2954. }
  2955. if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
  2956. &chip)) < 0) {
  2957. snd_card_free(card);
  2958. return err;
  2959. }
  2960. card->private_data = chip;
  2961. if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) {
  2962. snd_card_free(card);
  2963. return err;
  2964. }
  2965. if ((err = snd_intel8x0_pcm(chip)) < 0) {
  2966. snd_card_free(card);
  2967. return err;
  2968. }
  2969. snd_intel8x0_proc_init(chip);
  2970. snprintf(card->longname, sizeof(card->longname),
  2971. "%s with %s at irq %i", card->shortname,
  2972. snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
  2973. if (ac97_clock == 0 || ac97_clock == 1) {
  2974. if (ac97_clock == 0) {
  2975. if (intel8x0_in_clock_list(chip) == 0)
  2976. intel8x0_measure_ac97_clock(chip);
  2977. } else {
  2978. intel8x0_measure_ac97_clock(chip);
  2979. }
  2980. }
  2981. if ((err = snd_card_register(card)) < 0) {
  2982. snd_card_free(card);
  2983. return err;
  2984. }
  2985. pci_set_drvdata(pci, card);
  2986. return 0;
  2987. }
  2988. static void snd_intel8x0_remove(struct pci_dev *pci)
  2989. {
  2990. snd_card_free(pci_get_drvdata(pci));
  2991. }
  2992. static struct pci_driver intel8x0_driver = {
  2993. .name = KBUILD_MODNAME,
  2994. .id_table = snd_intel8x0_ids,
  2995. .probe = snd_intel8x0_probe,
  2996. .remove = snd_intel8x0_remove,
  2997. .driver = {
  2998. .pm = INTEL8X0_PM_OPS,
  2999. },
  3000. };
  3001. module_pci_driver(intel8x0_driver);