intel8x0.c 88 KB

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