trident_main.c 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004
  1. /*
  2. * Maintained by Jaroslav Kysela <perex@suse.cz>
  3. * Originated by audio@tridentmicro.com
  4. * Fri Feb 19 15:55:28 MST 1999
  5. * Routines for control of Trident 4DWave (DX and NX) chip
  6. *
  7. * BUGS:
  8. *
  9. * TODO:
  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. * SiS7018 S/PDIF support by Thomas Winischhofer <thomas@winischhofer.net>
  28. */
  29. #include <sound/driver.h>
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/pci.h>
  34. #include <linux/slab.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/gameport.h>
  37. #include <sound/core.h>
  38. #include <sound/info.h>
  39. #include <sound/control.h>
  40. #include <sound/trident.h>
  41. #include <sound/asoundef.h>
  42. #include <asm/io.h>
  43. static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
  44. struct snd_trident_voice * voice,
  45. struct snd_pcm_substream *substream);
  46. static int snd_trident_pcm_mixer_free(struct snd_trident *trident,
  47. struct snd_trident_voice * voice,
  48. struct snd_pcm_substream *substream);
  49. static irqreturn_t snd_trident_interrupt(int irq, void *dev_id,
  50. struct pt_regs *regs);
  51. static int snd_trident_sis_reset(struct snd_trident *trident);
  52. static void snd_trident_clear_voices(struct snd_trident * trident,
  53. unsigned short v_min, unsigned short v_max);
  54. static int snd_trident_free(struct snd_trident *trident);
  55. /*
  56. * common I/O routines
  57. */
  58. #if 0
  59. static void snd_trident_print_voice_regs(struct snd_trident *trident, int voice)
  60. {
  61. unsigned int val, tmp;
  62. printk("Trident voice %i:\n", voice);
  63. outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR));
  64. val = inl(TRID_REG(trident, CH_LBA));
  65. printk("LBA: 0x%x\n", val);
  66. val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
  67. printk("GVSel: %i\n", val >> 31);
  68. printk("Pan: 0x%x\n", (val >> 24) & 0x7f);
  69. printk("Vol: 0x%x\n", (val >> 16) & 0xff);
  70. printk("CTRL: 0x%x\n", (val >> 12) & 0x0f);
  71. printk("EC: 0x%x\n", val & 0x0fff);
  72. if (trident->device != TRIDENT_DEVICE_ID_NX) {
  73. val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS));
  74. printk("CSO: 0x%x\n", val >> 16);
  75. printk("Alpha: 0x%x\n", (val >> 4) & 0x0fff);
  76. printk("FMS: 0x%x\n", val & 0x0f);
  77. val = inl(TRID_REG(trident, CH_DX_ESO_DELTA));
  78. printk("ESO: 0x%x\n", val >> 16);
  79. printk("Delta: 0x%x\n", val & 0xffff);
  80. val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL));
  81. } else { // TRIDENT_DEVICE_ID_NX
  82. val = inl(TRID_REG(trident, CH_NX_DELTA_CSO));
  83. tmp = (val >> 24) & 0xff;
  84. printk("CSO: 0x%x\n", val & 0x00ffffff);
  85. val = inl(TRID_REG(trident, CH_NX_DELTA_ESO));
  86. tmp |= (val >> 16) & 0xff00;
  87. printk("Delta: 0x%x\n", tmp);
  88. printk("ESO: 0x%x\n", val & 0x00ffffff);
  89. val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL));
  90. printk("Alpha: 0x%x\n", val >> 20);
  91. printk("FMS: 0x%x\n", (val >> 16) & 0x0f);
  92. }
  93. printk("FMC: 0x%x\n", (val >> 14) & 3);
  94. printk("RVol: 0x%x\n", (val >> 7) & 0x7f);
  95. printk("CVol: 0x%x\n", val & 0x7f);
  96. }
  97. #endif
  98. /*---------------------------------------------------------------------------
  99. unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
  100. Description: This routine will do all of the reading from the external
  101. CODEC (AC97).
  102. Parameters: ac97 - ac97 codec structure
  103. reg - CODEC register index, from AC97 Hal.
  104. returns: 16 bit value read from the AC97.
  105. ---------------------------------------------------------------------------*/
  106. static unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
  107. {
  108. unsigned int data = 0, treg;
  109. unsigned short count = 0xffff;
  110. unsigned long flags;
  111. struct snd_trident *trident = ac97->private_data;
  112. spin_lock_irqsave(&trident->reg_lock, flags);
  113. if (trident->device == TRIDENT_DEVICE_ID_DX) {
  114. data = (DX_AC97_BUSY_READ | (reg & 0x000000ff));
  115. outl(data, TRID_REG(trident, DX_ACR1_AC97_R));
  116. do {
  117. data = inl(TRID_REG(trident, DX_ACR1_AC97_R));
  118. if ((data & DX_AC97_BUSY_READ) == 0)
  119. break;
  120. } while (--count);
  121. } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
  122. data = (NX_AC97_BUSY_READ | (reg & 0x000000ff));
  123. treg = ac97->num == 0 ? NX_ACR2_AC97_R_PRIMARY : NX_ACR3_AC97_R_SECONDARY;
  124. outl(data, TRID_REG(trident, treg));
  125. do {
  126. data = inl(TRID_REG(trident, treg));
  127. if ((data & 0x00000C00) == 0)
  128. break;
  129. } while (--count);
  130. } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  131. data = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff);
  132. if (ac97->num == 1)
  133. data |= SI_AC97_SECONDARY;
  134. outl(data, TRID_REG(trident, SI_AC97_READ));
  135. do {
  136. data = inl(TRID_REG(trident, SI_AC97_READ));
  137. if ((data & (SI_AC97_BUSY_READ)) == 0)
  138. break;
  139. } while (--count);
  140. }
  141. if (count == 0 && !trident->ac97_detect) {
  142. snd_printk(KERN_ERR "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
  143. reg, data);
  144. data = 0;
  145. }
  146. spin_unlock_irqrestore(&trident->reg_lock, flags);
  147. return ((unsigned short) (data >> 16));
  148. }
  149. /*---------------------------------------------------------------------------
  150. void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  151. unsigned short wdata)
  152. Description: This routine will do all of the writing to the external
  153. CODEC (AC97).
  154. Parameters: ac97 - ac97 codec structure
  155. reg - CODEC register index, from AC97 Hal.
  156. data - Lower 16 bits are the data to write to CODEC.
  157. returns: TRUE if everything went ok, else FALSE.
  158. ---------------------------------------------------------------------------*/
  159. static void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  160. unsigned short wdata)
  161. {
  162. unsigned int address, data;
  163. unsigned short count = 0xffff;
  164. unsigned long flags;
  165. struct snd_trident *trident = ac97->private_data;
  166. data = ((unsigned long) wdata) << 16;
  167. spin_lock_irqsave(&trident->reg_lock, flags);
  168. if (trident->device == TRIDENT_DEVICE_ID_DX) {
  169. address = DX_ACR0_AC97_W;
  170. /* read AC-97 write register status */
  171. do {
  172. if ((inw(TRID_REG(trident, address)) & DX_AC97_BUSY_WRITE) == 0)
  173. break;
  174. } while (--count);
  175. data |= (DX_AC97_BUSY_WRITE | (reg & 0x000000ff));
  176. } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
  177. address = NX_ACR1_AC97_W;
  178. /* read AC-97 write register status */
  179. do {
  180. if ((inw(TRID_REG(trident, address)) & NX_AC97_BUSY_WRITE) == 0)
  181. break;
  182. } while (--count);
  183. data |= (NX_AC97_BUSY_WRITE | (ac97->num << 8) | (reg & 0x000000ff));
  184. } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  185. address = SI_AC97_WRITE;
  186. /* read AC-97 write register status */
  187. do {
  188. if ((inw(TRID_REG(trident, address)) & (SI_AC97_BUSY_WRITE)) == 0)
  189. break;
  190. } while (--count);
  191. data |= SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff);
  192. if (ac97->num == 1)
  193. data |= SI_AC97_SECONDARY;
  194. } else {
  195. address = 0; /* keep GCC happy */
  196. count = 0; /* return */
  197. }
  198. if (count == 0) {
  199. spin_unlock_irqrestore(&trident->reg_lock, flags);
  200. return;
  201. }
  202. outl(data, TRID_REG(trident, address));
  203. spin_unlock_irqrestore(&trident->reg_lock, flags);
  204. }
  205. /*---------------------------------------------------------------------------
  206. void snd_trident_enable_eso(struct snd_trident *trident)
  207. Description: This routine will enable end of loop interrupts.
  208. End of loop interrupts will occur when a running
  209. channel reaches ESO.
  210. Also enables middle of loop interrupts.
  211. Parameters: trident - pointer to target device class for 4DWave.
  212. ---------------------------------------------------------------------------*/
  213. static void snd_trident_enable_eso(struct snd_trident * trident)
  214. {
  215. unsigned int val;
  216. val = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
  217. val |= ENDLP_IE;
  218. val |= MIDLP_IE;
  219. if (trident->device == TRIDENT_DEVICE_ID_SI7018)
  220. val |= BANK_B_EN;
  221. outl(val, TRID_REG(trident, T4D_LFO_GC_CIR));
  222. }
  223. /*---------------------------------------------------------------------------
  224. void snd_trident_disable_eso(struct snd_trident *trident)
  225. Description: This routine will disable end of loop interrupts.
  226. End of loop interrupts will occur when a running
  227. channel reaches ESO.
  228. Also disables middle of loop interrupts.
  229. Parameters:
  230. trident - pointer to target device class for 4DWave.
  231. returns: TRUE if everything went ok, else FALSE.
  232. ---------------------------------------------------------------------------*/
  233. static void snd_trident_disable_eso(struct snd_trident * trident)
  234. {
  235. unsigned int tmp;
  236. tmp = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
  237. tmp &= ~ENDLP_IE;
  238. tmp &= ~MIDLP_IE;
  239. outl(tmp, TRID_REG(trident, T4D_LFO_GC_CIR));
  240. }
  241. /*---------------------------------------------------------------------------
  242. void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
  243. Description: Start a voice, any channel 0 thru 63.
  244. This routine automatically handles the fact that there are
  245. more than 32 channels available.
  246. Parameters : voice - Voice number 0 thru n.
  247. trident - pointer to target device class for 4DWave.
  248. Return Value: None.
  249. ---------------------------------------------------------------------------*/
  250. void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
  251. {
  252. unsigned int mask = 1 << (voice & 0x1f);
  253. unsigned int reg = (voice & 0x20) ? T4D_START_B : T4D_START_A;
  254. outl(mask, TRID_REG(trident, reg));
  255. }
  256. /*---------------------------------------------------------------------------
  257. void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
  258. Description: Stop a voice, any channel 0 thru 63.
  259. This routine automatically handles the fact that there are
  260. more than 32 channels available.
  261. Parameters : voice - Voice number 0 thru n.
  262. trident - pointer to target device class for 4DWave.
  263. Return Value: None.
  264. ---------------------------------------------------------------------------*/
  265. void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
  266. {
  267. unsigned int mask = 1 << (voice & 0x1f);
  268. unsigned int reg = (voice & 0x20) ? T4D_STOP_B : T4D_STOP_A;
  269. outl(mask, TRID_REG(trident, reg));
  270. }
  271. /*---------------------------------------------------------------------------
  272. int snd_trident_allocate_pcm_channel(struct snd_trident *trident)
  273. Description: Allocate hardware channel in Bank B (32-63).
  274. Parameters : trident - pointer to target device class for 4DWave.
  275. Return Value: hardware channel - 32-63 or -1 when no channel is available
  276. ---------------------------------------------------------------------------*/
  277. static int snd_trident_allocate_pcm_channel(struct snd_trident * trident)
  278. {
  279. int idx;
  280. if (trident->ChanPCMcnt >= trident->ChanPCM)
  281. return -1;
  282. for (idx = 31; idx >= 0; idx--) {
  283. if (!(trident->ChanMap[T4D_BANK_B] & (1 << idx))) {
  284. trident->ChanMap[T4D_BANK_B] |= 1 << idx;
  285. trident->ChanPCMcnt++;
  286. return idx + 32;
  287. }
  288. }
  289. return -1;
  290. }
  291. /*---------------------------------------------------------------------------
  292. void snd_trident_free_pcm_channel(int channel)
  293. Description: Free hardware channel in Bank B (32-63)
  294. Parameters : trident - pointer to target device class for 4DWave.
  295. channel - hardware channel number 0-63
  296. Return Value: none
  297. ---------------------------------------------------------------------------*/
  298. static void snd_trident_free_pcm_channel(struct snd_trident *trident, int channel)
  299. {
  300. if (channel < 32 || channel > 63)
  301. return;
  302. channel &= 0x1f;
  303. if (trident->ChanMap[T4D_BANK_B] & (1 << channel)) {
  304. trident->ChanMap[T4D_BANK_B] &= ~(1 << channel);
  305. trident->ChanPCMcnt--;
  306. }
  307. }
  308. /*---------------------------------------------------------------------------
  309. unsigned int snd_trident_allocate_synth_channel(void)
  310. Description: Allocate hardware channel in Bank A (0-31).
  311. Parameters : trident - pointer to target device class for 4DWave.
  312. Return Value: hardware channel - 0-31 or -1 when no channel is available
  313. ---------------------------------------------------------------------------*/
  314. static int snd_trident_allocate_synth_channel(struct snd_trident * trident)
  315. {
  316. int idx;
  317. for (idx = 31; idx >= 0; idx--) {
  318. if (!(trident->ChanMap[T4D_BANK_A] & (1 << idx))) {
  319. trident->ChanMap[T4D_BANK_A] |= 1 << idx;
  320. trident->synth.ChanSynthCount++;
  321. return idx;
  322. }
  323. }
  324. return -1;
  325. }
  326. /*---------------------------------------------------------------------------
  327. void snd_trident_free_synth_channel( int channel )
  328. Description: Free hardware channel in Bank B (0-31).
  329. Parameters : trident - pointer to target device class for 4DWave.
  330. channel - hardware channel number 0-63
  331. Return Value: none
  332. ---------------------------------------------------------------------------*/
  333. static void snd_trident_free_synth_channel(struct snd_trident *trident, int channel)
  334. {
  335. if (channel < 0 || channel > 31)
  336. return;
  337. channel &= 0x1f;
  338. if (trident->ChanMap[T4D_BANK_A] & (1 << channel)) {
  339. trident->ChanMap[T4D_BANK_A] &= ~(1 << channel);
  340. trident->synth.ChanSynthCount--;
  341. }
  342. }
  343. /*---------------------------------------------------------------------------
  344. snd_trident_write_voice_regs
  345. Description: This routine will complete and write the 5 hardware channel
  346. registers to hardware.
  347. Paramters: trident - pointer to target device class for 4DWave.
  348. voice - synthesizer voice structure
  349. Each register field.
  350. ---------------------------------------------------------------------------*/
  351. void snd_trident_write_voice_regs(struct snd_trident * trident,
  352. struct snd_trident_voice * voice)
  353. {
  354. unsigned int FmcRvolCvol;
  355. unsigned int regs[5];
  356. regs[1] = voice->LBA;
  357. regs[4] = (voice->GVSel << 31) |
  358. ((voice->Pan & 0x0000007f) << 24) |
  359. ((voice->CTRL & 0x0000000f) << 12);
  360. FmcRvolCvol = ((voice->FMC & 3) << 14) |
  361. ((voice->RVol & 0x7f) << 7) |
  362. (voice->CVol & 0x7f);
  363. switch (trident->device) {
  364. case TRIDENT_DEVICE_ID_SI7018:
  365. regs[4] |= voice->number > 31 ?
  366. (voice->Vol & 0x000003ff) :
  367. ((voice->Vol & 0x00003fc) << (16-2)) |
  368. (voice->EC & 0x00000fff);
  369. regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
  370. (voice->FMS & 0x0000000f);
  371. regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
  372. regs[3] = (voice->Attribute << 16) | FmcRvolCvol;
  373. break;
  374. case TRIDENT_DEVICE_ID_DX:
  375. regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
  376. (voice->EC & 0x00000fff);
  377. regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
  378. (voice->FMS & 0x0000000f);
  379. regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
  380. regs[3] = FmcRvolCvol;
  381. break;
  382. case TRIDENT_DEVICE_ID_NX:
  383. regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
  384. (voice->EC & 0x00000fff);
  385. regs[0] = (voice->Delta << 24) | (voice->CSO & 0x00ffffff);
  386. regs[2] = ((voice->Delta << 16) & 0xff000000) |
  387. (voice->ESO & 0x00ffffff);
  388. regs[3] = (voice->Alpha << 20) |
  389. ((voice->FMS & 0x0000000f) << 16) | FmcRvolCvol;
  390. break;
  391. default:
  392. snd_BUG();
  393. return;
  394. }
  395. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  396. outl(regs[0], TRID_REG(trident, CH_START + 0));
  397. outl(regs[1], TRID_REG(trident, CH_START + 4));
  398. outl(regs[2], TRID_REG(trident, CH_START + 8));
  399. outl(regs[3], TRID_REG(trident, CH_START + 12));
  400. outl(regs[4], TRID_REG(trident, CH_START + 16));
  401. #if 0
  402. printk("written %i channel:\n", voice->number);
  403. printk(" regs[0] = 0x%x/0x%x\n", regs[0], inl(TRID_REG(trident, CH_START + 0)));
  404. printk(" regs[1] = 0x%x/0x%x\n", regs[1], inl(TRID_REG(trident, CH_START + 4)));
  405. printk(" regs[2] = 0x%x/0x%x\n", regs[2], inl(TRID_REG(trident, CH_START + 8)));
  406. printk(" regs[3] = 0x%x/0x%x\n", regs[3], inl(TRID_REG(trident, CH_START + 12)));
  407. printk(" regs[4] = 0x%x/0x%x\n", regs[4], inl(TRID_REG(trident, CH_START + 16)));
  408. #endif
  409. }
  410. /*---------------------------------------------------------------------------
  411. snd_trident_write_cso_reg
  412. Description: This routine will write the new CSO offset
  413. register to hardware.
  414. Paramters: trident - pointer to target device class for 4DWave.
  415. voice - synthesizer voice structure
  416. CSO - new CSO value
  417. ---------------------------------------------------------------------------*/
  418. static void snd_trident_write_cso_reg(struct snd_trident * trident,
  419. struct snd_trident_voice * voice,
  420. unsigned int CSO)
  421. {
  422. voice->CSO = CSO;
  423. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  424. if (trident->device != TRIDENT_DEVICE_ID_NX) {
  425. outw(voice->CSO, TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2);
  426. } else {
  427. outl((voice->Delta << 24) |
  428. (voice->CSO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_CSO));
  429. }
  430. }
  431. /*---------------------------------------------------------------------------
  432. snd_trident_write_eso_reg
  433. Description: This routine will write the new ESO offset
  434. register to hardware.
  435. Paramters: trident - pointer to target device class for 4DWave.
  436. voice - synthesizer voice structure
  437. ESO - new ESO value
  438. ---------------------------------------------------------------------------*/
  439. static void snd_trident_write_eso_reg(struct snd_trident * trident,
  440. struct snd_trident_voice * voice,
  441. unsigned int ESO)
  442. {
  443. voice->ESO = ESO;
  444. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  445. if (trident->device != TRIDENT_DEVICE_ID_NX) {
  446. outw(voice->ESO, TRID_REG(trident, CH_DX_ESO_DELTA) + 2);
  447. } else {
  448. outl(((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff),
  449. TRID_REG(trident, CH_NX_DELTA_ESO));
  450. }
  451. }
  452. /*---------------------------------------------------------------------------
  453. snd_trident_write_vol_reg
  454. Description: This routine will write the new voice volume
  455. register to hardware.
  456. Paramters: trident - pointer to target device class for 4DWave.
  457. voice - synthesizer voice structure
  458. Vol - new voice volume
  459. ---------------------------------------------------------------------------*/
  460. static void snd_trident_write_vol_reg(struct snd_trident * trident,
  461. struct snd_trident_voice * voice,
  462. unsigned int Vol)
  463. {
  464. voice->Vol = Vol;
  465. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  466. switch (trident->device) {
  467. case TRIDENT_DEVICE_ID_DX:
  468. case TRIDENT_DEVICE_ID_NX:
  469. outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2));
  470. break;
  471. case TRIDENT_DEVICE_ID_SI7018:
  472. // printk("voice->Vol = 0x%x\n", voice->Vol);
  473. outw((voice->CTRL << 12) | voice->Vol,
  474. TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
  475. break;
  476. }
  477. }
  478. /*---------------------------------------------------------------------------
  479. snd_trident_write_pan_reg
  480. Description: This routine will write the new voice pan
  481. register to hardware.
  482. Paramters: trident - pointer to target device class for 4DWave.
  483. voice - synthesizer voice structure
  484. Pan - new pan value
  485. ---------------------------------------------------------------------------*/
  486. static void snd_trident_write_pan_reg(struct snd_trident * trident,
  487. struct snd_trident_voice * voice,
  488. unsigned int Pan)
  489. {
  490. voice->Pan = Pan;
  491. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  492. outb(((voice->GVSel & 0x01) << 7) | (voice->Pan & 0x7f),
  493. TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 3));
  494. }
  495. /*---------------------------------------------------------------------------
  496. snd_trident_write_rvol_reg
  497. Description: This routine will write the new reverb volume
  498. register to hardware.
  499. Paramters: trident - pointer to target device class for 4DWave.
  500. voice - synthesizer voice structure
  501. RVol - new reverb volume
  502. ---------------------------------------------------------------------------*/
  503. static void snd_trident_write_rvol_reg(struct snd_trident * trident,
  504. struct snd_trident_voice * voice,
  505. unsigned int RVol)
  506. {
  507. voice->RVol = RVol;
  508. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  509. outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
  510. (voice->CVol & 0x007f),
  511. TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
  512. CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL));
  513. }
  514. /*---------------------------------------------------------------------------
  515. snd_trident_write_cvol_reg
  516. Description: This routine will write the new chorus volume
  517. register to hardware.
  518. Paramters: trident - pointer to target device class for 4DWave.
  519. voice - synthesizer voice structure
  520. CVol - new chorus volume
  521. ---------------------------------------------------------------------------*/
  522. static void snd_trident_write_cvol_reg(struct snd_trident * trident,
  523. struct snd_trident_voice * voice,
  524. unsigned int CVol)
  525. {
  526. voice->CVol = CVol;
  527. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  528. outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
  529. (voice->CVol & 0x007f),
  530. TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
  531. CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL));
  532. }
  533. /*---------------------------------------------------------------------------
  534. snd_trident_convert_rate
  535. Description: This routine converts rate in HZ to hardware delta value.
  536. Paramters: trident - pointer to target device class for 4DWave.
  537. rate - Real or Virtual channel number.
  538. Returns: Delta value.
  539. ---------------------------------------------------------------------------*/
  540. static unsigned int snd_trident_convert_rate(unsigned int rate)
  541. {
  542. unsigned int delta;
  543. // We special case 44100 and 8000 since rounding with the equation
  544. // does not give us an accurate enough value. For 11025 and 22050
  545. // the equation gives us the best answer. All other frequencies will
  546. // also use the equation. JDW
  547. if (rate == 44100)
  548. delta = 0xeb3;
  549. else if (rate == 8000)
  550. delta = 0x2ab;
  551. else if (rate == 48000)
  552. delta = 0x1000;
  553. else
  554. delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff;
  555. return delta;
  556. }
  557. /*---------------------------------------------------------------------------
  558. snd_trident_convert_adc_rate
  559. Description: This routine converts rate in HZ to hardware delta value.
  560. Paramters: trident - pointer to target device class for 4DWave.
  561. rate - Real or Virtual channel number.
  562. Returns: Delta value.
  563. ---------------------------------------------------------------------------*/
  564. static unsigned int snd_trident_convert_adc_rate(unsigned int rate)
  565. {
  566. unsigned int delta;
  567. // We special case 44100 and 8000 since rounding with the equation
  568. // does not give us an accurate enough value. For 11025 and 22050
  569. // the equation gives us the best answer. All other frequencies will
  570. // also use the equation. JDW
  571. if (rate == 44100)
  572. delta = 0x116a;
  573. else if (rate == 8000)
  574. delta = 0x6000;
  575. else if (rate == 48000)
  576. delta = 0x1000;
  577. else
  578. delta = ((48000 << 12) / rate) & 0x0000ffff;
  579. return delta;
  580. }
  581. /*---------------------------------------------------------------------------
  582. snd_trident_spurious_threshold
  583. Description: This routine converts rate in HZ to spurious threshold.
  584. Paramters: trident - pointer to target device class for 4DWave.
  585. rate - Real or Virtual channel number.
  586. Returns: Delta value.
  587. ---------------------------------------------------------------------------*/
  588. static unsigned int snd_trident_spurious_threshold(unsigned int rate,
  589. unsigned int period_size)
  590. {
  591. unsigned int res = (rate * period_size) / 48000;
  592. if (res < 64)
  593. res = res / 2;
  594. else
  595. res -= 32;
  596. return res;
  597. }
  598. /*---------------------------------------------------------------------------
  599. snd_trident_control_mode
  600. Description: This routine returns a control mode for a PCM channel.
  601. Paramters: trident - pointer to target device class for 4DWave.
  602. substream - PCM substream
  603. Returns: Control value.
  604. ---------------------------------------------------------------------------*/
  605. static unsigned int snd_trident_control_mode(struct snd_pcm_substream *substream)
  606. {
  607. unsigned int CTRL;
  608. struct snd_pcm_runtime *runtime = substream->runtime;
  609. /* set ctrl mode
  610. CTRL default: 8-bit (unsigned) mono, loop mode enabled
  611. */
  612. CTRL = 0x00000001;
  613. if (snd_pcm_format_width(runtime->format) == 16)
  614. CTRL |= 0x00000008; // 16-bit data
  615. if (snd_pcm_format_signed(runtime->format))
  616. CTRL |= 0x00000002; // signed data
  617. if (runtime->channels > 1)
  618. CTRL |= 0x00000004; // stereo data
  619. return CTRL;
  620. }
  621. /*
  622. * PCM part
  623. */
  624. /*---------------------------------------------------------------------------
  625. snd_trident_ioctl
  626. Description: Device I/O control handler for playback/capture parameters.
  627. Paramters: substream - PCM substream class
  628. cmd - what ioctl message to process
  629. arg - additional message infoarg
  630. Returns: Error status
  631. ---------------------------------------------------------------------------*/
  632. static int snd_trident_ioctl(struct snd_pcm_substream *substream,
  633. unsigned int cmd,
  634. void *arg)
  635. {
  636. /* FIXME: it seems that with small periods the behaviour of
  637. trident hardware is unpredictable and interrupt generator
  638. is broken */
  639. return snd_pcm_lib_ioctl(substream, cmd, arg);
  640. }
  641. /*---------------------------------------------------------------------------
  642. snd_trident_allocate_pcm_mem
  643. Description: Allocate PCM ring buffer for given substream
  644. Parameters: substream - PCM substream class
  645. hw_params - hardware parameters
  646. Returns: Error status
  647. ---------------------------------------------------------------------------*/
  648. static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream *substream,
  649. struct snd_pcm_hw_params *hw_params)
  650. {
  651. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  652. struct snd_pcm_runtime *runtime = substream->runtime;
  653. struct snd_trident_voice *voice = runtime->private_data;
  654. int err;
  655. if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
  656. return err;
  657. if (trident->tlb.entries) {
  658. if (err > 0) { /* change */
  659. if (voice->memblk)
  660. snd_trident_free_pages(trident, voice->memblk);
  661. voice->memblk = snd_trident_alloc_pages(trident, substream);
  662. if (voice->memblk == NULL)
  663. return -ENOMEM;
  664. }
  665. }
  666. return 0;
  667. }
  668. /*---------------------------------------------------------------------------
  669. snd_trident_allocate_evoice
  670. Description: Allocate extra voice as interrupt generator
  671. Parameters: substream - PCM substream class
  672. hw_params - hardware parameters
  673. Returns: Error status
  674. ---------------------------------------------------------------------------*/
  675. static int snd_trident_allocate_evoice(struct snd_pcm_substream *substream,
  676. struct snd_pcm_hw_params *hw_params)
  677. {
  678. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  679. struct snd_pcm_runtime *runtime = substream->runtime;
  680. struct snd_trident_voice *voice = runtime->private_data;
  681. struct snd_trident_voice *evoice = voice->extra;
  682. /* voice management */
  683. if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) {
  684. if (evoice == NULL) {
  685. evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
  686. if (evoice == NULL)
  687. return -ENOMEM;
  688. voice->extra = evoice;
  689. evoice->substream = substream;
  690. }
  691. } else {
  692. if (evoice != NULL) {
  693. snd_trident_free_voice(trident, evoice);
  694. voice->extra = evoice = NULL;
  695. }
  696. }
  697. return 0;
  698. }
  699. /*---------------------------------------------------------------------------
  700. snd_trident_hw_params
  701. Description: Set the hardware parameters for the playback device.
  702. Parameters: substream - PCM substream class
  703. hw_params - hardware parameters
  704. Returns: Error status
  705. ---------------------------------------------------------------------------*/
  706. static int snd_trident_hw_params(struct snd_pcm_substream *substream,
  707. struct snd_pcm_hw_params *hw_params)
  708. {
  709. int err;
  710. err = snd_trident_allocate_pcm_mem(substream, hw_params);
  711. if (err >= 0)
  712. err = snd_trident_allocate_evoice(substream, hw_params);
  713. return err;
  714. }
  715. /*---------------------------------------------------------------------------
  716. snd_trident_playback_hw_free
  717. Description: Release the hardware resources for the playback device.
  718. Parameters: substream - PCM substream class
  719. Returns: Error status
  720. ---------------------------------------------------------------------------*/
  721. static int snd_trident_hw_free(struct snd_pcm_substream *substream)
  722. {
  723. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  724. struct snd_pcm_runtime *runtime = substream->runtime;
  725. struct snd_trident_voice *voice = runtime->private_data;
  726. struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
  727. if (trident->tlb.entries) {
  728. if (voice && voice->memblk) {
  729. snd_trident_free_pages(trident, voice->memblk);
  730. voice->memblk = NULL;
  731. }
  732. }
  733. snd_pcm_lib_free_pages(substream);
  734. if (evoice != NULL) {
  735. snd_trident_free_voice(trident, evoice);
  736. voice->extra = NULL;
  737. }
  738. return 0;
  739. }
  740. /*---------------------------------------------------------------------------
  741. snd_trident_playback_prepare
  742. Description: Prepare playback device for playback.
  743. Parameters: substream - PCM substream class
  744. Returns: Error status
  745. ---------------------------------------------------------------------------*/
  746. static int snd_trident_playback_prepare(struct snd_pcm_substream *substream)
  747. {
  748. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  749. struct snd_pcm_runtime *runtime = substream->runtime;
  750. struct snd_trident_voice *voice = runtime->private_data;
  751. struct snd_trident_voice *evoice = voice->extra;
  752. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
  753. spin_lock_irq(&trident->reg_lock);
  754. /* set delta (rate) value */
  755. voice->Delta = snd_trident_convert_rate(runtime->rate);
  756. voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
  757. /* set Loop Begin Address */
  758. if (voice->memblk)
  759. voice->LBA = voice->memblk->offset;
  760. else
  761. voice->LBA = runtime->dma_addr;
  762. voice->CSO = 0;
  763. voice->ESO = runtime->buffer_size - 1; /* in samples */
  764. voice->CTRL = snd_trident_control_mode(substream);
  765. voice->FMC = 3;
  766. voice->GVSel = 1;
  767. voice->EC = 0;
  768. voice->Alpha = 0;
  769. voice->FMS = 0;
  770. voice->Vol = mix->vol;
  771. voice->RVol = mix->rvol;
  772. voice->CVol = mix->cvol;
  773. voice->Pan = mix->pan;
  774. voice->Attribute = 0;
  775. #if 0
  776. voice->Attribute = (1<<(30-16))|(2<<(26-16))|
  777. (0<<(24-16))|(0x1f<<(19-16));
  778. #else
  779. voice->Attribute = 0;
  780. #endif
  781. snd_trident_write_voice_regs(trident, voice);
  782. if (evoice != NULL) {
  783. evoice->Delta = voice->Delta;
  784. evoice->spurious_threshold = voice->spurious_threshold;
  785. evoice->LBA = voice->LBA;
  786. evoice->CSO = 0;
  787. evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
  788. evoice->CTRL = voice->CTRL;
  789. evoice->FMC = 3;
  790. evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
  791. evoice->EC = 0;
  792. evoice->Alpha = 0;
  793. evoice->FMS = 0;
  794. evoice->Vol = 0x3ff; /* mute */
  795. evoice->RVol = evoice->CVol = 0x7f; /* mute */
  796. evoice->Pan = 0x7f; /* mute */
  797. #if 0
  798. evoice->Attribute = (1<<(30-16))|(2<<(26-16))|
  799. (0<<(24-16))|(0x1f<<(19-16));
  800. #else
  801. evoice->Attribute = 0;
  802. #endif
  803. snd_trident_write_voice_regs(trident, evoice);
  804. evoice->isync2 = 1;
  805. evoice->isync_mark = runtime->period_size;
  806. evoice->ESO = (runtime->period_size * 2) - 1;
  807. }
  808. spin_unlock_irq(&trident->reg_lock);
  809. return 0;
  810. }
  811. /*---------------------------------------------------------------------------
  812. snd_trident_capture_hw_params
  813. Description: Set the hardware parameters for the capture device.
  814. Parameters: substream - PCM substream class
  815. hw_params - hardware parameters
  816. Returns: Error status
  817. ---------------------------------------------------------------------------*/
  818. static int snd_trident_capture_hw_params(struct snd_pcm_substream *substream,
  819. struct snd_pcm_hw_params *hw_params)
  820. {
  821. return snd_trident_allocate_pcm_mem(substream, hw_params);
  822. }
  823. /*---------------------------------------------------------------------------
  824. snd_trident_capture_prepare
  825. Description: Prepare capture device for playback.
  826. Parameters: substream - PCM substream class
  827. Returns: Error status
  828. ---------------------------------------------------------------------------*/
  829. static int snd_trident_capture_prepare(struct snd_pcm_substream *substream)
  830. {
  831. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  832. struct snd_pcm_runtime *runtime = substream->runtime;
  833. struct snd_trident_voice *voice = runtime->private_data;
  834. unsigned int val, ESO_bytes;
  835. spin_lock_irq(&trident->reg_lock);
  836. // Initilize the channel and set channel Mode
  837. outb(0, TRID_REG(trident, LEGACY_DMAR15));
  838. // Set DMA channel operation mode register
  839. outb(0x54, TRID_REG(trident, LEGACY_DMAR11));
  840. // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
  841. voice->LBA = runtime->dma_addr;
  842. outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0));
  843. if (voice->memblk)
  844. voice->LBA = voice->memblk->offset;
  845. // set ESO
  846. ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1;
  847. outb((ESO_bytes & 0x00ff0000) >> 16, TRID_REG(trident, LEGACY_DMAR6));
  848. outw((ESO_bytes & 0x0000ffff), TRID_REG(trident, LEGACY_DMAR4));
  849. ESO_bytes++;
  850. // Set channel sample rate, 4.12 format
  851. val = (((unsigned int) 48000L << 12) + (runtime->rate/2)) / runtime->rate;
  852. outw(val, TRID_REG(trident, T4D_SBDELTA_DELTA_R));
  853. // Set channel interrupt blk length
  854. if (snd_pcm_format_width(runtime->format) == 16) {
  855. val = (unsigned short) ((ESO_bytes >> 1) - 1);
  856. } else {
  857. val = (unsigned short) (ESO_bytes - 1);
  858. }
  859. outl((val << 16) | val, TRID_REG(trident, T4D_SBBL_SBCL));
  860. // Right now, set format and start to run captureing,
  861. // continuous run loop enable.
  862. trident->bDMAStart = 0x19; // 0001 1001b
  863. if (snd_pcm_format_width(runtime->format) == 16)
  864. trident->bDMAStart |= 0x80;
  865. if (snd_pcm_format_signed(runtime->format))
  866. trident->bDMAStart |= 0x20;
  867. if (runtime->channels > 1)
  868. trident->bDMAStart |= 0x40;
  869. // Prepare capture intr channel
  870. voice->Delta = snd_trident_convert_rate(runtime->rate);
  871. voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
  872. voice->isync = 1;
  873. voice->isync_mark = runtime->period_size;
  874. voice->isync_max = runtime->buffer_size;
  875. // Set voice parameters
  876. voice->CSO = 0;
  877. voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
  878. voice->CTRL = snd_trident_control_mode(substream);
  879. voice->FMC = 3;
  880. voice->RVol = 0x7f;
  881. voice->CVol = 0x7f;
  882. voice->GVSel = 1;
  883. voice->Pan = 0x7f; /* mute */
  884. voice->Vol = 0x3ff; /* mute */
  885. voice->EC = 0;
  886. voice->Alpha = 0;
  887. voice->FMS = 0;
  888. voice->Attribute = 0;
  889. snd_trident_write_voice_regs(trident, voice);
  890. spin_unlock_irq(&trident->reg_lock);
  891. return 0;
  892. }
  893. /*---------------------------------------------------------------------------
  894. snd_trident_si7018_capture_hw_params
  895. Description: Set the hardware parameters for the capture device.
  896. Parameters: substream - PCM substream class
  897. hw_params - hardware parameters
  898. Returns: Error status
  899. ---------------------------------------------------------------------------*/
  900. static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream *substream,
  901. struct snd_pcm_hw_params *hw_params)
  902. {
  903. int err;
  904. if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
  905. return err;
  906. return snd_trident_allocate_evoice(substream, hw_params);
  907. }
  908. /*---------------------------------------------------------------------------
  909. snd_trident_si7018_capture_hw_free
  910. Description: Release the hardware resources for the capture device.
  911. Parameters: substream - PCM substream class
  912. Returns: Error status
  913. ---------------------------------------------------------------------------*/
  914. static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream *substream)
  915. {
  916. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  917. struct snd_pcm_runtime *runtime = substream->runtime;
  918. struct snd_trident_voice *voice = runtime->private_data;
  919. struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
  920. snd_pcm_lib_free_pages(substream);
  921. if (evoice != NULL) {
  922. snd_trident_free_voice(trident, evoice);
  923. voice->extra = NULL;
  924. }
  925. return 0;
  926. }
  927. /*---------------------------------------------------------------------------
  928. snd_trident_si7018_capture_prepare
  929. Description: Prepare capture device for playback.
  930. Parameters: substream - PCM substream class
  931. Returns: Error status
  932. ---------------------------------------------------------------------------*/
  933. static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream *substream)
  934. {
  935. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  936. struct snd_pcm_runtime *runtime = substream->runtime;
  937. struct snd_trident_voice *voice = runtime->private_data;
  938. struct snd_trident_voice *evoice = voice->extra;
  939. spin_lock_irq(&trident->reg_lock);
  940. voice->LBA = runtime->dma_addr;
  941. voice->Delta = snd_trident_convert_adc_rate(runtime->rate);
  942. voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
  943. // Set voice parameters
  944. voice->CSO = 0;
  945. voice->ESO = runtime->buffer_size - 1; /* in samples */
  946. voice->CTRL = snd_trident_control_mode(substream);
  947. voice->FMC = 0;
  948. voice->RVol = 0;
  949. voice->CVol = 0;
  950. voice->GVSel = 1;
  951. voice->Pan = T4D_DEFAULT_PCM_PAN;
  952. voice->Vol = 0;
  953. voice->EC = 0;
  954. voice->Alpha = 0;
  955. voice->FMS = 0;
  956. voice->Attribute = (2 << (30-16)) |
  957. (2 << (26-16)) |
  958. (2 << (24-16)) |
  959. (1 << (23-16));
  960. snd_trident_write_voice_regs(trident, voice);
  961. if (evoice != NULL) {
  962. evoice->Delta = snd_trident_convert_rate(runtime->rate);
  963. evoice->spurious_threshold = voice->spurious_threshold;
  964. evoice->LBA = voice->LBA;
  965. evoice->CSO = 0;
  966. evoice->ESO = (runtime->period_size * 2) + 20 - 1; /* in samples, 20 means correction */
  967. evoice->CTRL = voice->CTRL;
  968. evoice->FMC = 3;
  969. evoice->GVSel = 0;
  970. evoice->EC = 0;
  971. evoice->Alpha = 0;
  972. evoice->FMS = 0;
  973. evoice->Vol = 0x3ff; /* mute */
  974. evoice->RVol = evoice->CVol = 0x7f; /* mute */
  975. evoice->Pan = 0x7f; /* mute */
  976. evoice->Attribute = 0;
  977. snd_trident_write_voice_regs(trident, evoice);
  978. evoice->isync2 = 1;
  979. evoice->isync_mark = runtime->period_size;
  980. evoice->ESO = (runtime->period_size * 2) - 1;
  981. }
  982. spin_unlock_irq(&trident->reg_lock);
  983. return 0;
  984. }
  985. /*---------------------------------------------------------------------------
  986. snd_trident_foldback_prepare
  987. Description: Prepare foldback capture device for playback.
  988. Parameters: substream - PCM substream class
  989. Returns: Error status
  990. ---------------------------------------------------------------------------*/
  991. static int snd_trident_foldback_prepare(struct snd_pcm_substream *substream)
  992. {
  993. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  994. struct snd_pcm_runtime *runtime = substream->runtime;
  995. struct snd_trident_voice *voice = runtime->private_data;
  996. struct snd_trident_voice *evoice = voice->extra;
  997. spin_lock_irq(&trident->reg_lock);
  998. /* Set channel buffer Address */
  999. if (voice->memblk)
  1000. voice->LBA = voice->memblk->offset;
  1001. else
  1002. voice->LBA = runtime->dma_addr;
  1003. /* set target ESO for channel */
  1004. voice->ESO = runtime->buffer_size - 1; /* in samples */
  1005. /* set sample rate */
  1006. voice->Delta = 0x1000;
  1007. voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
  1008. voice->CSO = 0;
  1009. voice->CTRL = snd_trident_control_mode(substream);
  1010. voice->FMC = 3;
  1011. voice->RVol = 0x7f;
  1012. voice->CVol = 0x7f;
  1013. voice->GVSel = 1;
  1014. voice->Pan = 0x7f; /* mute */
  1015. voice->Vol = 0x3ff; /* mute */
  1016. voice->EC = 0;
  1017. voice->Alpha = 0;
  1018. voice->FMS = 0;
  1019. voice->Attribute = 0;
  1020. /* set up capture channel */
  1021. outb(((voice->number & 0x3f) | 0x80), TRID_REG(trident, T4D_RCI + voice->foldback_chan));
  1022. snd_trident_write_voice_regs(trident, voice);
  1023. if (evoice != NULL) {
  1024. evoice->Delta = voice->Delta;
  1025. evoice->spurious_threshold = voice->spurious_threshold;
  1026. evoice->LBA = voice->LBA;
  1027. evoice->CSO = 0;
  1028. evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
  1029. evoice->CTRL = voice->CTRL;
  1030. evoice->FMC = 3;
  1031. evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
  1032. evoice->EC = 0;
  1033. evoice->Alpha = 0;
  1034. evoice->FMS = 0;
  1035. evoice->Vol = 0x3ff; /* mute */
  1036. evoice->RVol = evoice->CVol = 0x7f; /* mute */
  1037. evoice->Pan = 0x7f; /* mute */
  1038. evoice->Attribute = 0;
  1039. snd_trident_write_voice_regs(trident, evoice);
  1040. evoice->isync2 = 1;
  1041. evoice->isync_mark = runtime->period_size;
  1042. evoice->ESO = (runtime->period_size * 2) - 1;
  1043. }
  1044. spin_unlock_irq(&trident->reg_lock);
  1045. return 0;
  1046. }
  1047. /*---------------------------------------------------------------------------
  1048. snd_trident_spdif_hw_params
  1049. Description: Set the hardware parameters for the spdif device.
  1050. Parameters: substream - PCM substream class
  1051. hw_params - hardware parameters
  1052. Returns: Error status
  1053. ---------------------------------------------------------------------------*/
  1054. static int snd_trident_spdif_hw_params(struct snd_pcm_substream *substream,
  1055. struct snd_pcm_hw_params *hw_params)
  1056. {
  1057. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1058. unsigned int old_bits = 0, change = 0;
  1059. int err;
  1060. err = snd_trident_allocate_pcm_mem(substream, hw_params);
  1061. if (err < 0)
  1062. return err;
  1063. if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  1064. err = snd_trident_allocate_evoice(substream, hw_params);
  1065. if (err < 0)
  1066. return err;
  1067. }
  1068. /* prepare SPDIF channel */
  1069. spin_lock_irq(&trident->reg_lock);
  1070. old_bits = trident->spdif_pcm_bits;
  1071. if (old_bits & IEC958_AES0_PROFESSIONAL)
  1072. trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS;
  1073. else
  1074. trident->spdif_pcm_bits &= ~(IEC958_AES3_CON_FS << 24);
  1075. if (params_rate(hw_params) >= 48000) {
  1076. trident->spdif_pcm_ctrl = 0x3c; // 48000 Hz
  1077. trident->spdif_pcm_bits |=
  1078. trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
  1079. IEC958_AES0_PRO_FS_48000 :
  1080. (IEC958_AES3_CON_FS_48000 << 24);
  1081. }
  1082. else if (params_rate(hw_params) >= 44100) {
  1083. trident->spdif_pcm_ctrl = 0x3e; // 44100 Hz
  1084. trident->spdif_pcm_bits |=
  1085. trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
  1086. IEC958_AES0_PRO_FS_44100 :
  1087. (IEC958_AES3_CON_FS_44100 << 24);
  1088. }
  1089. else {
  1090. trident->spdif_pcm_ctrl = 0x3d; // 32000 Hz
  1091. trident->spdif_pcm_bits |=
  1092. trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
  1093. IEC958_AES0_PRO_FS_32000 :
  1094. (IEC958_AES3_CON_FS_32000 << 24);
  1095. }
  1096. change = old_bits != trident->spdif_pcm_bits;
  1097. spin_unlock_irq(&trident->reg_lock);
  1098. if (change)
  1099. snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id);
  1100. return 0;
  1101. }
  1102. /*---------------------------------------------------------------------------
  1103. snd_trident_spdif_prepare
  1104. Description: Prepare SPDIF device for playback.
  1105. Parameters: substream - PCM substream class
  1106. Returns: Error status
  1107. ---------------------------------------------------------------------------*/
  1108. static int snd_trident_spdif_prepare(struct snd_pcm_substream *substream)
  1109. {
  1110. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1111. struct snd_pcm_runtime *runtime = substream->runtime;
  1112. struct snd_trident_voice *voice = runtime->private_data;
  1113. struct snd_trident_voice *evoice = voice->extra;
  1114. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
  1115. unsigned int RESO, LBAO;
  1116. unsigned int temp;
  1117. spin_lock_irq(&trident->reg_lock);
  1118. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1119. /* set delta (rate) value */
  1120. voice->Delta = snd_trident_convert_rate(runtime->rate);
  1121. voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
  1122. /* set Loop Back Address */
  1123. LBAO = runtime->dma_addr;
  1124. if (voice->memblk)
  1125. voice->LBA = voice->memblk->offset;
  1126. else
  1127. voice->LBA = LBAO;
  1128. voice->isync = 1;
  1129. voice->isync3 = 1;
  1130. voice->isync_mark = runtime->period_size;
  1131. voice->isync_max = runtime->buffer_size;
  1132. /* set target ESO for channel */
  1133. RESO = runtime->buffer_size - 1;
  1134. voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
  1135. /* set ctrl mode */
  1136. voice->CTRL = snd_trident_control_mode(substream);
  1137. voice->FMC = 3;
  1138. voice->RVol = 0x7f;
  1139. voice->CVol = 0x7f;
  1140. voice->GVSel = 1;
  1141. voice->Pan = 0x7f;
  1142. voice->Vol = 0x3ff;
  1143. voice->EC = 0;
  1144. voice->CSO = 0;
  1145. voice->Alpha = 0;
  1146. voice->FMS = 0;
  1147. voice->Attribute = 0;
  1148. /* prepare surrogate IRQ channel */
  1149. snd_trident_write_voice_regs(trident, voice);
  1150. outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO));
  1151. outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2));
  1152. outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA));
  1153. outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO));
  1154. outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2));
  1155. /* set SPDIF setting */
  1156. outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  1157. outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
  1158. } else { /* SiS */
  1159. /* set delta (rate) value */
  1160. voice->Delta = 0x800;
  1161. voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
  1162. /* set Loop Begin Address */
  1163. if (voice->memblk)
  1164. voice->LBA = voice->memblk->offset;
  1165. else
  1166. voice->LBA = runtime->dma_addr;
  1167. voice->CSO = 0;
  1168. voice->ESO = runtime->buffer_size - 1; /* in samples */
  1169. voice->CTRL = snd_trident_control_mode(substream);
  1170. voice->FMC = 3;
  1171. voice->GVSel = 1;
  1172. voice->EC = 0;
  1173. voice->Alpha = 0;
  1174. voice->FMS = 0;
  1175. voice->Vol = mix->vol;
  1176. voice->RVol = mix->rvol;
  1177. voice->CVol = mix->cvol;
  1178. voice->Pan = mix->pan;
  1179. voice->Attribute = (1<<(30-16))|(7<<(26-16))|
  1180. (0<<(24-16))|(0<<(19-16));
  1181. snd_trident_write_voice_regs(trident, voice);
  1182. if (evoice != NULL) {
  1183. evoice->Delta = voice->Delta;
  1184. evoice->spurious_threshold = voice->spurious_threshold;
  1185. evoice->LBA = voice->LBA;
  1186. evoice->CSO = 0;
  1187. evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
  1188. evoice->CTRL = voice->CTRL;
  1189. evoice->FMC = 3;
  1190. evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
  1191. evoice->EC = 0;
  1192. evoice->Alpha = 0;
  1193. evoice->FMS = 0;
  1194. evoice->Vol = 0x3ff; /* mute */
  1195. evoice->RVol = evoice->CVol = 0x7f; /* mute */
  1196. evoice->Pan = 0x7f; /* mute */
  1197. evoice->Attribute = 0;
  1198. snd_trident_write_voice_regs(trident, evoice);
  1199. evoice->isync2 = 1;
  1200. evoice->isync_mark = runtime->period_size;
  1201. evoice->ESO = (runtime->period_size * 2) - 1;
  1202. }
  1203. outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
  1204. temp = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
  1205. temp &= ~(1<<19);
  1206. outl(temp, TRID_REG(trident, T4D_LFO_GC_CIR));
  1207. temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1208. temp |= SPDIF_EN;
  1209. outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1210. }
  1211. spin_unlock_irq(&trident->reg_lock);
  1212. return 0;
  1213. }
  1214. /*---------------------------------------------------------------------------
  1215. snd_trident_trigger
  1216. Description: Start/stop devices
  1217. Parameters: substream - PCM substream class
  1218. cmd - trigger command (STOP, GO)
  1219. Returns: Error status
  1220. ---------------------------------------------------------------------------*/
  1221. static int snd_trident_trigger(struct snd_pcm_substream *substream,
  1222. int cmd)
  1223. {
  1224. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1225. struct list_head *pos;
  1226. struct snd_pcm_substream *s;
  1227. unsigned int what, whati, capture_flag, spdif_flag;
  1228. struct snd_trident_voice *voice, *evoice;
  1229. unsigned int val, go;
  1230. switch (cmd) {
  1231. case SNDRV_PCM_TRIGGER_START:
  1232. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1233. case SNDRV_PCM_TRIGGER_RESUME:
  1234. go = 1;
  1235. break;
  1236. case SNDRV_PCM_TRIGGER_STOP:
  1237. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1238. case SNDRV_PCM_TRIGGER_SUSPEND:
  1239. go = 0;
  1240. break;
  1241. default:
  1242. return -EINVAL;
  1243. }
  1244. what = whati = capture_flag = spdif_flag = 0;
  1245. spin_lock(&trident->reg_lock);
  1246. val = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff;
  1247. snd_pcm_group_for_each(pos, substream) {
  1248. s = snd_pcm_group_substream_entry(pos);
  1249. if ((struct snd_trident *) snd_pcm_substream_chip(s) == trident) {
  1250. voice = s->runtime->private_data;
  1251. evoice = voice->extra;
  1252. what |= 1 << (voice->number & 0x1f);
  1253. if (evoice == NULL) {
  1254. whati |= 1 << (voice->number & 0x1f);
  1255. } else {
  1256. what |= 1 << (evoice->number & 0x1f);
  1257. whati |= 1 << (evoice->number & 0x1f);
  1258. if (go)
  1259. evoice->stimer = val;
  1260. }
  1261. if (go) {
  1262. voice->running = 1;
  1263. voice->stimer = val;
  1264. } else {
  1265. voice->running = 0;
  1266. }
  1267. snd_pcm_trigger_done(s, substream);
  1268. if (voice->capture)
  1269. capture_flag = 1;
  1270. if (voice->spdif)
  1271. spdif_flag = 1;
  1272. }
  1273. }
  1274. if (spdif_flag) {
  1275. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1276. outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
  1277. outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  1278. } else {
  1279. outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
  1280. val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN;
  1281. outl(val, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1282. }
  1283. }
  1284. if (!go)
  1285. outl(what, TRID_REG(trident, T4D_STOP_B));
  1286. val = inl(TRID_REG(trident, T4D_AINTEN_B));
  1287. if (go) {
  1288. val |= whati;
  1289. } else {
  1290. val &= ~whati;
  1291. }
  1292. outl(val, TRID_REG(trident, T4D_AINTEN_B));
  1293. if (go) {
  1294. outl(what, TRID_REG(trident, T4D_START_B));
  1295. if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
  1296. outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
  1297. } else {
  1298. if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
  1299. outb(0x00, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
  1300. }
  1301. spin_unlock(&trident->reg_lock);
  1302. return 0;
  1303. }
  1304. /*---------------------------------------------------------------------------
  1305. snd_trident_playback_pointer
  1306. Description: This routine return the playback position
  1307. Parameters: substream - PCM substream class
  1308. Returns: position of buffer
  1309. ---------------------------------------------------------------------------*/
  1310. static snd_pcm_uframes_t snd_trident_playback_pointer(struct snd_pcm_substream *substream)
  1311. {
  1312. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1313. struct snd_pcm_runtime *runtime = substream->runtime;
  1314. struct snd_trident_voice *voice = runtime->private_data;
  1315. unsigned int cso;
  1316. if (!voice->running)
  1317. return 0;
  1318. spin_lock(&trident->reg_lock);
  1319. outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
  1320. if (trident->device != TRIDENT_DEVICE_ID_NX) {
  1321. cso = inw(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS + 2));
  1322. } else { // ID_4DWAVE_NX
  1323. cso = (unsigned int) inl(TRID_REG(trident, CH_NX_DELTA_CSO)) & 0x00ffffff;
  1324. }
  1325. spin_unlock(&trident->reg_lock);
  1326. if (cso >= runtime->buffer_size)
  1327. cso = 0;
  1328. return cso;
  1329. }
  1330. /*---------------------------------------------------------------------------
  1331. snd_trident_capture_pointer
  1332. Description: This routine return the capture position
  1333. Paramters: pcm1 - PCM device class
  1334. Returns: position of buffer
  1335. ---------------------------------------------------------------------------*/
  1336. static snd_pcm_uframes_t snd_trident_capture_pointer(struct snd_pcm_substream *substream)
  1337. {
  1338. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1339. struct snd_pcm_runtime *runtime = substream->runtime;
  1340. struct snd_trident_voice *voice = runtime->private_data;
  1341. unsigned int result;
  1342. if (!voice->running)
  1343. return 0;
  1344. result = inw(TRID_REG(trident, T4D_SBBL_SBCL));
  1345. if (runtime->channels > 1)
  1346. result >>= 1;
  1347. if (result > 0)
  1348. result = runtime->buffer_size - result;
  1349. return result;
  1350. }
  1351. /*---------------------------------------------------------------------------
  1352. snd_trident_spdif_pointer
  1353. Description: This routine return the SPDIF playback position
  1354. Parameters: substream - PCM substream class
  1355. Returns: position of buffer
  1356. ---------------------------------------------------------------------------*/
  1357. static snd_pcm_uframes_t snd_trident_spdif_pointer(struct snd_pcm_substream *substream)
  1358. {
  1359. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1360. struct snd_pcm_runtime *runtime = substream->runtime;
  1361. struct snd_trident_voice *voice = runtime->private_data;
  1362. unsigned int result;
  1363. if (!voice->running)
  1364. return 0;
  1365. result = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff;
  1366. return result;
  1367. }
  1368. /*
  1369. * Playback support device description
  1370. */
  1371. static struct snd_pcm_hardware snd_trident_playback =
  1372. {
  1373. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1374. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1375. SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
  1376. SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
  1377. .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
  1378. SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
  1379. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  1380. .rate_min = 4000,
  1381. .rate_max = 48000,
  1382. .channels_min = 1,
  1383. .channels_max = 2,
  1384. .buffer_bytes_max = (256*1024),
  1385. .period_bytes_min = 64,
  1386. .period_bytes_max = (256*1024),
  1387. .periods_min = 1,
  1388. .periods_max = 1024,
  1389. .fifo_size = 0,
  1390. };
  1391. /*
  1392. * Capture support device description
  1393. */
  1394. static struct snd_pcm_hardware snd_trident_capture =
  1395. {
  1396. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1397. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1398. SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
  1399. SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
  1400. .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
  1401. SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
  1402. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  1403. .rate_min = 4000,
  1404. .rate_max = 48000,
  1405. .channels_min = 1,
  1406. .channels_max = 2,
  1407. .buffer_bytes_max = (128*1024),
  1408. .period_bytes_min = 64,
  1409. .period_bytes_max = (128*1024),
  1410. .periods_min = 1,
  1411. .periods_max = 1024,
  1412. .fifo_size = 0,
  1413. };
  1414. /*
  1415. * Foldback capture support device description
  1416. */
  1417. static struct snd_pcm_hardware snd_trident_foldback =
  1418. {
  1419. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1420. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1421. SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
  1422. SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
  1423. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1424. .rates = SNDRV_PCM_RATE_48000,
  1425. .rate_min = 48000,
  1426. .rate_max = 48000,
  1427. .channels_min = 2,
  1428. .channels_max = 2,
  1429. .buffer_bytes_max = (128*1024),
  1430. .period_bytes_min = 64,
  1431. .period_bytes_max = (128*1024),
  1432. .periods_min = 1,
  1433. .periods_max = 1024,
  1434. .fifo_size = 0,
  1435. };
  1436. /*
  1437. * SPDIF playback support device description
  1438. */
  1439. static struct snd_pcm_hardware snd_trident_spdif =
  1440. {
  1441. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1442. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1443. SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
  1444. SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
  1445. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1446. .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
  1447. SNDRV_PCM_RATE_48000),
  1448. .rate_min = 32000,
  1449. .rate_max = 48000,
  1450. .channels_min = 2,
  1451. .channels_max = 2,
  1452. .buffer_bytes_max = (128*1024),
  1453. .period_bytes_min = 64,
  1454. .period_bytes_max = (128*1024),
  1455. .periods_min = 1,
  1456. .periods_max = 1024,
  1457. .fifo_size = 0,
  1458. };
  1459. static struct snd_pcm_hardware snd_trident_spdif_7018 =
  1460. {
  1461. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1462. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1463. SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
  1464. SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
  1465. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1466. .rates = SNDRV_PCM_RATE_48000,
  1467. .rate_min = 48000,
  1468. .rate_max = 48000,
  1469. .channels_min = 2,
  1470. .channels_max = 2,
  1471. .buffer_bytes_max = (128*1024),
  1472. .period_bytes_min = 64,
  1473. .period_bytes_max = (128*1024),
  1474. .periods_min = 1,
  1475. .periods_max = 1024,
  1476. .fifo_size = 0,
  1477. };
  1478. static void snd_trident_pcm_free_substream(struct snd_pcm_runtime *runtime)
  1479. {
  1480. struct snd_trident_voice *voice = runtime->private_data;
  1481. struct snd_trident *trident;
  1482. if (voice) {
  1483. trident = voice->trident;
  1484. snd_trident_free_voice(trident, voice);
  1485. }
  1486. }
  1487. static int snd_trident_playback_open(struct snd_pcm_substream *substream)
  1488. {
  1489. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1490. struct snd_pcm_runtime *runtime = substream->runtime;
  1491. struct snd_trident_voice *voice;
  1492. voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
  1493. if (voice == NULL)
  1494. return -EAGAIN;
  1495. snd_trident_pcm_mixer_build(trident, voice, substream);
  1496. voice->substream = substream;
  1497. runtime->private_data = voice;
  1498. runtime->private_free = snd_trident_pcm_free_substream;
  1499. runtime->hw = snd_trident_playback;
  1500. snd_pcm_set_sync(substream);
  1501. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
  1502. return 0;
  1503. }
  1504. /*---------------------------------------------------------------------------
  1505. snd_trident_playback_close
  1506. Description: This routine will close the 4DWave playback device. For now
  1507. we will simply free the dma transfer buffer.
  1508. Parameters: substream - PCM substream class
  1509. ---------------------------------------------------------------------------*/
  1510. static int snd_trident_playback_close(struct snd_pcm_substream *substream)
  1511. {
  1512. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1513. struct snd_pcm_runtime *runtime = substream->runtime;
  1514. struct snd_trident_voice *voice = runtime->private_data;
  1515. snd_trident_pcm_mixer_free(trident, voice, substream);
  1516. return 0;
  1517. }
  1518. /*---------------------------------------------------------------------------
  1519. snd_trident_spdif_open
  1520. Description: This routine will open the 4DWave SPDIF device.
  1521. Parameters: substream - PCM substream class
  1522. Returns: status - success or failure flag
  1523. ---------------------------------------------------------------------------*/
  1524. static int snd_trident_spdif_open(struct snd_pcm_substream *substream)
  1525. {
  1526. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1527. struct snd_trident_voice *voice;
  1528. struct snd_pcm_runtime *runtime = substream->runtime;
  1529. voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
  1530. if (voice == NULL)
  1531. return -EAGAIN;
  1532. voice->spdif = 1;
  1533. voice->substream = substream;
  1534. spin_lock_irq(&trident->reg_lock);
  1535. trident->spdif_pcm_bits = trident->spdif_bits;
  1536. spin_unlock_irq(&trident->reg_lock);
  1537. runtime->private_data = voice;
  1538. runtime->private_free = snd_trident_pcm_free_substream;
  1539. if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  1540. runtime->hw = snd_trident_spdif;
  1541. } else {
  1542. runtime->hw = snd_trident_spdif_7018;
  1543. }
  1544. trident->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1545. snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
  1546. SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
  1547. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
  1548. return 0;
  1549. }
  1550. /*---------------------------------------------------------------------------
  1551. snd_trident_spdif_close
  1552. Description: This routine will close the 4DWave SPDIF device.
  1553. Parameters: substream - PCM substream class
  1554. ---------------------------------------------------------------------------*/
  1555. static int snd_trident_spdif_close(struct snd_pcm_substream *substream)
  1556. {
  1557. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1558. unsigned int temp;
  1559. spin_lock_irq(&trident->reg_lock);
  1560. // restore default SPDIF setting
  1561. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1562. outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  1563. outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
  1564. } else {
  1565. outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
  1566. temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1567. if (trident->spdif_ctrl) {
  1568. temp |= SPDIF_EN;
  1569. } else {
  1570. temp &= ~SPDIF_EN;
  1571. }
  1572. outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1573. }
  1574. spin_unlock_irq(&trident->reg_lock);
  1575. trident->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1576. snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
  1577. SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
  1578. return 0;
  1579. }
  1580. /*---------------------------------------------------------------------------
  1581. snd_trident_capture_open
  1582. Description: This routine will open the 4DWave capture device.
  1583. Parameters: substream - PCM substream class
  1584. Returns: status - success or failure flag
  1585. ---------------------------------------------------------------------------*/
  1586. static int snd_trident_capture_open(struct snd_pcm_substream *substream)
  1587. {
  1588. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1589. struct snd_trident_voice *voice;
  1590. struct snd_pcm_runtime *runtime = substream->runtime;
  1591. voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
  1592. if (voice == NULL)
  1593. return -EAGAIN;
  1594. voice->capture = 1;
  1595. voice->substream = substream;
  1596. runtime->private_data = voice;
  1597. runtime->private_free = snd_trident_pcm_free_substream;
  1598. runtime->hw = snd_trident_capture;
  1599. snd_pcm_set_sync(substream);
  1600. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
  1601. return 0;
  1602. }
  1603. /*---------------------------------------------------------------------------
  1604. snd_trident_capture_close
  1605. Description: This routine will close the 4DWave capture device. For now
  1606. we will simply free the dma transfer buffer.
  1607. Parameters: substream - PCM substream class
  1608. ---------------------------------------------------------------------------*/
  1609. static int snd_trident_capture_close(struct snd_pcm_substream *substream)
  1610. {
  1611. return 0;
  1612. }
  1613. /*---------------------------------------------------------------------------
  1614. snd_trident_foldback_open
  1615. Description: This routine will open the 4DWave foldback capture device.
  1616. Parameters: substream - PCM substream class
  1617. Returns: status - success or failure flag
  1618. ---------------------------------------------------------------------------*/
  1619. static int snd_trident_foldback_open(struct snd_pcm_substream *substream)
  1620. {
  1621. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1622. struct snd_trident_voice *voice;
  1623. struct snd_pcm_runtime *runtime = substream->runtime;
  1624. voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
  1625. if (voice == NULL)
  1626. return -EAGAIN;
  1627. voice->foldback_chan = substream->number;
  1628. voice->substream = substream;
  1629. runtime->private_data = voice;
  1630. runtime->private_free = snd_trident_pcm_free_substream;
  1631. runtime->hw = snd_trident_foldback;
  1632. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
  1633. return 0;
  1634. }
  1635. /*---------------------------------------------------------------------------
  1636. snd_trident_foldback_close
  1637. Description: This routine will close the 4DWave foldback capture device.
  1638. For now we will simply free the dma transfer buffer.
  1639. Parameters: substream - PCM substream class
  1640. ---------------------------------------------------------------------------*/
  1641. static int snd_trident_foldback_close(struct snd_pcm_substream *substream)
  1642. {
  1643. struct snd_trident *trident = snd_pcm_substream_chip(substream);
  1644. struct snd_trident_voice *voice;
  1645. struct snd_pcm_runtime *runtime = substream->runtime;
  1646. voice = runtime->private_data;
  1647. /* stop capture channel */
  1648. spin_lock_irq(&trident->reg_lock);
  1649. outb(0x00, TRID_REG(trident, T4D_RCI + voice->foldback_chan));
  1650. spin_unlock_irq(&trident->reg_lock);
  1651. return 0;
  1652. }
  1653. /*---------------------------------------------------------------------------
  1654. PCM operations
  1655. ---------------------------------------------------------------------------*/
  1656. static struct snd_pcm_ops snd_trident_playback_ops = {
  1657. .open = snd_trident_playback_open,
  1658. .close = snd_trident_playback_close,
  1659. .ioctl = snd_trident_ioctl,
  1660. .hw_params = snd_trident_hw_params,
  1661. .hw_free = snd_trident_hw_free,
  1662. .prepare = snd_trident_playback_prepare,
  1663. .trigger = snd_trident_trigger,
  1664. .pointer = snd_trident_playback_pointer,
  1665. };
  1666. static struct snd_pcm_ops snd_trident_nx_playback_ops = {
  1667. .open = snd_trident_playback_open,
  1668. .close = snd_trident_playback_close,
  1669. .ioctl = snd_trident_ioctl,
  1670. .hw_params = snd_trident_hw_params,
  1671. .hw_free = snd_trident_hw_free,
  1672. .prepare = snd_trident_playback_prepare,
  1673. .trigger = snd_trident_trigger,
  1674. .pointer = snd_trident_playback_pointer,
  1675. .page = snd_pcm_sgbuf_ops_page,
  1676. };
  1677. static struct snd_pcm_ops snd_trident_capture_ops = {
  1678. .open = snd_trident_capture_open,
  1679. .close = snd_trident_capture_close,
  1680. .ioctl = snd_trident_ioctl,
  1681. .hw_params = snd_trident_capture_hw_params,
  1682. .hw_free = snd_trident_hw_free,
  1683. .prepare = snd_trident_capture_prepare,
  1684. .trigger = snd_trident_trigger,
  1685. .pointer = snd_trident_capture_pointer,
  1686. };
  1687. static struct snd_pcm_ops snd_trident_si7018_capture_ops = {
  1688. .open = snd_trident_capture_open,
  1689. .close = snd_trident_capture_close,
  1690. .ioctl = snd_trident_ioctl,
  1691. .hw_params = snd_trident_si7018_capture_hw_params,
  1692. .hw_free = snd_trident_si7018_capture_hw_free,
  1693. .prepare = snd_trident_si7018_capture_prepare,
  1694. .trigger = snd_trident_trigger,
  1695. .pointer = snd_trident_playback_pointer,
  1696. };
  1697. static struct snd_pcm_ops snd_trident_foldback_ops = {
  1698. .open = snd_trident_foldback_open,
  1699. .close = snd_trident_foldback_close,
  1700. .ioctl = snd_trident_ioctl,
  1701. .hw_params = snd_trident_hw_params,
  1702. .hw_free = snd_trident_hw_free,
  1703. .prepare = snd_trident_foldback_prepare,
  1704. .trigger = snd_trident_trigger,
  1705. .pointer = snd_trident_playback_pointer,
  1706. };
  1707. static struct snd_pcm_ops snd_trident_nx_foldback_ops = {
  1708. .open = snd_trident_foldback_open,
  1709. .close = snd_trident_foldback_close,
  1710. .ioctl = snd_trident_ioctl,
  1711. .hw_params = snd_trident_hw_params,
  1712. .hw_free = snd_trident_hw_free,
  1713. .prepare = snd_trident_foldback_prepare,
  1714. .trigger = snd_trident_trigger,
  1715. .pointer = snd_trident_playback_pointer,
  1716. .page = snd_pcm_sgbuf_ops_page,
  1717. };
  1718. static struct snd_pcm_ops snd_trident_spdif_ops = {
  1719. .open = snd_trident_spdif_open,
  1720. .close = snd_trident_spdif_close,
  1721. .ioctl = snd_trident_ioctl,
  1722. .hw_params = snd_trident_spdif_hw_params,
  1723. .hw_free = snd_trident_hw_free,
  1724. .prepare = snd_trident_spdif_prepare,
  1725. .trigger = snd_trident_trigger,
  1726. .pointer = snd_trident_spdif_pointer,
  1727. };
  1728. static struct snd_pcm_ops snd_trident_spdif_7018_ops = {
  1729. .open = snd_trident_spdif_open,
  1730. .close = snd_trident_spdif_close,
  1731. .ioctl = snd_trident_ioctl,
  1732. .hw_params = snd_trident_spdif_hw_params,
  1733. .hw_free = snd_trident_hw_free,
  1734. .prepare = snd_trident_spdif_prepare,
  1735. .trigger = snd_trident_trigger,
  1736. .pointer = snd_trident_playback_pointer,
  1737. };
  1738. /*---------------------------------------------------------------------------
  1739. snd_trident_pcm
  1740. Description: This routine registers the 4DWave device for PCM support.
  1741. Paramters: trident - pointer to target device class for 4DWave.
  1742. Returns: None
  1743. ---------------------------------------------------------------------------*/
  1744. int __devinit snd_trident_pcm(struct snd_trident * trident,
  1745. int device, struct snd_pcm ** rpcm)
  1746. {
  1747. struct snd_pcm *pcm;
  1748. int err;
  1749. if (rpcm)
  1750. *rpcm = NULL;
  1751. if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, trident->ChanPCM, 1, &pcm)) < 0)
  1752. return err;
  1753. pcm->private_data = trident;
  1754. if (trident->tlb.entries) {
  1755. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_nx_playback_ops);
  1756. } else {
  1757. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_playback_ops);
  1758. }
  1759. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  1760. trident->device != TRIDENT_DEVICE_ID_SI7018 ?
  1761. &snd_trident_capture_ops :
  1762. &snd_trident_si7018_capture_ops);
  1763. pcm->info_flags = 0;
  1764. pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
  1765. strcpy(pcm->name, "Trident 4DWave");
  1766. trident->pcm = pcm;
  1767. if (trident->tlb.entries) {
  1768. struct snd_pcm_substream *substream;
  1769. for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
  1770. snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
  1771. snd_dma_pci_data(trident->pci),
  1772. 64*1024, 128*1024);
  1773. snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
  1774. SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
  1775. 64*1024, 128*1024);
  1776. } else {
  1777. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1778. snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
  1779. }
  1780. if (rpcm)
  1781. *rpcm = pcm;
  1782. return 0;
  1783. }
  1784. /*---------------------------------------------------------------------------
  1785. snd_trident_foldback_pcm
  1786. Description: This routine registers the 4DWave device for foldback PCM support.
  1787. Paramters: trident - pointer to target device class for 4DWave.
  1788. Returns: None
  1789. ---------------------------------------------------------------------------*/
  1790. int __devinit snd_trident_foldback_pcm(struct snd_trident * trident,
  1791. int device, struct snd_pcm ** rpcm)
  1792. {
  1793. struct snd_pcm *foldback;
  1794. int err;
  1795. int num_chan = 3;
  1796. struct snd_pcm_substream *substream;
  1797. if (rpcm)
  1798. *rpcm = NULL;
  1799. if (trident->device == TRIDENT_DEVICE_ID_NX)
  1800. num_chan = 4;
  1801. if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, 0, num_chan, &foldback)) < 0)
  1802. return err;
  1803. foldback->private_data = trident;
  1804. if (trident->tlb.entries)
  1805. snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_nx_foldback_ops);
  1806. else
  1807. snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_foldback_ops);
  1808. foldback->info_flags = 0;
  1809. strcpy(foldback->name, "Trident 4DWave");
  1810. substream = foldback->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  1811. strcpy(substream->name, "Front Mixer");
  1812. substream = substream->next;
  1813. strcpy(substream->name, "Reverb Mixer");
  1814. substream = substream->next;
  1815. strcpy(substream->name, "Chorus Mixer");
  1816. if (num_chan == 4) {
  1817. substream = substream->next;
  1818. strcpy(substream->name, "Second AC'97 ADC");
  1819. }
  1820. trident->foldback = foldback;
  1821. if (trident->tlb.entries)
  1822. snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV_SG,
  1823. snd_dma_pci_data(trident->pci), 0, 128*1024);
  1824. else
  1825. snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV,
  1826. snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
  1827. if (rpcm)
  1828. *rpcm = foldback;
  1829. return 0;
  1830. }
  1831. /*---------------------------------------------------------------------------
  1832. snd_trident_spdif
  1833. Description: This routine registers the 4DWave-NX device for SPDIF support.
  1834. Paramters: trident - pointer to target device class for 4DWave-NX.
  1835. Returns: None
  1836. ---------------------------------------------------------------------------*/
  1837. int __devinit snd_trident_spdif_pcm(struct snd_trident * trident,
  1838. int device, struct snd_pcm ** rpcm)
  1839. {
  1840. struct snd_pcm *spdif;
  1841. int err;
  1842. if (rpcm)
  1843. *rpcm = NULL;
  1844. if ((err = snd_pcm_new(trident->card, "trident_dx_nx IEC958", device, 1, 0, &spdif)) < 0)
  1845. return err;
  1846. spdif->private_data = trident;
  1847. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1848. snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops);
  1849. } else {
  1850. snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_7018_ops);
  1851. }
  1852. spdif->info_flags = 0;
  1853. strcpy(spdif->name, "Trident 4DWave IEC958");
  1854. trident->spdif = spdif;
  1855. snd_pcm_lib_preallocate_pages_for_all(spdif, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
  1856. if (rpcm)
  1857. *rpcm = spdif;
  1858. return 0;
  1859. }
  1860. /*
  1861. * Mixer part
  1862. */
  1863. /*---------------------------------------------------------------------------
  1864. snd_trident_spdif_control
  1865. Description: enable/disable S/PDIF out from ac97 mixer
  1866. ---------------------------------------------------------------------------*/
  1867. static int snd_trident_spdif_control_info(struct snd_kcontrol *kcontrol,
  1868. struct snd_ctl_elem_info *uinfo)
  1869. {
  1870. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1871. uinfo->count = 1;
  1872. uinfo->value.integer.min = 0;
  1873. uinfo->value.integer.max = 1;
  1874. return 0;
  1875. }
  1876. static int snd_trident_spdif_control_get(struct snd_kcontrol *kcontrol,
  1877. struct snd_ctl_elem_value *ucontrol)
  1878. {
  1879. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  1880. unsigned char val;
  1881. spin_lock_irq(&trident->reg_lock);
  1882. val = trident->spdif_ctrl;
  1883. ucontrol->value.integer.value[0] = val == kcontrol->private_value;
  1884. spin_unlock_irq(&trident->reg_lock);
  1885. return 0;
  1886. }
  1887. static int snd_trident_spdif_control_put(struct snd_kcontrol *kcontrol,
  1888. struct snd_ctl_elem_value *ucontrol)
  1889. {
  1890. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  1891. unsigned char val;
  1892. int change;
  1893. val = ucontrol->value.integer.value[0] ? (unsigned char) kcontrol->private_value : 0x00;
  1894. spin_lock_irq(&trident->reg_lock);
  1895. /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
  1896. change = trident->spdif_ctrl != val;
  1897. trident->spdif_ctrl = val;
  1898. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1899. if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) {
  1900. outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
  1901. outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  1902. }
  1903. } else {
  1904. if (trident->spdif == NULL) {
  1905. unsigned int temp;
  1906. outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
  1907. temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & ~SPDIF_EN;
  1908. if (val)
  1909. temp |= SPDIF_EN;
  1910. outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  1911. }
  1912. }
  1913. spin_unlock_irq(&trident->reg_lock);
  1914. return change;
  1915. }
  1916. static struct snd_kcontrol_new snd_trident_spdif_control __devinitdata =
  1917. {
  1918. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1919. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
  1920. .info = snd_trident_spdif_control_info,
  1921. .get = snd_trident_spdif_control_get,
  1922. .put = snd_trident_spdif_control_put,
  1923. .private_value = 0x28,
  1924. };
  1925. /*---------------------------------------------------------------------------
  1926. snd_trident_spdif_default
  1927. Description: put/get the S/PDIF default settings
  1928. ---------------------------------------------------------------------------*/
  1929. static int snd_trident_spdif_default_info(struct snd_kcontrol *kcontrol,
  1930. struct snd_ctl_elem_info *uinfo)
  1931. {
  1932. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1933. uinfo->count = 1;
  1934. return 0;
  1935. }
  1936. static int snd_trident_spdif_default_get(struct snd_kcontrol *kcontrol,
  1937. struct snd_ctl_elem_value *ucontrol)
  1938. {
  1939. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  1940. spin_lock_irq(&trident->reg_lock);
  1941. ucontrol->value.iec958.status[0] = (trident->spdif_bits >> 0) & 0xff;
  1942. ucontrol->value.iec958.status[1] = (trident->spdif_bits >> 8) & 0xff;
  1943. ucontrol->value.iec958.status[2] = (trident->spdif_bits >> 16) & 0xff;
  1944. ucontrol->value.iec958.status[3] = (trident->spdif_bits >> 24) & 0xff;
  1945. spin_unlock_irq(&trident->reg_lock);
  1946. return 0;
  1947. }
  1948. static int snd_trident_spdif_default_put(struct snd_kcontrol *kcontrol,
  1949. struct snd_ctl_elem_value *ucontrol)
  1950. {
  1951. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  1952. unsigned int val;
  1953. int change;
  1954. val = (ucontrol->value.iec958.status[0] << 0) |
  1955. (ucontrol->value.iec958.status[1] << 8) |
  1956. (ucontrol->value.iec958.status[2] << 16) |
  1957. (ucontrol->value.iec958.status[3] << 24);
  1958. spin_lock_irq(&trident->reg_lock);
  1959. change = trident->spdif_bits != val;
  1960. trident->spdif_bits = val;
  1961. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  1962. if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0)
  1963. outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
  1964. } else {
  1965. if (trident->spdif == NULL)
  1966. outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
  1967. }
  1968. spin_unlock_irq(&trident->reg_lock);
  1969. return change;
  1970. }
  1971. static struct snd_kcontrol_new snd_trident_spdif_default __devinitdata =
  1972. {
  1973. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1974. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  1975. .info = snd_trident_spdif_default_info,
  1976. .get = snd_trident_spdif_default_get,
  1977. .put = snd_trident_spdif_default_put
  1978. };
  1979. /*---------------------------------------------------------------------------
  1980. snd_trident_spdif_mask
  1981. Description: put/get the S/PDIF mask
  1982. ---------------------------------------------------------------------------*/
  1983. static int snd_trident_spdif_mask_info(struct snd_kcontrol *kcontrol,
  1984. struct snd_ctl_elem_info *uinfo)
  1985. {
  1986. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1987. uinfo->count = 1;
  1988. return 0;
  1989. }
  1990. static int snd_trident_spdif_mask_get(struct snd_kcontrol *kcontrol,
  1991. struct snd_ctl_elem_value *ucontrol)
  1992. {
  1993. ucontrol->value.iec958.status[0] = 0xff;
  1994. ucontrol->value.iec958.status[1] = 0xff;
  1995. ucontrol->value.iec958.status[2] = 0xff;
  1996. ucontrol->value.iec958.status[3] = 0xff;
  1997. return 0;
  1998. }
  1999. static struct snd_kcontrol_new snd_trident_spdif_mask __devinitdata =
  2000. {
  2001. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  2002. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2003. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  2004. .info = snd_trident_spdif_mask_info,
  2005. .get = snd_trident_spdif_mask_get,
  2006. };
  2007. /*---------------------------------------------------------------------------
  2008. snd_trident_spdif_stream
  2009. Description: put/get the S/PDIF stream settings
  2010. ---------------------------------------------------------------------------*/
  2011. static int snd_trident_spdif_stream_info(struct snd_kcontrol *kcontrol,
  2012. struct snd_ctl_elem_info *uinfo)
  2013. {
  2014. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  2015. uinfo->count = 1;
  2016. return 0;
  2017. }
  2018. static int snd_trident_spdif_stream_get(struct snd_kcontrol *kcontrol,
  2019. struct snd_ctl_elem_value *ucontrol)
  2020. {
  2021. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2022. spin_lock_irq(&trident->reg_lock);
  2023. ucontrol->value.iec958.status[0] = (trident->spdif_pcm_bits >> 0) & 0xff;
  2024. ucontrol->value.iec958.status[1] = (trident->spdif_pcm_bits >> 8) & 0xff;
  2025. ucontrol->value.iec958.status[2] = (trident->spdif_pcm_bits >> 16) & 0xff;
  2026. ucontrol->value.iec958.status[3] = (trident->spdif_pcm_bits >> 24) & 0xff;
  2027. spin_unlock_irq(&trident->reg_lock);
  2028. return 0;
  2029. }
  2030. static int snd_trident_spdif_stream_put(struct snd_kcontrol *kcontrol,
  2031. struct snd_ctl_elem_value *ucontrol)
  2032. {
  2033. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2034. unsigned int val;
  2035. int change;
  2036. val = (ucontrol->value.iec958.status[0] << 0) |
  2037. (ucontrol->value.iec958.status[1] << 8) |
  2038. (ucontrol->value.iec958.status[2] << 16) |
  2039. (ucontrol->value.iec958.status[3] << 24);
  2040. spin_lock_irq(&trident->reg_lock);
  2041. change = trident->spdif_pcm_bits != val;
  2042. trident->spdif_pcm_bits = val;
  2043. if (trident->spdif != NULL) {
  2044. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  2045. outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
  2046. } else {
  2047. outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
  2048. }
  2049. }
  2050. spin_unlock_irq(&trident->reg_lock);
  2051. return change;
  2052. }
  2053. static struct snd_kcontrol_new snd_trident_spdif_stream __devinitdata =
  2054. {
  2055. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2056. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2057. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  2058. .info = snd_trident_spdif_stream_info,
  2059. .get = snd_trident_spdif_stream_get,
  2060. .put = snd_trident_spdif_stream_put
  2061. };
  2062. /*---------------------------------------------------------------------------
  2063. snd_trident_ac97_control
  2064. Description: enable/disable rear path for ac97
  2065. ---------------------------------------------------------------------------*/
  2066. static int snd_trident_ac97_control_info(struct snd_kcontrol *kcontrol,
  2067. struct snd_ctl_elem_info *uinfo)
  2068. {
  2069. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2070. uinfo->count = 1;
  2071. uinfo->value.integer.min = 0;
  2072. uinfo->value.integer.max = 1;
  2073. return 0;
  2074. }
  2075. static int snd_trident_ac97_control_get(struct snd_kcontrol *kcontrol,
  2076. struct snd_ctl_elem_value *ucontrol)
  2077. {
  2078. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2079. unsigned char val;
  2080. spin_lock_irq(&trident->reg_lock);
  2081. val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2082. ucontrol->value.integer.value[0] = (val & (1 << kcontrol->private_value)) ? 1 : 0;
  2083. spin_unlock_irq(&trident->reg_lock);
  2084. return 0;
  2085. }
  2086. static int snd_trident_ac97_control_put(struct snd_kcontrol *kcontrol,
  2087. struct snd_ctl_elem_value *ucontrol)
  2088. {
  2089. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2090. unsigned char val;
  2091. int change = 0;
  2092. spin_lock_irq(&trident->reg_lock);
  2093. val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2094. val &= ~(1 << kcontrol->private_value);
  2095. if (ucontrol->value.integer.value[0])
  2096. val |= 1 << kcontrol->private_value;
  2097. change = val != trident->ac97_ctrl;
  2098. trident->ac97_ctrl = val;
  2099. outl(trident->ac97_ctrl = val, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2100. spin_unlock_irq(&trident->reg_lock);
  2101. return change;
  2102. }
  2103. static struct snd_kcontrol_new snd_trident_ac97_rear_control __devinitdata =
  2104. {
  2105. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2106. .name = "Rear Path",
  2107. .info = snd_trident_ac97_control_info,
  2108. .get = snd_trident_ac97_control_get,
  2109. .put = snd_trident_ac97_control_put,
  2110. .private_value = 4,
  2111. };
  2112. /*---------------------------------------------------------------------------
  2113. snd_trident_vol_control
  2114. Description: wave & music volume control
  2115. ---------------------------------------------------------------------------*/
  2116. static int snd_trident_vol_control_info(struct snd_kcontrol *kcontrol,
  2117. struct snd_ctl_elem_info *uinfo)
  2118. {
  2119. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2120. uinfo->count = 2;
  2121. uinfo->value.integer.min = 0;
  2122. uinfo->value.integer.max = 255;
  2123. return 0;
  2124. }
  2125. static int snd_trident_vol_control_get(struct snd_kcontrol *kcontrol,
  2126. struct snd_ctl_elem_value *ucontrol)
  2127. {
  2128. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2129. unsigned int val;
  2130. val = trident->musicvol_wavevol;
  2131. ucontrol->value.integer.value[0] = 255 - ((val >> kcontrol->private_value) & 0xff);
  2132. ucontrol->value.integer.value[1] = 255 - ((val >> (kcontrol->private_value + 8)) & 0xff);
  2133. return 0;
  2134. }
  2135. static int snd_trident_vol_control_put(struct snd_kcontrol *kcontrol,
  2136. struct snd_ctl_elem_value *ucontrol)
  2137. {
  2138. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2139. unsigned int val;
  2140. int change = 0;
  2141. spin_lock_irq(&trident->reg_lock);
  2142. val = trident->musicvol_wavevol;
  2143. val &= ~(0xffff << kcontrol->private_value);
  2144. val |= ((255 - (ucontrol->value.integer.value[0] & 0xff)) |
  2145. ((255 - (ucontrol->value.integer.value[1] & 0xff)) << 8)) << kcontrol->private_value;
  2146. change = val != trident->musicvol_wavevol;
  2147. outl(trident->musicvol_wavevol = val, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
  2148. spin_unlock_irq(&trident->reg_lock);
  2149. return change;
  2150. }
  2151. static struct snd_kcontrol_new snd_trident_vol_music_control __devinitdata =
  2152. {
  2153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2154. .name = "Music Playback Volume",
  2155. .info = snd_trident_vol_control_info,
  2156. .get = snd_trident_vol_control_get,
  2157. .put = snd_trident_vol_control_put,
  2158. .private_value = 16,
  2159. };
  2160. static struct snd_kcontrol_new snd_trident_vol_wave_control __devinitdata =
  2161. {
  2162. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2163. .name = "Wave Playback Volume",
  2164. .info = snd_trident_vol_control_info,
  2165. .get = snd_trident_vol_control_get,
  2166. .put = snd_trident_vol_control_put,
  2167. .private_value = 0,
  2168. };
  2169. /*---------------------------------------------------------------------------
  2170. snd_trident_pcm_vol_control
  2171. Description: PCM front volume control
  2172. ---------------------------------------------------------------------------*/
  2173. static int snd_trident_pcm_vol_control_info(struct snd_kcontrol *kcontrol,
  2174. struct snd_ctl_elem_info *uinfo)
  2175. {
  2176. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2177. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2178. uinfo->count = 1;
  2179. uinfo->value.integer.min = 0;
  2180. uinfo->value.integer.max = 255;
  2181. if (trident->device == TRIDENT_DEVICE_ID_SI7018)
  2182. uinfo->value.integer.max = 1023;
  2183. return 0;
  2184. }
  2185. static int snd_trident_pcm_vol_control_get(struct snd_kcontrol *kcontrol,
  2186. struct snd_ctl_elem_value *ucontrol)
  2187. {
  2188. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2189. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2190. if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  2191. ucontrol->value.integer.value[0] = 1023 - mix->vol;
  2192. } else {
  2193. ucontrol->value.integer.value[0] = 255 - (mix->vol>>2);
  2194. }
  2195. return 0;
  2196. }
  2197. static int snd_trident_pcm_vol_control_put(struct snd_kcontrol *kcontrol,
  2198. struct snd_ctl_elem_value *ucontrol)
  2199. {
  2200. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2201. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2202. unsigned int val;
  2203. int change = 0;
  2204. if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  2205. val = 1023 - (ucontrol->value.integer.value[0] & 1023);
  2206. } else {
  2207. val = (255 - (ucontrol->value.integer.value[0] & 255)) << 2;
  2208. }
  2209. spin_lock_irq(&trident->reg_lock);
  2210. change = val != mix->vol;
  2211. mix->vol = val;
  2212. if (mix->voice != NULL)
  2213. snd_trident_write_vol_reg(trident, mix->voice, val);
  2214. spin_unlock_irq(&trident->reg_lock);
  2215. return change;
  2216. }
  2217. static struct snd_kcontrol_new snd_trident_pcm_vol_control __devinitdata =
  2218. {
  2219. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2220. .name = "PCM Front Playback Volume",
  2221. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2222. .count = 32,
  2223. .info = snd_trident_pcm_vol_control_info,
  2224. .get = snd_trident_pcm_vol_control_get,
  2225. .put = snd_trident_pcm_vol_control_put,
  2226. };
  2227. /*---------------------------------------------------------------------------
  2228. snd_trident_pcm_pan_control
  2229. Description: PCM front pan control
  2230. ---------------------------------------------------------------------------*/
  2231. static int snd_trident_pcm_pan_control_info(struct snd_kcontrol *kcontrol,
  2232. struct snd_ctl_elem_info *uinfo)
  2233. {
  2234. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2235. uinfo->count = 1;
  2236. uinfo->value.integer.min = 0;
  2237. uinfo->value.integer.max = 127;
  2238. return 0;
  2239. }
  2240. static int snd_trident_pcm_pan_control_get(struct snd_kcontrol *kcontrol,
  2241. struct snd_ctl_elem_value *ucontrol)
  2242. {
  2243. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2244. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2245. ucontrol->value.integer.value[0] = mix->pan;
  2246. if (ucontrol->value.integer.value[0] & 0x40) {
  2247. ucontrol->value.integer.value[0] = (0x3f - (ucontrol->value.integer.value[0] & 0x3f));
  2248. } else {
  2249. ucontrol->value.integer.value[0] |= 0x40;
  2250. }
  2251. return 0;
  2252. }
  2253. static int snd_trident_pcm_pan_control_put(struct snd_kcontrol *kcontrol,
  2254. struct snd_ctl_elem_value *ucontrol)
  2255. {
  2256. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2257. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2258. unsigned char val;
  2259. int change = 0;
  2260. if (ucontrol->value.integer.value[0] & 0x40)
  2261. val = ucontrol->value.integer.value[0] & 0x3f;
  2262. else
  2263. val = (0x3f - (ucontrol->value.integer.value[0] & 0x3f)) | 0x40;
  2264. spin_lock_irq(&trident->reg_lock);
  2265. change = val != mix->pan;
  2266. mix->pan = val;
  2267. if (mix->voice != NULL)
  2268. snd_trident_write_pan_reg(trident, mix->voice, val);
  2269. spin_unlock_irq(&trident->reg_lock);
  2270. return change;
  2271. }
  2272. static struct snd_kcontrol_new snd_trident_pcm_pan_control __devinitdata =
  2273. {
  2274. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2275. .name = "PCM Pan Playback Control",
  2276. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2277. .count = 32,
  2278. .info = snd_trident_pcm_pan_control_info,
  2279. .get = snd_trident_pcm_pan_control_get,
  2280. .put = snd_trident_pcm_pan_control_put,
  2281. };
  2282. /*---------------------------------------------------------------------------
  2283. snd_trident_pcm_rvol_control
  2284. Description: PCM reverb volume control
  2285. ---------------------------------------------------------------------------*/
  2286. static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol *kcontrol,
  2287. struct snd_ctl_elem_info *uinfo)
  2288. {
  2289. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2290. uinfo->count = 1;
  2291. uinfo->value.integer.min = 0;
  2292. uinfo->value.integer.max = 127;
  2293. return 0;
  2294. }
  2295. static int snd_trident_pcm_rvol_control_get(struct snd_kcontrol *kcontrol,
  2296. struct snd_ctl_elem_value *ucontrol)
  2297. {
  2298. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2299. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2300. ucontrol->value.integer.value[0] = 127 - mix->rvol;
  2301. return 0;
  2302. }
  2303. static int snd_trident_pcm_rvol_control_put(struct snd_kcontrol *kcontrol,
  2304. struct snd_ctl_elem_value *ucontrol)
  2305. {
  2306. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2307. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2308. unsigned short val;
  2309. int change = 0;
  2310. val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
  2311. spin_lock_irq(&trident->reg_lock);
  2312. change = val != mix->rvol;
  2313. mix->rvol = val;
  2314. if (mix->voice != NULL)
  2315. snd_trident_write_rvol_reg(trident, mix->voice, val);
  2316. spin_unlock_irq(&trident->reg_lock);
  2317. return change;
  2318. }
  2319. static struct snd_kcontrol_new snd_trident_pcm_rvol_control __devinitdata =
  2320. {
  2321. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2322. .name = "PCM Reverb Playback Volume",
  2323. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2324. .count = 32,
  2325. .info = snd_trident_pcm_rvol_control_info,
  2326. .get = snd_trident_pcm_rvol_control_get,
  2327. .put = snd_trident_pcm_rvol_control_put,
  2328. };
  2329. /*---------------------------------------------------------------------------
  2330. snd_trident_pcm_cvol_control
  2331. Description: PCM chorus volume control
  2332. ---------------------------------------------------------------------------*/
  2333. static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol *kcontrol,
  2334. struct snd_ctl_elem_info *uinfo)
  2335. {
  2336. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2337. uinfo->count = 1;
  2338. uinfo->value.integer.min = 0;
  2339. uinfo->value.integer.max = 127;
  2340. return 0;
  2341. }
  2342. static int snd_trident_pcm_cvol_control_get(struct snd_kcontrol *kcontrol,
  2343. struct snd_ctl_elem_value *ucontrol)
  2344. {
  2345. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2346. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2347. ucontrol->value.integer.value[0] = 127 - mix->cvol;
  2348. return 0;
  2349. }
  2350. static int snd_trident_pcm_cvol_control_put(struct snd_kcontrol *kcontrol,
  2351. struct snd_ctl_elem_value *ucontrol)
  2352. {
  2353. struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
  2354. struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
  2355. unsigned short val;
  2356. int change = 0;
  2357. val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
  2358. spin_lock_irq(&trident->reg_lock);
  2359. change = val != mix->cvol;
  2360. mix->cvol = val;
  2361. if (mix->voice != NULL)
  2362. snd_trident_write_cvol_reg(trident, mix->voice, val);
  2363. spin_unlock_irq(&trident->reg_lock);
  2364. return change;
  2365. }
  2366. static struct snd_kcontrol_new snd_trident_pcm_cvol_control __devinitdata =
  2367. {
  2368. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2369. .name = "PCM Chorus Playback Volume",
  2370. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2371. .count = 32,
  2372. .info = snd_trident_pcm_cvol_control_info,
  2373. .get = snd_trident_pcm_cvol_control_get,
  2374. .put = snd_trident_pcm_cvol_control_put,
  2375. };
  2376. static void snd_trident_notify_pcm_change1(struct snd_card *card,
  2377. struct snd_kcontrol *kctl,
  2378. int num, int activate)
  2379. {
  2380. struct snd_ctl_elem_id id;
  2381. if (! kctl)
  2382. return;
  2383. if (activate)
  2384. kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  2385. else
  2386. kctl->vd[num].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  2387. snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE |
  2388. SNDRV_CTL_EVENT_MASK_INFO,
  2389. snd_ctl_build_ioff(&id, kctl, num));
  2390. }
  2391. static void snd_trident_notify_pcm_change(struct snd_trident *trident,
  2392. struct snd_trident_pcm_mixer *tmix,
  2393. int num, int activate)
  2394. {
  2395. snd_trident_notify_pcm_change1(trident->card, trident->ctl_vol, num, activate);
  2396. snd_trident_notify_pcm_change1(trident->card, trident->ctl_pan, num, activate);
  2397. snd_trident_notify_pcm_change1(trident->card, trident->ctl_rvol, num, activate);
  2398. snd_trident_notify_pcm_change1(trident->card, trident->ctl_cvol, num, activate);
  2399. }
  2400. static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
  2401. struct snd_trident_voice *voice,
  2402. struct snd_pcm_substream *substream)
  2403. {
  2404. struct snd_trident_pcm_mixer *tmix;
  2405. snd_assert(trident != NULL && voice != NULL && substream != NULL, return -EINVAL);
  2406. tmix = &trident->pcm_mixer[substream->number];
  2407. tmix->voice = voice;
  2408. tmix->vol = T4D_DEFAULT_PCM_VOL;
  2409. tmix->pan = T4D_DEFAULT_PCM_PAN;
  2410. tmix->rvol = T4D_DEFAULT_PCM_RVOL;
  2411. tmix->cvol = T4D_DEFAULT_PCM_CVOL;
  2412. snd_trident_notify_pcm_change(trident, tmix, substream->number, 1);
  2413. return 0;
  2414. }
  2415. static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_trident_voice *voice, struct snd_pcm_substream *substream)
  2416. {
  2417. struct snd_trident_pcm_mixer *tmix;
  2418. snd_assert(trident != NULL && substream != NULL, return -EINVAL);
  2419. tmix = &trident->pcm_mixer[substream->number];
  2420. tmix->voice = NULL;
  2421. snd_trident_notify_pcm_change(trident, tmix, substream->number, 0);
  2422. return 0;
  2423. }
  2424. /*---------------------------------------------------------------------------
  2425. snd_trident_mixer
  2426. Description: This routine registers the 4DWave device for mixer support.
  2427. Paramters: trident - pointer to target device class for 4DWave.
  2428. Returns: None
  2429. ---------------------------------------------------------------------------*/
  2430. static int __devinit snd_trident_mixer(struct snd_trident * trident, int pcm_spdif_device)
  2431. {
  2432. struct snd_ac97_template _ac97;
  2433. struct snd_card *card = trident->card;
  2434. struct snd_kcontrol *kctl;
  2435. struct snd_ctl_elem_value *uctl;
  2436. int idx, err, retries = 2;
  2437. static struct snd_ac97_bus_ops ops = {
  2438. .write = snd_trident_codec_write,
  2439. .read = snd_trident_codec_read,
  2440. };
  2441. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  2442. if (!uctl)
  2443. return -ENOMEM;
  2444. if ((err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus)) < 0)
  2445. goto __out;
  2446. memset(&_ac97, 0, sizeof(_ac97));
  2447. _ac97.private_data = trident;
  2448. trident->ac97_detect = 1;
  2449. __again:
  2450. if ((err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97)) < 0) {
  2451. if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  2452. if ((err = snd_trident_sis_reset(trident)) < 0)
  2453. goto __out;
  2454. if (retries-- > 0)
  2455. goto __again;
  2456. err = -EIO;
  2457. }
  2458. goto __out;
  2459. }
  2460. /* secondary codec? */
  2461. if (trident->device == TRIDENT_DEVICE_ID_SI7018 &&
  2462. (inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0) {
  2463. _ac97.num = 1;
  2464. err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
  2465. if (err < 0)
  2466. snd_printk(KERN_ERR "SI7018: the secondary codec - invalid access\n");
  2467. #if 0 // only for my testing purpose --jk
  2468. {
  2469. struct snd_ac97 *mc97;
  2470. err = snd_ac97_modem(trident->card, &_ac97, &mc97);
  2471. if (err < 0)
  2472. snd_printk(KERN_ERR "snd_ac97_modem returned error %i\n", err);
  2473. }
  2474. #endif
  2475. }
  2476. trident->ac97_detect = 0;
  2477. if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
  2478. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident))) < 0)
  2479. goto __out;
  2480. kctl->put(kctl, uctl);
  2481. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_music_control, trident))) < 0)
  2482. goto __out;
  2483. kctl->put(kctl, uctl);
  2484. outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
  2485. } else {
  2486. outl(trident->musicvol_wavevol = 0xffff0000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
  2487. }
  2488. for (idx = 0; idx < 32; idx++) {
  2489. struct snd_trident_pcm_mixer *tmix;
  2490. tmix = &trident->pcm_mixer[idx];
  2491. tmix->voice = NULL;
  2492. }
  2493. if ((trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident)) == NULL)
  2494. goto __nomem;
  2495. if ((err = snd_ctl_add(card, trident->ctl_vol)))
  2496. goto __out;
  2497. if ((trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident)) == NULL)
  2498. goto __nomem;
  2499. if ((err = snd_ctl_add(card, trident->ctl_pan)))
  2500. goto __out;
  2501. if ((trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control, trident)) == NULL)
  2502. goto __nomem;
  2503. if ((err = snd_ctl_add(card, trident->ctl_rvol)))
  2504. goto __out;
  2505. if ((trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control, trident)) == NULL)
  2506. goto __nomem;
  2507. if ((err = snd_ctl_add(card, trident->ctl_cvol)))
  2508. goto __out;
  2509. if (trident->device == TRIDENT_DEVICE_ID_NX) {
  2510. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident))) < 0)
  2511. goto __out;
  2512. kctl->put(kctl, uctl);
  2513. }
  2514. if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
  2515. kctl = snd_ctl_new1(&snd_trident_spdif_control, trident);
  2516. if (kctl == NULL) {
  2517. err = -ENOMEM;
  2518. goto __out;
  2519. }
  2520. if (trident->ac97->ext_id & AC97_EI_SPDIF)
  2521. kctl->id.index++;
  2522. if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF))
  2523. kctl->id.index++;
  2524. idx = kctl->id.index;
  2525. if ((err = snd_ctl_add(card, kctl)) < 0)
  2526. goto __out;
  2527. kctl->put(kctl, uctl);
  2528. kctl = snd_ctl_new1(&snd_trident_spdif_default, trident);
  2529. if (kctl == NULL) {
  2530. err = -ENOMEM;
  2531. goto __out;
  2532. }
  2533. kctl->id.index = idx;
  2534. kctl->id.device = pcm_spdif_device;
  2535. if ((err = snd_ctl_add(card, kctl)) < 0)
  2536. goto __out;
  2537. kctl = snd_ctl_new1(&snd_trident_spdif_mask, trident);
  2538. if (kctl == NULL) {
  2539. err = -ENOMEM;
  2540. goto __out;
  2541. }
  2542. kctl->id.index = idx;
  2543. kctl->id.device = pcm_spdif_device;
  2544. if ((err = snd_ctl_add(card, kctl)) < 0)
  2545. goto __out;
  2546. kctl = snd_ctl_new1(&snd_trident_spdif_stream, trident);
  2547. if (kctl == NULL) {
  2548. err = -ENOMEM;
  2549. goto __out;
  2550. }
  2551. kctl->id.index = idx;
  2552. kctl->id.device = pcm_spdif_device;
  2553. if ((err = snd_ctl_add(card, kctl)) < 0)
  2554. goto __out;
  2555. trident->spdif_pcm_ctl = kctl;
  2556. }
  2557. err = 0;
  2558. goto __out;
  2559. __nomem:
  2560. err = -ENOMEM;
  2561. __out:
  2562. kfree(uctl);
  2563. return err;
  2564. }
  2565. /*
  2566. * gameport interface
  2567. */
  2568. #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  2569. static unsigned char snd_trident_gameport_read(struct gameport *gameport)
  2570. {
  2571. struct snd_trident *chip = gameport_get_port_data(gameport);
  2572. snd_assert(chip, return 0);
  2573. return inb(TRID_REG(chip, GAMEPORT_LEGACY));
  2574. }
  2575. static void snd_trident_gameport_trigger(struct gameport *gameport)
  2576. {
  2577. struct snd_trident *chip = gameport_get_port_data(gameport);
  2578. snd_assert(chip, return);
  2579. outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY));
  2580. }
  2581. static int snd_trident_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  2582. {
  2583. struct snd_trident *chip = gameport_get_port_data(gameport);
  2584. int i;
  2585. snd_assert(chip, return 0);
  2586. *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf;
  2587. for (i = 0; i < 4; i++) {
  2588. axes[i] = inw(TRID_REG(chip, GAMEPORT_AXES + i * 2));
  2589. if (axes[i] == 0xffff) axes[i] = -1;
  2590. }
  2591. return 0;
  2592. }
  2593. static int snd_trident_gameport_open(struct gameport *gameport, int mode)
  2594. {
  2595. struct snd_trident *chip = gameport_get_port_data(gameport);
  2596. snd_assert(chip, return 0);
  2597. switch (mode) {
  2598. case GAMEPORT_MODE_COOKED:
  2599. outb(GAMEPORT_MODE_ADC, TRID_REG(chip, GAMEPORT_GCR));
  2600. msleep(20);
  2601. return 0;
  2602. case GAMEPORT_MODE_RAW:
  2603. outb(0, TRID_REG(chip, GAMEPORT_GCR));
  2604. return 0;
  2605. default:
  2606. return -1;
  2607. }
  2608. }
  2609. int __devinit snd_trident_create_gameport(struct snd_trident *chip)
  2610. {
  2611. struct gameport *gp;
  2612. chip->gameport = gp = gameport_allocate_port();
  2613. if (!gp) {
  2614. printk(KERN_ERR "trident: cannot allocate memory for gameport\n");
  2615. return -ENOMEM;
  2616. }
  2617. gameport_set_name(gp, "Trident 4DWave");
  2618. gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
  2619. gameport_set_dev_parent(gp, &chip->pci->dev);
  2620. gameport_set_port_data(gp, chip);
  2621. gp->fuzz = 64;
  2622. gp->read = snd_trident_gameport_read;
  2623. gp->trigger = snd_trident_gameport_trigger;
  2624. gp->cooked_read = snd_trident_gameport_cooked_read;
  2625. gp->open = snd_trident_gameport_open;
  2626. gameport_register_port(gp);
  2627. return 0;
  2628. }
  2629. static inline void snd_trident_free_gameport(struct snd_trident *chip)
  2630. {
  2631. if (chip->gameport) {
  2632. gameport_unregister_port(chip->gameport);
  2633. chip->gameport = NULL;
  2634. }
  2635. }
  2636. #else
  2637. int __devinit snd_trident_create_gameport(struct snd_trident *chip) { return -ENOSYS; }
  2638. static inline void snd_trident_free_gameport(struct snd_trident *chip) { }
  2639. #endif /* CONFIG_GAMEPORT */
  2640. /*
  2641. * delay for 1 tick
  2642. */
  2643. static inline void do_delay(struct snd_trident *chip)
  2644. {
  2645. schedule_timeout_uninterruptible(1);
  2646. }
  2647. /*
  2648. * SiS reset routine
  2649. */
  2650. static int snd_trident_sis_reset(struct snd_trident *trident)
  2651. {
  2652. unsigned long end_time;
  2653. unsigned int i;
  2654. int r;
  2655. r = trident->in_suspend ? 0 : 2; /* count of retries */
  2656. __si7018_retry:
  2657. pci_write_config_byte(trident->pci, 0x46, 0x04); /* SOFTWARE RESET */
  2658. udelay(100);
  2659. pci_write_config_byte(trident->pci, 0x46, 0x00);
  2660. udelay(100);
  2661. /* disable AC97 GPIO interrupt */
  2662. outb(0x00, TRID_REG(trident, SI_AC97_GPIO));
  2663. /* initialize serial interface, force cold reset */
  2664. i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET;
  2665. outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  2666. udelay(1000);
  2667. /* remove cold reset */
  2668. i &= ~COLD_RESET;
  2669. outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  2670. udelay(2000);
  2671. /* wait, until the codec is ready */
  2672. end_time = (jiffies + (HZ * 3) / 4) + 1;
  2673. do {
  2674. if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0)
  2675. goto __si7018_ok;
  2676. do_delay(trident);
  2677. } while (time_after_eq(end_time, jiffies));
  2678. snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
  2679. if (r-- > 0) {
  2680. end_time = jiffies + HZ;
  2681. do {
  2682. do_delay(trident);
  2683. } while (time_after_eq(end_time, jiffies));
  2684. goto __si7018_retry;
  2685. }
  2686. __si7018_ok:
  2687. /* wait for the second codec */
  2688. do {
  2689. if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_SECONDARY_READY) != 0)
  2690. break;
  2691. do_delay(trident);
  2692. } while (time_after_eq(end_time, jiffies));
  2693. /* enable 64 channel mode */
  2694. outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR));
  2695. return 0;
  2696. }
  2697. /*
  2698. * /proc interface
  2699. */
  2700. static void snd_trident_proc_read(struct snd_info_entry *entry,
  2701. struct snd_info_buffer *buffer)
  2702. {
  2703. struct snd_trident *trident = entry->private_data;
  2704. char *s;
  2705. switch (trident->device) {
  2706. case TRIDENT_DEVICE_ID_SI7018:
  2707. s = "SiS 7018 Audio";
  2708. break;
  2709. case TRIDENT_DEVICE_ID_DX:
  2710. s = "Trident 4DWave PCI DX";
  2711. break;
  2712. case TRIDENT_DEVICE_ID_NX:
  2713. s = "Trident 4DWave PCI NX";
  2714. break;
  2715. default:
  2716. s = "???";
  2717. }
  2718. snd_iprintf(buffer, "%s\n\n", s);
  2719. snd_iprintf(buffer, "Spurious IRQs : %d\n", trident->spurious_irq_count);
  2720. snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta);
  2721. if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018)
  2722. snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", trident->spdif_ctrl == 0x28 ? "on" : "off");
  2723. if (trident->device == TRIDENT_DEVICE_ID_NX) {
  2724. snd_iprintf(buffer, "Rear Speakers : %s\n", trident->ac97_ctrl & 0x00000010 ? "on" : "off");
  2725. if (trident->tlb.entries) {
  2726. snd_iprintf(buffer,"\nVirtual Memory\n");
  2727. snd_iprintf(buffer, "Memory Maximum : %d\n", trident->tlb.memhdr->size);
  2728. snd_iprintf(buffer, "Memory Used : %d\n", trident->tlb.memhdr->used);
  2729. snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr));
  2730. }
  2731. }
  2732. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  2733. snd_iprintf(buffer,"\nWavetable Synth\n");
  2734. snd_iprintf(buffer, "Memory Maximum : %d\n", trident->synth.max_size);
  2735. snd_iprintf(buffer, "Memory Used : %d\n", trident->synth.current_size);
  2736. snd_iprintf(buffer, "Memory Free : %d\n", (trident->synth.max_size-trident->synth.current_size));
  2737. #endif
  2738. }
  2739. static void __devinit snd_trident_proc_init(struct snd_trident * trident)
  2740. {
  2741. struct snd_info_entry *entry;
  2742. const char *s = "trident";
  2743. if (trident->device == TRIDENT_DEVICE_ID_SI7018)
  2744. s = "sis7018";
  2745. if (! snd_card_proc_new(trident->card, s, &entry))
  2746. snd_info_set_text_ops(entry, trident, 1024, snd_trident_proc_read);
  2747. }
  2748. static int snd_trident_dev_free(struct snd_device *device)
  2749. {
  2750. struct snd_trident *trident = device->device_data;
  2751. return snd_trident_free(trident);
  2752. }
  2753. /*---------------------------------------------------------------------------
  2754. snd_trident_tlb_alloc
  2755. Description: Allocate and set up the TLB page table on 4D NX.
  2756. Each entry has 4 bytes (physical PCI address).
  2757. Paramters: trident - pointer to target device class for 4DWave.
  2758. Returns: 0 or negative error code
  2759. ---------------------------------------------------------------------------*/
  2760. static int __devinit snd_trident_tlb_alloc(struct snd_trident *trident)
  2761. {
  2762. int i;
  2763. /* TLB array must be aligned to 16kB !!! so we allocate
  2764. 32kB region and correct offset when necessary */
  2765. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
  2766. 2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) {
  2767. snd_printk(KERN_ERR "trident: unable to allocate TLB buffer\n");
  2768. return -ENOMEM;
  2769. }
  2770. trident->tlb.entries = (unsigned int*)(((unsigned long)trident->tlb.buffer.area + SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1));
  2771. trident->tlb.entries_dmaaddr = (trident->tlb.buffer.addr + SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1);
  2772. /* allocate shadow TLB page table (virtual addresses) */
  2773. trident->tlb.shadow_entries = vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long));
  2774. if (trident->tlb.shadow_entries == NULL) {
  2775. snd_printk(KERN_ERR "trident: unable to allocate shadow TLB entries\n");
  2776. return -ENOMEM;
  2777. }
  2778. /* allocate and setup silent page and initialise TLB entries */
  2779. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
  2780. SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) {
  2781. snd_printk(KERN_ERR "trident: unable to allocate silent page\n");
  2782. return -ENOMEM;
  2783. }
  2784. memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
  2785. for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) {
  2786. trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1));
  2787. trident->tlb.shadow_entries[i] = (unsigned long)trident->tlb.silent_page.area;
  2788. }
  2789. /* use emu memory block manager code to manage tlb page allocation */
  2790. trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES);
  2791. if (trident->tlb.memhdr == NULL)
  2792. return -ENOMEM;
  2793. trident->tlb.memhdr->block_extra_size = sizeof(struct snd_trident_memblk_arg);
  2794. return 0;
  2795. }
  2796. /*
  2797. * initialize 4D DX chip
  2798. */
  2799. static void snd_trident_stop_all_voices(struct snd_trident *trident)
  2800. {
  2801. outl(0xffffffff, TRID_REG(trident, T4D_STOP_A));
  2802. outl(0xffffffff, TRID_REG(trident, T4D_STOP_B));
  2803. outl(0, TRID_REG(trident, T4D_AINTEN_A));
  2804. outl(0, TRID_REG(trident, T4D_AINTEN_B));
  2805. }
  2806. static int snd_trident_4d_dx_init(struct snd_trident *trident)
  2807. {
  2808. struct pci_dev *pci = trident->pci;
  2809. unsigned long end_time;
  2810. /* reset the legacy configuration and whole audio/wavetable block */
  2811. pci_write_config_dword(pci, 0x40, 0); /* DDMA */
  2812. pci_write_config_byte(pci, 0x44, 0); /* ports */
  2813. pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */
  2814. pci_write_config_byte(pci, 0x46, 4); /* reset */
  2815. udelay(100);
  2816. pci_write_config_byte(pci, 0x46, 0); /* release reset */
  2817. udelay(100);
  2818. /* warm reset of the AC'97 codec */
  2819. outl(0x00000001, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
  2820. udelay(100);
  2821. outl(0x00000000, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
  2822. /* DAC on, disable SB IRQ and try to force ADC valid signal */
  2823. trident->ac97_ctrl = 0x0000004a;
  2824. outl(trident->ac97_ctrl, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
  2825. /* wait, until the codec is ready */
  2826. end_time = (jiffies + (HZ * 3) / 4) + 1;
  2827. do {
  2828. if ((inl(TRID_REG(trident, DX_ACR2_AC97_COM_STAT)) & 0x0010) != 0)
  2829. goto __dx_ok;
  2830. do_delay(trident);
  2831. } while (time_after_eq(end_time, jiffies));
  2832. snd_printk(KERN_ERR "AC'97 codec ready error\n");
  2833. return -EIO;
  2834. __dx_ok:
  2835. snd_trident_stop_all_voices(trident);
  2836. return 0;
  2837. }
  2838. /*
  2839. * initialize 4D NX chip
  2840. */
  2841. static int snd_trident_4d_nx_init(struct snd_trident *trident)
  2842. {
  2843. struct pci_dev *pci = trident->pci;
  2844. unsigned long end_time;
  2845. /* reset the legacy configuration and whole audio/wavetable block */
  2846. pci_write_config_dword(pci, 0x40, 0); /* DDMA */
  2847. pci_write_config_byte(pci, 0x44, 0); /* ports */
  2848. pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */
  2849. pci_write_config_byte(pci, 0x46, 1); /* reset */
  2850. udelay(100);
  2851. pci_write_config_byte(pci, 0x46, 0); /* release reset */
  2852. udelay(100);
  2853. /* warm reset of the AC'97 codec */
  2854. outl(0x00000001, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2855. udelay(100);
  2856. outl(0x00000000, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2857. /* wait, until the codec is ready */
  2858. end_time = (jiffies + (HZ * 3) / 4) + 1;
  2859. do {
  2860. if ((inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)) & 0x0008) != 0)
  2861. goto __nx_ok;
  2862. do_delay(trident);
  2863. } while (time_after_eq(end_time, jiffies));
  2864. snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)));
  2865. return -EIO;
  2866. __nx_ok:
  2867. /* DAC on */
  2868. trident->ac97_ctrl = 0x00000002;
  2869. outl(trident->ac97_ctrl, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
  2870. /* disable SB IRQ */
  2871. outl(NX_SB_IRQ_DISABLE, TRID_REG(trident, T4D_MISCINT));
  2872. snd_trident_stop_all_voices(trident);
  2873. if (trident->tlb.entries != NULL) {
  2874. unsigned int i;
  2875. /* enable virtual addressing via TLB */
  2876. i = trident->tlb.entries_dmaaddr;
  2877. i |= 0x00000001;
  2878. outl(i, TRID_REG(trident, NX_TLBC));
  2879. } else {
  2880. outl(0, TRID_REG(trident, NX_TLBC));
  2881. }
  2882. /* initialize S/PDIF */
  2883. outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
  2884. outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  2885. return 0;
  2886. }
  2887. /*
  2888. * initialize sis7018 chip
  2889. */
  2890. static int snd_trident_sis_init(struct snd_trident *trident)
  2891. {
  2892. int err;
  2893. if ((err = snd_trident_sis_reset(trident)) < 0)
  2894. return err;
  2895. snd_trident_stop_all_voices(trident);
  2896. /* initialize S/PDIF */
  2897. outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
  2898. return 0;
  2899. }
  2900. /*---------------------------------------------------------------------------
  2901. snd_trident_create
  2902. Description: This routine will create the device specific class for
  2903. the 4DWave card. It will also perform basic initialization.
  2904. Paramters: card - which card to create
  2905. pci - interface to PCI bus resource info
  2906. dma1ptr - playback dma buffer
  2907. dma2ptr - capture dma buffer
  2908. irqptr - interrupt resource info
  2909. Returns: 4DWave device class private data
  2910. ---------------------------------------------------------------------------*/
  2911. int __devinit snd_trident_create(struct snd_card *card,
  2912. struct pci_dev *pci,
  2913. int pcm_streams,
  2914. int pcm_spdif_device,
  2915. int max_wavetable_size,
  2916. struct snd_trident ** rtrident)
  2917. {
  2918. struct snd_trident *trident;
  2919. int i, err;
  2920. struct snd_trident_voice *voice;
  2921. struct snd_trident_pcm_mixer *tmix;
  2922. static struct snd_device_ops ops = {
  2923. .dev_free = snd_trident_dev_free,
  2924. };
  2925. *rtrident = NULL;
  2926. /* enable PCI device */
  2927. if ((err = pci_enable_device(pci)) < 0)
  2928. return err;
  2929. /* check, if we can restrict PCI DMA transfers to 30 bits */
  2930. if (pci_set_dma_mask(pci, 0x3fffffff) < 0 ||
  2931. pci_set_consistent_dma_mask(pci, 0x3fffffff) < 0) {
  2932. snd_printk(KERN_ERR "architecture does not support 30bit PCI busmaster DMA\n");
  2933. pci_disable_device(pci);
  2934. return -ENXIO;
  2935. }
  2936. trident = kzalloc(sizeof(*trident), GFP_KERNEL);
  2937. if (trident == NULL) {
  2938. pci_disable_device(pci);
  2939. return -ENOMEM;
  2940. }
  2941. trident->device = (pci->vendor << 16) | pci->device;
  2942. trident->card = card;
  2943. trident->pci = pci;
  2944. spin_lock_init(&trident->reg_lock);
  2945. spin_lock_init(&trident->event_lock);
  2946. spin_lock_init(&trident->voice_alloc);
  2947. if (pcm_streams < 1)
  2948. pcm_streams = 1;
  2949. if (pcm_streams > 32)
  2950. pcm_streams = 32;
  2951. trident->ChanPCM = pcm_streams;
  2952. if (max_wavetable_size < 0 )
  2953. max_wavetable_size = 0;
  2954. trident->synth.max_size = max_wavetable_size * 1024;
  2955. trident->irq = -1;
  2956. trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE);
  2957. pci_set_master(pci);
  2958. if ((err = pci_request_regions(pci, "Trident Audio")) < 0) {
  2959. kfree(trident);
  2960. pci_disable_device(pci);
  2961. return err;
  2962. }
  2963. trident->port = pci_resource_start(pci, 0);
  2964. if (request_irq(pci->irq, snd_trident_interrupt, SA_INTERRUPT|SA_SHIRQ,
  2965. "Trident Audio", trident)) {
  2966. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  2967. snd_trident_free(trident);
  2968. return -EBUSY;
  2969. }
  2970. trident->irq = pci->irq;
  2971. /* allocate 16k-aligned TLB for NX cards */
  2972. trident->tlb.entries = NULL;
  2973. trident->tlb.buffer.area = NULL;
  2974. if (trident->device == TRIDENT_DEVICE_ID_NX) {
  2975. if ((err = snd_trident_tlb_alloc(trident)) < 0) {
  2976. snd_trident_free(trident);
  2977. return err;
  2978. }
  2979. }
  2980. trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
  2981. /* initialize chip */
  2982. switch (trident->device) {
  2983. case TRIDENT_DEVICE_ID_DX:
  2984. err = snd_trident_4d_dx_init(trident);
  2985. break;
  2986. case TRIDENT_DEVICE_ID_NX:
  2987. err = snd_trident_4d_nx_init(trident);
  2988. break;
  2989. case TRIDENT_DEVICE_ID_SI7018:
  2990. err = snd_trident_sis_init(trident);
  2991. break;
  2992. default:
  2993. snd_BUG();
  2994. break;
  2995. }
  2996. if (err < 0) {
  2997. snd_trident_free(trident);
  2998. return err;
  2999. }
  3000. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, trident, &ops)) < 0) {
  3001. snd_trident_free(trident);
  3002. return err;
  3003. }
  3004. if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
  3005. return err;
  3006. /* initialise synth voices */
  3007. for (i = 0; i < 64; i++) {
  3008. voice = &trident->synth.voices[i];
  3009. voice->number = i;
  3010. voice->trident = trident;
  3011. }
  3012. /* initialize pcm mixer entries */
  3013. for (i = 0; i < 32; i++) {
  3014. tmix = &trident->pcm_mixer[i];
  3015. tmix->vol = T4D_DEFAULT_PCM_VOL;
  3016. tmix->pan = T4D_DEFAULT_PCM_PAN;
  3017. tmix->rvol = T4D_DEFAULT_PCM_RVOL;
  3018. tmix->cvol = T4D_DEFAULT_PCM_CVOL;
  3019. }
  3020. snd_trident_enable_eso(trident);
  3021. snd_trident_proc_init(trident);
  3022. snd_card_set_dev(card, &pci->dev);
  3023. *rtrident = trident;
  3024. return 0;
  3025. }
  3026. /*---------------------------------------------------------------------------
  3027. snd_trident_free
  3028. Description: This routine will free the device specific class for
  3029. the 4DWave card.
  3030. Paramters: trident - device specific private data for 4DWave card
  3031. Returns: None.
  3032. ---------------------------------------------------------------------------*/
  3033. static int snd_trident_free(struct snd_trident *trident)
  3034. {
  3035. snd_trident_free_gameport(trident);
  3036. snd_trident_disable_eso(trident);
  3037. // Disable S/PDIF out
  3038. if (trident->device == TRIDENT_DEVICE_ID_NX)
  3039. outb(0x00, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
  3040. else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
  3041. outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
  3042. }
  3043. if (trident->tlb.buffer.area) {
  3044. outl(0, TRID_REG(trident, NX_TLBC));
  3045. if (trident->tlb.memhdr)
  3046. snd_util_memhdr_free(trident->tlb.memhdr);
  3047. if (trident->tlb.silent_page.area)
  3048. snd_dma_free_pages(&trident->tlb.silent_page);
  3049. vfree(trident->tlb.shadow_entries);
  3050. snd_dma_free_pages(&trident->tlb.buffer);
  3051. }
  3052. if (trident->irq >= 0)
  3053. free_irq(trident->irq, trident);
  3054. pci_release_regions(trident->pci);
  3055. pci_disable_device(trident->pci);
  3056. kfree(trident);
  3057. return 0;
  3058. }
  3059. /*---------------------------------------------------------------------------
  3060. snd_trident_interrupt
  3061. Description: ISR for Trident 4DWave device
  3062. Paramters: trident - device specific private data for 4DWave card
  3063. Problems: It seems that Trident chips generates interrupts more than
  3064. one time in special cases. The spurious interrupts are
  3065. detected via sample timer (T4D_STIMER) and computing
  3066. corresponding delta value. The limits are detected with
  3067. the method try & fail so it is possible that it won't
  3068. work on all computers. [jaroslav]
  3069. Returns: None.
  3070. ---------------------------------------------------------------------------*/
  3071. static irqreturn_t snd_trident_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  3072. {
  3073. struct snd_trident *trident = dev_id;
  3074. unsigned int audio_int, chn_int, stimer, channel, mask, tmp;
  3075. int delta;
  3076. struct snd_trident_voice *voice;
  3077. audio_int = inl(TRID_REG(trident, T4D_MISCINT));
  3078. if ((audio_int & (ADDRESS_IRQ|MPU401_IRQ)) == 0)
  3079. return IRQ_NONE;
  3080. if (audio_int & ADDRESS_IRQ) {
  3081. // get interrupt status for all channels
  3082. spin_lock(&trident->reg_lock);
  3083. stimer = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff;
  3084. chn_int = inl(TRID_REG(trident, T4D_AINT_A));
  3085. if (chn_int == 0)
  3086. goto __skip1;
  3087. outl(chn_int, TRID_REG(trident, T4D_AINT_A)); /* ack */
  3088. __skip1:
  3089. chn_int = inl(TRID_REG(trident, T4D_AINT_B));
  3090. if (chn_int == 0)
  3091. goto __skip2;
  3092. for (channel = 63; channel >= 32; channel--) {
  3093. mask = 1 << (channel&0x1f);
  3094. if ((chn_int & mask) == 0)
  3095. continue;
  3096. voice = &trident->synth.voices[channel];
  3097. if (!voice->pcm || voice->substream == NULL) {
  3098. outl(mask, TRID_REG(trident, T4D_STOP_B));
  3099. continue;
  3100. }
  3101. delta = (int)stimer - (int)voice->stimer;
  3102. if (delta < 0)
  3103. delta = -delta;
  3104. if ((unsigned int)delta < voice->spurious_threshold) {
  3105. /* do some statistics here */
  3106. trident->spurious_irq_count++;
  3107. if (trident->spurious_irq_max_delta < (unsigned int)delta)
  3108. trident->spurious_irq_max_delta = delta;
  3109. continue;
  3110. }
  3111. voice->stimer = stimer;
  3112. if (voice->isync) {
  3113. if (!voice->isync3) {
  3114. tmp = inw(TRID_REG(trident, T4D_SBBL_SBCL));
  3115. if (trident->bDMAStart & 0x40)
  3116. tmp >>= 1;
  3117. if (tmp > 0)
  3118. tmp = voice->isync_max - tmp;
  3119. } else {
  3120. tmp = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff;
  3121. }
  3122. if (tmp < voice->isync_mark) {
  3123. if (tmp > 0x10)
  3124. tmp = voice->isync_ESO - 7;
  3125. else
  3126. tmp = voice->isync_ESO + 2;
  3127. /* update ESO for IRQ voice to preserve sync */
  3128. snd_trident_stop_voice(trident, voice->number);
  3129. snd_trident_write_eso_reg(trident, voice, tmp);
  3130. snd_trident_start_voice(trident, voice->number);
  3131. }
  3132. } else if (voice->isync2) {
  3133. voice->isync2 = 0;
  3134. /* write original ESO and update CSO for IRQ voice to preserve sync */
  3135. snd_trident_stop_voice(trident, voice->number);
  3136. snd_trident_write_cso_reg(trident, voice, voice->isync_mark);
  3137. snd_trident_write_eso_reg(trident, voice, voice->ESO);
  3138. snd_trident_start_voice(trident, voice->number);
  3139. }
  3140. #if 0
  3141. if (voice->extra) {
  3142. /* update CSO for extra voice to preserve sync */
  3143. snd_trident_stop_voice(trident, voice->extra->number);
  3144. snd_trident_write_cso_reg(trident, voice->extra, 0);
  3145. snd_trident_start_voice(trident, voice->extra->number);
  3146. }
  3147. #endif
  3148. spin_unlock(&trident->reg_lock);
  3149. snd_pcm_period_elapsed(voice->substream);
  3150. spin_lock(&trident->reg_lock);
  3151. }
  3152. outl(chn_int, TRID_REG(trident, T4D_AINT_B)); /* ack */
  3153. __skip2:
  3154. spin_unlock(&trident->reg_lock);
  3155. }
  3156. if (audio_int & MPU401_IRQ) {
  3157. if (trident->rmidi) {
  3158. snd_mpu401_uart_interrupt(irq, trident->rmidi->private_data, regs);
  3159. } else {
  3160. inb(TRID_REG(trident, T4D_MPUR0));
  3161. }
  3162. }
  3163. // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
  3164. return IRQ_HANDLED;
  3165. }
  3166. /*---------------------------------------------------------------------------
  3167. snd_trident_attach_synthesizer
  3168. Description: Attach synthesizer hooks
  3169. Paramters: trident - device specific private data for 4DWave card
  3170. Returns: None.
  3171. ---------------------------------------------------------------------------*/
  3172. int snd_trident_attach_synthesizer(struct snd_trident *trident)
  3173. {
  3174. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  3175. if (snd_seq_device_new(trident->card, 1, SNDRV_SEQ_DEV_ID_TRIDENT,
  3176. sizeof(struct snd_trident *), &trident->seq_dev) >= 0) {
  3177. strcpy(trident->seq_dev->name, "4DWave");
  3178. *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(trident->seq_dev) = trident;
  3179. }
  3180. #endif
  3181. return 0;
  3182. }
  3183. struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type, int client, int port)
  3184. {
  3185. struct snd_trident_voice *pvoice;
  3186. unsigned long flags;
  3187. int idx;
  3188. spin_lock_irqsave(&trident->voice_alloc, flags);
  3189. if (type == SNDRV_TRIDENT_VOICE_TYPE_PCM) {
  3190. idx = snd_trident_allocate_pcm_channel(trident);
  3191. if(idx < 0) {
  3192. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3193. return NULL;
  3194. }
  3195. pvoice = &trident->synth.voices[idx];
  3196. pvoice->use = 1;
  3197. pvoice->pcm = 1;
  3198. pvoice->capture = 0;
  3199. pvoice->spdif = 0;
  3200. pvoice->memblk = NULL;
  3201. pvoice->substream = NULL;
  3202. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3203. return pvoice;
  3204. }
  3205. if (type == SNDRV_TRIDENT_VOICE_TYPE_SYNTH) {
  3206. idx = snd_trident_allocate_synth_channel(trident);
  3207. if(idx < 0) {
  3208. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3209. return NULL;
  3210. }
  3211. pvoice = &trident->synth.voices[idx];
  3212. pvoice->use = 1;
  3213. pvoice->synth = 1;
  3214. pvoice->client = client;
  3215. pvoice->port = port;
  3216. pvoice->memblk = NULL;
  3217. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3218. return pvoice;
  3219. }
  3220. if (type == SNDRV_TRIDENT_VOICE_TYPE_MIDI) {
  3221. }
  3222. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3223. return NULL;
  3224. }
  3225. void snd_trident_free_voice(struct snd_trident * trident, struct snd_trident_voice *voice)
  3226. {
  3227. unsigned long flags;
  3228. void (*private_free)(struct snd_trident_voice *);
  3229. void *private_data;
  3230. if (voice == NULL || !voice->use)
  3231. return;
  3232. snd_trident_clear_voices(trident, voice->number, voice->number);
  3233. spin_lock_irqsave(&trident->voice_alloc, flags);
  3234. private_free = voice->private_free;
  3235. private_data = voice->private_data;
  3236. voice->private_free = NULL;
  3237. voice->private_data = NULL;
  3238. if (voice->pcm)
  3239. snd_trident_free_pcm_channel(trident, voice->number);
  3240. if (voice->synth)
  3241. snd_trident_free_synth_channel(trident, voice->number);
  3242. voice->use = voice->pcm = voice->synth = voice->midi = 0;
  3243. voice->capture = voice->spdif = 0;
  3244. voice->sample_ops = NULL;
  3245. voice->substream = NULL;
  3246. voice->extra = NULL;
  3247. spin_unlock_irqrestore(&trident->voice_alloc, flags);
  3248. if (private_free)
  3249. private_free(voice);
  3250. }
  3251. static void snd_trident_clear_voices(struct snd_trident * trident, unsigned short v_min, unsigned short v_max)
  3252. {
  3253. unsigned int i, val, mask[2] = { 0, 0 };
  3254. snd_assert(v_min <= 63, return);
  3255. snd_assert(v_max <= 63, return);
  3256. for (i = v_min; i <= v_max; i++)
  3257. mask[i >> 5] |= 1 << (i & 0x1f);
  3258. if (mask[0]) {
  3259. outl(mask[0], TRID_REG(trident, T4D_STOP_A));
  3260. val = inl(TRID_REG(trident, T4D_AINTEN_A));
  3261. outl(val & ~mask[0], TRID_REG(trident, T4D_AINTEN_A));
  3262. }
  3263. if (mask[1]) {
  3264. outl(mask[1], TRID_REG(trident, T4D_STOP_B));
  3265. val = inl(TRID_REG(trident, T4D_AINTEN_B));
  3266. outl(val & ~mask[1], TRID_REG(trident, T4D_AINTEN_B));
  3267. }
  3268. }
  3269. #ifdef CONFIG_PM
  3270. int snd_trident_suspend(struct pci_dev *pci, pm_message_t state)
  3271. {
  3272. struct snd_card *card = pci_get_drvdata(pci);
  3273. struct snd_trident *trident = card->private_data;
  3274. trident->in_suspend = 1;
  3275. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  3276. snd_pcm_suspend_all(trident->pcm);
  3277. snd_pcm_suspend_all(trident->foldback);
  3278. snd_pcm_suspend_all(trident->spdif);
  3279. snd_ac97_suspend(trident->ac97);
  3280. snd_ac97_suspend(trident->ac97_sec);
  3281. switch (trident->device) {
  3282. case TRIDENT_DEVICE_ID_DX:
  3283. case TRIDENT_DEVICE_ID_NX:
  3284. break; /* TODO */
  3285. case TRIDENT_DEVICE_ID_SI7018:
  3286. break;
  3287. }
  3288. pci_disable_device(pci);
  3289. pci_save_state(pci);
  3290. return 0;
  3291. }
  3292. int snd_trident_resume(struct pci_dev *pci)
  3293. {
  3294. struct snd_card *card = pci_get_drvdata(pci);
  3295. struct snd_trident *trident = card->private_data;
  3296. pci_restore_state(pci);
  3297. pci_enable_device(pci);
  3298. pci_set_master(pci); /* to be sure */
  3299. switch (trident->device) {
  3300. case TRIDENT_DEVICE_ID_DX:
  3301. snd_trident_4d_dx_init(trident);
  3302. break;
  3303. case TRIDENT_DEVICE_ID_NX:
  3304. snd_trident_4d_nx_init(trident);
  3305. break;
  3306. case TRIDENT_DEVICE_ID_SI7018:
  3307. snd_trident_sis_init(trident);
  3308. break;
  3309. }
  3310. snd_ac97_resume(trident->ac97);
  3311. snd_ac97_resume(trident->ac97_sec);
  3312. /* restore some registers */
  3313. outl(trident->musicvol_wavevol, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
  3314. snd_trident_enable_eso(trident);
  3315. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  3316. trident->in_suspend = 0;
  3317. return 0;
  3318. }
  3319. #endif /* CONFIG_PM */
  3320. EXPORT_SYMBOL(snd_trident_alloc_voice);
  3321. EXPORT_SYMBOL(snd_trident_free_voice);
  3322. EXPORT_SYMBOL(snd_trident_start_voice);
  3323. EXPORT_SYMBOL(snd_trident_stop_voice);
  3324. EXPORT_SYMBOL(snd_trident_write_voice_regs);
  3325. /* trident_memory.c symbols */
  3326. EXPORT_SYMBOL(snd_trident_synth_alloc);
  3327. EXPORT_SYMBOL(snd_trident_synth_free);
  3328. EXPORT_SYMBOL(snd_trident_synth_copy_from_user);