intel8x0.c 88 KB

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