intel8x0.c 87 KB

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