intel8x0.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199
  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 <perex@perex.cz>
  6. *
  7. * This code also contains alpha support for SiS 735 chipsets provided
  8. * by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
  9. * for SiS735, so the code is not fully functional.
  10. *
  11. */
  12. #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 <perex@perex.cz>");
  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. step = 1;
  625. ichdev->civ++;
  626. ichdev->civ &= ICH_REG_LVI_MASK;
  627. } else {
  628. step = civ - ichdev->civ;
  629. if (step < 0)
  630. step += ICH_REG_LVI_MASK + 1;
  631. ichdev->civ = civ;
  632. }
  633. ichdev->position += step * ichdev->fragsize1;
  634. if (! chip->in_measurement)
  635. ichdev->position %= ichdev->size;
  636. ichdev->lvi += step;
  637. ichdev->lvi &= ICH_REG_LVI_MASK;
  638. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  639. for (i = 0; i < step; i++) {
  640. ichdev->lvi_frag++;
  641. ichdev->lvi_frag %= ichdev->frags;
  642. ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
  643. #if 0
  644. dev_dbg(chip->card->dev,
  645. "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
  646. ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
  647. ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
  648. inl(port + 4), inb(port + ICH_REG_OFF_CR));
  649. #endif
  650. if (--ichdev->ack == 0) {
  651. ichdev->ack = ichdev->ack_reload;
  652. ack = 1;
  653. }
  654. }
  655. spin_unlock_irqrestore(&chip->reg_lock, flags);
  656. if (ack && ichdev->substream) {
  657. snd_pcm_period_elapsed(ichdev->substream);
  658. }
  659. iputbyte(chip, port + ichdev->roff_sr,
  660. status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
  661. }
  662. static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id)
  663. {
  664. struct intel8x0 *chip = dev_id;
  665. struct ichdev *ichdev;
  666. unsigned int status;
  667. unsigned int i;
  668. status = igetdword(chip, chip->int_sta_reg);
  669. if (status == 0xffffffff) /* we are not yet resumed */
  670. return IRQ_NONE;
  671. if ((status & chip->int_sta_mask) == 0) {
  672. if (status) {
  673. /* ack */
  674. iputdword(chip, chip->int_sta_reg, status);
  675. if (! chip->buggy_irq)
  676. status = 0;
  677. }
  678. return IRQ_RETVAL(status);
  679. }
  680. for (i = 0; i < chip->bdbars_count; i++) {
  681. ichdev = &chip->ichd[i];
  682. if (status & ichdev->int_sta_mask)
  683. snd_intel8x0_update(chip, ichdev);
  684. }
  685. /* ack them */
  686. iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  687. return IRQ_HANDLED;
  688. }
  689. /*
  690. * PCM part
  691. */
  692. static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  693. {
  694. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  695. struct ichdev *ichdev = get_ichdev(substream);
  696. unsigned char val = 0;
  697. unsigned long port = ichdev->reg_offset;
  698. switch (cmd) {
  699. case SNDRV_PCM_TRIGGER_RESUME:
  700. ichdev->suspended = 0;
  701. fallthrough;
  702. case SNDRV_PCM_TRIGGER_START:
  703. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  704. val = ICH_IOCE | ICH_STARTBM;
  705. ichdev->last_pos = ichdev->position;
  706. break;
  707. case SNDRV_PCM_TRIGGER_SUSPEND:
  708. ichdev->suspended = 1;
  709. fallthrough;
  710. case SNDRV_PCM_TRIGGER_STOP:
  711. val = 0;
  712. break;
  713. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  714. val = ICH_IOCE;
  715. break;
  716. default:
  717. return -EINVAL;
  718. }
  719. iputbyte(chip, port + ICH_REG_OFF_CR, val);
  720. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  721. /* wait until DMA stopped */
  722. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  723. /* reset whole DMA things */
  724. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  725. }
  726. return 0;
  727. }
  728. static int snd_intel8x0_ali_trigger(struct snd_pcm_substream *substream, int cmd)
  729. {
  730. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  731. struct ichdev *ichdev = get_ichdev(substream);
  732. unsigned long port = ichdev->reg_offset;
  733. static const int fiforeg[] = {
  734. ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3)
  735. };
  736. unsigned int val, fifo;
  737. val = igetdword(chip, ICHREG(ALI_DMACR));
  738. switch (cmd) {
  739. case SNDRV_PCM_TRIGGER_RESUME:
  740. ichdev->suspended = 0;
  741. fallthrough;
  742. case SNDRV_PCM_TRIGGER_START:
  743. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  744. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  745. /* clear FIFO for synchronization of channels */
  746. fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
  747. fifo &= ~(0xff << (ichdev->ali_slot % 4));
  748. fifo |= 0x83 << (ichdev->ali_slot % 4);
  749. iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
  750. }
  751. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  752. val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
  753. /* start DMA */
  754. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot));
  755. break;
  756. case SNDRV_PCM_TRIGGER_SUSPEND:
  757. ichdev->suspended = 1;
  758. fallthrough;
  759. case SNDRV_PCM_TRIGGER_STOP:
  760. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  761. /* pause */
  762. iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16)));
  763. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  764. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  765. ;
  766. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  767. break;
  768. /* reset whole DMA things */
  769. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  770. /* clear interrupts */
  771. iputbyte(chip, port + ICH_REG_OFF_SR,
  772. igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
  773. iputdword(chip, ICHREG(ALI_INTERRUPTSR),
  774. igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
  775. break;
  776. default:
  777. return -EINVAL;
  778. }
  779. return 0;
  780. }
  781. static int snd_intel8x0_hw_params(struct snd_pcm_substream *substream,
  782. struct snd_pcm_hw_params *hw_params)
  783. {
  784. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  785. struct ichdev *ichdev = get_ichdev(substream);
  786. int dbl = params_rate(hw_params) > 48000;
  787. int err;
  788. if (ichdev->pcm_open_flag) {
  789. snd_ac97_pcm_close(ichdev->pcm);
  790. ichdev->pcm_open_flag = 0;
  791. ichdev->prepared = 0;
  792. }
  793. err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
  794. params_channels(hw_params),
  795. ichdev->pcm->r[dbl].slots);
  796. if (err >= 0) {
  797. ichdev->pcm_open_flag = 1;
  798. /* Force SPDIF setting */
  799. if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
  800. snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF,
  801. params_rate(hw_params));
  802. }
  803. return err;
  804. }
  805. static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
  806. {
  807. struct ichdev *ichdev = get_ichdev(substream);
  808. if (ichdev->pcm_open_flag) {
  809. snd_ac97_pcm_close(ichdev->pcm);
  810. ichdev->pcm_open_flag = 0;
  811. ichdev->prepared = 0;
  812. }
  813. return 0;
  814. }
  815. static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
  816. struct snd_pcm_runtime *runtime)
  817. {
  818. unsigned int cnt;
  819. int dbl = runtime->rate > 48000;
  820. spin_lock_irq(&chip->reg_lock);
  821. switch (chip->device_type) {
  822. case DEVICE_ALI:
  823. cnt = igetdword(chip, ICHREG(ALI_SCR));
  824. cnt &= ~ICH_ALI_SC_PCM_246_MASK;
  825. if (runtime->channels == 4 || dbl)
  826. cnt |= ICH_ALI_SC_PCM_4;
  827. else if (runtime->channels == 6)
  828. cnt |= ICH_ALI_SC_PCM_6;
  829. iputdword(chip, ICHREG(ALI_SCR), cnt);
  830. break;
  831. case DEVICE_SIS:
  832. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  833. cnt &= ~ICH_SIS_PCM_246_MASK;
  834. if (runtime->channels == 4 || dbl)
  835. cnt |= ICH_SIS_PCM_4;
  836. else if (runtime->channels == 6)
  837. cnt |= ICH_SIS_PCM_6;
  838. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  839. break;
  840. default:
  841. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  842. cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
  843. if (runtime->channels == 4 || dbl)
  844. cnt |= ICH_PCM_4;
  845. else if (runtime->channels == 6)
  846. cnt |= ICH_PCM_6;
  847. else if (runtime->channels == 8)
  848. cnt |= ICH_PCM_8;
  849. if (chip->device_type == DEVICE_NFORCE) {
  850. /* reset to 2ch once to keep the 6 channel data in alignment,
  851. * to start from Front Left always
  852. */
  853. if (cnt & ICH_PCM_246_MASK) {
  854. iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
  855. spin_unlock_irq(&chip->reg_lock);
  856. msleep(50); /* grrr... */
  857. spin_lock_irq(&chip->reg_lock);
  858. }
  859. } else if (chip->device_type == DEVICE_INTEL_ICH4) {
  860. if (runtime->sample_bits > 16)
  861. cnt |= ICH_PCM_20BIT;
  862. }
  863. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  864. break;
  865. }
  866. spin_unlock_irq(&chip->reg_lock);
  867. }
  868. static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
  869. {
  870. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  871. struct snd_pcm_runtime *runtime = substream->runtime;
  872. struct ichdev *ichdev = get_ichdev(substream);
  873. ichdev->physbuf = runtime->dma_addr;
  874. ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  875. ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
  876. if (ichdev->ichd == ICHD_PCMOUT) {
  877. snd_intel8x0_setup_pcm_out(chip, runtime);
  878. if (chip->device_type == DEVICE_INTEL_ICH4)
  879. ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
  880. }
  881. snd_intel8x0_setup_periods(chip, ichdev);
  882. ichdev->prepared = 1;
  883. return 0;
  884. }
  885. static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *substream)
  886. {
  887. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  888. struct ichdev *ichdev = get_ichdev(substream);
  889. size_t ptr1, ptr;
  890. int civ, timeout = 10;
  891. unsigned int position;
  892. spin_lock(&chip->reg_lock);
  893. do {
  894. civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  895. ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  896. position = ichdev->position;
  897. if (ptr1 == 0) {
  898. udelay(10);
  899. continue;
  900. }
  901. if (civ != igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV))
  902. continue;
  903. /* IO read operation is very expensive inside virtual machine
  904. * as it is emulated. The probability that subsequent PICB read
  905. * will return different result is high enough to loop till
  906. * timeout here.
  907. * Same CIV is strict enough condition to be sure that PICB
  908. * is valid inside VM on emulated card. */
  909. if (chip->inside_vm)
  910. break;
  911. if (ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  912. break;
  913. } while (timeout--);
  914. ptr = ichdev->last_pos;
  915. if (ptr1 != 0) {
  916. ptr1 <<= ichdev->pos_shift;
  917. ptr = ichdev->fragsize1 - ptr1;
  918. ptr += position;
  919. if (ptr < ichdev->last_pos) {
  920. unsigned int pos_base, last_base;
  921. pos_base = position / ichdev->fragsize1;
  922. last_base = ichdev->last_pos / ichdev->fragsize1;
  923. /* another sanity check; ptr1 can go back to full
  924. * before the base position is updated
  925. */
  926. if (pos_base == last_base)
  927. ptr = ichdev->last_pos;
  928. }
  929. }
  930. ichdev->last_pos = ptr;
  931. spin_unlock(&chip->reg_lock);
  932. if (ptr >= ichdev->size)
  933. return 0;
  934. return bytes_to_frames(substream->runtime, ptr);
  935. }
  936. static const struct snd_pcm_hardware snd_intel8x0_stream =
  937. {
  938. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  939. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  940. SNDRV_PCM_INFO_MMAP_VALID |
  941. SNDRV_PCM_INFO_PAUSE |
  942. SNDRV_PCM_INFO_RESUME),
  943. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  944. .rates = SNDRV_PCM_RATE_48000,
  945. .rate_min = 48000,
  946. .rate_max = 48000,
  947. .channels_min = 2,
  948. .channels_max = 2,
  949. .buffer_bytes_max = 128 * 1024,
  950. .period_bytes_min = 32,
  951. .period_bytes_max = 128 * 1024,
  952. .periods_min = 1,
  953. .periods_max = 1024,
  954. .fifo_size = 0,
  955. };
  956. static const unsigned int channels4[] = {
  957. 2, 4,
  958. };
  959. static const struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
  960. .count = ARRAY_SIZE(channels4),
  961. .list = channels4,
  962. .mask = 0,
  963. };
  964. static const unsigned int channels6[] = {
  965. 2, 4, 6,
  966. };
  967. static const struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
  968. .count = ARRAY_SIZE(channels6),
  969. .list = channels6,
  970. .mask = 0,
  971. };
  972. static const unsigned int channels8[] = {
  973. 2, 4, 6, 8,
  974. };
  975. static const struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
  976. .count = ARRAY_SIZE(channels8),
  977. .list = channels8,
  978. .mask = 0,
  979. };
  980. static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
  981. {
  982. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  983. struct snd_pcm_runtime *runtime = substream->runtime;
  984. int err;
  985. ichdev->substream = substream;
  986. runtime->hw = snd_intel8x0_stream;
  987. runtime->hw.rates = ichdev->pcm->rates;
  988. snd_pcm_limit_hw_rates(runtime);
  989. if (chip->device_type == DEVICE_SIS) {
  990. runtime->hw.buffer_bytes_max = 64*1024;
  991. runtime->hw.period_bytes_max = 64*1024;
  992. }
  993. err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  994. if (err < 0)
  995. return err;
  996. runtime->private_data = ichdev;
  997. return 0;
  998. }
  999. static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
  1000. {
  1001. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1002. struct snd_pcm_runtime *runtime = substream->runtime;
  1003. int err;
  1004. err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
  1005. if (err < 0)
  1006. return err;
  1007. if (chip->multi8) {
  1008. runtime->hw.channels_max = 8;
  1009. snd_pcm_hw_constraint_list(runtime, 0,
  1010. SNDRV_PCM_HW_PARAM_CHANNELS,
  1011. &hw_constraints_channels8);
  1012. } else if (chip->multi6) {
  1013. runtime->hw.channels_max = 6;
  1014. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  1015. &hw_constraints_channels6);
  1016. } else if (chip->multi4) {
  1017. runtime->hw.channels_max = 4;
  1018. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  1019. &hw_constraints_channels4);
  1020. }
  1021. if (chip->dra) {
  1022. snd_ac97_pcm_double_rate_rules(runtime);
  1023. }
  1024. if (chip->smp20bit) {
  1025. runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
  1026. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
  1027. }
  1028. return 0;
  1029. }
  1030. static int snd_intel8x0_playback_close(struct snd_pcm_substream *substream)
  1031. {
  1032. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1033. chip->ichd[ICHD_PCMOUT].substream = NULL;
  1034. return 0;
  1035. }
  1036. static int snd_intel8x0_capture_open(struct snd_pcm_substream *substream)
  1037. {
  1038. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1039. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
  1040. }
  1041. static int snd_intel8x0_capture_close(struct snd_pcm_substream *substream)
  1042. {
  1043. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1044. chip->ichd[ICHD_PCMIN].substream = NULL;
  1045. return 0;
  1046. }
  1047. static int snd_intel8x0_mic_open(struct snd_pcm_substream *substream)
  1048. {
  1049. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1050. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
  1051. }
  1052. static int snd_intel8x0_mic_close(struct snd_pcm_substream *substream)
  1053. {
  1054. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1055. chip->ichd[ICHD_MIC].substream = NULL;
  1056. return 0;
  1057. }
  1058. static int snd_intel8x0_mic2_open(struct snd_pcm_substream *substream)
  1059. {
  1060. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1061. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
  1062. }
  1063. static int snd_intel8x0_mic2_close(struct snd_pcm_substream *substream)
  1064. {
  1065. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1066. chip->ichd[ICHD_MIC2].substream = NULL;
  1067. return 0;
  1068. }
  1069. static int snd_intel8x0_capture2_open(struct snd_pcm_substream *substream)
  1070. {
  1071. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1072. return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
  1073. }
  1074. static int snd_intel8x0_capture2_close(struct snd_pcm_substream *substream)
  1075. {
  1076. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1077. chip->ichd[ICHD_PCM2IN].substream = NULL;
  1078. return 0;
  1079. }
  1080. static int snd_intel8x0_spdif_open(struct snd_pcm_substream *substream)
  1081. {
  1082. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1083. int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  1084. return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
  1085. }
  1086. static int snd_intel8x0_spdif_close(struct snd_pcm_substream *substream)
  1087. {
  1088. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1089. int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  1090. chip->ichd[idx].substream = NULL;
  1091. return 0;
  1092. }
  1093. static int snd_intel8x0_ali_ac97spdifout_open(struct snd_pcm_substream *substream)
  1094. {
  1095. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1096. unsigned int val;
  1097. spin_lock_irq(&chip->reg_lock);
  1098. val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  1099. val |= ICH_ALI_IF_AC97SP;
  1100. iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  1101. /* also needs to set ALI_SC_CODEC_SPDF correctly */
  1102. spin_unlock_irq(&chip->reg_lock);
  1103. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
  1104. }
  1105. static int snd_intel8x0_ali_ac97spdifout_close(struct snd_pcm_substream *substream)
  1106. {
  1107. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1108. unsigned int val;
  1109. chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
  1110. spin_lock_irq(&chip->reg_lock);
  1111. val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  1112. val &= ~ICH_ALI_IF_AC97SP;
  1113. iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  1114. spin_unlock_irq(&chip->reg_lock);
  1115. return 0;
  1116. }
  1117. #if 0 // NYI
  1118. static int snd_intel8x0_ali_spdifin_open(struct snd_pcm_substream *substream)
  1119. {
  1120. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1121. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
  1122. }
  1123. static int snd_intel8x0_ali_spdifin_close(struct snd_pcm_substream *substream)
  1124. {
  1125. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1126. chip->ichd[ALID_SPDIFIN].substream = NULL;
  1127. return 0;
  1128. }
  1129. static int snd_intel8x0_ali_spdifout_open(struct snd_pcm_substream *substream)
  1130. {
  1131. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1132. return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
  1133. }
  1134. static int snd_intel8x0_ali_spdifout_close(struct snd_pcm_substream *substream)
  1135. {
  1136. struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  1137. chip->ichd[ALID_SPDIFOUT].substream = NULL;
  1138. return 0;
  1139. }
  1140. #endif
  1141. static const struct snd_pcm_ops snd_intel8x0_playback_ops = {
  1142. .open = snd_intel8x0_playback_open,
  1143. .close = snd_intel8x0_playback_close,
  1144. .hw_params = snd_intel8x0_hw_params,
  1145. .hw_free = snd_intel8x0_hw_free,
  1146. .prepare = snd_intel8x0_pcm_prepare,
  1147. .trigger = snd_intel8x0_pcm_trigger,
  1148. .pointer = snd_intel8x0_pcm_pointer,
  1149. };
  1150. static const struct snd_pcm_ops snd_intel8x0_capture_ops = {
  1151. .open = snd_intel8x0_capture_open,
  1152. .close = snd_intel8x0_capture_close,
  1153. .hw_params = snd_intel8x0_hw_params,
  1154. .hw_free = snd_intel8x0_hw_free,
  1155. .prepare = snd_intel8x0_pcm_prepare,
  1156. .trigger = snd_intel8x0_pcm_trigger,
  1157. .pointer = snd_intel8x0_pcm_pointer,
  1158. };
  1159. static const struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
  1160. .open = snd_intel8x0_mic_open,
  1161. .close = snd_intel8x0_mic_close,
  1162. .hw_params = snd_intel8x0_hw_params,
  1163. .hw_free = snd_intel8x0_hw_free,
  1164. .prepare = snd_intel8x0_pcm_prepare,
  1165. .trigger = snd_intel8x0_pcm_trigger,
  1166. .pointer = snd_intel8x0_pcm_pointer,
  1167. };
  1168. static const struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
  1169. .open = snd_intel8x0_mic2_open,
  1170. .close = snd_intel8x0_mic2_close,
  1171. .hw_params = snd_intel8x0_hw_params,
  1172. .hw_free = snd_intel8x0_hw_free,
  1173. .prepare = snd_intel8x0_pcm_prepare,
  1174. .trigger = snd_intel8x0_pcm_trigger,
  1175. .pointer = snd_intel8x0_pcm_pointer,
  1176. };
  1177. static const struct snd_pcm_ops snd_intel8x0_capture2_ops = {
  1178. .open = snd_intel8x0_capture2_open,
  1179. .close = snd_intel8x0_capture2_close,
  1180. .hw_params = snd_intel8x0_hw_params,
  1181. .hw_free = snd_intel8x0_hw_free,
  1182. .prepare = snd_intel8x0_pcm_prepare,
  1183. .trigger = snd_intel8x0_pcm_trigger,
  1184. .pointer = snd_intel8x0_pcm_pointer,
  1185. };
  1186. static const struct snd_pcm_ops snd_intel8x0_spdif_ops = {
  1187. .open = snd_intel8x0_spdif_open,
  1188. .close = snd_intel8x0_spdif_close,
  1189. .hw_params = snd_intel8x0_hw_params,
  1190. .hw_free = snd_intel8x0_hw_free,
  1191. .prepare = snd_intel8x0_pcm_prepare,
  1192. .trigger = snd_intel8x0_pcm_trigger,
  1193. .pointer = snd_intel8x0_pcm_pointer,
  1194. };
  1195. static const struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
  1196. .open = snd_intel8x0_playback_open,
  1197. .close = snd_intel8x0_playback_close,
  1198. .hw_params = snd_intel8x0_hw_params,
  1199. .hw_free = snd_intel8x0_hw_free,
  1200. .prepare = snd_intel8x0_pcm_prepare,
  1201. .trigger = snd_intel8x0_ali_trigger,
  1202. .pointer = snd_intel8x0_pcm_pointer,
  1203. };
  1204. static const struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
  1205. .open = snd_intel8x0_capture_open,
  1206. .close = snd_intel8x0_capture_close,
  1207. .hw_params = snd_intel8x0_hw_params,
  1208. .hw_free = snd_intel8x0_hw_free,
  1209. .prepare = snd_intel8x0_pcm_prepare,
  1210. .trigger = snd_intel8x0_ali_trigger,
  1211. .pointer = snd_intel8x0_pcm_pointer,
  1212. };
  1213. static const struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
  1214. .open = snd_intel8x0_mic_open,
  1215. .close = snd_intel8x0_mic_close,
  1216. .hw_params = snd_intel8x0_hw_params,
  1217. .hw_free = snd_intel8x0_hw_free,
  1218. .prepare = snd_intel8x0_pcm_prepare,
  1219. .trigger = snd_intel8x0_ali_trigger,
  1220. .pointer = snd_intel8x0_pcm_pointer,
  1221. };
  1222. static const struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
  1223. .open = snd_intel8x0_ali_ac97spdifout_open,
  1224. .close = snd_intel8x0_ali_ac97spdifout_close,
  1225. .hw_params = snd_intel8x0_hw_params,
  1226. .hw_free = snd_intel8x0_hw_free,
  1227. .prepare = snd_intel8x0_pcm_prepare,
  1228. .trigger = snd_intel8x0_ali_trigger,
  1229. .pointer = snd_intel8x0_pcm_pointer,
  1230. };
  1231. #if 0 // NYI
  1232. static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
  1233. .open = snd_intel8x0_ali_spdifin_open,
  1234. .close = snd_intel8x0_ali_spdifin_close,
  1235. .hw_params = snd_intel8x0_hw_params,
  1236. .hw_free = snd_intel8x0_hw_free,
  1237. .prepare = snd_intel8x0_pcm_prepare,
  1238. .trigger = snd_intel8x0_pcm_trigger,
  1239. .pointer = snd_intel8x0_pcm_pointer,
  1240. };
  1241. static struct snd_pcm_ops snd_intel8x0_ali_spdifout_ops = {
  1242. .open = snd_intel8x0_ali_spdifout_open,
  1243. .close = snd_intel8x0_ali_spdifout_close,
  1244. .hw_params = snd_intel8x0_hw_params,
  1245. .hw_free = snd_intel8x0_hw_free,
  1246. .prepare = snd_intel8x0_pcm_prepare,
  1247. .trigger = snd_intel8x0_pcm_trigger,
  1248. .pointer = snd_intel8x0_pcm_pointer,
  1249. };
  1250. #endif // NYI
  1251. struct ich_pcm_table {
  1252. char *suffix;
  1253. const struct snd_pcm_ops *playback_ops;
  1254. const struct snd_pcm_ops *capture_ops;
  1255. size_t prealloc_size;
  1256. size_t prealloc_max_size;
  1257. int ac97_idx;
  1258. };
  1259. #define intel8x0_dma_type(chip) \
  1260. ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_WC : SNDRV_DMA_TYPE_DEV)
  1261. static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
  1262. const struct ich_pcm_table *rec)
  1263. {
  1264. struct snd_pcm *pcm;
  1265. int err;
  1266. char name[32];
  1267. if (rec->suffix)
  1268. sprintf(name, "Intel ICH - %s", rec->suffix);
  1269. else
  1270. strcpy(name, "Intel ICH");
  1271. err = snd_pcm_new(chip->card, name, device,
  1272. rec->playback_ops ? 1 : 0,
  1273. rec->capture_ops ? 1 : 0, &pcm);
  1274. if (err < 0)
  1275. return err;
  1276. if (rec->playback_ops)
  1277. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
  1278. if (rec->capture_ops)
  1279. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
  1280. pcm->private_data = chip;
  1281. pcm->info_flags = 0;
  1282. if (rec->suffix)
  1283. sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
  1284. else
  1285. strcpy(pcm->name, chip->card->shortname);
  1286. chip->pcm[device] = pcm;
  1287. snd_pcm_set_managed_buffer_all(pcm, intel8x0_dma_type(chip),
  1288. &chip->pci->dev,
  1289. rec->prealloc_size, rec->prealloc_max_size);
  1290. if (rec->playback_ops &&
  1291. rec->playback_ops->open == snd_intel8x0_playback_open) {
  1292. struct snd_pcm_chmap *chmap;
  1293. int chs = 2;
  1294. if (chip->multi8)
  1295. chs = 8;
  1296. else if (chip->multi6)
  1297. chs = 6;
  1298. else if (chip->multi4)
  1299. chs = 4;
  1300. err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1301. snd_pcm_alt_chmaps, chs, 0,
  1302. &chmap);
  1303. if (err < 0)
  1304. return err;
  1305. chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
  1306. chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
  1307. }
  1308. return 0;
  1309. }
  1310. static const struct ich_pcm_table intel_pcms[] = {
  1311. {
  1312. .playback_ops = &snd_intel8x0_playback_ops,
  1313. .capture_ops = &snd_intel8x0_capture_ops,
  1314. .prealloc_size = 64 * 1024,
  1315. .prealloc_max_size = 128 * 1024,
  1316. },
  1317. {
  1318. .suffix = "MIC ADC",
  1319. .capture_ops = &snd_intel8x0_capture_mic_ops,
  1320. .prealloc_size = 0,
  1321. .prealloc_max_size = 128 * 1024,
  1322. .ac97_idx = ICHD_MIC,
  1323. },
  1324. {
  1325. .suffix = "MIC2 ADC",
  1326. .capture_ops = &snd_intel8x0_capture_mic2_ops,
  1327. .prealloc_size = 0,
  1328. .prealloc_max_size = 128 * 1024,
  1329. .ac97_idx = ICHD_MIC2,
  1330. },
  1331. {
  1332. .suffix = "ADC2",
  1333. .capture_ops = &snd_intel8x0_capture2_ops,
  1334. .prealloc_size = 0,
  1335. .prealloc_max_size = 128 * 1024,
  1336. .ac97_idx = ICHD_PCM2IN,
  1337. },
  1338. {
  1339. .suffix = "IEC958",
  1340. .playback_ops = &snd_intel8x0_spdif_ops,
  1341. .prealloc_size = 64 * 1024,
  1342. .prealloc_max_size = 128 * 1024,
  1343. .ac97_idx = ICHD_SPBAR,
  1344. },
  1345. };
  1346. static const struct ich_pcm_table nforce_pcms[] = {
  1347. {
  1348. .playback_ops = &snd_intel8x0_playback_ops,
  1349. .capture_ops = &snd_intel8x0_capture_ops,
  1350. .prealloc_size = 64 * 1024,
  1351. .prealloc_max_size = 128 * 1024,
  1352. },
  1353. {
  1354. .suffix = "MIC ADC",
  1355. .capture_ops = &snd_intel8x0_capture_mic_ops,
  1356. .prealloc_size = 0,
  1357. .prealloc_max_size = 128 * 1024,
  1358. .ac97_idx = NVD_MIC,
  1359. },
  1360. {
  1361. .suffix = "IEC958",
  1362. .playback_ops = &snd_intel8x0_spdif_ops,
  1363. .prealloc_size = 64 * 1024,
  1364. .prealloc_max_size = 128 * 1024,
  1365. .ac97_idx = NVD_SPBAR,
  1366. },
  1367. };
  1368. static const struct ich_pcm_table ali_pcms[] = {
  1369. {
  1370. .playback_ops = &snd_intel8x0_ali_playback_ops,
  1371. .capture_ops = &snd_intel8x0_ali_capture_ops,
  1372. .prealloc_size = 64 * 1024,
  1373. .prealloc_max_size = 128 * 1024,
  1374. },
  1375. {
  1376. .suffix = "MIC ADC",
  1377. .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
  1378. .prealloc_size = 0,
  1379. .prealloc_max_size = 128 * 1024,
  1380. .ac97_idx = ALID_MIC,
  1381. },
  1382. {
  1383. .suffix = "IEC958",
  1384. .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
  1385. /* .capture_ops = &snd_intel8x0_ali_spdifin_ops, */
  1386. .prealloc_size = 64 * 1024,
  1387. .prealloc_max_size = 128 * 1024,
  1388. .ac97_idx = ALID_AC97SPDIFOUT,
  1389. },
  1390. #if 0 // NYI
  1391. {
  1392. .suffix = "HW IEC958",
  1393. .playback_ops = &snd_intel8x0_ali_spdifout_ops,
  1394. .prealloc_size = 64 * 1024,
  1395. .prealloc_max_size = 128 * 1024,
  1396. },
  1397. #endif
  1398. };
  1399. static int snd_intel8x0_pcm(struct intel8x0 *chip)
  1400. {
  1401. int i, tblsize, device, err;
  1402. const struct ich_pcm_table *tbl, *rec;
  1403. switch (chip->device_type) {
  1404. case DEVICE_INTEL_ICH4:
  1405. tbl = intel_pcms;
  1406. tblsize = ARRAY_SIZE(intel_pcms);
  1407. if (spdif_aclink)
  1408. tblsize--;
  1409. break;
  1410. case DEVICE_NFORCE:
  1411. tbl = nforce_pcms;
  1412. tblsize = ARRAY_SIZE(nforce_pcms);
  1413. if (spdif_aclink)
  1414. tblsize--;
  1415. break;
  1416. case DEVICE_ALI:
  1417. tbl = ali_pcms;
  1418. tblsize = ARRAY_SIZE(ali_pcms);
  1419. break;
  1420. default:
  1421. tbl = intel_pcms;
  1422. tblsize = 2;
  1423. break;
  1424. }
  1425. device = 0;
  1426. for (i = 0; i < tblsize; i++) {
  1427. rec = tbl + i;
  1428. if (i > 0 && rec->ac97_idx) {
  1429. /* activate PCM only when associated AC'97 codec */
  1430. if (! chip->ichd[rec->ac97_idx].pcm)
  1431. continue;
  1432. }
  1433. err = snd_intel8x0_pcm1(chip, device, rec);
  1434. if (err < 0)
  1435. return err;
  1436. device++;
  1437. }
  1438. chip->pcm_devs = device;
  1439. return 0;
  1440. }
  1441. /*
  1442. * Mixer part
  1443. */
  1444. static void snd_intel8x0_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  1445. {
  1446. struct intel8x0 *chip = bus->private_data;
  1447. chip->ac97_bus = NULL;
  1448. }
  1449. static void snd_intel8x0_mixer_free_ac97(struct snd_ac97 *ac97)
  1450. {
  1451. struct intel8x0 *chip = ac97->private_data;
  1452. chip->ac97[ac97->num] = NULL;
  1453. }
  1454. static const struct ac97_pcm ac97_pcm_defs[] = {
  1455. /* front PCM */
  1456. {
  1457. .exclusive = 1,
  1458. .r = { {
  1459. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1460. (1 << AC97_SLOT_PCM_RIGHT) |
  1461. (1 << AC97_SLOT_PCM_CENTER) |
  1462. (1 << AC97_SLOT_PCM_SLEFT) |
  1463. (1 << AC97_SLOT_PCM_SRIGHT) |
  1464. (1 << AC97_SLOT_LFE)
  1465. },
  1466. {
  1467. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1468. (1 << AC97_SLOT_PCM_RIGHT) |
  1469. (1 << AC97_SLOT_PCM_LEFT_0) |
  1470. (1 << AC97_SLOT_PCM_RIGHT_0)
  1471. }
  1472. }
  1473. },
  1474. /* PCM IN #1 */
  1475. {
  1476. .stream = 1,
  1477. .exclusive = 1,
  1478. .r = { {
  1479. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1480. (1 << AC97_SLOT_PCM_RIGHT)
  1481. }
  1482. }
  1483. },
  1484. /* MIC IN #1 */
  1485. {
  1486. .stream = 1,
  1487. .exclusive = 1,
  1488. .r = { {
  1489. .slots = (1 << AC97_SLOT_MIC)
  1490. }
  1491. }
  1492. },
  1493. /* S/PDIF PCM */
  1494. {
  1495. .exclusive = 1,
  1496. .spdif = 1,
  1497. .r = { {
  1498. .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
  1499. (1 << AC97_SLOT_SPDIF_RIGHT2)
  1500. }
  1501. }
  1502. },
  1503. /* PCM IN #2 */
  1504. {
  1505. .stream = 1,
  1506. .exclusive = 1,
  1507. .r = { {
  1508. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1509. (1 << AC97_SLOT_PCM_RIGHT)
  1510. }
  1511. }
  1512. },
  1513. /* MIC IN #2 */
  1514. {
  1515. .stream = 1,
  1516. .exclusive = 1,
  1517. .r = { {
  1518. .slots = (1 << AC97_SLOT_MIC)
  1519. }
  1520. }
  1521. },
  1522. };
  1523. static const struct ac97_quirk ac97_quirks[] = {
  1524. {
  1525. .subvendor = 0x0e11,
  1526. .subdevice = 0x000e,
  1527. .name = "Compaq Deskpro EN", /* AD1885 */
  1528. .type = AC97_TUNE_HP_ONLY
  1529. },
  1530. {
  1531. .subvendor = 0x0e11,
  1532. .subdevice = 0x008a,
  1533. .name = "Compaq Evo W4000", /* AD1885 */
  1534. .type = AC97_TUNE_HP_ONLY
  1535. },
  1536. {
  1537. .subvendor = 0x0e11,
  1538. .subdevice = 0x00b8,
  1539. .name = "Compaq Evo D510C",
  1540. .type = AC97_TUNE_HP_ONLY
  1541. },
  1542. {
  1543. .subvendor = 0x0e11,
  1544. .subdevice = 0x0860,
  1545. .name = "HP/Compaq nx7010",
  1546. .type = AC97_TUNE_MUTE_LED
  1547. },
  1548. {
  1549. .subvendor = 0x1014,
  1550. .subdevice = 0x0534,
  1551. .name = "ThinkPad X31",
  1552. .type = AC97_TUNE_INV_EAPD
  1553. },
  1554. {
  1555. .subvendor = 0x1014,
  1556. .subdevice = 0x1f00,
  1557. .name = "MS-9128",
  1558. .type = AC97_TUNE_ALC_JACK
  1559. },
  1560. {
  1561. .subvendor = 0x1014,
  1562. .subdevice = 0x0267,
  1563. .name = "IBM NetVista A30p", /* AD1981B */
  1564. .type = AC97_TUNE_HP_ONLY
  1565. },
  1566. {
  1567. .subvendor = 0x1025,
  1568. .subdevice = 0x0082,
  1569. .name = "Acer Travelmate 2310",
  1570. .type = AC97_TUNE_HP_ONLY
  1571. },
  1572. {
  1573. .subvendor = 0x1025,
  1574. .subdevice = 0x0083,
  1575. .name = "Acer Aspire 3003LCi",
  1576. .type = AC97_TUNE_HP_ONLY
  1577. },
  1578. {
  1579. .subvendor = 0x1028,
  1580. .subdevice = 0x00d8,
  1581. .name = "Dell Precision 530", /* AD1885 */
  1582. .type = AC97_TUNE_HP_ONLY
  1583. },
  1584. {
  1585. .subvendor = 0x1028,
  1586. .subdevice = 0x010d,
  1587. .name = "Dell", /* which model? AD1885 */
  1588. .type = AC97_TUNE_HP_ONLY
  1589. },
  1590. {
  1591. .subvendor = 0x1028,
  1592. .subdevice = 0x0126,
  1593. .name = "Dell Optiplex GX260", /* AD1981A */
  1594. .type = AC97_TUNE_HP_ONLY
  1595. },
  1596. {
  1597. .subvendor = 0x1028,
  1598. .subdevice = 0x012c,
  1599. .name = "Dell Precision 650", /* AD1981A */
  1600. .type = AC97_TUNE_HP_ONLY
  1601. },
  1602. {
  1603. .subvendor = 0x1028,
  1604. .subdevice = 0x012d,
  1605. .name = "Dell Precision 450", /* AD1981B*/
  1606. .type = AC97_TUNE_HP_ONLY
  1607. },
  1608. {
  1609. .subvendor = 0x1028,
  1610. .subdevice = 0x0147,
  1611. .name = "Dell", /* which model? AD1981B*/
  1612. .type = AC97_TUNE_HP_ONLY
  1613. },
  1614. {
  1615. .subvendor = 0x1028,
  1616. .subdevice = 0x0151,
  1617. .name = "Dell Optiplex GX270", /* AD1981B */
  1618. .type = AC97_TUNE_HP_ONLY
  1619. },
  1620. {
  1621. .subvendor = 0x1028,
  1622. .subdevice = 0x014e,
  1623. .name = "Dell D800", /* STAC9750/51 */
  1624. .type = AC97_TUNE_HP_ONLY
  1625. },
  1626. {
  1627. .subvendor = 0x1028,
  1628. .subdevice = 0x0163,
  1629. .name = "Dell Unknown", /* STAC9750/51 */
  1630. .type = AC97_TUNE_HP_ONLY
  1631. },
  1632. {
  1633. .subvendor = 0x1028,
  1634. .subdevice = 0x016a,
  1635. .name = "Dell Inspiron 8600", /* STAC9750/51 */
  1636. .type = AC97_TUNE_HP_ONLY
  1637. },
  1638. {
  1639. .subvendor = 0x1028,
  1640. .subdevice = 0x0182,
  1641. .name = "Dell Latitude D610", /* STAC9750/51 */
  1642. .type = AC97_TUNE_HP_ONLY
  1643. },
  1644. {
  1645. .subvendor = 0x1028,
  1646. .subdevice = 0x0186,
  1647. .name = "Dell Latitude D810", /* cf. Malone #41015 */
  1648. .type = AC97_TUNE_HP_MUTE_LED
  1649. },
  1650. {
  1651. .subvendor = 0x1028,
  1652. .subdevice = 0x0188,
  1653. .name = "Dell Inspiron 6000",
  1654. .type = AC97_TUNE_HP_MUTE_LED /* cf. Malone #41015 */
  1655. },
  1656. {
  1657. .subvendor = 0x1028,
  1658. .subdevice = 0x0189,
  1659. .name = "Dell Inspiron 9300",
  1660. .type = AC97_TUNE_HP_MUTE_LED
  1661. },
  1662. {
  1663. .subvendor = 0x1028,
  1664. .subdevice = 0x0191,
  1665. .name = "Dell Inspiron 8600",
  1666. .type = AC97_TUNE_HP_ONLY
  1667. },
  1668. {
  1669. .subvendor = 0x103c,
  1670. .subdevice = 0x006d,
  1671. .name = "HP zv5000",
  1672. .type = AC97_TUNE_MUTE_LED /*AD1981B*/
  1673. },
  1674. { /* FIXME: which codec? */
  1675. .subvendor = 0x103c,
  1676. .subdevice = 0x00c3,
  1677. .name = "HP xw6000",
  1678. .type = AC97_TUNE_HP_ONLY
  1679. },
  1680. {
  1681. .subvendor = 0x103c,
  1682. .subdevice = 0x088c,
  1683. .name = "HP nc8000",
  1684. .type = AC97_TUNE_HP_MUTE_LED
  1685. },
  1686. {
  1687. .subvendor = 0x103c,
  1688. .subdevice = 0x0890,
  1689. .name = "HP nc6000",
  1690. .type = AC97_TUNE_MUTE_LED
  1691. },
  1692. {
  1693. .subvendor = 0x103c,
  1694. .subdevice = 0x129d,
  1695. .name = "HP xw8000",
  1696. .type = AC97_TUNE_HP_ONLY
  1697. },
  1698. {
  1699. .subvendor = 0x103c,
  1700. .subdevice = 0x0938,
  1701. .name = "HP nc4200",
  1702. .type = AC97_TUNE_HP_MUTE_LED
  1703. },
  1704. {
  1705. .subvendor = 0x103c,
  1706. .subdevice = 0x099c,
  1707. .name = "HP nx6110/nc6120",
  1708. .type = AC97_TUNE_HP_MUTE_LED
  1709. },
  1710. {
  1711. .subvendor = 0x103c,
  1712. .subdevice = 0x0944,
  1713. .name = "HP nc6220",
  1714. .type = AC97_TUNE_HP_MUTE_LED
  1715. },
  1716. {
  1717. .subvendor = 0x103c,
  1718. .subdevice = 0x0934,
  1719. .name = "HP nc8220",
  1720. .type = AC97_TUNE_HP_MUTE_LED
  1721. },
  1722. {
  1723. .subvendor = 0x103c,
  1724. .subdevice = 0x12f1,
  1725. .name = "HP xw8200", /* AD1981B*/
  1726. .type = AC97_TUNE_HP_ONLY
  1727. },
  1728. {
  1729. .subvendor = 0x103c,
  1730. .subdevice = 0x12f2,
  1731. .name = "HP xw6200",
  1732. .type = AC97_TUNE_HP_ONLY
  1733. },
  1734. {
  1735. .subvendor = 0x103c,
  1736. .subdevice = 0x3008,
  1737. .name = "HP xw4200", /* AD1981B*/
  1738. .type = AC97_TUNE_HP_ONLY
  1739. },
  1740. {
  1741. .subvendor = 0x104d,
  1742. .subdevice = 0x8144,
  1743. .name = "Sony",
  1744. .type = AC97_TUNE_INV_EAPD
  1745. },
  1746. {
  1747. .subvendor = 0x104d,
  1748. .subdevice = 0x8197,
  1749. .name = "Sony S1XP",
  1750. .type = AC97_TUNE_INV_EAPD
  1751. },
  1752. {
  1753. .subvendor = 0x104d,
  1754. .subdevice = 0x81c0,
  1755. .name = "Sony VAIO VGN-T350P", /*AD1981B*/
  1756. .type = AC97_TUNE_INV_EAPD
  1757. },
  1758. {
  1759. .subvendor = 0x104d,
  1760. .subdevice = 0x81c5,
  1761. .name = "Sony VAIO VGN-B1VP", /*AD1981B*/
  1762. .type = AC97_TUNE_INV_EAPD
  1763. },
  1764. {
  1765. .subvendor = 0x1043,
  1766. .subdevice = 0x80f3,
  1767. .name = "ASUS ICH5/AD1985",
  1768. .type = AC97_TUNE_AD_SHARING
  1769. },
  1770. {
  1771. .subvendor = 0x10cf,
  1772. .subdevice = 0x11c3,
  1773. .name = "Fujitsu-Siemens E4010",
  1774. .type = AC97_TUNE_HP_ONLY
  1775. },
  1776. {
  1777. .subvendor = 0x10cf,
  1778. .subdevice = 0x1225,
  1779. .name = "Fujitsu-Siemens T3010",
  1780. .type = AC97_TUNE_HP_ONLY
  1781. },
  1782. {
  1783. .subvendor = 0x10cf,
  1784. .subdevice = 0x1253,
  1785. .name = "Fujitsu S6210", /* STAC9750/51 */
  1786. .type = AC97_TUNE_HP_ONLY
  1787. },
  1788. {
  1789. .subvendor = 0x10cf,
  1790. .subdevice = 0x127d,
  1791. .name = "Fujitsu Lifebook P7010",
  1792. .type = AC97_TUNE_HP_ONLY
  1793. },
  1794. {
  1795. .subvendor = 0x10cf,
  1796. .subdevice = 0x127e,
  1797. .name = "Fujitsu Lifebook C1211D",
  1798. .type = AC97_TUNE_HP_ONLY
  1799. },
  1800. {
  1801. .subvendor = 0x10cf,
  1802. .subdevice = 0x12ec,
  1803. .name = "Fujitsu-Siemens 4010",
  1804. .type = AC97_TUNE_HP_ONLY
  1805. },
  1806. {
  1807. .subvendor = 0x10cf,
  1808. .subdevice = 0x12f2,
  1809. .name = "Fujitsu-Siemens Celsius H320",
  1810. .type = AC97_TUNE_SWAP_HP
  1811. },
  1812. {
  1813. .subvendor = 0x10f1,
  1814. .subdevice = 0x2665,
  1815. .name = "Fujitsu-Siemens Celsius", /* AD1981? */
  1816. .type = AC97_TUNE_HP_ONLY
  1817. },
  1818. {
  1819. .subvendor = 0x10f1,
  1820. .subdevice = 0x2885,
  1821. .name = "AMD64 Mobo", /* ALC650 */
  1822. .type = AC97_TUNE_HP_ONLY
  1823. },
  1824. {
  1825. .subvendor = 0x10f1,
  1826. .subdevice = 0x2895,
  1827. .name = "Tyan Thunder K8WE",
  1828. .type = AC97_TUNE_HP_ONLY
  1829. },
  1830. {
  1831. .subvendor = 0x10f7,
  1832. .subdevice = 0x834c,
  1833. .name = "Panasonic CF-R4",
  1834. .type = AC97_TUNE_HP_ONLY,
  1835. },
  1836. {
  1837. .subvendor = 0x110a,
  1838. .subdevice = 0x0056,
  1839. .name = "Fujitsu-Siemens Scenic", /* AD1981? */
  1840. .type = AC97_TUNE_HP_ONLY
  1841. },
  1842. {
  1843. .subvendor = 0x11d4,
  1844. .subdevice = 0x5375,
  1845. .name = "ADI AD1985 (discrete)",
  1846. .type = AC97_TUNE_HP_ONLY
  1847. },
  1848. {
  1849. .subvendor = 0x1462,
  1850. .subdevice = 0x5470,
  1851. .name = "MSI P4 ATX 645 Ultra",
  1852. .type = AC97_TUNE_HP_ONLY
  1853. },
  1854. {
  1855. .subvendor = 0x161f,
  1856. .subdevice = 0x202f,
  1857. .name = "Gateway M520",
  1858. .type = AC97_TUNE_INV_EAPD
  1859. },
  1860. {
  1861. .subvendor = 0x161f,
  1862. .subdevice = 0x203a,
  1863. .name = "Gateway 4525GZ", /* AD1981B */
  1864. .type = AC97_TUNE_INV_EAPD
  1865. },
  1866. {
  1867. .subvendor = 0x1734,
  1868. .subdevice = 0x0088,
  1869. .name = "Fujitsu-Siemens D1522", /* AD1981 */
  1870. .type = AC97_TUNE_HP_ONLY
  1871. },
  1872. {
  1873. .subvendor = 0x8086,
  1874. .subdevice = 0x2000,
  1875. .mask = 0xfff0,
  1876. .name = "Intel ICH5/AD1985",
  1877. .type = AC97_TUNE_AD_SHARING
  1878. },
  1879. {
  1880. .subvendor = 0x8086,
  1881. .subdevice = 0x4000,
  1882. .mask = 0xfff0,
  1883. .name = "Intel ICH5/AD1985",
  1884. .type = AC97_TUNE_AD_SHARING
  1885. },
  1886. {
  1887. .subvendor = 0x8086,
  1888. .subdevice = 0x4856,
  1889. .name = "Intel D845WN (82801BA)",
  1890. .type = AC97_TUNE_SWAP_HP
  1891. },
  1892. {
  1893. .subvendor = 0x8086,
  1894. .subdevice = 0x4d44,
  1895. .name = "Intel D850EMV2", /* AD1885 */
  1896. .type = AC97_TUNE_HP_ONLY
  1897. },
  1898. {
  1899. .subvendor = 0x8086,
  1900. .subdevice = 0x4d56,
  1901. .name = "Intel ICH/AD1885",
  1902. .type = AC97_TUNE_HP_ONLY
  1903. },
  1904. {
  1905. .subvendor = 0x8086,
  1906. .subdevice = 0x6000,
  1907. .mask = 0xfff0,
  1908. .name = "Intel ICH5/AD1985",
  1909. .type = AC97_TUNE_AD_SHARING
  1910. },
  1911. {
  1912. .subvendor = 0x8086,
  1913. .subdevice = 0xe000,
  1914. .mask = 0xfff0,
  1915. .name = "Intel ICH5/AD1985",
  1916. .type = AC97_TUNE_AD_SHARING
  1917. },
  1918. #if 0 /* FIXME: this seems wrong on most boards */
  1919. {
  1920. .subvendor = 0x8086,
  1921. .subdevice = 0xa000,
  1922. .mask = 0xfff0,
  1923. .name = "Intel ICH5/AD1985",
  1924. .type = AC97_TUNE_HP_ONLY
  1925. },
  1926. #endif
  1927. { } /* terminator */
  1928. };
  1929. static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
  1930. const char *quirk_override)
  1931. {
  1932. struct snd_ac97_bus *pbus;
  1933. struct snd_ac97_template ac97;
  1934. int err;
  1935. unsigned int i, codecs;
  1936. unsigned int glob_sta = 0;
  1937. const struct snd_ac97_bus_ops *ops;
  1938. static const struct snd_ac97_bus_ops standard_bus_ops = {
  1939. .write = snd_intel8x0_codec_write,
  1940. .read = snd_intel8x0_codec_read,
  1941. };
  1942. static const struct snd_ac97_bus_ops ali_bus_ops = {
  1943. .write = snd_intel8x0_ali_codec_write,
  1944. .read = snd_intel8x0_ali_codec_read,
  1945. };
  1946. chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
  1947. if (!spdif_aclink) {
  1948. switch (chip->device_type) {
  1949. case DEVICE_NFORCE:
  1950. chip->spdif_idx = NVD_SPBAR;
  1951. break;
  1952. case DEVICE_ALI:
  1953. chip->spdif_idx = ALID_AC97SPDIFOUT;
  1954. break;
  1955. case DEVICE_INTEL_ICH4:
  1956. chip->spdif_idx = ICHD_SPBAR;
  1957. break;
  1958. }
  1959. }
  1960. chip->in_ac97_init = 1;
  1961. memset(&ac97, 0, sizeof(ac97));
  1962. ac97.private_data = chip;
  1963. ac97.private_free = snd_intel8x0_mixer_free_ac97;
  1964. ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
  1965. if (chip->xbox)
  1966. ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
  1967. if (chip->device_type != DEVICE_ALI) {
  1968. glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  1969. ops = &standard_bus_ops;
  1970. chip->in_sdin_init = 1;
  1971. codecs = 0;
  1972. for (i = 0; i < chip->max_codecs; i++) {
  1973. if (! (glob_sta & chip->codec_bit[i]))
  1974. continue;
  1975. if (chip->device_type == DEVICE_INTEL_ICH4) {
  1976. snd_intel8x0_codec_read_test(chip, codecs);
  1977. chip->ac97_sdin[codecs] =
  1978. igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
  1979. if (snd_BUG_ON(chip->ac97_sdin[codecs] >= 3))
  1980. chip->ac97_sdin[codecs] = 0;
  1981. } else
  1982. chip->ac97_sdin[codecs] = i;
  1983. codecs++;
  1984. }
  1985. chip->in_sdin_init = 0;
  1986. if (! codecs)
  1987. codecs = 1;
  1988. } else {
  1989. ops = &ali_bus_ops;
  1990. codecs = 1;
  1991. /* detect the secondary codec */
  1992. for (i = 0; i < 100; i++) {
  1993. unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
  1994. if (reg & 0x40) {
  1995. codecs = 2;
  1996. break;
  1997. }
  1998. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
  1999. udelay(1);
  2000. }
  2001. }
  2002. err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus);
  2003. if (err < 0)
  2004. goto __err;
  2005. pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
  2006. if (ac97_clock >= 8000 && ac97_clock <= 48000)
  2007. pbus->clock = ac97_clock;
  2008. /* FIXME: my test board doesn't work well with VRA... */
  2009. if (chip->device_type == DEVICE_ALI)
  2010. pbus->no_vra = 1;
  2011. else
  2012. pbus->dra = 1;
  2013. chip->ac97_bus = pbus;
  2014. chip->ncodecs = codecs;
  2015. ac97.pci = chip->pci;
  2016. for (i = 0; i < codecs; i++) {
  2017. ac97.num = i;
  2018. err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i]);
  2019. if (err < 0) {
  2020. if (err != -EACCES)
  2021. dev_err(chip->card->dev,
  2022. "Unable to initialize codec #%d\n", i);
  2023. if (i == 0)
  2024. goto __err;
  2025. }
  2026. }
  2027. /* tune up the primary codec */
  2028. snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
  2029. /* enable separate SDINs for ICH4 */
  2030. if (chip->device_type == DEVICE_INTEL_ICH4)
  2031. pbus->isdin = 1;
  2032. /* find the available PCM streams */
  2033. i = ARRAY_SIZE(ac97_pcm_defs);
  2034. if (chip->device_type != DEVICE_INTEL_ICH4)
  2035. i -= 2; /* do not allocate PCM2IN and MIC2 */
  2036. if (chip->spdif_idx < 0)
  2037. i--; /* do not allocate S/PDIF */
  2038. err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
  2039. if (err < 0)
  2040. goto __err;
  2041. chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
  2042. chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
  2043. chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
  2044. if (chip->spdif_idx >= 0)
  2045. chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
  2046. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2047. chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
  2048. chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
  2049. }
  2050. /* enable separate SDINs for ICH4 */
  2051. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2052. struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
  2053. u8 tmp = igetbyte(chip, ICHREG(SDM));
  2054. tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
  2055. if (pcm) {
  2056. tmp |= ICH_SE; /* steer enable for multiple SDINs */
  2057. tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
  2058. for (i = 1; i < 4; i++) {
  2059. if (pcm->r[0].codec[i]) {
  2060. tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
  2061. break;
  2062. }
  2063. }
  2064. } else {
  2065. tmp &= ~ICH_SE; /* steer disable */
  2066. }
  2067. iputbyte(chip, ICHREG(SDM), tmp);
  2068. }
  2069. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
  2070. chip->multi4 = 1;
  2071. if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
  2072. chip->multi6 = 1;
  2073. if (chip->ac97[0]->flags & AC97_HAS_8CH)
  2074. chip->multi8 = 1;
  2075. }
  2076. }
  2077. if (pbus->pcms[0].r[1].rslots[0]) {
  2078. chip->dra = 1;
  2079. }
  2080. if (chip->device_type == DEVICE_INTEL_ICH4) {
  2081. if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
  2082. chip->smp20bit = 1;
  2083. }
  2084. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2085. /* 48kHz only */
  2086. chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
  2087. }
  2088. if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
  2089. /* use slot 10/11 for SPDIF */
  2090. u32 val;
  2091. val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
  2092. val |= ICH_PCM_SPDIF_1011;
  2093. iputdword(chip, ICHREG(GLOB_CNT), val);
  2094. snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
  2095. }
  2096. chip->in_ac97_init = 0;
  2097. return 0;
  2098. __err:
  2099. /* clear the cold-reset bit for the next chance */
  2100. if (chip->device_type != DEVICE_ALI)
  2101. iputdword(chip, ICHREG(GLOB_CNT),
  2102. igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
  2103. return err;
  2104. }
  2105. /*
  2106. *
  2107. */
  2108. static void do_ali_reset(struct intel8x0 *chip)
  2109. {
  2110. iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
  2111. iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
  2112. iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
  2113. iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
  2114. iputdword(chip, ICHREG(ALI_INTERFACECR),
  2115. ICH_ALI_IF_PI|ICH_ALI_IF_PO);
  2116. iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
  2117. iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
  2118. }
  2119. #ifdef CONFIG_SND_AC97_POWER_SAVE
  2120. static const struct snd_pci_quirk ich_chip_reset_mode[] = {
  2121. SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
  2122. { } /* end */
  2123. };
  2124. static int snd_intel8x0_ich_chip_cold_reset(struct intel8x0 *chip)
  2125. {
  2126. unsigned int cnt;
  2127. /* ACLink on, 2 channels */
  2128. if (snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
  2129. return -EIO;
  2130. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2131. cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
  2132. /* do cold reset - the full ac97 powerdown may leave the controller
  2133. * in a warm state but actually it cannot communicate with the codec.
  2134. */
  2135. iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_AC97COLD);
  2136. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2137. udelay(10);
  2138. iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD);
  2139. msleep(1);
  2140. return 0;
  2141. }
  2142. #define snd_intel8x0_ich_chip_can_cold_reset(chip) \
  2143. (!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
  2144. #else
  2145. #define snd_intel8x0_ich_chip_cold_reset(chip) 0
  2146. #define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
  2147. #endif
  2148. static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
  2149. {
  2150. unsigned long end_time;
  2151. unsigned int cnt;
  2152. /* ACLink on, 2 channels */
  2153. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  2154. cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
  2155. /* finish cold or do warm reset */
  2156. cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  2157. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  2158. end_time = (jiffies + (HZ / 4)) + 1;
  2159. do {
  2160. if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
  2161. return 0;
  2162. schedule_timeout_uninterruptible(1);
  2163. } while (time_after_eq(end_time, jiffies));
  2164. dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
  2165. igetdword(chip, ICHREG(GLOB_CNT)));
  2166. return -EIO;
  2167. }
  2168. static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
  2169. {
  2170. unsigned long end_time;
  2171. unsigned int status, nstatus;
  2172. unsigned int cnt;
  2173. int err;
  2174. /* put logic to right state */
  2175. /* first clear status bits */
  2176. status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
  2177. if (chip->device_type == DEVICE_NFORCE)
  2178. status |= ICH_NVSPINT;
  2179. cnt = igetdword(chip, ICHREG(GLOB_STA));
  2180. iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  2181. if (snd_intel8x0_ich_chip_can_cold_reset(chip))
  2182. err = snd_intel8x0_ich_chip_cold_reset(chip);
  2183. else
  2184. err = snd_intel8x0_ich_chip_reset(chip);
  2185. if (err < 0)
  2186. return err;
  2187. if (probing) {
  2188. /* wait for any codec ready status.
  2189. * Once it becomes ready it should remain ready
  2190. * as long as we do not disable the ac97 link.
  2191. */
  2192. end_time = jiffies + HZ;
  2193. do {
  2194. status = igetdword(chip, ICHREG(GLOB_STA)) &
  2195. chip->codec_isr_bits;
  2196. if (status)
  2197. break;
  2198. schedule_timeout_uninterruptible(1);
  2199. } while (time_after_eq(end_time, jiffies));
  2200. if (! status) {
  2201. /* no codec is found */
  2202. dev_err(chip->card->dev,
  2203. "codec_ready: codec is not ready [0x%x]\n",
  2204. igetdword(chip, ICHREG(GLOB_STA)));
  2205. return -EIO;
  2206. }
  2207. /* wait for other codecs ready status. */
  2208. end_time = jiffies + HZ / 4;
  2209. while (status != chip->codec_isr_bits &&
  2210. time_after_eq(end_time, jiffies)) {
  2211. schedule_timeout_uninterruptible(1);
  2212. status |= igetdword(chip, ICHREG(GLOB_STA)) &
  2213. chip->codec_isr_bits;
  2214. }
  2215. } else {
  2216. /* resume phase */
  2217. int i;
  2218. status = 0;
  2219. for (i = 0; i < chip->ncodecs; i++)
  2220. if (chip->ac97[i])
  2221. status |= chip->codec_bit[chip->ac97_sdin[i]];
  2222. /* wait until all the probed codecs are ready */
  2223. end_time = jiffies + HZ;
  2224. do {
  2225. nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
  2226. chip->codec_isr_bits;
  2227. if (status == nstatus)
  2228. break;
  2229. schedule_timeout_uninterruptible(1);
  2230. } while (time_after_eq(end_time, jiffies));
  2231. }
  2232. if (chip->device_type == DEVICE_SIS) {
  2233. /* unmute the output on SIS7012 */
  2234. iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  2235. }
  2236. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2237. /* enable SPDIF interrupt */
  2238. unsigned int val;
  2239. pci_read_config_dword(chip->pci, 0x4c, &val);
  2240. val |= 0x1000000;
  2241. pci_write_config_dword(chip->pci, 0x4c, val);
  2242. }
  2243. return 0;
  2244. }
  2245. static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
  2246. {
  2247. u32 reg;
  2248. int i = 0;
  2249. reg = igetdword(chip, ICHREG(ALI_SCR));
  2250. if ((reg & 2) == 0) /* Cold required */
  2251. reg |= 2;
  2252. else
  2253. reg |= 1; /* Warm */
  2254. reg &= ~0x80000000; /* ACLink on */
  2255. iputdword(chip, ICHREG(ALI_SCR), reg);
  2256. for (i = 0; i < HZ / 2; i++) {
  2257. if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
  2258. goto __ok;
  2259. schedule_timeout_uninterruptible(1);
  2260. }
  2261. dev_err(chip->card->dev, "AC'97 reset failed.\n");
  2262. if (probing)
  2263. return -EIO;
  2264. __ok:
  2265. for (i = 0; i < HZ / 2; i++) {
  2266. reg = igetdword(chip, ICHREG(ALI_RTSR));
  2267. if (reg & 0x80) /* primary codec */
  2268. break;
  2269. iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
  2270. schedule_timeout_uninterruptible(1);
  2271. }
  2272. do_ali_reset(chip);
  2273. return 0;
  2274. }
  2275. static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
  2276. {
  2277. unsigned int i, timeout;
  2278. int err;
  2279. if (chip->device_type != DEVICE_ALI) {
  2280. err = snd_intel8x0_ich_chip_init(chip, probing);
  2281. if (err < 0)
  2282. return err;
  2283. iagetword(chip, 0); /* clear semaphore flag */
  2284. } else {
  2285. err = snd_intel8x0_ali_chip_init(chip, probing);
  2286. if (err < 0)
  2287. return err;
  2288. }
  2289. /* disable interrupts */
  2290. for (i = 0; i < chip->bdbars_count; i++)
  2291. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2292. /* reset channels */
  2293. for (i = 0; i < chip->bdbars_count; i++)
  2294. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2295. for (i = 0; i < chip->bdbars_count; i++) {
  2296. timeout = 100000;
  2297. while (--timeout != 0) {
  2298. if ((igetbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset) & ICH_RESETREGS) == 0)
  2299. break;
  2300. }
  2301. if (timeout == 0)
  2302. dev_err(chip->card->dev, "reset of registers failed?\n");
  2303. }
  2304. /* initialize Buffer Descriptor Lists */
  2305. for (i = 0; i < chip->bdbars_count; i++)
  2306. iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset,
  2307. chip->ichd[i].bdbar_addr);
  2308. return 0;
  2309. }
  2310. static void snd_intel8x0_free(struct snd_card *card)
  2311. {
  2312. struct intel8x0 *chip = card->private_data;
  2313. unsigned int i;
  2314. if (chip->irq < 0)
  2315. goto __hw_end;
  2316. /* disable interrupts */
  2317. for (i = 0; i < chip->bdbars_count; i++)
  2318. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  2319. /* reset channels */
  2320. for (i = 0; i < chip->bdbars_count; i++)
  2321. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  2322. if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
  2323. /* stop the spdif interrupt */
  2324. unsigned int val;
  2325. pci_read_config_dword(chip->pci, 0x4c, &val);
  2326. val &= ~0x1000000;
  2327. pci_write_config_dword(chip->pci, 0x4c, val);
  2328. }
  2329. /* --- */
  2330. __hw_end:
  2331. if (chip->irq >= 0)
  2332. free_irq(chip->irq, chip);
  2333. }
  2334. /*
  2335. * power management
  2336. */
  2337. static int intel8x0_suspend(struct device *dev)
  2338. {
  2339. struct snd_card *card = dev_get_drvdata(dev);
  2340. struct intel8x0 *chip = card->private_data;
  2341. int i;
  2342. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  2343. for (i = 0; i < chip->ncodecs; i++)
  2344. snd_ac97_suspend(chip->ac97[i]);
  2345. if (chip->device_type == DEVICE_INTEL_ICH4)
  2346. chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
  2347. if (chip->irq >= 0) {
  2348. free_irq(chip->irq, chip);
  2349. chip->irq = -1;
  2350. card->sync_irq = -1;
  2351. }
  2352. return 0;
  2353. }
  2354. static int intel8x0_resume(struct device *dev)
  2355. {
  2356. struct pci_dev *pci = to_pci_dev(dev);
  2357. struct snd_card *card = dev_get_drvdata(dev);
  2358. struct intel8x0 *chip = card->private_data;
  2359. int i;
  2360. snd_intel8x0_chip_init(chip, 0);
  2361. if (request_irq(pci->irq, snd_intel8x0_interrupt,
  2362. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  2363. dev_err(dev, "unable to grab IRQ %d, disabling device\n",
  2364. pci->irq);
  2365. snd_card_disconnect(card);
  2366. return -EIO;
  2367. }
  2368. chip->irq = pci->irq;
  2369. card->sync_irq = chip->irq;
  2370. /* re-initialize mixer stuff */
  2371. if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
  2372. /* enable separate SDINs for ICH4 */
  2373. iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
  2374. /* use slot 10/11 for SPDIF */
  2375. iputdword(chip, ICHREG(GLOB_CNT),
  2376. (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
  2377. ICH_PCM_SPDIF_1011);
  2378. }
  2379. for (i = 0; i < chip->ncodecs; i++)
  2380. snd_ac97_resume(chip->ac97[i]);
  2381. /* resume status */
  2382. for (i = 0; i < chip->bdbars_count; i++) {
  2383. struct ichdev *ichdev = &chip->ichd[i];
  2384. unsigned long port = ichdev->reg_offset;
  2385. if (! ichdev->substream || ! ichdev->suspended)
  2386. continue;
  2387. if (ichdev->ichd == ICHD_PCMOUT)
  2388. snd_intel8x0_setup_pcm_out(chip, ichdev->substream->runtime);
  2389. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  2390. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  2391. iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->civ);
  2392. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  2393. }
  2394. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  2395. return 0;
  2396. }
  2397. static DEFINE_SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume);
  2398. #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
  2399. static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
  2400. {
  2401. struct snd_pcm_substream *subs;
  2402. struct ichdev *ichdev;
  2403. unsigned long port;
  2404. unsigned long pos, pos1, t;
  2405. int civ, timeout = 1000, attempt = 1;
  2406. ktime_t start_time, stop_time;
  2407. if (chip->ac97_bus->clock != 48000)
  2408. return; /* specified in module option */
  2409. if (chip->inside_vm && !ac97_clock)
  2410. return; /* no measurement on VM */
  2411. __again:
  2412. subs = chip->pcm[0]->streams[0].substream;
  2413. if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
  2414. dev_warn(chip->card->dev,
  2415. "no playback buffer allocated - aborting measure ac97 clock\n");
  2416. return;
  2417. }
  2418. ichdev = &chip->ichd[ICHD_PCMOUT];
  2419. ichdev->physbuf = subs->dma_buffer.addr;
  2420. ichdev->size = ichdev->fragsize = INTEL8X0_TESTBUF_SIZE;
  2421. ichdev->substream = NULL; /* don't process interrupts */
  2422. /* set rate */
  2423. if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
  2424. dev_err(chip->card->dev, "cannot set ac97 rate: clock = %d\n",
  2425. chip->ac97_bus->clock);
  2426. return;
  2427. }
  2428. snd_intel8x0_setup_periods(chip, ichdev);
  2429. port = ichdev->reg_offset;
  2430. spin_lock_irq(&chip->reg_lock);
  2431. chip->in_measurement = 1;
  2432. /* trigger */
  2433. if (chip->device_type != DEVICE_ALI)
  2434. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
  2435. else {
  2436. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  2437. iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
  2438. }
  2439. start_time = ktime_get();
  2440. spin_unlock_irq(&chip->reg_lock);
  2441. msleep(50);
  2442. spin_lock_irq(&chip->reg_lock);
  2443. /* check the position */
  2444. do {
  2445. civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  2446. pos1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  2447. if (pos1 == 0) {
  2448. udelay(10);
  2449. continue;
  2450. }
  2451. if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
  2452. pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  2453. break;
  2454. } while (timeout--);
  2455. if (pos1 == 0) { /* oops, this value is not reliable */
  2456. pos = 0;
  2457. } else {
  2458. pos = ichdev->fragsize1;
  2459. pos -= pos1 << ichdev->pos_shift;
  2460. pos += ichdev->position;
  2461. }
  2462. chip->in_measurement = 0;
  2463. stop_time = ktime_get();
  2464. /* stop */
  2465. if (chip->device_type == DEVICE_ALI) {
  2466. iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
  2467. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2468. while (igetbyte(chip, port + ICH_REG_OFF_CR))
  2469. ;
  2470. } else {
  2471. iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  2472. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
  2473. ;
  2474. }
  2475. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  2476. spin_unlock_irq(&chip->reg_lock);
  2477. if (pos == 0) {
  2478. dev_err(chip->card->dev,
  2479. "measure - unreliable DMA position..\n");
  2480. __retry:
  2481. if (attempt < 3) {
  2482. msleep(300);
  2483. attempt++;
  2484. goto __again;
  2485. }
  2486. goto __end;
  2487. }
  2488. pos /= 4;
  2489. t = ktime_us_delta(stop_time, start_time);
  2490. dev_info(chip->card->dev,
  2491. "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
  2492. if (t == 0) {
  2493. dev_err(chip->card->dev, "?? calculation error..\n");
  2494. goto __retry;
  2495. }
  2496. pos *= 1000;
  2497. pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
  2498. if (pos < 40000 || pos >= 60000) {
  2499. /* abnormal value. hw problem? */
  2500. dev_info(chip->card->dev, "measured clock %ld rejected\n", pos);
  2501. goto __retry;
  2502. } else if (pos > 40500 && pos < 41500)
  2503. /* first exception - 41000Hz reference clock */
  2504. chip->ac97_bus->clock = 41000;
  2505. else if (pos > 43600 && pos < 44600)
  2506. /* second exception - 44100HZ reference clock */
  2507. chip->ac97_bus->clock = 44100;
  2508. else if (pos < 47500 || pos > 48500)
  2509. /* not 48000Hz, tuning the clock.. */
  2510. chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
  2511. __end:
  2512. dev_info(chip->card->dev, "clocking to %d\n", chip->ac97_bus->clock);
  2513. snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
  2514. }
  2515. static const struct snd_pci_quirk intel8x0_clock_list[] = {
  2516. SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
  2517. SND_PCI_QUIRK(0x1014, 0x0581, "AD1981B", 48000),
  2518. SND_PCI_QUIRK(0x1028, 0x00be, "AD1885", 44100),
  2519. SND_PCI_QUIRK(0x1028, 0x0177, "AD1980", 48000),
  2520. SND_PCI_QUIRK(0x1028, 0x01ad, "AD1981B", 48000),
  2521. SND_PCI_QUIRK(0x1043, 0x80f3, "AD1985", 48000),
  2522. { } /* terminator */
  2523. };
  2524. static int intel8x0_in_clock_list(struct intel8x0 *chip)
  2525. {
  2526. struct pci_dev *pci = chip->pci;
  2527. const struct snd_pci_quirk *wl;
  2528. wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
  2529. if (!wl)
  2530. return 0;
  2531. dev_info(chip->card->dev, "allow list rate for %04x:%04x is %i\n",
  2532. pci->subsystem_vendor, pci->subsystem_device, wl->value);
  2533. chip->ac97_bus->clock = wl->value;
  2534. return 1;
  2535. }
  2536. static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
  2537. struct snd_info_buffer *buffer)
  2538. {
  2539. struct intel8x0 *chip = entry->private_data;
  2540. unsigned int tmp;
  2541. snd_iprintf(buffer, "Intel8x0\n\n");
  2542. if (chip->device_type == DEVICE_ALI)
  2543. return;
  2544. tmp = igetdword(chip, ICHREG(GLOB_STA));
  2545. snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
  2546. snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
  2547. if (chip->device_type == DEVICE_INTEL_ICH4)
  2548. snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
  2549. snd_iprintf(buffer, "AC'97 codecs ready :");
  2550. if (tmp & chip->codec_isr_bits) {
  2551. int i;
  2552. static const char *codecs[3] = {
  2553. "primary", "secondary", "tertiary"
  2554. };
  2555. for (i = 0; i < chip->max_codecs; i++)
  2556. if (tmp & chip->codec_bit[i])
  2557. snd_iprintf(buffer, " %s", codecs[i]);
  2558. } else
  2559. snd_iprintf(buffer, " none");
  2560. snd_iprintf(buffer, "\n");
  2561. if (chip->device_type == DEVICE_INTEL_ICH4 ||
  2562. chip->device_type == DEVICE_SIS)
  2563. snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
  2564. chip->ac97_sdin[0],
  2565. chip->ac97_sdin[1],
  2566. chip->ac97_sdin[2]);
  2567. }
  2568. static void snd_intel8x0_proc_init(struct intel8x0 *chip)
  2569. {
  2570. snd_card_ro_proc_new(chip->card, "intel8x0", chip,
  2571. snd_intel8x0_proc_read);
  2572. }
  2573. struct ich_reg_info {
  2574. unsigned int int_sta_mask;
  2575. unsigned int offset;
  2576. };
  2577. static const unsigned int ich_codec_bits[3] = {
  2578. ICH_PCR, ICH_SCR, ICH_TCR
  2579. };
  2580. static const unsigned int sis_codec_bits[3] = {
  2581. ICH_PCR, ICH_SCR, ICH_SIS_TCR
  2582. };
  2583. static int snd_intel8x0_inside_vm(struct pci_dev *pci)
  2584. {
  2585. int result = inside_vm;
  2586. char *msg = NULL;
  2587. /* check module parameter first (override detection) */
  2588. if (result >= 0) {
  2589. msg = result ? "enable (forced) VM" : "disable (forced) VM";
  2590. goto fini;
  2591. }
  2592. /* check for known (emulated) devices */
  2593. result = 0;
  2594. if (pci->subsystem_vendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
  2595. pci->subsystem_device == PCI_SUBDEVICE_ID_QEMU) {
  2596. /* KVM emulated sound, PCI SSID: 1af4:1100 */
  2597. msg = "enable KVM";
  2598. result = 1;
  2599. } else if (pci->subsystem_vendor == 0x1ab8) {
  2600. /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */
  2601. msg = "enable Parallels VM";
  2602. result = 1;
  2603. }
  2604. fini:
  2605. if (msg != NULL)
  2606. dev_info(&pci->dev, "%s optimization\n", msg);
  2607. return result;
  2608. }
  2609. static int snd_intel8x0_init(struct snd_card *card,
  2610. struct pci_dev *pci,
  2611. unsigned long device_type)
  2612. {
  2613. struct intel8x0 *chip = card->private_data;
  2614. int err;
  2615. unsigned int i;
  2616. unsigned int int_sta_masks;
  2617. struct ichdev *ichdev;
  2618. static const unsigned int bdbars[] = {
  2619. 3, /* DEVICE_INTEL */
  2620. 6, /* DEVICE_INTEL_ICH4 */
  2621. 3, /* DEVICE_SIS */
  2622. 6, /* DEVICE_ALI */
  2623. 4, /* DEVICE_NFORCE */
  2624. };
  2625. static const struct ich_reg_info intel_regs[6] = {
  2626. { ICH_PIINT, 0 },
  2627. { ICH_POINT, 0x10 },
  2628. { ICH_MCINT, 0x20 },
  2629. { ICH_M2INT, 0x40 },
  2630. { ICH_P2INT, 0x50 },
  2631. { ICH_SPINT, 0x60 },
  2632. };
  2633. static const struct ich_reg_info nforce_regs[4] = {
  2634. { ICH_PIINT, 0 },
  2635. { ICH_POINT, 0x10 },
  2636. { ICH_MCINT, 0x20 },
  2637. { ICH_NVSPINT, 0x70 },
  2638. };
  2639. static const struct ich_reg_info ali_regs[6] = {
  2640. { ALI_INT_PCMIN, 0x40 },
  2641. { ALI_INT_PCMOUT, 0x50 },
  2642. { ALI_INT_MICIN, 0x60 },
  2643. { ALI_INT_CODECSPDIFOUT, 0x70 },
  2644. { ALI_INT_SPDIFIN, 0xa0 },
  2645. { ALI_INT_SPDIFOUT, 0xb0 },
  2646. };
  2647. const struct ich_reg_info *tbl;
  2648. err = pcim_enable_device(pci);
  2649. if (err < 0)
  2650. return err;
  2651. spin_lock_init(&chip->reg_lock);
  2652. chip->device_type = device_type;
  2653. chip->card = card;
  2654. chip->pci = pci;
  2655. chip->irq = -1;
  2656. /* module parameters */
  2657. chip->buggy_irq = buggy_irq;
  2658. chip->buggy_semaphore = buggy_semaphore;
  2659. if (xbox)
  2660. chip->xbox = 1;
  2661. chip->inside_vm = snd_intel8x0_inside_vm(pci);
  2662. /*
  2663. * Intel 82443MX running a 100MHz processor system bus has a hardware
  2664. * bug, which aborts PCI busmaster for audio transfer. A workaround
  2665. * is to set the pages as non-cached. For details, see the errata in
  2666. * http://download.intel.com/design/chipsets/specupdt/24505108.pdf
  2667. */
  2668. if (pci->vendor == PCI_VENDOR_ID_INTEL &&
  2669. pci->device == PCI_DEVICE_ID_INTEL_440MX)
  2670. chip->fix_nocache = 1; /* enable workaround */
  2671. err = pci_request_regions(pci, card->shortname);
  2672. if (err < 0)
  2673. return err;
  2674. if (device_type == DEVICE_ALI) {
  2675. /* ALI5455 has no ac97 region */
  2676. chip->bmaddr = pcim_iomap(pci, 0, 0);
  2677. } else {
  2678. if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
  2679. chip->addr = pcim_iomap(pci, 2, 0);
  2680. else
  2681. chip->addr = pcim_iomap(pci, 0, 0);
  2682. if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
  2683. chip->bmaddr = pcim_iomap(pci, 3, 0);
  2684. else
  2685. chip->bmaddr = pcim_iomap(pci, 1, 0);
  2686. }
  2687. chip->bdbars_count = bdbars[device_type];
  2688. /* initialize offsets */
  2689. switch (device_type) {
  2690. case DEVICE_NFORCE:
  2691. tbl = nforce_regs;
  2692. break;
  2693. case DEVICE_ALI:
  2694. tbl = ali_regs;
  2695. break;
  2696. default:
  2697. tbl = intel_regs;
  2698. break;
  2699. }
  2700. for (i = 0; i < chip->bdbars_count; i++) {
  2701. ichdev = &chip->ichd[i];
  2702. ichdev->ichd = i;
  2703. ichdev->reg_offset = tbl[i].offset;
  2704. ichdev->int_sta_mask = tbl[i].int_sta_mask;
  2705. if (device_type == DEVICE_SIS) {
  2706. /* SiS 7012 swaps the registers */
  2707. ichdev->roff_sr = ICH_REG_OFF_PICB;
  2708. ichdev->roff_picb = ICH_REG_OFF_SR;
  2709. } else {
  2710. ichdev->roff_sr = ICH_REG_OFF_SR;
  2711. ichdev->roff_picb = ICH_REG_OFF_PICB;
  2712. }
  2713. if (device_type == DEVICE_ALI)
  2714. ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  2715. /* SIS7012 handles the pcm data in bytes, others are in samples */
  2716. ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  2717. }
  2718. /* allocate buffer descriptor lists */
  2719. /* the start of each lists must be aligned to 8 bytes */
  2720. chip->bdbars = snd_devm_alloc_pages(&pci->dev, intel8x0_dma_type(chip),
  2721. chip->bdbars_count * sizeof(u32) *
  2722. ICH_MAX_FRAGS * 2);
  2723. if (!chip->bdbars)
  2724. return -ENOMEM;
  2725. /* tables must be aligned to 8 bytes here, but the kernel pages
  2726. are much bigger, so we don't care (on i386) */
  2727. int_sta_masks = 0;
  2728. for (i = 0; i < chip->bdbars_count; i++) {
  2729. ichdev = &chip->ichd[i];
  2730. ichdev->bdbar = ((__le32 *)chip->bdbars->area) +
  2731. (i * ICH_MAX_FRAGS * 2);
  2732. ichdev->bdbar_addr = chip->bdbars->addr +
  2733. (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
  2734. int_sta_masks |= ichdev->int_sta_mask;
  2735. }
  2736. chip->int_sta_reg = device_type == DEVICE_ALI ?
  2737. ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
  2738. chip->int_sta_mask = int_sta_masks;
  2739. pci_set_master(pci);
  2740. switch(chip->device_type) {
  2741. case DEVICE_INTEL_ICH4:
  2742. /* ICH4 can have three codecs */
  2743. chip->max_codecs = 3;
  2744. chip->codec_bit = ich_codec_bits;
  2745. chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_TRI;
  2746. break;
  2747. case DEVICE_SIS:
  2748. /* recent SIS7012 can have three codecs */
  2749. chip->max_codecs = 3;
  2750. chip->codec_bit = sis_codec_bits;
  2751. chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_SIS_TRI;
  2752. break;
  2753. default:
  2754. /* others up to two codecs */
  2755. chip->max_codecs = 2;
  2756. chip->codec_bit = ich_codec_bits;
  2757. chip->codec_ready_bits = ICH_PRI | ICH_SRI;
  2758. break;
  2759. }
  2760. for (i = 0; i < chip->max_codecs; i++)
  2761. chip->codec_isr_bits |= chip->codec_bit[i];
  2762. err = snd_intel8x0_chip_init(chip, 1);
  2763. if (err < 0)
  2764. return err;
  2765. /* request irq after initializaing int_sta_mask, etc */
  2766. /* NOTE: we don't use devm version here since it's released /
  2767. * re-acquired in PM callbacks.
  2768. * It's released explicitly in snd_intel8x0_free(), too.
  2769. */
  2770. if (request_irq(pci->irq, snd_intel8x0_interrupt,
  2771. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  2772. dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
  2773. return -EBUSY;
  2774. }
  2775. chip->irq = pci->irq;
  2776. card->sync_irq = chip->irq;
  2777. card->private_free = snd_intel8x0_free;
  2778. return 0;
  2779. }
  2780. static struct shortname_table {
  2781. unsigned int id;
  2782. const char *s;
  2783. } shortnames[] = {
  2784. { PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
  2785. { PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
  2786. { PCI_DEVICE_ID_INTEL_82801BA_4, "Intel 82801BA-ICH2" },
  2787. { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
  2788. { PCI_DEVICE_ID_INTEL_82801CA_5, "Intel 82801CA-ICH3" },
  2789. { PCI_DEVICE_ID_INTEL_82801DB_5, "Intel 82801DB-ICH4" },
  2790. { PCI_DEVICE_ID_INTEL_82801EB_5, "Intel ICH5" },
  2791. { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
  2792. { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
  2793. { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
  2794. { PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
  2795. { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
  2796. { PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO, "NVidia nForce" },
  2797. { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
  2798. { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
  2799. { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
  2800. { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
  2801. { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
  2802. { 0x003a, "NVidia MCP04" },
  2803. { 0x746d, "AMD AMD8111" },
  2804. { 0x7445, "AMD AMD768" },
  2805. { 0x5455, "ALi M5455" },
  2806. { 0, NULL },
  2807. };
  2808. static const struct snd_pci_quirk spdif_aclink_defaults[] = {
  2809. SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
  2810. { } /* end */
  2811. };
  2812. /* look up allow/deny list for SPDIF over ac-link */
  2813. static int check_default_spdif_aclink(struct pci_dev *pci)
  2814. {
  2815. const struct snd_pci_quirk *w;
  2816. w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
  2817. if (w) {
  2818. if (w->value)
  2819. dev_dbg(&pci->dev,
  2820. "Using SPDIF over AC-Link for %s\n",
  2821. snd_pci_quirk_name(w));
  2822. else
  2823. dev_dbg(&pci->dev,
  2824. "Using integrated SPDIF DMA for %s\n",
  2825. snd_pci_quirk_name(w));
  2826. return w->value;
  2827. }
  2828. return 0;
  2829. }
  2830. static int __snd_intel8x0_probe(struct pci_dev *pci,
  2831. const struct pci_device_id *pci_id)
  2832. {
  2833. struct snd_card *card;
  2834. struct intel8x0 *chip;
  2835. int err;
  2836. struct shortname_table *name;
  2837. err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
  2838. sizeof(*chip), &card);
  2839. if (err < 0)
  2840. return err;
  2841. chip = card->private_data;
  2842. if (spdif_aclink < 0)
  2843. spdif_aclink = check_default_spdif_aclink(pci);
  2844. strcpy(card->driver, "ICH");
  2845. if (!spdif_aclink) {
  2846. switch (pci_id->driver_data) {
  2847. case DEVICE_NFORCE:
  2848. strcpy(card->driver, "NFORCE");
  2849. break;
  2850. case DEVICE_INTEL_ICH4:
  2851. strcpy(card->driver, "ICH4");
  2852. }
  2853. }
  2854. strcpy(card->shortname, "Intel ICH");
  2855. for (name = shortnames; name->id; name++) {
  2856. if (pci->device == name->id) {
  2857. strcpy(card->shortname, name->s);
  2858. break;
  2859. }
  2860. }
  2861. if (buggy_irq < 0) {
  2862. /* some Nforce[2] and ICH boards have problems with IRQ handling.
  2863. * Needs to return IRQ_HANDLED for unknown irqs.
  2864. */
  2865. if (pci_id->driver_data == DEVICE_NFORCE)
  2866. buggy_irq = 1;
  2867. else
  2868. buggy_irq = 0;
  2869. }
  2870. err = snd_intel8x0_init(card, pci, pci_id->driver_data);
  2871. if (err < 0)
  2872. return err;
  2873. err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk);
  2874. if (err < 0)
  2875. return err;
  2876. err = snd_intel8x0_pcm(chip);
  2877. if (err < 0)
  2878. return err;
  2879. snd_intel8x0_proc_init(chip);
  2880. snprintf(card->longname, sizeof(card->longname),
  2881. "%s with %s at irq %i", card->shortname,
  2882. snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
  2883. if (ac97_clock == 0 || ac97_clock == 1) {
  2884. if (ac97_clock == 0) {
  2885. if (intel8x0_in_clock_list(chip) == 0)
  2886. intel8x0_measure_ac97_clock(chip);
  2887. } else {
  2888. intel8x0_measure_ac97_clock(chip);
  2889. }
  2890. }
  2891. err = snd_card_register(card);
  2892. if (err < 0)
  2893. return err;
  2894. pci_set_drvdata(pci, card);
  2895. return 0;
  2896. }
  2897. static int snd_intel8x0_probe(struct pci_dev *pci,
  2898. const struct pci_device_id *pci_id)
  2899. {
  2900. return snd_card_free_on_error(&pci->dev, __snd_intel8x0_probe(pci, pci_id));
  2901. }
  2902. static struct pci_driver intel8x0_driver = {
  2903. .name = KBUILD_MODNAME,
  2904. .id_table = snd_intel8x0_ids,
  2905. .probe = snd_intel8x0_probe,
  2906. .driver = {
  2907. .pm = &intel8x0_pm,
  2908. },
  2909. };
  2910. module_pci_driver(intel8x0_driver);