intel8x0.c 92 KB

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