hdspm.c 185 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998
  1. /*
  2. * ALSA driver for RME Hammerfall DSP MADI audio interface(s)
  3. *
  4. * Copyright (c) 2003 Winfried Ritsch (IEM)
  5. * code based on hdsp.c Paul Davis
  6. * Marcus Andersson
  7. * Thomas Charbonnel
  8. * Modified 2006-06-01 for AES32 support by Remy Bruno
  9. * <remy.bruno@trinnov.com>
  10. *
  11. * Modified 2009-04-13 for proper metering by Florian Faber
  12. * <faber@faberman.de>
  13. *
  14. * Modified 2009-04-14 for native float support by Florian Faber
  15. * <faber@faberman.de>
  16. *
  17. * Modified 2009-04-26 fixed bug in rms metering by Florian Faber
  18. * <faber@faberman.de>
  19. *
  20. * Modified 2009-04-30 added hw serial number support by Florian Faber
  21. *
  22. * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth
  23. *
  24. * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth
  25. *
  26. * This program is free software; you can redistribute it and/or modify
  27. * it under the terms of the GNU General Public License as published by
  28. * the Free Software Foundation; either version 2 of the License, or
  29. * (at your option) any later version.
  30. *
  31. * This program is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. * GNU General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  39. *
  40. */
  41. /* ************* Register Documentation *******************************************************
  42. *
  43. * Work in progress! Documentation is based on the code in this file.
  44. *
  45. * --------- HDSPM_controlRegister ---------
  46. * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte
  47. * :||||.||||:||||.||||:||||.||||:||||.||||:
  48. * :3322.2222:2222.1111:1111.1100:0000.0000: bit number
  49. * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31
  50. * :||||.||||:||||.||||:||||.||||:||||.||||:
  51. * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
  52. * : . : . : . : x . : HDSPM_AudioInterruptEnable \_ setting both bits
  53. * : . : . : . : . x: HDSPM_Start / enables audio IO
  54. * : . : . : . : x. : HDSPM_ClockModeMaster - 1: Master, 0: Slave
  55. * : . : . : . : .210 : HDSPM_LatencyMask - 3 Bit value for latency
  56. * : . : . : . : . : 0:64, 1:128, 2:256, 3:512,
  57. * : . : . : . : . : 4:1024, 5:2048, 6:4096, 7:8192
  58. * :x . : . : . x:xx . : HDSPM_FrequencyMask
  59. * : . : . : . :10 . : HDSPM_Frequency1|HDSPM_Frequency0: 1=32K,2=44.1K,3=48K,0=??
  60. * : . : . : . x: . : <MADI> HDSPM_DoubleSpeed
  61. * :x . : . : . : . : <MADI> HDSPM_QuadSpeed
  62. * : . 3 : . 10: 2 . : . : HDSPM_SyncRefMask :
  63. * : . : . x: . : . : HDSPM_SyncRef0
  64. * : . : . x : . : . : HDSPM_SyncRef1
  65. * : . : . : x . : . : <AES32> HDSPM_SyncRef2
  66. * : . x : . : . : . : <AES32> HDSPM_SyncRef3
  67. * : . : . 10: . : . : <MADI> sync ref: 0:WC, 1:Madi, 2:TCO, 3:SyncIn
  68. * : . 3 : . 10: 2 . : . : <AES32> 0:WC, 1:AES1 ... 8:AES8, 9: TCO, 10:SyncIn?
  69. * : . x : . : . : . : <MADIe> HDSPe_FLOAT_FORMAT
  70. * : . : . : x . : . : <MADI> HDSPM_InputSelect0 : 0=optical,1=coax
  71. * : . : . :x . : . : <MADI> HDSPM_InputSelect1
  72. * : . : .x : . : . : <MADI> HDSPM_clr_tms
  73. * : . : . : . x : . : <MADI> HDSPM_TX_64ch
  74. * : . : . : . x : . : <AES32> HDSPM_Emphasis
  75. * : . : . : .x : . : <MADI> HDSPM_AutoInp
  76. * : . : . x : . : . : <MADI> HDSPM_SMUX
  77. * : . : .x : . : . : <MADI> HDSPM_clr_tms
  78. * : . : x. : . : . : <MADI> HDSPM_taxi_reset
  79. * : . x: . : . : . : <MADI> HDSPM_LineOut
  80. * : . x: . : . : . : <AES32> ??????????????????
  81. * : . : x. : . : . : <AES32> HDSPM_WCK48
  82. * : . : . : .x : . : <AES32> HDSPM_Dolby
  83. * : . : x . : . : . : HDSPM_Midi0InterruptEnable
  84. * : . :x . : . : . : HDSPM_Midi1InterruptEnable
  85. * : . : x . : . : . : HDSPM_Midi2InterruptEnable
  86. * : . x : . : . : . : <MADI> HDSPM_Midi3InterruptEnable
  87. * : . x : . : . : . : <AES32> HDSPM_DS_DoubleWire
  88. * : .x : . : . : . : <AES32> HDSPM_QS_DoubleWire
  89. * : x. : . : . : . : <AES32> HDSPM_QS_QuadWire
  90. * : . : . : . x : . : <AES32> HDSPM_Professional
  91. * : x . : . : . : . : HDSPM_wclk_sel
  92. * : . : . : . : . :
  93. * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte
  94. * :||||.||||:||||.||||:||||.||||:||||.||||:
  95. * :3322.2222:2222.1111:1111.1100:0000.0000: bit number
  96. * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31
  97. * :||||.||||:||||.||||:||||.||||:||||.||||:
  98. * :8421.8421:8421.8421:8421.8421:8421.8421:hex digit
  99. *
  100. *
  101. *
  102. * AIO / RayDAT only
  103. *
  104. * ------------ HDSPM_WR_SETTINGS ----------
  105. * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte
  106. * :1098.7654:3210.9876:5432.1098:7654.3210:
  107. * :||||.||||:||||.||||:||||.||||:||||.||||: bit number
  108. * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31
  109. * :||||.||||:||||.||||:||||.||||:||||.||||:
  110. * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
  111. * : . : . : . : . x: HDSPM_c0Master 1: Master, 0: Slave
  112. * : . : . : . : . x : HDSPM_c0_SyncRef0
  113. * : . : . : . : . x : HDSPM_c0_SyncRef1
  114. * : . : . : . : .x : HDSPM_c0_SyncRef2
  115. * : . : . : . : x. : HDSPM_c0_SyncRef3
  116. * : . : . : . : 3.210 : HDSPM_c0_SyncRefMask:
  117. * : . : . : . : . : RayDat: 0:WC, 1:AES, 2:SPDIF, 3..6: ADAT1..4,
  118. * : . : . : . : . : 9:TCO, 10:SyncIn
  119. * : . : . : . : . : AIO: 0:WC, 1:AES, 2: SPDIF, 3: ATAT,
  120. * : . : . : . : . : 9:TCO, 10:SyncIn
  121. * : . : . : . : . :
  122. * : . : . : . : . :
  123. * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte
  124. * :1098.7654:3210.9876:5432.1098:7654.3210:
  125. * :||||.||||:||||.||||:||||.||||:||||.||||: bit number
  126. * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31
  127. * :||||.||||:||||.||||:||||.||||:||||.||||:
  128. * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
  129. *
  130. */
  131. #include <linux/init.h>
  132. #include <linux/delay.h>
  133. #include <linux/interrupt.h>
  134. #include <linux/module.h>
  135. #include <linux/slab.h>
  136. #include <linux/pci.h>
  137. #include <linux/math64.h>
  138. #include <linux/io.h>
  139. #include <linux/nospec.h>
  140. #include <sound/core.h>
  141. #include <sound/control.h>
  142. #include <sound/pcm.h>
  143. #include <sound/pcm_params.h>
  144. #include <sound/info.h>
  145. #include <sound/asoundef.h>
  146. #include <sound/rawmidi.h>
  147. #include <sound/hwdep.h>
  148. #include <sound/initval.h>
  149. #include <sound/hdspm.h>
  150. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  151. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  152. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
  153. module_param_array(index, int, NULL, 0444);
  154. MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
  155. module_param_array(id, charp, NULL, 0444);
  156. MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
  157. module_param_array(enable, bool, NULL, 0444);
  158. MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
  159. MODULE_AUTHOR
  160. (
  161. "Winfried Ritsch <ritsch_AT_iem.at>, "
  162. "Paul Davis <paul@linuxaudiosystems.com>, "
  163. "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, "
  164. "Remy Bruno <remy.bruno@trinnov.com>, "
  165. "Florian Faber <faberman@linuxproaudio.org>, "
  166. "Adrian Knoth <adi@drcomp.erfurt.thur.de>"
  167. );
  168. MODULE_DESCRIPTION("RME HDSPM");
  169. MODULE_LICENSE("GPL");
  170. MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
  171. /* --- Write registers. ---
  172. These are defined as byte-offsets from the iobase value. */
  173. #define HDSPM_WR_SETTINGS 0
  174. #define HDSPM_outputBufferAddress 32
  175. #define HDSPM_inputBufferAddress 36
  176. #define HDSPM_controlRegister 64
  177. #define HDSPM_interruptConfirmation 96
  178. #define HDSPM_control2Reg 256 /* not in specs ???????? */
  179. #define HDSPM_freqReg 256 /* for setting arbitrary clock values (DDS feature) */
  180. #define HDSPM_midiDataOut0 352 /* just believe in old code */
  181. #define HDSPM_midiDataOut1 356
  182. #define HDSPM_eeprom_wr 384 /* for AES32 */
  183. /* DMA enable for 64 channels, only Bit 0 is relevant */
  184. #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
  185. #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
  186. /* 16 page addresses for each of the 64 channels DMA buffer in and out
  187. (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */
  188. #define HDSPM_pageAddressBufferOut 8192
  189. #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4)
  190. #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */
  191. #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */
  192. /* --- Read registers. ---
  193. These are defined as byte-offsets from the iobase value */
  194. #define HDSPM_statusRegister 0
  195. /*#define HDSPM_statusRegister2 96 */
  196. /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at
  197. * offset 192, for AES32 *and* MADI
  198. * => need to check that offset 192 is working on MADI */
  199. #define HDSPM_statusRegister2 192
  200. #define HDSPM_timecodeRegister 128
  201. /* AIO, RayDAT */
  202. #define HDSPM_RD_STATUS_0 0
  203. #define HDSPM_RD_STATUS_1 64
  204. #define HDSPM_RD_STATUS_2 128
  205. #define HDSPM_RD_STATUS_3 192
  206. #define HDSPM_RD_TCO 256
  207. #define HDSPM_RD_PLL_FREQ 512
  208. #define HDSPM_WR_TCO 128
  209. #define HDSPM_TCO1_TCO_lock 0x00000001
  210. #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002
  211. #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004
  212. #define HDSPM_TCO1_LTC_Input_valid 0x00000008
  213. #define HDSPM_TCO1_WCK_Input_valid 0x00000010
  214. #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020
  215. #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040
  216. #define HDSPM_TCO1_set_TC 0x00000100
  217. #define HDSPM_TCO1_set_drop_frame_flag 0x00000200
  218. #define HDSPM_TCO1_LTC_Format_LSB 0x00000400
  219. #define HDSPM_TCO1_LTC_Format_MSB 0x00000800
  220. #define HDSPM_TCO2_TC_run 0x00010000
  221. #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000
  222. #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000
  223. #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000
  224. #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000
  225. #define HDSPM_TCO2_set_jam_sync 0x00200000
  226. #define HDSPM_TCO2_set_flywheel 0x00400000
  227. #define HDSPM_TCO2_set_01_4 0x01000000
  228. #define HDSPM_TCO2_set_pull_down 0x02000000
  229. #define HDSPM_TCO2_set_pull_up 0x04000000
  230. #define HDSPM_TCO2_set_freq 0x08000000
  231. #define HDSPM_TCO2_set_term_75R 0x10000000
  232. #define HDSPM_TCO2_set_input_LSB 0x20000000
  233. #define HDSPM_TCO2_set_input_MSB 0x40000000
  234. #define HDSPM_TCO2_set_freq_from_app 0x80000000
  235. #define HDSPM_midiDataOut0 352
  236. #define HDSPM_midiDataOut1 356
  237. #define HDSPM_midiDataOut2 368
  238. #define HDSPM_midiDataIn0 360
  239. #define HDSPM_midiDataIn1 364
  240. #define HDSPM_midiDataIn2 372
  241. #define HDSPM_midiDataIn3 376
  242. /* status is data bytes in MIDI-FIFO (0-128) */
  243. #define HDSPM_midiStatusOut0 384
  244. #define HDSPM_midiStatusOut1 388
  245. #define HDSPM_midiStatusOut2 400
  246. #define HDSPM_midiStatusIn0 392
  247. #define HDSPM_midiStatusIn1 396
  248. #define HDSPM_midiStatusIn2 404
  249. #define HDSPM_midiStatusIn3 408
  250. /* the meters are regular i/o-mapped registers, but offset
  251. considerably from the rest. the peak registers are reset
  252. when read; the least-significant 4 bits are full-scale counters;
  253. the actual peak value is in the most-significant 24 bits.
  254. */
  255. #define HDSPM_MADI_INPUT_PEAK 4096
  256. #define HDSPM_MADI_PLAYBACK_PEAK 4352
  257. #define HDSPM_MADI_OUTPUT_PEAK 4608
  258. #define HDSPM_MADI_INPUT_RMS_L 6144
  259. #define HDSPM_MADI_PLAYBACK_RMS_L 6400
  260. #define HDSPM_MADI_OUTPUT_RMS_L 6656
  261. #define HDSPM_MADI_INPUT_RMS_H 7168
  262. #define HDSPM_MADI_PLAYBACK_RMS_H 7424
  263. #define HDSPM_MADI_OUTPUT_RMS_H 7680
  264. /* --- Control Register bits --------- */
  265. #define HDSPM_Start (1<<0) /* start engine */
  266. #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */
  267. #define HDSPM_Latency1 (1<<2) /* where n is defined */
  268. #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */
  269. #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */
  270. #define HDSPM_c0Master 0x1 /* Master clock bit in settings
  271. register [RayDAT, AIO] */
  272. #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */
  273. #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
  274. #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */
  275. #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
  276. #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */
  277. #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */
  278. #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
  279. 56channelMODE=0 */ /* MADI ONLY*/
  280. #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */
  281. #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
  282. 0=off, 1=on */ /* MADI ONLY */
  283. #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */
  284. #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax
  285. * -- MADI ONLY
  286. */
  287. #define HDSPM_InputSelect1 (1<<15) /* should be 0 */
  288. #define HDSPM_SyncRef2 (1<<13)
  289. #define HDSPM_SyncRef3 (1<<25)
  290. #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */
  291. #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
  292. AES additional bits in
  293. lower 5 Audiodatabits ??? */
  294. #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */
  295. #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */
  296. #define HDSPM_Midi0InterruptEnable 0x0400000
  297. #define HDSPM_Midi1InterruptEnable 0x0800000
  298. #define HDSPM_Midi2InterruptEnable 0x0200000
  299. #define HDSPM_Midi3InterruptEnable 0x4000000
  300. #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
  301. #define HDSPe_FLOAT_FORMAT 0x2000000
  302. #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */
  303. #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */
  304. #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */
  305. #define HDSPM_wclk_sel (1<<30)
  306. /* additional control register bits for AIO*/
  307. #define HDSPM_c0_Wck48 0x20 /* also RayDAT */
  308. #define HDSPM_c0_Input0 0x1000
  309. #define HDSPM_c0_Input1 0x2000
  310. #define HDSPM_c0_Spdif_Opt 0x4000
  311. #define HDSPM_c0_Pro 0x8000
  312. #define HDSPM_c0_clr_tms 0x10000
  313. #define HDSPM_c0_AEB1 0x20000
  314. #define HDSPM_c0_AEB2 0x40000
  315. #define HDSPM_c0_LineOut 0x80000
  316. #define HDSPM_c0_AD_GAIN0 0x100000
  317. #define HDSPM_c0_AD_GAIN1 0x200000
  318. #define HDSPM_c0_DA_GAIN0 0x400000
  319. #define HDSPM_c0_DA_GAIN1 0x800000
  320. #define HDSPM_c0_PH_GAIN0 0x1000000
  321. #define HDSPM_c0_PH_GAIN1 0x2000000
  322. #define HDSPM_c0_Sym6db 0x4000000
  323. /* --- bit helper defines */
  324. #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
  325. #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\
  326. HDSPM_DoubleSpeed|HDSPM_QuadSpeed)
  327. #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
  328. #define HDSPM_InputOptical 0
  329. #define HDSPM_InputCoaxial (HDSPM_InputSelect0)
  330. #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\
  331. HDSPM_SyncRef2|HDSPM_SyncRef3)
  332. #define HDSPM_c0_SyncRef0 0x2
  333. #define HDSPM_c0_SyncRef1 0x4
  334. #define HDSPM_c0_SyncRef2 0x8
  335. #define HDSPM_c0_SyncRef3 0x10
  336. #define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\
  337. HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3)
  338. #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */
  339. #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */
  340. #define HDSPM_SYNC_FROM_TCO 2
  341. #define HDSPM_SYNC_FROM_SYNC_IN 3
  342. #define HDSPM_Frequency32KHz HDSPM_Frequency0
  343. #define HDSPM_Frequency44_1KHz HDSPM_Frequency1
  344. #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0)
  345. #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0)
  346. #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1)
  347. #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\
  348. HDSPM_Frequency0)
  349. #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0)
  350. #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1)
  351. #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\
  352. HDSPM_Frequency0)
  353. /* Synccheck Status */
  354. #define HDSPM_SYNC_CHECK_NO_LOCK 0
  355. #define HDSPM_SYNC_CHECK_LOCK 1
  356. #define HDSPM_SYNC_CHECK_SYNC 2
  357. /* AutoSync References - used by "autosync_ref" control switch */
  358. #define HDSPM_AUTOSYNC_FROM_WORD 0
  359. #define HDSPM_AUTOSYNC_FROM_MADI 1
  360. #define HDSPM_AUTOSYNC_FROM_TCO 2
  361. #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3
  362. #define HDSPM_AUTOSYNC_FROM_NONE 4
  363. /* Possible sources of MADI input */
  364. #define HDSPM_OPTICAL 0 /* optical */
  365. #define HDSPM_COAXIAL 1 /* BNC */
  366. #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
  367. #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1))
  368. #define hdspm_encode_in(x) (((x)&0x3)<<14)
  369. #define hdspm_decode_in(x) (((x)>>14)&0x3)
  370. /* --- control2 register bits --- */
  371. #define HDSPM_TMS (1<<0)
  372. #define HDSPM_TCK (1<<1)
  373. #define HDSPM_TDI (1<<2)
  374. #define HDSPM_JTAG (1<<3)
  375. #define HDSPM_PWDN (1<<4)
  376. #define HDSPM_PROGRAM (1<<5)
  377. #define HDSPM_CONFIG_MODE_0 (1<<6)
  378. #define HDSPM_CONFIG_MODE_1 (1<<7)
  379. /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/
  380. #define HDSPM_BIGENDIAN_MODE (1<<9)
  381. #define HDSPM_RD_MULTIPLE (1<<10)
  382. /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and
  383. that do not conflict with specific bits for AES32 seem to be valid also
  384. for the AES32
  385. */
  386. #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
  387. #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */
  388. #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1
  389. * (like inp0)
  390. */
  391. #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
  392. #define HDSPM_madiSync (1<<18) /* MADI is in sync */
  393. #define HDSPM_tcoLockMadi 0x00000020 /* Optional TCO locked status for HDSPe MADI*/
  394. #define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status for HDSPe MADI and AES32!*/
  395. #define HDSPM_syncInLock 0x00010000 /* Sync In lock status for HDSPe MADI! */
  396. #define HDSPM_syncInSync 0x00020000 /* Sync In sync status for HDSPe MADI! */
  397. #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
  398. /* since 64byte accurate, last 6 bits are not used */
  399. #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
  400. #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */
  401. #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */
  402. #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */
  403. #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */
  404. #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with
  405. * Interrupt
  406. */
  407. #define HDSPM_tco_detect 0x08000000
  408. #define HDSPM_tcoLockAes 0x20000000 /* Optional TCO locked status for HDSPe AES */
  409. #define HDSPM_s2_tco_detect 0x00000040
  410. #define HDSPM_s2_AEBO_D 0x00000080
  411. #define HDSPM_s2_AEBI_D 0x00000100
  412. #define HDSPM_midi0IRQPending 0x40000000
  413. #define HDSPM_midi1IRQPending 0x80000000
  414. #define HDSPM_midi2IRQPending 0x20000000
  415. #define HDSPM_midi2IRQPendingAES 0x00000020
  416. #define HDSPM_midi3IRQPending 0x00200000
  417. /* --- status bit helpers */
  418. #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\
  419. HDSPM_madiFreq2|HDSPM_madiFreq3)
  420. #define HDSPM_madiFreq32 (HDSPM_madiFreq0)
  421. #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1)
  422. #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1)
  423. #define HDSPM_madiFreq64 (HDSPM_madiFreq2)
  424. #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2)
  425. #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2)
  426. #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2)
  427. #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3)
  428. #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0)
  429. /* Status2 Register bits */ /* MADI ONLY */
  430. #define HDSPM_version0 (1<<0) /* not really defined but I guess */
  431. #define HDSPM_version1 (1<<1) /* in former cards it was ??? */
  432. #define HDSPM_version2 (1<<2)
  433. #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
  434. #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
  435. #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */
  436. #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */
  437. #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, 111=128 */
  438. #define HDSPM_wc_freq3 0x800 /* 1000=176.4, 1001=192 */
  439. #define HDSPM_SyncRef0 0x10000 /* Sync Reference */
  440. #define HDSPM_SyncRef1 0x20000
  441. #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */
  442. #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
  443. #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
  444. #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
  445. #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\
  446. HDSPM_wc_freq3)
  447. #define HDSPM_wcFreq32 (HDSPM_wc_freq0)
  448. #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1)
  449. #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1)
  450. #define HDSPM_wcFreq64 (HDSPM_wc_freq2)
  451. #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2)
  452. #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2)
  453. #define HDSPM_wcFreq128 (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2)
  454. #define HDSPM_wcFreq176_4 (HDSPM_wc_freq3)
  455. #define HDSPM_wcFreq192 (HDSPM_wc_freq0|HDSPM_wc_freq3)
  456. #define HDSPM_status1_F_0 0x0400000
  457. #define HDSPM_status1_F_1 0x0800000
  458. #define HDSPM_status1_F_2 0x1000000
  459. #define HDSPM_status1_F_3 0x2000000
  460. #define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3)
  461. #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
  462. HDSPM_SelSyncRef2)
  463. #define HDSPM_SelSyncRef_WORD 0
  464. #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
  465. #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1)
  466. #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1)
  467. #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
  468. HDSPM_SelSyncRef2)
  469. /*
  470. For AES32, bits for status, status2 and timecode are different
  471. */
  472. /* status */
  473. #define HDSPM_AES32_wcLock 0x0200000
  474. #define HDSPM_AES32_wcSync 0x0100000
  475. #define HDSPM_AES32_wcFreq_bit 22
  476. /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function
  477. HDSPM_bit2freq */
  478. #define HDSPM_AES32_syncref_bit 16
  479. /* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */
  480. #define HDSPM_AES32_AUTOSYNC_FROM_WORD 0
  481. #define HDSPM_AES32_AUTOSYNC_FROM_AES1 1
  482. #define HDSPM_AES32_AUTOSYNC_FROM_AES2 2
  483. #define HDSPM_AES32_AUTOSYNC_FROM_AES3 3
  484. #define HDSPM_AES32_AUTOSYNC_FROM_AES4 4
  485. #define HDSPM_AES32_AUTOSYNC_FROM_AES5 5
  486. #define HDSPM_AES32_AUTOSYNC_FROM_AES6 6
  487. #define HDSPM_AES32_AUTOSYNC_FROM_AES7 7
  488. #define HDSPM_AES32_AUTOSYNC_FROM_AES8 8
  489. #define HDSPM_AES32_AUTOSYNC_FROM_TCO 9
  490. #define HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN 10
  491. #define HDSPM_AES32_AUTOSYNC_FROM_NONE 11
  492. /* status2 */
  493. /* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */
  494. #define HDSPM_LockAES 0x80
  495. #define HDSPM_LockAES1 0x80
  496. #define HDSPM_LockAES2 0x40
  497. #define HDSPM_LockAES3 0x20
  498. #define HDSPM_LockAES4 0x10
  499. #define HDSPM_LockAES5 0x8
  500. #define HDSPM_LockAES6 0x4
  501. #define HDSPM_LockAES7 0x2
  502. #define HDSPM_LockAES8 0x1
  503. /*
  504. Timecode
  505. After windows driver sources, bits 4*i to 4*i+3 give the input frequency on
  506. AES i+1
  507. bits 3210
  508. 0001 32kHz
  509. 0010 44.1kHz
  510. 0011 48kHz
  511. 0100 64kHz
  512. 0101 88.2kHz
  513. 0110 96kHz
  514. 0111 128kHz
  515. 1000 176.4kHz
  516. 1001 192kHz
  517. NB: Timecode register doesn't seem to work on AES32 card revision 230
  518. */
  519. /* Mixer Values */
  520. #define UNITY_GAIN 32768 /* = 65536/2 */
  521. #define MINUS_INFINITY_GAIN 0
  522. /* Number of channels for different Speed Modes */
  523. #define MADI_SS_CHANNELS 64
  524. #define MADI_DS_CHANNELS 32
  525. #define MADI_QS_CHANNELS 16
  526. #define RAYDAT_SS_CHANNELS 36
  527. #define RAYDAT_DS_CHANNELS 20
  528. #define RAYDAT_QS_CHANNELS 12
  529. #define AIO_IN_SS_CHANNELS 14
  530. #define AIO_IN_DS_CHANNELS 10
  531. #define AIO_IN_QS_CHANNELS 8
  532. #define AIO_OUT_SS_CHANNELS 16
  533. #define AIO_OUT_DS_CHANNELS 12
  534. #define AIO_OUT_QS_CHANNELS 10
  535. #define AES32_CHANNELS 16
  536. /* the size of a substream (1 mono data stream) */
  537. #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024)
  538. #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES)
  539. /* the size of the area we need to allocate for DMA transfers. the
  540. size is the same regardless of the number of channels, and
  541. also the latency to use.
  542. for one direction !!!
  543. */
  544. #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
  545. #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
  546. #define HDSPM_RAYDAT_REV 211
  547. #define HDSPM_AIO_REV 212
  548. #define HDSPM_MADIFACE_REV 213
  549. /* speed factor modes */
  550. #define HDSPM_SPEED_SINGLE 0
  551. #define HDSPM_SPEED_DOUBLE 1
  552. #define HDSPM_SPEED_QUAD 2
  553. /* names for speed modes */
  554. static char *hdspm_speed_names[] = { "single", "double", "quad" };
  555. static const char *const texts_autosync_aes_tco[] = { "Word Clock",
  556. "AES1", "AES2", "AES3", "AES4",
  557. "AES5", "AES6", "AES7", "AES8",
  558. "TCO", "Sync In"
  559. };
  560. static const char *const texts_autosync_aes[] = { "Word Clock",
  561. "AES1", "AES2", "AES3", "AES4",
  562. "AES5", "AES6", "AES7", "AES8",
  563. "Sync In"
  564. };
  565. static const char *const texts_autosync_madi_tco[] = { "Word Clock",
  566. "MADI", "TCO", "Sync In" };
  567. static const char *const texts_autosync_madi[] = { "Word Clock",
  568. "MADI", "Sync In" };
  569. static const char *const texts_autosync_raydat_tco[] = {
  570. "Word Clock",
  571. "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
  572. "AES", "SPDIF", "TCO", "Sync In"
  573. };
  574. static const char *const texts_autosync_raydat[] = {
  575. "Word Clock",
  576. "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
  577. "AES", "SPDIF", "Sync In"
  578. };
  579. static const char *const texts_autosync_aio_tco[] = {
  580. "Word Clock",
  581. "ADAT", "AES", "SPDIF", "TCO", "Sync In"
  582. };
  583. static const char *const texts_autosync_aio[] = { "Word Clock",
  584. "ADAT", "AES", "SPDIF", "Sync In" };
  585. static const char *const texts_freq[] = {
  586. "No Lock",
  587. "32 kHz",
  588. "44.1 kHz",
  589. "48 kHz",
  590. "64 kHz",
  591. "88.2 kHz",
  592. "96 kHz",
  593. "128 kHz",
  594. "176.4 kHz",
  595. "192 kHz"
  596. };
  597. static char *texts_ports_madi[] = {
  598. "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6",
  599. "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12",
  600. "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18",
  601. "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24",
  602. "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30",
  603. "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36",
  604. "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42",
  605. "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48",
  606. "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54",
  607. "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60",
  608. "MADI.61", "MADI.62", "MADI.63", "MADI.64",
  609. };
  610. static char *texts_ports_raydat_ss[] = {
  611. "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6",
  612. "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
  613. "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2",
  614. "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8",
  615. "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6",
  616. "ADAT4.7", "ADAT4.8",
  617. "AES.L", "AES.R",
  618. "SPDIF.L", "SPDIF.R"
  619. };
  620. static char *texts_ports_raydat_ds[] = {
  621. "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4",
  622. "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
  623. "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4",
  624. "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4",
  625. "AES.L", "AES.R",
  626. "SPDIF.L", "SPDIF.R"
  627. };
  628. static char *texts_ports_raydat_qs[] = {
  629. "ADAT1.1", "ADAT1.2",
  630. "ADAT2.1", "ADAT2.2",
  631. "ADAT3.1", "ADAT3.2",
  632. "ADAT4.1", "ADAT4.2",
  633. "AES.L", "AES.R",
  634. "SPDIF.L", "SPDIF.R"
  635. };
  636. static char *texts_ports_aio_in_ss[] = {
  637. "Analogue.L", "Analogue.R",
  638. "AES.L", "AES.R",
  639. "SPDIF.L", "SPDIF.R",
  640. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
  641. "ADAT.7", "ADAT.8",
  642. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  643. };
  644. static char *texts_ports_aio_out_ss[] = {
  645. "Analogue.L", "Analogue.R",
  646. "AES.L", "AES.R",
  647. "SPDIF.L", "SPDIF.R",
  648. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
  649. "ADAT.7", "ADAT.8",
  650. "Phone.L", "Phone.R",
  651. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  652. };
  653. static char *texts_ports_aio_in_ds[] = {
  654. "Analogue.L", "Analogue.R",
  655. "AES.L", "AES.R",
  656. "SPDIF.L", "SPDIF.R",
  657. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
  658. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  659. };
  660. static char *texts_ports_aio_out_ds[] = {
  661. "Analogue.L", "Analogue.R",
  662. "AES.L", "AES.R",
  663. "SPDIF.L", "SPDIF.R",
  664. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
  665. "Phone.L", "Phone.R",
  666. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  667. };
  668. static char *texts_ports_aio_in_qs[] = {
  669. "Analogue.L", "Analogue.R",
  670. "AES.L", "AES.R",
  671. "SPDIF.L", "SPDIF.R",
  672. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
  673. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  674. };
  675. static char *texts_ports_aio_out_qs[] = {
  676. "Analogue.L", "Analogue.R",
  677. "AES.L", "AES.R",
  678. "SPDIF.L", "SPDIF.R",
  679. "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
  680. "Phone.L", "Phone.R",
  681. "AEB.1", "AEB.2", "AEB.3", "AEB.4"
  682. };
  683. static char *texts_ports_aes32[] = {
  684. "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7",
  685. "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14",
  686. "AES.15", "AES.16"
  687. };
  688. /* These tables map the ALSA channels 1..N to the channels that we
  689. need to use in order to find the relevant channel buffer. RME
  690. refers to this kind of mapping as between "the ADAT channel and
  691. the DMA channel." We index it using the logical audio channel,
  692. and the value is the DMA channel (i.e. channel buffer number)
  693. where the data for that channel can be read/written from/to.
  694. */
  695. static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = {
  696. 0, 1, 2, 3, 4, 5, 6, 7,
  697. 8, 9, 10, 11, 12, 13, 14, 15,
  698. 16, 17, 18, 19, 20, 21, 22, 23,
  699. 24, 25, 26, 27, 28, 29, 30, 31,
  700. 32, 33, 34, 35, 36, 37, 38, 39,
  701. 40, 41, 42, 43, 44, 45, 46, 47,
  702. 48, 49, 50, 51, 52, 53, 54, 55,
  703. 56, 57, 58, 59, 60, 61, 62, 63
  704. };
  705. static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = {
  706. 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */
  707. 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */
  708. 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */
  709. 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */
  710. 0, 1, /* AES */
  711. 2, 3, /* SPDIF */
  712. -1, -1, -1, -1,
  713. -1, -1, -1, -1, -1, -1, -1, -1,
  714. -1, -1, -1, -1, -1, -1, -1, -1,
  715. -1, -1, -1, -1, -1, -1, -1, -1,
  716. };
  717. static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = {
  718. 4, 5, 6, 7, /* ADAT 1 */
  719. 8, 9, 10, 11, /* ADAT 2 */
  720. 12, 13, 14, 15, /* ADAT 3 */
  721. 16, 17, 18, 19, /* ADAT 4 */
  722. 0, 1, /* AES */
  723. 2, 3, /* SPDIF */
  724. -1, -1, -1, -1,
  725. -1, -1, -1, -1, -1, -1, -1, -1,
  726. -1, -1, -1, -1, -1, -1, -1, -1,
  727. -1, -1, -1, -1, -1, -1, -1, -1,
  728. -1, -1, -1, -1, -1, -1, -1, -1,
  729. -1, -1, -1, -1, -1, -1, -1, -1,
  730. };
  731. static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = {
  732. 4, 5, /* ADAT 1 */
  733. 6, 7, /* ADAT 2 */
  734. 8, 9, /* ADAT 3 */
  735. 10, 11, /* ADAT 4 */
  736. 0, 1, /* AES */
  737. 2, 3, /* SPDIF */
  738. -1, -1, -1, -1,
  739. -1, -1, -1, -1, -1, -1, -1, -1,
  740. -1, -1, -1, -1, -1, -1, -1, -1,
  741. -1, -1, -1, -1, -1, -1, -1, -1,
  742. -1, -1, -1, -1, -1, -1, -1, -1,
  743. -1, -1, -1, -1, -1, -1, -1, -1,
  744. -1, -1, -1, -1, -1, -1, -1, -1,
  745. };
  746. static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = {
  747. 0, 1, /* line in */
  748. 8, 9, /* aes in, */
  749. 10, 11, /* spdif in */
  750. 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */
  751. 2, 3, 4, 5, /* AEB */
  752. -1, -1, -1, -1, -1, -1,
  753. -1, -1, -1, -1, -1, -1, -1, -1,
  754. -1, -1, -1, -1, -1, -1, -1, -1,
  755. -1, -1, -1, -1, -1, -1, -1, -1,
  756. -1, -1, -1, -1, -1, -1, -1, -1,
  757. -1, -1, -1, -1, -1, -1, -1, -1,
  758. };
  759. static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = {
  760. 0, 1, /* line out */
  761. 8, 9, /* aes out */
  762. 10, 11, /* spdif out */
  763. 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */
  764. 6, 7, /* phone out */
  765. 2, 3, 4, 5, /* AEB */
  766. -1, -1, -1, -1,
  767. -1, -1, -1, -1, -1, -1, -1, -1,
  768. -1, -1, -1, -1, -1, -1, -1, -1,
  769. -1, -1, -1, -1, -1, -1, -1, -1,
  770. -1, -1, -1, -1, -1, -1, -1, -1,
  771. -1, -1, -1, -1, -1, -1, -1, -1,
  772. };
  773. static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = {
  774. 0, 1, /* line in */
  775. 8, 9, /* aes in */
  776. 10, 11, /* spdif in */
  777. 12, 14, 16, 18, /* adat in */
  778. 2, 3, 4, 5, /* AEB */
  779. -1, -1,
  780. -1, -1, -1, -1, -1, -1, -1, -1,
  781. -1, -1, -1, -1, -1, -1, -1, -1,
  782. -1, -1, -1, -1, -1, -1, -1, -1,
  783. -1, -1, -1, -1, -1, -1, -1, -1,
  784. -1, -1, -1, -1, -1, -1, -1, -1,
  785. -1, -1, -1, -1, -1, -1, -1, -1
  786. };
  787. static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = {
  788. 0, 1, /* line out */
  789. 8, 9, /* aes out */
  790. 10, 11, /* spdif out */
  791. 12, 14, 16, 18, /* adat out */
  792. 6, 7, /* phone out */
  793. 2, 3, 4, 5, /* AEB */
  794. -1, -1, -1, -1, -1, -1, -1, -1,
  795. -1, -1, -1, -1, -1, -1, -1, -1,
  796. -1, -1, -1, -1, -1, -1, -1, -1,
  797. -1, -1, -1, -1, -1, -1, -1, -1,
  798. -1, -1, -1, -1, -1, -1, -1, -1,
  799. -1, -1, -1, -1, -1, -1, -1, -1
  800. };
  801. static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = {
  802. 0, 1, /* line in */
  803. 8, 9, /* aes in */
  804. 10, 11, /* spdif in */
  805. 12, 16, /* adat in */
  806. 2, 3, 4, 5, /* AEB */
  807. -1, -1, -1, -1,
  808. -1, -1, -1, -1, -1, -1, -1, -1,
  809. -1, -1, -1, -1, -1, -1, -1, -1,
  810. -1, -1, -1, -1, -1, -1, -1, -1,
  811. -1, -1, -1, -1, -1, -1, -1, -1,
  812. -1, -1, -1, -1, -1, -1, -1, -1,
  813. -1, -1, -1, -1, -1, -1, -1, -1
  814. };
  815. static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = {
  816. 0, 1, /* line out */
  817. 8, 9, /* aes out */
  818. 10, 11, /* spdif out */
  819. 12, 16, /* adat out */
  820. 6, 7, /* phone out */
  821. 2, 3, 4, 5, /* AEB */
  822. -1, -1,
  823. -1, -1, -1, -1, -1, -1, -1, -1,
  824. -1, -1, -1, -1, -1, -1, -1, -1,
  825. -1, -1, -1, -1, -1, -1, -1, -1,
  826. -1, -1, -1, -1, -1, -1, -1, -1,
  827. -1, -1, -1, -1, -1, -1, -1, -1,
  828. -1, -1, -1, -1, -1, -1, -1, -1
  829. };
  830. static char channel_map_aes32[HDSPM_MAX_CHANNELS] = {
  831. 0, 1, 2, 3, 4, 5, 6, 7,
  832. 8, 9, 10, 11, 12, 13, 14, 15,
  833. -1, -1, -1, -1, -1, -1, -1, -1,
  834. -1, -1, -1, -1, -1, -1, -1, -1,
  835. -1, -1, -1, -1, -1, -1, -1, -1,
  836. -1, -1, -1, -1, -1, -1, -1, -1,
  837. -1, -1, -1, -1, -1, -1, -1, -1,
  838. -1, -1, -1, -1, -1, -1, -1, -1
  839. };
  840. struct hdspm_midi {
  841. struct hdspm *hdspm;
  842. int id;
  843. struct snd_rawmidi *rmidi;
  844. struct snd_rawmidi_substream *input;
  845. struct snd_rawmidi_substream *output;
  846. char istimer; /* timer in use */
  847. struct timer_list timer;
  848. spinlock_t lock;
  849. int pending;
  850. int dataIn;
  851. int statusIn;
  852. int dataOut;
  853. int statusOut;
  854. int ie;
  855. int irq;
  856. };
  857. struct hdspm_tco {
  858. int input; /* 0: LTC, 1:Video, 2: WC*/
  859. int framerate; /* 0=24, 1=25, 2=29.97, 3=29.97d, 4=30, 5=30d */
  860. int wordclock; /* 0=1:1, 1=44.1->48, 2=48->44.1 */
  861. int samplerate; /* 0=44.1, 1=48, 2= freq from app */
  862. int pull; /* 0=0, 1=+0.1%, 2=-0.1%, 3=+4%, 4=-4%*/
  863. int term; /* 0 = off, 1 = on */
  864. };
  865. struct hdspm {
  866. spinlock_t lock;
  867. /* only one playback and/or capture stream */
  868. struct snd_pcm_substream *capture_substream;
  869. struct snd_pcm_substream *playback_substream;
  870. char *card_name; /* for procinfo */
  871. unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/
  872. uint8_t io_type;
  873. int monitor_outs; /* set up monitoring outs init flag */
  874. u32 control_register; /* cached value */
  875. u32 control2_register; /* cached value */
  876. u32 settings_register; /* cached value for AIO / RayDat (sync reference, master/slave) */
  877. struct hdspm_midi midi[4];
  878. struct tasklet_struct midi_tasklet;
  879. size_t period_bytes;
  880. unsigned char ss_in_channels;
  881. unsigned char ds_in_channels;
  882. unsigned char qs_in_channels;
  883. unsigned char ss_out_channels;
  884. unsigned char ds_out_channels;
  885. unsigned char qs_out_channels;
  886. unsigned char max_channels_in;
  887. unsigned char max_channels_out;
  888. signed char *channel_map_in;
  889. signed char *channel_map_out;
  890. signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs;
  891. signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs;
  892. char **port_names_in;
  893. char **port_names_out;
  894. char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs;
  895. char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs;
  896. unsigned char *playback_buffer; /* suitably aligned address */
  897. unsigned char *capture_buffer; /* suitably aligned address */
  898. pid_t capture_pid; /* process id which uses capture */
  899. pid_t playback_pid; /* process id which uses capture */
  900. int running; /* running status */
  901. int last_external_sample_rate; /* samplerate mystic ... */
  902. int last_internal_sample_rate;
  903. int system_sample_rate;
  904. int dev; /* Hardware vars... */
  905. int irq;
  906. unsigned long port;
  907. void __iomem *iobase;
  908. int irq_count; /* for debug */
  909. int midiPorts;
  910. struct snd_card *card; /* one card */
  911. struct snd_pcm *pcm; /* has one pcm */
  912. struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */
  913. struct pci_dev *pci; /* and an pci info */
  914. /* Mixer vars */
  915. /* fast alsa mixer */
  916. struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS];
  917. /* but input to much, so not used */
  918. struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS];
  919. /* full mixer accessible over mixer ioctl or hwdep-device */
  920. struct hdspm_mixer *mixer;
  921. struct hdspm_tco *tco; /* NULL if no TCO detected */
  922. const char *const *texts_autosync;
  923. int texts_autosync_items;
  924. cycles_t last_interrupt;
  925. unsigned int serial;
  926. struct hdspm_peak_rms peak_rms;
  927. };
  928. static const struct pci_device_id snd_hdspm_ids[] = {
  929. {
  930. .vendor = PCI_VENDOR_ID_XILINX,
  931. .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
  932. .subvendor = PCI_ANY_ID,
  933. .subdevice = PCI_ANY_ID,
  934. .class = 0,
  935. .class_mask = 0,
  936. .driver_data = 0},
  937. {0,}
  938. };
  939. MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
  940. /* prototypes */
  941. static int snd_hdspm_create_alsa_devices(struct snd_card *card,
  942. struct hdspm *hdspm);
  943. static int snd_hdspm_create_pcm(struct snd_card *card,
  944. struct hdspm *hdspm);
  945. static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
  946. static inline int hdspm_get_pll_freq(struct hdspm *hdspm);
  947. static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
  948. static int hdspm_autosync_ref(struct hdspm *hdspm);
  949. static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out);
  950. static int snd_hdspm_set_defaults(struct hdspm *hdspm);
  951. static int hdspm_system_clock_mode(struct hdspm *hdspm);
  952. static void hdspm_set_sgbuf(struct hdspm *hdspm,
  953. struct snd_pcm_substream *substream,
  954. unsigned int reg, int channels);
  955. static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx);
  956. static int hdspm_wc_sync_check(struct hdspm *hdspm);
  957. static int hdspm_tco_sync_check(struct hdspm *hdspm);
  958. static int hdspm_sync_in_sync_check(struct hdspm *hdspm);
  959. static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index);
  960. static int hdspm_get_tco_sample_rate(struct hdspm *hdspm);
  961. static int hdspm_get_wc_sample_rate(struct hdspm *hdspm);
  962. static inline int HDSPM_bit2freq(int n)
  963. {
  964. static const int bit2freq_tab[] = {
  965. 0, 32000, 44100, 48000, 64000, 88200,
  966. 96000, 128000, 176400, 192000 };
  967. if (n < 1 || n > 9)
  968. return 0;
  969. return bit2freq_tab[n];
  970. }
  971. static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm)
  972. {
  973. return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type));
  974. }
  975. /* Write/read to/from HDSPM with Adresses in Bytes
  976. not words but only 32Bit writes are allowed */
  977. static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
  978. unsigned int val)
  979. {
  980. writel(val, hdspm->iobase + reg);
  981. }
  982. static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
  983. {
  984. return readl(hdspm->iobase + reg);
  985. }
  986. /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader
  987. mixer is write only on hardware so we have to cache him for read
  988. each fader is a u32, but uses only the first 16 bit */
  989. static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
  990. unsigned int in)
  991. {
  992. if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
  993. return 0;
  994. return hdspm->mixer->ch[chan].in[in];
  995. }
  996. static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
  997. unsigned int pb)
  998. {
  999. if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
  1000. return 0;
  1001. return hdspm->mixer->ch[chan].pb[pb];
  1002. }
  1003. static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
  1004. unsigned int in, unsigned short data)
  1005. {
  1006. if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
  1007. return -1;
  1008. hdspm_write(hdspm,
  1009. HDSPM_MADI_mixerBase +
  1010. ((in + 128 * chan) * sizeof(u32)),
  1011. (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
  1012. return 0;
  1013. }
  1014. static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
  1015. unsigned int pb, unsigned short data)
  1016. {
  1017. if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
  1018. return -1;
  1019. hdspm_write(hdspm,
  1020. HDSPM_MADI_mixerBase +
  1021. ((64 + pb + 128 * chan) * sizeof(u32)),
  1022. (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
  1023. return 0;
  1024. }
  1025. /* enable DMA for specific channels, now available for DSP-MADI */
  1026. static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
  1027. {
  1028. hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
  1029. }
  1030. static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
  1031. {
  1032. hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
  1033. }
  1034. /* check if same process is writing and reading */
  1035. static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
  1036. {
  1037. unsigned long flags;
  1038. int ret = 1;
  1039. spin_lock_irqsave(&hdspm->lock, flags);
  1040. if ((hdspm->playback_pid != hdspm->capture_pid) &&
  1041. (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
  1042. ret = 0;
  1043. }
  1044. spin_unlock_irqrestore(&hdspm->lock, flags);
  1045. return ret;
  1046. }
  1047. /* round arbitary sample rates to commonly known rates */
  1048. static int hdspm_round_frequency(int rate)
  1049. {
  1050. if (rate < 38050)
  1051. return 32000;
  1052. if (rate < 46008)
  1053. return 44100;
  1054. else
  1055. return 48000;
  1056. }
  1057. /* QS and DS rates normally can not be detected
  1058. * automatically by the card. Only exception is MADI
  1059. * in 96k frame mode.
  1060. *
  1061. * So if we read SS values (32 .. 48k), check for
  1062. * user-provided DS/QS bits in the control register
  1063. * and multiply the base frequency accordingly.
  1064. */
  1065. static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate)
  1066. {
  1067. if (rate <= 48000) {
  1068. if (hdspm->control_register & HDSPM_QuadSpeed)
  1069. return rate * 4;
  1070. else if (hdspm->control_register &
  1071. HDSPM_DoubleSpeed)
  1072. return rate * 2;
  1073. }
  1074. return rate;
  1075. }
  1076. /* check for external sample rate, returns the sample rate in Hz*/
  1077. static int hdspm_external_sample_rate(struct hdspm *hdspm)
  1078. {
  1079. unsigned int status, status2;
  1080. int syncref, rate = 0, rate_bits;
  1081. switch (hdspm->io_type) {
  1082. case AES32:
  1083. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  1084. status = hdspm_read(hdspm, HDSPM_statusRegister);
  1085. syncref = hdspm_autosync_ref(hdspm);
  1086. switch (syncref) {
  1087. case HDSPM_AES32_AUTOSYNC_FROM_WORD:
  1088. /* Check WC sync and get sample rate */
  1089. if (hdspm_wc_sync_check(hdspm))
  1090. return HDSPM_bit2freq(hdspm_get_wc_sample_rate(hdspm));
  1091. break;
  1092. case HDSPM_AES32_AUTOSYNC_FROM_AES1:
  1093. case HDSPM_AES32_AUTOSYNC_FROM_AES2:
  1094. case HDSPM_AES32_AUTOSYNC_FROM_AES3:
  1095. case HDSPM_AES32_AUTOSYNC_FROM_AES4:
  1096. case HDSPM_AES32_AUTOSYNC_FROM_AES5:
  1097. case HDSPM_AES32_AUTOSYNC_FROM_AES6:
  1098. case HDSPM_AES32_AUTOSYNC_FROM_AES7:
  1099. case HDSPM_AES32_AUTOSYNC_FROM_AES8:
  1100. /* Check AES sync and get sample rate */
  1101. if (hdspm_aes_sync_check(hdspm, syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))
  1102. return HDSPM_bit2freq(hdspm_get_aes_sample_rate(hdspm,
  1103. syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1));
  1104. break;
  1105. case HDSPM_AES32_AUTOSYNC_FROM_TCO:
  1106. /* Check TCO sync and get sample rate */
  1107. if (hdspm_tco_sync_check(hdspm))
  1108. return HDSPM_bit2freq(hdspm_get_tco_sample_rate(hdspm));
  1109. break;
  1110. default:
  1111. return 0;
  1112. } /* end switch(syncref) */
  1113. break;
  1114. case MADIface:
  1115. status = hdspm_read(hdspm, HDSPM_statusRegister);
  1116. if (!(status & HDSPM_madiLock)) {
  1117. rate = 0; /* no lock */
  1118. } else {
  1119. switch (status & (HDSPM_status1_freqMask)) {
  1120. case HDSPM_status1_F_0*1:
  1121. rate = 32000; break;
  1122. case HDSPM_status1_F_0*2:
  1123. rate = 44100; break;
  1124. case HDSPM_status1_F_0*3:
  1125. rate = 48000; break;
  1126. case HDSPM_status1_F_0*4:
  1127. rate = 64000; break;
  1128. case HDSPM_status1_F_0*5:
  1129. rate = 88200; break;
  1130. case HDSPM_status1_F_0*6:
  1131. rate = 96000; break;
  1132. case HDSPM_status1_F_0*7:
  1133. rate = 128000; break;
  1134. case HDSPM_status1_F_0*8:
  1135. rate = 176400; break;
  1136. case HDSPM_status1_F_0*9:
  1137. rate = 192000; break;
  1138. default:
  1139. rate = 0; break;
  1140. }
  1141. }
  1142. break;
  1143. case MADI:
  1144. case AIO:
  1145. case RayDAT:
  1146. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  1147. status = hdspm_read(hdspm, HDSPM_statusRegister);
  1148. rate = 0;
  1149. /* if wordclock has synced freq and wordclock is valid */
  1150. if ((status2 & HDSPM_wcLock) != 0 &&
  1151. (status2 & HDSPM_SelSyncRef0) == 0) {
  1152. rate_bits = status2 & HDSPM_wcFreqMask;
  1153. switch (rate_bits) {
  1154. case HDSPM_wcFreq32:
  1155. rate = 32000;
  1156. break;
  1157. case HDSPM_wcFreq44_1:
  1158. rate = 44100;
  1159. break;
  1160. case HDSPM_wcFreq48:
  1161. rate = 48000;
  1162. break;
  1163. case HDSPM_wcFreq64:
  1164. rate = 64000;
  1165. break;
  1166. case HDSPM_wcFreq88_2:
  1167. rate = 88200;
  1168. break;
  1169. case HDSPM_wcFreq96:
  1170. rate = 96000;
  1171. break;
  1172. case HDSPM_wcFreq128:
  1173. rate = 128000;
  1174. break;
  1175. case HDSPM_wcFreq176_4:
  1176. rate = 176400;
  1177. break;
  1178. case HDSPM_wcFreq192:
  1179. rate = 192000;
  1180. break;
  1181. default:
  1182. rate = 0;
  1183. break;
  1184. }
  1185. }
  1186. /* if rate detected and Syncref is Word than have it,
  1187. * word has priority to MADI
  1188. */
  1189. if (rate != 0 &&
  1190. (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
  1191. return hdspm_rate_multiplier(hdspm, rate);
  1192. /* maybe a madi input (which is taken if sel sync is madi) */
  1193. if (status & HDSPM_madiLock) {
  1194. rate_bits = status & HDSPM_madiFreqMask;
  1195. switch (rate_bits) {
  1196. case HDSPM_madiFreq32:
  1197. rate = 32000;
  1198. break;
  1199. case HDSPM_madiFreq44_1:
  1200. rate = 44100;
  1201. break;
  1202. case HDSPM_madiFreq48:
  1203. rate = 48000;
  1204. break;
  1205. case HDSPM_madiFreq64:
  1206. rate = 64000;
  1207. break;
  1208. case HDSPM_madiFreq88_2:
  1209. rate = 88200;
  1210. break;
  1211. case HDSPM_madiFreq96:
  1212. rate = 96000;
  1213. break;
  1214. case HDSPM_madiFreq128:
  1215. rate = 128000;
  1216. break;
  1217. case HDSPM_madiFreq176_4:
  1218. rate = 176400;
  1219. break;
  1220. case HDSPM_madiFreq192:
  1221. rate = 192000;
  1222. break;
  1223. default:
  1224. rate = 0;
  1225. break;
  1226. }
  1227. } /* endif HDSPM_madiLock */
  1228. /* check sample rate from TCO or SYNC_IN */
  1229. {
  1230. bool is_valid_input = 0;
  1231. bool has_sync = 0;
  1232. syncref = hdspm_autosync_ref(hdspm);
  1233. if (HDSPM_AUTOSYNC_FROM_TCO == syncref) {
  1234. is_valid_input = 1;
  1235. has_sync = (HDSPM_SYNC_CHECK_SYNC ==
  1236. hdspm_tco_sync_check(hdspm));
  1237. } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) {
  1238. is_valid_input = 1;
  1239. has_sync = (HDSPM_SYNC_CHECK_SYNC ==
  1240. hdspm_sync_in_sync_check(hdspm));
  1241. }
  1242. if (is_valid_input && has_sync) {
  1243. rate = hdspm_round_frequency(
  1244. hdspm_get_pll_freq(hdspm));
  1245. }
  1246. }
  1247. rate = hdspm_rate_multiplier(hdspm, rate);
  1248. break;
  1249. }
  1250. return rate;
  1251. }
  1252. /* return latency in samples per period */
  1253. static int hdspm_get_latency(struct hdspm *hdspm)
  1254. {
  1255. int n;
  1256. n = hdspm_decode_latency(hdspm->control_register);
  1257. /* Special case for new RME cards with 32 samples period size.
  1258. * The three latency bits in the control register
  1259. * (HDSP_LatencyMask) encode latency values of 64 samples as
  1260. * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
  1261. * denotes 8192 samples, but on new cards like RayDAT or AIO,
  1262. * it corresponds to 32 samples.
  1263. */
  1264. if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
  1265. n = -1;
  1266. return 1 << (n + 6);
  1267. }
  1268. /* Latency function */
  1269. static inline void hdspm_compute_period_size(struct hdspm *hdspm)
  1270. {
  1271. hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
  1272. }
  1273. static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm)
  1274. {
  1275. int position;
  1276. position = hdspm_read(hdspm, HDSPM_statusRegister);
  1277. switch (hdspm->io_type) {
  1278. case RayDAT:
  1279. case AIO:
  1280. position &= HDSPM_BufferPositionMask;
  1281. position /= 4; /* Bytes per sample */
  1282. break;
  1283. default:
  1284. position = (position & HDSPM_BufferID) ?
  1285. (hdspm->period_bytes / 4) : 0;
  1286. }
  1287. return position;
  1288. }
  1289. static inline void hdspm_start_audio(struct hdspm * s)
  1290. {
  1291. s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
  1292. hdspm_write(s, HDSPM_controlRegister, s->control_register);
  1293. }
  1294. static inline void hdspm_stop_audio(struct hdspm * s)
  1295. {
  1296. s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
  1297. hdspm_write(s, HDSPM_controlRegister, s->control_register);
  1298. }
  1299. /* should I silence all or only opened ones ? doit all for first even is 4MB*/
  1300. static void hdspm_silence_playback(struct hdspm *hdspm)
  1301. {
  1302. int i;
  1303. int n = hdspm->period_bytes;
  1304. void *buf = hdspm->playback_buffer;
  1305. if (buf == NULL)
  1306. return;
  1307. for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
  1308. memset(buf, 0, n);
  1309. buf += HDSPM_CHANNEL_BUFFER_BYTES;
  1310. }
  1311. }
  1312. static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
  1313. {
  1314. int n;
  1315. spin_lock_irq(&s->lock);
  1316. if (32 == frames) {
  1317. /* Special case for new RME cards like RayDAT/AIO which
  1318. * support period sizes of 32 samples. Since latency is
  1319. * encoded in the three bits of HDSP_LatencyMask, we can only
  1320. * have values from 0 .. 7. While 0 still means 64 samples and
  1321. * 6 represents 4096 samples on all cards, 7 represents 8192
  1322. * on older cards and 32 samples on new cards.
  1323. *
  1324. * In other words, period size in samples is calculated by
  1325. * 2^(n+6) with n ranging from 0 .. 7.
  1326. */
  1327. n = 7;
  1328. } else {
  1329. frames >>= 7;
  1330. n = 0;
  1331. while (frames) {
  1332. n++;
  1333. frames >>= 1;
  1334. }
  1335. }
  1336. s->control_register &= ~HDSPM_LatencyMask;
  1337. s->control_register |= hdspm_encode_latency(n);
  1338. hdspm_write(s, HDSPM_controlRegister, s->control_register);
  1339. hdspm_compute_period_size(s);
  1340. spin_unlock_irq(&s->lock);
  1341. return 0;
  1342. }
  1343. static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
  1344. {
  1345. u64 freq_const;
  1346. if (period == 0)
  1347. return 0;
  1348. switch (hdspm->io_type) {
  1349. case MADI:
  1350. case AES32:
  1351. freq_const = 110069313433624ULL;
  1352. break;
  1353. case RayDAT:
  1354. case AIO:
  1355. freq_const = 104857600000000ULL;
  1356. break;
  1357. case MADIface:
  1358. freq_const = 131072000000000ULL;
  1359. break;
  1360. default:
  1361. snd_BUG();
  1362. return 0;
  1363. }
  1364. return div_u64(freq_const, period);
  1365. }
  1366. static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
  1367. {
  1368. u64 n;
  1369. if (snd_BUG_ON(rate <= 0))
  1370. return;
  1371. if (rate >= 112000)
  1372. rate /= 4;
  1373. else if (rate >= 56000)
  1374. rate /= 2;
  1375. switch (hdspm->io_type) {
  1376. case MADIface:
  1377. n = 131072000000000ULL; /* 125 MHz */
  1378. break;
  1379. case MADI:
  1380. case AES32:
  1381. n = 110069313433624ULL; /* 105 MHz */
  1382. break;
  1383. case RayDAT:
  1384. case AIO:
  1385. n = 104857600000000ULL; /* 100 MHz */
  1386. break;
  1387. default:
  1388. snd_BUG();
  1389. return;
  1390. }
  1391. n = div_u64(n, rate);
  1392. /* n should be less than 2^32 for being written to FREQ register */
  1393. snd_BUG_ON(n >> 32);
  1394. hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
  1395. }
  1396. /* dummy set rate lets see what happens */
  1397. static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
  1398. {
  1399. int current_rate;
  1400. int rate_bits;
  1401. int not_set = 0;
  1402. int current_speed, target_speed;
  1403. /* ASSUMPTION: hdspm->lock is either set, or there is no need for
  1404. it (e.g. during module initialization).
  1405. */
  1406. if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
  1407. /* SLAVE --- */
  1408. if (called_internally) {
  1409. /* request from ctl or card initialization
  1410. just make a warning an remember setting
  1411. for future master mode switching */
  1412. dev_warn(hdspm->card->dev,
  1413. "Warning: device is not running as a clock master.\n");
  1414. not_set = 1;
  1415. } else {
  1416. /* hw_param request while in AutoSync mode */
  1417. int external_freq =
  1418. hdspm_external_sample_rate(hdspm);
  1419. if (hdspm_autosync_ref(hdspm) ==
  1420. HDSPM_AUTOSYNC_FROM_NONE) {
  1421. dev_warn(hdspm->card->dev,
  1422. "Detected no Externel Sync\n");
  1423. not_set = 1;
  1424. } else if (rate != external_freq) {
  1425. dev_warn(hdspm->card->dev,
  1426. "Warning: No AutoSync source for requested rate\n");
  1427. not_set = 1;
  1428. }
  1429. }
  1430. }
  1431. current_rate = hdspm->system_sample_rate;
  1432. /* Changing between Singe, Double and Quad speed is not
  1433. allowed if any substreams are open. This is because such a change
  1434. causes a shift in the location of the DMA buffers and a reduction
  1435. in the number of available buffers.
  1436. Note that a similar but essentially insoluble problem exists for
  1437. externally-driven rate changes. All we can do is to flag rate
  1438. changes in the read/write routines.
  1439. */
  1440. if (current_rate <= 48000)
  1441. current_speed = HDSPM_SPEED_SINGLE;
  1442. else if (current_rate <= 96000)
  1443. current_speed = HDSPM_SPEED_DOUBLE;
  1444. else
  1445. current_speed = HDSPM_SPEED_QUAD;
  1446. if (rate <= 48000)
  1447. target_speed = HDSPM_SPEED_SINGLE;
  1448. else if (rate <= 96000)
  1449. target_speed = HDSPM_SPEED_DOUBLE;
  1450. else
  1451. target_speed = HDSPM_SPEED_QUAD;
  1452. switch (rate) {
  1453. case 32000:
  1454. rate_bits = HDSPM_Frequency32KHz;
  1455. break;
  1456. case 44100:
  1457. rate_bits = HDSPM_Frequency44_1KHz;
  1458. break;
  1459. case 48000:
  1460. rate_bits = HDSPM_Frequency48KHz;
  1461. break;
  1462. case 64000:
  1463. rate_bits = HDSPM_Frequency64KHz;
  1464. break;
  1465. case 88200:
  1466. rate_bits = HDSPM_Frequency88_2KHz;
  1467. break;
  1468. case 96000:
  1469. rate_bits = HDSPM_Frequency96KHz;
  1470. break;
  1471. case 128000:
  1472. rate_bits = HDSPM_Frequency128KHz;
  1473. break;
  1474. case 176400:
  1475. rate_bits = HDSPM_Frequency176_4KHz;
  1476. break;
  1477. case 192000:
  1478. rate_bits = HDSPM_Frequency192KHz;
  1479. break;
  1480. default:
  1481. return -EINVAL;
  1482. }
  1483. if (current_speed != target_speed
  1484. && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
  1485. dev_err(hdspm->card->dev,
  1486. "cannot change from %s speed to %s speed mode (capture PID = %d, playback PID = %d)\n",
  1487. hdspm_speed_names[current_speed],
  1488. hdspm_speed_names[target_speed],
  1489. hdspm->capture_pid, hdspm->playback_pid);
  1490. return -EBUSY;
  1491. }
  1492. hdspm->control_register &= ~HDSPM_FrequencyMask;
  1493. hdspm->control_register |= rate_bits;
  1494. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  1495. /* For AES32, need to set DDS value in FREQ register
  1496. For MADI, also apparently */
  1497. hdspm_set_dds_value(hdspm, rate);
  1498. if (AES32 == hdspm->io_type && rate != current_rate)
  1499. hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
  1500. hdspm->system_sample_rate = rate;
  1501. if (rate <= 48000) {
  1502. hdspm->channel_map_in = hdspm->channel_map_in_ss;
  1503. hdspm->channel_map_out = hdspm->channel_map_out_ss;
  1504. hdspm->max_channels_in = hdspm->ss_in_channels;
  1505. hdspm->max_channels_out = hdspm->ss_out_channels;
  1506. hdspm->port_names_in = hdspm->port_names_in_ss;
  1507. hdspm->port_names_out = hdspm->port_names_out_ss;
  1508. } else if (rate <= 96000) {
  1509. hdspm->channel_map_in = hdspm->channel_map_in_ds;
  1510. hdspm->channel_map_out = hdspm->channel_map_out_ds;
  1511. hdspm->max_channels_in = hdspm->ds_in_channels;
  1512. hdspm->max_channels_out = hdspm->ds_out_channels;
  1513. hdspm->port_names_in = hdspm->port_names_in_ds;
  1514. hdspm->port_names_out = hdspm->port_names_out_ds;
  1515. } else {
  1516. hdspm->channel_map_in = hdspm->channel_map_in_qs;
  1517. hdspm->channel_map_out = hdspm->channel_map_out_qs;
  1518. hdspm->max_channels_in = hdspm->qs_in_channels;
  1519. hdspm->max_channels_out = hdspm->qs_out_channels;
  1520. hdspm->port_names_in = hdspm->port_names_in_qs;
  1521. hdspm->port_names_out = hdspm->port_names_out_qs;
  1522. }
  1523. if (not_set != 0)
  1524. return -1;
  1525. return 0;
  1526. }
  1527. /* mainly for init to 0 on load */
  1528. static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
  1529. {
  1530. int i, j;
  1531. unsigned int gain;
  1532. if (sgain > UNITY_GAIN)
  1533. gain = UNITY_GAIN;
  1534. else if (sgain < 0)
  1535. gain = 0;
  1536. else
  1537. gain = sgain;
  1538. for (i = 0; i < HDSPM_MIXER_CHANNELS; i++)
  1539. for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) {
  1540. hdspm_write_in_gain(hdspm, i, j, gain);
  1541. hdspm_write_pb_gain(hdspm, i, j, gain);
  1542. }
  1543. }
  1544. /*----------------------------------------------------------------------------
  1545. MIDI
  1546. ----------------------------------------------------------------------------*/
  1547. static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm,
  1548. int id)
  1549. {
  1550. /* the hardware already does the relevant bit-mask with 0xff */
  1551. return hdspm_read(hdspm, hdspm->midi[id].dataIn);
  1552. }
  1553. static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
  1554. int val)
  1555. {
  1556. /* the hardware already does the relevant bit-mask with 0xff */
  1557. return hdspm_write(hdspm, hdspm->midi[id].dataOut, val);
  1558. }
  1559. static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
  1560. {
  1561. return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF;
  1562. }
  1563. static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
  1564. {
  1565. int fifo_bytes_used;
  1566. fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF;
  1567. if (fifo_bytes_used < 128)
  1568. return 128 - fifo_bytes_used;
  1569. else
  1570. return 0;
  1571. }
  1572. static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
  1573. {
  1574. while (snd_hdspm_midi_input_available (hdspm, id))
  1575. snd_hdspm_midi_read_byte (hdspm, id);
  1576. }
  1577. static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)
  1578. {
  1579. unsigned long flags;
  1580. int n_pending;
  1581. int to_write;
  1582. int i;
  1583. unsigned char buf[128];
  1584. /* Output is not interrupt driven */
  1585. spin_lock_irqsave (&hmidi->lock, flags);
  1586. if (hmidi->output &&
  1587. !snd_rawmidi_transmit_empty (hmidi->output)) {
  1588. n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
  1589. hmidi->id);
  1590. if (n_pending > 0) {
  1591. if (n_pending > (int)sizeof (buf))
  1592. n_pending = sizeof (buf);
  1593. to_write = snd_rawmidi_transmit (hmidi->output, buf,
  1594. n_pending);
  1595. if (to_write > 0) {
  1596. for (i = 0; i < to_write; ++i)
  1597. snd_hdspm_midi_write_byte (hmidi->hdspm,
  1598. hmidi->id,
  1599. buf[i]);
  1600. }
  1601. }
  1602. }
  1603. spin_unlock_irqrestore (&hmidi->lock, flags);
  1604. return 0;
  1605. }
  1606. static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)
  1607. {
  1608. unsigned char buf[128]; /* this buffer is designed to match the MIDI
  1609. * input FIFO size
  1610. */
  1611. unsigned long flags;
  1612. int n_pending;
  1613. int i;
  1614. spin_lock_irqsave (&hmidi->lock, flags);
  1615. n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
  1616. if (n_pending > 0) {
  1617. if (hmidi->input) {
  1618. if (n_pending > (int)sizeof (buf))
  1619. n_pending = sizeof (buf);
  1620. for (i = 0; i < n_pending; ++i)
  1621. buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm,
  1622. hmidi->id);
  1623. if (n_pending)
  1624. snd_rawmidi_receive (hmidi->input, buf,
  1625. n_pending);
  1626. } else {
  1627. /* flush the MIDI input FIFO */
  1628. while (n_pending--)
  1629. snd_hdspm_midi_read_byte (hmidi->hdspm,
  1630. hmidi->id);
  1631. }
  1632. }
  1633. hmidi->pending = 0;
  1634. spin_unlock_irqrestore(&hmidi->lock, flags);
  1635. spin_lock_irqsave(&hmidi->hdspm->lock, flags);
  1636. hmidi->hdspm->control_register |= hmidi->ie;
  1637. hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
  1638. hmidi->hdspm->control_register);
  1639. spin_unlock_irqrestore(&hmidi->hdspm->lock, flags);
  1640. return snd_hdspm_midi_output_write (hmidi);
  1641. }
  1642. static void
  1643. snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  1644. {
  1645. struct hdspm *hdspm;
  1646. struct hdspm_midi *hmidi;
  1647. unsigned long flags;
  1648. hmidi = substream->rmidi->private_data;
  1649. hdspm = hmidi->hdspm;
  1650. spin_lock_irqsave (&hdspm->lock, flags);
  1651. if (up) {
  1652. if (!(hdspm->control_register & hmidi->ie)) {
  1653. snd_hdspm_flush_midi_input (hdspm, hmidi->id);
  1654. hdspm->control_register |= hmidi->ie;
  1655. }
  1656. } else {
  1657. hdspm->control_register &= ~hmidi->ie;
  1658. }
  1659. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  1660. spin_unlock_irqrestore (&hdspm->lock, flags);
  1661. }
  1662. static void snd_hdspm_midi_output_timer(unsigned long data)
  1663. {
  1664. struct hdspm_midi *hmidi = (struct hdspm_midi *) data;
  1665. unsigned long flags;
  1666. snd_hdspm_midi_output_write(hmidi);
  1667. spin_lock_irqsave (&hmidi->lock, flags);
  1668. /* this does not bump hmidi->istimer, because the
  1669. kernel automatically removed the timer when it
  1670. expired, and we are now adding it back, thus
  1671. leaving istimer wherever it was set before.
  1672. */
  1673. if (hmidi->istimer)
  1674. mod_timer(&hmidi->timer, 1 + jiffies);
  1675. spin_unlock_irqrestore (&hmidi->lock, flags);
  1676. }
  1677. static void
  1678. snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
  1679. {
  1680. struct hdspm_midi *hmidi;
  1681. unsigned long flags;
  1682. hmidi = substream->rmidi->private_data;
  1683. spin_lock_irqsave (&hmidi->lock, flags);
  1684. if (up) {
  1685. if (!hmidi->istimer) {
  1686. setup_timer(&hmidi->timer, snd_hdspm_midi_output_timer,
  1687. (unsigned long) hmidi);
  1688. mod_timer(&hmidi->timer, 1 + jiffies);
  1689. hmidi->istimer++;
  1690. }
  1691. } else {
  1692. if (hmidi->istimer && --hmidi->istimer <= 0)
  1693. del_timer (&hmidi->timer);
  1694. }
  1695. spin_unlock_irqrestore (&hmidi->lock, flags);
  1696. if (up)
  1697. snd_hdspm_midi_output_write(hmidi);
  1698. }
  1699. static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)
  1700. {
  1701. struct hdspm_midi *hmidi;
  1702. hmidi = substream->rmidi->private_data;
  1703. spin_lock_irq (&hmidi->lock);
  1704. snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
  1705. hmidi->input = substream;
  1706. spin_unlock_irq (&hmidi->lock);
  1707. return 0;
  1708. }
  1709. static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)
  1710. {
  1711. struct hdspm_midi *hmidi;
  1712. hmidi = substream->rmidi->private_data;
  1713. spin_lock_irq (&hmidi->lock);
  1714. hmidi->output = substream;
  1715. spin_unlock_irq (&hmidi->lock);
  1716. return 0;
  1717. }
  1718. static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)
  1719. {
  1720. struct hdspm_midi *hmidi;
  1721. snd_hdspm_midi_input_trigger (substream, 0);
  1722. hmidi = substream->rmidi->private_data;
  1723. spin_lock_irq (&hmidi->lock);
  1724. hmidi->input = NULL;
  1725. spin_unlock_irq (&hmidi->lock);
  1726. return 0;
  1727. }
  1728. static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)
  1729. {
  1730. struct hdspm_midi *hmidi;
  1731. snd_hdspm_midi_output_trigger (substream, 0);
  1732. hmidi = substream->rmidi->private_data;
  1733. spin_lock_irq (&hmidi->lock);
  1734. hmidi->output = NULL;
  1735. spin_unlock_irq (&hmidi->lock);
  1736. return 0;
  1737. }
  1738. static struct snd_rawmidi_ops snd_hdspm_midi_output =
  1739. {
  1740. .open = snd_hdspm_midi_output_open,
  1741. .close = snd_hdspm_midi_output_close,
  1742. .trigger = snd_hdspm_midi_output_trigger,
  1743. };
  1744. static struct snd_rawmidi_ops snd_hdspm_midi_input =
  1745. {
  1746. .open = snd_hdspm_midi_input_open,
  1747. .close = snd_hdspm_midi_input_close,
  1748. .trigger = snd_hdspm_midi_input_trigger,
  1749. };
  1750. static int snd_hdspm_create_midi(struct snd_card *card,
  1751. struct hdspm *hdspm, int id)
  1752. {
  1753. int err;
  1754. char buf[32];
  1755. hdspm->midi[id].id = id;
  1756. hdspm->midi[id].hdspm = hdspm;
  1757. spin_lock_init (&hdspm->midi[id].lock);
  1758. if (0 == id) {
  1759. if (MADIface == hdspm->io_type) {
  1760. /* MIDI-over-MADI on HDSPe MADIface */
  1761. hdspm->midi[0].dataIn = HDSPM_midiDataIn2;
  1762. hdspm->midi[0].statusIn = HDSPM_midiStatusIn2;
  1763. hdspm->midi[0].dataOut = HDSPM_midiDataOut2;
  1764. hdspm->midi[0].statusOut = HDSPM_midiStatusOut2;
  1765. hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable;
  1766. hdspm->midi[0].irq = HDSPM_midi2IRQPending;
  1767. } else {
  1768. hdspm->midi[0].dataIn = HDSPM_midiDataIn0;
  1769. hdspm->midi[0].statusIn = HDSPM_midiStatusIn0;
  1770. hdspm->midi[0].dataOut = HDSPM_midiDataOut0;
  1771. hdspm->midi[0].statusOut = HDSPM_midiStatusOut0;
  1772. hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable;
  1773. hdspm->midi[0].irq = HDSPM_midi0IRQPending;
  1774. }
  1775. } else if (1 == id) {
  1776. hdspm->midi[1].dataIn = HDSPM_midiDataIn1;
  1777. hdspm->midi[1].statusIn = HDSPM_midiStatusIn1;
  1778. hdspm->midi[1].dataOut = HDSPM_midiDataOut1;
  1779. hdspm->midi[1].statusOut = HDSPM_midiStatusOut1;
  1780. hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable;
  1781. hdspm->midi[1].irq = HDSPM_midi1IRQPending;
  1782. } else if ((2 == id) && (MADI == hdspm->io_type)) {
  1783. /* MIDI-over-MADI on HDSPe MADI */
  1784. hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
  1785. hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
  1786. hdspm->midi[2].dataOut = HDSPM_midiDataOut2;
  1787. hdspm->midi[2].statusOut = HDSPM_midiStatusOut2;
  1788. hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
  1789. hdspm->midi[2].irq = HDSPM_midi2IRQPending;
  1790. } else if (2 == id) {
  1791. /* TCO MTC, read only */
  1792. hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
  1793. hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
  1794. hdspm->midi[2].dataOut = -1;
  1795. hdspm->midi[2].statusOut = -1;
  1796. hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
  1797. hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES;
  1798. } else if (3 == id) {
  1799. /* TCO MTC on HDSPe MADI */
  1800. hdspm->midi[3].dataIn = HDSPM_midiDataIn3;
  1801. hdspm->midi[3].statusIn = HDSPM_midiStatusIn3;
  1802. hdspm->midi[3].dataOut = -1;
  1803. hdspm->midi[3].statusOut = -1;
  1804. hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable;
  1805. hdspm->midi[3].irq = HDSPM_midi3IRQPending;
  1806. }
  1807. if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) ||
  1808. (MADIface == hdspm->io_type)))) {
  1809. if ((id == 0) && (MADIface == hdspm->io_type)) {
  1810. sprintf(buf, "%s MIDIoverMADI", card->shortname);
  1811. } else if ((id == 2) && (MADI == hdspm->io_type)) {
  1812. sprintf(buf, "%s MIDIoverMADI", card->shortname);
  1813. } else {
  1814. sprintf(buf, "%s MIDI %d", card->shortname, id+1);
  1815. }
  1816. err = snd_rawmidi_new(card, buf, id, 1, 1,
  1817. &hdspm->midi[id].rmidi);
  1818. if (err < 0)
  1819. return err;
  1820. sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d",
  1821. card->id, id+1);
  1822. hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
  1823. snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
  1824. SNDRV_RAWMIDI_STREAM_OUTPUT,
  1825. &snd_hdspm_midi_output);
  1826. snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
  1827. SNDRV_RAWMIDI_STREAM_INPUT,
  1828. &snd_hdspm_midi_input);
  1829. hdspm->midi[id].rmidi->info_flags |=
  1830. SNDRV_RAWMIDI_INFO_OUTPUT |
  1831. SNDRV_RAWMIDI_INFO_INPUT |
  1832. SNDRV_RAWMIDI_INFO_DUPLEX;
  1833. } else {
  1834. /* TCO MTC, read only */
  1835. sprintf(buf, "%s MTC %d", card->shortname, id+1);
  1836. err = snd_rawmidi_new(card, buf, id, 1, 1,
  1837. &hdspm->midi[id].rmidi);
  1838. if (err < 0)
  1839. return err;
  1840. sprintf(hdspm->midi[id].rmidi->name,
  1841. "%s MTC %d", card->id, id+1);
  1842. hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
  1843. snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
  1844. SNDRV_RAWMIDI_STREAM_INPUT,
  1845. &snd_hdspm_midi_input);
  1846. hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
  1847. }
  1848. return 0;
  1849. }
  1850. static void hdspm_midi_tasklet(unsigned long arg)
  1851. {
  1852. struct hdspm *hdspm = (struct hdspm *)arg;
  1853. int i = 0;
  1854. while (i < hdspm->midiPorts) {
  1855. if (hdspm->midi[i].pending)
  1856. snd_hdspm_midi_input_read(&hdspm->midi[i]);
  1857. i++;
  1858. }
  1859. }
  1860. /*-----------------------------------------------------------------------------
  1861. Status Interface
  1862. ----------------------------------------------------------------------------*/
  1863. /* get the system sample rate which is set */
  1864. static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
  1865. {
  1866. unsigned int period, rate;
  1867. period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
  1868. rate = hdspm_calc_dds_value(hdspm, period);
  1869. return rate;
  1870. }
  1871. /*
  1872. * Calculate the real sample rate from the
  1873. * current DDS value.
  1874. */
  1875. static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
  1876. {
  1877. unsigned int rate;
  1878. rate = hdspm_get_pll_freq(hdspm);
  1879. if (rate > 207000) {
  1880. /* Unreasonable high sample rate as seen on PCI MADI cards. */
  1881. if (0 == hdspm_system_clock_mode(hdspm)) {
  1882. /* master mode, return internal sample rate */
  1883. rate = hdspm->system_sample_rate;
  1884. } else {
  1885. /* slave mode, return external sample rate */
  1886. rate = hdspm_external_sample_rate(hdspm);
  1887. if (!rate)
  1888. rate = hdspm->system_sample_rate;
  1889. }
  1890. }
  1891. return rate;
  1892. }
  1893. #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
  1894. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1895. .name = xname, \
  1896. .index = xindex, \
  1897. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  1898. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  1899. .info = snd_hdspm_info_system_sample_rate, \
  1900. .put = snd_hdspm_put_system_sample_rate, \
  1901. .get = snd_hdspm_get_system_sample_rate \
  1902. }
  1903. static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol,
  1904. struct snd_ctl_elem_info *uinfo)
  1905. {
  1906. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1907. uinfo->count = 1;
  1908. uinfo->value.integer.min = 27000;
  1909. uinfo->value.integer.max = 207000;
  1910. uinfo->value.integer.step = 1;
  1911. return 0;
  1912. }
  1913. static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol,
  1914. struct snd_ctl_elem_value *
  1915. ucontrol)
  1916. {
  1917. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  1918. ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm);
  1919. return 0;
  1920. }
  1921. static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
  1922. struct snd_ctl_elem_value *
  1923. ucontrol)
  1924. {
  1925. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  1926. int rate = ucontrol->value.integer.value[0];
  1927. if (rate < 27000 || rate > 207000)
  1928. return -EINVAL;
  1929. hdspm_set_dds_value(hdspm, ucontrol->value.integer.value[0]);
  1930. return 0;
  1931. }
  1932. /*
  1933. * Returns the WordClock sample rate class for the given card.
  1934. */
  1935. static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
  1936. {
  1937. int status;
  1938. switch (hdspm->io_type) {
  1939. case RayDAT:
  1940. case AIO:
  1941. status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
  1942. return (status >> 16) & 0xF;
  1943. break;
  1944. case AES32:
  1945. status = hdspm_read(hdspm, HDSPM_statusRegister);
  1946. return (status >> HDSPM_AES32_wcFreq_bit) & 0xF;
  1947. default:
  1948. break;
  1949. }
  1950. return 0;
  1951. }
  1952. /*
  1953. * Returns the TCO sample rate class for the given card.
  1954. */
  1955. static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
  1956. {
  1957. int status;
  1958. if (hdspm->tco) {
  1959. switch (hdspm->io_type) {
  1960. case RayDAT:
  1961. case AIO:
  1962. status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
  1963. return (status >> 20) & 0xF;
  1964. break;
  1965. case AES32:
  1966. status = hdspm_read(hdspm, HDSPM_statusRegister);
  1967. return (status >> 1) & 0xF;
  1968. default:
  1969. break;
  1970. }
  1971. }
  1972. return 0;
  1973. }
  1974. /*
  1975. * Returns the SYNC_IN sample rate class for the given card.
  1976. */
  1977. static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
  1978. {
  1979. int status;
  1980. if (hdspm->tco) {
  1981. switch (hdspm->io_type) {
  1982. case RayDAT:
  1983. case AIO:
  1984. status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
  1985. return (status >> 12) & 0xF;
  1986. break;
  1987. default:
  1988. break;
  1989. }
  1990. }
  1991. return 0;
  1992. }
  1993. /*
  1994. * Returns the AES sample rate class for the given card.
  1995. */
  1996. static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
  1997. {
  1998. int timecode;
  1999. switch (hdspm->io_type) {
  2000. case AES32:
  2001. timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
  2002. return (timecode >> (4*index)) & 0xF;
  2003. break;
  2004. default:
  2005. break;
  2006. }
  2007. return 0;
  2008. }
  2009. /*
  2010. * Returns the sample rate class for input source <idx> for
  2011. * 'new style' cards like the AIO and RayDAT.
  2012. */
  2013. static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
  2014. {
  2015. int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
  2016. return (status >> (idx*4)) & 0xF;
  2017. }
  2018. #define ENUMERATED_CTL_INFO(info, texts) \
  2019. snd_ctl_enum_info(info, 1, ARRAY_SIZE(texts), texts)
  2020. /* Helper function to query the external sample rate and return the
  2021. * corresponding enum to be returned to userspace.
  2022. */
  2023. static int hdspm_external_rate_to_enum(struct hdspm *hdspm)
  2024. {
  2025. int rate = hdspm_external_sample_rate(hdspm);
  2026. int i, selected_rate = 0;
  2027. for (i = 1; i < 10; i++)
  2028. if (HDSPM_bit2freq(i) == rate) {
  2029. selected_rate = i;
  2030. break;
  2031. }
  2032. return selected_rate;
  2033. }
  2034. #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
  2035. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2036. .name = xname, \
  2037. .private_value = xindex, \
  2038. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  2039. .info = snd_hdspm_info_autosync_sample_rate, \
  2040. .get = snd_hdspm_get_autosync_sample_rate \
  2041. }
  2042. static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
  2043. struct snd_ctl_elem_info *uinfo)
  2044. {
  2045. ENUMERATED_CTL_INFO(uinfo, texts_freq);
  2046. return 0;
  2047. }
  2048. static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
  2049. struct snd_ctl_elem_value *
  2050. ucontrol)
  2051. {
  2052. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2053. switch (hdspm->io_type) {
  2054. case RayDAT:
  2055. switch (kcontrol->private_value) {
  2056. case 0:
  2057. ucontrol->value.enumerated.item[0] =
  2058. hdspm_get_wc_sample_rate(hdspm);
  2059. break;
  2060. case 7:
  2061. ucontrol->value.enumerated.item[0] =
  2062. hdspm_get_tco_sample_rate(hdspm);
  2063. break;
  2064. case 8:
  2065. ucontrol->value.enumerated.item[0] =
  2066. hdspm_get_sync_in_sample_rate(hdspm);
  2067. break;
  2068. default:
  2069. ucontrol->value.enumerated.item[0] =
  2070. hdspm_get_s1_sample_rate(hdspm,
  2071. kcontrol->private_value-1);
  2072. }
  2073. break;
  2074. case AIO:
  2075. switch (kcontrol->private_value) {
  2076. case 0: /* WC */
  2077. ucontrol->value.enumerated.item[0] =
  2078. hdspm_get_wc_sample_rate(hdspm);
  2079. break;
  2080. case 4: /* TCO */
  2081. ucontrol->value.enumerated.item[0] =
  2082. hdspm_get_tco_sample_rate(hdspm);
  2083. break;
  2084. case 5: /* SYNC_IN */
  2085. ucontrol->value.enumerated.item[0] =
  2086. hdspm_get_sync_in_sample_rate(hdspm);
  2087. break;
  2088. default:
  2089. ucontrol->value.enumerated.item[0] =
  2090. hdspm_get_s1_sample_rate(hdspm,
  2091. kcontrol->private_value-1);
  2092. }
  2093. break;
  2094. case AES32:
  2095. switch (kcontrol->private_value) {
  2096. case 0: /* WC */
  2097. ucontrol->value.enumerated.item[0] =
  2098. hdspm_get_wc_sample_rate(hdspm);
  2099. break;
  2100. case 9: /* TCO */
  2101. ucontrol->value.enumerated.item[0] =
  2102. hdspm_get_tco_sample_rate(hdspm);
  2103. break;
  2104. case 10: /* SYNC_IN */
  2105. ucontrol->value.enumerated.item[0] =
  2106. hdspm_get_sync_in_sample_rate(hdspm);
  2107. break;
  2108. case 11: /* External Rate */
  2109. ucontrol->value.enumerated.item[0] =
  2110. hdspm_external_rate_to_enum(hdspm);
  2111. break;
  2112. default: /* AES1 to AES8 */
  2113. ucontrol->value.enumerated.item[0] =
  2114. hdspm_get_aes_sample_rate(hdspm,
  2115. kcontrol->private_value -
  2116. HDSPM_AES32_AUTOSYNC_FROM_AES1);
  2117. break;
  2118. }
  2119. break;
  2120. case MADI:
  2121. case MADIface:
  2122. ucontrol->value.enumerated.item[0] =
  2123. hdspm_external_rate_to_enum(hdspm);
  2124. break;
  2125. default:
  2126. break;
  2127. }
  2128. return 0;
  2129. }
  2130. #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
  2131. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2132. .name = xname, \
  2133. .index = xindex, \
  2134. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  2135. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2136. .info = snd_hdspm_info_system_clock_mode, \
  2137. .get = snd_hdspm_get_system_clock_mode, \
  2138. .put = snd_hdspm_put_system_clock_mode, \
  2139. }
  2140. /*
  2141. * Returns the system clock mode for the given card.
  2142. * @returns 0 - master, 1 - slave
  2143. */
  2144. static int hdspm_system_clock_mode(struct hdspm *hdspm)
  2145. {
  2146. switch (hdspm->io_type) {
  2147. case AIO:
  2148. case RayDAT:
  2149. if (hdspm->settings_register & HDSPM_c0Master)
  2150. return 0;
  2151. break;
  2152. default:
  2153. if (hdspm->control_register & HDSPM_ClockModeMaster)
  2154. return 0;
  2155. }
  2156. return 1;
  2157. }
  2158. /*
  2159. * Sets the system clock mode.
  2160. * @param mode 0 - master, 1 - slave
  2161. */
  2162. static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
  2163. {
  2164. hdspm_set_toggle_setting(hdspm,
  2165. (hdspm_is_raydat_or_aio(hdspm)) ?
  2166. HDSPM_c0Master : HDSPM_ClockModeMaster,
  2167. (0 == mode));
  2168. }
  2169. static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
  2170. struct snd_ctl_elem_info *uinfo)
  2171. {
  2172. static const char *const texts[] = { "Master", "AutoSync" };
  2173. ENUMERATED_CTL_INFO(uinfo, texts);
  2174. return 0;
  2175. }
  2176. static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol,
  2177. struct snd_ctl_elem_value *ucontrol)
  2178. {
  2179. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2180. ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm);
  2181. return 0;
  2182. }
  2183. static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol,
  2184. struct snd_ctl_elem_value *ucontrol)
  2185. {
  2186. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2187. int val;
  2188. if (!snd_hdspm_use_is_exclusive(hdspm))
  2189. return -EBUSY;
  2190. val = ucontrol->value.enumerated.item[0];
  2191. if (val < 0)
  2192. val = 0;
  2193. else if (val > 1)
  2194. val = 1;
  2195. hdspm_set_system_clock_mode(hdspm, val);
  2196. return 0;
  2197. }
  2198. #define HDSPM_INTERNAL_CLOCK(xname, xindex) \
  2199. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2200. .name = xname, \
  2201. .index = xindex, \
  2202. .info = snd_hdspm_info_clock_source, \
  2203. .get = snd_hdspm_get_clock_source, \
  2204. .put = snd_hdspm_put_clock_source \
  2205. }
  2206. static int hdspm_clock_source(struct hdspm * hdspm)
  2207. {
  2208. switch (hdspm->system_sample_rate) {
  2209. case 32000: return 0;
  2210. case 44100: return 1;
  2211. case 48000: return 2;
  2212. case 64000: return 3;
  2213. case 88200: return 4;
  2214. case 96000: return 5;
  2215. case 128000: return 6;
  2216. case 176400: return 7;
  2217. case 192000: return 8;
  2218. }
  2219. return -1;
  2220. }
  2221. static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
  2222. {
  2223. int rate;
  2224. switch (mode) {
  2225. case 0:
  2226. rate = 32000; break;
  2227. case 1:
  2228. rate = 44100; break;
  2229. case 2:
  2230. rate = 48000; break;
  2231. case 3:
  2232. rate = 64000; break;
  2233. case 4:
  2234. rate = 88200; break;
  2235. case 5:
  2236. rate = 96000; break;
  2237. case 6:
  2238. rate = 128000; break;
  2239. case 7:
  2240. rate = 176400; break;
  2241. case 8:
  2242. rate = 192000; break;
  2243. default:
  2244. rate = 48000;
  2245. }
  2246. hdspm_set_rate(hdspm, rate, 1);
  2247. return 0;
  2248. }
  2249. static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
  2250. struct snd_ctl_elem_info *uinfo)
  2251. {
  2252. return snd_ctl_enum_info(uinfo, 1, 9, texts_freq + 1);
  2253. }
  2254. static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
  2255. struct snd_ctl_elem_value *ucontrol)
  2256. {
  2257. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2258. ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
  2259. return 0;
  2260. }
  2261. static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
  2262. struct snd_ctl_elem_value *ucontrol)
  2263. {
  2264. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2265. int change;
  2266. int val;
  2267. if (!snd_hdspm_use_is_exclusive(hdspm))
  2268. return -EBUSY;
  2269. val = ucontrol->value.enumerated.item[0];
  2270. if (val < 0)
  2271. val = 0;
  2272. if (val > 9)
  2273. val = 9;
  2274. spin_lock_irq(&hdspm->lock);
  2275. if (val != hdspm_clock_source(hdspm))
  2276. change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
  2277. else
  2278. change = 0;
  2279. spin_unlock_irq(&hdspm->lock);
  2280. return change;
  2281. }
  2282. #define HDSPM_PREF_SYNC_REF(xname, xindex) \
  2283. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2284. .name = xname, \
  2285. .index = xindex, \
  2286. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  2287. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2288. .info = snd_hdspm_info_pref_sync_ref, \
  2289. .get = snd_hdspm_get_pref_sync_ref, \
  2290. .put = snd_hdspm_put_pref_sync_ref \
  2291. }
  2292. /*
  2293. * Returns the current preferred sync reference setting.
  2294. * The semantics of the return value are depending on the
  2295. * card, please see the comments for clarification.
  2296. */
  2297. static int hdspm_pref_sync_ref(struct hdspm * hdspm)
  2298. {
  2299. switch (hdspm->io_type) {
  2300. case AES32:
  2301. switch (hdspm->control_register & HDSPM_SyncRefMask) {
  2302. case 0: return 0; /* WC */
  2303. case HDSPM_SyncRef0: return 1; /* AES 1 */
  2304. case HDSPM_SyncRef1: return 2; /* AES 2 */
  2305. case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */
  2306. case HDSPM_SyncRef2: return 4; /* AES 4 */
  2307. case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */
  2308. case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */
  2309. case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0:
  2310. return 7; /* AES 7 */
  2311. case HDSPM_SyncRef3: return 8; /* AES 8 */
  2312. case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */
  2313. }
  2314. break;
  2315. case MADI:
  2316. case MADIface:
  2317. if (hdspm->tco) {
  2318. switch (hdspm->control_register & HDSPM_SyncRefMask) {
  2319. case 0: return 0; /* WC */
  2320. case HDSPM_SyncRef0: return 1; /* MADI */
  2321. case HDSPM_SyncRef1: return 2; /* TCO */
  2322. case HDSPM_SyncRef1+HDSPM_SyncRef0:
  2323. return 3; /* SYNC_IN */
  2324. }
  2325. } else {
  2326. switch (hdspm->control_register & HDSPM_SyncRefMask) {
  2327. case 0: return 0; /* WC */
  2328. case HDSPM_SyncRef0: return 1; /* MADI */
  2329. case HDSPM_SyncRef1+HDSPM_SyncRef0:
  2330. return 2; /* SYNC_IN */
  2331. }
  2332. }
  2333. break;
  2334. case RayDAT:
  2335. if (hdspm->tco) {
  2336. switch ((hdspm->settings_register &
  2337. HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
  2338. case 0: return 0; /* WC */
  2339. case 3: return 1; /* ADAT 1 */
  2340. case 4: return 2; /* ADAT 2 */
  2341. case 5: return 3; /* ADAT 3 */
  2342. case 6: return 4; /* ADAT 4 */
  2343. case 1: return 5; /* AES */
  2344. case 2: return 6; /* SPDIF */
  2345. case 9: return 7; /* TCO */
  2346. case 10: return 8; /* SYNC_IN */
  2347. }
  2348. } else {
  2349. switch ((hdspm->settings_register &
  2350. HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
  2351. case 0: return 0; /* WC */
  2352. case 3: return 1; /* ADAT 1 */
  2353. case 4: return 2; /* ADAT 2 */
  2354. case 5: return 3; /* ADAT 3 */
  2355. case 6: return 4; /* ADAT 4 */
  2356. case 1: return 5; /* AES */
  2357. case 2: return 6; /* SPDIF */
  2358. case 10: return 7; /* SYNC_IN */
  2359. }
  2360. }
  2361. break;
  2362. case AIO:
  2363. if (hdspm->tco) {
  2364. switch ((hdspm->settings_register &
  2365. HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
  2366. case 0: return 0; /* WC */
  2367. case 3: return 1; /* ADAT */
  2368. case 1: return 2; /* AES */
  2369. case 2: return 3; /* SPDIF */
  2370. case 9: return 4; /* TCO */
  2371. case 10: return 5; /* SYNC_IN */
  2372. }
  2373. } else {
  2374. switch ((hdspm->settings_register &
  2375. HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
  2376. case 0: return 0; /* WC */
  2377. case 3: return 1; /* ADAT */
  2378. case 1: return 2; /* AES */
  2379. case 2: return 3; /* SPDIF */
  2380. case 10: return 4; /* SYNC_IN */
  2381. }
  2382. }
  2383. break;
  2384. }
  2385. return -1;
  2386. }
  2387. /*
  2388. * Set the preferred sync reference to <pref>. The semantics
  2389. * of <pref> are depending on the card type, see the comments
  2390. * for clarification.
  2391. */
  2392. static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
  2393. {
  2394. int p = 0;
  2395. switch (hdspm->io_type) {
  2396. case AES32:
  2397. hdspm->control_register &= ~HDSPM_SyncRefMask;
  2398. switch (pref) {
  2399. case 0: /* WC */
  2400. break;
  2401. case 1: /* AES 1 */
  2402. hdspm->control_register |= HDSPM_SyncRef0;
  2403. break;
  2404. case 2: /* AES 2 */
  2405. hdspm->control_register |= HDSPM_SyncRef1;
  2406. break;
  2407. case 3: /* AES 3 */
  2408. hdspm->control_register |=
  2409. HDSPM_SyncRef1+HDSPM_SyncRef0;
  2410. break;
  2411. case 4: /* AES 4 */
  2412. hdspm->control_register |= HDSPM_SyncRef2;
  2413. break;
  2414. case 5: /* AES 5 */
  2415. hdspm->control_register |=
  2416. HDSPM_SyncRef2+HDSPM_SyncRef0;
  2417. break;
  2418. case 6: /* AES 6 */
  2419. hdspm->control_register |=
  2420. HDSPM_SyncRef2+HDSPM_SyncRef1;
  2421. break;
  2422. case 7: /* AES 7 */
  2423. hdspm->control_register |=
  2424. HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
  2425. break;
  2426. case 8: /* AES 8 */
  2427. hdspm->control_register |= HDSPM_SyncRef3;
  2428. break;
  2429. case 9: /* TCO */
  2430. hdspm->control_register |=
  2431. HDSPM_SyncRef3+HDSPM_SyncRef0;
  2432. break;
  2433. default:
  2434. return -1;
  2435. }
  2436. break;
  2437. case MADI:
  2438. case MADIface:
  2439. hdspm->control_register &= ~HDSPM_SyncRefMask;
  2440. if (hdspm->tco) {
  2441. switch (pref) {
  2442. case 0: /* WC */
  2443. break;
  2444. case 1: /* MADI */
  2445. hdspm->control_register |= HDSPM_SyncRef0;
  2446. break;
  2447. case 2: /* TCO */
  2448. hdspm->control_register |= HDSPM_SyncRef1;
  2449. break;
  2450. case 3: /* SYNC_IN */
  2451. hdspm->control_register |=
  2452. HDSPM_SyncRef0+HDSPM_SyncRef1;
  2453. break;
  2454. default:
  2455. return -1;
  2456. }
  2457. } else {
  2458. switch (pref) {
  2459. case 0: /* WC */
  2460. break;
  2461. case 1: /* MADI */
  2462. hdspm->control_register |= HDSPM_SyncRef0;
  2463. break;
  2464. case 2: /* SYNC_IN */
  2465. hdspm->control_register |=
  2466. HDSPM_SyncRef0+HDSPM_SyncRef1;
  2467. break;
  2468. default:
  2469. return -1;
  2470. }
  2471. }
  2472. break;
  2473. case RayDAT:
  2474. if (hdspm->tco) {
  2475. switch (pref) {
  2476. case 0: p = 0; break; /* WC */
  2477. case 1: p = 3; break; /* ADAT 1 */
  2478. case 2: p = 4; break; /* ADAT 2 */
  2479. case 3: p = 5; break; /* ADAT 3 */
  2480. case 4: p = 6; break; /* ADAT 4 */
  2481. case 5: p = 1; break; /* AES */
  2482. case 6: p = 2; break; /* SPDIF */
  2483. case 7: p = 9; break; /* TCO */
  2484. case 8: p = 10; break; /* SYNC_IN */
  2485. default: return -1;
  2486. }
  2487. } else {
  2488. switch (pref) {
  2489. case 0: p = 0; break; /* WC */
  2490. case 1: p = 3; break; /* ADAT 1 */
  2491. case 2: p = 4; break; /* ADAT 2 */
  2492. case 3: p = 5; break; /* ADAT 3 */
  2493. case 4: p = 6; break; /* ADAT 4 */
  2494. case 5: p = 1; break; /* AES */
  2495. case 6: p = 2; break; /* SPDIF */
  2496. case 7: p = 10; break; /* SYNC_IN */
  2497. default: return -1;
  2498. }
  2499. }
  2500. break;
  2501. case AIO:
  2502. if (hdspm->tco) {
  2503. switch (pref) {
  2504. case 0: p = 0; break; /* WC */
  2505. case 1: p = 3; break; /* ADAT */
  2506. case 2: p = 1; break; /* AES */
  2507. case 3: p = 2; break; /* SPDIF */
  2508. case 4: p = 9; break; /* TCO */
  2509. case 5: p = 10; break; /* SYNC_IN */
  2510. default: return -1;
  2511. }
  2512. } else {
  2513. switch (pref) {
  2514. case 0: p = 0; break; /* WC */
  2515. case 1: p = 3; break; /* ADAT */
  2516. case 2: p = 1; break; /* AES */
  2517. case 3: p = 2; break; /* SPDIF */
  2518. case 4: p = 10; break; /* SYNC_IN */
  2519. default: return -1;
  2520. }
  2521. }
  2522. break;
  2523. }
  2524. switch (hdspm->io_type) {
  2525. case RayDAT:
  2526. case AIO:
  2527. hdspm->settings_register &= ~HDSPM_c0_SyncRefMask;
  2528. hdspm->settings_register |= HDSPM_c0_SyncRef0 * p;
  2529. hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
  2530. break;
  2531. case MADI:
  2532. case MADIface:
  2533. case AES32:
  2534. hdspm_write(hdspm, HDSPM_controlRegister,
  2535. hdspm->control_register);
  2536. }
  2537. return 0;
  2538. }
  2539. static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol,
  2540. struct snd_ctl_elem_info *uinfo)
  2541. {
  2542. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2543. snd_ctl_enum_info(uinfo, 1, hdspm->texts_autosync_items, hdspm->texts_autosync);
  2544. return 0;
  2545. }
  2546. static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol,
  2547. struct snd_ctl_elem_value *ucontrol)
  2548. {
  2549. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2550. int psf = hdspm_pref_sync_ref(hdspm);
  2551. if (psf >= 0) {
  2552. ucontrol->value.enumerated.item[0] = psf;
  2553. return 0;
  2554. }
  2555. return -1;
  2556. }
  2557. static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,
  2558. struct snd_ctl_elem_value *ucontrol)
  2559. {
  2560. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2561. int val, change = 0;
  2562. if (!snd_hdspm_use_is_exclusive(hdspm))
  2563. return -EBUSY;
  2564. val = ucontrol->value.enumerated.item[0];
  2565. if (val < 0)
  2566. val = 0;
  2567. else if (val >= hdspm->texts_autosync_items)
  2568. val = hdspm->texts_autosync_items-1;
  2569. spin_lock_irq(&hdspm->lock);
  2570. if (val != hdspm_pref_sync_ref(hdspm))
  2571. change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0;
  2572. spin_unlock_irq(&hdspm->lock);
  2573. return change;
  2574. }
  2575. #define HDSPM_AUTOSYNC_REF(xname, xindex) \
  2576. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2577. .name = xname, \
  2578. .index = xindex, \
  2579. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  2580. .info = snd_hdspm_info_autosync_ref, \
  2581. .get = snd_hdspm_get_autosync_ref, \
  2582. }
  2583. static int hdspm_autosync_ref(struct hdspm *hdspm)
  2584. {
  2585. /* This looks at the autosync selected sync reference */
  2586. if (AES32 == hdspm->io_type) {
  2587. unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
  2588. unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF;
  2589. if ((syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD) &&
  2590. (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN)) {
  2591. return syncref;
  2592. }
  2593. return HDSPM_AES32_AUTOSYNC_FROM_NONE;
  2594. } else if (MADI == hdspm->io_type) {
  2595. unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  2596. switch (status2 & HDSPM_SelSyncRefMask) {
  2597. case HDSPM_SelSyncRef_WORD:
  2598. return HDSPM_AUTOSYNC_FROM_WORD;
  2599. case HDSPM_SelSyncRef_MADI:
  2600. return HDSPM_AUTOSYNC_FROM_MADI;
  2601. case HDSPM_SelSyncRef_TCO:
  2602. return HDSPM_AUTOSYNC_FROM_TCO;
  2603. case HDSPM_SelSyncRef_SyncIn:
  2604. return HDSPM_AUTOSYNC_FROM_SYNC_IN;
  2605. case HDSPM_SelSyncRef_NVALID:
  2606. return HDSPM_AUTOSYNC_FROM_NONE;
  2607. default:
  2608. return HDSPM_AUTOSYNC_FROM_NONE;
  2609. }
  2610. }
  2611. return 0;
  2612. }
  2613. static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol,
  2614. struct snd_ctl_elem_info *uinfo)
  2615. {
  2616. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2617. if (AES32 == hdspm->io_type) {
  2618. static const char *const texts[] = { "WordClock", "AES1", "AES2", "AES3",
  2619. "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In", "None"};
  2620. ENUMERATED_CTL_INFO(uinfo, texts);
  2621. } else if (MADI == hdspm->io_type) {
  2622. static const char *const texts[] = {"Word Clock", "MADI", "TCO",
  2623. "Sync In", "None" };
  2624. ENUMERATED_CTL_INFO(uinfo, texts);
  2625. }
  2626. return 0;
  2627. }
  2628. static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
  2629. struct snd_ctl_elem_value *ucontrol)
  2630. {
  2631. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2632. ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm);
  2633. return 0;
  2634. }
  2635. #define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \
  2636. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2637. .name = xname, \
  2638. .access = SNDRV_CTL_ELEM_ACCESS_READ |\
  2639. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2640. .info = snd_hdspm_info_tco_video_input_format, \
  2641. .get = snd_hdspm_get_tco_video_input_format, \
  2642. }
  2643. static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol,
  2644. struct snd_ctl_elem_info *uinfo)
  2645. {
  2646. static const char *const texts[] = {"No video", "NTSC", "PAL"};
  2647. ENUMERATED_CTL_INFO(uinfo, texts);
  2648. return 0;
  2649. }
  2650. static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol,
  2651. struct snd_ctl_elem_value *ucontrol)
  2652. {
  2653. u32 status;
  2654. int ret = 0;
  2655. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2656. status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
  2657. switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC |
  2658. HDSPM_TCO1_Video_Input_Format_PAL)) {
  2659. case HDSPM_TCO1_Video_Input_Format_NTSC:
  2660. /* ntsc */
  2661. ret = 1;
  2662. break;
  2663. case HDSPM_TCO1_Video_Input_Format_PAL:
  2664. /* pal */
  2665. ret = 2;
  2666. break;
  2667. default:
  2668. /* no video */
  2669. ret = 0;
  2670. break;
  2671. }
  2672. ucontrol->value.enumerated.item[0] = ret;
  2673. return 0;
  2674. }
  2675. #define HDSPM_TCO_LTC_FRAMES(xname, xindex) \
  2676. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2677. .name = xname, \
  2678. .access = SNDRV_CTL_ELEM_ACCESS_READ |\
  2679. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2680. .info = snd_hdspm_info_tco_ltc_frames, \
  2681. .get = snd_hdspm_get_tco_ltc_frames, \
  2682. }
  2683. static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol,
  2684. struct snd_ctl_elem_info *uinfo)
  2685. {
  2686. static const char *const texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps",
  2687. "30 fps"};
  2688. ENUMERATED_CTL_INFO(uinfo, texts);
  2689. return 0;
  2690. }
  2691. static int hdspm_tco_ltc_frames(struct hdspm *hdspm)
  2692. {
  2693. u32 status;
  2694. int ret = 0;
  2695. status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
  2696. if (status & HDSPM_TCO1_LTC_Input_valid) {
  2697. switch (status & (HDSPM_TCO1_LTC_Format_LSB |
  2698. HDSPM_TCO1_LTC_Format_MSB)) {
  2699. case 0:
  2700. /* 24 fps */
  2701. ret = fps_24;
  2702. break;
  2703. case HDSPM_TCO1_LTC_Format_LSB:
  2704. /* 25 fps */
  2705. ret = fps_25;
  2706. break;
  2707. case HDSPM_TCO1_LTC_Format_MSB:
  2708. /* 29.97 fps */
  2709. ret = fps_2997;
  2710. break;
  2711. default:
  2712. /* 30 fps */
  2713. ret = fps_30;
  2714. break;
  2715. }
  2716. }
  2717. return ret;
  2718. }
  2719. static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol,
  2720. struct snd_ctl_elem_value *ucontrol)
  2721. {
  2722. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2723. ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm);
  2724. return 0;
  2725. }
  2726. #define HDSPM_TOGGLE_SETTING(xname, xindex) \
  2727. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2728. .name = xname, \
  2729. .private_value = xindex, \
  2730. .info = snd_hdspm_info_toggle_setting, \
  2731. .get = snd_hdspm_get_toggle_setting, \
  2732. .put = snd_hdspm_put_toggle_setting \
  2733. }
  2734. static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask)
  2735. {
  2736. u32 reg;
  2737. if (hdspm_is_raydat_or_aio(hdspm))
  2738. reg = hdspm->settings_register;
  2739. else
  2740. reg = hdspm->control_register;
  2741. return (reg & regmask) ? 1 : 0;
  2742. }
  2743. static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out)
  2744. {
  2745. u32 *reg;
  2746. u32 target_reg;
  2747. if (hdspm_is_raydat_or_aio(hdspm)) {
  2748. reg = &(hdspm->settings_register);
  2749. target_reg = HDSPM_WR_SETTINGS;
  2750. } else {
  2751. reg = &(hdspm->control_register);
  2752. target_reg = HDSPM_controlRegister;
  2753. }
  2754. if (out)
  2755. *reg |= regmask;
  2756. else
  2757. *reg &= ~regmask;
  2758. hdspm_write(hdspm, target_reg, *reg);
  2759. return 0;
  2760. }
  2761. #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info
  2762. static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol,
  2763. struct snd_ctl_elem_value *ucontrol)
  2764. {
  2765. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2766. u32 regmask = kcontrol->private_value;
  2767. spin_lock_irq(&hdspm->lock);
  2768. ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask);
  2769. spin_unlock_irq(&hdspm->lock);
  2770. return 0;
  2771. }
  2772. static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol,
  2773. struct snd_ctl_elem_value *ucontrol)
  2774. {
  2775. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2776. u32 regmask = kcontrol->private_value;
  2777. int change;
  2778. unsigned int val;
  2779. if (!snd_hdspm_use_is_exclusive(hdspm))
  2780. return -EBUSY;
  2781. val = ucontrol->value.integer.value[0] & 1;
  2782. spin_lock_irq(&hdspm->lock);
  2783. change = (int) val != hdspm_toggle_setting(hdspm, regmask);
  2784. hdspm_set_toggle_setting(hdspm, regmask, val);
  2785. spin_unlock_irq(&hdspm->lock);
  2786. return change;
  2787. }
  2788. #define HDSPM_INPUT_SELECT(xname, xindex) \
  2789. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2790. .name = xname, \
  2791. .index = xindex, \
  2792. .info = snd_hdspm_info_input_select, \
  2793. .get = snd_hdspm_get_input_select, \
  2794. .put = snd_hdspm_put_input_select \
  2795. }
  2796. static int hdspm_input_select(struct hdspm * hdspm)
  2797. {
  2798. return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
  2799. }
  2800. static int hdspm_set_input_select(struct hdspm * hdspm, int out)
  2801. {
  2802. if (out)
  2803. hdspm->control_register |= HDSPM_InputSelect0;
  2804. else
  2805. hdspm->control_register &= ~HDSPM_InputSelect0;
  2806. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  2807. return 0;
  2808. }
  2809. static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
  2810. struct snd_ctl_elem_info *uinfo)
  2811. {
  2812. static const char *const texts[] = { "optical", "coaxial" };
  2813. ENUMERATED_CTL_INFO(uinfo, texts);
  2814. return 0;
  2815. }
  2816. static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol,
  2817. struct snd_ctl_elem_value *ucontrol)
  2818. {
  2819. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2820. spin_lock_irq(&hdspm->lock);
  2821. ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
  2822. spin_unlock_irq(&hdspm->lock);
  2823. return 0;
  2824. }
  2825. static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,
  2826. struct snd_ctl_elem_value *ucontrol)
  2827. {
  2828. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2829. int change;
  2830. unsigned int val;
  2831. if (!snd_hdspm_use_is_exclusive(hdspm))
  2832. return -EBUSY;
  2833. val = ucontrol->value.integer.value[0] & 1;
  2834. spin_lock_irq(&hdspm->lock);
  2835. change = (int) val != hdspm_input_select(hdspm);
  2836. hdspm_set_input_select(hdspm, val);
  2837. spin_unlock_irq(&hdspm->lock);
  2838. return change;
  2839. }
  2840. #define HDSPM_DS_WIRE(xname, xindex) \
  2841. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2842. .name = xname, \
  2843. .index = xindex, \
  2844. .info = snd_hdspm_info_ds_wire, \
  2845. .get = snd_hdspm_get_ds_wire, \
  2846. .put = snd_hdspm_put_ds_wire \
  2847. }
  2848. static int hdspm_ds_wire(struct hdspm * hdspm)
  2849. {
  2850. return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
  2851. }
  2852. static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
  2853. {
  2854. if (ds)
  2855. hdspm->control_register |= HDSPM_DS_DoubleWire;
  2856. else
  2857. hdspm->control_register &= ~HDSPM_DS_DoubleWire;
  2858. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  2859. return 0;
  2860. }
  2861. static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
  2862. struct snd_ctl_elem_info *uinfo)
  2863. {
  2864. static const char *const texts[] = { "Single", "Double" };
  2865. ENUMERATED_CTL_INFO(uinfo, texts);
  2866. return 0;
  2867. }
  2868. static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol,
  2869. struct snd_ctl_elem_value *ucontrol)
  2870. {
  2871. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2872. spin_lock_irq(&hdspm->lock);
  2873. ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
  2874. spin_unlock_irq(&hdspm->lock);
  2875. return 0;
  2876. }
  2877. static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,
  2878. struct snd_ctl_elem_value *ucontrol)
  2879. {
  2880. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2881. int change;
  2882. unsigned int val;
  2883. if (!snd_hdspm_use_is_exclusive(hdspm))
  2884. return -EBUSY;
  2885. val = ucontrol->value.integer.value[0] & 1;
  2886. spin_lock_irq(&hdspm->lock);
  2887. change = (int) val != hdspm_ds_wire(hdspm);
  2888. hdspm_set_ds_wire(hdspm, val);
  2889. spin_unlock_irq(&hdspm->lock);
  2890. return change;
  2891. }
  2892. #define HDSPM_QS_WIRE(xname, xindex) \
  2893. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2894. .name = xname, \
  2895. .index = xindex, \
  2896. .info = snd_hdspm_info_qs_wire, \
  2897. .get = snd_hdspm_get_qs_wire, \
  2898. .put = snd_hdspm_put_qs_wire \
  2899. }
  2900. static int hdspm_qs_wire(struct hdspm * hdspm)
  2901. {
  2902. if (hdspm->control_register & HDSPM_QS_DoubleWire)
  2903. return 1;
  2904. if (hdspm->control_register & HDSPM_QS_QuadWire)
  2905. return 2;
  2906. return 0;
  2907. }
  2908. static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
  2909. {
  2910. hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
  2911. switch (mode) {
  2912. case 0:
  2913. break;
  2914. case 1:
  2915. hdspm->control_register |= HDSPM_QS_DoubleWire;
  2916. break;
  2917. case 2:
  2918. hdspm->control_register |= HDSPM_QS_QuadWire;
  2919. break;
  2920. }
  2921. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  2922. return 0;
  2923. }
  2924. static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
  2925. struct snd_ctl_elem_info *uinfo)
  2926. {
  2927. static const char *const texts[] = { "Single", "Double", "Quad" };
  2928. ENUMERATED_CTL_INFO(uinfo, texts);
  2929. return 0;
  2930. }
  2931. static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol,
  2932. struct snd_ctl_elem_value *ucontrol)
  2933. {
  2934. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2935. spin_lock_irq(&hdspm->lock);
  2936. ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
  2937. spin_unlock_irq(&hdspm->lock);
  2938. return 0;
  2939. }
  2940. static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
  2941. struct snd_ctl_elem_value *ucontrol)
  2942. {
  2943. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2944. int change;
  2945. int val;
  2946. if (!snd_hdspm_use_is_exclusive(hdspm))
  2947. return -EBUSY;
  2948. val = ucontrol->value.integer.value[0];
  2949. if (val < 0)
  2950. val = 0;
  2951. if (val > 2)
  2952. val = 2;
  2953. spin_lock_irq(&hdspm->lock);
  2954. change = val != hdspm_qs_wire(hdspm);
  2955. hdspm_set_qs_wire(hdspm, val);
  2956. spin_unlock_irq(&hdspm->lock);
  2957. return change;
  2958. }
  2959. #define HDSPM_CONTROL_TRISTATE(xname, xindex) \
  2960. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2961. .name = xname, \
  2962. .private_value = xindex, \
  2963. .info = snd_hdspm_info_tristate, \
  2964. .get = snd_hdspm_get_tristate, \
  2965. .put = snd_hdspm_put_tristate \
  2966. }
  2967. static int hdspm_tristate(struct hdspm *hdspm, u32 regmask)
  2968. {
  2969. u32 reg = hdspm->settings_register & (regmask * 3);
  2970. return reg / regmask;
  2971. }
  2972. static int hdspm_set_tristate(struct hdspm *hdspm, int mode, u32 regmask)
  2973. {
  2974. hdspm->settings_register &= ~(regmask * 3);
  2975. hdspm->settings_register |= (regmask * mode);
  2976. hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
  2977. return 0;
  2978. }
  2979. static int snd_hdspm_info_tristate(struct snd_kcontrol *kcontrol,
  2980. struct snd_ctl_elem_info *uinfo)
  2981. {
  2982. u32 regmask = kcontrol->private_value;
  2983. static const char *const texts_spdif[] = { "Optical", "Coaxial", "Internal" };
  2984. static const char *const texts_levels[] = { "Hi Gain", "+4 dBu", "-10 dBV" };
  2985. switch (regmask) {
  2986. case HDSPM_c0_Input0:
  2987. ENUMERATED_CTL_INFO(uinfo, texts_spdif);
  2988. break;
  2989. default:
  2990. ENUMERATED_CTL_INFO(uinfo, texts_levels);
  2991. break;
  2992. }
  2993. return 0;
  2994. }
  2995. static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol,
  2996. struct snd_ctl_elem_value *ucontrol)
  2997. {
  2998. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  2999. u32 regmask = kcontrol->private_value;
  3000. spin_lock_irq(&hdspm->lock);
  3001. ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask);
  3002. spin_unlock_irq(&hdspm->lock);
  3003. return 0;
  3004. }
  3005. static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol,
  3006. struct snd_ctl_elem_value *ucontrol)
  3007. {
  3008. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3009. u32 regmask = kcontrol->private_value;
  3010. int change;
  3011. int val;
  3012. if (!snd_hdspm_use_is_exclusive(hdspm))
  3013. return -EBUSY;
  3014. val = ucontrol->value.integer.value[0];
  3015. if (val < 0)
  3016. val = 0;
  3017. if (val > 2)
  3018. val = 2;
  3019. spin_lock_irq(&hdspm->lock);
  3020. change = val != hdspm_tristate(hdspm, regmask);
  3021. hdspm_set_tristate(hdspm, val, regmask);
  3022. spin_unlock_irq(&hdspm->lock);
  3023. return change;
  3024. }
  3025. #define HDSPM_MADI_SPEEDMODE(xname, xindex) \
  3026. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3027. .name = xname, \
  3028. .index = xindex, \
  3029. .info = snd_hdspm_info_madi_speedmode, \
  3030. .get = snd_hdspm_get_madi_speedmode, \
  3031. .put = snd_hdspm_put_madi_speedmode \
  3032. }
  3033. static int hdspm_madi_speedmode(struct hdspm *hdspm)
  3034. {
  3035. if (hdspm->control_register & HDSPM_QuadSpeed)
  3036. return 2;
  3037. if (hdspm->control_register & HDSPM_DoubleSpeed)
  3038. return 1;
  3039. return 0;
  3040. }
  3041. static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode)
  3042. {
  3043. hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed);
  3044. switch (mode) {
  3045. case 0:
  3046. break;
  3047. case 1:
  3048. hdspm->control_register |= HDSPM_DoubleSpeed;
  3049. break;
  3050. case 2:
  3051. hdspm->control_register |= HDSPM_QuadSpeed;
  3052. break;
  3053. }
  3054. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  3055. return 0;
  3056. }
  3057. static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
  3058. struct snd_ctl_elem_info *uinfo)
  3059. {
  3060. static const char *const texts[] = { "Single", "Double", "Quad" };
  3061. ENUMERATED_CTL_INFO(uinfo, texts);
  3062. return 0;
  3063. }
  3064. static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol,
  3065. struct snd_ctl_elem_value *ucontrol)
  3066. {
  3067. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3068. spin_lock_irq(&hdspm->lock);
  3069. ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm);
  3070. spin_unlock_irq(&hdspm->lock);
  3071. return 0;
  3072. }
  3073. static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol,
  3074. struct snd_ctl_elem_value *ucontrol)
  3075. {
  3076. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3077. int change;
  3078. int val;
  3079. if (!snd_hdspm_use_is_exclusive(hdspm))
  3080. return -EBUSY;
  3081. val = ucontrol->value.integer.value[0];
  3082. if (val < 0)
  3083. val = 0;
  3084. if (val > 2)
  3085. val = 2;
  3086. spin_lock_irq(&hdspm->lock);
  3087. change = val != hdspm_madi_speedmode(hdspm);
  3088. hdspm_set_madi_speedmode(hdspm, val);
  3089. spin_unlock_irq(&hdspm->lock);
  3090. return change;
  3091. }
  3092. #define HDSPM_MIXER(xname, xindex) \
  3093. { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
  3094. .name = xname, \
  3095. .index = xindex, \
  3096. .device = 0, \
  3097. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  3098. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3099. .info = snd_hdspm_info_mixer, \
  3100. .get = snd_hdspm_get_mixer, \
  3101. .put = snd_hdspm_put_mixer \
  3102. }
  3103. static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol,
  3104. struct snd_ctl_elem_info *uinfo)
  3105. {
  3106. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  3107. uinfo->count = 3;
  3108. uinfo->value.integer.min = 0;
  3109. uinfo->value.integer.max = 65535;
  3110. uinfo->value.integer.step = 1;
  3111. return 0;
  3112. }
  3113. static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,
  3114. struct snd_ctl_elem_value *ucontrol)
  3115. {
  3116. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3117. int source;
  3118. int destination;
  3119. source = ucontrol->value.integer.value[0];
  3120. if (source < 0)
  3121. source = 0;
  3122. else if (source >= 2 * HDSPM_MAX_CHANNELS)
  3123. source = 2 * HDSPM_MAX_CHANNELS - 1;
  3124. destination = ucontrol->value.integer.value[1];
  3125. if (destination < 0)
  3126. destination = 0;
  3127. else if (destination >= HDSPM_MAX_CHANNELS)
  3128. destination = HDSPM_MAX_CHANNELS - 1;
  3129. spin_lock_irq(&hdspm->lock);
  3130. if (source >= HDSPM_MAX_CHANNELS)
  3131. ucontrol->value.integer.value[2] =
  3132. hdspm_read_pb_gain(hdspm, destination,
  3133. source - HDSPM_MAX_CHANNELS);
  3134. else
  3135. ucontrol->value.integer.value[2] =
  3136. hdspm_read_in_gain(hdspm, destination, source);
  3137. spin_unlock_irq(&hdspm->lock);
  3138. return 0;
  3139. }
  3140. static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,
  3141. struct snd_ctl_elem_value *ucontrol)
  3142. {
  3143. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3144. int change;
  3145. int source;
  3146. int destination;
  3147. int gain;
  3148. if (!snd_hdspm_use_is_exclusive(hdspm))
  3149. return -EBUSY;
  3150. source = ucontrol->value.integer.value[0];
  3151. destination = ucontrol->value.integer.value[1];
  3152. if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
  3153. return -1;
  3154. if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
  3155. return -1;
  3156. gain = ucontrol->value.integer.value[2];
  3157. spin_lock_irq(&hdspm->lock);
  3158. if (source >= HDSPM_MAX_CHANNELS)
  3159. change = gain != hdspm_read_pb_gain(hdspm, destination,
  3160. source -
  3161. HDSPM_MAX_CHANNELS);
  3162. else
  3163. change = gain != hdspm_read_in_gain(hdspm, destination,
  3164. source);
  3165. if (change) {
  3166. if (source >= HDSPM_MAX_CHANNELS)
  3167. hdspm_write_pb_gain(hdspm, destination,
  3168. source - HDSPM_MAX_CHANNELS,
  3169. gain);
  3170. else
  3171. hdspm_write_in_gain(hdspm, destination, source,
  3172. gain);
  3173. }
  3174. spin_unlock_irq(&hdspm->lock);
  3175. return change;
  3176. }
  3177. /* The simple mixer control(s) provide gain control for the
  3178. basic 1:1 mappings of playback streams to output
  3179. streams.
  3180. */
  3181. #define HDSPM_PLAYBACK_MIXER \
  3182. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3183. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
  3184. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3185. .info = snd_hdspm_info_playback_mixer, \
  3186. .get = snd_hdspm_get_playback_mixer, \
  3187. .put = snd_hdspm_put_playback_mixer \
  3188. }
  3189. static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol,
  3190. struct snd_ctl_elem_info *uinfo)
  3191. {
  3192. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  3193. uinfo->count = 1;
  3194. uinfo->value.integer.min = 0;
  3195. uinfo->value.integer.max = 64;
  3196. uinfo->value.integer.step = 1;
  3197. return 0;
  3198. }
  3199. static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
  3200. struct snd_ctl_elem_value *ucontrol)
  3201. {
  3202. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3203. int channel;
  3204. channel = ucontrol->id.index - 1;
  3205. if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
  3206. return -EINVAL;
  3207. spin_lock_irq(&hdspm->lock);
  3208. ucontrol->value.integer.value[0] =
  3209. (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN;
  3210. spin_unlock_irq(&hdspm->lock);
  3211. return 0;
  3212. }
  3213. static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
  3214. struct snd_ctl_elem_value *ucontrol)
  3215. {
  3216. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3217. int change;
  3218. int channel;
  3219. int gain;
  3220. if (!snd_hdspm_use_is_exclusive(hdspm))
  3221. return -EBUSY;
  3222. channel = ucontrol->id.index - 1;
  3223. if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
  3224. return -EINVAL;
  3225. gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64;
  3226. spin_lock_irq(&hdspm->lock);
  3227. change =
  3228. gain != hdspm_read_pb_gain(hdspm, channel,
  3229. channel);
  3230. if (change)
  3231. hdspm_write_pb_gain(hdspm, channel, channel,
  3232. gain);
  3233. spin_unlock_irq(&hdspm->lock);
  3234. return change;
  3235. }
  3236. #define HDSPM_SYNC_CHECK(xname, xindex) \
  3237. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3238. .name = xname, \
  3239. .private_value = xindex, \
  3240. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3241. .info = snd_hdspm_info_sync_check, \
  3242. .get = snd_hdspm_get_sync_check \
  3243. }
  3244. #define HDSPM_TCO_LOCK_CHECK(xname, xindex) \
  3245. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3246. .name = xname, \
  3247. .private_value = xindex, \
  3248. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3249. .info = snd_hdspm_tco_info_lock_check, \
  3250. .get = snd_hdspm_get_sync_check \
  3251. }
  3252. static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
  3253. struct snd_ctl_elem_info *uinfo)
  3254. {
  3255. static const char *const texts[] = { "No Lock", "Lock", "Sync", "N/A" };
  3256. ENUMERATED_CTL_INFO(uinfo, texts);
  3257. return 0;
  3258. }
  3259. static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol,
  3260. struct snd_ctl_elem_info *uinfo)
  3261. {
  3262. static const char *const texts[] = { "No Lock", "Lock" };
  3263. ENUMERATED_CTL_INFO(uinfo, texts);
  3264. return 0;
  3265. }
  3266. static int hdspm_wc_sync_check(struct hdspm *hdspm)
  3267. {
  3268. int status, status2;
  3269. switch (hdspm->io_type) {
  3270. case AES32:
  3271. status = hdspm_read(hdspm, HDSPM_statusRegister);
  3272. if (status & HDSPM_AES32_wcLock) {
  3273. if (status & HDSPM_AES32_wcSync)
  3274. return 2;
  3275. else
  3276. return 1;
  3277. }
  3278. return 0;
  3279. break;
  3280. case MADI:
  3281. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  3282. if (status2 & HDSPM_wcLock) {
  3283. if (status2 & HDSPM_wcSync)
  3284. return 2;
  3285. else
  3286. return 1;
  3287. }
  3288. return 0;
  3289. break;
  3290. case RayDAT:
  3291. case AIO:
  3292. status = hdspm_read(hdspm, HDSPM_statusRegister);
  3293. if (status & 0x2000000)
  3294. return 2;
  3295. else if (status & 0x1000000)
  3296. return 1;
  3297. return 0;
  3298. break;
  3299. case MADIface:
  3300. break;
  3301. }
  3302. return 3;
  3303. }
  3304. static int hdspm_madi_sync_check(struct hdspm *hdspm)
  3305. {
  3306. int status = hdspm_read(hdspm, HDSPM_statusRegister);
  3307. if (status & HDSPM_madiLock) {
  3308. if (status & HDSPM_madiSync)
  3309. return 2;
  3310. else
  3311. return 1;
  3312. }
  3313. return 0;
  3314. }
  3315. static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx)
  3316. {
  3317. int status, lock, sync;
  3318. status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
  3319. lock = (status & (0x1<<idx)) ? 1 : 0;
  3320. sync = (status & (0x100<<idx)) ? 1 : 0;
  3321. if (lock && sync)
  3322. return 2;
  3323. else if (lock)
  3324. return 1;
  3325. return 0;
  3326. }
  3327. static int hdspm_sync_in_sync_check(struct hdspm *hdspm)
  3328. {
  3329. int status, lock = 0, sync = 0;
  3330. switch (hdspm->io_type) {
  3331. case RayDAT:
  3332. case AIO:
  3333. status = hdspm_read(hdspm, HDSPM_RD_STATUS_3);
  3334. lock = (status & 0x400) ? 1 : 0;
  3335. sync = (status & 0x800) ? 1 : 0;
  3336. break;
  3337. case MADI:
  3338. status = hdspm_read(hdspm, HDSPM_statusRegister);
  3339. lock = (status & HDSPM_syncInLock) ? 1 : 0;
  3340. sync = (status & HDSPM_syncInSync) ? 1 : 0;
  3341. break;
  3342. case AES32:
  3343. status = hdspm_read(hdspm, HDSPM_statusRegister2);
  3344. lock = (status & 0x100000) ? 1 : 0;
  3345. sync = (status & 0x200000) ? 1 : 0;
  3346. break;
  3347. case MADIface:
  3348. break;
  3349. }
  3350. if (lock && sync)
  3351. return 2;
  3352. else if (lock)
  3353. return 1;
  3354. return 0;
  3355. }
  3356. static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
  3357. {
  3358. int status2, lock, sync;
  3359. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  3360. lock = (status2 & (0x0080 >> idx)) ? 1 : 0;
  3361. sync = (status2 & (0x8000 >> idx)) ? 1 : 0;
  3362. if (sync)
  3363. return 2;
  3364. else if (lock)
  3365. return 1;
  3366. return 0;
  3367. }
  3368. static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask)
  3369. {
  3370. u32 status;
  3371. status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
  3372. return (status & mask) ? 1 : 0;
  3373. }
  3374. static int hdspm_tco_sync_check(struct hdspm *hdspm)
  3375. {
  3376. int status;
  3377. if (hdspm->tco) {
  3378. switch (hdspm->io_type) {
  3379. case MADI:
  3380. status = hdspm_read(hdspm, HDSPM_statusRegister);
  3381. if (status & HDSPM_tcoLockMadi) {
  3382. if (status & HDSPM_tcoSync)
  3383. return 2;
  3384. else
  3385. return 1;
  3386. }
  3387. return 0;
  3388. case AES32:
  3389. status = hdspm_read(hdspm, HDSPM_statusRegister);
  3390. if (status & HDSPM_tcoLockAes) {
  3391. if (status & HDSPM_tcoSync)
  3392. return 2;
  3393. else
  3394. return 1;
  3395. }
  3396. return 0;
  3397. case RayDAT:
  3398. case AIO:
  3399. status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
  3400. if (status & 0x8000000)
  3401. return 2; /* Sync */
  3402. if (status & 0x4000000)
  3403. return 1; /* Lock */
  3404. return 0; /* No signal */
  3405. default:
  3406. break;
  3407. }
  3408. }
  3409. return 3; /* N/A */
  3410. }
  3411. static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
  3412. struct snd_ctl_elem_value *ucontrol)
  3413. {
  3414. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3415. int val = -1;
  3416. switch (hdspm->io_type) {
  3417. case RayDAT:
  3418. switch (kcontrol->private_value) {
  3419. case 0: /* WC */
  3420. val = hdspm_wc_sync_check(hdspm); break;
  3421. case 7: /* TCO */
  3422. val = hdspm_tco_sync_check(hdspm); break;
  3423. case 8: /* SYNC IN */
  3424. val = hdspm_sync_in_sync_check(hdspm); break;
  3425. default:
  3426. val = hdspm_s1_sync_check(hdspm,
  3427. kcontrol->private_value-1);
  3428. }
  3429. break;
  3430. case AIO:
  3431. switch (kcontrol->private_value) {
  3432. case 0: /* WC */
  3433. val = hdspm_wc_sync_check(hdspm); break;
  3434. case 4: /* TCO */
  3435. val = hdspm_tco_sync_check(hdspm); break;
  3436. case 5: /* SYNC IN */
  3437. val = hdspm_sync_in_sync_check(hdspm); break;
  3438. default:
  3439. val = hdspm_s1_sync_check(hdspm,
  3440. kcontrol->private_value-1);
  3441. }
  3442. break;
  3443. case MADI:
  3444. switch (kcontrol->private_value) {
  3445. case 0: /* WC */
  3446. val = hdspm_wc_sync_check(hdspm); break;
  3447. case 1: /* MADI */
  3448. val = hdspm_madi_sync_check(hdspm); break;
  3449. case 2: /* TCO */
  3450. val = hdspm_tco_sync_check(hdspm); break;
  3451. case 3: /* SYNC_IN */
  3452. val = hdspm_sync_in_sync_check(hdspm); break;
  3453. }
  3454. break;
  3455. case MADIface:
  3456. val = hdspm_madi_sync_check(hdspm); /* MADI */
  3457. break;
  3458. case AES32:
  3459. switch (kcontrol->private_value) {
  3460. case 0: /* WC */
  3461. val = hdspm_wc_sync_check(hdspm); break;
  3462. case 9: /* TCO */
  3463. val = hdspm_tco_sync_check(hdspm); break;
  3464. case 10 /* SYNC IN */:
  3465. val = hdspm_sync_in_sync_check(hdspm); break;
  3466. default: /* AES1 to AES8 */
  3467. val = hdspm_aes_sync_check(hdspm,
  3468. kcontrol->private_value-1);
  3469. }
  3470. break;
  3471. }
  3472. if (hdspm->tco) {
  3473. switch (kcontrol->private_value) {
  3474. case 11:
  3475. /* Check TCO for lock state of its current input */
  3476. val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock);
  3477. break;
  3478. case 12:
  3479. /* Check TCO for valid time code on LTC input. */
  3480. val = hdspm_tco_input_check(hdspm,
  3481. HDSPM_TCO1_LTC_Input_valid);
  3482. break;
  3483. default:
  3484. break;
  3485. }
  3486. }
  3487. if (-1 == val)
  3488. val = 3;
  3489. ucontrol->value.enumerated.item[0] = val;
  3490. return 0;
  3491. }
  3492. /*
  3493. * TCO controls
  3494. */
  3495. static void hdspm_tco_write(struct hdspm *hdspm)
  3496. {
  3497. unsigned int tc[4] = { 0, 0, 0, 0};
  3498. switch (hdspm->tco->input) {
  3499. case 0:
  3500. tc[2] |= HDSPM_TCO2_set_input_MSB;
  3501. break;
  3502. case 1:
  3503. tc[2] |= HDSPM_TCO2_set_input_LSB;
  3504. break;
  3505. default:
  3506. break;
  3507. }
  3508. switch (hdspm->tco->framerate) {
  3509. case 1:
  3510. tc[1] |= HDSPM_TCO1_LTC_Format_LSB;
  3511. break;
  3512. case 2:
  3513. tc[1] |= HDSPM_TCO1_LTC_Format_MSB;
  3514. break;
  3515. case 3:
  3516. tc[1] |= HDSPM_TCO1_LTC_Format_MSB +
  3517. HDSPM_TCO1_set_drop_frame_flag;
  3518. break;
  3519. case 4:
  3520. tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
  3521. HDSPM_TCO1_LTC_Format_MSB;
  3522. break;
  3523. case 5:
  3524. tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
  3525. HDSPM_TCO1_LTC_Format_MSB +
  3526. HDSPM_TCO1_set_drop_frame_flag;
  3527. break;
  3528. default:
  3529. break;
  3530. }
  3531. switch (hdspm->tco->wordclock) {
  3532. case 1:
  3533. tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB;
  3534. break;
  3535. case 2:
  3536. tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB;
  3537. break;
  3538. default:
  3539. break;
  3540. }
  3541. switch (hdspm->tco->samplerate) {
  3542. case 1:
  3543. tc[2] |= HDSPM_TCO2_set_freq;
  3544. break;
  3545. case 2:
  3546. tc[2] |= HDSPM_TCO2_set_freq_from_app;
  3547. break;
  3548. default:
  3549. break;
  3550. }
  3551. switch (hdspm->tco->pull) {
  3552. case 1:
  3553. tc[2] |= HDSPM_TCO2_set_pull_up;
  3554. break;
  3555. case 2:
  3556. tc[2] |= HDSPM_TCO2_set_pull_down;
  3557. break;
  3558. case 3:
  3559. tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4;
  3560. break;
  3561. case 4:
  3562. tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4;
  3563. break;
  3564. default:
  3565. break;
  3566. }
  3567. if (1 == hdspm->tco->term) {
  3568. tc[2] |= HDSPM_TCO2_set_term_75R;
  3569. }
  3570. hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]);
  3571. hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]);
  3572. hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]);
  3573. hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]);
  3574. }
  3575. #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \
  3576. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3577. .name = xname, \
  3578. .index = xindex, \
  3579. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3580. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3581. .info = snd_hdspm_info_tco_sample_rate, \
  3582. .get = snd_hdspm_get_tco_sample_rate, \
  3583. .put = snd_hdspm_put_tco_sample_rate \
  3584. }
  3585. static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
  3586. struct snd_ctl_elem_info *uinfo)
  3587. {
  3588. /* TODO freq from app could be supported here, see tco->samplerate */
  3589. static const char *const texts[] = { "44.1 kHz", "48 kHz" };
  3590. ENUMERATED_CTL_INFO(uinfo, texts);
  3591. return 0;
  3592. }
  3593. static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol,
  3594. struct snd_ctl_elem_value *ucontrol)
  3595. {
  3596. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3597. ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate;
  3598. return 0;
  3599. }
  3600. static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol,
  3601. struct snd_ctl_elem_value *ucontrol)
  3602. {
  3603. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3604. if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) {
  3605. hdspm->tco->samplerate = ucontrol->value.enumerated.item[0];
  3606. hdspm_tco_write(hdspm);
  3607. return 1;
  3608. }
  3609. return 0;
  3610. }
  3611. #define HDSPM_TCO_PULL(xname, xindex) \
  3612. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3613. .name = xname, \
  3614. .index = xindex, \
  3615. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3616. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3617. .info = snd_hdspm_info_tco_pull, \
  3618. .get = snd_hdspm_get_tco_pull, \
  3619. .put = snd_hdspm_put_tco_pull \
  3620. }
  3621. static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
  3622. struct snd_ctl_elem_info *uinfo)
  3623. {
  3624. static const char *const texts[] = { "0", "+ 0.1 %", "- 0.1 %",
  3625. "+ 4 %", "- 4 %" };
  3626. ENUMERATED_CTL_INFO(uinfo, texts);
  3627. return 0;
  3628. }
  3629. static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol,
  3630. struct snd_ctl_elem_value *ucontrol)
  3631. {
  3632. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3633. ucontrol->value.enumerated.item[0] = hdspm->tco->pull;
  3634. return 0;
  3635. }
  3636. static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol,
  3637. struct snd_ctl_elem_value *ucontrol)
  3638. {
  3639. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3640. if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) {
  3641. hdspm->tco->pull = ucontrol->value.enumerated.item[0];
  3642. hdspm_tco_write(hdspm);
  3643. return 1;
  3644. }
  3645. return 0;
  3646. }
  3647. #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \
  3648. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3649. .name = xname, \
  3650. .index = xindex, \
  3651. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3652. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3653. .info = snd_hdspm_info_tco_wck_conversion, \
  3654. .get = snd_hdspm_get_tco_wck_conversion, \
  3655. .put = snd_hdspm_put_tco_wck_conversion \
  3656. }
  3657. static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
  3658. struct snd_ctl_elem_info *uinfo)
  3659. {
  3660. static const char *const texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
  3661. ENUMERATED_CTL_INFO(uinfo, texts);
  3662. return 0;
  3663. }
  3664. static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol,
  3665. struct snd_ctl_elem_value *ucontrol)
  3666. {
  3667. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3668. ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock;
  3669. return 0;
  3670. }
  3671. static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol,
  3672. struct snd_ctl_elem_value *ucontrol)
  3673. {
  3674. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3675. if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) {
  3676. hdspm->tco->wordclock = ucontrol->value.enumerated.item[0];
  3677. hdspm_tco_write(hdspm);
  3678. return 1;
  3679. }
  3680. return 0;
  3681. }
  3682. #define HDSPM_TCO_FRAME_RATE(xname, xindex) \
  3683. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3684. .name = xname, \
  3685. .index = xindex, \
  3686. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3687. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3688. .info = snd_hdspm_info_tco_frame_rate, \
  3689. .get = snd_hdspm_get_tco_frame_rate, \
  3690. .put = snd_hdspm_put_tco_frame_rate \
  3691. }
  3692. static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
  3693. struct snd_ctl_elem_info *uinfo)
  3694. {
  3695. static const char *const texts[] = { "24 fps", "25 fps", "29.97fps",
  3696. "29.97 dfps", "30 fps", "30 dfps" };
  3697. ENUMERATED_CTL_INFO(uinfo, texts);
  3698. return 0;
  3699. }
  3700. static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol,
  3701. struct snd_ctl_elem_value *ucontrol)
  3702. {
  3703. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3704. ucontrol->value.enumerated.item[0] = hdspm->tco->framerate;
  3705. return 0;
  3706. }
  3707. static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol,
  3708. struct snd_ctl_elem_value *ucontrol)
  3709. {
  3710. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3711. if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) {
  3712. hdspm->tco->framerate = ucontrol->value.enumerated.item[0];
  3713. hdspm_tco_write(hdspm);
  3714. return 1;
  3715. }
  3716. return 0;
  3717. }
  3718. #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \
  3719. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3720. .name = xname, \
  3721. .index = xindex, \
  3722. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3723. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3724. .info = snd_hdspm_info_tco_sync_source, \
  3725. .get = snd_hdspm_get_tco_sync_source, \
  3726. .put = snd_hdspm_put_tco_sync_source \
  3727. }
  3728. static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
  3729. struct snd_ctl_elem_info *uinfo)
  3730. {
  3731. static const char *const texts[] = { "LTC", "Video", "WCK" };
  3732. ENUMERATED_CTL_INFO(uinfo, texts);
  3733. return 0;
  3734. }
  3735. static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol,
  3736. struct snd_ctl_elem_value *ucontrol)
  3737. {
  3738. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3739. ucontrol->value.enumerated.item[0] = hdspm->tco->input;
  3740. return 0;
  3741. }
  3742. static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol,
  3743. struct snd_ctl_elem_value *ucontrol)
  3744. {
  3745. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3746. if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) {
  3747. hdspm->tco->input = ucontrol->value.enumerated.item[0];
  3748. hdspm_tco_write(hdspm);
  3749. return 1;
  3750. }
  3751. return 0;
  3752. }
  3753. #define HDSPM_TCO_WORD_TERM(xname, xindex) \
  3754. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  3755. .name = xname, \
  3756. .index = xindex, \
  3757. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  3758. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  3759. .info = snd_hdspm_info_tco_word_term, \
  3760. .get = snd_hdspm_get_tco_word_term, \
  3761. .put = snd_hdspm_put_tco_word_term \
  3762. }
  3763. static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol,
  3764. struct snd_ctl_elem_info *uinfo)
  3765. {
  3766. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  3767. uinfo->count = 1;
  3768. uinfo->value.integer.min = 0;
  3769. uinfo->value.integer.max = 1;
  3770. return 0;
  3771. }
  3772. static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol,
  3773. struct snd_ctl_elem_value *ucontrol)
  3774. {
  3775. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3776. ucontrol->value.integer.value[0] = hdspm->tco->term;
  3777. return 0;
  3778. }
  3779. static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol,
  3780. struct snd_ctl_elem_value *ucontrol)
  3781. {
  3782. struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
  3783. if (hdspm->tco->term != ucontrol->value.integer.value[0]) {
  3784. hdspm->tco->term = ucontrol->value.integer.value[0];
  3785. hdspm_tco_write(hdspm);
  3786. return 1;
  3787. }
  3788. return 0;
  3789. }
  3790. static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
  3791. HDSPM_MIXER("Mixer", 0),
  3792. HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
  3793. HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
  3794. HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
  3795. HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
  3796. HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  3797. HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
  3798. HDSPM_SYNC_CHECK("WC SyncCheck", 0),
  3799. HDSPM_SYNC_CHECK("MADI SyncCheck", 1),
  3800. HDSPM_SYNC_CHECK("TCO SyncCheck", 2),
  3801. HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
  3802. HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
  3803. HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
  3804. HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX),
  3805. HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
  3806. HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
  3807. HDSPM_INPUT_SELECT("Input Select", 0),
  3808. HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
  3809. };
  3810. static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = {
  3811. HDSPM_MIXER("Mixer", 0),
  3812. HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
  3813. HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
  3814. HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  3815. HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
  3816. HDSPM_SYNC_CHECK("MADI SyncCheck", 0),
  3817. HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
  3818. HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
  3819. HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
  3820. HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
  3821. };
  3822. static struct snd_kcontrol_new snd_hdspm_controls_aio[] = {
  3823. HDSPM_MIXER("Mixer", 0),
  3824. HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
  3825. HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
  3826. HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
  3827. HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  3828. HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
  3829. HDSPM_SYNC_CHECK("WC SyncCheck", 0),
  3830. HDSPM_SYNC_CHECK("AES SyncCheck", 1),
  3831. HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
  3832. HDSPM_SYNC_CHECK("ADAT SyncCheck", 3),
  3833. HDSPM_SYNC_CHECK("TCO SyncCheck", 4),
  3834. HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5),
  3835. HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
  3836. HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
  3837. HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
  3838. HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3),
  3839. HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4),
  3840. HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5),
  3841. HDSPM_CONTROL_TRISTATE("S/PDIF Input", HDSPM_c0_Input0),
  3842. HDSPM_TOGGLE_SETTING("S/PDIF Out Optical", HDSPM_c0_Spdif_Opt),
  3843. HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
  3844. HDSPM_TOGGLE_SETTING("ADAT internal (AEB/TEB)", HDSPM_c0_AEB1),
  3845. HDSPM_TOGGLE_SETTING("XLR Breakout Cable", HDSPM_c0_Sym6db),
  3846. HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48),
  3847. HDSPM_CONTROL_TRISTATE("Input Level", HDSPM_c0_AD_GAIN0),
  3848. HDSPM_CONTROL_TRISTATE("Output Level", HDSPM_c0_DA_GAIN0),
  3849. HDSPM_CONTROL_TRISTATE("Phones Level", HDSPM_c0_PH_GAIN0)
  3850. /*
  3851. HDSPM_INPUT_SELECT("Input Select", 0),
  3852. HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0),
  3853. HDSPM_PROFESSIONAL("SPDIF Out Professional", 0);
  3854. HDSPM_SPDIF_IN("SPDIF In", 0);
  3855. HDSPM_BREAKOUT_CABLE("Breakout Cable", 0);
  3856. HDSPM_INPUT_LEVEL("Input Level", 0);
  3857. HDSPM_OUTPUT_LEVEL("Output Level", 0);
  3858. HDSPM_PHONES("Phones", 0);
  3859. */
  3860. };
  3861. static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = {
  3862. HDSPM_MIXER("Mixer", 0),
  3863. HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
  3864. HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0),
  3865. HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0),
  3866. HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  3867. HDSPM_SYNC_CHECK("WC SyncCheck", 0),
  3868. HDSPM_SYNC_CHECK("AES SyncCheck", 1),
  3869. HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
  3870. HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3),
  3871. HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4),
  3872. HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5),
  3873. HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6),
  3874. HDSPM_SYNC_CHECK("TCO SyncCheck", 7),
  3875. HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8),
  3876. HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
  3877. HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
  3878. HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
  3879. HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3),
  3880. HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4),
  3881. HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5),
  3882. HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6),
  3883. HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7),
  3884. HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8),
  3885. HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
  3886. HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48)
  3887. };
  3888. static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = {
  3889. HDSPM_MIXER("Mixer", 0),
  3890. HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
  3891. HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
  3892. HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
  3893. HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
  3894. HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  3895. HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 11),
  3896. HDSPM_SYNC_CHECK("WC Sync Check", 0),
  3897. HDSPM_SYNC_CHECK("AES1 Sync Check", 1),
  3898. HDSPM_SYNC_CHECK("AES2 Sync Check", 2),
  3899. HDSPM_SYNC_CHECK("AES3 Sync Check", 3),
  3900. HDSPM_SYNC_CHECK("AES4 Sync Check", 4),
  3901. HDSPM_SYNC_CHECK("AES5 Sync Check", 5),
  3902. HDSPM_SYNC_CHECK("AES6 Sync Check", 6),
  3903. HDSPM_SYNC_CHECK("AES7 Sync Check", 7),
  3904. HDSPM_SYNC_CHECK("AES8 Sync Check", 8),
  3905. HDSPM_SYNC_CHECK("TCO Sync Check", 9),
  3906. HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10),
  3907. HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
  3908. HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1),
  3909. HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2),
  3910. HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3),
  3911. HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4),
  3912. HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5),
  3913. HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6),
  3914. HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7),
  3915. HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8),
  3916. HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9),
  3917. HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10),
  3918. HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
  3919. HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis),
  3920. HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby),
  3921. HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional),
  3922. HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
  3923. HDSPM_DS_WIRE("Double Speed Wire Mode", 0),
  3924. HDSPM_QS_WIRE("Quad Speed Wire Mode", 0),
  3925. };
  3926. /* Control elements for the optional TCO module */
  3927. static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
  3928. HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0),
  3929. HDSPM_TCO_PULL("TCO Pull", 0),
  3930. HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
  3931. HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
  3932. HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
  3933. HDSPM_TCO_WORD_TERM("TCO Word Term", 0),
  3934. HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11),
  3935. HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12),
  3936. HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0),
  3937. HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0)
  3938. };
  3939. static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
  3940. static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
  3941. {
  3942. int i;
  3943. for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) {
  3944. if (hdspm->system_sample_rate > 48000) {
  3945. hdspm->playback_mixer_ctls[i]->vd[0].access =
  3946. SNDRV_CTL_ELEM_ACCESS_INACTIVE |
  3947. SNDRV_CTL_ELEM_ACCESS_READ |
  3948. SNDRV_CTL_ELEM_ACCESS_VOLATILE;
  3949. } else {
  3950. hdspm->playback_mixer_ctls[i]->vd[0].access =
  3951. SNDRV_CTL_ELEM_ACCESS_READWRITE |
  3952. SNDRV_CTL_ELEM_ACCESS_VOLATILE;
  3953. }
  3954. snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
  3955. SNDRV_CTL_EVENT_MASK_INFO,
  3956. &hdspm->playback_mixer_ctls[i]->id);
  3957. }
  3958. return 0;
  3959. }
  3960. static int snd_hdspm_create_controls(struct snd_card *card,
  3961. struct hdspm *hdspm)
  3962. {
  3963. unsigned int idx, limit;
  3964. int err;
  3965. struct snd_kcontrol *kctl;
  3966. struct snd_kcontrol_new *list = NULL;
  3967. switch (hdspm->io_type) {
  3968. case MADI:
  3969. list = snd_hdspm_controls_madi;
  3970. limit = ARRAY_SIZE(snd_hdspm_controls_madi);
  3971. break;
  3972. case MADIface:
  3973. list = snd_hdspm_controls_madiface;
  3974. limit = ARRAY_SIZE(snd_hdspm_controls_madiface);
  3975. break;
  3976. case AIO:
  3977. list = snd_hdspm_controls_aio;
  3978. limit = ARRAY_SIZE(snd_hdspm_controls_aio);
  3979. break;
  3980. case RayDAT:
  3981. list = snd_hdspm_controls_raydat;
  3982. limit = ARRAY_SIZE(snd_hdspm_controls_raydat);
  3983. break;
  3984. case AES32:
  3985. list = snd_hdspm_controls_aes32;
  3986. limit = ARRAY_SIZE(snd_hdspm_controls_aes32);
  3987. break;
  3988. }
  3989. if (NULL != list) {
  3990. for (idx = 0; idx < limit; idx++) {
  3991. err = snd_ctl_add(card,
  3992. snd_ctl_new1(&list[idx], hdspm));
  3993. if (err < 0)
  3994. return err;
  3995. }
  3996. }
  3997. /* create simple 1:1 playback mixer controls */
  3998. snd_hdspm_playback_mixer.name = "Chn";
  3999. if (hdspm->system_sample_rate >= 128000) {
  4000. limit = hdspm->qs_out_channels;
  4001. } else if (hdspm->system_sample_rate >= 64000) {
  4002. limit = hdspm->ds_out_channels;
  4003. } else {
  4004. limit = hdspm->ss_out_channels;
  4005. }
  4006. for (idx = 0; idx < limit; ++idx) {
  4007. snd_hdspm_playback_mixer.index = idx + 1;
  4008. kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm);
  4009. err = snd_ctl_add(card, kctl);
  4010. if (err < 0)
  4011. return err;
  4012. hdspm->playback_mixer_ctls[idx] = kctl;
  4013. }
  4014. if (hdspm->tco) {
  4015. /* add tco control elements */
  4016. list = snd_hdspm_controls_tco;
  4017. limit = ARRAY_SIZE(snd_hdspm_controls_tco);
  4018. for (idx = 0; idx < limit; idx++) {
  4019. err = snd_ctl_add(card,
  4020. snd_ctl_new1(&list[idx], hdspm));
  4021. if (err < 0)
  4022. return err;
  4023. }
  4024. }
  4025. return 0;
  4026. }
  4027. /*------------------------------------------------------------
  4028. /proc interface
  4029. ------------------------------------------------------------*/
  4030. static void
  4031. snd_hdspm_proc_read_tco(struct snd_info_entry *entry,
  4032. struct snd_info_buffer *buffer)
  4033. {
  4034. struct hdspm *hdspm = entry->private_data;
  4035. unsigned int status, control;
  4036. int a, ltc, frames, seconds, minutes, hours;
  4037. unsigned int period;
  4038. u64 freq_const = 0;
  4039. u32 rate;
  4040. snd_iprintf(buffer, "--- TCO ---\n");
  4041. status = hdspm_read(hdspm, HDSPM_statusRegister);
  4042. control = hdspm->control_register;
  4043. if (status & HDSPM_tco_detect) {
  4044. snd_iprintf(buffer, "TCO module detected.\n");
  4045. a = hdspm_read(hdspm, HDSPM_RD_TCO+4);
  4046. if (a & HDSPM_TCO1_LTC_Input_valid) {
  4047. snd_iprintf(buffer, " LTC valid, ");
  4048. switch (a & (HDSPM_TCO1_LTC_Format_LSB |
  4049. HDSPM_TCO1_LTC_Format_MSB)) {
  4050. case 0:
  4051. snd_iprintf(buffer, "24 fps, ");
  4052. break;
  4053. case HDSPM_TCO1_LTC_Format_LSB:
  4054. snd_iprintf(buffer, "25 fps, ");
  4055. break;
  4056. case HDSPM_TCO1_LTC_Format_MSB:
  4057. snd_iprintf(buffer, "29.97 fps, ");
  4058. break;
  4059. default:
  4060. snd_iprintf(buffer, "30 fps, ");
  4061. break;
  4062. }
  4063. if (a & HDSPM_TCO1_set_drop_frame_flag) {
  4064. snd_iprintf(buffer, "drop frame\n");
  4065. } else {
  4066. snd_iprintf(buffer, "full frame\n");
  4067. }
  4068. } else {
  4069. snd_iprintf(buffer, " no LTC\n");
  4070. }
  4071. if (a & HDSPM_TCO1_Video_Input_Format_NTSC) {
  4072. snd_iprintf(buffer, " Video: NTSC\n");
  4073. } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) {
  4074. snd_iprintf(buffer, " Video: PAL\n");
  4075. } else {
  4076. snd_iprintf(buffer, " No video\n");
  4077. }
  4078. if (a & HDSPM_TCO1_TCO_lock) {
  4079. snd_iprintf(buffer, " Sync: lock\n");
  4080. } else {
  4081. snd_iprintf(buffer, " Sync: no lock\n");
  4082. }
  4083. switch (hdspm->io_type) {
  4084. case MADI:
  4085. case AES32:
  4086. freq_const = 110069313433624ULL;
  4087. break;
  4088. case RayDAT:
  4089. case AIO:
  4090. freq_const = 104857600000000ULL;
  4091. break;
  4092. case MADIface:
  4093. break; /* no TCO possible */
  4094. }
  4095. period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
  4096. snd_iprintf(buffer, " period: %u\n", period);
  4097. /* rate = freq_const/period; */
  4098. rate = div_u64(freq_const, period);
  4099. if (control & HDSPM_QuadSpeed) {
  4100. rate *= 4;
  4101. } else if (control & HDSPM_DoubleSpeed) {
  4102. rate *= 2;
  4103. }
  4104. snd_iprintf(buffer, " Frequency: %u Hz\n",
  4105. (unsigned int) rate);
  4106. ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
  4107. frames = ltc & 0xF;
  4108. ltc >>= 4;
  4109. frames += (ltc & 0x3) * 10;
  4110. ltc >>= 4;
  4111. seconds = ltc & 0xF;
  4112. ltc >>= 4;
  4113. seconds += (ltc & 0x7) * 10;
  4114. ltc >>= 4;
  4115. minutes = ltc & 0xF;
  4116. ltc >>= 4;
  4117. minutes += (ltc & 0x7) * 10;
  4118. ltc >>= 4;
  4119. hours = ltc & 0xF;
  4120. ltc >>= 4;
  4121. hours += (ltc & 0x3) * 10;
  4122. snd_iprintf(buffer,
  4123. " LTC In: %02d:%02d:%02d:%02d\n",
  4124. hours, minutes, seconds, frames);
  4125. } else {
  4126. snd_iprintf(buffer, "No TCO module detected.\n");
  4127. }
  4128. }
  4129. static void
  4130. snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
  4131. struct snd_info_buffer *buffer)
  4132. {
  4133. struct hdspm *hdspm = entry->private_data;
  4134. unsigned int status, status2;
  4135. char *pref_sync_ref;
  4136. char *autosync_ref;
  4137. char *system_clock_mode;
  4138. int x, x2;
  4139. status = hdspm_read(hdspm, HDSPM_statusRegister);
  4140. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  4141. snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
  4142. hdspm->card_name, hdspm->card->number + 1,
  4143. hdspm->firmware_rev,
  4144. (status2 & HDSPM_version0) |
  4145. (status2 & HDSPM_version1) | (status2 &
  4146. HDSPM_version2));
  4147. snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n",
  4148. (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF,
  4149. hdspm->serial);
  4150. snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
  4151. hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
  4152. snd_iprintf(buffer, "--- System ---\n");
  4153. snd_iprintf(buffer,
  4154. "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
  4155. status & HDSPM_audioIRQPending,
  4156. (status & HDSPM_midi0IRQPending) ? 1 : 0,
  4157. (status & HDSPM_midi1IRQPending) ? 1 : 0,
  4158. hdspm->irq_count);
  4159. snd_iprintf(buffer,
  4160. "HW pointer: id = %d, rawptr = %d (%d->%d) "
  4161. "estimated= %ld (bytes)\n",
  4162. ((status & HDSPM_BufferID) ? 1 : 0),
  4163. (status & HDSPM_BufferPositionMask),
  4164. (status & HDSPM_BufferPositionMask) %
  4165. (2 * (int)hdspm->period_bytes),
  4166. ((status & HDSPM_BufferPositionMask) - 64) %
  4167. (2 * (int)hdspm->period_bytes),
  4168. (long) hdspm_hw_pointer(hdspm) * 4);
  4169. snd_iprintf(buffer,
  4170. "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
  4171. hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
  4172. hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
  4173. hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
  4174. hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
  4175. snd_iprintf(buffer,
  4176. "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
  4177. hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
  4178. hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
  4179. snd_iprintf(buffer,
  4180. "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
  4181. "status2=0x%x\n",
  4182. hdspm->control_register, hdspm->control2_register,
  4183. status, status2);
  4184. snd_iprintf(buffer, "--- Settings ---\n");
  4185. x = hdspm_get_latency(hdspm);
  4186. snd_iprintf(buffer,
  4187. "Size (Latency): %d samples (2 periods of %lu bytes)\n",
  4188. x, (unsigned long) hdspm->period_bytes);
  4189. snd_iprintf(buffer, "Line out: %s\n",
  4190. (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
  4191. snd_iprintf(buffer,
  4192. "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
  4193. "Auto Input %s\n",
  4194. (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off",
  4195. (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56",
  4196. (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off");
  4197. if (!(hdspm->control_register & HDSPM_ClockModeMaster))
  4198. system_clock_mode = "AutoSync";
  4199. else
  4200. system_clock_mode = "Master";
  4201. snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode);
  4202. switch (hdspm_pref_sync_ref(hdspm)) {
  4203. case HDSPM_SYNC_FROM_WORD:
  4204. pref_sync_ref = "Word Clock";
  4205. break;
  4206. case HDSPM_SYNC_FROM_MADI:
  4207. pref_sync_ref = "MADI Sync";
  4208. break;
  4209. case HDSPM_SYNC_FROM_TCO:
  4210. pref_sync_ref = "TCO";
  4211. break;
  4212. case HDSPM_SYNC_FROM_SYNC_IN:
  4213. pref_sync_ref = "Sync In";
  4214. break;
  4215. default:
  4216. pref_sync_ref = "XXXX Clock";
  4217. break;
  4218. }
  4219. snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
  4220. pref_sync_ref);
  4221. snd_iprintf(buffer, "System Clock Frequency: %d\n",
  4222. hdspm->system_sample_rate);
  4223. snd_iprintf(buffer, "--- Status:\n");
  4224. x = status & HDSPM_madiSync;
  4225. x2 = status2 & HDSPM_wcSync;
  4226. snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
  4227. (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
  4228. "NoLock",
  4229. (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
  4230. "NoLock");
  4231. switch (hdspm_autosync_ref(hdspm)) {
  4232. case HDSPM_AUTOSYNC_FROM_SYNC_IN:
  4233. autosync_ref = "Sync In";
  4234. break;
  4235. case HDSPM_AUTOSYNC_FROM_TCO:
  4236. autosync_ref = "TCO";
  4237. break;
  4238. case HDSPM_AUTOSYNC_FROM_WORD:
  4239. autosync_ref = "Word Clock";
  4240. break;
  4241. case HDSPM_AUTOSYNC_FROM_MADI:
  4242. autosync_ref = "MADI Sync";
  4243. break;
  4244. case HDSPM_AUTOSYNC_FROM_NONE:
  4245. autosync_ref = "Input not valid";
  4246. break;
  4247. default:
  4248. autosync_ref = "---";
  4249. break;
  4250. }
  4251. snd_iprintf(buffer,
  4252. "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
  4253. autosync_ref, hdspm_external_sample_rate(hdspm),
  4254. (status & HDSPM_madiFreqMask) >> 22,
  4255. (status2 & HDSPM_wcFreqMask) >> 5);
  4256. snd_iprintf(buffer, "Input: %s, Mode=%s\n",
  4257. (status & HDSPM_AB_int) ? "Coax" : "Optical",
  4258. (status & HDSPM_RX_64ch) ? "64 channels" :
  4259. "56 channels");
  4260. /* call readout function for TCO specific status */
  4261. snd_hdspm_proc_read_tco(entry, buffer);
  4262. snd_iprintf(buffer, "\n");
  4263. }
  4264. static void
  4265. snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
  4266. struct snd_info_buffer *buffer)
  4267. {
  4268. struct hdspm *hdspm = entry->private_data;
  4269. unsigned int status;
  4270. unsigned int status2;
  4271. unsigned int timecode;
  4272. unsigned int wcLock, wcSync;
  4273. int pref_syncref;
  4274. char *autosync_ref;
  4275. int x;
  4276. status = hdspm_read(hdspm, HDSPM_statusRegister);
  4277. status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  4278. timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
  4279. snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n",
  4280. hdspm->card_name, hdspm->card->number + 1,
  4281. hdspm->firmware_rev);
  4282. snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
  4283. hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
  4284. snd_iprintf(buffer, "--- System ---\n");
  4285. snd_iprintf(buffer,
  4286. "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
  4287. status & HDSPM_audioIRQPending,
  4288. (status & HDSPM_midi0IRQPending) ? 1 : 0,
  4289. (status & HDSPM_midi1IRQPending) ? 1 : 0,
  4290. hdspm->irq_count);
  4291. snd_iprintf(buffer,
  4292. "HW pointer: id = %d, rawptr = %d (%d->%d) "
  4293. "estimated= %ld (bytes)\n",
  4294. ((status & HDSPM_BufferID) ? 1 : 0),
  4295. (status & HDSPM_BufferPositionMask),
  4296. (status & HDSPM_BufferPositionMask) %
  4297. (2 * (int)hdspm->period_bytes),
  4298. ((status & HDSPM_BufferPositionMask) - 64) %
  4299. (2 * (int)hdspm->period_bytes),
  4300. (long) hdspm_hw_pointer(hdspm) * 4);
  4301. snd_iprintf(buffer,
  4302. "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
  4303. hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
  4304. hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
  4305. hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
  4306. hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
  4307. snd_iprintf(buffer,
  4308. "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
  4309. hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
  4310. hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
  4311. snd_iprintf(buffer,
  4312. "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
  4313. "status2=0x%x\n",
  4314. hdspm->control_register, hdspm->control2_register,
  4315. status, status2);
  4316. snd_iprintf(buffer, "--- Settings ---\n");
  4317. x = hdspm_get_latency(hdspm);
  4318. snd_iprintf(buffer,
  4319. "Size (Latency): %d samples (2 periods of %lu bytes)\n",
  4320. x, (unsigned long) hdspm->period_bytes);
  4321. snd_iprintf(buffer, "Line out: %s\n",
  4322. (hdspm->
  4323. control_register & HDSPM_LineOut) ? "on " : "off");
  4324. snd_iprintf(buffer,
  4325. "ClearTrackMarker %s, Emphasis %s, Dolby %s\n",
  4326. (hdspm->
  4327. control_register & HDSPM_clr_tms) ? "on" : "off",
  4328. (hdspm->
  4329. control_register & HDSPM_Emphasis) ? "on" : "off",
  4330. (hdspm->
  4331. control_register & HDSPM_Dolby) ? "on" : "off");
  4332. pref_syncref = hdspm_pref_sync_ref(hdspm);
  4333. if (pref_syncref == 0)
  4334. snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n");
  4335. else
  4336. snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n",
  4337. pref_syncref);
  4338. snd_iprintf(buffer, "System Clock Frequency: %d\n",
  4339. hdspm->system_sample_rate);
  4340. snd_iprintf(buffer, "Double speed: %s\n",
  4341. hdspm->control_register & HDSPM_DS_DoubleWire?
  4342. "Double wire" : "Single wire");
  4343. snd_iprintf(buffer, "Quad speed: %s\n",
  4344. hdspm->control_register & HDSPM_QS_DoubleWire?
  4345. "Double wire" :
  4346. hdspm->control_register & HDSPM_QS_QuadWire?
  4347. "Quad wire" : "Single wire");
  4348. snd_iprintf(buffer, "--- Status:\n");
  4349. wcLock = status & HDSPM_AES32_wcLock;
  4350. wcSync = wcLock && (status & HDSPM_AES32_wcSync);
  4351. snd_iprintf(buffer, "Word: %s Frequency: %d\n",
  4352. (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock",
  4353. HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF));
  4354. for (x = 0; x < 8; x++) {
  4355. snd_iprintf(buffer, "AES%d: %s Frequency: %d\n",
  4356. x+1,
  4357. (status2 & (HDSPM_LockAES >> x)) ?
  4358. "Sync " : "No Lock",
  4359. HDSPM_bit2freq((timecode >> (4*x)) & 0xF));
  4360. }
  4361. switch (hdspm_autosync_ref(hdspm)) {
  4362. case HDSPM_AES32_AUTOSYNC_FROM_NONE:
  4363. autosync_ref = "None"; break;
  4364. case HDSPM_AES32_AUTOSYNC_FROM_WORD:
  4365. autosync_ref = "Word Clock"; break;
  4366. case HDSPM_AES32_AUTOSYNC_FROM_AES1:
  4367. autosync_ref = "AES1"; break;
  4368. case HDSPM_AES32_AUTOSYNC_FROM_AES2:
  4369. autosync_ref = "AES2"; break;
  4370. case HDSPM_AES32_AUTOSYNC_FROM_AES3:
  4371. autosync_ref = "AES3"; break;
  4372. case HDSPM_AES32_AUTOSYNC_FROM_AES4:
  4373. autosync_ref = "AES4"; break;
  4374. case HDSPM_AES32_AUTOSYNC_FROM_AES5:
  4375. autosync_ref = "AES5"; break;
  4376. case HDSPM_AES32_AUTOSYNC_FROM_AES6:
  4377. autosync_ref = "AES6"; break;
  4378. case HDSPM_AES32_AUTOSYNC_FROM_AES7:
  4379. autosync_ref = "AES7"; break;
  4380. case HDSPM_AES32_AUTOSYNC_FROM_AES8:
  4381. autosync_ref = "AES8"; break;
  4382. case HDSPM_AES32_AUTOSYNC_FROM_TCO:
  4383. autosync_ref = "TCO"; break;
  4384. case HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN:
  4385. autosync_ref = "Sync In"; break;
  4386. default:
  4387. autosync_ref = "---"; break;
  4388. }
  4389. snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref);
  4390. /* call readout function for TCO specific status */
  4391. snd_hdspm_proc_read_tco(entry, buffer);
  4392. snd_iprintf(buffer, "\n");
  4393. }
  4394. static void
  4395. snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
  4396. struct snd_info_buffer *buffer)
  4397. {
  4398. struct hdspm *hdspm = entry->private_data;
  4399. unsigned int status1, status2, status3, i;
  4400. unsigned int lock, sync;
  4401. status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
  4402. status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
  4403. status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
  4404. snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
  4405. snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
  4406. snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
  4407. snd_iprintf(buffer, "\n*** CLOCK MODE\n\n");
  4408. snd_iprintf(buffer, "Clock mode : %s\n",
  4409. (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave");
  4410. snd_iprintf(buffer, "System frequency: %d Hz\n",
  4411. hdspm_get_system_sample_rate(hdspm));
  4412. snd_iprintf(buffer, "\n*** INPUT STATUS\n\n");
  4413. lock = 0x1;
  4414. sync = 0x100;
  4415. for (i = 0; i < 8; i++) {
  4416. snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n",
  4417. i,
  4418. (status1 & lock) ? 1 : 0,
  4419. (status1 & sync) ? 1 : 0,
  4420. texts_freq[(status2 >> (i * 4)) & 0xF]);
  4421. lock = lock<<1;
  4422. sync = sync<<1;
  4423. }
  4424. snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n",
  4425. (status1 & 0x1000000) ? 1 : 0,
  4426. (status1 & 0x2000000) ? 1 : 0,
  4427. texts_freq[(status1 >> 16) & 0xF]);
  4428. snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n",
  4429. (status1 & 0x4000000) ? 1 : 0,
  4430. (status1 & 0x8000000) ? 1 : 0,
  4431. texts_freq[(status1 >> 20) & 0xF]);
  4432. snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n",
  4433. (status3 & 0x400) ? 1 : 0,
  4434. (status3 & 0x800) ? 1 : 0,
  4435. texts_freq[(status2 >> 12) & 0xF]);
  4436. }
  4437. #ifdef CONFIG_SND_DEBUG
  4438. static void
  4439. snd_hdspm_proc_read_debug(struct snd_info_entry *entry,
  4440. struct snd_info_buffer *buffer)
  4441. {
  4442. struct hdspm *hdspm = entry->private_data;
  4443. int j,i;
  4444. for (i = 0; i < 256 /* 1024*64 */; i += j) {
  4445. snd_iprintf(buffer, "0x%08X: ", i);
  4446. for (j = 0; j < 16; j += 4)
  4447. snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
  4448. snd_iprintf(buffer, "\n");
  4449. }
  4450. }
  4451. #endif
  4452. static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry,
  4453. struct snd_info_buffer *buffer)
  4454. {
  4455. struct hdspm *hdspm = entry->private_data;
  4456. int i;
  4457. snd_iprintf(buffer, "# generated by hdspm\n");
  4458. for (i = 0; i < hdspm->max_channels_in; i++) {
  4459. snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]);
  4460. }
  4461. }
  4462. static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry,
  4463. struct snd_info_buffer *buffer)
  4464. {
  4465. struct hdspm *hdspm = entry->private_data;
  4466. int i;
  4467. snd_iprintf(buffer, "# generated by hdspm\n");
  4468. for (i = 0; i < hdspm->max_channels_out; i++) {
  4469. snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]);
  4470. }
  4471. }
  4472. static void snd_hdspm_proc_init(struct hdspm *hdspm)
  4473. {
  4474. struct snd_info_entry *entry;
  4475. if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) {
  4476. switch (hdspm->io_type) {
  4477. case AES32:
  4478. snd_info_set_text_ops(entry, hdspm,
  4479. snd_hdspm_proc_read_aes32);
  4480. break;
  4481. case MADI:
  4482. snd_info_set_text_ops(entry, hdspm,
  4483. snd_hdspm_proc_read_madi);
  4484. break;
  4485. case MADIface:
  4486. /* snd_info_set_text_ops(entry, hdspm,
  4487. snd_hdspm_proc_read_madiface); */
  4488. break;
  4489. case RayDAT:
  4490. snd_info_set_text_ops(entry, hdspm,
  4491. snd_hdspm_proc_read_raydat);
  4492. break;
  4493. case AIO:
  4494. break;
  4495. }
  4496. }
  4497. if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) {
  4498. snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in);
  4499. }
  4500. if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) {
  4501. snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out);
  4502. }
  4503. #ifdef CONFIG_SND_DEBUG
  4504. /* debug file to read all hdspm registers */
  4505. if (!snd_card_proc_new(hdspm->card, "debug", &entry))
  4506. snd_info_set_text_ops(entry, hdspm,
  4507. snd_hdspm_proc_read_debug);
  4508. #endif
  4509. }
  4510. /*------------------------------------------------------------
  4511. hdspm intitialize
  4512. ------------------------------------------------------------*/
  4513. static int snd_hdspm_set_defaults(struct hdspm * hdspm)
  4514. {
  4515. /* ASSUMPTION: hdspm->lock is either held, or there is no need to
  4516. hold it (e.g. during module initialization).
  4517. */
  4518. /* set defaults: */
  4519. hdspm->settings_register = 0;
  4520. switch (hdspm->io_type) {
  4521. case MADI:
  4522. case MADIface:
  4523. hdspm->control_register =
  4524. 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
  4525. break;
  4526. case RayDAT:
  4527. case AIO:
  4528. hdspm->settings_register = 0x1 + 0x1000;
  4529. /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0,
  4530. * line_out */
  4531. hdspm->control_register =
  4532. 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
  4533. break;
  4534. case AES32:
  4535. hdspm->control_register =
  4536. HDSPM_ClockModeMaster | /* Master Clock Mode on */
  4537. hdspm_encode_latency(7) | /* latency max=8192samples */
  4538. HDSPM_SyncRef0 | /* AES1 is syncclock */
  4539. HDSPM_LineOut | /* Analog output in */
  4540. HDSPM_Professional; /* Professional mode */
  4541. break;
  4542. }
  4543. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  4544. if (AES32 == hdspm->io_type) {
  4545. /* No control2 register for AES32 */
  4546. #ifdef SNDRV_BIG_ENDIAN
  4547. hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
  4548. #else
  4549. hdspm->control2_register = 0;
  4550. #endif
  4551. hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
  4552. }
  4553. hdspm_compute_period_size(hdspm);
  4554. /* silence everything */
  4555. all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
  4556. if (hdspm_is_raydat_or_aio(hdspm))
  4557. hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
  4558. /* set a default rate so that the channel map is set up. */
  4559. hdspm_set_rate(hdspm, 48000, 1);
  4560. return 0;
  4561. }
  4562. /*------------------------------------------------------------
  4563. interrupt
  4564. ------------------------------------------------------------*/
  4565. static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
  4566. {
  4567. struct hdspm *hdspm = (struct hdspm *) dev_id;
  4568. unsigned int status;
  4569. int i, audio, midi, schedule = 0;
  4570. /* cycles_t now; */
  4571. status = hdspm_read(hdspm, HDSPM_statusRegister);
  4572. audio = status & HDSPM_audioIRQPending;
  4573. midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending |
  4574. HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
  4575. /* now = get_cycles(); */
  4576. /*
  4577. * LAT_2..LAT_0 period counter (win) counter (mac)
  4578. * 6 4096 ~256053425 ~514672358
  4579. * 5 2048 ~128024983 ~257373821
  4580. * 4 1024 ~64023706 ~128718089
  4581. * 3 512 ~32005945 ~64385999
  4582. * 2 256 ~16003039 ~32260176
  4583. * 1 128 ~7998738 ~16194507
  4584. * 0 64 ~3998231 ~8191558
  4585. */
  4586. /*
  4587. dev_info(hdspm->card->dev, "snd_hdspm_interrupt %llu @ %llx\n",
  4588. now-hdspm->last_interrupt, status & 0xFFC0);
  4589. hdspm->last_interrupt = now;
  4590. */
  4591. if (!audio && !midi)
  4592. return IRQ_NONE;
  4593. hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
  4594. hdspm->irq_count++;
  4595. if (audio) {
  4596. if (hdspm->capture_substream)
  4597. snd_pcm_period_elapsed(hdspm->capture_substream);
  4598. if (hdspm->playback_substream)
  4599. snd_pcm_period_elapsed(hdspm->playback_substream);
  4600. }
  4601. if (midi) {
  4602. i = 0;
  4603. while (i < hdspm->midiPorts) {
  4604. if ((hdspm_read(hdspm,
  4605. hdspm->midi[i].statusIn) & 0xff) &&
  4606. (status & hdspm->midi[i].irq)) {
  4607. /* we disable interrupts for this input until
  4608. * processing is done
  4609. */
  4610. hdspm->control_register &= ~hdspm->midi[i].ie;
  4611. hdspm_write(hdspm, HDSPM_controlRegister,
  4612. hdspm->control_register);
  4613. hdspm->midi[i].pending = 1;
  4614. schedule = 1;
  4615. }
  4616. i++;
  4617. }
  4618. if (schedule)
  4619. tasklet_hi_schedule(&hdspm->midi_tasklet);
  4620. }
  4621. return IRQ_HANDLED;
  4622. }
  4623. /*------------------------------------------------------------
  4624. pcm interface
  4625. ------------------------------------------------------------*/
  4626. static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream
  4627. *substream)
  4628. {
  4629. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4630. return hdspm_hw_pointer(hdspm);
  4631. }
  4632. static int snd_hdspm_reset(struct snd_pcm_substream *substream)
  4633. {
  4634. struct snd_pcm_runtime *runtime = substream->runtime;
  4635. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4636. struct snd_pcm_substream *other;
  4637. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  4638. other = hdspm->capture_substream;
  4639. else
  4640. other = hdspm->playback_substream;
  4641. if (hdspm->running)
  4642. runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
  4643. else
  4644. runtime->status->hw_ptr = 0;
  4645. if (other) {
  4646. struct snd_pcm_substream *s;
  4647. struct snd_pcm_runtime *oruntime = other->runtime;
  4648. snd_pcm_group_for_each_entry(s, substream) {
  4649. if (s == other) {
  4650. oruntime->status->hw_ptr =
  4651. runtime->status->hw_ptr;
  4652. break;
  4653. }
  4654. }
  4655. }
  4656. return 0;
  4657. }
  4658. static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
  4659. struct snd_pcm_hw_params *params)
  4660. {
  4661. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4662. int err;
  4663. int i;
  4664. pid_t this_pid;
  4665. pid_t other_pid;
  4666. spin_lock_irq(&hdspm->lock);
  4667. if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  4668. this_pid = hdspm->playback_pid;
  4669. other_pid = hdspm->capture_pid;
  4670. } else {
  4671. this_pid = hdspm->capture_pid;
  4672. other_pid = hdspm->playback_pid;
  4673. }
  4674. if (other_pid > 0 && this_pid != other_pid) {
  4675. /* The other stream is open, and not by the same
  4676. task as this one. Make sure that the parameters
  4677. that matter are the same.
  4678. */
  4679. if (params_rate(params) != hdspm->system_sample_rate) {
  4680. spin_unlock_irq(&hdspm->lock);
  4681. _snd_pcm_hw_param_setempty(params,
  4682. SNDRV_PCM_HW_PARAM_RATE);
  4683. return -EBUSY;
  4684. }
  4685. if (params_period_size(params) != hdspm->period_bytes / 4) {
  4686. spin_unlock_irq(&hdspm->lock);
  4687. _snd_pcm_hw_param_setempty(params,
  4688. SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
  4689. return -EBUSY;
  4690. }
  4691. }
  4692. /* We're fine. */
  4693. spin_unlock_irq(&hdspm->lock);
  4694. /* how to make sure that the rate matches an externally-set one ? */
  4695. spin_lock_irq(&hdspm->lock);
  4696. err = hdspm_set_rate(hdspm, params_rate(params), 0);
  4697. if (err < 0) {
  4698. dev_info(hdspm->card->dev, "err on hdspm_set_rate: %d\n", err);
  4699. spin_unlock_irq(&hdspm->lock);
  4700. _snd_pcm_hw_param_setempty(params,
  4701. SNDRV_PCM_HW_PARAM_RATE);
  4702. return err;
  4703. }
  4704. spin_unlock_irq(&hdspm->lock);
  4705. err = hdspm_set_interrupt_interval(hdspm,
  4706. params_period_size(params));
  4707. if (err < 0) {
  4708. dev_info(hdspm->card->dev,
  4709. "err on hdspm_set_interrupt_interval: %d\n", err);
  4710. _snd_pcm_hw_param_setempty(params,
  4711. SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
  4712. return err;
  4713. }
  4714. /* Memory allocation, takashi's method, dont know if we should
  4715. * spinlock
  4716. */
  4717. /* malloc all buffer even if not enabled to get sure */
  4718. /* Update for MADI rev 204: we need to allocate for all channels,
  4719. * otherwise it doesn't work at 96kHz */
  4720. err =
  4721. snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
  4722. if (err < 0) {
  4723. dev_info(hdspm->card->dev,
  4724. "err on snd_pcm_lib_malloc_pages: %d\n", err);
  4725. return err;
  4726. }
  4727. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  4728. hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
  4729. params_channels(params));
  4730. for (i = 0; i < params_channels(params); ++i)
  4731. snd_hdspm_enable_out(hdspm, i, 1);
  4732. hdspm->playback_buffer =
  4733. (unsigned char *) substream->runtime->dma_area;
  4734. dev_dbg(hdspm->card->dev,
  4735. "Allocated sample buffer for playback at %p\n",
  4736. hdspm->playback_buffer);
  4737. } else {
  4738. hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
  4739. params_channels(params));
  4740. for (i = 0; i < params_channels(params); ++i)
  4741. snd_hdspm_enable_in(hdspm, i, 1);
  4742. hdspm->capture_buffer =
  4743. (unsigned char *) substream->runtime->dma_area;
  4744. dev_dbg(hdspm->card->dev,
  4745. "Allocated sample buffer for capture at %p\n",
  4746. hdspm->capture_buffer);
  4747. }
  4748. /*
  4749. dev_dbg(hdspm->card->dev,
  4750. "Allocated sample buffer for %s at 0x%08X\n",
  4751. substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  4752. "playback" : "capture",
  4753. snd_pcm_sgbuf_get_addr(substream, 0));
  4754. */
  4755. /*
  4756. dev_dbg(hdspm->card->dev,
  4757. "set_hwparams: %s %d Hz, %d channels, bs = %d\n",
  4758. substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  4759. "playback" : "capture",
  4760. params_rate(params), params_channels(params),
  4761. params_buffer_size(params));
  4762. */
  4763. /* For AES cards, the float format bit is the same as the
  4764. * preferred sync reference. Since we don't want to break
  4765. * sync settings, we have to skip the remaining part of this
  4766. * function.
  4767. */
  4768. if (hdspm->io_type == AES32) {
  4769. return 0;
  4770. }
  4771. /* Switch to native float format if requested */
  4772. if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
  4773. if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
  4774. dev_info(hdspm->card->dev,
  4775. "Switching to native 32bit LE float format.\n");
  4776. hdspm->control_register |= HDSPe_FLOAT_FORMAT;
  4777. } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
  4778. if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
  4779. dev_info(hdspm->card->dev,
  4780. "Switching to native 32bit LE integer format.\n");
  4781. hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
  4782. }
  4783. hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
  4784. return 0;
  4785. }
  4786. static int snd_hdspm_hw_free(struct snd_pcm_substream *substream)
  4787. {
  4788. int i;
  4789. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4790. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  4791. /* params_channels(params) should be enough,
  4792. but to get sure in case of error */
  4793. for (i = 0; i < hdspm->max_channels_out; ++i)
  4794. snd_hdspm_enable_out(hdspm, i, 0);
  4795. hdspm->playback_buffer = NULL;
  4796. } else {
  4797. for (i = 0; i < hdspm->max_channels_in; ++i)
  4798. snd_hdspm_enable_in(hdspm, i, 0);
  4799. hdspm->capture_buffer = NULL;
  4800. }
  4801. snd_pcm_lib_free_pages(substream);
  4802. return 0;
  4803. }
  4804. static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
  4805. struct snd_pcm_channel_info *info)
  4806. {
  4807. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4808. unsigned int channel = info->channel;
  4809. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  4810. if (snd_BUG_ON(channel >= hdspm->max_channels_out)) {
  4811. dev_info(hdspm->card->dev,
  4812. "snd_hdspm_channel_info: output channel out of range (%d)\n",
  4813. channel);
  4814. return -EINVAL;
  4815. }
  4816. channel = array_index_nospec(channel, hdspm->max_channels_out);
  4817. if (hdspm->channel_map_out[channel] < 0) {
  4818. dev_info(hdspm->card->dev,
  4819. "snd_hdspm_channel_info: output channel %d mapped out\n",
  4820. channel);
  4821. return -EINVAL;
  4822. }
  4823. info->offset = hdspm->channel_map_out[channel] *
  4824. HDSPM_CHANNEL_BUFFER_BYTES;
  4825. } else {
  4826. if (snd_BUG_ON(channel >= hdspm->max_channels_in)) {
  4827. dev_info(hdspm->card->dev,
  4828. "snd_hdspm_channel_info: input channel out of range (%d)\n",
  4829. channel);
  4830. return -EINVAL;
  4831. }
  4832. channel = array_index_nospec(channel, hdspm->max_channels_in);
  4833. if (hdspm->channel_map_in[channel] < 0) {
  4834. dev_info(hdspm->card->dev,
  4835. "snd_hdspm_channel_info: input channel %d mapped out\n",
  4836. channel);
  4837. return -EINVAL;
  4838. }
  4839. info->offset = hdspm->channel_map_in[channel] *
  4840. HDSPM_CHANNEL_BUFFER_BYTES;
  4841. }
  4842. info->first = 0;
  4843. info->step = 32;
  4844. return 0;
  4845. }
  4846. static int snd_hdspm_ioctl(struct snd_pcm_substream *substream,
  4847. unsigned int cmd, void *arg)
  4848. {
  4849. switch (cmd) {
  4850. case SNDRV_PCM_IOCTL1_RESET:
  4851. return snd_hdspm_reset(substream);
  4852. case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
  4853. {
  4854. struct snd_pcm_channel_info *info = arg;
  4855. return snd_hdspm_channel_info(substream, info);
  4856. }
  4857. default:
  4858. break;
  4859. }
  4860. return snd_pcm_lib_ioctl(substream, cmd, arg);
  4861. }
  4862. static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)
  4863. {
  4864. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  4865. struct snd_pcm_substream *other;
  4866. int running;
  4867. spin_lock(&hdspm->lock);
  4868. running = hdspm->running;
  4869. switch (cmd) {
  4870. case SNDRV_PCM_TRIGGER_START:
  4871. running |= 1 << substream->stream;
  4872. break;
  4873. case SNDRV_PCM_TRIGGER_STOP:
  4874. running &= ~(1 << substream->stream);
  4875. break;
  4876. default:
  4877. snd_BUG();
  4878. spin_unlock(&hdspm->lock);
  4879. return -EINVAL;
  4880. }
  4881. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  4882. other = hdspm->capture_substream;
  4883. else
  4884. other = hdspm->playback_substream;
  4885. if (other) {
  4886. struct snd_pcm_substream *s;
  4887. snd_pcm_group_for_each_entry(s, substream) {
  4888. if (s == other) {
  4889. snd_pcm_trigger_done(s, substream);
  4890. if (cmd == SNDRV_PCM_TRIGGER_START)
  4891. running |= 1 << s->stream;
  4892. else
  4893. running &= ~(1 << s->stream);
  4894. goto _ok;
  4895. }
  4896. }
  4897. if (cmd == SNDRV_PCM_TRIGGER_START) {
  4898. if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
  4899. && substream->stream ==
  4900. SNDRV_PCM_STREAM_CAPTURE)
  4901. hdspm_silence_playback(hdspm);
  4902. } else {
  4903. if (running &&
  4904. substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  4905. hdspm_silence_playback(hdspm);
  4906. }
  4907. } else {
  4908. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  4909. hdspm_silence_playback(hdspm);
  4910. }
  4911. _ok:
  4912. snd_pcm_trigger_done(substream, substream);
  4913. if (!hdspm->running && running)
  4914. hdspm_start_audio(hdspm);
  4915. else if (hdspm->running && !running)
  4916. hdspm_stop_audio(hdspm);
  4917. hdspm->running = running;
  4918. spin_unlock(&hdspm->lock);
  4919. return 0;
  4920. }
  4921. static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
  4922. {
  4923. return 0;
  4924. }
  4925. static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
  4926. .info = (SNDRV_PCM_INFO_MMAP |
  4927. SNDRV_PCM_INFO_MMAP_VALID |
  4928. SNDRV_PCM_INFO_NONINTERLEAVED |
  4929. SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
  4930. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  4931. .rates = (SNDRV_PCM_RATE_32000 |
  4932. SNDRV_PCM_RATE_44100 |
  4933. SNDRV_PCM_RATE_48000 |
  4934. SNDRV_PCM_RATE_64000 |
  4935. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
  4936. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ),
  4937. .rate_min = 32000,
  4938. .rate_max = 192000,
  4939. .channels_min = 1,
  4940. .channels_max = HDSPM_MAX_CHANNELS,
  4941. .buffer_bytes_max =
  4942. HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
  4943. .period_bytes_min = (32 * 4),
  4944. .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
  4945. .periods_min = 2,
  4946. .periods_max = 512,
  4947. .fifo_size = 0
  4948. };
  4949. static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
  4950. .info = (SNDRV_PCM_INFO_MMAP |
  4951. SNDRV_PCM_INFO_MMAP_VALID |
  4952. SNDRV_PCM_INFO_NONINTERLEAVED |
  4953. SNDRV_PCM_INFO_SYNC_START),
  4954. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  4955. .rates = (SNDRV_PCM_RATE_32000 |
  4956. SNDRV_PCM_RATE_44100 |
  4957. SNDRV_PCM_RATE_48000 |
  4958. SNDRV_PCM_RATE_64000 |
  4959. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
  4960. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000),
  4961. .rate_min = 32000,
  4962. .rate_max = 192000,
  4963. .channels_min = 1,
  4964. .channels_max = HDSPM_MAX_CHANNELS,
  4965. .buffer_bytes_max =
  4966. HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
  4967. .period_bytes_min = (32 * 4),
  4968. .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
  4969. .periods_min = 2,
  4970. .periods_max = 512,
  4971. .fifo_size = 0
  4972. };
  4973. static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
  4974. struct snd_pcm_hw_rule *rule)
  4975. {
  4976. struct hdspm *hdspm = rule->private;
  4977. struct snd_interval *c =
  4978. hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  4979. struct snd_interval *r =
  4980. hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  4981. if (r->min > 96000 && r->max <= 192000) {
  4982. struct snd_interval t = {
  4983. .min = hdspm->qs_in_channels,
  4984. .max = hdspm->qs_in_channels,
  4985. .integer = 1,
  4986. };
  4987. return snd_interval_refine(c, &t);
  4988. } else if (r->min > 48000 && r->max <= 96000) {
  4989. struct snd_interval t = {
  4990. .min = hdspm->ds_in_channels,
  4991. .max = hdspm->ds_in_channels,
  4992. .integer = 1,
  4993. };
  4994. return snd_interval_refine(c, &t);
  4995. } else if (r->max < 64000) {
  4996. struct snd_interval t = {
  4997. .min = hdspm->ss_in_channels,
  4998. .max = hdspm->ss_in_channels,
  4999. .integer = 1,
  5000. };
  5001. return snd_interval_refine(c, &t);
  5002. }
  5003. return 0;
  5004. }
  5005. static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
  5006. struct snd_pcm_hw_rule * rule)
  5007. {
  5008. struct hdspm *hdspm = rule->private;
  5009. struct snd_interval *c =
  5010. hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  5011. struct snd_interval *r =
  5012. hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  5013. if (r->min > 96000 && r->max <= 192000) {
  5014. struct snd_interval t = {
  5015. .min = hdspm->qs_out_channels,
  5016. .max = hdspm->qs_out_channels,
  5017. .integer = 1,
  5018. };
  5019. return snd_interval_refine(c, &t);
  5020. } else if (r->min > 48000 && r->max <= 96000) {
  5021. struct snd_interval t = {
  5022. .min = hdspm->ds_out_channels,
  5023. .max = hdspm->ds_out_channels,
  5024. .integer = 1,
  5025. };
  5026. return snd_interval_refine(c, &t);
  5027. } else if (r->max < 64000) {
  5028. struct snd_interval t = {
  5029. .min = hdspm->ss_out_channels,
  5030. .max = hdspm->ss_out_channels,
  5031. .integer = 1,
  5032. };
  5033. return snd_interval_refine(c, &t);
  5034. } else {
  5035. }
  5036. return 0;
  5037. }
  5038. static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
  5039. struct snd_pcm_hw_rule * rule)
  5040. {
  5041. struct hdspm *hdspm = rule->private;
  5042. struct snd_interval *c =
  5043. hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  5044. struct snd_interval *r =
  5045. hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  5046. if (c->min >= hdspm->ss_in_channels) {
  5047. struct snd_interval t = {
  5048. .min = 32000,
  5049. .max = 48000,
  5050. .integer = 1,
  5051. };
  5052. return snd_interval_refine(r, &t);
  5053. } else if (c->max <= hdspm->qs_in_channels) {
  5054. struct snd_interval t = {
  5055. .min = 128000,
  5056. .max = 192000,
  5057. .integer = 1,
  5058. };
  5059. return snd_interval_refine(r, &t);
  5060. } else if (c->max <= hdspm->ds_in_channels) {
  5061. struct snd_interval t = {
  5062. .min = 64000,
  5063. .max = 96000,
  5064. .integer = 1,
  5065. };
  5066. return snd_interval_refine(r, &t);
  5067. }
  5068. return 0;
  5069. }
  5070. static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
  5071. struct snd_pcm_hw_rule *rule)
  5072. {
  5073. struct hdspm *hdspm = rule->private;
  5074. struct snd_interval *c =
  5075. hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  5076. struct snd_interval *r =
  5077. hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  5078. if (c->min >= hdspm->ss_out_channels) {
  5079. struct snd_interval t = {
  5080. .min = 32000,
  5081. .max = 48000,
  5082. .integer = 1,
  5083. };
  5084. return snd_interval_refine(r, &t);
  5085. } else if (c->max <= hdspm->qs_out_channels) {
  5086. struct snd_interval t = {
  5087. .min = 128000,
  5088. .max = 192000,
  5089. .integer = 1,
  5090. };
  5091. return snd_interval_refine(r, &t);
  5092. } else if (c->max <= hdspm->ds_out_channels) {
  5093. struct snd_interval t = {
  5094. .min = 64000,
  5095. .max = 96000,
  5096. .integer = 1,
  5097. };
  5098. return snd_interval_refine(r, &t);
  5099. }
  5100. return 0;
  5101. }
  5102. static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params,
  5103. struct snd_pcm_hw_rule *rule)
  5104. {
  5105. unsigned int list[3];
  5106. struct hdspm *hdspm = rule->private;
  5107. struct snd_interval *c = hw_param_interval(params,
  5108. SNDRV_PCM_HW_PARAM_CHANNELS);
  5109. list[0] = hdspm->qs_in_channels;
  5110. list[1] = hdspm->ds_in_channels;
  5111. list[2] = hdspm->ss_in_channels;
  5112. return snd_interval_list(c, 3, list, 0);
  5113. }
  5114. static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params,
  5115. struct snd_pcm_hw_rule *rule)
  5116. {
  5117. unsigned int list[3];
  5118. struct hdspm *hdspm = rule->private;
  5119. struct snd_interval *c = hw_param_interval(params,
  5120. SNDRV_PCM_HW_PARAM_CHANNELS);
  5121. list[0] = hdspm->qs_out_channels;
  5122. list[1] = hdspm->ds_out_channels;
  5123. list[2] = hdspm->ss_out_channels;
  5124. return snd_interval_list(c, 3, list, 0);
  5125. }
  5126. static unsigned int hdspm_aes32_sample_rates[] = {
  5127. 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
  5128. };
  5129. static struct snd_pcm_hw_constraint_list
  5130. hdspm_hw_constraints_aes32_sample_rates = {
  5131. .count = ARRAY_SIZE(hdspm_aes32_sample_rates),
  5132. .list = hdspm_aes32_sample_rates,
  5133. .mask = 0
  5134. };
  5135. static int snd_hdspm_open(struct snd_pcm_substream *substream)
  5136. {
  5137. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  5138. struct snd_pcm_runtime *runtime = substream->runtime;
  5139. bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  5140. spin_lock_irq(&hdspm->lock);
  5141. snd_pcm_set_sync(substream);
  5142. runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
  5143. snd_hdspm_capture_subinfo;
  5144. if (playback) {
  5145. if (hdspm->capture_substream == NULL)
  5146. hdspm_stop_audio(hdspm);
  5147. hdspm->playback_pid = current->pid;
  5148. hdspm->playback_substream = substream;
  5149. } else {
  5150. if (hdspm->playback_substream == NULL)
  5151. hdspm_stop_audio(hdspm);
  5152. hdspm->capture_pid = current->pid;
  5153. hdspm->capture_substream = substream;
  5154. }
  5155. spin_unlock_irq(&hdspm->lock);
  5156. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  5157. snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
  5158. switch (hdspm->io_type) {
  5159. case AIO:
  5160. case RayDAT:
  5161. snd_pcm_hw_constraint_minmax(runtime,
  5162. SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
  5163. 32, 4096);
  5164. /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
  5165. snd_pcm_hw_constraint_single(runtime,
  5166. SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
  5167. 16384);
  5168. break;
  5169. default:
  5170. snd_pcm_hw_constraint_minmax(runtime,
  5171. SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
  5172. 64, 8192);
  5173. snd_pcm_hw_constraint_single(runtime,
  5174. SNDRV_PCM_HW_PARAM_PERIODS, 2);
  5175. break;
  5176. }
  5177. if (AES32 == hdspm->io_type) {
  5178. runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
  5179. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  5180. &hdspm_hw_constraints_aes32_sample_rates);
  5181. } else {
  5182. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  5183. (playback ?
  5184. snd_hdspm_hw_rule_rate_out_channels :
  5185. snd_hdspm_hw_rule_rate_in_channels), hdspm,
  5186. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  5187. }
  5188. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  5189. (playback ? snd_hdspm_hw_rule_out_channels :
  5190. snd_hdspm_hw_rule_in_channels), hdspm,
  5191. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  5192. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  5193. (playback ? snd_hdspm_hw_rule_out_channels_rate :
  5194. snd_hdspm_hw_rule_in_channels_rate), hdspm,
  5195. SNDRV_PCM_HW_PARAM_RATE, -1);
  5196. return 0;
  5197. }
  5198. static int snd_hdspm_release(struct snd_pcm_substream *substream)
  5199. {
  5200. struct hdspm *hdspm = snd_pcm_substream_chip(substream);
  5201. bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  5202. spin_lock_irq(&hdspm->lock);
  5203. if (playback) {
  5204. hdspm->playback_pid = -1;
  5205. hdspm->playback_substream = NULL;
  5206. } else {
  5207. hdspm->capture_pid = -1;
  5208. hdspm->capture_substream = NULL;
  5209. }
  5210. spin_unlock_irq(&hdspm->lock);
  5211. return 0;
  5212. }
  5213. static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
  5214. {
  5215. /* we have nothing to initialize but the call is required */
  5216. return 0;
  5217. }
  5218. static inline int copy_u32_le(void __user *dest, void __iomem *src)
  5219. {
  5220. u32 val = readl(src);
  5221. return copy_to_user(dest, &val, 4);
  5222. }
  5223. static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
  5224. unsigned int cmd, unsigned long arg)
  5225. {
  5226. void __user *argp = (void __user *)arg;
  5227. struct hdspm *hdspm = hw->private_data;
  5228. struct hdspm_mixer_ioctl mixer;
  5229. struct hdspm_config info;
  5230. struct hdspm_status status;
  5231. struct hdspm_version hdspm_version;
  5232. struct hdspm_peak_rms *levels;
  5233. struct hdspm_ltc ltc;
  5234. unsigned int statusregister;
  5235. long unsigned int s;
  5236. int i = 0;
  5237. switch (cmd) {
  5238. case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
  5239. levels = &hdspm->peak_rms;
  5240. for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
  5241. levels->input_peaks[i] =
  5242. readl(hdspm->iobase +
  5243. HDSPM_MADI_INPUT_PEAK + i*4);
  5244. levels->playback_peaks[i] =
  5245. readl(hdspm->iobase +
  5246. HDSPM_MADI_PLAYBACK_PEAK + i*4);
  5247. levels->output_peaks[i] =
  5248. readl(hdspm->iobase +
  5249. HDSPM_MADI_OUTPUT_PEAK + i*4);
  5250. levels->input_rms[i] =
  5251. ((uint64_t) readl(hdspm->iobase +
  5252. HDSPM_MADI_INPUT_RMS_H + i*4) << 32) |
  5253. (uint64_t) readl(hdspm->iobase +
  5254. HDSPM_MADI_INPUT_RMS_L + i*4);
  5255. levels->playback_rms[i] =
  5256. ((uint64_t)readl(hdspm->iobase +
  5257. HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) |
  5258. (uint64_t)readl(hdspm->iobase +
  5259. HDSPM_MADI_PLAYBACK_RMS_L + i*4);
  5260. levels->output_rms[i] =
  5261. ((uint64_t)readl(hdspm->iobase +
  5262. HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) |
  5263. (uint64_t)readl(hdspm->iobase +
  5264. HDSPM_MADI_OUTPUT_RMS_L + i*4);
  5265. }
  5266. if (hdspm->system_sample_rate > 96000) {
  5267. levels->speed = qs;
  5268. } else if (hdspm->system_sample_rate > 48000) {
  5269. levels->speed = ds;
  5270. } else {
  5271. levels->speed = ss;
  5272. }
  5273. levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
  5274. s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
  5275. if (0 != s) {
  5276. /* dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu
  5277. [Levels]\n", sizeof(struct hdspm_peak_rms), s);
  5278. */
  5279. return -EFAULT;
  5280. }
  5281. break;
  5282. case SNDRV_HDSPM_IOCTL_GET_LTC:
  5283. ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
  5284. i = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
  5285. if (i & HDSPM_TCO1_LTC_Input_valid) {
  5286. switch (i & (HDSPM_TCO1_LTC_Format_LSB |
  5287. HDSPM_TCO1_LTC_Format_MSB)) {
  5288. case 0:
  5289. ltc.format = fps_24;
  5290. break;
  5291. case HDSPM_TCO1_LTC_Format_LSB:
  5292. ltc.format = fps_25;
  5293. break;
  5294. case HDSPM_TCO1_LTC_Format_MSB:
  5295. ltc.format = fps_2997;
  5296. break;
  5297. default:
  5298. ltc.format = fps_30;
  5299. break;
  5300. }
  5301. if (i & HDSPM_TCO1_set_drop_frame_flag) {
  5302. ltc.frame = drop_frame;
  5303. } else {
  5304. ltc.frame = full_frame;
  5305. }
  5306. } else {
  5307. ltc.format = format_invalid;
  5308. ltc.frame = frame_invalid;
  5309. }
  5310. if (i & HDSPM_TCO1_Video_Input_Format_NTSC) {
  5311. ltc.input_format = ntsc;
  5312. } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) {
  5313. ltc.input_format = pal;
  5314. } else {
  5315. ltc.input_format = no_video;
  5316. }
  5317. s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc));
  5318. if (0 != s) {
  5319. /*
  5320. dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
  5321. return -EFAULT;
  5322. }
  5323. break;
  5324. case SNDRV_HDSPM_IOCTL_GET_CONFIG:
  5325. memset(&info, 0, sizeof(info));
  5326. spin_lock_irq(&hdspm->lock);
  5327. info.pref_sync_ref = hdspm_pref_sync_ref(hdspm);
  5328. info.wordclock_sync_check = hdspm_wc_sync_check(hdspm);
  5329. info.system_sample_rate = hdspm->system_sample_rate;
  5330. info.autosync_sample_rate =
  5331. hdspm_external_sample_rate(hdspm);
  5332. info.system_clock_mode = hdspm_system_clock_mode(hdspm);
  5333. info.clock_source = hdspm_clock_source(hdspm);
  5334. info.autosync_ref = hdspm_autosync_ref(hdspm);
  5335. info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut);
  5336. info.passthru = 0;
  5337. spin_unlock_irq(&hdspm->lock);
  5338. if (copy_to_user(argp, &info, sizeof(info)))
  5339. return -EFAULT;
  5340. break;
  5341. case SNDRV_HDSPM_IOCTL_GET_STATUS:
  5342. memset(&status, 0, sizeof(status));
  5343. status.card_type = hdspm->io_type;
  5344. status.autosync_source = hdspm_autosync_ref(hdspm);
  5345. status.card_clock = 110069313433624ULL;
  5346. status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
  5347. switch (hdspm->io_type) {
  5348. case MADI:
  5349. case MADIface:
  5350. status.card_specific.madi.sync_wc =
  5351. hdspm_wc_sync_check(hdspm);
  5352. status.card_specific.madi.sync_madi =
  5353. hdspm_madi_sync_check(hdspm);
  5354. status.card_specific.madi.sync_tco =
  5355. hdspm_tco_sync_check(hdspm);
  5356. status.card_specific.madi.sync_in =
  5357. hdspm_sync_in_sync_check(hdspm);
  5358. statusregister =
  5359. hdspm_read(hdspm, HDSPM_statusRegister);
  5360. status.card_specific.madi.madi_input =
  5361. (statusregister & HDSPM_AB_int) ? 1 : 0;
  5362. status.card_specific.madi.channel_format =
  5363. (statusregister & HDSPM_RX_64ch) ? 1 : 0;
  5364. /* TODO: Mac driver sets it when f_s>48kHz */
  5365. status.card_specific.madi.frame_format = 0;
  5366. default:
  5367. break;
  5368. }
  5369. if (copy_to_user(argp, &status, sizeof(status)))
  5370. return -EFAULT;
  5371. break;
  5372. case SNDRV_HDSPM_IOCTL_GET_VERSION:
  5373. memset(&hdspm_version, 0, sizeof(hdspm_version));
  5374. hdspm_version.card_type = hdspm->io_type;
  5375. strlcpy(hdspm_version.cardname, hdspm->card_name,
  5376. sizeof(hdspm_version.cardname));
  5377. hdspm_version.serial = hdspm->serial;
  5378. hdspm_version.firmware_rev = hdspm->firmware_rev;
  5379. hdspm_version.addons = 0;
  5380. if (hdspm->tco)
  5381. hdspm_version.addons |= HDSPM_ADDON_TCO;
  5382. if (copy_to_user(argp, &hdspm_version,
  5383. sizeof(hdspm_version)))
  5384. return -EFAULT;
  5385. break;
  5386. case SNDRV_HDSPM_IOCTL_GET_MIXER:
  5387. if (copy_from_user(&mixer, argp, sizeof(mixer)))
  5388. return -EFAULT;
  5389. if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
  5390. sizeof(struct hdspm_mixer)))
  5391. return -EFAULT;
  5392. break;
  5393. default:
  5394. return -EINVAL;
  5395. }
  5396. return 0;
  5397. }
  5398. static struct snd_pcm_ops snd_hdspm_ops = {
  5399. .open = snd_hdspm_open,
  5400. .close = snd_hdspm_release,
  5401. .ioctl = snd_hdspm_ioctl,
  5402. .hw_params = snd_hdspm_hw_params,
  5403. .hw_free = snd_hdspm_hw_free,
  5404. .prepare = snd_hdspm_prepare,
  5405. .trigger = snd_hdspm_trigger,
  5406. .pointer = snd_hdspm_hw_pointer,
  5407. .page = snd_pcm_sgbuf_ops_page,
  5408. };
  5409. static int snd_hdspm_create_hwdep(struct snd_card *card,
  5410. struct hdspm *hdspm)
  5411. {
  5412. struct snd_hwdep *hw;
  5413. int err;
  5414. err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw);
  5415. if (err < 0)
  5416. return err;
  5417. hdspm->hwdep = hw;
  5418. hw->private_data = hdspm;
  5419. strcpy(hw->name, "HDSPM hwdep interface");
  5420. hw->ops.open = snd_hdspm_hwdep_dummy_op;
  5421. hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
  5422. hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl;
  5423. hw->ops.release = snd_hdspm_hwdep_dummy_op;
  5424. return 0;
  5425. }
  5426. /*------------------------------------------------------------
  5427. memory interface
  5428. ------------------------------------------------------------*/
  5429. static int snd_hdspm_preallocate_memory(struct hdspm *hdspm)
  5430. {
  5431. int err;
  5432. struct snd_pcm *pcm;
  5433. size_t wanted;
  5434. pcm = hdspm->pcm;
  5435. wanted = HDSPM_DMA_AREA_BYTES;
  5436. err =
  5437. snd_pcm_lib_preallocate_pages_for_all(pcm,
  5438. SNDRV_DMA_TYPE_DEV_SG,
  5439. snd_dma_pci_data(hdspm->pci),
  5440. wanted,
  5441. wanted);
  5442. if (err < 0) {
  5443. dev_dbg(hdspm->card->dev,
  5444. "Could not preallocate %zd Bytes\n", wanted);
  5445. return err;
  5446. } else
  5447. dev_dbg(hdspm->card->dev,
  5448. " Preallocated %zd Bytes\n", wanted);
  5449. return 0;
  5450. }
  5451. static void hdspm_set_sgbuf(struct hdspm *hdspm,
  5452. struct snd_pcm_substream *substream,
  5453. unsigned int reg, int channels)
  5454. {
  5455. int i;
  5456. /* continuous memory segment */
  5457. for (i = 0; i < (channels * 16); i++)
  5458. hdspm_write(hdspm, reg + 4 * i,
  5459. snd_pcm_sgbuf_get_addr(substream, 4096 * i));
  5460. }
  5461. /* ------------- ALSA Devices ---------------------------- */
  5462. static int snd_hdspm_create_pcm(struct snd_card *card,
  5463. struct hdspm *hdspm)
  5464. {
  5465. struct snd_pcm *pcm;
  5466. int err;
  5467. err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm);
  5468. if (err < 0)
  5469. return err;
  5470. hdspm->pcm = pcm;
  5471. pcm->private_data = hdspm;
  5472. strcpy(pcm->name, hdspm->card_name);
  5473. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  5474. &snd_hdspm_ops);
  5475. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  5476. &snd_hdspm_ops);
  5477. pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
  5478. err = snd_hdspm_preallocate_memory(hdspm);
  5479. if (err < 0)
  5480. return err;
  5481. return 0;
  5482. }
  5483. static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
  5484. {
  5485. int i;
  5486. for (i = 0; i < hdspm->midiPorts; i++)
  5487. snd_hdspm_flush_midi_input(hdspm, i);
  5488. }
  5489. static int snd_hdspm_create_alsa_devices(struct snd_card *card,
  5490. struct hdspm *hdspm)
  5491. {
  5492. int err, i;
  5493. dev_dbg(card->dev, "Create card...\n");
  5494. err = snd_hdspm_create_pcm(card, hdspm);
  5495. if (err < 0)
  5496. return err;
  5497. i = 0;
  5498. while (i < hdspm->midiPorts) {
  5499. err = snd_hdspm_create_midi(card, hdspm, i);
  5500. if (err < 0) {
  5501. return err;
  5502. }
  5503. i++;
  5504. }
  5505. err = snd_hdspm_create_controls(card, hdspm);
  5506. if (err < 0)
  5507. return err;
  5508. err = snd_hdspm_create_hwdep(card, hdspm);
  5509. if (err < 0)
  5510. return err;
  5511. dev_dbg(card->dev, "proc init...\n");
  5512. snd_hdspm_proc_init(hdspm);
  5513. hdspm->system_sample_rate = -1;
  5514. hdspm->last_external_sample_rate = -1;
  5515. hdspm->last_internal_sample_rate = -1;
  5516. hdspm->playback_pid = -1;
  5517. hdspm->capture_pid = -1;
  5518. hdspm->capture_substream = NULL;
  5519. hdspm->playback_substream = NULL;
  5520. dev_dbg(card->dev, "Set defaults...\n");
  5521. err = snd_hdspm_set_defaults(hdspm);
  5522. if (err < 0)
  5523. return err;
  5524. dev_dbg(card->dev, "Update mixer controls...\n");
  5525. hdspm_update_simple_mixer_controls(hdspm);
  5526. dev_dbg(card->dev, "Initializeing complete ???\n");
  5527. err = snd_card_register(card);
  5528. if (err < 0) {
  5529. dev_err(card->dev, "error registering card\n");
  5530. return err;
  5531. }
  5532. dev_dbg(card->dev, "... yes now\n");
  5533. return 0;
  5534. }
  5535. static int snd_hdspm_create(struct snd_card *card,
  5536. struct hdspm *hdspm)
  5537. {
  5538. struct pci_dev *pci = hdspm->pci;
  5539. int err;
  5540. unsigned long io_extent;
  5541. hdspm->irq = -1;
  5542. hdspm->card = card;
  5543. spin_lock_init(&hdspm->lock);
  5544. pci_read_config_word(hdspm->pci,
  5545. PCI_CLASS_REVISION, &hdspm->firmware_rev);
  5546. strcpy(card->mixername, "Xilinx FPGA");
  5547. strcpy(card->driver, "HDSPM");
  5548. switch (hdspm->firmware_rev) {
  5549. case HDSPM_RAYDAT_REV:
  5550. hdspm->io_type = RayDAT;
  5551. hdspm->card_name = "RME RayDAT";
  5552. hdspm->midiPorts = 2;
  5553. break;
  5554. case HDSPM_AIO_REV:
  5555. hdspm->io_type = AIO;
  5556. hdspm->card_name = "RME AIO";
  5557. hdspm->midiPorts = 1;
  5558. break;
  5559. case HDSPM_MADIFACE_REV:
  5560. hdspm->io_type = MADIface;
  5561. hdspm->card_name = "RME MADIface";
  5562. hdspm->midiPorts = 1;
  5563. break;
  5564. default:
  5565. if ((hdspm->firmware_rev == 0xf0) ||
  5566. ((hdspm->firmware_rev >= 0xe6) &&
  5567. (hdspm->firmware_rev <= 0xea))) {
  5568. hdspm->io_type = AES32;
  5569. hdspm->card_name = "RME AES32";
  5570. hdspm->midiPorts = 2;
  5571. } else if ((hdspm->firmware_rev == 0xd2) ||
  5572. ((hdspm->firmware_rev >= 0xc8) &&
  5573. (hdspm->firmware_rev <= 0xcf))) {
  5574. hdspm->io_type = MADI;
  5575. hdspm->card_name = "RME MADI";
  5576. hdspm->midiPorts = 3;
  5577. } else {
  5578. dev_err(card->dev,
  5579. "unknown firmware revision %x\n",
  5580. hdspm->firmware_rev);
  5581. return -ENODEV;
  5582. }
  5583. }
  5584. err = pci_enable_device(pci);
  5585. if (err < 0)
  5586. return err;
  5587. pci_set_master(hdspm->pci);
  5588. err = pci_request_regions(pci, "hdspm");
  5589. if (err < 0)
  5590. return err;
  5591. hdspm->port = pci_resource_start(pci, 0);
  5592. io_extent = pci_resource_len(pci, 0);
  5593. dev_dbg(card->dev, "grabbed memory region 0x%lx-0x%lx\n",
  5594. hdspm->port, hdspm->port + io_extent - 1);
  5595. hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
  5596. if (!hdspm->iobase) {
  5597. dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n",
  5598. hdspm->port, hdspm->port + io_extent - 1);
  5599. return -EBUSY;
  5600. }
  5601. dev_dbg(card->dev, "remapped region (0x%lx) 0x%lx-0x%lx\n",
  5602. (unsigned long)hdspm->iobase, hdspm->port,
  5603. hdspm->port + io_extent - 1);
  5604. if (request_irq(pci->irq, snd_hdspm_interrupt,
  5605. IRQF_SHARED, KBUILD_MODNAME, hdspm)) {
  5606. dev_err(card->dev, "unable to use IRQ %d\n", pci->irq);
  5607. return -EBUSY;
  5608. }
  5609. dev_dbg(card->dev, "use IRQ %d\n", pci->irq);
  5610. hdspm->irq = pci->irq;
  5611. dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n",
  5612. sizeof(struct hdspm_mixer));
  5613. hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
  5614. if (!hdspm->mixer) {
  5615. dev_err(card->dev,
  5616. "unable to kmalloc Mixer memory of %d Bytes\n",
  5617. (int)sizeof(struct hdspm_mixer));
  5618. return -ENOMEM;
  5619. }
  5620. hdspm->port_names_in = NULL;
  5621. hdspm->port_names_out = NULL;
  5622. switch (hdspm->io_type) {
  5623. case AES32:
  5624. hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS;
  5625. hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS;
  5626. hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS;
  5627. hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
  5628. channel_map_aes32;
  5629. hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
  5630. channel_map_aes32;
  5631. hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
  5632. channel_map_aes32;
  5633. hdspm->port_names_in_ss = hdspm->port_names_out_ss =
  5634. texts_ports_aes32;
  5635. hdspm->port_names_in_ds = hdspm->port_names_out_ds =
  5636. texts_ports_aes32;
  5637. hdspm->port_names_in_qs = hdspm->port_names_out_qs =
  5638. texts_ports_aes32;
  5639. hdspm->max_channels_out = hdspm->max_channels_in =
  5640. AES32_CHANNELS;
  5641. hdspm->port_names_in = hdspm->port_names_out =
  5642. texts_ports_aes32;
  5643. hdspm->channel_map_in = hdspm->channel_map_out =
  5644. channel_map_aes32;
  5645. break;
  5646. case MADI:
  5647. case MADIface:
  5648. hdspm->ss_in_channels = hdspm->ss_out_channels =
  5649. MADI_SS_CHANNELS;
  5650. hdspm->ds_in_channels = hdspm->ds_out_channels =
  5651. MADI_DS_CHANNELS;
  5652. hdspm->qs_in_channels = hdspm->qs_out_channels =
  5653. MADI_QS_CHANNELS;
  5654. hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
  5655. channel_map_unity_ss;
  5656. hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
  5657. channel_map_unity_ss;
  5658. hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
  5659. channel_map_unity_ss;
  5660. hdspm->port_names_in_ss = hdspm->port_names_out_ss =
  5661. texts_ports_madi;
  5662. hdspm->port_names_in_ds = hdspm->port_names_out_ds =
  5663. texts_ports_madi;
  5664. hdspm->port_names_in_qs = hdspm->port_names_out_qs =
  5665. texts_ports_madi;
  5666. break;
  5667. case AIO:
  5668. hdspm->ss_in_channels = AIO_IN_SS_CHANNELS;
  5669. hdspm->ds_in_channels = AIO_IN_DS_CHANNELS;
  5670. hdspm->qs_in_channels = AIO_IN_QS_CHANNELS;
  5671. hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS;
  5672. hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS;
  5673. hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
  5674. if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
  5675. dev_info(card->dev, "AEB input board found\n");
  5676. hdspm->ss_in_channels += 4;
  5677. hdspm->ds_in_channels += 4;
  5678. hdspm->qs_in_channels += 4;
  5679. }
  5680. if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) {
  5681. dev_info(card->dev, "AEB output board found\n");
  5682. hdspm->ss_out_channels += 4;
  5683. hdspm->ds_out_channels += 4;
  5684. hdspm->qs_out_channels += 4;
  5685. }
  5686. hdspm->channel_map_out_ss = channel_map_aio_out_ss;
  5687. hdspm->channel_map_out_ds = channel_map_aio_out_ds;
  5688. hdspm->channel_map_out_qs = channel_map_aio_out_qs;
  5689. hdspm->channel_map_in_ss = channel_map_aio_in_ss;
  5690. hdspm->channel_map_in_ds = channel_map_aio_in_ds;
  5691. hdspm->channel_map_in_qs = channel_map_aio_in_qs;
  5692. hdspm->port_names_in_ss = texts_ports_aio_in_ss;
  5693. hdspm->port_names_out_ss = texts_ports_aio_out_ss;
  5694. hdspm->port_names_in_ds = texts_ports_aio_in_ds;
  5695. hdspm->port_names_out_ds = texts_ports_aio_out_ds;
  5696. hdspm->port_names_in_qs = texts_ports_aio_in_qs;
  5697. hdspm->port_names_out_qs = texts_ports_aio_out_qs;
  5698. break;
  5699. case RayDAT:
  5700. hdspm->ss_in_channels = hdspm->ss_out_channels =
  5701. RAYDAT_SS_CHANNELS;
  5702. hdspm->ds_in_channels = hdspm->ds_out_channels =
  5703. RAYDAT_DS_CHANNELS;
  5704. hdspm->qs_in_channels = hdspm->qs_out_channels =
  5705. RAYDAT_QS_CHANNELS;
  5706. hdspm->max_channels_in = RAYDAT_SS_CHANNELS;
  5707. hdspm->max_channels_out = RAYDAT_SS_CHANNELS;
  5708. hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
  5709. channel_map_raydat_ss;
  5710. hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
  5711. channel_map_raydat_ds;
  5712. hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
  5713. channel_map_raydat_qs;
  5714. hdspm->channel_map_in = hdspm->channel_map_out =
  5715. channel_map_raydat_ss;
  5716. hdspm->port_names_in_ss = hdspm->port_names_out_ss =
  5717. texts_ports_raydat_ss;
  5718. hdspm->port_names_in_ds = hdspm->port_names_out_ds =
  5719. texts_ports_raydat_ds;
  5720. hdspm->port_names_in_qs = hdspm->port_names_out_qs =
  5721. texts_ports_raydat_qs;
  5722. break;
  5723. }
  5724. /* TCO detection */
  5725. switch (hdspm->io_type) {
  5726. case AIO:
  5727. case RayDAT:
  5728. if (hdspm_read(hdspm, HDSPM_statusRegister2) &
  5729. HDSPM_s2_tco_detect) {
  5730. hdspm->midiPorts++;
  5731. hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
  5732. GFP_KERNEL);
  5733. if (NULL != hdspm->tco) {
  5734. hdspm_tco_write(hdspm);
  5735. }
  5736. dev_info(card->dev, "AIO/RayDAT TCO module found\n");
  5737. } else {
  5738. hdspm->tco = NULL;
  5739. }
  5740. break;
  5741. case MADI:
  5742. case AES32:
  5743. if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) {
  5744. hdspm->midiPorts++;
  5745. hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
  5746. GFP_KERNEL);
  5747. if (NULL != hdspm->tco) {
  5748. hdspm_tco_write(hdspm);
  5749. }
  5750. dev_info(card->dev, "MADI/AES TCO module found\n");
  5751. } else {
  5752. hdspm->tco = NULL;
  5753. }
  5754. break;
  5755. default:
  5756. hdspm->tco = NULL;
  5757. }
  5758. /* texts */
  5759. switch (hdspm->io_type) {
  5760. case AES32:
  5761. if (hdspm->tco) {
  5762. hdspm->texts_autosync = texts_autosync_aes_tco;
  5763. hdspm->texts_autosync_items =
  5764. ARRAY_SIZE(texts_autosync_aes_tco);
  5765. } else {
  5766. hdspm->texts_autosync = texts_autosync_aes;
  5767. hdspm->texts_autosync_items =
  5768. ARRAY_SIZE(texts_autosync_aes);
  5769. }
  5770. break;
  5771. case MADI:
  5772. if (hdspm->tco) {
  5773. hdspm->texts_autosync = texts_autosync_madi_tco;
  5774. hdspm->texts_autosync_items = 4;
  5775. } else {
  5776. hdspm->texts_autosync = texts_autosync_madi;
  5777. hdspm->texts_autosync_items = 3;
  5778. }
  5779. break;
  5780. case MADIface:
  5781. break;
  5782. case RayDAT:
  5783. if (hdspm->tco) {
  5784. hdspm->texts_autosync = texts_autosync_raydat_tco;
  5785. hdspm->texts_autosync_items = 9;
  5786. } else {
  5787. hdspm->texts_autosync = texts_autosync_raydat;
  5788. hdspm->texts_autosync_items = 8;
  5789. }
  5790. break;
  5791. case AIO:
  5792. if (hdspm->tco) {
  5793. hdspm->texts_autosync = texts_autosync_aio_tco;
  5794. hdspm->texts_autosync_items = 6;
  5795. } else {
  5796. hdspm->texts_autosync = texts_autosync_aio;
  5797. hdspm->texts_autosync_items = 5;
  5798. }
  5799. break;
  5800. }
  5801. tasklet_init(&hdspm->midi_tasklet,
  5802. hdspm_midi_tasklet, (unsigned long) hdspm);
  5803. if (hdspm->io_type != MADIface) {
  5804. hdspm->serial = (hdspm_read(hdspm,
  5805. HDSPM_midiStatusIn0)>>8) & 0xFFFFFF;
  5806. /* id contains either a user-provided value or the default
  5807. * NULL. If it's the default, we're safe to
  5808. * fill card->id with the serial number.
  5809. *
  5810. * If the serial number is 0xFFFFFF, then we're dealing with
  5811. * an old PCI revision that comes without a sane number. In
  5812. * this case, we don't set card->id to avoid collisions
  5813. * when running with multiple cards.
  5814. */
  5815. if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) {
  5816. sprintf(card->id, "HDSPMx%06x", hdspm->serial);
  5817. snd_card_set_id(card, card->id);
  5818. }
  5819. }
  5820. dev_dbg(card->dev, "create alsa devices.\n");
  5821. err = snd_hdspm_create_alsa_devices(card, hdspm);
  5822. if (err < 0)
  5823. return err;
  5824. snd_hdspm_initialize_midi_flush(hdspm);
  5825. return 0;
  5826. }
  5827. static int snd_hdspm_free(struct hdspm * hdspm)
  5828. {
  5829. if (hdspm->port) {
  5830. /* stop th audio, and cancel all interrupts */
  5831. hdspm->control_register &=
  5832. ~(HDSPM_Start | HDSPM_AudioInterruptEnable |
  5833. HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable |
  5834. HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable);
  5835. hdspm_write(hdspm, HDSPM_controlRegister,
  5836. hdspm->control_register);
  5837. }
  5838. if (hdspm->irq >= 0)
  5839. free_irq(hdspm->irq, (void *) hdspm);
  5840. kfree(hdspm->mixer);
  5841. iounmap(hdspm->iobase);
  5842. if (hdspm->port)
  5843. pci_release_regions(hdspm->pci);
  5844. pci_disable_device(hdspm->pci);
  5845. return 0;
  5846. }
  5847. static void snd_hdspm_card_free(struct snd_card *card)
  5848. {
  5849. struct hdspm *hdspm = card->private_data;
  5850. if (hdspm)
  5851. snd_hdspm_free(hdspm);
  5852. }
  5853. static int snd_hdspm_probe(struct pci_dev *pci,
  5854. const struct pci_device_id *pci_id)
  5855. {
  5856. static int dev;
  5857. struct hdspm *hdspm;
  5858. struct snd_card *card;
  5859. int err;
  5860. if (dev >= SNDRV_CARDS)
  5861. return -ENODEV;
  5862. if (!enable[dev]) {
  5863. dev++;
  5864. return -ENOENT;
  5865. }
  5866. err = snd_card_new(&pci->dev, index[dev], id[dev],
  5867. THIS_MODULE, sizeof(struct hdspm), &card);
  5868. if (err < 0)
  5869. return err;
  5870. hdspm = card->private_data;
  5871. card->private_free = snd_hdspm_card_free;
  5872. hdspm->dev = dev;
  5873. hdspm->pci = pci;
  5874. err = snd_hdspm_create(card, hdspm);
  5875. if (err < 0) {
  5876. snd_card_free(card);
  5877. return err;
  5878. }
  5879. if (hdspm->io_type != MADIface) {
  5880. sprintf(card->shortname, "%s_%x",
  5881. hdspm->card_name,
  5882. hdspm->serial);
  5883. sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d",
  5884. hdspm->card_name,
  5885. hdspm->serial,
  5886. hdspm->port, hdspm->irq);
  5887. } else {
  5888. sprintf(card->shortname, "%s", hdspm->card_name);
  5889. sprintf(card->longname, "%s at 0x%lx, irq %d",
  5890. hdspm->card_name, hdspm->port, hdspm->irq);
  5891. }
  5892. err = snd_card_register(card);
  5893. if (err < 0) {
  5894. snd_card_free(card);
  5895. return err;
  5896. }
  5897. pci_set_drvdata(pci, card);
  5898. dev++;
  5899. return 0;
  5900. }
  5901. static void snd_hdspm_remove(struct pci_dev *pci)
  5902. {
  5903. snd_card_free(pci_get_drvdata(pci));
  5904. }
  5905. static struct pci_driver hdspm_driver = {
  5906. .name = KBUILD_MODNAME,
  5907. .id_table = snd_hdspm_ids,
  5908. .probe = snd_hdspm_probe,
  5909. .remove = snd_hdspm_remove,
  5910. };
  5911. module_pci_driver(hdspm_driver);