intel8x0.c 81 KB

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