1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982 |
- /*
- * Maintained by Jaroslav Kysela <perex@perex.cz>
- * Originated by audio@tridentmicro.com
- * Fri Feb 19 15:55:28 MST 1999
- * Routines for control of Trident 4DWave (DX and NX) chip
- *
- * BUGS:
- *
- * TODO:
- * ---
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *
- * SiS7018 S/PDIF support by Thomas Winischhofer <thomas@winischhofer.net>
- */
- #include <linux/delay.h>
- #include <linux/init.h>
- #include <linux/interrupt.h>
- #include <linux/pci.h>
- #include <linux/slab.h>
- #include <linux/vmalloc.h>
- #include <linux/gameport.h>
- #include <linux/dma-mapping.h>
- #include <sound/core.h>
- #include <sound/info.h>
- #include <sound/control.h>
- #include <sound/tlv.h>
- #include <sound/trident.h>
- #include <sound/asoundef.h>
- #include <asm/io.h>
- static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
- struct snd_trident_voice * voice,
- struct snd_pcm_substream *substream);
- static int snd_trident_pcm_mixer_free(struct snd_trident *trident,
- struct snd_trident_voice * voice,
- struct snd_pcm_substream *substream);
- static irqreturn_t snd_trident_interrupt(int irq, void *dev_id);
- static int snd_trident_sis_reset(struct snd_trident *trident);
- static void snd_trident_clear_voices(struct snd_trident * trident,
- unsigned short v_min, unsigned short v_max);
- static int snd_trident_free(struct snd_trident *trident);
- /*
- * common I/O routines
- */
- #if 0
- static void snd_trident_print_voice_regs(struct snd_trident *trident, int voice)
- {
- unsigned int val, tmp;
- printk(KERN_DEBUG "Trident voice %i:\n", voice);
- outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR));
- val = inl(TRID_REG(trident, CH_LBA));
- printk(KERN_DEBUG "LBA: 0x%x\n", val);
- val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
- printk(KERN_DEBUG "GVSel: %i\n", val >> 31);
- printk(KERN_DEBUG "Pan: 0x%x\n", (val >> 24) & 0x7f);
- printk(KERN_DEBUG "Vol: 0x%x\n", (val >> 16) & 0xff);
- printk(KERN_DEBUG "CTRL: 0x%x\n", (val >> 12) & 0x0f);
- printk(KERN_DEBUG "EC: 0x%x\n", val & 0x0fff);
- if (trident->device != TRIDENT_DEVICE_ID_NX) {
- val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS));
- printk(KERN_DEBUG "CSO: 0x%x\n", val >> 16);
- printk("Alpha: 0x%x\n", (val >> 4) & 0x0fff);
- printk(KERN_DEBUG "FMS: 0x%x\n", val & 0x0f);
- val = inl(TRID_REG(trident, CH_DX_ESO_DELTA));
- printk(KERN_DEBUG "ESO: 0x%x\n", val >> 16);
- printk(KERN_DEBUG "Delta: 0x%x\n", val & 0xffff);
- val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL));
- } else { // TRIDENT_DEVICE_ID_NX
- val = inl(TRID_REG(trident, CH_NX_DELTA_CSO));
- tmp = (val >> 24) & 0xff;
- printk(KERN_DEBUG "CSO: 0x%x\n", val & 0x00ffffff);
- val = inl(TRID_REG(trident, CH_NX_DELTA_ESO));
- tmp |= (val >> 16) & 0xff00;
- printk(KERN_DEBUG "Delta: 0x%x\n", tmp);
- printk(KERN_DEBUG "ESO: 0x%x\n", val & 0x00ffffff);
- val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL));
- printk(KERN_DEBUG "Alpha: 0x%x\n", val >> 20);
- printk(KERN_DEBUG "FMS: 0x%x\n", (val >> 16) & 0x0f);
- }
- printk(KERN_DEBUG "FMC: 0x%x\n", (val >> 14) & 3);
- printk(KERN_DEBUG "RVol: 0x%x\n", (val >> 7) & 0x7f);
- printk(KERN_DEBUG "CVol: 0x%x\n", val & 0x7f);
- }
- #endif
- /*---------------------------------------------------------------------------
- unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
-
- Description: This routine will do all of the reading from the external
- CODEC (AC97).
-
- Parameters: ac97 - ac97 codec structure
- reg - CODEC register index, from AC97 Hal.
-
- returns: 16 bit value read from the AC97.
-
- ---------------------------------------------------------------------------*/
- static unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg)
- {
- unsigned int data = 0, treg;
- unsigned short count = 0xffff;
- unsigned long flags;
- struct snd_trident *trident = ac97->private_data;
- spin_lock_irqsave(&trident->reg_lock, flags);
- if (trident->device == TRIDENT_DEVICE_ID_DX) {
- data = (DX_AC97_BUSY_READ | (reg & 0x000000ff));
- outl(data, TRID_REG(trident, DX_ACR1_AC97_R));
- do {
- data = inl(TRID_REG(trident, DX_ACR1_AC97_R));
- if ((data & DX_AC97_BUSY_READ) == 0)
- break;
- } while (--count);
- } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
- data = (NX_AC97_BUSY_READ | (reg & 0x000000ff));
- treg = ac97->num == 0 ? NX_ACR2_AC97_R_PRIMARY : NX_ACR3_AC97_R_SECONDARY;
- outl(data, TRID_REG(trident, treg));
- do {
- data = inl(TRID_REG(trident, treg));
- if ((data & 0x00000C00) == 0)
- break;
- } while (--count);
- } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- data = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff);
- if (ac97->num == 1)
- data |= SI_AC97_SECONDARY;
- outl(data, TRID_REG(trident, SI_AC97_READ));
- do {
- data = inl(TRID_REG(trident, SI_AC97_READ));
- if ((data & (SI_AC97_BUSY_READ)) == 0)
- break;
- } while (--count);
- }
- if (count == 0 && !trident->ac97_detect) {
- snd_printk(KERN_ERR "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
- reg, data);
- data = 0;
- }
- spin_unlock_irqrestore(&trident->reg_lock, flags);
- return ((unsigned short) (data >> 16));
- }
- /*---------------------------------------------------------------------------
- void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
- unsigned short wdata)
-
- Description: This routine will do all of the writing to the external
- CODEC (AC97).
-
- Parameters: ac97 - ac97 codec structure
- reg - CODEC register index, from AC97 Hal.
- data - Lower 16 bits are the data to write to CODEC.
-
- returns: TRUE if everything went ok, else FALSE.
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg,
- unsigned short wdata)
- {
- unsigned int address, data;
- unsigned short count = 0xffff;
- unsigned long flags;
- struct snd_trident *trident = ac97->private_data;
- data = ((unsigned long) wdata) << 16;
- spin_lock_irqsave(&trident->reg_lock, flags);
- if (trident->device == TRIDENT_DEVICE_ID_DX) {
- address = DX_ACR0_AC97_W;
- /* read AC-97 write register status */
- do {
- if ((inw(TRID_REG(trident, address)) & DX_AC97_BUSY_WRITE) == 0)
- break;
- } while (--count);
- data |= (DX_AC97_BUSY_WRITE | (reg & 0x000000ff));
- } else if (trident->device == TRIDENT_DEVICE_ID_NX) {
- address = NX_ACR1_AC97_W;
- /* read AC-97 write register status */
- do {
- if ((inw(TRID_REG(trident, address)) & NX_AC97_BUSY_WRITE) == 0)
- break;
- } while (--count);
- data |= (NX_AC97_BUSY_WRITE | (ac97->num << 8) | (reg & 0x000000ff));
- } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- address = SI_AC97_WRITE;
- /* read AC-97 write register status */
- do {
- if ((inw(TRID_REG(trident, address)) & (SI_AC97_BUSY_WRITE)) == 0)
- break;
- } while (--count);
- data |= SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff);
- if (ac97->num == 1)
- data |= SI_AC97_SECONDARY;
- } else {
- address = 0; /* keep GCC happy */
- count = 0; /* return */
- }
- if (count == 0) {
- spin_unlock_irqrestore(&trident->reg_lock, flags);
- return;
- }
- outl(data, TRID_REG(trident, address));
- spin_unlock_irqrestore(&trident->reg_lock, flags);
- }
- /*---------------------------------------------------------------------------
- void snd_trident_enable_eso(struct snd_trident *trident)
-
- Description: This routine will enable end of loop interrupts.
- End of loop interrupts will occur when a running
- channel reaches ESO.
- Also enables middle of loop interrupts.
-
- Parameters: trident - pointer to target device class for 4DWave.
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_enable_eso(struct snd_trident * trident)
- {
- unsigned int val;
- val = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
- val |= ENDLP_IE;
- val |= MIDLP_IE;
- if (trident->device == TRIDENT_DEVICE_ID_SI7018)
- val |= BANK_B_EN;
- outl(val, TRID_REG(trident, T4D_LFO_GC_CIR));
- }
- /*---------------------------------------------------------------------------
- void snd_trident_disable_eso(struct snd_trident *trident)
-
- Description: This routine will disable end of loop interrupts.
- End of loop interrupts will occur when a running
- channel reaches ESO.
- Also disables middle of loop interrupts.
-
- Parameters:
- trident - pointer to target device class for 4DWave.
-
- returns: TRUE if everything went ok, else FALSE.
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_disable_eso(struct snd_trident * trident)
- {
- unsigned int tmp;
- tmp = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
- tmp &= ~ENDLP_IE;
- tmp &= ~MIDLP_IE;
- outl(tmp, TRID_REG(trident, T4D_LFO_GC_CIR));
- }
- /*---------------------------------------------------------------------------
- void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
- Description: Start a voice, any channel 0 thru 63.
- This routine automatically handles the fact that there are
- more than 32 channels available.
- Parameters : voice - Voice number 0 thru n.
- trident - pointer to target device class for 4DWave.
- Return Value: None.
- ---------------------------------------------------------------------------*/
- void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice)
- {
- unsigned int mask = 1 << (voice & 0x1f);
- unsigned int reg = (voice & 0x20) ? T4D_START_B : T4D_START_A;
- outl(mask, TRID_REG(trident, reg));
- }
- EXPORT_SYMBOL(snd_trident_start_voice);
- /*---------------------------------------------------------------------------
- void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
- Description: Stop a voice, any channel 0 thru 63.
- This routine automatically handles the fact that there are
- more than 32 channels available.
- Parameters : voice - Voice number 0 thru n.
- trident - pointer to target device class for 4DWave.
- Return Value: None.
- ---------------------------------------------------------------------------*/
- void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice)
- {
- unsigned int mask = 1 << (voice & 0x1f);
- unsigned int reg = (voice & 0x20) ? T4D_STOP_B : T4D_STOP_A;
- outl(mask, TRID_REG(trident, reg));
- }
- EXPORT_SYMBOL(snd_trident_stop_voice);
- /*---------------------------------------------------------------------------
- int snd_trident_allocate_pcm_channel(struct snd_trident *trident)
-
- Description: Allocate hardware channel in Bank B (32-63).
-
- Parameters : trident - pointer to target device class for 4DWave.
-
- Return Value: hardware channel - 32-63 or -1 when no channel is available
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_allocate_pcm_channel(struct snd_trident * trident)
- {
- int idx;
- if (trident->ChanPCMcnt >= trident->ChanPCM)
- return -1;
- for (idx = 31; idx >= 0; idx--) {
- if (!(trident->ChanMap[T4D_BANK_B] & (1 << idx))) {
- trident->ChanMap[T4D_BANK_B] |= 1 << idx;
- trident->ChanPCMcnt++;
- return idx + 32;
- }
- }
- return -1;
- }
- /*---------------------------------------------------------------------------
- void snd_trident_free_pcm_channel(int channel)
-
- Description: Free hardware channel in Bank B (32-63)
-
- Parameters : trident - pointer to target device class for 4DWave.
- channel - hardware channel number 0-63
-
- Return Value: none
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_free_pcm_channel(struct snd_trident *trident, int channel)
- {
- if (channel < 32 || channel > 63)
- return;
- channel &= 0x1f;
- if (trident->ChanMap[T4D_BANK_B] & (1 << channel)) {
- trident->ChanMap[T4D_BANK_B] &= ~(1 << channel);
- trident->ChanPCMcnt--;
- }
- }
- /*---------------------------------------------------------------------------
- unsigned int snd_trident_allocate_synth_channel(void)
-
- Description: Allocate hardware channel in Bank A (0-31).
-
- Parameters : trident - pointer to target device class for 4DWave.
-
- Return Value: hardware channel - 0-31 or -1 when no channel is available
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_allocate_synth_channel(struct snd_trident * trident)
- {
- int idx;
- for (idx = 31; idx >= 0; idx--) {
- if (!(trident->ChanMap[T4D_BANK_A] & (1 << idx))) {
- trident->ChanMap[T4D_BANK_A] |= 1 << idx;
- trident->synth.ChanSynthCount++;
- return idx;
- }
- }
- return -1;
- }
- /*---------------------------------------------------------------------------
- void snd_trident_free_synth_channel( int channel )
-
- Description: Free hardware channel in Bank B (0-31).
-
- Parameters : trident - pointer to target device class for 4DWave.
- channel - hardware channel number 0-63
-
- Return Value: none
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_free_synth_channel(struct snd_trident *trident, int channel)
- {
- if (channel < 0 || channel > 31)
- return;
- channel &= 0x1f;
- if (trident->ChanMap[T4D_BANK_A] & (1 << channel)) {
- trident->ChanMap[T4D_BANK_A] &= ~(1 << channel);
- trident->synth.ChanSynthCount--;
- }
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_voice_regs
-
- Description: This routine will complete and write the 5 hardware channel
- registers to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- Each register field.
-
- ---------------------------------------------------------------------------*/
- void snd_trident_write_voice_regs(struct snd_trident * trident,
- struct snd_trident_voice * voice)
- {
- unsigned int FmcRvolCvol;
- unsigned int regs[5];
- regs[1] = voice->LBA;
- regs[4] = (voice->GVSel << 31) |
- ((voice->Pan & 0x0000007f) << 24) |
- ((voice->CTRL & 0x0000000f) << 12);
- FmcRvolCvol = ((voice->FMC & 3) << 14) |
- ((voice->RVol & 0x7f) << 7) |
- (voice->CVol & 0x7f);
- switch (trident->device) {
- case TRIDENT_DEVICE_ID_SI7018:
- regs[4] |= voice->number > 31 ?
- (voice->Vol & 0x000003ff) :
- ((voice->Vol & 0x00003fc) << (16-2)) |
- (voice->EC & 0x00000fff);
- regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
- (voice->FMS & 0x0000000f);
- regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
- regs[3] = (voice->Attribute << 16) | FmcRvolCvol;
- break;
- case TRIDENT_DEVICE_ID_DX:
- regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
- (voice->EC & 0x00000fff);
- regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) |
- (voice->FMS & 0x0000000f);
- regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff);
- regs[3] = FmcRvolCvol;
- break;
- case TRIDENT_DEVICE_ID_NX:
- regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) |
- (voice->EC & 0x00000fff);
- regs[0] = (voice->Delta << 24) | (voice->CSO & 0x00ffffff);
- regs[2] = ((voice->Delta << 16) & 0xff000000) |
- (voice->ESO & 0x00ffffff);
- regs[3] = (voice->Alpha << 20) |
- ((voice->FMS & 0x0000000f) << 16) | FmcRvolCvol;
- break;
- default:
- snd_BUG();
- return;
- }
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- outl(regs[0], TRID_REG(trident, CH_START + 0));
- outl(regs[1], TRID_REG(trident, CH_START + 4));
- outl(regs[2], TRID_REG(trident, CH_START + 8));
- outl(regs[3], TRID_REG(trident, CH_START + 12));
- outl(regs[4], TRID_REG(trident, CH_START + 16));
- #if 0
- printk(KERN_DEBUG "written %i channel:\n", voice->number);
- printk(KERN_DEBUG " regs[0] = 0x%x/0x%x\n",
- regs[0], inl(TRID_REG(trident, CH_START + 0)));
- printk(KERN_DEBUG " regs[1] = 0x%x/0x%x\n",
- regs[1], inl(TRID_REG(trident, CH_START + 4)));
- printk(KERN_DEBUG " regs[2] = 0x%x/0x%x\n",
- regs[2], inl(TRID_REG(trident, CH_START + 8)));
- printk(KERN_DEBUG " regs[3] = 0x%x/0x%x\n",
- regs[3], inl(TRID_REG(trident, CH_START + 12)));
- printk(KERN_DEBUG " regs[4] = 0x%x/0x%x\n",
- regs[4], inl(TRID_REG(trident, CH_START + 16)));
- #endif
- }
- EXPORT_SYMBOL(snd_trident_write_voice_regs);
- /*---------------------------------------------------------------------------
- snd_trident_write_cso_reg
-
- Description: This routine will write the new CSO offset
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- CSO - new CSO value
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_cso_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int CSO)
- {
- voice->CSO = CSO;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- if (trident->device != TRIDENT_DEVICE_ID_NX) {
- outw(voice->CSO, TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2);
- } else {
- outl((voice->Delta << 24) |
- (voice->CSO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_CSO));
- }
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_eso_reg
-
- Description: This routine will write the new ESO offset
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- ESO - new ESO value
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_eso_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int ESO)
- {
- voice->ESO = ESO;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- if (trident->device != TRIDENT_DEVICE_ID_NX) {
- outw(voice->ESO, TRID_REG(trident, CH_DX_ESO_DELTA) + 2);
- } else {
- outl(((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff),
- TRID_REG(trident, CH_NX_DELTA_ESO));
- }
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_vol_reg
-
- Description: This routine will write the new voice volume
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- Vol - new voice volume
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_vol_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int Vol)
- {
- voice->Vol = Vol;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- switch (trident->device) {
- case TRIDENT_DEVICE_ID_DX:
- case TRIDENT_DEVICE_ID_NX:
- outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2));
- break;
- case TRIDENT_DEVICE_ID_SI7018:
- /* printk(KERN_DEBUG "voice->Vol = 0x%x\n", voice->Vol); */
- outw((voice->CTRL << 12) | voice->Vol,
- TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
- break;
- }
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_pan_reg
-
- Description: This routine will write the new voice pan
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- Pan - new pan value
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_pan_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int Pan)
- {
- voice->Pan = Pan;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- outb(((voice->GVSel & 0x01) << 7) | (voice->Pan & 0x7f),
- TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 3));
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_rvol_reg
-
- Description: This routine will write the new reverb volume
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- RVol - new reverb volume
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_rvol_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int RVol)
- {
- voice->RVol = RVol;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
- (voice->CVol & 0x007f),
- TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
- CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL));
- }
- /*---------------------------------------------------------------------------
- snd_trident_write_cvol_reg
-
- Description: This routine will write the new chorus volume
- register to hardware.
-
- Parameters: trident - pointer to target device class for 4DWave.
- voice - synthesizer voice structure
- CVol - new chorus volume
-
- ---------------------------------------------------------------------------*/
- static void snd_trident_write_cvol_reg(struct snd_trident * trident,
- struct snd_trident_voice * voice,
- unsigned int CVol)
- {
- voice->CVol = CVol;
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) |
- (voice->CVol & 0x007f),
- TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ?
- CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL));
- }
- /*---------------------------------------------------------------------------
- snd_trident_convert_rate
- Description: This routine converts rate in HZ to hardware delta value.
-
- Parameters: trident - pointer to target device class for 4DWave.
- rate - Real or Virtual channel number.
-
- Returns: Delta value.
-
- ---------------------------------------------------------------------------*/
- static unsigned int snd_trident_convert_rate(unsigned int rate)
- {
- unsigned int delta;
- // We special case 44100 and 8000 since rounding with the equation
- // does not give us an accurate enough value. For 11025 and 22050
- // the equation gives us the best answer. All other frequencies will
- // also use the equation. JDW
- if (rate == 44100)
- delta = 0xeb3;
- else if (rate == 8000)
- delta = 0x2ab;
- else if (rate == 48000)
- delta = 0x1000;
- else
- delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff;
- return delta;
- }
- /*---------------------------------------------------------------------------
- snd_trident_convert_adc_rate
- Description: This routine converts rate in HZ to hardware delta value.
-
- Parameters: trident - pointer to target device class for 4DWave.
- rate - Real or Virtual channel number.
-
- Returns: Delta value.
-
- ---------------------------------------------------------------------------*/
- static unsigned int snd_trident_convert_adc_rate(unsigned int rate)
- {
- unsigned int delta;
- // We special case 44100 and 8000 since rounding with the equation
- // does not give us an accurate enough value. For 11025 and 22050
- // the equation gives us the best answer. All other frequencies will
- // also use the equation. JDW
- if (rate == 44100)
- delta = 0x116a;
- else if (rate == 8000)
- delta = 0x6000;
- else if (rate == 48000)
- delta = 0x1000;
- else
- delta = ((48000 << 12) / rate) & 0x0000ffff;
- return delta;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spurious_threshold
- Description: This routine converts rate in HZ to spurious threshold.
-
- Parameters: trident - pointer to target device class for 4DWave.
- rate - Real or Virtual channel number.
-
- Returns: Delta value.
-
- ---------------------------------------------------------------------------*/
- static unsigned int snd_trident_spurious_threshold(unsigned int rate,
- unsigned int period_size)
- {
- unsigned int res = (rate * period_size) / 48000;
- if (res < 64)
- res = res / 2;
- else
- res -= 32;
- return res;
- }
- /*---------------------------------------------------------------------------
- snd_trident_control_mode
- Description: This routine returns a control mode for a PCM channel.
-
- Parameters: trident - pointer to target device class for 4DWave.
- substream - PCM substream
-
- Returns: Control value.
-
- ---------------------------------------------------------------------------*/
- static unsigned int snd_trident_control_mode(struct snd_pcm_substream *substream)
- {
- unsigned int CTRL;
- struct snd_pcm_runtime *runtime = substream->runtime;
- /* set ctrl mode
- CTRL default: 8-bit (unsigned) mono, loop mode enabled
- */
- CTRL = 0x00000001;
- if (snd_pcm_format_width(runtime->format) == 16)
- CTRL |= 0x00000008; // 16-bit data
- if (snd_pcm_format_signed(runtime->format))
- CTRL |= 0x00000002; // signed data
- if (runtime->channels > 1)
- CTRL |= 0x00000004; // stereo data
- return CTRL;
- }
- /*
- * PCM part
- */
- /*---------------------------------------------------------------------------
- snd_trident_ioctl
-
- Description: Device I/O control handler for playback/capture parameters.
-
- Parameters: substream - PCM substream class
- cmd - what ioctl message to process
- arg - additional message infoarg
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_ioctl(struct snd_pcm_substream *substream,
- unsigned int cmd,
- void *arg)
- {
- /* FIXME: it seems that with small periods the behaviour of
- trident hardware is unpredictable and interrupt generator
- is broken */
- return snd_pcm_lib_ioctl(substream, cmd, arg);
- }
- /*---------------------------------------------------------------------------
- snd_trident_allocate_pcm_mem
-
- Description: Allocate PCM ring buffer for given substream
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- int err;
- if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
- return err;
- if (trident->tlb.entries) {
- if (err > 0) { /* change */
- if (voice->memblk)
- snd_trident_free_pages(trident, voice->memblk);
- voice->memblk = snd_trident_alloc_pages(trident, substream);
- if (voice->memblk == NULL)
- return -ENOMEM;
- }
- }
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_allocate_evoice
-
- Description: Allocate extra voice as interrupt generator
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_allocate_evoice(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice->extra;
- /* voice management */
- if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) {
- if (evoice == NULL) {
- evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
- if (evoice == NULL)
- return -ENOMEM;
- voice->extra = evoice;
- evoice->substream = substream;
- }
- } else {
- if (evoice != NULL) {
- snd_trident_free_voice(trident, evoice);
- voice->extra = evoice = NULL;
- }
- }
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_hw_params
-
- Description: Set the hardware parameters for the playback device.
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- int err;
- err = snd_trident_allocate_pcm_mem(substream, hw_params);
- if (err >= 0)
- err = snd_trident_allocate_evoice(substream, hw_params);
- return err;
- }
- /*---------------------------------------------------------------------------
- snd_trident_playback_hw_free
-
- Description: Release the hardware resources for the playback device.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_hw_free(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
- if (trident->tlb.entries) {
- if (voice && voice->memblk) {
- snd_trident_free_pages(trident, voice->memblk);
- voice->memblk = NULL;
- }
- }
- snd_pcm_lib_free_pages(substream);
- if (evoice != NULL) {
- snd_trident_free_voice(trident, evoice);
- voice->extra = NULL;
- }
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_playback_prepare
-
- Description: Prepare playback device for playback.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_playback_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice->extra;
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
- spin_lock_irq(&trident->reg_lock);
- /* set delta (rate) value */
- voice->Delta = snd_trident_convert_rate(runtime->rate);
- voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
- /* set Loop Begin Address */
- if (voice->memblk)
- voice->LBA = voice->memblk->offset;
- else
- voice->LBA = runtime->dma_addr;
-
- voice->CSO = 0;
- voice->ESO = runtime->buffer_size - 1; /* in samples */
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 3;
- voice->GVSel = 1;
- voice->EC = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Vol = mix->vol;
- voice->RVol = mix->rvol;
- voice->CVol = mix->cvol;
- voice->Pan = mix->pan;
- voice->Attribute = 0;
- #if 0
- voice->Attribute = (1<<(30-16))|(2<<(26-16))|
- (0<<(24-16))|(0x1f<<(19-16));
- #else
- voice->Attribute = 0;
- #endif
- snd_trident_write_voice_regs(trident, voice);
- if (evoice != NULL) {
- evoice->Delta = voice->Delta;
- evoice->spurious_threshold = voice->spurious_threshold;
- evoice->LBA = voice->LBA;
- evoice->CSO = 0;
- evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
- evoice->CTRL = voice->CTRL;
- evoice->FMC = 3;
- evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
- evoice->EC = 0;
- evoice->Alpha = 0;
- evoice->FMS = 0;
- evoice->Vol = 0x3ff; /* mute */
- evoice->RVol = evoice->CVol = 0x7f; /* mute */
- evoice->Pan = 0x7f; /* mute */
- #if 0
- evoice->Attribute = (1<<(30-16))|(2<<(26-16))|
- (0<<(24-16))|(0x1f<<(19-16));
- #else
- evoice->Attribute = 0;
- #endif
- snd_trident_write_voice_regs(trident, evoice);
- evoice->isync2 = 1;
- evoice->isync_mark = runtime->period_size;
- evoice->ESO = (runtime->period_size * 2) - 1;
- }
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_capture_hw_params
-
- Description: Set the hardware parameters for the capture device.
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_capture_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- return snd_trident_allocate_pcm_mem(substream, hw_params);
- }
- /*---------------------------------------------------------------------------
- snd_trident_capture_prepare
-
- Description: Prepare capture device for playback.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_capture_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- unsigned int val, ESO_bytes;
- spin_lock_irq(&trident->reg_lock);
- // Initialize the channel and set channel Mode
- outb(0, TRID_REG(trident, LEGACY_DMAR15));
- // Set DMA channel operation mode register
- outb(0x54, TRID_REG(trident, LEGACY_DMAR11));
- // Set channel buffer Address, DMAR0 expects contiguous PCI memory area
- voice->LBA = runtime->dma_addr;
- outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0));
- if (voice->memblk)
- voice->LBA = voice->memblk->offset;
- // set ESO
- ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1;
- outb((ESO_bytes & 0x00ff0000) >> 16, TRID_REG(trident, LEGACY_DMAR6));
- outw((ESO_bytes & 0x0000ffff), TRID_REG(trident, LEGACY_DMAR4));
- ESO_bytes++;
- // Set channel sample rate, 4.12 format
- val = (((unsigned int) 48000L << 12) + (runtime->rate/2)) / runtime->rate;
- outw(val, TRID_REG(trident, T4D_SBDELTA_DELTA_R));
- // Set channel interrupt blk length
- if (snd_pcm_format_width(runtime->format) == 16) {
- val = (unsigned short) ((ESO_bytes >> 1) - 1);
- } else {
- val = (unsigned short) (ESO_bytes - 1);
- }
- outl((val << 16) | val, TRID_REG(trident, T4D_SBBL_SBCL));
- // Right now, set format and start to run captureing,
- // continuous run loop enable.
- trident->bDMAStart = 0x19; // 0001 1001b
- if (snd_pcm_format_width(runtime->format) == 16)
- trident->bDMAStart |= 0x80;
- if (snd_pcm_format_signed(runtime->format))
- trident->bDMAStart |= 0x20;
- if (runtime->channels > 1)
- trident->bDMAStart |= 0x40;
- // Prepare capture intr channel
- voice->Delta = snd_trident_convert_rate(runtime->rate);
- voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
- voice->isync = 1;
- voice->isync_mark = runtime->period_size;
- voice->isync_max = runtime->buffer_size;
- // Set voice parameters
- voice->CSO = 0;
- voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 3;
- voice->RVol = 0x7f;
- voice->CVol = 0x7f;
- voice->GVSel = 1;
- voice->Pan = 0x7f; /* mute */
- voice->Vol = 0x3ff; /* mute */
- voice->EC = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Attribute = 0;
- snd_trident_write_voice_regs(trident, voice);
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_si7018_capture_hw_params
-
- Description: Set the hardware parameters for the capture device.
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- int err;
- if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
- return err;
- return snd_trident_allocate_evoice(substream, hw_params);
- }
- /*---------------------------------------------------------------------------
- snd_trident_si7018_capture_hw_free
-
- Description: Release the hardware resources for the capture device.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice ? voice->extra : NULL;
- snd_pcm_lib_free_pages(substream);
- if (evoice != NULL) {
- snd_trident_free_voice(trident, evoice);
- voice->extra = NULL;
- }
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_si7018_capture_prepare
-
- Description: Prepare capture device for playback.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice->extra;
- spin_lock_irq(&trident->reg_lock);
- voice->LBA = runtime->dma_addr;
- voice->Delta = snd_trident_convert_adc_rate(runtime->rate);
- voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
- // Set voice parameters
- voice->CSO = 0;
- voice->ESO = runtime->buffer_size - 1; /* in samples */
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 0;
- voice->RVol = 0;
- voice->CVol = 0;
- voice->GVSel = 1;
- voice->Pan = T4D_DEFAULT_PCM_PAN;
- voice->Vol = 0;
- voice->EC = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Attribute = (2 << (30-16)) |
- (2 << (26-16)) |
- (2 << (24-16)) |
- (1 << (23-16));
- snd_trident_write_voice_regs(trident, voice);
- if (evoice != NULL) {
- evoice->Delta = snd_trident_convert_rate(runtime->rate);
- evoice->spurious_threshold = voice->spurious_threshold;
- evoice->LBA = voice->LBA;
- evoice->CSO = 0;
- evoice->ESO = (runtime->period_size * 2) + 20 - 1; /* in samples, 20 means correction */
- evoice->CTRL = voice->CTRL;
- evoice->FMC = 3;
- evoice->GVSel = 0;
- evoice->EC = 0;
- evoice->Alpha = 0;
- evoice->FMS = 0;
- evoice->Vol = 0x3ff; /* mute */
- evoice->RVol = evoice->CVol = 0x7f; /* mute */
- evoice->Pan = 0x7f; /* mute */
- evoice->Attribute = 0;
- snd_trident_write_voice_regs(trident, evoice);
- evoice->isync2 = 1;
- evoice->isync_mark = runtime->period_size;
- evoice->ESO = (runtime->period_size * 2) - 1;
- }
-
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_foldback_prepare
-
- Description: Prepare foldback capture device for playback.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_foldback_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice->extra;
- spin_lock_irq(&trident->reg_lock);
- /* Set channel buffer Address */
- if (voice->memblk)
- voice->LBA = voice->memblk->offset;
- else
- voice->LBA = runtime->dma_addr;
- /* set target ESO for channel */
- voice->ESO = runtime->buffer_size - 1; /* in samples */
- /* set sample rate */
- voice->Delta = 0x1000;
- voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
- voice->CSO = 0;
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 3;
- voice->RVol = 0x7f;
- voice->CVol = 0x7f;
- voice->GVSel = 1;
- voice->Pan = 0x7f; /* mute */
- voice->Vol = 0x3ff; /* mute */
- voice->EC = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Attribute = 0;
- /* set up capture channel */
- outb(((voice->number & 0x3f) | 0x80), TRID_REG(trident, T4D_RCI + voice->foldback_chan));
- snd_trident_write_voice_regs(trident, voice);
- if (evoice != NULL) {
- evoice->Delta = voice->Delta;
- evoice->spurious_threshold = voice->spurious_threshold;
- evoice->LBA = voice->LBA;
- evoice->CSO = 0;
- evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
- evoice->CTRL = voice->CTRL;
- evoice->FMC = 3;
- evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
- evoice->EC = 0;
- evoice->Alpha = 0;
- evoice->FMS = 0;
- evoice->Vol = 0x3ff; /* mute */
- evoice->RVol = evoice->CVol = 0x7f; /* mute */
- evoice->Pan = 0x7f; /* mute */
- evoice->Attribute = 0;
- snd_trident_write_voice_regs(trident, evoice);
- evoice->isync2 = 1;
- evoice->isync_mark = runtime->period_size;
- evoice->ESO = (runtime->period_size * 2) - 1;
- }
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif_hw_params
-
- Description: Set the hardware parameters for the spdif device.
-
- Parameters: substream - PCM substream class
- hw_params - hardware parameters
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- unsigned int old_bits = 0, change = 0;
- int err;
- err = snd_trident_allocate_pcm_mem(substream, hw_params);
- if (err < 0)
- return err;
- if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- err = snd_trident_allocate_evoice(substream, hw_params);
- if (err < 0)
- return err;
- }
- /* prepare SPDIF channel */
- spin_lock_irq(&trident->reg_lock);
- old_bits = trident->spdif_pcm_bits;
- if (old_bits & IEC958_AES0_PROFESSIONAL)
- trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS;
- else
- trident->spdif_pcm_bits &= ~(IEC958_AES3_CON_FS << 24);
- if (params_rate(hw_params) >= 48000) {
- trident->spdif_pcm_ctrl = 0x3c; // 48000 Hz
- trident->spdif_pcm_bits |=
- trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
- IEC958_AES0_PRO_FS_48000 :
- (IEC958_AES3_CON_FS_48000 << 24);
- }
- else if (params_rate(hw_params) >= 44100) {
- trident->spdif_pcm_ctrl = 0x3e; // 44100 Hz
- trident->spdif_pcm_bits |=
- trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
- IEC958_AES0_PRO_FS_44100 :
- (IEC958_AES3_CON_FS_44100 << 24);
- }
- else {
- trident->spdif_pcm_ctrl = 0x3d; // 32000 Hz
- trident->spdif_pcm_bits |=
- trident->spdif_bits & IEC958_AES0_PROFESSIONAL ?
- IEC958_AES0_PRO_FS_32000 :
- (IEC958_AES3_CON_FS_32000 << 24);
- }
- change = old_bits != trident->spdif_pcm_bits;
- spin_unlock_irq(&trident->reg_lock);
- if (change)
- snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif_prepare
-
- Description: Prepare SPDIF device for playback.
-
- Parameters: substream - PCM substream class
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident_voice *evoice = voice->extra;
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number];
- unsigned int RESO, LBAO;
- unsigned int temp;
- spin_lock_irq(&trident->reg_lock);
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- /* set delta (rate) value */
- voice->Delta = snd_trident_convert_rate(runtime->rate);
- voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
- /* set Loop Back Address */
- LBAO = runtime->dma_addr;
- if (voice->memblk)
- voice->LBA = voice->memblk->offset;
- else
- voice->LBA = LBAO;
- voice->isync = 1;
- voice->isync3 = 1;
- voice->isync_mark = runtime->period_size;
- voice->isync_max = runtime->buffer_size;
- /* set target ESO for channel */
- RESO = runtime->buffer_size - 1;
- voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1;
- /* set ctrl mode */
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 3;
- voice->RVol = 0x7f;
- voice->CVol = 0x7f;
- voice->GVSel = 1;
- voice->Pan = 0x7f;
- voice->Vol = 0x3ff;
- voice->EC = 0;
- voice->CSO = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Attribute = 0;
- /* prepare surrogate IRQ channel */
- snd_trident_write_voice_regs(trident, voice);
- outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO));
- outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2));
- outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA));
- outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO));
- outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2));
- /* set SPDIF setting */
- outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
- } else { /* SiS */
-
- /* set delta (rate) value */
- voice->Delta = 0x800;
- voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
- /* set Loop Begin Address */
- if (voice->memblk)
- voice->LBA = voice->memblk->offset;
- else
- voice->LBA = runtime->dma_addr;
- voice->CSO = 0;
- voice->ESO = runtime->buffer_size - 1; /* in samples */
- voice->CTRL = snd_trident_control_mode(substream);
- voice->FMC = 3;
- voice->GVSel = 1;
- voice->EC = 0;
- voice->Alpha = 0;
- voice->FMS = 0;
- voice->Vol = mix->vol;
- voice->RVol = mix->rvol;
- voice->CVol = mix->cvol;
- voice->Pan = mix->pan;
- voice->Attribute = (1<<(30-16))|(7<<(26-16))|
- (0<<(24-16))|(0<<(19-16));
- snd_trident_write_voice_regs(trident, voice);
- if (evoice != NULL) {
- evoice->Delta = voice->Delta;
- evoice->spurious_threshold = voice->spurious_threshold;
- evoice->LBA = voice->LBA;
- evoice->CSO = 0;
- evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */
- evoice->CTRL = voice->CTRL;
- evoice->FMC = 3;
- evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
- evoice->EC = 0;
- evoice->Alpha = 0;
- evoice->FMS = 0;
- evoice->Vol = 0x3ff; /* mute */
- evoice->RVol = evoice->CVol = 0x7f; /* mute */
- evoice->Pan = 0x7f; /* mute */
- evoice->Attribute = 0;
- snd_trident_write_voice_regs(trident, evoice);
- evoice->isync2 = 1;
- evoice->isync_mark = runtime->period_size;
- evoice->ESO = (runtime->period_size * 2) - 1;
- }
- outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
- temp = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
- temp &= ~(1<<19);
- outl(temp, TRID_REG(trident, T4D_LFO_GC_CIR));
- temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- temp |= SPDIF_EN;
- outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- }
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_trigger
-
- Description: Start/stop devices
-
- Parameters: substream - PCM substream class
- cmd - trigger command (STOP, GO)
-
- Returns: Error status
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_trigger(struct snd_pcm_substream *substream,
- int cmd)
-
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_substream *s;
- unsigned int what, whati, capture_flag, spdif_flag;
- struct snd_trident_voice *voice, *evoice;
- unsigned int val, go;
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- case SNDRV_PCM_TRIGGER_RESUME:
- go = 1;
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- case SNDRV_PCM_TRIGGER_SUSPEND:
- go = 0;
- break;
- default:
- return -EINVAL;
- }
- what = whati = capture_flag = spdif_flag = 0;
- spin_lock(&trident->reg_lock);
- val = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff;
- snd_pcm_group_for_each_entry(s, substream) {
- if ((struct snd_trident *) snd_pcm_substream_chip(s) == trident) {
- voice = s->runtime->private_data;
- evoice = voice->extra;
- what |= 1 << (voice->number & 0x1f);
- if (evoice == NULL) {
- whati |= 1 << (voice->number & 0x1f);
- } else {
- what |= 1 << (evoice->number & 0x1f);
- whati |= 1 << (evoice->number & 0x1f);
- if (go)
- evoice->stimer = val;
- }
- if (go) {
- voice->running = 1;
- voice->stimer = val;
- } else {
- voice->running = 0;
- }
- snd_pcm_trigger_done(s, substream);
- if (voice->capture)
- capture_flag = 1;
- if (voice->spdif)
- spdif_flag = 1;
- }
- }
- if (spdif_flag) {
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
- val = trident->spdif_pcm_ctrl;
- if (!go)
- val &= ~(0x28);
- outb(val, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- } else {
- outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
- val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN;
- outl(val, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- }
- }
- if (!go)
- outl(what, TRID_REG(trident, T4D_STOP_B));
- val = inl(TRID_REG(trident, T4D_AINTEN_B));
- if (go) {
- val |= whati;
- } else {
- val &= ~whati;
- }
- outl(val, TRID_REG(trident, T4D_AINTEN_B));
- if (go) {
- outl(what, TRID_REG(trident, T4D_START_B));
- if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
- outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
- } else {
- if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
- outb(0x00, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
- }
- spin_unlock(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_playback_pointer
-
- Description: This routine return the playback position
-
- Parameters: substream - PCM substream class
- Returns: position of buffer
-
- ---------------------------------------------------------------------------*/
- static snd_pcm_uframes_t snd_trident_playback_pointer(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- unsigned int cso;
- if (!voice->running)
- return 0;
- spin_lock(&trident->reg_lock);
- outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR));
- if (trident->device != TRIDENT_DEVICE_ID_NX) {
- cso = inw(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS + 2));
- } else { // ID_4DWAVE_NX
- cso = (unsigned int) inl(TRID_REG(trident, CH_NX_DELTA_CSO)) & 0x00ffffff;
- }
- spin_unlock(&trident->reg_lock);
- if (cso >= runtime->buffer_size)
- cso = 0;
- return cso;
- }
- /*---------------------------------------------------------------------------
- snd_trident_capture_pointer
-
- Description: This routine return the capture position
-
- Parameters: pcm1 - PCM device class
- Returns: position of buffer
-
- ---------------------------------------------------------------------------*/
- static snd_pcm_uframes_t snd_trident_capture_pointer(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- unsigned int result;
- if (!voice->running)
- return 0;
- result = inw(TRID_REG(trident, T4D_SBBL_SBCL));
- if (runtime->channels > 1)
- result >>= 1;
- if (result > 0)
- result = runtime->buffer_size - result;
- return result;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif_pointer
-
- Description: This routine return the SPDIF playback position
-
- Parameters: substream - PCM substream class
- Returns: position of buffer
-
- ---------------------------------------------------------------------------*/
- static snd_pcm_uframes_t snd_trident_spdif_pointer(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- unsigned int result;
- if (!voice->running)
- return 0;
- result = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff;
- return result;
- }
- /*
- * Playback support device description
- */
- static struct snd_pcm_hardware snd_trident_playback =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
- SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
- .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
- SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
- .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
- .rate_min = 4000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = (256*1024),
- .period_bytes_min = 64,
- .period_bytes_max = (256*1024),
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0,
- };
- /*
- * Capture support device description
- */
- static struct snd_pcm_hardware snd_trident_capture =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
- SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
- .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
- SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
- .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
- .rate_min = 4000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = (128*1024),
- .period_bytes_min = 64,
- .period_bytes_max = (128*1024),
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0,
- };
- /*
- * Foldback capture support device description
- */
- static struct snd_pcm_hardware snd_trident_foldback =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
- SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = SNDRV_PCM_RATE_48000,
- .rate_min = 48000,
- .rate_max = 48000,
- .channels_min = 2,
- .channels_max = 2,
- .buffer_bytes_max = (128*1024),
- .period_bytes_min = 64,
- .period_bytes_max = (128*1024),
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0,
- };
- /*
- * SPDIF playback support device description
- */
- static struct snd_pcm_hardware snd_trident_spdif =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
- SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
- SNDRV_PCM_RATE_48000),
- .rate_min = 32000,
- .rate_max = 48000,
- .channels_min = 2,
- .channels_max = 2,
- .buffer_bytes_max = (128*1024),
- .period_bytes_min = 64,
- .period_bytes_max = (128*1024),
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0,
- };
- static struct snd_pcm_hardware snd_trident_spdif_7018 =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
- SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */),
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = SNDRV_PCM_RATE_48000,
- .rate_min = 48000,
- .rate_max = 48000,
- .channels_min = 2,
- .channels_max = 2,
- .buffer_bytes_max = (128*1024),
- .period_bytes_min = 64,
- .period_bytes_max = (128*1024),
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0,
- };
- static void snd_trident_pcm_free_substream(struct snd_pcm_runtime *runtime)
- {
- struct snd_trident_voice *voice = runtime->private_data;
- struct snd_trident *trident;
- if (voice) {
- trident = voice->trident;
- snd_trident_free_voice(trident, voice);
- }
- }
- static int snd_trident_playback_open(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice;
- voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
- if (voice == NULL)
- return -EAGAIN;
- snd_trident_pcm_mixer_build(trident, voice, substream);
- voice->substream = substream;
- runtime->private_data = voice;
- runtime->private_free = snd_trident_pcm_free_substream;
- runtime->hw = snd_trident_playback;
- snd_pcm_set_sync(substream);
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_playback_close
-
- Description: This routine will close the 4DWave playback device. For now
- we will simply free the dma transfer buffer.
-
- Parameters: substream - PCM substream class
- ---------------------------------------------------------------------------*/
- static int snd_trident_playback_close(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- struct snd_trident_voice *voice = runtime->private_data;
- snd_trident_pcm_mixer_free(trident, voice, substream);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif_open
-
- Description: This routine will open the 4DWave SPDIF device.
- Parameters: substream - PCM substream class
- Returns: status - success or failure flag
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_open(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_trident_voice *voice;
- struct snd_pcm_runtime *runtime = substream->runtime;
-
- voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
- if (voice == NULL)
- return -EAGAIN;
- voice->spdif = 1;
- voice->substream = substream;
- spin_lock_irq(&trident->reg_lock);
- trident->spdif_pcm_bits = trident->spdif_bits;
- spin_unlock_irq(&trident->reg_lock);
- runtime->private_data = voice;
- runtime->private_free = snd_trident_pcm_free_substream;
- if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- runtime->hw = snd_trident_spdif;
- } else {
- runtime->hw = snd_trident_spdif_7018;
- }
- trident->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
- SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif_close
-
- Description: This routine will close the 4DWave SPDIF device.
-
- Parameters: substream - PCM substream class
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_close(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- unsigned int temp;
- spin_lock_irq(&trident->reg_lock);
- // restore default SPDIF setting
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
- } else {
- outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
- temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- if (trident->spdif_ctrl) {
- temp |= SPDIF_EN;
- } else {
- temp &= ~SPDIF_EN;
- }
- outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- }
- spin_unlock_irq(&trident->reg_lock);
- trident->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
- SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_capture_open
-
- Description: This routine will open the 4DWave capture device.
- Parameters: substream - PCM substream class
- Returns: status - success or failure flag
- ---------------------------------------------------------------------------*/
- static int snd_trident_capture_open(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_trident_voice *voice;
- struct snd_pcm_runtime *runtime = substream->runtime;
- voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
- if (voice == NULL)
- return -EAGAIN;
- voice->capture = 1;
- voice->substream = substream;
- runtime->private_data = voice;
- runtime->private_free = snd_trident_pcm_free_substream;
- runtime->hw = snd_trident_capture;
- snd_pcm_set_sync(substream);
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_capture_close
-
- Description: This routine will close the 4DWave capture device. For now
- we will simply free the dma transfer buffer.
-
- Parameters: substream - PCM substream class
- ---------------------------------------------------------------------------*/
- static int snd_trident_capture_close(struct snd_pcm_substream *substream)
- {
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_foldback_open
-
- Description: This routine will open the 4DWave foldback capture device.
- Parameters: substream - PCM substream class
- Returns: status - success or failure flag
- ---------------------------------------------------------------------------*/
- static int snd_trident_foldback_open(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_trident_voice *voice;
- struct snd_pcm_runtime *runtime = substream->runtime;
- voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
- if (voice == NULL)
- return -EAGAIN;
- voice->foldback_chan = substream->number;
- voice->substream = substream;
- runtime->private_data = voice;
- runtime->private_free = snd_trident_pcm_free_substream;
- runtime->hw = snd_trident_foldback;
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_foldback_close
-
- Description: This routine will close the 4DWave foldback capture device.
- For now we will simply free the dma transfer buffer.
-
- Parameters: substream - PCM substream class
- ---------------------------------------------------------------------------*/
- static int snd_trident_foldback_close(struct snd_pcm_substream *substream)
- {
- struct snd_trident *trident = snd_pcm_substream_chip(substream);
- struct snd_trident_voice *voice;
- struct snd_pcm_runtime *runtime = substream->runtime;
- voice = runtime->private_data;
-
- /* stop capture channel */
- spin_lock_irq(&trident->reg_lock);
- outb(0x00, TRID_REG(trident, T4D_RCI + voice->foldback_chan));
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- /*---------------------------------------------------------------------------
- PCM operations
- ---------------------------------------------------------------------------*/
- static struct snd_pcm_ops snd_trident_playback_ops = {
- .open = snd_trident_playback_open,
- .close = snd_trident_playback_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_playback_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- };
- static struct snd_pcm_ops snd_trident_nx_playback_ops = {
- .open = snd_trident_playback_open,
- .close = snd_trident_playback_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_playback_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- .page = snd_pcm_sgbuf_ops_page,
- };
- static struct snd_pcm_ops snd_trident_capture_ops = {
- .open = snd_trident_capture_open,
- .close = snd_trident_capture_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_capture_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_capture_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_capture_pointer,
- };
- static struct snd_pcm_ops snd_trident_si7018_capture_ops = {
- .open = snd_trident_capture_open,
- .close = snd_trident_capture_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_si7018_capture_hw_params,
- .hw_free = snd_trident_si7018_capture_hw_free,
- .prepare = snd_trident_si7018_capture_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- };
- static struct snd_pcm_ops snd_trident_foldback_ops = {
- .open = snd_trident_foldback_open,
- .close = snd_trident_foldback_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_foldback_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- };
- static struct snd_pcm_ops snd_trident_nx_foldback_ops = {
- .open = snd_trident_foldback_open,
- .close = snd_trident_foldback_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_foldback_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- .page = snd_pcm_sgbuf_ops_page,
- };
- static struct snd_pcm_ops snd_trident_spdif_ops = {
- .open = snd_trident_spdif_open,
- .close = snd_trident_spdif_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_spdif_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_spdif_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_spdif_pointer,
- };
- static struct snd_pcm_ops snd_trident_spdif_7018_ops = {
- .open = snd_trident_spdif_open,
- .close = snd_trident_spdif_close,
- .ioctl = snd_trident_ioctl,
- .hw_params = snd_trident_spdif_hw_params,
- .hw_free = snd_trident_hw_free,
- .prepare = snd_trident_spdif_prepare,
- .trigger = snd_trident_trigger,
- .pointer = snd_trident_playback_pointer,
- };
- /*---------------------------------------------------------------------------
- snd_trident_pcm
-
- Description: This routine registers the 4DWave device for PCM support.
-
- Parameters: trident - pointer to target device class for 4DWave.
- Returns: None
-
- ---------------------------------------------------------------------------*/
- int __devinit snd_trident_pcm(struct snd_trident * trident,
- int device, struct snd_pcm ** rpcm)
- {
- struct snd_pcm *pcm;
- int err;
- if (rpcm)
- *rpcm = NULL;
- if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, trident->ChanPCM, 1, &pcm)) < 0)
- return err;
- pcm->private_data = trident;
- if (trident->tlb.entries) {
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_nx_playback_ops);
- } else {
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_playback_ops);
- }
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
- trident->device != TRIDENT_DEVICE_ID_SI7018 ?
- &snd_trident_capture_ops :
- &snd_trident_si7018_capture_ops);
- pcm->info_flags = 0;
- pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
- strcpy(pcm->name, "Trident 4DWave");
- trident->pcm = pcm;
- if (trident->tlb.entries) {
- struct snd_pcm_substream *substream;
- for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
- snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
- snd_dma_pci_data(trident->pci),
- 64*1024, 128*1024);
- snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
- SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
- 64*1024, 128*1024);
- } else {
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
- snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
- }
- if (rpcm)
- *rpcm = pcm;
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_foldback_pcm
-
- Description: This routine registers the 4DWave device for foldback PCM support.
-
- Parameters: trident - pointer to target device class for 4DWave.
- Returns: None
-
- ---------------------------------------------------------------------------*/
- int __devinit snd_trident_foldback_pcm(struct snd_trident * trident,
- int device, struct snd_pcm ** rpcm)
- {
- struct snd_pcm *foldback;
- int err;
- int num_chan = 3;
- struct snd_pcm_substream *substream;
- if (rpcm)
- *rpcm = NULL;
- if (trident->device == TRIDENT_DEVICE_ID_NX)
- num_chan = 4;
- if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, 0, num_chan, &foldback)) < 0)
- return err;
- foldback->private_data = trident;
- if (trident->tlb.entries)
- snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_nx_foldback_ops);
- else
- snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_foldback_ops);
- foldback->info_flags = 0;
- strcpy(foldback->name, "Trident 4DWave");
- substream = foldback->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
- strcpy(substream->name, "Front Mixer");
- substream = substream->next;
- strcpy(substream->name, "Reverb Mixer");
- substream = substream->next;
- strcpy(substream->name, "Chorus Mixer");
- if (num_chan == 4) {
- substream = substream->next;
- strcpy(substream->name, "Second AC'97 ADC");
- }
- trident->foldback = foldback;
- if (trident->tlb.entries)
- snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV_SG,
- snd_dma_pci_data(trident->pci), 0, 128*1024);
- else
- snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV,
- snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
- if (rpcm)
- *rpcm = foldback;
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_spdif
-
- Description: This routine registers the 4DWave-NX device for SPDIF support.
-
- Parameters: trident - pointer to target device class for 4DWave-NX.
- Returns: None
-
- ---------------------------------------------------------------------------*/
- int __devinit snd_trident_spdif_pcm(struct snd_trident * trident,
- int device, struct snd_pcm ** rpcm)
- {
- struct snd_pcm *spdif;
- int err;
- if (rpcm)
- *rpcm = NULL;
- if ((err = snd_pcm_new(trident->card, "trident_dx_nx IEC958", device, 1, 0, &spdif)) < 0)
- return err;
- spdif->private_data = trident;
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops);
- } else {
- snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_7018_ops);
- }
- spdif->info_flags = 0;
- strcpy(spdif->name, "Trident 4DWave IEC958");
- trident->spdif = spdif;
- snd_pcm_lib_preallocate_pages_for_all(spdif, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024);
- if (rpcm)
- *rpcm = spdif;
- return 0;
- }
- /*
- * Mixer part
- */
- /*---------------------------------------------------------------------------
- snd_trident_spdif_control
- Description: enable/disable S/PDIF out from ac97 mixer
- ---------------------------------------------------------------------------*/
- #define snd_trident_spdif_control_info snd_ctl_boolean_mono_info
- static int snd_trident_spdif_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned char val;
- spin_lock_irq(&trident->reg_lock);
- val = trident->spdif_ctrl;
- ucontrol->value.integer.value[0] = val == kcontrol->private_value;
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- static int snd_trident_spdif_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned char val;
- int change;
- val = ucontrol->value.integer.value[0] ? (unsigned char) kcontrol->private_value : 0x00;
- spin_lock_irq(&trident->reg_lock);
- /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
- change = trident->spdif_ctrl != val;
- trident->spdif_ctrl = val;
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) {
- outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
- outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- }
- } else {
- if (trident->spdif == NULL) {
- unsigned int temp;
- outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
- temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & ~SPDIF_EN;
- if (val)
- temp |= SPDIF_EN;
- outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- }
- }
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_spdif_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
- .info = snd_trident_spdif_control_info,
- .get = snd_trident_spdif_control_get,
- .put = snd_trident_spdif_control_put,
- .private_value = 0x28,
- };
- /*---------------------------------------------------------------------------
- snd_trident_spdif_default
- Description: put/get the S/PDIF default settings
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_default_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
- uinfo->count = 1;
- return 0;
- }
- static int snd_trident_spdif_default_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&trident->reg_lock);
- ucontrol->value.iec958.status[0] = (trident->spdif_bits >> 0) & 0xff;
- ucontrol->value.iec958.status[1] = (trident->spdif_bits >> 8) & 0xff;
- ucontrol->value.iec958.status[2] = (trident->spdif_bits >> 16) & 0xff;
- ucontrol->value.iec958.status[3] = (trident->spdif_bits >> 24) & 0xff;
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- static int snd_trident_spdif_default_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned int val;
- int change;
- val = (ucontrol->value.iec958.status[0] << 0) |
- (ucontrol->value.iec958.status[1] << 8) |
- (ucontrol->value.iec958.status[2] << 16) |
- (ucontrol->value.iec958.status[3] << 24);
- spin_lock_irq(&trident->reg_lock);
- change = trident->spdif_bits != val;
- trident->spdif_bits = val;
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0)
- outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
- } else {
- if (trident->spdif == NULL)
- outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
- }
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_spdif_default __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_PCM,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
- .info = snd_trident_spdif_default_info,
- .get = snd_trident_spdif_default_get,
- .put = snd_trident_spdif_default_put
- };
- /*---------------------------------------------------------------------------
- snd_trident_spdif_mask
- Description: put/get the S/PDIF mask
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_mask_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
- uinfo->count = 1;
- return 0;
- }
- static int snd_trident_spdif_mask_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- ucontrol->value.iec958.status[0] = 0xff;
- ucontrol->value.iec958.status[1] = 0xff;
- ucontrol->value.iec958.status[2] = 0xff;
- ucontrol->value.iec958.status[3] = 0xff;
- return 0;
- }
- static struct snd_kcontrol_new snd_trident_spdif_mask __devinitdata =
- {
- .access = SNDRV_CTL_ELEM_ACCESS_READ,
- .iface = SNDRV_CTL_ELEM_IFACE_PCM,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
- .info = snd_trident_spdif_mask_info,
- .get = snd_trident_spdif_mask_get,
- };
- /*---------------------------------------------------------------------------
- snd_trident_spdif_stream
- Description: put/get the S/PDIF stream settings
- ---------------------------------------------------------------------------*/
- static int snd_trident_spdif_stream_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
- uinfo->count = 1;
- return 0;
- }
- static int snd_trident_spdif_stream_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&trident->reg_lock);
- ucontrol->value.iec958.status[0] = (trident->spdif_pcm_bits >> 0) & 0xff;
- ucontrol->value.iec958.status[1] = (trident->spdif_pcm_bits >> 8) & 0xff;
- ucontrol->value.iec958.status[2] = (trident->spdif_pcm_bits >> 16) & 0xff;
- ucontrol->value.iec958.status[3] = (trident->spdif_pcm_bits >> 24) & 0xff;
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- static int snd_trident_spdif_stream_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned int val;
- int change;
- val = (ucontrol->value.iec958.status[0] << 0) |
- (ucontrol->value.iec958.status[1] << 8) |
- (ucontrol->value.iec958.status[2] << 16) |
- (ucontrol->value.iec958.status[3] << 24);
- spin_lock_irq(&trident->reg_lock);
- change = trident->spdif_pcm_bits != val;
- trident->spdif_pcm_bits = val;
- if (trident->spdif != NULL) {
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
- } else {
- outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
- }
- }
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_spdif_stream __devinitdata =
- {
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
- .iface = SNDRV_CTL_ELEM_IFACE_PCM,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
- .info = snd_trident_spdif_stream_info,
- .get = snd_trident_spdif_stream_get,
- .put = snd_trident_spdif_stream_put
- };
- /*---------------------------------------------------------------------------
- snd_trident_ac97_control
- Description: enable/disable rear path for ac97
- ---------------------------------------------------------------------------*/
- #define snd_trident_ac97_control_info snd_ctl_boolean_mono_info
- static int snd_trident_ac97_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned char val;
- spin_lock_irq(&trident->reg_lock);
- val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- ucontrol->value.integer.value[0] = (val & (1 << kcontrol->private_value)) ? 1 : 0;
- spin_unlock_irq(&trident->reg_lock);
- return 0;
- }
- static int snd_trident_ac97_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned char val;
- int change = 0;
- spin_lock_irq(&trident->reg_lock);
- val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- val &= ~(1 << kcontrol->private_value);
- if (ucontrol->value.integer.value[0])
- val |= 1 << kcontrol->private_value;
- change = val != trident->ac97_ctrl;
- trident->ac97_ctrl = val;
- outl(trident->ac97_ctrl = val, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_ac97_rear_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Rear Path",
- .info = snd_trident_ac97_control_info,
- .get = snd_trident_ac97_control_get,
- .put = snd_trident_ac97_control_put,
- .private_value = 4,
- };
- /*---------------------------------------------------------------------------
- snd_trident_vol_control
- Description: wave & music volume control
- ---------------------------------------------------------------------------*/
- static int snd_trident_vol_control_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 2;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 255;
- return 0;
- }
- static int snd_trident_vol_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned int val;
- val = trident->musicvol_wavevol;
- ucontrol->value.integer.value[0] = 255 - ((val >> kcontrol->private_value) & 0xff);
- ucontrol->value.integer.value[1] = 255 - ((val >> (kcontrol->private_value + 8)) & 0xff);
- return 0;
- }
- static const DECLARE_TLV_DB_SCALE(db_scale_gvol, -6375, 25, 0);
- static int snd_trident_vol_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- unsigned int val;
- int change = 0;
- spin_lock_irq(&trident->reg_lock);
- val = trident->musicvol_wavevol;
- val &= ~(0xffff << kcontrol->private_value);
- val |= ((255 - (ucontrol->value.integer.value[0] & 0xff)) |
- ((255 - (ucontrol->value.integer.value[1] & 0xff)) << 8)) << kcontrol->private_value;
- change = val != trident->musicvol_wavevol;
- outl(trident->musicvol_wavevol = val, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_vol_music_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Music Playback Volume",
- .info = snd_trident_vol_control_info,
- .get = snd_trident_vol_control_get,
- .put = snd_trident_vol_control_put,
- .private_value = 16,
- .tlv = { .p = db_scale_gvol },
- };
- static struct snd_kcontrol_new snd_trident_vol_wave_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Wave Playback Volume",
- .info = snd_trident_vol_control_info,
- .get = snd_trident_vol_control_get,
- .put = snd_trident_vol_control_put,
- .private_value = 0,
- .tlv = { .p = db_scale_gvol },
- };
- /*---------------------------------------------------------------------------
- snd_trident_pcm_vol_control
- Description: PCM front volume control
- ---------------------------------------------------------------------------*/
- static int snd_trident_pcm_vol_control_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 255;
- if (trident->device == TRIDENT_DEVICE_ID_SI7018)
- uinfo->value.integer.max = 1023;
- return 0;
- }
- static int snd_trident_pcm_vol_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- ucontrol->value.integer.value[0] = 1023 - mix->vol;
- } else {
- ucontrol->value.integer.value[0] = 255 - (mix->vol>>2);
- }
- return 0;
- }
- static int snd_trident_pcm_vol_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- unsigned int val;
- int change = 0;
- if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- val = 1023 - (ucontrol->value.integer.value[0] & 1023);
- } else {
- val = (255 - (ucontrol->value.integer.value[0] & 255)) << 2;
- }
- spin_lock_irq(&trident->reg_lock);
- change = val != mix->vol;
- mix->vol = val;
- if (mix->voice != NULL)
- snd_trident_write_vol_reg(trident, mix->voice, val);
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_pcm_vol_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "PCM Front Playback Volume",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
- .count = 32,
- .info = snd_trident_pcm_vol_control_info,
- .get = snd_trident_pcm_vol_control_get,
- .put = snd_trident_pcm_vol_control_put,
- /* FIXME: no tlv yet */
- };
- /*---------------------------------------------------------------------------
- snd_trident_pcm_pan_control
- Description: PCM front pan control
- ---------------------------------------------------------------------------*/
- static int snd_trident_pcm_pan_control_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 127;
- return 0;
- }
- static int snd_trident_pcm_pan_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- ucontrol->value.integer.value[0] = mix->pan;
- if (ucontrol->value.integer.value[0] & 0x40) {
- ucontrol->value.integer.value[0] = (0x3f - (ucontrol->value.integer.value[0] & 0x3f));
- } else {
- ucontrol->value.integer.value[0] |= 0x40;
- }
- return 0;
- }
- static int snd_trident_pcm_pan_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- unsigned char val;
- int change = 0;
- if (ucontrol->value.integer.value[0] & 0x40)
- val = ucontrol->value.integer.value[0] & 0x3f;
- else
- val = (0x3f - (ucontrol->value.integer.value[0] & 0x3f)) | 0x40;
- spin_lock_irq(&trident->reg_lock);
- change = val != mix->pan;
- mix->pan = val;
- if (mix->voice != NULL)
- snd_trident_write_pan_reg(trident, mix->voice, val);
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_pcm_pan_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "PCM Pan Playback Control",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
- .count = 32,
- .info = snd_trident_pcm_pan_control_info,
- .get = snd_trident_pcm_pan_control_get,
- .put = snd_trident_pcm_pan_control_put,
- };
- /*---------------------------------------------------------------------------
- snd_trident_pcm_rvol_control
- Description: PCM reverb volume control
- ---------------------------------------------------------------------------*/
- static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 127;
- return 0;
- }
- static int snd_trident_pcm_rvol_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- ucontrol->value.integer.value[0] = 127 - mix->rvol;
- return 0;
- }
- static int snd_trident_pcm_rvol_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- unsigned short val;
- int change = 0;
- val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
- spin_lock_irq(&trident->reg_lock);
- change = val != mix->rvol;
- mix->rvol = val;
- if (mix->voice != NULL)
- snd_trident_write_rvol_reg(trident, mix->voice, val);
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static const DECLARE_TLV_DB_SCALE(db_scale_crvol, -3175, 25, 1);
- static struct snd_kcontrol_new snd_trident_pcm_rvol_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "PCM Reverb Playback Volume",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
- .count = 32,
- .info = snd_trident_pcm_rvol_control_info,
- .get = snd_trident_pcm_rvol_control_get,
- .put = snd_trident_pcm_rvol_control_put,
- .tlv = { .p = db_scale_crvol },
- };
- /*---------------------------------------------------------------------------
- snd_trident_pcm_cvol_control
- Description: PCM chorus volume control
- ---------------------------------------------------------------------------*/
- static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 127;
- return 0;
- }
- static int snd_trident_pcm_cvol_control_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- ucontrol->value.integer.value[0] = 127 - mix->cvol;
- return 0;
- }
- static int snd_trident_pcm_cvol_control_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
- struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)];
- unsigned short val;
- int change = 0;
- val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f);
- spin_lock_irq(&trident->reg_lock);
- change = val != mix->cvol;
- mix->cvol = val;
- if (mix->voice != NULL)
- snd_trident_write_cvol_reg(trident, mix->voice, val);
- spin_unlock_irq(&trident->reg_lock);
- return change;
- }
- static struct snd_kcontrol_new snd_trident_pcm_cvol_control __devinitdata =
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "PCM Chorus Playback Volume",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
- .count = 32,
- .info = snd_trident_pcm_cvol_control_info,
- .get = snd_trident_pcm_cvol_control_get,
- .put = snd_trident_pcm_cvol_control_put,
- .tlv = { .p = db_scale_crvol },
- };
- static void snd_trident_notify_pcm_change1(struct snd_card *card,
- struct snd_kcontrol *kctl,
- int num, int activate)
- {
- struct snd_ctl_elem_id id;
- if (! kctl)
- return;
- if (activate)
- kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- else
- kctl->vd[num].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE |
- SNDRV_CTL_EVENT_MASK_INFO,
- snd_ctl_build_ioff(&id, kctl, num));
- }
- static void snd_trident_notify_pcm_change(struct snd_trident *trident,
- struct snd_trident_pcm_mixer *tmix,
- int num, int activate)
- {
- snd_trident_notify_pcm_change1(trident->card, trident->ctl_vol, num, activate);
- snd_trident_notify_pcm_change1(trident->card, trident->ctl_pan, num, activate);
- snd_trident_notify_pcm_change1(trident->card, trident->ctl_rvol, num, activate);
- snd_trident_notify_pcm_change1(trident->card, trident->ctl_cvol, num, activate);
- }
- static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
- struct snd_trident_voice *voice,
- struct snd_pcm_substream *substream)
- {
- struct snd_trident_pcm_mixer *tmix;
- if (snd_BUG_ON(!trident || !voice || !substream))
- return -EINVAL;
- tmix = &trident->pcm_mixer[substream->number];
- tmix->voice = voice;
- tmix->vol = T4D_DEFAULT_PCM_VOL;
- tmix->pan = T4D_DEFAULT_PCM_PAN;
- tmix->rvol = T4D_DEFAULT_PCM_RVOL;
- tmix->cvol = T4D_DEFAULT_PCM_CVOL;
- snd_trident_notify_pcm_change(trident, tmix, substream->number, 1);
- return 0;
- }
- static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_trident_voice *voice, struct snd_pcm_substream *substream)
- {
- struct snd_trident_pcm_mixer *tmix;
- if (snd_BUG_ON(!trident || !substream))
- return -EINVAL;
- tmix = &trident->pcm_mixer[substream->number];
- tmix->voice = NULL;
- snd_trident_notify_pcm_change(trident, tmix, substream->number, 0);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_mixer
-
- Description: This routine registers the 4DWave device for mixer support.
-
- Parameters: trident - pointer to target device class for 4DWave.
- Returns: None
-
- ---------------------------------------------------------------------------*/
- static int __devinit snd_trident_mixer(struct snd_trident * trident, int pcm_spdif_device)
- {
- struct snd_ac97_template _ac97;
- struct snd_card *card = trident->card;
- struct snd_kcontrol *kctl;
- struct snd_ctl_elem_value *uctl;
- int idx, err, retries = 2;
- static struct snd_ac97_bus_ops ops = {
- .write = snd_trident_codec_write,
- .read = snd_trident_codec_read,
- };
- uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
- if (!uctl)
- return -ENOMEM;
- if ((err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus)) < 0)
- goto __out;
- memset(&_ac97, 0, sizeof(_ac97));
- _ac97.private_data = trident;
- trident->ac97_detect = 1;
- __again:
- if ((err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97)) < 0) {
- if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- if ((err = snd_trident_sis_reset(trident)) < 0)
- goto __out;
- if (retries-- > 0)
- goto __again;
- err = -EIO;
- }
- goto __out;
- }
-
- /* secondary codec? */
- if (trident->device == TRIDENT_DEVICE_ID_SI7018 &&
- (inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0) {
- _ac97.num = 1;
- err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
- if (err < 0)
- snd_printk(KERN_ERR "SI7018: the secondary codec - invalid access\n");
- #if 0 // only for my testing purpose --jk
- {
- struct snd_ac97 *mc97;
- err = snd_ac97_modem(trident->card, &_ac97, &mc97);
- if (err < 0)
- snd_printk(KERN_ERR "snd_ac97_modem returned error %i\n", err);
- }
- #endif
- }
-
- trident->ac97_detect = 0;
- if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
- if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident))) < 0)
- goto __out;
- kctl->put(kctl, uctl);
- if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_music_control, trident))) < 0)
- goto __out;
- kctl->put(kctl, uctl);
- outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
- } else {
- outl(trident->musicvol_wavevol = 0xffff0000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
- }
- for (idx = 0; idx < 32; idx++) {
- struct snd_trident_pcm_mixer *tmix;
-
- tmix = &trident->pcm_mixer[idx];
- tmix->voice = NULL;
- }
- if ((trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident)) == NULL)
- goto __nomem;
- if ((err = snd_ctl_add(card, trident->ctl_vol)))
- goto __out;
-
- if ((trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident)) == NULL)
- goto __nomem;
- if ((err = snd_ctl_add(card, trident->ctl_pan)))
- goto __out;
- if ((trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control, trident)) == NULL)
- goto __nomem;
- if ((err = snd_ctl_add(card, trident->ctl_rvol)))
- goto __out;
- if ((trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control, trident)) == NULL)
- goto __nomem;
- if ((err = snd_ctl_add(card, trident->ctl_cvol)))
- goto __out;
- if (trident->device == TRIDENT_DEVICE_ID_NX) {
- if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident))) < 0)
- goto __out;
- kctl->put(kctl, uctl);
- }
- if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
- kctl = snd_ctl_new1(&snd_trident_spdif_control, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
- if (trident->ac97->ext_id & AC97_EI_SPDIF)
- kctl->id.index++;
- if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF))
- kctl->id.index++;
- idx = kctl->id.index;
- if ((err = snd_ctl_add(card, kctl)) < 0)
- goto __out;
- kctl->put(kctl, uctl);
- kctl = snd_ctl_new1(&snd_trident_spdif_default, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
- kctl->id.index = idx;
- kctl->id.device = pcm_spdif_device;
- if ((err = snd_ctl_add(card, kctl)) < 0)
- goto __out;
- kctl = snd_ctl_new1(&snd_trident_spdif_mask, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
- kctl->id.index = idx;
- kctl->id.device = pcm_spdif_device;
- if ((err = snd_ctl_add(card, kctl)) < 0)
- goto __out;
- kctl = snd_ctl_new1(&snd_trident_spdif_stream, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
- kctl->id.index = idx;
- kctl->id.device = pcm_spdif_device;
- if ((err = snd_ctl_add(card, kctl)) < 0)
- goto __out;
- trident->spdif_pcm_ctl = kctl;
- }
- err = 0;
- goto __out;
- __nomem:
- err = -ENOMEM;
- __out:
- kfree(uctl);
- return err;
- }
- /*
- * gameport interface
- */
- #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
- static unsigned char snd_trident_gameport_read(struct gameport *gameport)
- {
- struct snd_trident *chip = gameport_get_port_data(gameport);
- if (snd_BUG_ON(!chip))
- return 0;
- return inb(TRID_REG(chip, GAMEPORT_LEGACY));
- }
- static void snd_trident_gameport_trigger(struct gameport *gameport)
- {
- struct snd_trident *chip = gameport_get_port_data(gameport);
- if (snd_BUG_ON(!chip))
- return;
- outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY));
- }
- static int snd_trident_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
- {
- struct snd_trident *chip = gameport_get_port_data(gameport);
- int i;
- if (snd_BUG_ON(!chip))
- return 0;
- *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf;
- for (i = 0; i < 4; i++) {
- axes[i] = inw(TRID_REG(chip, GAMEPORT_AXES + i * 2));
- if (axes[i] == 0xffff) axes[i] = -1;
- }
-
- return 0;
- }
- static int snd_trident_gameport_open(struct gameport *gameport, int mode)
- {
- struct snd_trident *chip = gameport_get_port_data(gameport);
- if (snd_BUG_ON(!chip))
- return 0;
- switch (mode) {
- case GAMEPORT_MODE_COOKED:
- outb(GAMEPORT_MODE_ADC, TRID_REG(chip, GAMEPORT_GCR));
- msleep(20);
- return 0;
- case GAMEPORT_MODE_RAW:
- outb(0, TRID_REG(chip, GAMEPORT_GCR));
- return 0;
- default:
- return -1;
- }
- }
- int __devinit snd_trident_create_gameport(struct snd_trident *chip)
- {
- struct gameport *gp;
- chip->gameport = gp = gameport_allocate_port();
- if (!gp) {
- printk(KERN_ERR "trident: cannot allocate memory for gameport\n");
- return -ENOMEM;
- }
- gameport_set_name(gp, "Trident 4DWave");
- gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
- gameport_set_dev_parent(gp, &chip->pci->dev);
- gameport_set_port_data(gp, chip);
- gp->fuzz = 64;
- gp->read = snd_trident_gameport_read;
- gp->trigger = snd_trident_gameport_trigger;
- gp->cooked_read = snd_trident_gameport_cooked_read;
- gp->open = snd_trident_gameport_open;
- gameport_register_port(gp);
- return 0;
- }
- static inline void snd_trident_free_gameport(struct snd_trident *chip)
- {
- if (chip->gameport) {
- gameport_unregister_port(chip->gameport);
- chip->gameport = NULL;
- }
- }
- #else
- int __devinit snd_trident_create_gameport(struct snd_trident *chip) { return -ENOSYS; }
- static inline void snd_trident_free_gameport(struct snd_trident *chip) { }
- #endif /* CONFIG_GAMEPORT */
- /*
- * delay for 1 tick
- */
- static inline void do_delay(struct snd_trident *chip)
- {
- schedule_timeout_uninterruptible(1);
- }
- /*
- * SiS reset routine
- */
- static int snd_trident_sis_reset(struct snd_trident *trident)
- {
- unsigned long end_time;
- unsigned int i;
- int r;
- r = trident->in_suspend ? 0 : 2; /* count of retries */
- __si7018_retry:
- pci_write_config_byte(trident->pci, 0x46, 0x04); /* SOFTWARE RESET */
- udelay(100);
- pci_write_config_byte(trident->pci, 0x46, 0x00);
- udelay(100);
- /* disable AC97 GPIO interrupt */
- outb(0x00, TRID_REG(trident, SI_AC97_GPIO));
- /* initialize serial interface, force cold reset */
- i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET;
- outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- udelay(1000);
- /* remove cold reset */
- i &= ~COLD_RESET;
- outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- udelay(2000);
- /* wait, until the codec is ready */
- end_time = (jiffies + (HZ * 3) / 4) + 1;
- do {
- if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0)
- goto __si7018_ok;
- do_delay(trident);
- } while (time_after_eq(end_time, jiffies));
- snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
- if (r-- > 0) {
- end_time = jiffies + HZ;
- do {
- do_delay(trident);
- } while (time_after_eq(end_time, jiffies));
- goto __si7018_retry;
- }
- __si7018_ok:
- /* wait for the second codec */
- do {
- if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_SECONDARY_READY) != 0)
- break;
- do_delay(trident);
- } while (time_after_eq(end_time, jiffies));
- /* enable 64 channel mode */
- outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR));
- return 0;
- }
- /*
- * /proc interface
- */
- static void snd_trident_proc_read(struct snd_info_entry *entry,
- struct snd_info_buffer *buffer)
- {
- struct snd_trident *trident = entry->private_data;
- char *s;
- switch (trident->device) {
- case TRIDENT_DEVICE_ID_SI7018:
- s = "SiS 7018 Audio";
- break;
- case TRIDENT_DEVICE_ID_DX:
- s = "Trident 4DWave PCI DX";
- break;
- case TRIDENT_DEVICE_ID_NX:
- s = "Trident 4DWave PCI NX";
- break;
- default:
- s = "???";
- }
- snd_iprintf(buffer, "%s\n\n", s);
- snd_iprintf(buffer, "Spurious IRQs : %d\n", trident->spurious_irq_count);
- snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta);
- if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018)
- snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", trident->spdif_ctrl == 0x28 ? "on" : "off");
- if (trident->device == TRIDENT_DEVICE_ID_NX) {
- snd_iprintf(buffer, "Rear Speakers : %s\n", trident->ac97_ctrl & 0x00000010 ? "on" : "off");
- if (trident->tlb.entries) {
- snd_iprintf(buffer,"\nVirtual Memory\n");
- snd_iprintf(buffer, "Memory Maximum : %d\n", trident->tlb.memhdr->size);
- snd_iprintf(buffer, "Memory Used : %d\n", trident->tlb.memhdr->used);
- snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr));
- }
- }
- }
- static void __devinit snd_trident_proc_init(struct snd_trident * trident)
- {
- struct snd_info_entry *entry;
- const char *s = "trident";
-
- if (trident->device == TRIDENT_DEVICE_ID_SI7018)
- s = "sis7018";
- if (! snd_card_proc_new(trident->card, s, &entry))
- snd_info_set_text_ops(entry, trident, snd_trident_proc_read);
- }
- static int snd_trident_dev_free(struct snd_device *device)
- {
- struct snd_trident *trident = device->device_data;
- return snd_trident_free(trident);
- }
- /*---------------------------------------------------------------------------
- snd_trident_tlb_alloc
-
- Description: Allocate and set up the TLB page table on 4D NX.
- Each entry has 4 bytes (physical PCI address).
-
- Parameters: trident - pointer to target device class for 4DWave.
- Returns: 0 or negative error code
-
- ---------------------------------------------------------------------------*/
- static int __devinit snd_trident_tlb_alloc(struct snd_trident *trident)
- {
- int i;
- /* TLB array must be aligned to 16kB !!! so we allocate
- 32kB region and correct offset when necessary */
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
- 2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) {
- snd_printk(KERN_ERR "trident: unable to allocate TLB buffer\n");
- return -ENOMEM;
- }
- trident->tlb.entries = (unsigned int*)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4);
- trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer.addr, SNDRV_TRIDENT_MAX_PAGES * 4);
- /* allocate shadow TLB page table (virtual addresses) */
- trident->tlb.shadow_entries = vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long));
- if (trident->tlb.shadow_entries == NULL) {
- snd_printk(KERN_ERR "trident: unable to allocate shadow TLB entries\n");
- return -ENOMEM;
- }
- /* allocate and setup silent page and initialise TLB entries */
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
- SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) {
- snd_printk(KERN_ERR "trident: unable to allocate silent page\n");
- return -ENOMEM;
- }
- memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
- for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) {
- trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1));
- trident->tlb.shadow_entries[i] = (unsigned long)trident->tlb.silent_page.area;
- }
- /* use emu memory block manager code to manage tlb page allocation */
- trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES);
- if (trident->tlb.memhdr == NULL)
- return -ENOMEM;
- trident->tlb.memhdr->block_extra_size = sizeof(struct snd_trident_memblk_arg);
- return 0;
- }
- /*
- * initialize 4D DX chip
- */
- static void snd_trident_stop_all_voices(struct snd_trident *trident)
- {
- outl(0xffffffff, TRID_REG(trident, T4D_STOP_A));
- outl(0xffffffff, TRID_REG(trident, T4D_STOP_B));
- outl(0, TRID_REG(trident, T4D_AINTEN_A));
- outl(0, TRID_REG(trident, T4D_AINTEN_B));
- }
- static int snd_trident_4d_dx_init(struct snd_trident *trident)
- {
- struct pci_dev *pci = trident->pci;
- unsigned long end_time;
- /* reset the legacy configuration and whole audio/wavetable block */
- pci_write_config_dword(pci, 0x40, 0); /* DDMA */
- pci_write_config_byte(pci, 0x44, 0); /* ports */
- pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */
- pci_write_config_byte(pci, 0x46, 4); /* reset */
- udelay(100);
- pci_write_config_byte(pci, 0x46, 0); /* release reset */
- udelay(100);
-
- /* warm reset of the AC'97 codec */
- outl(0x00000001, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
- udelay(100);
- outl(0x00000000, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
- /* DAC on, disable SB IRQ and try to force ADC valid signal */
- trident->ac97_ctrl = 0x0000004a;
- outl(trident->ac97_ctrl, TRID_REG(trident, DX_ACR2_AC97_COM_STAT));
- /* wait, until the codec is ready */
- end_time = (jiffies + (HZ * 3) / 4) + 1;
- do {
- if ((inl(TRID_REG(trident, DX_ACR2_AC97_COM_STAT)) & 0x0010) != 0)
- goto __dx_ok;
- do_delay(trident);
- } while (time_after_eq(end_time, jiffies));
- snd_printk(KERN_ERR "AC'97 codec ready error\n");
- return -EIO;
- __dx_ok:
- snd_trident_stop_all_voices(trident);
- return 0;
- }
- /*
- * initialize 4D NX chip
- */
- static int snd_trident_4d_nx_init(struct snd_trident *trident)
- {
- struct pci_dev *pci = trident->pci;
- unsigned long end_time;
- /* reset the legacy configuration and whole audio/wavetable block */
- pci_write_config_dword(pci, 0x40, 0); /* DDMA */
- pci_write_config_byte(pci, 0x44, 0); /* ports */
- pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */
- pci_write_config_byte(pci, 0x46, 1); /* reset */
- udelay(100);
- pci_write_config_byte(pci, 0x46, 0); /* release reset */
- udelay(100);
- /* warm reset of the AC'97 codec */
- outl(0x00000001, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- udelay(100);
- outl(0x00000000, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- /* wait, until the codec is ready */
- end_time = (jiffies + (HZ * 3) / 4) + 1;
- do {
- if ((inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)) & 0x0008) != 0)
- goto __nx_ok;
- do_delay(trident);
- } while (time_after_eq(end_time, jiffies));
- snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)));
- return -EIO;
- __nx_ok:
- /* DAC on */
- trident->ac97_ctrl = 0x00000002;
- outl(trident->ac97_ctrl, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
- /* disable SB IRQ */
- outl(NX_SB_IRQ_DISABLE, TRID_REG(trident, T4D_MISCINT));
- snd_trident_stop_all_voices(trident);
- if (trident->tlb.entries != NULL) {
- unsigned int i;
- /* enable virtual addressing via TLB */
- i = trident->tlb.entries_dmaaddr;
- i |= 0x00000001;
- outl(i, TRID_REG(trident, NX_TLBC));
- } else {
- outl(0, TRID_REG(trident, NX_TLBC));
- }
- /* initialize S/PDIF */
- outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
- outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- return 0;
- }
- /*
- * initialize sis7018 chip
- */
- static int snd_trident_sis_init(struct snd_trident *trident)
- {
- int err;
- if ((err = snd_trident_sis_reset(trident)) < 0)
- return err;
- snd_trident_stop_all_voices(trident);
- /* initialize S/PDIF */
- outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_create
-
- Description: This routine will create the device specific class for
- the 4DWave card. It will also perform basic initialization.
-
- Parameters: card - which card to create
- pci - interface to PCI bus resource info
- dma1ptr - playback dma buffer
- dma2ptr - capture dma buffer
- irqptr - interrupt resource info
- Returns: 4DWave device class private data
-
- ---------------------------------------------------------------------------*/
- int __devinit snd_trident_create(struct snd_card *card,
- struct pci_dev *pci,
- int pcm_streams,
- int pcm_spdif_device,
- int max_wavetable_size,
- struct snd_trident ** rtrident)
- {
- struct snd_trident *trident;
- int i, err;
- struct snd_trident_voice *voice;
- struct snd_trident_pcm_mixer *tmix;
- static struct snd_device_ops ops = {
- .dev_free = snd_trident_dev_free,
- };
- *rtrident = NULL;
- /* enable PCI device */
- if ((err = pci_enable_device(pci)) < 0)
- return err;
- /* check, if we can restrict PCI DMA transfers to 30 bits */
- if (pci_set_dma_mask(pci, DMA_BIT_MASK(30)) < 0 ||
- pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(30)) < 0) {
- snd_printk(KERN_ERR "architecture does not support 30bit PCI busmaster DMA\n");
- pci_disable_device(pci);
- return -ENXIO;
- }
-
- trident = kzalloc(sizeof(*trident), GFP_KERNEL);
- if (trident == NULL) {
- pci_disable_device(pci);
- return -ENOMEM;
- }
- trident->device = (pci->vendor << 16) | pci->device;
- trident->card = card;
- trident->pci = pci;
- spin_lock_init(&trident->reg_lock);
- spin_lock_init(&trident->event_lock);
- spin_lock_init(&trident->voice_alloc);
- if (pcm_streams < 1)
- pcm_streams = 1;
- if (pcm_streams > 32)
- pcm_streams = 32;
- trident->ChanPCM = pcm_streams;
- if (max_wavetable_size < 0 )
- max_wavetable_size = 0;
- trident->synth.max_size = max_wavetable_size * 1024;
- trident->irq = -1;
- trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE);
- pci_set_master(pci);
- if ((err = pci_request_regions(pci, "Trident Audio")) < 0) {
- kfree(trident);
- pci_disable_device(pci);
- return err;
- }
- trident->port = pci_resource_start(pci, 0);
- if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED,
- "Trident Audio", trident)) {
- snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
- snd_trident_free(trident);
- return -EBUSY;
- }
- trident->irq = pci->irq;
- /* allocate 16k-aligned TLB for NX cards */
- trident->tlb.entries = NULL;
- trident->tlb.buffer.area = NULL;
- if (trident->device == TRIDENT_DEVICE_ID_NX) {
- if ((err = snd_trident_tlb_alloc(trident)) < 0) {
- snd_trident_free(trident);
- return err;
- }
- }
- trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
- /* initialize chip */
- switch (trident->device) {
- case TRIDENT_DEVICE_ID_DX:
- err = snd_trident_4d_dx_init(trident);
- break;
- case TRIDENT_DEVICE_ID_NX:
- err = snd_trident_4d_nx_init(trident);
- break;
- case TRIDENT_DEVICE_ID_SI7018:
- err = snd_trident_sis_init(trident);
- break;
- default:
- snd_BUG();
- break;
- }
- if (err < 0) {
- snd_trident_free(trident);
- return err;
- }
- if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, trident, &ops)) < 0) {
- snd_trident_free(trident);
- return err;
- }
- if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
- return err;
-
- /* initialise synth voices */
- for (i = 0; i < 64; i++) {
- voice = &trident->synth.voices[i];
- voice->number = i;
- voice->trident = trident;
- }
- /* initialize pcm mixer entries */
- for (i = 0; i < 32; i++) {
- tmix = &trident->pcm_mixer[i];
- tmix->vol = T4D_DEFAULT_PCM_VOL;
- tmix->pan = T4D_DEFAULT_PCM_PAN;
- tmix->rvol = T4D_DEFAULT_PCM_RVOL;
- tmix->cvol = T4D_DEFAULT_PCM_CVOL;
- }
- snd_trident_enable_eso(trident);
- snd_trident_proc_init(trident);
- snd_card_set_dev(card, &pci->dev);
- *rtrident = trident;
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_free
-
- Description: This routine will free the device specific class for
- the 4DWave card.
-
- Parameters: trident - device specific private data for 4DWave card
- Returns: None.
-
- ---------------------------------------------------------------------------*/
- static int snd_trident_free(struct snd_trident *trident)
- {
- snd_trident_free_gameport(trident);
- snd_trident_disable_eso(trident);
- // Disable S/PDIF out
- if (trident->device == TRIDENT_DEVICE_ID_NX)
- outb(0x00, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
- else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
- outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
- }
- if (trident->irq >= 0)
- free_irq(trident->irq, trident);
- if (trident->tlb.buffer.area) {
- outl(0, TRID_REG(trident, NX_TLBC));
- if (trident->tlb.memhdr)
- snd_util_memhdr_free(trident->tlb.memhdr);
- if (trident->tlb.silent_page.area)
- snd_dma_free_pages(&trident->tlb.silent_page);
- vfree(trident->tlb.shadow_entries);
- snd_dma_free_pages(&trident->tlb.buffer);
- }
- pci_release_regions(trident->pci);
- pci_disable_device(trident->pci);
- kfree(trident);
- return 0;
- }
- /*---------------------------------------------------------------------------
- snd_trident_interrupt
-
- Description: ISR for Trident 4DWave device
-
- Parameters: trident - device specific private data for 4DWave card
- Problems: It seems that Trident chips generates interrupts more than
- one time in special cases. The spurious interrupts are
- detected via sample timer (T4D_STIMER) and computing
- corresponding delta value. The limits are detected with
- the method try & fail so it is possible that it won't
- work on all computers. [jaroslav]
- Returns: None.
-
- ---------------------------------------------------------------------------*/
- static irqreturn_t snd_trident_interrupt(int irq, void *dev_id)
- {
- struct snd_trident *trident = dev_id;
- unsigned int audio_int, chn_int, stimer, channel, mask, tmp;
- int delta;
- struct snd_trident_voice *voice;
- audio_int = inl(TRID_REG(trident, T4D_MISCINT));
- if ((audio_int & (ADDRESS_IRQ|MPU401_IRQ)) == 0)
- return IRQ_NONE;
- if (audio_int & ADDRESS_IRQ) {
- // get interrupt status for all channels
- spin_lock(&trident->reg_lock);
- stimer = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff;
- chn_int = inl(TRID_REG(trident, T4D_AINT_A));
- if (chn_int == 0)
- goto __skip1;
- outl(chn_int, TRID_REG(trident, T4D_AINT_A)); /* ack */
- __skip1:
- chn_int = inl(TRID_REG(trident, T4D_AINT_B));
- if (chn_int == 0)
- goto __skip2;
- for (channel = 63; channel >= 32; channel--) {
- mask = 1 << (channel&0x1f);
- if ((chn_int & mask) == 0)
- continue;
- voice = &trident->synth.voices[channel];
- if (!voice->pcm || voice->substream == NULL) {
- outl(mask, TRID_REG(trident, T4D_STOP_B));
- continue;
- }
- delta = (int)stimer - (int)voice->stimer;
- if (delta < 0)
- delta = -delta;
- if ((unsigned int)delta < voice->spurious_threshold) {
- /* do some statistics here */
- trident->spurious_irq_count++;
- if (trident->spurious_irq_max_delta < (unsigned int)delta)
- trident->spurious_irq_max_delta = delta;
- continue;
- }
- voice->stimer = stimer;
- if (voice->isync) {
- if (!voice->isync3) {
- tmp = inw(TRID_REG(trident, T4D_SBBL_SBCL));
- if (trident->bDMAStart & 0x40)
- tmp >>= 1;
- if (tmp > 0)
- tmp = voice->isync_max - tmp;
- } else {
- tmp = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff;
- }
- if (tmp < voice->isync_mark) {
- if (tmp > 0x10)
- tmp = voice->isync_ESO - 7;
- else
- tmp = voice->isync_ESO + 2;
- /* update ESO for IRQ voice to preserve sync */
- snd_trident_stop_voice(trident, voice->number);
- snd_trident_write_eso_reg(trident, voice, tmp);
- snd_trident_start_voice(trident, voice->number);
- }
- } else if (voice->isync2) {
- voice->isync2 = 0;
- /* write original ESO and update CSO for IRQ voice to preserve sync */
- snd_trident_stop_voice(trident, voice->number);
- snd_trident_write_cso_reg(trident, voice, voice->isync_mark);
- snd_trident_write_eso_reg(trident, voice, voice->ESO);
- snd_trident_start_voice(trident, voice->number);
- }
- #if 0
- if (voice->extra) {
- /* update CSO for extra voice to preserve sync */
- snd_trident_stop_voice(trident, voice->extra->number);
- snd_trident_write_cso_reg(trident, voice->extra, 0);
- snd_trident_start_voice(trident, voice->extra->number);
- }
- #endif
- spin_unlock(&trident->reg_lock);
- snd_pcm_period_elapsed(voice->substream);
- spin_lock(&trident->reg_lock);
- }
- outl(chn_int, TRID_REG(trident, T4D_AINT_B)); /* ack */
- __skip2:
- spin_unlock(&trident->reg_lock);
- }
- if (audio_int & MPU401_IRQ) {
- if (trident->rmidi) {
- snd_mpu401_uart_interrupt(irq, trident->rmidi->private_data);
- } else {
- inb(TRID_REG(trident, T4D_MPUR0));
- }
- }
- // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
- return IRQ_HANDLED;
- }
- struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type, int client, int port)
- {
- struct snd_trident_voice *pvoice;
- unsigned long flags;
- int idx;
- spin_lock_irqsave(&trident->voice_alloc, flags);
- if (type == SNDRV_TRIDENT_VOICE_TYPE_PCM) {
- idx = snd_trident_allocate_pcm_channel(trident);
- if(idx < 0) {
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- return NULL;
- }
- pvoice = &trident->synth.voices[idx];
- pvoice->use = 1;
- pvoice->pcm = 1;
- pvoice->capture = 0;
- pvoice->spdif = 0;
- pvoice->memblk = NULL;
- pvoice->substream = NULL;
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- return pvoice;
- }
- if (type == SNDRV_TRIDENT_VOICE_TYPE_SYNTH) {
- idx = snd_trident_allocate_synth_channel(trident);
- if(idx < 0) {
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- return NULL;
- }
- pvoice = &trident->synth.voices[idx];
- pvoice->use = 1;
- pvoice->synth = 1;
- pvoice->client = client;
- pvoice->port = port;
- pvoice->memblk = NULL;
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- return pvoice;
- }
- if (type == SNDRV_TRIDENT_VOICE_TYPE_MIDI) {
- }
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- return NULL;
- }
- EXPORT_SYMBOL(snd_trident_alloc_voice);
- void snd_trident_free_voice(struct snd_trident * trident, struct snd_trident_voice *voice)
- {
- unsigned long flags;
- void (*private_free)(struct snd_trident_voice *);
- void *private_data;
- if (voice == NULL || !voice->use)
- return;
- snd_trident_clear_voices(trident, voice->number, voice->number);
- spin_lock_irqsave(&trident->voice_alloc, flags);
- private_free = voice->private_free;
- private_data = voice->private_data;
- voice->private_free = NULL;
- voice->private_data = NULL;
- if (voice->pcm)
- snd_trident_free_pcm_channel(trident, voice->number);
- if (voice->synth)
- snd_trident_free_synth_channel(trident, voice->number);
- voice->use = voice->pcm = voice->synth = voice->midi = 0;
- voice->capture = voice->spdif = 0;
- voice->sample_ops = NULL;
- voice->substream = NULL;
- voice->extra = NULL;
- spin_unlock_irqrestore(&trident->voice_alloc, flags);
- if (private_free)
- private_free(voice);
- }
- EXPORT_SYMBOL(snd_trident_free_voice);
- static void snd_trident_clear_voices(struct snd_trident * trident, unsigned short v_min, unsigned short v_max)
- {
- unsigned int i, val, mask[2] = { 0, 0 };
- if (snd_BUG_ON(v_min > 63 || v_max > 63))
- return;
- for (i = v_min; i <= v_max; i++)
- mask[i >> 5] |= 1 << (i & 0x1f);
- if (mask[0]) {
- outl(mask[0], TRID_REG(trident, T4D_STOP_A));
- val = inl(TRID_REG(trident, T4D_AINTEN_A));
- outl(val & ~mask[0], TRID_REG(trident, T4D_AINTEN_A));
- }
- if (mask[1]) {
- outl(mask[1], TRID_REG(trident, T4D_STOP_B));
- val = inl(TRID_REG(trident, T4D_AINTEN_B));
- outl(val & ~mask[1], TRID_REG(trident, T4D_AINTEN_B));
- }
- }
- #ifdef CONFIG_PM
- int snd_trident_suspend(struct pci_dev *pci, pm_message_t state)
- {
- struct snd_card *card = pci_get_drvdata(pci);
- struct snd_trident *trident = card->private_data;
- trident->in_suspend = 1;
- snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
- snd_pcm_suspend_all(trident->pcm);
- snd_pcm_suspend_all(trident->foldback);
- snd_pcm_suspend_all(trident->spdif);
- snd_ac97_suspend(trident->ac97);
- snd_ac97_suspend(trident->ac97_sec);
- pci_disable_device(pci);
- pci_save_state(pci);
- pci_set_power_state(pci, pci_choose_state(pci, state));
- return 0;
- }
- int snd_trident_resume(struct pci_dev *pci)
- {
- struct snd_card *card = pci_get_drvdata(pci);
- struct snd_trident *trident = card->private_data;
- pci_set_power_state(pci, PCI_D0);
- pci_restore_state(pci);
- if (pci_enable_device(pci) < 0) {
- printk(KERN_ERR "trident: pci_enable_device failed, "
- "disabling device\n");
- snd_card_disconnect(card);
- return -EIO;
- }
- pci_set_master(pci);
- switch (trident->device) {
- case TRIDENT_DEVICE_ID_DX:
- snd_trident_4d_dx_init(trident);
- break;
- case TRIDENT_DEVICE_ID_NX:
- snd_trident_4d_nx_init(trident);
- break;
- case TRIDENT_DEVICE_ID_SI7018:
- snd_trident_sis_init(trident);
- break;
- }
- snd_ac97_resume(trident->ac97);
- snd_ac97_resume(trident->ac97_sec);
- /* restore some registers */
- outl(trident->musicvol_wavevol, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
- snd_trident_enable_eso(trident);
- snd_power_change_state(card, SNDRV_CTL_POWER_D0);
- trident->in_suspend = 0;
- return 0;
- }
- #endif /* CONFIG_PM */
|