intel8x0.c 83 KB

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