intel8x0.c 89 KB

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