intel8x0.c 92 KB

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