intel8x0.c 91 KB

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