intel8x0.c 81 KB

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