intel8x0.c 81 KB

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