intel8x0.c 87 KB

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