intel8x0.c 86 KB

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