intel8x0.c 81 KB

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