intel8x0.c 82 KB

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