intel8x0.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952
  1. /*
  2. * ALSA driver for Intel ICH (i8x0) chipsets
  3. *
  4. * Copyright (c) 2000 Jaroslav Kysela <perex@suse.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 <sound/driver.h>
  28. #include <asm/io.h>
  29. #include <linux/delay.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/init.h>
  32. #include <linux/pci.h>
  33. #include <linux/slab.h>
  34. #include <linux/moduleparam.h>
  35. #include <sound/core.h>
  36. #include <sound/pcm.h>
  37. #include <sound/ac97_codec.h>
  38. #include <sound/info.h>
  39. #include <sound/initval.h>
  40. /* for 440MX workaround */
  41. #include <asm/pgtable.h>
  42. #include <asm/cacheflush.h>
  43. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  44. MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
  45. MODULE_LICENSE("GPL");
  46. MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
  47. "{Intel,82901AB-ICH0},"
  48. "{Intel,82801BA-ICH2},"
  49. "{Intel,82801CA-ICH3},"
  50. "{Intel,82801DB-ICH4},"
  51. "{Intel,ICH5},"
  52. "{Intel,ICH6},"
  53. "{Intel,ICH7},"
  54. "{Intel,6300ESB},"
  55. "{Intel,ESB2},"
  56. "{Intel,MX440},"
  57. "{SiS,SI7012},"
  58. "{NVidia,nForce Audio},"
  59. "{NVidia,nForce2 Audio},"
  60. "{AMD,AMD768},"
  61. "{AMD,AMD8111},"
  62. "{ALI,M5455}}");
  63. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  64. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  65. static int ac97_clock = 0;
  66. static char *ac97_quirk;
  67. static int buggy_semaphore;
  68. static int buggy_irq = -1; /* auto-check */
  69. static int xbox;
  70. module_param(index, int, 0444);
  71. MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
  72. module_param(id, charp, 0444);
  73. MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
  74. module_param(ac97_clock, int, 0444);
  75. MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
  76. module_param(ac97_quirk, charp, 0444);
  77. MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
  78. module_param(buggy_semaphore, bool, 0444);
  79. MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
  80. module_param(buggy_irq, bool, 0444);
  81. MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
  82. module_param(xbox, bool, 0444);
  83. MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
  84. /* just for backward compatibility */
  85. static int enable;
  86. module_param(enable, bool, 0444);
  87. static int joystick;
  88. module_param(joystick, int, 0444);
  89. /*
  90. * Direct registers
  91. */
  92. enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
  93. #define ICHREG(x) ICH_REG_##x
  94. #define DEFINE_REGSET(name,base) \
  95. enum { \
  96. ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
  97. ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
  98. ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
  99. ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
  100. ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
  101. ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
  102. ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
  103. };
  104. /* busmaster blocks */
  105. DEFINE_REGSET(OFF, 0); /* offset */
  106. DEFINE_REGSET(PI, 0x00); /* PCM in */
  107. DEFINE_REGSET(PO, 0x10); /* PCM out */
  108. DEFINE_REGSET(MC, 0x20); /* Mic in */
  109. /* ICH4 busmaster blocks */
  110. DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
  111. DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
  112. DEFINE_REGSET(SP, 0x60); /* SPDIF out */
  113. /* values for each busmaster block */
  114. /* LVI */
  115. #define ICH_REG_LVI_MASK 0x1f
  116. /* SR */
  117. #define ICH_FIFOE 0x10 /* FIFO error */
  118. #define ICH_BCIS 0x08 /* buffer completion interrupt status */
  119. #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
  120. #define ICH_CELV 0x02 /* current equals last valid */
  121. #define ICH_DCH 0x01 /* DMA controller halted */
  122. /* PIV */
  123. #define ICH_REG_PIV_MASK 0x1f /* mask */
  124. /* CR */
  125. #define ICH_IOCE 0x10 /* interrupt on completion enable */
  126. #define ICH_FEIE 0x08 /* fifo error interrupt enable */
  127. #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
  128. #define ICH_RESETREGS 0x02 /* reset busmaster registers */
  129. #define ICH_STARTBM 0x01 /* start busmaster operation */
  130. /* global block */
  131. #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
  132. #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
  133. #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
  134. #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
  135. #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
  136. #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
  137. #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
  138. #define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */
  139. #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
  140. #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
  141. #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
  142. #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
  143. #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
  144. #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
  145. #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
  146. #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
  147. #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
  148. #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
  149. #define ICH_ACLINK 0x00000008 /* AClink shut off */
  150. #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
  151. #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
  152. #define ICH_GIE 0x00000001 /* GPI interrupt enable */
  153. #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
  154. #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
  155. #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
  156. #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
  157. #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
  158. #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
  159. #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
  160. #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
  161. #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
  162. #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
  163. #define ICH_MD3 0x00020000 /* modem power down semaphore */
  164. #define ICH_AD3 0x00010000 /* audio power down semaphore */
  165. #define ICH_RCS 0x00008000 /* read completion status */
  166. #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
  167. #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
  168. #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
  169. #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
  170. #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
  171. #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
  172. #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
  173. #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
  174. #define ICH_POINT 0x00000040 /* playback interrupt */
  175. #define ICH_PIINT 0x00000020 /* capture interrupt */
  176. #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
  177. #define ICH_MOINT 0x00000004 /* modem playback interrupt */
  178. #define ICH_MIINT 0x00000002 /* modem capture interrupt */
  179. #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
  180. #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
  181. #define ICH_CAS 0x01 /* codec access semaphore */
  182. #define ICH_REG_SDM 0x80
  183. #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
  184. #define ICH_DI2L_SHIFT 6
  185. #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
  186. #define ICH_DI1L_SHIFT 4
  187. #define ICH_SE 0x00000008 /* steer enable */
  188. #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
  189. #define ICH_MAX_FRAGS 32 /* max hw frags */
  190. /*
  191. * registers for Ali5455
  192. */
  193. /* ALi 5455 busmaster blocks */
  194. DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
  195. DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
  196. DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
  197. DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
  198. DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
  199. DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
  200. DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
  201. DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
  202. DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
  203. DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
  204. DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
  205. enum {
  206. ICH_REG_ALI_SCR = 0x00, /* System Control Register */
  207. ICH_REG_ALI_SSR = 0x04, /* System Status Register */
  208. ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
  209. ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
  210. ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
  211. ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
  212. ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
  213. ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
  214. ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
  215. ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
  216. ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
  217. ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
  218. ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
  219. ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
  220. ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
  221. ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
  222. ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
  223. ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
  224. ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
  225. ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
  226. ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
  227. };
  228. #define ALI_CAS_SEM_BUSY 0x80000000
  229. #define ALI_CPR_ADDR_SECONDARY 0x100
  230. #define ALI_CPR_ADDR_READ 0x80
  231. #define ALI_CSPSR_CODEC_READY 0x08
  232. #define ALI_CSPSR_READ_OK 0x02
  233. #define ALI_CSPSR_WRITE_OK 0x01
  234. /* interrupts for the whole chip by interrupt status register finish */
  235. #define ALI_INT_MICIN2 (1<<26)
  236. #define ALI_INT_PCMIN2 (1<<25)
  237. #define ALI_INT_I2SIN (1<<24)
  238. #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
  239. #define ALI_INT_SPDIFIN (1<<22)
  240. #define ALI_INT_LFEOUT (1<<21)
  241. #define ALI_INT_CENTEROUT (1<<20)
  242. #define ALI_INT_CODECSPDIFOUT (1<<19)
  243. #define ALI_INT_MICIN (1<<18)
  244. #define ALI_INT_PCMOUT (1<<17)
  245. #define ALI_INT_PCMIN (1<<16)
  246. #define ALI_INT_CPRAIS (1<<7) /* command port available */
  247. #define ALI_INT_SPRAIS (1<<5) /* status port available */
  248. #define ALI_INT_GPIO (1<<1)
  249. #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|\
  250. ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
  251. #define ICH_ALI_SC_RESET (1<<31) /* master reset */
  252. #define ICH_ALI_SC_AC97_DBL (1<<30)
  253. #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
  254. #define ICH_ALI_SC_IN_BITS (3<<18)
  255. #define ICH_ALI_SC_OUT_BITS (3<<16)
  256. #define ICH_ALI_SC_6CH_CFG (3<<14)
  257. #define ICH_ALI_SC_PCM_4 (1<<8)
  258. #define ICH_ALI_SC_PCM_6 (2<<8)
  259. #define ICH_ALI_SC_PCM_246_MASK (3<<8)
  260. #define ICH_ALI_SS_SEC_ID (3<<5)
  261. #define ICH_ALI_SS_PRI_ID (3<<3)
  262. #define ICH_ALI_IF_AC97SP (1<<21)
  263. #define ICH_ALI_IF_MC (1<<20)
  264. #define ICH_ALI_IF_PI (1<<19)
  265. #define ICH_ALI_IF_MC2 (1<<18)
  266. #define ICH_ALI_IF_PI2 (1<<17)
  267. #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
  268. #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
  269. #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
  270. #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
  271. #define ICH_ALI_IF_PO_SPDF (1<<3)
  272. #define ICH_ALI_IF_PO (1<<1)
  273. /*
  274. *
  275. */
  276. enum {
  277. ICHD_PCMIN,
  278. ICHD_PCMOUT,
  279. ICHD_MIC,
  280. ICHD_MIC2,
  281. ICHD_PCM2IN,
  282. ICHD_SPBAR,
  283. ICHD_LAST = ICHD_SPBAR
  284. };
  285. enum {
  286. NVD_PCMIN,
  287. NVD_PCMOUT,
  288. NVD_MIC,
  289. NVD_SPBAR,
  290. NVD_LAST = NVD_SPBAR
  291. };
  292. enum {
  293. ALID_PCMIN,
  294. ALID_PCMOUT,
  295. ALID_MIC,
  296. ALID_AC97SPDIFOUT,
  297. ALID_SPDIFIN,
  298. ALID_SPDIFOUT,
  299. ALID_LAST = ALID_SPDIFOUT
  300. };
  301. #define get_ichdev(substream) (substream->runtime->private_data)
  302. struct ichdev {
  303. unsigned int ichd; /* ich device number */
  304. unsigned long reg_offset; /* offset to bmaddr */
  305. u32 *bdbar; /* CPU address (32bit) */
  306. unsigned int bdbar_addr; /* PCI bus address (32bit) */
  307. struct snd_pcm_substream *substream;
  308. unsigned int physbuf; /* physical address (32bit) */
  309. unsigned int size;
  310. unsigned int fragsize;
  311. unsigned int fragsize1;
  312. unsigned int position;
  313. unsigned int pos_shift;
  314. int frags;
  315. int lvi;
  316. int lvi_frag;
  317. int civ;
  318. int ack;
  319. int ack_reload;
  320. unsigned int ack_bit;
  321. unsigned int roff_sr;
  322. unsigned int roff_picb;
  323. unsigned int int_sta_mask; /* interrupt status mask */
  324. unsigned int ali_slot; /* ALI DMA slot */
  325. struct ac97_pcm *pcm;
  326. int pcm_open_flag;
  327. unsigned int page_attr_changed: 1;
  328. unsigned int suspended: 1;
  329. };
  330. struct intel8x0 {
  331. unsigned int device_type;
  332. int irq;
  333. unsigned int mmio;
  334. unsigned long addr;
  335. void __iomem *remap_addr;
  336. unsigned int bm_mmio;
  337. unsigned long bmaddr;
  338. void __iomem *remap_bmaddr;
  339. struct pci_dev *pci;
  340. struct snd_card *card;
  341. int pcm_devs;
  342. struct snd_pcm *pcm[6];
  343. struct ichdev ichd[6];
  344. unsigned multi4: 1,
  345. multi6: 1,
  346. dra: 1,
  347. smp20bit: 1;
  348. unsigned in_ac97_init: 1,
  349. in_sdin_init: 1;
  350. unsigned in_measurement: 1; /* during ac97 clock measurement */
  351. unsigned fix_nocache: 1; /* workaround for 440MX */
  352. unsigned buggy_irq: 1; /* workaround for buggy mobos */
  353. unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
  354. unsigned buggy_semaphore: 1; /* workaround for buggy codec semaphore */
  355. int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
  356. unsigned int sdm_saved; /* SDM reg value */
  357. struct snd_ac97_bus *ac97_bus;
  358. struct snd_ac97 *ac97[3];
  359. unsigned int ac97_sdin[3];
  360. spinlock_t reg_lock;
  361. u32 bdbars_count;
  362. struct snd_dma_buffer bdbars;
  363. u32 int_sta_reg; /* interrupt status register */
  364. u32 int_sta_mask; /* interrupt status mask */
  365. };
  366. static struct pci_device_id snd_intel8x0_ids[] = {
  367. { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */
  368. { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */
  369. { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */
  370. { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */
  371. { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */
  372. { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */
  373. { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */
  374. { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */
  375. { 0x8086, 0x27de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH7 */
  376. { 0x8086, 0x2698, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB2 */
  377. { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */
  378. { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */
  379. { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */
  380. { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */
  381. { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */
  382. { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */
  383. { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */
  384. { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */
  385. { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */
  386. { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
  387. { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
  388. { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
  389. { 0, }
  390. };
  391. MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
  392. /*
  393. * Lowlevel I/O - busmaster
  394. */
  395. static u8 igetbyte(struct intel8x0 *chip, u32 offset)
  396. {
  397. if (chip->bm_mmio)
  398. return readb(chip->remap_bmaddr + offset);
  399. else
  400. return inb(chip->bmaddr + offset);
  401. }
  402. static u16 igetword(struct intel8x0 *chip, u32 offset)
  403. {
  404. if (chip->bm_mmio)
  405. return readw(chip->remap_bmaddr + offset);
  406. else
  407. return inw(chip->bmaddr + offset);
  408. }
  409. static u32 igetdword(struct intel8x0 *chip, u32 offset)
  410. {
  411. if (chip->bm_mmio)
  412. return readl(chip->remap_bmaddr + offset);
  413. else
  414. return inl(chip->bmaddr + offset);
  415. }
  416. static void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
  417. {
  418. if (chip->bm_mmio)
  419. writeb(val, chip->remap_bmaddr + offset);
  420. else
  421. outb(val, chip->bmaddr + offset);
  422. }
  423. static void iputword(struct intel8x0 *chip, u32 offset, u16 val)
  424. {
  425. if (chip->bm_mmio)
  426. writew(val, chip->remap_bmaddr + offset);
  427. else
  428. outw(val, chip->bmaddr + offset);
  429. }
  430. static void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
  431. {
  432. if (chip->bm_mmio)
  433. writel(val, chip->remap_bmaddr + offset);
  434. else
  435. outl(val, chip->bmaddr + offset);
  436. }
  437. /*
  438. * Lowlevel I/O - AC'97 registers
  439. */
  440. static u16 iagetword(struct intel8x0 *chip, u32 offset)
  441. {
  442. if (chip->mmio)
  443. return readw(chip->remap_addr + offset);
  444. else
  445. return inw(chip->addr + offset);
  446. }
  447. static void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
  448. {
  449. if (chip->mmio)
  450. writew(val, chip->remap_addr + offset);
  451. else
  452. outw(val, chip->addr + offset);
  453. }
  454. /*
  455. * Basic I/O
  456. */
  457. /*
  458. * access to AC97 codec via normal i/o (for ICH and SIS7012)
  459. */
  460. /* return the GLOB_STA bit for the corresponding codec */
  461. static unsigned int get_ich_codec_bit(struct intel8x0 *chip, unsigned int codec)
  462. {
  463. static unsigned int codec_bit[3] = {
  464. ICH_PCR, ICH_SCR, ICH_TCR
  465. };
  466. snd_assert(codec < 3, return ICH_PCR);
  467. if (chip->device_type == DEVICE_INTEL_ICH4)
  468. codec = chip->ac97_sdin[codec];
  469. return codec_bit[codec];
  470. }
  471. static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int codec)
  472. {
  473. int time;
  474. if (codec > 2)
  475. return -EIO;
  476. if (chip->in_sdin_init) {
  477. /* we don't know the ready bit assignment at the moment */
  478. /* so we check any */
  479. codec = ICH_PCR | ICH_SCR | ICH_TCR;
  480. } else {
  481. codec = get_ich_codec_bit(chip, codec);
  482. }
  483. /* codec ready ? */
  484. if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
  485. return -EIO;
  486. if (chip->buggy_semaphore)
  487. return 0; /* just ignore ... */
  488. /* Anyone holding a semaphore for 1 msec should be shot... */
  489. time = 100;
  490. do {
  491. if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
  492. return 0;
  493. udelay(10);
  494. } while (time--);
  495. /* access to some forbidden (non existant) ac97 registers will not
  496. * reset the semaphore. So even if you don't get the semaphore, still
  497. * continue the access. We don't need the semaphore anyway. */
  498. snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
  499. igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
  500. iagetword(chip, 0); /* clear semaphore flag */
  501. /* I don't care about the semaphore */
  502. return -EBUSY;
  503. }
  504. static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
  505. unsigned short reg,
  506. unsigned short val)
  507. {
  508. struct intel8x0 *chip = ac97->private_data;
  509. if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  510. if (! chip->in_ac97_init)
  511. snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
  512. }
  513. iaputword(chip, reg + ac97->num * 0x80, val);
  514. }
  515. static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
  516. unsigned short reg)
  517. {
  518. struct intel8x0 *chip = ac97->private_data;
  519. unsigned short res;
  520. unsigned int tmp;
  521. if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  522. if (! chip->in_ac97_init)
  523. snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
  524. res = 0xffff;
  525. } else {
  526. res = iagetword(chip, reg + ac97->num * 0x80);
  527. if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  528. /* reset RCS and preserve other R/WC bits */
  529. iputdword(chip, ICHREG(GLOB_STA), tmp &
  530. ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
  531. if (! chip->in_ac97_init)
  532. snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
  533. res = 0xffff;
  534. }
  535. }
  536. return res;
  537. }
  538. static void snd_intel8x0_codec_read_test(struct intel8x0 *chip, unsigned int codec)
  539. {
  540. unsigned int tmp;
  541. if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
  542. iagetword(chip, codec * 0x80);
  543. if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  544. /* reset RCS and preserve other R/WC bits */
  545. iputdword(chip, ICHREG(GLOB_STA), tmp &
  546. ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
  547. }
  548. }
  549. }
  550. /*
  551. * access to AC97 for Ali5455
  552. */
  553. static int snd_intel8x0_ali_codec_ready(struct intel8x0 *chip, int mask)
  554. {
  555. int count = 0;
  556. for (count = 0; count < 0x7f; count++) {
  557. int val = igetbyte(chip, ICHREG(ALI_CSPSR));
  558. if (val & mask)
  559. return 0;
  560. }
  561. if (! chip->in_ac97_init)
  562. snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
  563. return -EBUSY;
  564. }
  565. static int snd_intel8x0_ali_codec_semaphore(struct intel8x0 *chip)
  566. {
  567. int time = 100;
  568. if (chip->buggy_semaphore)
  569. return 0; /* just ignore ... */
  570. while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
  571. udelay(1);
  572. if (! time && ! chip->in_ac97_init)
  573. snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
  574. return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
  575. }
  576. static unsigned short snd_intel8x0_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg)
  577. {
  578. struct intel8x0 *chip = ac97->private_data;
  579. unsigned short data = 0xffff;
  580. if (snd_intel8x0_ali_codec_semaphore(chip))
  581. goto __err;
  582. reg |= ALI_CPR_ADDR_READ;
  583. if (ac97->num)
  584. reg |= ALI_CPR_ADDR_SECONDARY;
  585. iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  586. if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
  587. goto __err;
  588. data = igetword(chip, ICHREG(ALI_SPR));
  589. __err:
  590. return data;
  591. }
  592. static void snd_intel8x0_ali_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  593. unsigned short val)
  594. {
  595. struct intel8x0 *chip = ac97->private_data;
  596. if (snd_intel8x0_ali_codec_semaphore(chip))
  597. return;
  598. iputword(chip, ICHREG(ALI_CPR), val);
  599. if (ac97->num)
  600. reg |= ALI_CPR_ADDR_SECONDARY;
  601. iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  602. snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
  603. }
  604. /*
  605. * DMA I/O
  606. */
  607. static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ichdev)
  608. {
  609. int idx;
  610. u32 *bdbar = ichdev->bdbar;
  611. unsigned long port = ichdev->reg_offset;
  612. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  613. if (ichdev->size == ichdev->fragsize) {
  614. ichdev->ack_reload = ichdev->ack = 2;
  615. ichdev->fragsize1 = ichdev->fragsize >> 1;
  616. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
  617. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
  618. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  619. ichdev->fragsize1 >> ichdev->pos_shift);
  620. bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
  621. bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  622. ichdev->fragsize1 >> ichdev->pos_shift);
  623. }
  624. ichdev->frags = 2;
  625. } else {
  626. ichdev->ack_reload = ichdev->ack = 1;
  627. ichdev->fragsize1 = ichdev->fragsize;
  628. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
  629. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf +
  630. (((idx >> 1) * ichdev->fragsize) %
  631. ichdev->size));
  632. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  633. ichdev->fragsize >> ichdev->pos_shift);
  634. #if 0
  635. printk("bdbar[%i] = 0x%x [0x%x]\n",
  636. idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
  637. #endif
  638. }
  639. ichdev->frags = ichdev->size / ichdev->fragsize;
  640. }
  641. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
  642. ichdev->civ = 0;
  643. iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
  644. ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
  645. ichdev->position = 0;
  646. #if 0
  647. printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
  648. ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1);
  649. #endif
  650. /* clear interrupts */
  651. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  652. }
  653. #ifdef __i386__
  654. /*
  655. * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
  656. * which aborts PCI busmaster for audio transfer. A workaround is to set
  657. * the pages as non-cached. For details, see the errata in
  658. * http://www.intel.com/design/chipsets/specupdt/245051.htm
  659. */
  660. static void fill_nocache(void *buf, int size, int nocache)
  661. {
  662. size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
  663. change_page_attr(virt_to_page(buf), size, nocache ? PAGE_KERNEL_NOCACHE : PAGE_KERNEL);
  664. global_flush_tlb();
  665. }
  666. #else
  667. #define fill_nocache(buf,size,nocache)
  668. #endif
  669. /*
  670. * Interrupt handler
  671. */
  672. static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ichdev)
  673. {
  674. unsigned long port = ichdev->reg_offset;
  675. int status, civ, i, step;
  676. int ack = 0;
  677. spin_lock(&chip->reg_lock);
  678. status = igetbyte(chip, port + ichdev->roff_sr);
  679. civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
  680. if (!(status & ICH_BCIS)) {
  681. step = 0;
  682. } else if (civ == ichdev->civ) {
  683. // snd_printd("civ same %d\n", civ);
  684. step = 1;
  685. ichdev->civ++;
  686. ichdev->civ &= ICH_REG_LVI_MASK;
  687. } else {
  688. step = civ - ichdev->civ;
  689. if (step < 0)
  690. step += ICH_REG_LVI_MASK + 1;
  691. // if (step != 1)
  692. // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
  693. ichdev->civ = civ;
  694. }
  695. ichdev->position += step * ichdev->fragsize1;
  696. if (! chip->in_measurement)
  697. ichdev->position %= ichdev->size;
  698. ichdev->lvi += step;
  699. ichdev->lvi &= ICH_REG_LVI_MASK;
  700. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  701. for (i = 0; i < step; i++) {
  702. ichdev->lvi_frag++;
  703. ichdev->lvi_frag %= ichdev->frags;
  704. ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
  705. #if 0
  706. printk("new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
  707. ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
  708. ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
  709. inl(port + 4), inb(port + ICH_REG_OFF_CR));
  710. #endif
  711. if (--ichdev->ack == 0) {
  712. ichdev->ack = ichdev->ack_reload;
  713. ack = 1;
  714. }
  715. }
  716. spin_unlock(&chip->reg_lock);
  717. if (ack && ichdev->substream) {
  718. snd_pcm_period_elapsed(ichdev->substream);
  719. }
  720. iputbyte(chip, port + ichdev->roff_sr,
  721. status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
  722. }
  723. static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  724. {
  725. struct intel8x0 *chip = dev_id;
  726. struct ichdev *ichdev;
  727. unsigned int status;
  728. unsigned int i;
  729. status = igetdword(chip, chip->int_sta_reg);
  730. if (status == 0xffffffff) /* we are not yet resumed */
  731. return IRQ_NONE;
  732. if ((status & chip->int_sta_mask) == 0) {
  733. if (status) {
  734. /* ack */
  735. iputdword(chip, chip->int_sta_reg, status);
  736. if (! chip->buggy_irq)
  737. status = 0;
  738. }
  739. return IRQ_RETVAL(status);
  740. }
  741. for (i = 0; i < chip->bdbars_count; i++) {
  742. ichdev = &chip->ichd[i];
  743. if (status & ichdev->int_sta_mask)
  744. snd_intel8x0_update(chip, ichdev);
  745. }
  746. /* ack them */
  747. iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  748. return IRQ_HANDLED;
  749. }
  750. /*
  751. * PCM part
  752. */
  753. static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  754. {
  755. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  756. struct ichdev *ichdev = get_ichdev(substream);
  757. unsigned char val = 0;
  758. unsigned long port = ichdev->reg_offset;
  759. switch (cmd) {
  760. case SNDRV_PCM_TRIGGER_RESUME:
  761. ichdev->suspended = 0;
  762. /* fallthru */
  763. case SNDRV_PCM_TRIGGER_START:
  764. val = ICH_IOCE | ICH_STARTBM;
  765. break;
  766. case SNDRV_PCM_TRIGGER_SUSPEND:
  767. ichdev->suspended = 1;
  768. /* fallthru */
  769. case SNDRV_PCM_TRIGGER_STOP:
  770. val = 0;
  771. break;
  772. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  773. val = ICH_IOCE;
  774. break;
  775. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  776. val = ICH_IOCE | ICH_STARTBM;
  777. break;
  778. default:
  779. return -EINVAL;
  780. }
  781. iputbyte(chip, port + ICH_REG_OFF_CR, val);
  782. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  783. /* wait until DMA stopped */
  784. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  785. /* reset whole DMA things */
  786. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  787. }
  788. return 0;
  789. }
  790. static int snd_intel8x0_ali_trigger(struct snd_pcm_substream *substream, int cmd)
  791. {
  792. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  793. struct ichdev *ichdev = get_ichdev(substream);
  794. unsigned long port = ichdev->reg_offset;
  795. static int fiforeg[] = {
  796. ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3)
  797. };
  798. unsigned int val, fifo;
  799. val = igetdword(chip, ICHREG(ALI_DMACR));
  800. switch (cmd) {
  801. case SNDRV_PCM_TRIGGER_RESUME:
  802. ichdev->suspended = 0;
  803. /* fallthru */
  804. case SNDRV_PCM_TRIGGER_START:
  805. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  806. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  807. /* clear FIFO for synchronization of channels */
  808. fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
  809. fifo &= ~(0xff << (ichdev->ali_slot % 4));
  810. fifo |= 0x83 << (ichdev->ali_slot % 4);
  811. iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
  812. }
  813. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  814. val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
  815. /* start DMA */
  816. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot));
  817. break;
  818. case SNDRV_PCM_TRIGGER_SUSPEND:
  819. ichdev->suspended = 1;
  820. /* fallthru */
  821. case SNDRV_PCM_TRIGGER_STOP:
  822. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  823. /* pause */
  824. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16)));
  825. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  826. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  827. ;
  828. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  829. break;
  830. /* reset whole DMA things */
  831. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  832. /* clear interrupts */
  833. iputbyte(chip, port + ICH_REG_OFF_SR,
  834. igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
  835. iputdword(chip, ICHREG(ALI_INTERRUPTSR),
  836. igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
  837. break;
  838. default:
  839. return -EINVAL;
  840. }
  841. return 0;
  842. }
  843. static int snd_intel8x0_hw_params(struct snd_pcm_substream *substream,
  844. struct snd_pcm_hw_params *hw_params)
  845. {
  846. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  847. struct ichdev *ichdev = get_ichdev(substream);
  848. struct snd_pcm_runtime *runtime = substream->runtime;
  849. int dbl = params_rate(hw_params) > 48000;
  850. int err;
  851. if (chip->fix_nocache && ichdev->page_attr_changed) {
  852. fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
  853. ichdev->page_attr_changed = 0;
  854. }
  855. err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  856. if (err < 0)
  857. return err;
  858. if (chip->fix_nocache) {
  859. if (runtime->dma_area && ! ichdev->page_attr_changed) {
  860. fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
  861. ichdev->page_attr_changed = 1;
  862. }
  863. }
  864. if (ichdev->pcm_open_flag) {
  865. snd_ac97_pcm_close(ichdev->pcm);
  866. ichdev->pcm_open_flag = 0;
  867. }
  868. err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
  869. params_channels(hw_params),
  870. ichdev->pcm->r[dbl].slots);
  871. if (err >= 0) {
  872. ichdev->pcm_open_flag = 1;
  873. /* Force SPDIF setting */
  874. if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
  875. snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF,
  876. params_rate(hw_params));
  877. }
  878. return err;
  879. }
  880. static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
  881. {
  882. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  883. struct ichdev *ichdev = get_ichdev(substream);
  884. if (ichdev->pcm_open_flag) {
  885. snd_ac97_pcm_close(ichdev->pcm);
  886. ichdev->pcm_open_flag = 0;
  887. }
  888. if (chip->fix_nocache && ichdev->page_attr_changed) {
  889. fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
  890. ichdev->page_attr_changed = 0;
  891. }
  892. return snd_pcm_lib_free_pages(substream);
  893. }
  894. static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
  895. struct snd_pcm_runtime *runtime)
  896. {
  897. unsigned int cnt;
  898. int dbl = runtime->rate > 48000;
  899. spin_lock_irq(&chip->reg_lock);
  900. switch (chip->device_type) {
  901. case DEVICE_ALI:
  902. cnt = igetdword(chip, ICHREG(ALI_SCR));
  903. cnt &= ~ICH_ALI_SC_PCM_246_MASK;
  904. if (runtime->channels == 4 || dbl)
  905. cnt |= ICH_ALI_SC_PCM_4;
  906. else if (runtime->channels == 6)
  907. cnt |= ICH_ALI_SC_PCM_6;
  908. iputdword(chip, ICHREG(ALI_SCR), cnt);
  909. break;
  910. case DEVICE_SIS:
  911. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  912. cnt &= ~ICH_SIS_PCM_246_MASK;
  913. if (runtime->channels == 4 || dbl)
  914. cnt |= ICH_SIS_PCM_4;
  915. else if (runtime->channels == 6)
  916. cnt |= ICH_SIS_PCM_6;
  917. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  918. break;
  919. default:
  920. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  921. cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
  922. if (runtime->channels == 4 || dbl)
  923. cnt |= ICH_PCM_4;
  924. else if (runtime->channels == 6)
  925. cnt |= ICH_PCM_6;
  926. if (chip->device_type == DEVICE_NFORCE) {
  927. /* reset to 2ch once to keep the 6 channel data in alignment,
  928. * to start from Front Left always
  929. */
  930. if (cnt & ICH_PCM_246_MASK) {
  931. iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
  932. spin_unlock_irq(&chip->reg_lock);
  933. msleep(50); /* grrr... */
  934. spin_lock_irq(&chip->reg_lock);
  935. }
  936. } else if (chip->device_type == DEVICE_INTEL_ICH4) {
  937. if (runtime->sample_bits > 16)
  938. cnt |= ICH_PCM_20BIT;
  939. }
  940. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  941. break;
  942. }
  943. spin_unlock_irq(&chip->reg_lock);
  944. }
  945. static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
  946. {
  947. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  948. struct snd_pcm_runtime *runtime = substream->runtime;
  949. struct ichdev *ichdev = get_ichdev(substream);
  950. ichdev->physbuf = runtime->dma_addr;
  951. ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  952. ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
  953. if (ichdev->ichd == ICHD_PCMOUT) {
  954. snd_intel8x0_setup_pcm_out(chip, runtime);
  955. if (chip->device_type == DEVICE_INTEL_ICH4)
  956. ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
  957. }
  958. snd_intel8x0_setup_periods(chip, ichdev);
  959. return 0;
  960. }
  961. static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *substream)
  962. {
  963. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  964. struct ichdev *ichdev = get_ichdev(substream);
  965. size_t ptr1, ptr;
  966. int civ, timeout = 100;
  967. unsigned int position;
  968. spin_lock(&chip->reg_lock);
  969. do {
  970. civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  971. ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  972. position = ichdev->position;
  973. if (ptr1 == 0) {
  974. udelay(10);
  975. continue;
  976. }
  977. if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
  978. ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  979. break;
  980. } while (timeout--);
  981. ptr1 <<= ichdev->pos_shift;
  982. ptr = ichdev->fragsize1 - ptr1;
  983. ptr += position;
  984. spin_unlock(&chip->reg_lock);
  985. if (ptr >= ichdev->size)
  986. return 0;
  987. return bytes_to_frames(substream->runtime, ptr);
  988. }
  989. static struct snd_pcm_hardware snd_intel8x0_stream =
  990. {
  991. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  992. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  993. SNDRV_PCM_INFO_MMAP_VALID |
  994. SNDRV_PCM_INFO_PAUSE |
  995. SNDRV_PCM_INFO_RESUME),
  996. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  997. .rates = SNDRV_PCM_RATE_48000,
  998. .rate_min = 48000,
  999. .rate_max = 48000,
  1000. .channels_min = 2,
  1001. .channels_max = 2,
  1002. .buffer_bytes_max = 128 * 1024,
  1003. .period_bytes_min = 32,
  1004. .period_bytes_max = 128 * 1024,
  1005. .periods_min = 1,
  1006. .periods_max = 1024,
  1007. .fifo_size = 0,
  1008. };
  1009. static unsigned int channels4[] = {
  1010. 2, 4,
  1011. };
  1012. static struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
  1013. .count = ARRAY_SIZE(channels4),
  1014. .list = channels4,
  1015. .mask = 0,
  1016. };
  1017. static unsigned int channels6[] = {
  1018. 2, 4, 6,
  1019. };
  1020. static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
  1021. .count = ARRAY_SIZE(channels6),
  1022. .list = channels6,
  1023. .mask = 0,
  1024. };
  1025. static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
  1026. {
  1027. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1028. struct snd_pcm_runtime *runtime = substream->runtime;
  1029. int err;
  1030. ichdev->substream = substream;
  1031. runtime->hw = snd_intel8x0_stream;
  1032. runtime->hw.rates = ichdev->pcm->rates;
  1033. snd_pcm_limit_hw_rates(runtime);
  1034. if (chip->device_type == DEVICE_SIS) {
  1035. runtime->hw.buffer_bytes_max = 64*1024;
  1036. runtime->hw.period_bytes_max = 64*1024;
  1037. }
  1038. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  1039. return err;
  1040. runtime->private_data = ichdev;
  1041. return 0;
  1042. }
  1043. static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
  1044. {
  1045. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1046. struct snd_pcm_runtime *runtime = substream->runtime;
  1047. int err;
  1048. err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
  1049. if (err < 0)
  1050. return err;
  1051. 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. static int snd_intel8x0_ali_spdifin_open(struct snd_pcm_substream *substream)
  1157. {
  1158. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1159. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
  1160. }
  1161. static int snd_intel8x0_ali_spdifin_close(struct snd_pcm_substream *substream)
  1162. {
  1163. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1164. chip->ichd[ALID_SPDIFIN].substream = NULL;
  1165. return 0;
  1166. }
  1167. #if 0 // NYI
  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. static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
  1281. .open = snd_intel8x0_ali_spdifin_open,
  1282. .close = snd_intel8x0_ali_spdifin_close,
  1283. .ioctl = snd_pcm_lib_ioctl,
  1284. .hw_params = snd_intel8x0_hw_params,
  1285. .hw_free = snd_intel8x0_hw_free,
  1286. .prepare = snd_intel8x0_pcm_prepare,
  1287. .trigger = snd_intel8x0_pcm_trigger,
  1288. .pointer = snd_intel8x0_pcm_pointer,
  1289. };
  1290. #if 0 // NYI
  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. break;
  1439. case DEVICE_NFORCE:
  1440. tbl = nforce_pcms;
  1441. tblsize = ARRAY_SIZE(nforce_pcms);
  1442. break;
  1443. case DEVICE_ALI:
  1444. tbl = ali_pcms;
  1445. tblsize = ARRAY_SIZE(ali_pcms);
  1446. break;
  1447. default:
  1448. tbl = intel_pcms;
  1449. tblsize = 2;
  1450. break;
  1451. }
  1452. device = 0;
  1453. for (i = 0; i < tblsize; i++) {
  1454. rec = tbl + i;
  1455. if (i > 0 && rec->ac97_idx) {
  1456. /* activate PCM only when associated AC'97 codec */
  1457. if (! chip->ichd[rec->ac97_idx].pcm)
  1458. continue;
  1459. }
  1460. err = snd_intel8x0_pcm1(chip, device, rec);
  1461. if (err < 0)
  1462. return err;
  1463. device++;
  1464. }
  1465. chip->pcm_devs = device;
  1466. return 0;
  1467. }
  1468. /*
  1469. * Mixer part
  1470. */
  1471. static void snd_intel8x0_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  1472. {
  1473. struct intel8x0 *chip = bus->private_data;
  1474. chip->ac97_bus = NULL;
  1475. }
  1476. static void snd_intel8x0_mixer_free_ac97(struct snd_ac97 *ac97)
  1477. {
  1478. struct intel8x0 *chip = ac97->private_data;
  1479. chip->ac97[ac97->num] = NULL;
  1480. }
  1481. static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
  1482. /* front PCM */
  1483. {
  1484. .exclusive = 1,
  1485. .r = { {
  1486. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1487. (1 << AC97_SLOT_PCM_RIGHT) |
  1488. (1 << AC97_SLOT_PCM_CENTER) |
  1489. (1 << AC97_SLOT_PCM_SLEFT) |
  1490. (1 << AC97_SLOT_PCM_SRIGHT) |
  1491. (1 << AC97_SLOT_LFE)
  1492. },
  1493. {
  1494. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1495. (1 << AC97_SLOT_PCM_RIGHT) |
  1496. (1 << AC97_SLOT_PCM_LEFT_0) |
  1497. (1 << AC97_SLOT_PCM_RIGHT_0)
  1498. }
  1499. }
  1500. },
  1501. /* PCM IN #1 */
  1502. {
  1503. .stream = 1,
  1504. .exclusive = 1,
  1505. .r = { {
  1506. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1507. (1 << AC97_SLOT_PCM_RIGHT)
  1508. }
  1509. }
  1510. },
  1511. /* MIC IN #1 */
  1512. {
  1513. .stream = 1,
  1514. .exclusive = 1,
  1515. .r = { {
  1516. .slots = (1 << AC97_SLOT_MIC)
  1517. }
  1518. }
  1519. },
  1520. /* S/PDIF PCM */
  1521. {
  1522. .exclusive = 1,
  1523. .spdif = 1,
  1524. .r = { {
  1525. .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
  1526. (1 << AC97_SLOT_SPDIF_RIGHT2)
  1527. }
  1528. }
  1529. },
  1530. /* PCM IN #2 */
  1531. {
  1532. .stream = 1,
  1533. .exclusive = 1,
  1534. .r = { {
  1535. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1536. (1 << AC97_SLOT_PCM_RIGHT)
  1537. }
  1538. }
  1539. },
  1540. /* MIC IN #2 */
  1541. {
  1542. .stream = 1,
  1543. .exclusive = 1,
  1544. .r = { {
  1545. .slots = (1 << AC97_SLOT_MIC)
  1546. }
  1547. }
  1548. },
  1549. };
  1550. static struct ac97_quirk ac97_quirks[] __devinitdata = {
  1551. {
  1552. .subvendor = 0x0e11,
  1553. .subdevice = 0x008a,
  1554. .name = "Compaq Evo W4000", /* AD1885 */
  1555. .type = AC97_TUNE_HP_ONLY
  1556. },
  1557. {
  1558. .subvendor = 0x0e11,
  1559. .subdevice = 0x00b8,
  1560. .name = "Compaq Evo D510C",
  1561. .type = AC97_TUNE_HP_ONLY
  1562. },
  1563. {
  1564. .subvendor = 0x0e11,
  1565. .subdevice = 0x0860,
  1566. .name = "HP/Compaq nx7010",
  1567. .type = AC97_TUNE_MUTE_LED
  1568. },
  1569. {
  1570. .subvendor = 0x1014,
  1571. .subdevice = 0x1f00,
  1572. .name = "MS-9128",
  1573. .type = AC97_TUNE_ALC_JACK
  1574. },
  1575. {
  1576. .subvendor = 0x1014,
  1577. .subdevice = 0x0267,
  1578. .name = "IBM NetVista A30p", /* AD1981B */
  1579. .type = AC97_TUNE_HP_ONLY
  1580. },
  1581. {
  1582. .subvendor = 0x1025,
  1583. .subdevice = 0x0083,
  1584. .name = "Acer Aspire 3003LCi",
  1585. .type = AC97_TUNE_HP_ONLY
  1586. },
  1587. {
  1588. .subvendor = 0x1028,
  1589. .subdevice = 0x00d8,
  1590. .name = "Dell Precision 530", /* AD1885 */
  1591. .type = AC97_TUNE_HP_ONLY
  1592. },
  1593. {
  1594. .subvendor = 0x1028,
  1595. .subdevice = 0x010d,
  1596. .name = "Dell", /* which model? AD1885 */
  1597. .type = AC97_TUNE_HP_ONLY
  1598. },
  1599. {
  1600. .subvendor = 0x1028,
  1601. .subdevice = 0x0126,
  1602. .name = "Dell Optiplex GX260", /* AD1981A */
  1603. .type = AC97_TUNE_HP_ONLY
  1604. },
  1605. {
  1606. .subvendor = 0x1028,
  1607. .subdevice = 0x012c,
  1608. .name = "Dell Precision 650", /* AD1981A */
  1609. .type = AC97_TUNE_HP_ONLY
  1610. },
  1611. {
  1612. .subvendor = 0x1028,
  1613. .subdevice = 0x012d,
  1614. .name = "Dell Precision 450", /* AD1981B*/
  1615. .type = AC97_TUNE_HP_ONLY
  1616. },
  1617. {
  1618. .subvendor = 0x1028,
  1619. .subdevice = 0x0147,
  1620. .name = "Dell", /* which model? AD1981B*/
  1621. .type = AC97_TUNE_HP_ONLY
  1622. },
  1623. {
  1624. .subvendor = 0x1028,
  1625. .subdevice = 0x0163,
  1626. .name = "Dell Unknown", /* STAC9750/51 */
  1627. .type = AC97_TUNE_HP_ONLY
  1628. },
  1629. {
  1630. .subvendor = 0x1028,
  1631. .subdevice = 0x0191,
  1632. .name = "Dell Inspiron 8600",
  1633. .type = AC97_TUNE_HP_ONLY
  1634. },
  1635. {
  1636. .subvendor = 0x103c,
  1637. .subdevice = 0x006d,
  1638. .name = "HP zv5000",
  1639. .type = AC97_TUNE_MUTE_LED /*AD1981B*/
  1640. },
  1641. { /* FIXME: which codec? */
  1642. .subvendor = 0x103c,
  1643. .subdevice = 0x00c3,
  1644. .name = "HP xw6000",
  1645. .type = AC97_TUNE_HP_ONLY
  1646. },
  1647. {
  1648. .subvendor = 0x103c,
  1649. .subdevice = 0x088c,
  1650. .name = "HP nc8000",
  1651. .type = AC97_TUNE_MUTE_LED
  1652. },
  1653. {
  1654. .subvendor = 0x103c,
  1655. .subdevice = 0x0890,
  1656. .name = "HP nc6000",
  1657. .type = AC97_TUNE_MUTE_LED
  1658. },
  1659. {
  1660. .subvendor = 0x103c,
  1661. .subdevice = 0x0934,
  1662. .name = "HP nx8220",
  1663. .type = AC97_TUNE_MUTE_LED
  1664. },
  1665. {
  1666. .subvendor = 0x103c,
  1667. .subdevice = 0x099c,
  1668. .name = "HP nx6110", /* AD1981B */
  1669. .type = AC97_TUNE_HP_ONLY
  1670. },
  1671. {
  1672. .subvendor = 0x103c,
  1673. .subdevice = 0x129d,
  1674. .name = "HP xw8000",
  1675. .type = AC97_TUNE_HP_ONLY
  1676. },
  1677. {
  1678. .subvendor = 0x103c,
  1679. .subdevice = 0x12f1,
  1680. .name = "HP xw8200", /* AD1981B*/
  1681. .type = AC97_TUNE_HP_ONLY
  1682. },
  1683. {
  1684. .subvendor = 0x103c,
  1685. .subdevice = 0x12f2,
  1686. .name = "HP xw6200",
  1687. .type = AC97_TUNE_HP_ONLY
  1688. },
  1689. {
  1690. .subvendor = 0x103c,
  1691. .subdevice = 0x3008,
  1692. .name = "HP xw4200", /* AD1981B*/
  1693. .type = AC97_TUNE_HP_ONLY
  1694. },
  1695. {
  1696. .subvendor = 0x104d,
  1697. .subdevice = 0x8197,
  1698. .name = "Sony S1XP",
  1699. .type = AC97_TUNE_INV_EAPD
  1700. },
  1701. {
  1702. .subvendor = 0x1043,
  1703. .subdevice = 0x80f3,
  1704. .name = "ASUS ICH5/AD1985",
  1705. .type = AC97_TUNE_AD_SHARING
  1706. },
  1707. {
  1708. .subvendor = 0x10cf,
  1709. .subdevice = 0x11c3,
  1710. .name = "Fujitsu-Siemens E4010",
  1711. .type = AC97_TUNE_HP_ONLY
  1712. },
  1713. {
  1714. .subvendor = 0x10cf,
  1715. .subdevice = 0x1225,
  1716. .name = "Fujitsu-Siemens T3010",
  1717. .type = AC97_TUNE_HP_ONLY
  1718. },
  1719. {
  1720. .subvendor = 0x10cf,
  1721. .subdevice = 0x1253,
  1722. .name = "Fujitsu S6210", /* STAC9750/51 */
  1723. .type = AC97_TUNE_HP_ONLY
  1724. },
  1725. {
  1726. .subvendor = 0x10cf,
  1727. .subdevice = 0x12ec,
  1728. .name = "Fujitsu-Siemens 4010",
  1729. .type = AC97_TUNE_HP_ONLY
  1730. },
  1731. {
  1732. .subvendor = 0x10f1,
  1733. .subdevice = 0x2665,
  1734. .name = "Fujitsu-Siemens Celsius", /* AD1981? */
  1735. .type = AC97_TUNE_HP_ONLY
  1736. },
  1737. {
  1738. .subvendor = 0x10f1,
  1739. .subdevice = 0x2885,
  1740. .name = "AMD64 Mobo", /* ALC650 */
  1741. .type = AC97_TUNE_HP_ONLY
  1742. },
  1743. {
  1744. .subvendor = 0x110a,
  1745. .subdevice = 0x0056,
  1746. .name = "Fujitsu-Siemens Scenic", /* AD1981? */
  1747. .type = AC97_TUNE_HP_ONLY
  1748. },
  1749. {
  1750. .subvendor = 0x11d4,
  1751. .subdevice = 0x5375,
  1752. .name = "ADI AD1985 (discrete)",
  1753. .type = AC97_TUNE_HP_ONLY
  1754. },
  1755. {
  1756. .subvendor = 0x1462,
  1757. .subdevice = 0x5470,
  1758. .name = "MSI P4 ATX 645 Ultra",
  1759. .type = AC97_TUNE_HP_ONLY
  1760. },
  1761. {
  1762. .subvendor = 0x1734,
  1763. .subdevice = 0x0088,
  1764. .name = "Fujitsu-Siemens D1522", /* AD1981 */
  1765. .type = AC97_TUNE_HP_ONLY
  1766. },
  1767. {
  1768. .subvendor = 0x8086,
  1769. .subdevice = 0x2000,
  1770. .mask = 0xfff0,
  1771. .name = "Intel ICH5/AD1985",
  1772. .type = AC97_TUNE_AD_SHARING
  1773. },
  1774. {
  1775. .subvendor = 0x8086,
  1776. .subdevice = 0x4000,
  1777. .mask = 0xfff0,
  1778. .name = "Intel ICH5/AD1985",
  1779. .type = AC97_TUNE_AD_SHARING
  1780. },
  1781. {
  1782. .subvendor = 0x8086,
  1783. .subdevice = 0x4856,
  1784. .name = "Intel D845WN (82801BA)",
  1785. .type = AC97_TUNE_SWAP_HP
  1786. },
  1787. {
  1788. .subvendor = 0x8086,
  1789. .subdevice = 0x4d44,
  1790. .name = "Intel D850EMV2", /* AD1885 */
  1791. .type = AC97_TUNE_HP_ONLY
  1792. },
  1793. {
  1794. .subvendor = 0x8086,
  1795. .subdevice = 0x4d56,
  1796. .name = "Intel ICH/AD1885",
  1797. .type = AC97_TUNE_HP_ONLY
  1798. },
  1799. {
  1800. .subvendor = 0x8086,
  1801. .subdevice = 0x6000,
  1802. .mask = 0xfff0,
  1803. .name = "Intel ICH5/AD1985",
  1804. .type = AC97_TUNE_AD_SHARING
  1805. },
  1806. {
  1807. .subvendor = 0x8086,
  1808. .subdevice = 0xe000,
  1809. .mask = 0xfff0,
  1810. .name = "Intel ICH5/AD1985",
  1811. .type = AC97_TUNE_AD_SHARING
  1812. },
  1813. #if 0 /* FIXME: this seems wrong on most boards */
  1814. {
  1815. .subvendor = 0x8086,
  1816. .subdevice = 0xa000,
  1817. .mask = 0xfff0,
  1818. .name = "Intel ICH5/AD1985",
  1819. .type = AC97_TUNE_HP_ONLY
  1820. },
  1821. #endif
  1822. { } /* terminator */
  1823. };
  1824. static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
  1825. const char *quirk_override)
  1826. {
  1827. struct snd_ac97_bus *pbus;
  1828. struct snd_ac97_template ac97;
  1829. int err;
  1830. unsigned int i, codecs;
  1831. unsigned int glob_sta = 0;
  1832. struct snd_ac97_bus_ops *ops;
  1833. static struct snd_ac97_bus_ops standard_bus_ops = {
  1834. .write = snd_intel8x0_codec_write,
  1835. .read = snd_intel8x0_codec_read,
  1836. };
  1837. static struct snd_ac97_bus_ops ali_bus_ops = {
  1838. .write = snd_intel8x0_ali_codec_write,
  1839. .read = snd_intel8x0_ali_codec_read,
  1840. };
  1841. chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
  1842. switch (chip->device_type) {
  1843. case DEVICE_NFORCE:
  1844. chip->spdif_idx = NVD_SPBAR;
  1845. break;
  1846. case DEVICE_ALI:
  1847. chip->spdif_idx = ALID_AC97SPDIFOUT;
  1848. break;
  1849. case DEVICE_INTEL_ICH4:
  1850. chip->spdif_idx = ICHD_SPBAR;
  1851. break;
  1852. };
  1853. chip->in_ac97_init = 1;
  1854. memset(&ac97, 0, sizeof(ac97));
  1855. ac97.private_data = chip;
  1856. ac97.private_free = snd_intel8x0_mixer_free_ac97;
  1857. ac97.scaps = AC97_SCAP_SKIP_MODEM;
  1858. if (chip->xbox)
  1859. ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
  1860. if (chip->device_type != DEVICE_ALI) {
  1861. glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  1862. ops = &standard_bus_ops;
  1863. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1864. codecs = 0;
  1865. if (glob_sta & ICH_PCR)
  1866. codecs++;
  1867. if (glob_sta & ICH_SCR)
  1868. codecs++;
  1869. if (glob_sta & ICH_TCR)
  1870. codecs++;
  1871. chip->in_sdin_init = 1;
  1872. for (i = 0; i < codecs; i++) {
  1873. snd_intel8x0_codec_read_test(chip, i);
  1874. chip->ac97_sdin[i] = igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
  1875. }
  1876. chip->in_sdin_init = 0;
  1877. } else {
  1878. codecs = glob_sta & ICH_SCR ? 2 : 1;
  1879. }
  1880. } else {
  1881. ops = &ali_bus_ops;
  1882. codecs = 1;
  1883. /* detect the secondary codec */
  1884. for (i = 0; i < 100; i++) {
  1885. unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
  1886. if (reg & 0x40) {
  1887. codecs = 2;
  1888. break;
  1889. }
  1890. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
  1891. udelay(1);
  1892. }
  1893. }
  1894. if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
  1895. goto __err;
  1896. pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
  1897. if (ac97_clock >= 8000 && ac97_clock <= 48000)
  1898. pbus->clock = ac97_clock;
  1899. /* FIXME: my test board doesn't work well with VRA... */
  1900. if (chip->device_type == DEVICE_ALI)
  1901. pbus->no_vra = 1;
  1902. else
  1903. pbus->dra = 1;
  1904. chip->ac97_bus = pbus;
  1905. ac97.pci = chip->pci;
  1906. for (i = 0; i < codecs; i++) {
  1907. ac97.num = i;
  1908. if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
  1909. if (err != -EACCES)
  1910. snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
  1911. if (i == 0)
  1912. goto __err;
  1913. continue;
  1914. }
  1915. }
  1916. /* tune up the primary codec */
  1917. snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
  1918. /* enable separate SDINs for ICH4 */
  1919. if (chip->device_type == DEVICE_INTEL_ICH4)
  1920. pbus->isdin = 1;
  1921. /* find the available PCM streams */
  1922. i = ARRAY_SIZE(ac97_pcm_defs);
  1923. if (chip->device_type != DEVICE_INTEL_ICH4)
  1924. i -= 2; /* do not allocate PCM2IN and MIC2 */
  1925. if (chip->spdif_idx < 0)
  1926. i--; /* do not allocate S/PDIF */
  1927. err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
  1928. if (err < 0)
  1929. goto __err;
  1930. chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
  1931. chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
  1932. chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
  1933. if (chip->spdif_idx >= 0)
  1934. chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
  1935. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1936. chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
  1937. chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
  1938. }
  1939. /* enable separate SDINs for ICH4 */
  1940. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1941. struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
  1942. u8 tmp = igetbyte(chip, ICHREG(SDM));
  1943. tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
  1944. if (pcm) {
  1945. tmp |= ICH_SE; /* steer enable for multiple SDINs */
  1946. tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
  1947. for (i = 1; i < 4; i++) {
  1948. if (pcm->r[0].codec[i]) {
  1949. tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
  1950. break;
  1951. }
  1952. }
  1953. } else {
  1954. tmp &= ~ICH_SE; /* steer disable */
  1955. }
  1956. iputbyte(chip, ICHREG(SDM), tmp);
  1957. }
  1958. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
  1959. chip->multi4 = 1;
  1960. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE))
  1961. chip->multi6 = 1;
  1962. }
  1963. if (pbus->pcms[0].r[1].rslots[0]) {
  1964. chip->dra = 1;
  1965. }
  1966. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1967. if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
  1968. chip->smp20bit = 1;
  1969. }
  1970. if (chip->device_type == DEVICE_NFORCE) {
  1971. /* 48kHz only */
  1972. chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
  1973. }
  1974. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1975. /* use slot 10/11 for SPDIF */
  1976. u32 val;
  1977. val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
  1978. val |= ICH_PCM_SPDIF_1011;
  1979. iputdword(chip, ICHREG(GLOB_CNT), val);
  1980. snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
  1981. }
  1982. chip->in_ac97_init = 0;
  1983. return 0;
  1984. __err:
  1985. /* clear the cold-reset bit for the next chance */
  1986. if (chip->device_type != DEVICE_ALI)
  1987. iputdword(chip, ICHREG(GLOB_CNT),
  1988. igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
  1989. return err;
  1990. }
  1991. /*
  1992. *
  1993. */
  1994. static void do_ali_reset(struct intel8x0 *chip)
  1995. {
  1996. iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
  1997. iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
  1998. iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
  1999. iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
  2000. iputdword(chip, ICHREG(ALI_INTERFACECR),
  2001. ICH_ALI_IF_PI|ICH_ALI_IF_PO);
  2002. iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
  2003. iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
  2004. }
  2005. static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
  2006. {
  2007. unsigned long end_time;
  2008. unsigned int cnt, status, nstatus;
  2009. /* put logic to right state */
  2010. /* first clear status bits */
  2011. status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
  2012. if (chip->device_type == DEVICE_NFORCE)
  2013. status |= ICH_NVSPINT;
  2014. cnt = igetdword(chip, ICHREG(GLOB_STA));
  2015. iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  2016. /* ACLink on, 2 channels */
  2017. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2018. cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
  2019. /* finish cold or do warm reset */
  2020. cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  2021. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  2022. end_time = (jiffies + (HZ / 4)) + 1;
  2023. do {
  2024. if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
  2025. goto __ok;
  2026. schedule_timeout_uninterruptible(1);
  2027. } while (time_after_eq(end_time, jiffies));
  2028. snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n",
  2029. igetdword(chip, ICHREG(GLOB_CNT)));
  2030. return -EIO;
  2031. __ok:
  2032. if (probing) {
  2033. /* wait for any codec ready status.
  2034. * Once it becomes ready it should remain ready
  2035. * as long as we do not disable the ac97 link.
  2036. */
  2037. end_time = jiffies + HZ;
  2038. do {
  2039. status = igetdword(chip, ICHREG(GLOB_STA)) &
  2040. (ICH_PCR | ICH_SCR | ICH_TCR);
  2041. if (status)
  2042. break;
  2043. schedule_timeout_uninterruptible(1);
  2044. } while (time_after_eq(end_time, jiffies));
  2045. if (! status) {
  2046. /* no codec is found */
  2047. snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n",
  2048. igetdword(chip, ICHREG(GLOB_STA)));
  2049. return -EIO;
  2050. }
  2051. if (chip->device_type == DEVICE_INTEL_ICH4)
  2052. /* ICH4 can have three codecs */
  2053. nstatus = ICH_PCR | ICH_SCR | ICH_TCR;
  2054. else
  2055. /* others up to two codecs */
  2056. nstatus = ICH_PCR | ICH_SCR;
  2057. /* wait for other codecs ready status. */
  2058. end_time = jiffies + HZ / 4;
  2059. while (status != nstatus && time_after_eq(end_time, jiffies)) {
  2060. schedule_timeout_uninterruptible(1);
  2061. status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
  2062. }
  2063. } else {
  2064. /* resume phase */
  2065. int i;
  2066. status = 0;
  2067. for (i = 0; i < 3; i++)
  2068. if (chip->ac97[i])
  2069. status |= get_ich_codec_bit(chip, i);
  2070. /* wait until all the probed codecs are ready */
  2071. end_time = jiffies + HZ;
  2072. do {
  2073. nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
  2074. (ICH_PCR | ICH_SCR | ICH_TCR);
  2075. if (status == nstatus)
  2076. break;
  2077. schedule_timeout_uninterruptible(1);
  2078. } while (time_after_eq(end_time, jiffies));
  2079. }
  2080. if (chip->device_type == DEVICE_SIS) {
  2081. /* unmute the output on SIS7012 */
  2082. iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  2083. }
  2084. if (chip->device_type == DEVICE_NFORCE) {
  2085. /* enable SPDIF interrupt */
  2086. unsigned int val;
  2087. pci_read_config_dword(chip->pci, 0x4c, &val);
  2088. val |= 0x1000000;
  2089. pci_write_config_dword(chip->pci, 0x4c, val);
  2090. }
  2091. return 0;
  2092. }
  2093. static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
  2094. {
  2095. u32 reg;
  2096. int i = 0;
  2097. reg = igetdword(chip, ICHREG(ALI_SCR));
  2098. if ((reg & 2) == 0) /* Cold required */
  2099. reg |= 2;
  2100. else
  2101. reg |= 1; /* Warm */
  2102. reg &= ~0x80000000; /* ACLink on */
  2103. iputdword(chip, ICHREG(ALI_SCR), reg);
  2104. for (i = 0; i < HZ / 2; i++) {
  2105. if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
  2106. goto __ok;
  2107. schedule_timeout_uninterruptible(1);
  2108. }
  2109. snd_printk(KERN_ERR "AC'97 reset failed.\n");
  2110. if (probing)
  2111. return -EIO;
  2112. __ok:
  2113. for (i = 0; i < HZ / 2; i++) {
  2114. reg = igetdword(chip, ICHREG(ALI_RTSR));
  2115. if (reg & 0x80) /* primary codec */
  2116. break;
  2117. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
  2118. schedule_timeout_uninterruptible(1);
  2119. }
  2120. do_ali_reset(chip);
  2121. return 0;
  2122. }
  2123. static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
  2124. {
  2125. unsigned int i;
  2126. int err;
  2127. if (chip->device_type != DEVICE_ALI) {
  2128. if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
  2129. return err;
  2130. iagetword(chip, 0); /* clear semaphore flag */
  2131. } else {
  2132. if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
  2133. return err;
  2134. }
  2135. /* disable interrupts */
  2136. for (i = 0; i < chip->bdbars_count; i++)
  2137. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2138. /* reset channels */
  2139. for (i = 0; i < chip->bdbars_count; i++)
  2140. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2141. /* initialize Buffer Descriptor Lists */
  2142. for (i = 0; i < chip->bdbars_count; i++)
  2143. iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset,
  2144. chip->ichd[i].bdbar_addr);
  2145. return 0;
  2146. }
  2147. static int snd_intel8x0_free(struct intel8x0 *chip)
  2148. {
  2149. unsigned int i;
  2150. if (chip->irq < 0)
  2151. goto __hw_end;
  2152. /* disable interrupts */
  2153. for (i = 0; i < chip->bdbars_count; i++)
  2154. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2155. /* reset channels */
  2156. for (i = 0; i < chip->bdbars_count; i++)
  2157. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2158. if (chip->device_type == DEVICE_NFORCE) {
  2159. /* stop the spdif interrupt */
  2160. unsigned int val;
  2161. pci_read_config_dword(chip->pci, 0x4c, &val);
  2162. val &= ~0x1000000;
  2163. pci_write_config_dword(chip->pci, 0x4c, val);
  2164. }
  2165. /* --- */
  2166. synchronize_irq(chip->irq);
  2167. __hw_end:
  2168. if (chip->irq >= 0)
  2169. free_irq(chip->irq, chip);
  2170. if (chip->bdbars.area) {
  2171. if (chip->fix_nocache)
  2172. fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
  2173. snd_dma_free_pages(&chip->bdbars);
  2174. }
  2175. if (chip->remap_addr)
  2176. iounmap(chip->remap_addr);
  2177. if (chip->remap_bmaddr)
  2178. iounmap(chip->remap_bmaddr);
  2179. pci_release_regions(chip->pci);
  2180. pci_disable_device(chip->pci);
  2181. kfree(chip);
  2182. return 0;
  2183. }
  2184. #ifdef CONFIG_PM
  2185. /*
  2186. * power management
  2187. */
  2188. static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
  2189. {
  2190. struct snd_card *card = pci_get_drvdata(pci);
  2191. struct intel8x0 *chip = card->private_data;
  2192. int i;
  2193. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  2194. for (i = 0; i < chip->pcm_devs; i++)
  2195. snd_pcm_suspend_all(chip->pcm[i]);
  2196. /* clear nocache */
  2197. if (chip->fix_nocache) {
  2198. for (i = 0; i < chip->bdbars_count; i++) {
  2199. struct ichdev *ichdev = &chip->ichd[i];
  2200. if (ichdev->substream && ichdev->page_attr_changed) {
  2201. struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
  2202. if (runtime->dma_area)
  2203. fill_nocache(runtime->dma_area, runtime->dma_bytes, 0);
  2204. }
  2205. }
  2206. }
  2207. for (i = 0; i < 3; i++)
  2208. snd_ac97_suspend(chip->ac97[i]);
  2209. if (chip->device_type == DEVICE_INTEL_ICH4)
  2210. chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
  2211. if (chip->irq >= 0)
  2212. free_irq(chip->irq, chip);
  2213. pci_disable_device(pci);
  2214. pci_save_state(pci);
  2215. return 0;
  2216. }
  2217. static int intel8x0_resume(struct pci_dev *pci)
  2218. {
  2219. struct snd_card *card = pci_get_drvdata(pci);
  2220. struct intel8x0 *chip = card->private_data;
  2221. int i;
  2222. pci_restore_state(pci);
  2223. pci_enable_device(pci);
  2224. pci_set_master(pci);
  2225. request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ,
  2226. card->shortname, chip);
  2227. chip->irq = pci->irq;
  2228. synchronize_irq(chip->irq);
  2229. snd_intel8x0_chip_init(chip, 1);
  2230. /* re-initialize mixer stuff */
  2231. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2232. /* enable separate SDINs for ICH4 */
  2233. iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
  2234. /* use slot 10/11 for SPDIF */
  2235. iputdword(chip, ICHREG(GLOB_CNT),
  2236. (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
  2237. ICH_PCM_SPDIF_1011);
  2238. }
  2239. /* refill nocache */
  2240. if (chip->fix_nocache)
  2241. fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
  2242. for (i = 0; i < 3; i++)
  2243. snd_ac97_resume(chip->ac97[i]);
  2244. /* refill nocache */
  2245. if (chip->fix_nocache) {
  2246. for (i = 0; i < chip->bdbars_count; i++) {
  2247. struct ichdev *ichdev = &chip->ichd[i];
  2248. if (ichdev->substream && ichdev->page_attr_changed) {
  2249. struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
  2250. if (runtime->dma_area)
  2251. fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
  2252. }
  2253. }
  2254. }
  2255. /* resume status */
  2256. for (i = 0; i < chip->bdbars_count; i++) {
  2257. struct ichdev *ichdev = &chip->ichd[i];
  2258. unsigned long port = ichdev->reg_offset;
  2259. if (! ichdev->substream || ! ichdev->suspended)
  2260. continue;
  2261. if (ichdev->ichd == ICHD_PCMOUT)
  2262. snd_intel8x0_setup_pcm_out(chip, ichdev->substream->runtime);
  2263. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  2264. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  2265. iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->civ);
  2266. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  2267. }
  2268. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  2269. return 0;
  2270. }
  2271. #endif /* CONFIG_PM */
  2272. #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
  2273. static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
  2274. {
  2275. struct snd_pcm_substream *subs;
  2276. struct ichdev *ichdev;
  2277. unsigned long port;
  2278. unsigned long pos, t;
  2279. struct timeval start_time, stop_time;
  2280. if (chip->ac97_bus->clock != 48000)
  2281. return; /* specified in module option */
  2282. subs = chip->pcm[0]->streams[0].substream;
  2283. if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
  2284. snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
  2285. return;
  2286. }
  2287. ichdev = &chip->ichd[ICHD_PCMOUT];
  2288. ichdev->physbuf = subs->dma_buffer.addr;
  2289. ichdev->size = chip->ichd[ICHD_PCMOUT].fragsize = INTEL8X0_TESTBUF_SIZE;
  2290. ichdev->substream = NULL; /* don't process interrupts */
  2291. /* set rate */
  2292. if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
  2293. snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock);
  2294. return;
  2295. }
  2296. snd_intel8x0_setup_periods(chip, ichdev);
  2297. port = ichdev->reg_offset;
  2298. spin_lock_irq(&chip->reg_lock);
  2299. chip->in_measurement = 1;
  2300. /* trigger */
  2301. if (chip->device_type != DEVICE_ALI)
  2302. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
  2303. else {
  2304. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  2305. iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
  2306. }
  2307. do_gettimeofday(&start_time);
  2308. spin_unlock_irq(&chip->reg_lock);
  2309. msleep(50);
  2310. spin_lock_irq(&chip->reg_lock);
  2311. /* check the position */
  2312. pos = ichdev->fragsize1;
  2313. pos -= igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << ichdev->pos_shift;
  2314. pos += ichdev->position;
  2315. chip->in_measurement = 0;
  2316. do_gettimeofday(&stop_time);
  2317. /* stop */
  2318. if (chip->device_type == DEVICE_ALI) {
  2319. iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
  2320. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2321. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  2322. ;
  2323. } else {
  2324. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2325. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
  2326. ;
  2327. }
  2328. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  2329. spin_unlock_irq(&chip->reg_lock);
  2330. t = stop_time.tv_sec - start_time.tv_sec;
  2331. t *= 1000000;
  2332. t += stop_time.tv_usec - start_time.tv_usec;
  2333. printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t);
  2334. if (t == 0) {
  2335. snd_printk(KERN_ERR "?? calculation error..\n");
  2336. return;
  2337. }
  2338. pos = (pos / 4) * 1000;
  2339. pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
  2340. if (pos < 40000 || pos >= 60000)
  2341. /* abnormal value. hw problem? */
  2342. printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
  2343. else if (pos < 47500 || pos > 48500)
  2344. /* not 48000Hz, tuning the clock.. */
  2345. chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
  2346. printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
  2347. }
  2348. static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
  2349. struct snd_info_buffer *buffer)
  2350. {
  2351. struct intel8x0 *chip = entry->private_data;
  2352. unsigned int tmp;
  2353. snd_iprintf(buffer, "Intel8x0\n\n");
  2354. if (chip->device_type == DEVICE_ALI)
  2355. return;
  2356. tmp = igetdword(chip, ICHREG(GLOB_STA));
  2357. snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
  2358. snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
  2359. if (chip->device_type == DEVICE_INTEL_ICH4)
  2360. snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
  2361. snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
  2362. tmp & ICH_PCR ? " primary" : "",
  2363. tmp & ICH_SCR ? " secondary" : "",
  2364. tmp & ICH_TCR ? " tertiary" : "",
  2365. (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
  2366. if (chip->device_type == DEVICE_INTEL_ICH4)
  2367. snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
  2368. chip->ac97_sdin[0],
  2369. chip->ac97_sdin[1],
  2370. chip->ac97_sdin[2]);
  2371. }
  2372. static void __devinit snd_intel8x0_proc_init(struct intel8x0 * chip)
  2373. {
  2374. struct snd_info_entry *entry;
  2375. if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
  2376. snd_info_set_text_ops(entry, chip, 1024, snd_intel8x0_proc_read);
  2377. }
  2378. static int snd_intel8x0_dev_free(struct snd_device *device)
  2379. {
  2380. struct intel8x0 *chip = device->device_data;
  2381. return snd_intel8x0_free(chip);
  2382. }
  2383. struct ich_reg_info {
  2384. unsigned int int_sta_mask;
  2385. unsigned int offset;
  2386. };
  2387. static int __devinit snd_intel8x0_create(struct snd_card *card,
  2388. struct pci_dev *pci,
  2389. unsigned long device_type,
  2390. struct intel8x0 ** r_intel8x0)
  2391. {
  2392. struct intel8x0 *chip;
  2393. int err;
  2394. unsigned int i;
  2395. unsigned int int_sta_masks;
  2396. struct ichdev *ichdev;
  2397. static struct snd_device_ops ops = {
  2398. .dev_free = snd_intel8x0_dev_free,
  2399. };
  2400. static unsigned int bdbars[] = {
  2401. 3, /* DEVICE_INTEL */
  2402. 6, /* DEVICE_INTEL_ICH4 */
  2403. 3, /* DEVICE_SIS */
  2404. 6, /* DEVICE_ALI */
  2405. 4, /* DEVICE_NFORCE */
  2406. };
  2407. static struct ich_reg_info intel_regs[6] = {
  2408. { ICH_PIINT, 0 },
  2409. { ICH_POINT, 0x10 },
  2410. { ICH_MCINT, 0x20 },
  2411. { ICH_M2INT, 0x40 },
  2412. { ICH_P2INT, 0x50 },
  2413. { ICH_SPINT, 0x60 },
  2414. };
  2415. static struct ich_reg_info nforce_regs[4] = {
  2416. { ICH_PIINT, 0 },
  2417. { ICH_POINT, 0x10 },
  2418. { ICH_MCINT, 0x20 },
  2419. { ICH_NVSPINT, 0x70 },
  2420. };
  2421. static struct ich_reg_info ali_regs[6] = {
  2422. { ALI_INT_PCMIN, 0x40 },
  2423. { ALI_INT_PCMOUT, 0x50 },
  2424. { ALI_INT_MICIN, 0x60 },
  2425. { ALI_INT_CODECSPDIFOUT, 0x70 },
  2426. { ALI_INT_SPDIFIN, 0xa0 },
  2427. { ALI_INT_SPDIFOUT, 0xb0 },
  2428. };
  2429. struct ich_reg_info *tbl;
  2430. *r_intel8x0 = NULL;
  2431. if ((err = pci_enable_device(pci)) < 0)
  2432. return err;
  2433. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2434. if (chip == NULL) {
  2435. pci_disable_device(pci);
  2436. return -ENOMEM;
  2437. }
  2438. spin_lock_init(&chip->reg_lock);
  2439. chip->device_type = device_type;
  2440. chip->card = card;
  2441. chip->pci = pci;
  2442. chip->irq = -1;
  2443. /* module parameters */
  2444. chip->buggy_irq = buggy_irq;
  2445. chip->buggy_semaphore = buggy_semaphore;
  2446. if (xbox)
  2447. chip->xbox = 1;
  2448. if (pci->vendor == PCI_VENDOR_ID_INTEL &&
  2449. pci->device == PCI_DEVICE_ID_INTEL_440MX)
  2450. chip->fix_nocache = 1; /* enable workaround */
  2451. if ((err = pci_request_regions(pci, card->shortname)) < 0) {
  2452. kfree(chip);
  2453. pci_disable_device(pci);
  2454. return err;
  2455. }
  2456. if (device_type == DEVICE_ALI) {
  2457. /* ALI5455 has no ac97 region */
  2458. chip->bmaddr = pci_resource_start(pci, 0);
  2459. goto port_inited;
  2460. }
  2461. if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */
  2462. chip->mmio = 1;
  2463. chip->addr = pci_resource_start(pci, 2);
  2464. chip->remap_addr = ioremap_nocache(chip->addr,
  2465. pci_resource_len(pci, 2));
  2466. if (chip->remap_addr == NULL) {
  2467. snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
  2468. snd_intel8x0_free(chip);
  2469. return -EIO;
  2470. }
  2471. } else {
  2472. chip->addr = pci_resource_start(pci, 0);
  2473. }
  2474. if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */
  2475. chip->bm_mmio = 1;
  2476. chip->bmaddr = pci_resource_start(pci, 3);
  2477. chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
  2478. pci_resource_len(pci, 3));
  2479. if (chip->remap_bmaddr == NULL) {
  2480. snd_printk(KERN_ERR "Controller space ioremap problem\n");
  2481. snd_intel8x0_free(chip);
  2482. return -EIO;
  2483. }
  2484. } else {
  2485. chip->bmaddr = pci_resource_start(pci, 1);
  2486. }
  2487. port_inited:
  2488. chip->bdbars_count = bdbars[device_type];
  2489. /* initialize offsets */
  2490. switch (device_type) {
  2491. case DEVICE_NFORCE:
  2492. tbl = nforce_regs;
  2493. break;
  2494. case DEVICE_ALI:
  2495. tbl = ali_regs;
  2496. break;
  2497. default:
  2498. tbl = intel_regs;
  2499. break;
  2500. }
  2501. for (i = 0; i < chip->bdbars_count; i++) {
  2502. ichdev = &chip->ichd[i];
  2503. ichdev->ichd = i;
  2504. ichdev->reg_offset = tbl[i].offset;
  2505. ichdev->int_sta_mask = tbl[i].int_sta_mask;
  2506. if (device_type == DEVICE_SIS) {
  2507. /* SiS 7012 swaps the registers */
  2508. ichdev->roff_sr = ICH_REG_OFF_PICB;
  2509. ichdev->roff_picb = ICH_REG_OFF_SR;
  2510. } else {
  2511. ichdev->roff_sr = ICH_REG_OFF_SR;
  2512. ichdev->roff_picb = ICH_REG_OFF_PICB;
  2513. }
  2514. if (device_type == DEVICE_ALI)
  2515. ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  2516. /* SIS7012 handles the pcm data in bytes, others are in samples */
  2517. ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  2518. }
  2519. /* allocate buffer descriptor lists */
  2520. /* the start of each lists must be aligned to 8 bytes */
  2521. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  2522. chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
  2523. &chip->bdbars) < 0) {
  2524. snd_intel8x0_free(chip);
  2525. snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n");
  2526. return -ENOMEM;
  2527. }
  2528. /* tables must be aligned to 8 bytes here, but the kernel pages
  2529. are much bigger, so we don't care (on i386) */
  2530. /* workaround for 440MX */
  2531. if (chip->fix_nocache)
  2532. fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
  2533. int_sta_masks = 0;
  2534. for (i = 0; i < chip->bdbars_count; i++) {
  2535. ichdev = &chip->ichd[i];
  2536. ichdev->bdbar = ((u32 *)chip->bdbars.area) +
  2537. (i * ICH_MAX_FRAGS * 2);
  2538. ichdev->bdbar_addr = chip->bdbars.addr +
  2539. (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
  2540. int_sta_masks |= ichdev->int_sta_mask;
  2541. }
  2542. chip->int_sta_reg = device_type == DEVICE_ALI ?
  2543. ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
  2544. chip->int_sta_mask = int_sta_masks;
  2545. /* request irq after initializaing int_sta_mask, etc */
  2546. if (request_irq(pci->irq, snd_intel8x0_interrupt,
  2547. SA_INTERRUPT|SA_SHIRQ, card->shortname, chip)) {
  2548. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  2549. snd_intel8x0_free(chip);
  2550. return -EBUSY;
  2551. }
  2552. chip->irq = pci->irq;
  2553. pci_set_master(pci);
  2554. synchronize_irq(chip->irq);
  2555. if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
  2556. snd_intel8x0_free(chip);
  2557. return err;
  2558. }
  2559. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  2560. snd_intel8x0_free(chip);
  2561. return err;
  2562. }
  2563. snd_card_set_dev(card, &pci->dev);
  2564. *r_intel8x0 = chip;
  2565. return 0;
  2566. }
  2567. static struct shortname_table {
  2568. unsigned int id;
  2569. const char *s;
  2570. } shortnames[] __devinitdata = {
  2571. { PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
  2572. { PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
  2573. { PCI_DEVICE_ID_INTEL_82801BA_4, "Intel 82801BA-ICH2" },
  2574. { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
  2575. { PCI_DEVICE_ID_INTEL_82801CA_5, "Intel 82801CA-ICH3" },
  2576. { PCI_DEVICE_ID_INTEL_82801DB_5, "Intel 82801DB-ICH4" },
  2577. { PCI_DEVICE_ID_INTEL_82801EB_5, "Intel ICH5" },
  2578. { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
  2579. { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
  2580. { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
  2581. { PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
  2582. { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
  2583. { PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO, "NVidia nForce" },
  2584. { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
  2585. { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
  2586. { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
  2587. { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
  2588. { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
  2589. { 0x003a, "NVidia MCP04" },
  2590. { 0x746d, "AMD AMD8111" },
  2591. { 0x7445, "AMD AMD768" },
  2592. { 0x5455, "ALi M5455" },
  2593. { 0, NULL },
  2594. };
  2595. static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
  2596. const struct pci_device_id *pci_id)
  2597. {
  2598. struct snd_card *card;
  2599. struct intel8x0 *chip;
  2600. int err;
  2601. struct shortname_table *name;
  2602. card = snd_card_new(index, id, THIS_MODULE, 0);
  2603. if (card == NULL)
  2604. return -ENOMEM;
  2605. switch (pci_id->driver_data) {
  2606. case DEVICE_NFORCE:
  2607. strcpy(card->driver, "NFORCE");
  2608. break;
  2609. case DEVICE_INTEL_ICH4:
  2610. strcpy(card->driver, "ICH4");
  2611. break;
  2612. default:
  2613. strcpy(card->driver, "ICH");
  2614. break;
  2615. }
  2616. strcpy(card->shortname, "Intel ICH");
  2617. for (name = shortnames; name->id; name++) {
  2618. if (pci->device == name->id) {
  2619. strcpy(card->shortname, name->s);
  2620. break;
  2621. }
  2622. }
  2623. if (buggy_irq < 0) {
  2624. /* some Nforce[2] and ICH boards have problems with IRQ handling.
  2625. * Needs to return IRQ_HANDLED for unknown irqs.
  2626. */
  2627. if (pci_id->driver_data == DEVICE_NFORCE)
  2628. buggy_irq = 1;
  2629. else
  2630. buggy_irq = 0;
  2631. }
  2632. if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
  2633. &chip)) < 0) {
  2634. snd_card_free(card);
  2635. return err;
  2636. }
  2637. card->private_data = chip;
  2638. if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) {
  2639. snd_card_free(card);
  2640. return err;
  2641. }
  2642. if ((err = snd_intel8x0_pcm(chip)) < 0) {
  2643. snd_card_free(card);
  2644. return err;
  2645. }
  2646. snd_intel8x0_proc_init(chip);
  2647. snprintf(card->longname, sizeof(card->longname),
  2648. "%s with %s at %#lx, irq %i", card->shortname,
  2649. snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
  2650. if (! ac97_clock)
  2651. intel8x0_measure_ac97_clock(chip);
  2652. if ((err = snd_card_register(card)) < 0) {
  2653. snd_card_free(card);
  2654. return err;
  2655. }
  2656. pci_set_drvdata(pci, card);
  2657. return 0;
  2658. }
  2659. static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
  2660. {
  2661. snd_card_free(pci_get_drvdata(pci));
  2662. pci_set_drvdata(pci, NULL);
  2663. }
  2664. static struct pci_driver driver = {
  2665. .name = "Intel ICH",
  2666. .id_table = snd_intel8x0_ids,
  2667. .probe = snd_intel8x0_probe,
  2668. .remove = __devexit_p(snd_intel8x0_remove),
  2669. #ifdef CONFIG_PM
  2670. .suspend = intel8x0_suspend,
  2671. .resume = intel8x0_resume,
  2672. #endif
  2673. };
  2674. static int __init alsa_card_intel8x0_init(void)
  2675. {
  2676. return pci_register_driver(&driver);
  2677. }
  2678. static void __exit alsa_card_intel8x0_exit(void)
  2679. {
  2680. pci_unregister_driver(&driver);
  2681. }
  2682. module_init(alsa_card_intel8x0_init)
  2683. module_exit(alsa_card_intel8x0_exit)