intel8x0.c 83 KB

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