intel8x0.c 85 KB

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