intel8x0.c 92 KB

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