hdspm.c 185 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999
  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 External 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 const 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);