intel8x0.c 81 KB

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