intel8x0.c 86 KB

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