hdsp.c 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139
  1. /*
  2. * ALSA driver for RME Hammerfall DSP audio interface(s)
  3. *
  4. * Copyright (c) 2002 Paul Davis
  5. * Marcus Andersson
  6. * Thomas Charbonnel
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/slab.h>
  28. #include <linux/pci.h>
  29. #include <linux/firmware.h>
  30. #include <linux/moduleparam.h>
  31. #include <sound/core.h>
  32. #include <sound/control.h>
  33. #include <sound/pcm.h>
  34. #include <sound/info.h>
  35. #include <sound/asoundef.h>
  36. #include <sound/rawmidi.h>
  37. #include <sound/hwdep.h>
  38. #include <sound/initval.h>
  39. #include <sound/hdsp.h>
  40. #include <asm/byteorder.h>
  41. #include <asm/current.h>
  42. #include <asm/io.h>
  43. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  44. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  45. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  46. module_param_array(index, int, NULL, 0444);
  47. MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
  48. module_param_array(id, charp, NULL, 0444);
  49. MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
  50. module_param_array(enable, bool, NULL, 0444);
  51. MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
  52. MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
  53. MODULE_DESCRIPTION("RME Hammerfall DSP");
  54. MODULE_LICENSE("GPL");
  55. MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
  56. "{RME HDSP-9652},"
  57. "{RME HDSP-9632}}");
  58. #define HDSP_MAX_CHANNELS 26
  59. #define HDSP_MAX_DS_CHANNELS 14
  60. #define HDSP_MAX_QS_CHANNELS 8
  61. #define DIGIFACE_SS_CHANNELS 26
  62. #define DIGIFACE_DS_CHANNELS 14
  63. #define MULTIFACE_SS_CHANNELS 18
  64. #define MULTIFACE_DS_CHANNELS 14
  65. #define H9652_SS_CHANNELS 26
  66. #define H9652_DS_CHANNELS 14
  67. /* This does not include possible Analog Extension Boards
  68. AEBs are detected at card initialization
  69. */
  70. #define H9632_SS_CHANNELS 12
  71. #define H9632_DS_CHANNELS 8
  72. #define H9632_QS_CHANNELS 4
  73. /* Write registers. These are defined as byte-offsets from the iobase value.
  74. */
  75. #define HDSP_resetPointer 0
  76. #define HDSP_freqReg 0
  77. #define HDSP_outputBufferAddress 32
  78. #define HDSP_inputBufferAddress 36
  79. #define HDSP_controlRegister 64
  80. #define HDSP_interruptConfirmation 96
  81. #define HDSP_outputEnable 128
  82. #define HDSP_control2Reg 256
  83. #define HDSP_midiDataOut0 352
  84. #define HDSP_midiDataOut1 356
  85. #define HDSP_fifoData 368
  86. #define HDSP_inputEnable 384
  87. /* Read registers. These are defined as byte-offsets from the iobase value
  88. */
  89. #define HDSP_statusRegister 0
  90. #define HDSP_timecode 128
  91. #define HDSP_status2Register 192
  92. #define HDSP_midiDataOut0 352
  93. #define HDSP_midiDataOut1 356
  94. #define HDSP_midiDataIn0 360
  95. #define HDSP_midiDataIn1 364
  96. #define HDSP_midiStatusOut0 384
  97. #define HDSP_midiStatusOut1 388
  98. #define HDSP_midiStatusIn0 392
  99. #define HDSP_midiStatusIn1 396
  100. #define HDSP_fifoStatus 400
  101. /* the meters are regular i/o-mapped registers, but offset
  102. considerably from the rest. the peak registers are reset
  103. when read; the least-significant 4 bits are full-scale counters;
  104. the actual peak value is in the most-significant 24 bits.
  105. */
  106. #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
  107. #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
  108. #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
  109. #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
  110. #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
  111. /* This is for H9652 cards
  112. Peak values are read downward from the base
  113. Rms values are read upward
  114. There are rms values for the outputs too
  115. 26*3 values are read in ss mode
  116. 14*3 in ds mode, with no gap between values
  117. */
  118. #define HDSP_9652_peakBase 7164
  119. #define HDSP_9652_rmsBase 4096
  120. /* c.f. the hdsp_9632_meters_t struct */
  121. #define HDSP_9632_metersBase 4096
  122. #define HDSP_IO_EXTENT 7168
  123. /* control2 register bits */
  124. #define HDSP_TMS 0x01
  125. #define HDSP_TCK 0x02
  126. #define HDSP_TDI 0x04
  127. #define HDSP_JTAG 0x08
  128. #define HDSP_PWDN 0x10
  129. #define HDSP_PROGRAM 0x020
  130. #define HDSP_CONFIG_MODE_0 0x040
  131. #define HDSP_CONFIG_MODE_1 0x080
  132. #define HDSP_VERSION_BIT 0x100
  133. #define HDSP_BIGENDIAN_MODE 0x200
  134. #define HDSP_RD_MULTIPLE 0x400
  135. #define HDSP_9652_ENABLE_MIXER 0x800
  136. #define HDSP_TDO 0x10000000
  137. #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
  138. #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
  139. /* Control Register bits */
  140. #define HDSP_Start (1<<0) /* start engine */
  141. #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
  142. #define HDSP_Latency1 (1<<2) /* [ see above ] */
  143. #define HDSP_Latency2 (1<<3) /* [ see above ] */
  144. #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
  145. #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
  146. #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
  147. #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
  148. #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
  149. #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
  150. #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
  151. #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
  152. #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
  153. #define HDSP_SyncRef2 (1<<13)
  154. #define HDSP_SPDIFInputSelect0 (1<<14)
  155. #define HDSP_SPDIFInputSelect1 (1<<15)
  156. #define HDSP_SyncRef0 (1<<16)
  157. #define HDSP_SyncRef1 (1<<17)
  158. #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
  159. #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
  160. #define HDSP_Midi0InterruptEnable (1<<22)
  161. #define HDSP_Midi1InterruptEnable (1<<23)
  162. #define HDSP_LineOut (1<<24)
  163. #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
  164. #define HDSP_ADGain1 (1<<26)
  165. #define HDSP_DAGain0 (1<<27)
  166. #define HDSP_DAGain1 (1<<28)
  167. #define HDSP_PhoneGain0 (1<<29)
  168. #define HDSP_PhoneGain1 (1<<30)
  169. #define HDSP_QuadSpeed (1<<31)
  170. #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
  171. #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
  172. #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
  173. #define HDSP_ADGainLowGain 0
  174. #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
  175. #define HDSP_DAGainHighGain HDSP_DAGainMask
  176. #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
  177. #define HDSP_DAGainMinus10dBV 0
  178. #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
  179. #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
  180. #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
  181. #define HDSP_PhoneGainMinus12dB 0
  182. #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
  183. #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
  184. #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
  185. #define HDSP_SPDIFInputADAT1 0
  186. #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
  187. #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
  188. #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
  189. #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
  190. #define HDSP_SyncRef_ADAT1 0
  191. #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
  192. #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
  193. #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
  194. #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
  195. #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
  196. /* Sample Clock Sources */
  197. #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
  198. #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
  199. #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
  200. #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
  201. #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
  202. #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
  203. #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
  204. #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
  205. #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
  206. #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
  207. /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
  208. #define HDSP_SYNC_FROM_WORD 0
  209. #define HDSP_SYNC_FROM_SPDIF 1
  210. #define HDSP_SYNC_FROM_ADAT1 2
  211. #define HDSP_SYNC_FROM_ADAT_SYNC 3
  212. #define HDSP_SYNC_FROM_ADAT2 4
  213. #define HDSP_SYNC_FROM_ADAT3 5
  214. /* SyncCheck status */
  215. #define HDSP_SYNC_CHECK_NO_LOCK 0
  216. #define HDSP_SYNC_CHECK_LOCK 1
  217. #define HDSP_SYNC_CHECK_SYNC 2
  218. /* AutoSync references - used by "autosync_ref" control switch */
  219. #define HDSP_AUTOSYNC_FROM_WORD 0
  220. #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
  221. #define HDSP_AUTOSYNC_FROM_SPDIF 2
  222. #define HDSP_AUTOSYNC_FROM_NONE 3
  223. #define HDSP_AUTOSYNC_FROM_ADAT1 4
  224. #define HDSP_AUTOSYNC_FROM_ADAT2 5
  225. #define HDSP_AUTOSYNC_FROM_ADAT3 6
  226. /* Possible sources of S/PDIF input */
  227. #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
  228. #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
  229. #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
  230. #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
  231. #define HDSP_Frequency32KHz HDSP_Frequency0
  232. #define HDSP_Frequency44_1KHz HDSP_Frequency1
  233. #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
  234. #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
  235. #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
  236. #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
  237. /* For H9632 cards */
  238. #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
  239. #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
  240. #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
  241. #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
  242. #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
  243. #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
  244. #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
  245. /* Status Register bits */
  246. #define HDSP_audioIRQPending (1<<0)
  247. #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
  248. #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
  249. #define HDSP_Lock1 (1<<2)
  250. #define HDSP_Lock0 (1<<3)
  251. #define HDSP_SPDIFSync (1<<4)
  252. #define HDSP_TimecodeLock (1<<5)
  253. #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
  254. #define HDSP_Sync2 (1<<16)
  255. #define HDSP_Sync1 (1<<17)
  256. #define HDSP_Sync0 (1<<18)
  257. #define HDSP_DoubleSpeedStatus (1<<19)
  258. #define HDSP_ConfigError (1<<20)
  259. #define HDSP_DllError (1<<21)
  260. #define HDSP_spdifFrequency0 (1<<22)
  261. #define HDSP_spdifFrequency1 (1<<23)
  262. #define HDSP_spdifFrequency2 (1<<24)
  263. #define HDSP_SPDIFErrorFlag (1<<25)
  264. #define HDSP_BufferID (1<<26)
  265. #define HDSP_TimecodeSync (1<<27)
  266. #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
  267. #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
  268. #define HDSP_midi0IRQPending (1<<30)
  269. #define HDSP_midi1IRQPending (1<<31)
  270. #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
  271. #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
  272. #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
  273. #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
  274. #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
  275. #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
  276. #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
  277. /* This is for H9632 cards */
  278. #define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask
  279. #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
  280. #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
  281. /* Status2 Register bits */
  282. #define HDSP_version0 (1<<0)
  283. #define HDSP_version1 (1<<1)
  284. #define HDSP_version2 (1<<2)
  285. #define HDSP_wc_lock (1<<3)
  286. #define HDSP_wc_sync (1<<4)
  287. #define HDSP_inp_freq0 (1<<5)
  288. #define HDSP_inp_freq1 (1<<6)
  289. #define HDSP_inp_freq2 (1<<7)
  290. #define HDSP_SelSyncRef0 (1<<8)
  291. #define HDSP_SelSyncRef1 (1<<9)
  292. #define HDSP_SelSyncRef2 (1<<10)
  293. #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
  294. #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
  295. #define HDSP_systemFrequency32 (HDSP_inp_freq0)
  296. #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
  297. #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
  298. #define HDSP_systemFrequency64 (HDSP_inp_freq2)
  299. #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
  300. #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
  301. /* FIXME : more values for 9632 cards ? */
  302. #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
  303. #define HDSP_SelSyncRef_ADAT1 0
  304. #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
  305. #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
  306. #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
  307. #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
  308. #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
  309. /* Card state flags */
  310. #define HDSP_InitializationComplete (1<<0)
  311. #define HDSP_FirmwareLoaded (1<<1)
  312. #define HDSP_FirmwareCached (1<<2)
  313. /* FIFO wait times, defined in terms of 1/10ths of msecs */
  314. #define HDSP_LONG_WAIT 5000
  315. #define HDSP_SHORT_WAIT 30
  316. #define UNITY_GAIN 32768
  317. #define MINUS_INFINITY_GAIN 0
  318. /* the size of a substream (1 mono data stream) */
  319. #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
  320. #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
  321. /* the size of the area we need to allocate for DMA transfers. the
  322. size is the same regardless of the number of channels - the
  323. Multiface still uses the same memory area.
  324. Note that we allocate 1 more channel than is apparently needed
  325. because the h/w seems to write 1 byte beyond the end of the last
  326. page. Sigh.
  327. */
  328. #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
  329. #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
  330. /* use hotplug firmeare loader? */
  331. #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
  332. #if !defined(HDSP_USE_HWDEP_LOADER) && !defined(CONFIG_SND_HDSP)
  333. #define HDSP_FW_LOADER
  334. #endif
  335. #endif
  336. struct hdsp_9632_meters {
  337. u32 input_peak[16];
  338. u32 playback_peak[16];
  339. u32 output_peak[16];
  340. u32 xxx_peak[16];
  341. u32 padding[64];
  342. u32 input_rms_low[16];
  343. u32 playback_rms_low[16];
  344. u32 output_rms_low[16];
  345. u32 xxx_rms_low[16];
  346. u32 input_rms_high[16];
  347. u32 playback_rms_high[16];
  348. u32 output_rms_high[16];
  349. u32 xxx_rms_high[16];
  350. };
  351. struct hdsp_midi {
  352. struct hdsp *hdsp;
  353. int id;
  354. struct snd_rawmidi *rmidi;
  355. struct snd_rawmidi_substream *input;
  356. struct snd_rawmidi_substream *output;
  357. char istimer; /* timer in use */
  358. struct timer_list timer;
  359. spinlock_t lock;
  360. int pending;
  361. };
  362. struct hdsp {
  363. spinlock_t lock;
  364. struct snd_pcm_substream *capture_substream;
  365. struct snd_pcm_substream *playback_substream;
  366. struct hdsp_midi midi[2];
  367. struct tasklet_struct midi_tasklet;
  368. int use_midi_tasklet;
  369. int precise_ptr;
  370. u32 control_register; /* cached value */
  371. u32 control2_register; /* cached value */
  372. u32 creg_spdif;
  373. u32 creg_spdif_stream;
  374. int clock_source_locked;
  375. char *card_name; /* digiface/multiface */
  376. enum HDSP_IO_Type io_type; /* ditto, but for code use */
  377. unsigned short firmware_rev;
  378. unsigned short state; /* stores state bits */
  379. u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
  380. size_t period_bytes; /* guess what this is */
  381. unsigned char max_channels;
  382. unsigned char qs_in_channels; /* quad speed mode for H9632 */
  383. unsigned char ds_in_channels;
  384. unsigned char ss_in_channels; /* different for multiface/digiface */
  385. unsigned char qs_out_channels;
  386. unsigned char ds_out_channels;
  387. unsigned char ss_out_channels;
  388. struct snd_dma_buffer capture_dma_buf;
  389. struct snd_dma_buffer playback_dma_buf;
  390. unsigned char *capture_buffer; /* suitably aligned address */
  391. unsigned char *playback_buffer; /* suitably aligned address */
  392. pid_t capture_pid;
  393. pid_t playback_pid;
  394. int running;
  395. int system_sample_rate;
  396. char *channel_map;
  397. int dev;
  398. int irq;
  399. unsigned long port;
  400. void __iomem *iobase;
  401. struct snd_card *card;
  402. struct snd_pcm *pcm;
  403. struct snd_hwdep *hwdep;
  404. struct pci_dev *pci;
  405. struct snd_kcontrol *spdif_ctl;
  406. unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
  407. unsigned int dds_value; /* last value written to freq register */
  408. };
  409. /* These tables map the ALSA channels 1..N to the channels that we
  410. need to use in order to find the relevant channel buffer. RME
  411. refer to this kind of mapping as between "the ADAT channel and
  412. the DMA channel." We index it using the logical audio channel,
  413. and the value is the DMA channel (i.e. channel buffer number)
  414. where the data for that channel can be read/written from/to.
  415. */
  416. static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
  417. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  418. 18, 19, 20, 21, 22, 23, 24, 25
  419. };
  420. static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
  421. /* Analog */
  422. 0, 1, 2, 3, 4, 5, 6, 7,
  423. /* ADAT 2 */
  424. 16, 17, 18, 19, 20, 21, 22, 23,
  425. /* SPDIF */
  426. 24, 25,
  427. -1, -1, -1, -1, -1, -1, -1, -1
  428. };
  429. static char channel_map_ds[HDSP_MAX_CHANNELS] = {
  430. /* ADAT channels are remapped */
  431. 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
  432. /* channels 12 and 13 are S/PDIF */
  433. 24, 25,
  434. /* others don't exist */
  435. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  436. };
  437. static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
  438. /* ADAT channels */
  439. 0, 1, 2, 3, 4, 5, 6, 7,
  440. /* SPDIF */
  441. 8, 9,
  442. /* Analog */
  443. 10, 11,
  444. /* AO4S-192 and AI4S-192 extension boards */
  445. 12, 13, 14, 15,
  446. /* others don't exist */
  447. -1, -1, -1, -1, -1, -1, -1, -1,
  448. -1, -1
  449. };
  450. static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
  451. /* ADAT */
  452. 1, 3, 5, 7,
  453. /* SPDIF */
  454. 8, 9,
  455. /* Analog */
  456. 10, 11,
  457. /* AO4S-192 and AI4S-192 extension boards */
  458. 12, 13, 14, 15,
  459. /* others don't exist */
  460. -1, -1, -1, -1, -1, -1, -1, -1,
  461. -1, -1, -1, -1, -1, -1
  462. };
  463. static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
  464. /* ADAT is disabled in this mode */
  465. /* SPDIF */
  466. 8, 9,
  467. /* Analog */
  468. 10, 11,
  469. /* AO4S-192 and AI4S-192 extension boards */
  470. 12, 13, 14, 15,
  471. /* others don't exist */
  472. -1, -1, -1, -1, -1, -1, -1, -1,
  473. -1, -1, -1, -1, -1, -1, -1, -1,
  474. -1, -1
  475. };
  476. static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
  477. {
  478. dmab->dev.type = SNDRV_DMA_TYPE_DEV;
  479. dmab->dev.dev = snd_dma_pci_data(pci);
  480. if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
  481. if (dmab->bytes >= size)
  482. return 0;
  483. }
  484. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  485. size, dmab) < 0)
  486. return -ENOMEM;
  487. return 0;
  488. }
  489. static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
  490. {
  491. if (dmab->area) {
  492. dmab->dev.dev = NULL; /* make it anonymous */
  493. snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
  494. }
  495. }
  496. static struct pci_device_id snd_hdsp_ids[] = {
  497. {
  498. .vendor = PCI_VENDOR_ID_XILINX,
  499. .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
  500. .subvendor = PCI_ANY_ID,
  501. .subdevice = PCI_ANY_ID,
  502. }, /* RME Hammerfall-DSP */
  503. { 0, },
  504. };
  505. MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
  506. /* prototypes */
  507. static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
  508. static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
  509. static int snd_hdsp_enable_io (struct hdsp *hdsp);
  510. static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
  511. static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
  512. static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
  513. static int hdsp_autosync_ref(struct hdsp *hdsp);
  514. static int snd_hdsp_set_defaults(struct hdsp *hdsp);
  515. static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
  516. static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
  517. {
  518. switch (hdsp->firmware_rev) {
  519. case 0xa:
  520. return (64 * out) + (32 + (in));
  521. case 0x96:
  522. case 0x97:
  523. case 0x98:
  524. return (32 * out) + (16 + (in));
  525. default:
  526. return (52 * out) + (26 + (in));
  527. }
  528. }
  529. static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
  530. {
  531. switch (hdsp->firmware_rev) {
  532. case 0xa:
  533. return (64 * out) + in;
  534. case 0x96:
  535. case 0x97:
  536. case 0x98:
  537. return (32 * out) + in;
  538. default:
  539. return (52 * out) + in;
  540. }
  541. }
  542. static void hdsp_write(struct hdsp *hdsp, int reg, int val)
  543. {
  544. writel(val, hdsp->iobase + reg);
  545. }
  546. static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
  547. {
  548. return readl (hdsp->iobase + reg);
  549. }
  550. static int hdsp_check_for_iobox (struct hdsp *hdsp)
  551. {
  552. if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
  553. if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
  554. snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
  555. hdsp->state &= ~HDSP_FirmwareLoaded;
  556. return -EIO;
  557. }
  558. return 0;
  559. }
  560. static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
  561. int i;
  562. unsigned long flags;
  563. if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
  564. snd_printk ("Hammerfall-DSP: loading firmware\n");
  565. hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
  566. hdsp_write (hdsp, HDSP_fifoData, 0);
  567. if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
  568. snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
  569. return -EIO;
  570. }
  571. hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
  572. for (i = 0; i < 24413; ++i) {
  573. hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
  574. if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
  575. snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
  576. return -EIO;
  577. }
  578. }
  579. ssleep(3);
  580. if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
  581. snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
  582. return -EIO;
  583. }
  584. #ifdef SNDRV_BIG_ENDIAN
  585. hdsp->control2_register = HDSP_BIGENDIAN_MODE;
  586. #else
  587. hdsp->control2_register = 0;
  588. #endif
  589. hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
  590. snd_printk ("Hammerfall-DSP: finished firmware loading\n");
  591. }
  592. if (hdsp->state & HDSP_InitializationComplete) {
  593. snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
  594. spin_lock_irqsave(&hdsp->lock, flags);
  595. snd_hdsp_set_defaults(hdsp);
  596. spin_unlock_irqrestore(&hdsp->lock, flags);
  597. }
  598. hdsp->state |= HDSP_FirmwareLoaded;
  599. return 0;
  600. }
  601. static int hdsp_get_iobox_version (struct hdsp *hdsp)
  602. {
  603. if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
  604. hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
  605. hdsp_write (hdsp, HDSP_fifoData, 0);
  606. if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
  607. return -EIO;
  608. hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
  609. hdsp_write (hdsp, HDSP_fifoData, 0);
  610. if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
  611. hdsp->io_type = Multiface;
  612. hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
  613. hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
  614. hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
  615. } else {
  616. hdsp->io_type = Digiface;
  617. }
  618. } else {
  619. /* firmware was already loaded, get iobox type */
  620. if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
  621. hdsp->io_type = Multiface;
  622. else
  623. hdsp->io_type = Digiface;
  624. }
  625. return 0;
  626. }
  627. #ifdef HDSP_FW_LOADER
  628. static int __devinit hdsp_request_fw_loader(struct hdsp *hdsp);
  629. #endif
  630. static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
  631. {
  632. if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
  633. return 0;
  634. if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
  635. hdsp->state &= ~HDSP_FirmwareLoaded;
  636. if (! load_on_demand)
  637. return -EIO;
  638. snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
  639. /* try to load firmware */
  640. if (! (hdsp->state & HDSP_FirmwareCached)) {
  641. #ifdef HDSP_FW_LOADER
  642. if (! hdsp_request_fw_loader(hdsp))
  643. return 0;
  644. #endif
  645. snd_printk(KERN_ERR
  646. "Hammerfall-DSP: No firmware loaded nor "
  647. "cached, please upload firmware.\n");
  648. return -EIO;
  649. }
  650. if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
  651. snd_printk(KERN_ERR
  652. "Hammerfall-DSP: Firmware loading from "
  653. "cache failed, please upload manually.\n");
  654. return -EIO;
  655. }
  656. }
  657. return 0;
  658. }
  659. static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
  660. {
  661. int i;
  662. /* the fifoStatus registers reports on how many words
  663. are available in the command FIFO.
  664. */
  665. for (i = 0; i < timeout; i++) {
  666. if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
  667. return 0;
  668. /* not very friendly, but we only do this during a firmware
  669. load and changing the mixer, so we just put up with it.
  670. */
  671. udelay (100);
  672. }
  673. snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
  674. count, timeout);
  675. return -1;
  676. }
  677. static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
  678. {
  679. if (addr >= HDSP_MATRIX_MIXER_SIZE)
  680. return 0;
  681. return hdsp->mixer_matrix[addr];
  682. }
  683. static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
  684. {
  685. unsigned int ad;
  686. if (addr >= HDSP_MATRIX_MIXER_SIZE)
  687. return -1;
  688. if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
  689. /* from martin bjornsen:
  690. "You can only write dwords to the
  691. mixer memory which contain two
  692. mixer values in the low and high
  693. word. So if you want to change
  694. value 0 you have to read value 1
  695. from the cache and write both to
  696. the first dword in the mixer
  697. memory."
  698. */
  699. if (hdsp->io_type == H9632 && addr >= 512)
  700. return 0;
  701. if (hdsp->io_type == H9652 && addr >= 1352)
  702. return 0;
  703. hdsp->mixer_matrix[addr] = data;
  704. /* `addr' addresses a 16-bit wide address, but
  705. the address space accessed via hdsp_write
  706. uses byte offsets. put another way, addr
  707. varies from 0 to 1351, but to access the
  708. corresponding memory location, we need
  709. to access 0 to 2703 ...
  710. */
  711. ad = addr/2;
  712. hdsp_write (hdsp, 4096 + (ad*4),
  713. (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
  714. hdsp->mixer_matrix[addr&0x7fe]);
  715. return 0;
  716. } else {
  717. ad = (addr << 16) + data;
  718. if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
  719. return -1;
  720. hdsp_write (hdsp, HDSP_fifoData, ad);
  721. hdsp->mixer_matrix[addr] = data;
  722. }
  723. return 0;
  724. }
  725. static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
  726. {
  727. unsigned long flags;
  728. int ret = 1;
  729. spin_lock_irqsave(&hdsp->lock, flags);
  730. if ((hdsp->playback_pid != hdsp->capture_pid) &&
  731. (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
  732. ret = 0;
  733. spin_unlock_irqrestore(&hdsp->lock, flags);
  734. return ret;
  735. }
  736. static int hdsp_external_sample_rate (struct hdsp *hdsp)
  737. {
  738. unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
  739. unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
  740. switch (rate_bits) {
  741. case HDSP_systemFrequency32: return 32000;
  742. case HDSP_systemFrequency44_1: return 44100;
  743. case HDSP_systemFrequency48: return 48000;
  744. case HDSP_systemFrequency64: return 64000;
  745. case HDSP_systemFrequency88_2: return 88200;
  746. case HDSP_systemFrequency96: return 96000;
  747. default:
  748. return 0;
  749. }
  750. }
  751. static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
  752. {
  753. unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
  754. unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
  755. if (status & HDSP_SPDIFErrorFlag)
  756. return 0;
  757. switch (rate_bits) {
  758. case HDSP_spdifFrequency32KHz: return 32000;
  759. case HDSP_spdifFrequency44_1KHz: return 44100;
  760. case HDSP_spdifFrequency48KHz: return 48000;
  761. case HDSP_spdifFrequency64KHz: return 64000;
  762. case HDSP_spdifFrequency88_2KHz: return 88200;
  763. case HDSP_spdifFrequency96KHz: return 96000;
  764. case HDSP_spdifFrequency128KHz:
  765. if (hdsp->io_type == H9632) return 128000;
  766. break;
  767. case HDSP_spdifFrequency176_4KHz:
  768. if (hdsp->io_type == H9632) return 176400;
  769. break;
  770. case HDSP_spdifFrequency192KHz:
  771. if (hdsp->io_type == H9632) return 192000;
  772. break;
  773. default:
  774. break;
  775. }
  776. snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
  777. return 0;
  778. }
  779. static void hdsp_compute_period_size(struct hdsp *hdsp)
  780. {
  781. hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
  782. }
  783. static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
  784. {
  785. int position;
  786. position = hdsp_read(hdsp, HDSP_statusRegister);
  787. if (!hdsp->precise_ptr)
  788. return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
  789. position &= HDSP_BufferPositionMask;
  790. position /= 4;
  791. position &= (hdsp->period_bytes/2) - 1;
  792. return position;
  793. }
  794. static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
  795. {
  796. hdsp_write (hdsp, HDSP_resetPointer, 0);
  797. if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
  798. /* HDSP_resetPointer = HDSP_freqReg, which is strange and
  799. * requires (?) to write again DDS value after a reset pointer
  800. * (at least, it works like this) */
  801. hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
  802. }
  803. static void hdsp_start_audio(struct hdsp *s)
  804. {
  805. s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
  806. hdsp_write(s, HDSP_controlRegister, s->control_register);
  807. }
  808. static void hdsp_stop_audio(struct hdsp *s)
  809. {
  810. s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
  811. hdsp_write(s, HDSP_controlRegister, s->control_register);
  812. }
  813. static void hdsp_silence_playback(struct hdsp *hdsp)
  814. {
  815. memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
  816. }
  817. static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
  818. {
  819. int n;
  820. spin_lock_irq(&s->lock);
  821. frames >>= 7;
  822. n = 0;
  823. while (frames) {
  824. n++;
  825. frames >>= 1;
  826. }
  827. s->control_register &= ~HDSP_LatencyMask;
  828. s->control_register |= hdsp_encode_latency(n);
  829. hdsp_write(s, HDSP_controlRegister, s->control_register);
  830. hdsp_compute_period_size(s);
  831. spin_unlock_irq(&s->lock);
  832. return 0;
  833. }
  834. static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
  835. {
  836. u64 n;
  837. u32 r;
  838. if (rate >= 112000)
  839. rate /= 4;
  840. else if (rate >= 56000)
  841. rate /= 2;
  842. /* RME says n = 104857600000000, but in the windows MADI driver, I see:
  843. // return 104857600000000 / rate; // 100 MHz
  844. return 110100480000000 / rate; // 105 MHz
  845. */
  846. n = 104857600000000ULL; /* = 2^20 * 10^8 */
  847. div64_32(&n, rate, &r);
  848. /* n should be less than 2^32 for being written to FREQ register */
  849. snd_assert((n >> 32) == 0);
  850. /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
  851. value to write it after a reset */
  852. hdsp->dds_value = n;
  853. hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
  854. }
  855. static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
  856. {
  857. int reject_if_open = 0;
  858. int current_rate;
  859. int rate_bits;
  860. /* ASSUMPTION: hdsp->lock is either held, or
  861. there is no need for it (e.g. during module
  862. initialization).
  863. */
  864. if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
  865. if (called_internally) {
  866. /* request from ctl or card initialization */
  867. snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
  868. return -1;
  869. } else {
  870. /* hw_param request while in AutoSync mode */
  871. int external_freq = hdsp_external_sample_rate(hdsp);
  872. int spdif_freq = hdsp_spdif_sample_rate(hdsp);
  873. if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
  874. snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
  875. else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
  876. snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
  877. else if (rate != external_freq) {
  878. snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
  879. return -1;
  880. }
  881. }
  882. }
  883. current_rate = hdsp->system_sample_rate;
  884. /* Changing from a "single speed" to a "double speed" rate is
  885. not allowed if any substreams are open. This is because
  886. such a change causes a shift in the location of
  887. the DMA buffers and a reduction in the number of available
  888. buffers.
  889. Note that a similar but essentially insoluble problem
  890. exists for externally-driven rate changes. All we can do
  891. is to flag rate changes in the read/write routines. */
  892. if (rate > 96000 && hdsp->io_type != H9632)
  893. return -EINVAL;
  894. switch (rate) {
  895. case 32000:
  896. if (current_rate > 48000)
  897. reject_if_open = 1;
  898. rate_bits = HDSP_Frequency32KHz;
  899. break;
  900. case 44100:
  901. if (current_rate > 48000)
  902. reject_if_open = 1;
  903. rate_bits = HDSP_Frequency44_1KHz;
  904. break;
  905. case 48000:
  906. if (current_rate > 48000)
  907. reject_if_open = 1;
  908. rate_bits = HDSP_Frequency48KHz;
  909. break;
  910. case 64000:
  911. if (current_rate <= 48000 || current_rate > 96000)
  912. reject_if_open = 1;
  913. rate_bits = HDSP_Frequency64KHz;
  914. break;
  915. case 88200:
  916. if (current_rate <= 48000 || current_rate > 96000)
  917. reject_if_open = 1;
  918. rate_bits = HDSP_Frequency88_2KHz;
  919. break;
  920. case 96000:
  921. if (current_rate <= 48000 || current_rate > 96000)
  922. reject_if_open = 1;
  923. rate_bits = HDSP_Frequency96KHz;
  924. break;
  925. case 128000:
  926. if (current_rate < 128000)
  927. reject_if_open = 1;
  928. rate_bits = HDSP_Frequency128KHz;
  929. break;
  930. case 176400:
  931. if (current_rate < 128000)
  932. reject_if_open = 1;
  933. rate_bits = HDSP_Frequency176_4KHz;
  934. break;
  935. case 192000:
  936. if (current_rate < 128000)
  937. reject_if_open = 1;
  938. rate_bits = HDSP_Frequency192KHz;
  939. break;
  940. default:
  941. return -EINVAL;
  942. }
  943. if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
  944. snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
  945. hdsp->capture_pid,
  946. hdsp->playback_pid);
  947. return -EBUSY;
  948. }
  949. hdsp->control_register &= ~HDSP_FrequencyMask;
  950. hdsp->control_register |= rate_bits;
  951. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  952. /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
  953. if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
  954. hdsp_set_dds_value(hdsp, rate);
  955. if (rate >= 128000) {
  956. hdsp->channel_map = channel_map_H9632_qs;
  957. } else if (rate > 48000) {
  958. if (hdsp->io_type == H9632)
  959. hdsp->channel_map = channel_map_H9632_ds;
  960. else
  961. hdsp->channel_map = channel_map_ds;
  962. } else {
  963. switch (hdsp->io_type) {
  964. case Multiface:
  965. hdsp->channel_map = channel_map_mf_ss;
  966. break;
  967. case Digiface:
  968. case H9652:
  969. hdsp->channel_map = channel_map_df_ss;
  970. break;
  971. case H9632:
  972. hdsp->channel_map = channel_map_H9632_ss;
  973. break;
  974. default:
  975. /* should never happen */
  976. break;
  977. }
  978. }
  979. hdsp->system_sample_rate = rate;
  980. return 0;
  981. }
  982. /*----------------------------------------------------------------------------
  983. MIDI
  984. ----------------------------------------------------------------------------*/
  985. static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
  986. {
  987. /* the hardware already does the relevant bit-mask with 0xff */
  988. if (id)
  989. return hdsp_read(hdsp, HDSP_midiDataIn1);
  990. else
  991. return hdsp_read(hdsp, HDSP_midiDataIn0);
  992. }
  993. static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
  994. {
  995. /* the hardware already does the relevant bit-mask with 0xff */
  996. if (id)
  997. hdsp_write(hdsp, HDSP_midiDataOut1, val);
  998. else
  999. hdsp_write(hdsp, HDSP_midiDataOut0, val);
  1000. }
  1001. static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
  1002. {
  1003. if (id)
  1004. return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
  1005. else
  1006. return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
  1007. }
  1008. static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
  1009. {
  1010. int fifo_bytes_used;
  1011. if (id)
  1012. fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
  1013. else
  1014. fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
  1015. if (fifo_bytes_used < 128)
  1016. return 128 - fifo_bytes_used;
  1017. else
  1018. return 0;
  1019. }
  1020. static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
  1021. {
  1022. while (snd_hdsp_midi_input_available (hdsp, id))
  1023. snd_hdsp_midi_read_byte (hdsp, id);
  1024. }
  1025. static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)
  1026. {
  1027. unsigned long flags;
  1028. int n_pending;
  1029. int to_write;
  1030. int i;
  1031. unsigned char buf[128];
  1032. /* Output is not interrupt driven */
  1033. spin_lock_irqsave (&hmidi->lock, flags);
  1034. if (hmidi->output) {
  1035. if (!snd_rawmidi_transmit_empty (hmidi->output)) {
  1036. if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
  1037. if (n_pending > (int)sizeof (buf))
  1038. n_pending = sizeof (buf);
  1039. if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
  1040. for (i = 0; i < to_write; ++i)
  1041. snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. spin_unlock_irqrestore (&hmidi->lock, flags);
  1047. return 0;
  1048. }
  1049. static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
  1050. {
  1051. unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
  1052. unsigned long flags;
  1053. int n_pending;
  1054. int i;
  1055. spin_lock_irqsave (&hmidi->lock, flags);
  1056. if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
  1057. if (hmidi->input) {
  1058. if (n_pending > (int)sizeof (buf))
  1059. n_pending = sizeof (buf);
  1060. for (i = 0; i < n_pending; ++i)
  1061. buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
  1062. if (n_pending)
  1063. snd_rawmidi_receive (hmidi->input, buf, n_pending);
  1064. } else {
  1065. /* flush the MIDI input FIFO */
  1066. while (--n_pending)
  1067. snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
  1068. }
  1069. }
  1070. hmidi->pending = 0;
  1071. if (hmidi->id)
  1072. hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
  1073. else
  1074. hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
  1075. hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
  1076. spin_unlock_irqrestore (&hmidi->lock, flags);
  1077. return snd_hdsp_midi_output_write (hmidi);
  1078. }
  1079. static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  1080. {
  1081. struct hdsp *hdsp;
  1082. struct hdsp_midi *hmidi;
  1083. unsigned long flags;
  1084. u32 ie;
  1085. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1086. hdsp = hmidi->hdsp;
  1087. ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
  1088. spin_lock_irqsave (&hdsp->lock, flags);
  1089. if (up) {
  1090. if (!(hdsp->control_register & ie)) {
  1091. snd_hdsp_flush_midi_input (hdsp, hmidi->id);
  1092. hdsp->control_register |= ie;
  1093. }
  1094. } else {
  1095. hdsp->control_register &= ~ie;
  1096. tasklet_kill(&hdsp->midi_tasklet);
  1097. }
  1098. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1099. spin_unlock_irqrestore (&hdsp->lock, flags);
  1100. }
  1101. static void snd_hdsp_midi_output_timer(unsigned long data)
  1102. {
  1103. struct hdsp_midi *hmidi = (struct hdsp_midi *) data;
  1104. unsigned long flags;
  1105. snd_hdsp_midi_output_write(hmidi);
  1106. spin_lock_irqsave (&hmidi->lock, flags);
  1107. /* this does not bump hmidi->istimer, because the
  1108. kernel automatically removed the timer when it
  1109. expired, and we are now adding it back, thus
  1110. leaving istimer wherever it was set before.
  1111. */
  1112. if (hmidi->istimer) {
  1113. hmidi->timer.expires = 1 + jiffies;
  1114. add_timer(&hmidi->timer);
  1115. }
  1116. spin_unlock_irqrestore (&hmidi->lock, flags);
  1117. }
  1118. static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
  1119. {
  1120. struct hdsp_midi *hmidi;
  1121. unsigned long flags;
  1122. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1123. spin_lock_irqsave (&hmidi->lock, flags);
  1124. if (up) {
  1125. if (!hmidi->istimer) {
  1126. init_timer(&hmidi->timer);
  1127. hmidi->timer.function = snd_hdsp_midi_output_timer;
  1128. hmidi->timer.data = (unsigned long) hmidi;
  1129. hmidi->timer.expires = 1 + jiffies;
  1130. add_timer(&hmidi->timer);
  1131. hmidi->istimer++;
  1132. }
  1133. } else {
  1134. if (hmidi->istimer && --hmidi->istimer <= 0)
  1135. del_timer (&hmidi->timer);
  1136. }
  1137. spin_unlock_irqrestore (&hmidi->lock, flags);
  1138. if (up)
  1139. snd_hdsp_midi_output_write(hmidi);
  1140. }
  1141. static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)
  1142. {
  1143. struct hdsp_midi *hmidi;
  1144. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1145. spin_lock_irq (&hmidi->lock);
  1146. snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
  1147. hmidi->input = substream;
  1148. spin_unlock_irq (&hmidi->lock);
  1149. return 0;
  1150. }
  1151. static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)
  1152. {
  1153. struct hdsp_midi *hmidi;
  1154. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1155. spin_lock_irq (&hmidi->lock);
  1156. hmidi->output = substream;
  1157. spin_unlock_irq (&hmidi->lock);
  1158. return 0;
  1159. }
  1160. static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)
  1161. {
  1162. struct hdsp_midi *hmidi;
  1163. snd_hdsp_midi_input_trigger (substream, 0);
  1164. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1165. spin_lock_irq (&hmidi->lock);
  1166. hmidi->input = NULL;
  1167. spin_unlock_irq (&hmidi->lock);
  1168. return 0;
  1169. }
  1170. static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)
  1171. {
  1172. struct hdsp_midi *hmidi;
  1173. snd_hdsp_midi_output_trigger (substream, 0);
  1174. hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
  1175. spin_lock_irq (&hmidi->lock);
  1176. hmidi->output = NULL;
  1177. spin_unlock_irq (&hmidi->lock);
  1178. return 0;
  1179. }
  1180. static struct snd_rawmidi_ops snd_hdsp_midi_output =
  1181. {
  1182. .open = snd_hdsp_midi_output_open,
  1183. .close = snd_hdsp_midi_output_close,
  1184. .trigger = snd_hdsp_midi_output_trigger,
  1185. };
  1186. static struct snd_rawmidi_ops snd_hdsp_midi_input =
  1187. {
  1188. .open = snd_hdsp_midi_input_open,
  1189. .close = snd_hdsp_midi_input_close,
  1190. .trigger = snd_hdsp_midi_input_trigger,
  1191. };
  1192. static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
  1193. {
  1194. char buf[32];
  1195. hdsp->midi[id].id = id;
  1196. hdsp->midi[id].rmidi = NULL;
  1197. hdsp->midi[id].input = NULL;
  1198. hdsp->midi[id].output = NULL;
  1199. hdsp->midi[id].hdsp = hdsp;
  1200. hdsp->midi[id].istimer = 0;
  1201. hdsp->midi[id].pending = 0;
  1202. spin_lock_init (&hdsp->midi[id].lock);
  1203. sprintf (buf, "%s MIDI %d", card->shortname, id+1);
  1204. if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
  1205. return -1;
  1206. sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
  1207. hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
  1208. snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
  1209. snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
  1210. hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
  1211. SNDRV_RAWMIDI_INFO_INPUT |
  1212. SNDRV_RAWMIDI_INFO_DUPLEX;
  1213. return 0;
  1214. }
  1215. /*-----------------------------------------------------------------------------
  1216. Control Interface
  1217. ----------------------------------------------------------------------------*/
  1218. static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes)
  1219. {
  1220. u32 val = 0;
  1221. val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
  1222. val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
  1223. if (val & HDSP_SPDIFProfessional)
  1224. val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
  1225. else
  1226. val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
  1227. return val;
  1228. }
  1229. static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
  1230. {
  1231. aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
  1232. ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
  1233. if (val & HDSP_SPDIFProfessional)
  1234. aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
  1235. else
  1236. aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
  1237. }
  1238. static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1239. {
  1240. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1241. uinfo->count = 1;
  1242. return 0;
  1243. }
  1244. static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1245. {
  1246. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1247. snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
  1248. return 0;
  1249. }
  1250. static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1251. {
  1252. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1253. int change;
  1254. u32 val;
  1255. val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
  1256. spin_lock_irq(&hdsp->lock);
  1257. change = val != hdsp->creg_spdif;
  1258. hdsp->creg_spdif = val;
  1259. spin_unlock_irq(&hdsp->lock);
  1260. return change;
  1261. }
  1262. static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1263. {
  1264. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1265. uinfo->count = 1;
  1266. return 0;
  1267. }
  1268. static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1269. {
  1270. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1271. snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
  1272. return 0;
  1273. }
  1274. static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1275. {
  1276. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1277. int change;
  1278. u32 val;
  1279. val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
  1280. spin_lock_irq(&hdsp->lock);
  1281. change = val != hdsp->creg_spdif_stream;
  1282. hdsp->creg_spdif_stream = val;
  1283. hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
  1284. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
  1285. spin_unlock_irq(&hdsp->lock);
  1286. return change;
  1287. }
  1288. static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1289. {
  1290. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1291. uinfo->count = 1;
  1292. return 0;
  1293. }
  1294. static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1295. {
  1296. ucontrol->value.iec958.status[0] = kcontrol->private_value;
  1297. return 0;
  1298. }
  1299. #define HDSP_SPDIF_IN(xname, xindex) \
  1300. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1301. .name = xname, \
  1302. .index = xindex, \
  1303. .info = snd_hdsp_info_spdif_in, \
  1304. .get = snd_hdsp_get_spdif_in, \
  1305. .put = snd_hdsp_put_spdif_in }
  1306. static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
  1307. {
  1308. return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
  1309. }
  1310. static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
  1311. {
  1312. hdsp->control_register &= ~HDSP_SPDIFInputMask;
  1313. hdsp->control_register |= hdsp_encode_spdif_in(in);
  1314. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1315. return 0;
  1316. }
  1317. static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1318. {
  1319. static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
  1320. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1321. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1322. uinfo->count = 1;
  1323. uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
  1324. if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
  1325. uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
  1326. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1327. return 0;
  1328. }
  1329. static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1330. {
  1331. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1332. ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
  1333. return 0;
  1334. }
  1335. static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1336. {
  1337. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1338. int change;
  1339. unsigned int val;
  1340. if (!snd_hdsp_use_is_exclusive(hdsp))
  1341. return -EBUSY;
  1342. val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
  1343. spin_lock_irq(&hdsp->lock);
  1344. change = val != hdsp_spdif_in(hdsp);
  1345. if (change)
  1346. hdsp_set_spdif_input(hdsp, val);
  1347. spin_unlock_irq(&hdsp->lock);
  1348. return change;
  1349. }
  1350. #define HDSP_SPDIF_OUT(xname, xindex) \
  1351. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  1352. .info = snd_hdsp_info_spdif_bits, \
  1353. .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
  1354. static int hdsp_spdif_out(struct hdsp *hdsp)
  1355. {
  1356. return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
  1357. }
  1358. static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
  1359. {
  1360. if (out)
  1361. hdsp->control_register |= HDSP_SPDIFOpticalOut;
  1362. else
  1363. hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
  1364. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1365. return 0;
  1366. }
  1367. static int snd_hdsp_info_spdif_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1368. {
  1369. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1370. uinfo->count = 1;
  1371. uinfo->value.integer.min = 0;
  1372. uinfo->value.integer.max = 1;
  1373. return 0;
  1374. }
  1375. static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1376. {
  1377. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1378. ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
  1379. return 0;
  1380. }
  1381. static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1382. {
  1383. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1384. int change;
  1385. unsigned int val;
  1386. if (!snd_hdsp_use_is_exclusive(hdsp))
  1387. return -EBUSY;
  1388. val = ucontrol->value.integer.value[0] & 1;
  1389. spin_lock_irq(&hdsp->lock);
  1390. change = (int)val != hdsp_spdif_out(hdsp);
  1391. hdsp_set_spdif_output(hdsp, val);
  1392. spin_unlock_irq(&hdsp->lock);
  1393. return change;
  1394. }
  1395. #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
  1396. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  1397. .info = snd_hdsp_info_spdif_bits, \
  1398. .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
  1399. static int hdsp_spdif_professional(struct hdsp *hdsp)
  1400. {
  1401. return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
  1402. }
  1403. static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
  1404. {
  1405. if (val)
  1406. hdsp->control_register |= HDSP_SPDIFProfessional;
  1407. else
  1408. hdsp->control_register &= ~HDSP_SPDIFProfessional;
  1409. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1410. return 0;
  1411. }
  1412. static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1413. {
  1414. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1415. ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
  1416. return 0;
  1417. }
  1418. static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1419. {
  1420. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1421. int change;
  1422. unsigned int val;
  1423. if (!snd_hdsp_use_is_exclusive(hdsp))
  1424. return -EBUSY;
  1425. val = ucontrol->value.integer.value[0] & 1;
  1426. spin_lock_irq(&hdsp->lock);
  1427. change = (int)val != hdsp_spdif_professional(hdsp);
  1428. hdsp_set_spdif_professional(hdsp, val);
  1429. spin_unlock_irq(&hdsp->lock);
  1430. return change;
  1431. }
  1432. #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
  1433. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  1434. .info = snd_hdsp_info_spdif_bits, \
  1435. .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
  1436. static int hdsp_spdif_emphasis(struct hdsp *hdsp)
  1437. {
  1438. return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
  1439. }
  1440. static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
  1441. {
  1442. if (val)
  1443. hdsp->control_register |= HDSP_SPDIFEmphasis;
  1444. else
  1445. hdsp->control_register &= ~HDSP_SPDIFEmphasis;
  1446. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1447. return 0;
  1448. }
  1449. static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1450. {
  1451. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1452. ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
  1453. return 0;
  1454. }
  1455. static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1456. {
  1457. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1458. int change;
  1459. unsigned int val;
  1460. if (!snd_hdsp_use_is_exclusive(hdsp))
  1461. return -EBUSY;
  1462. val = ucontrol->value.integer.value[0] & 1;
  1463. spin_lock_irq(&hdsp->lock);
  1464. change = (int)val != hdsp_spdif_emphasis(hdsp);
  1465. hdsp_set_spdif_emphasis(hdsp, val);
  1466. spin_unlock_irq(&hdsp->lock);
  1467. return change;
  1468. }
  1469. #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
  1470. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  1471. .info = snd_hdsp_info_spdif_bits, \
  1472. .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
  1473. static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
  1474. {
  1475. return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
  1476. }
  1477. static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
  1478. {
  1479. if (val)
  1480. hdsp->control_register |= HDSP_SPDIFNonAudio;
  1481. else
  1482. hdsp->control_register &= ~HDSP_SPDIFNonAudio;
  1483. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1484. return 0;
  1485. }
  1486. static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1487. {
  1488. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1489. ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
  1490. return 0;
  1491. }
  1492. static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1493. {
  1494. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1495. int change;
  1496. unsigned int val;
  1497. if (!snd_hdsp_use_is_exclusive(hdsp))
  1498. return -EBUSY;
  1499. val = ucontrol->value.integer.value[0] & 1;
  1500. spin_lock_irq(&hdsp->lock);
  1501. change = (int)val != hdsp_spdif_nonaudio(hdsp);
  1502. hdsp_set_spdif_nonaudio(hdsp, val);
  1503. spin_unlock_irq(&hdsp->lock);
  1504. return change;
  1505. }
  1506. #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
  1507. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1508. .name = xname, \
  1509. .index = xindex, \
  1510. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  1511. .info = snd_hdsp_info_spdif_sample_rate, \
  1512. .get = snd_hdsp_get_spdif_sample_rate \
  1513. }
  1514. static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1515. {
  1516. static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
  1517. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1518. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1519. uinfo->count = 1;
  1520. uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
  1521. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1522. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1523. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1524. return 0;
  1525. }
  1526. static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1527. {
  1528. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1529. switch (hdsp_spdif_sample_rate(hdsp)) {
  1530. case 32000:
  1531. ucontrol->value.enumerated.item[0] = 0;
  1532. break;
  1533. case 44100:
  1534. ucontrol->value.enumerated.item[0] = 1;
  1535. break;
  1536. case 48000:
  1537. ucontrol->value.enumerated.item[0] = 2;
  1538. break;
  1539. case 64000:
  1540. ucontrol->value.enumerated.item[0] = 3;
  1541. break;
  1542. case 88200:
  1543. ucontrol->value.enumerated.item[0] = 4;
  1544. break;
  1545. case 96000:
  1546. ucontrol->value.enumerated.item[0] = 5;
  1547. break;
  1548. case 128000:
  1549. ucontrol->value.enumerated.item[0] = 7;
  1550. break;
  1551. case 176400:
  1552. ucontrol->value.enumerated.item[0] = 8;
  1553. break;
  1554. case 192000:
  1555. ucontrol->value.enumerated.item[0] = 9;
  1556. break;
  1557. default:
  1558. ucontrol->value.enumerated.item[0] = 6;
  1559. }
  1560. return 0;
  1561. }
  1562. #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
  1563. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1564. .name = xname, \
  1565. .index = xindex, \
  1566. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  1567. .info = snd_hdsp_info_system_sample_rate, \
  1568. .get = snd_hdsp_get_system_sample_rate \
  1569. }
  1570. static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1571. {
  1572. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1573. uinfo->count = 1;
  1574. return 0;
  1575. }
  1576. static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1577. {
  1578. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1579. ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
  1580. return 0;
  1581. }
  1582. #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
  1583. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1584. .name = xname, \
  1585. .index = xindex, \
  1586. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  1587. .info = snd_hdsp_info_autosync_sample_rate, \
  1588. .get = snd_hdsp_get_autosync_sample_rate \
  1589. }
  1590. static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1591. {
  1592. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1593. static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
  1594. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1595. uinfo->count = 1;
  1596. uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
  1597. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1598. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1599. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1600. return 0;
  1601. }
  1602. static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1603. {
  1604. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1605. switch (hdsp_external_sample_rate(hdsp)) {
  1606. case 32000:
  1607. ucontrol->value.enumerated.item[0] = 0;
  1608. break;
  1609. case 44100:
  1610. ucontrol->value.enumerated.item[0] = 1;
  1611. break;
  1612. case 48000:
  1613. ucontrol->value.enumerated.item[0] = 2;
  1614. break;
  1615. case 64000:
  1616. ucontrol->value.enumerated.item[0] = 3;
  1617. break;
  1618. case 88200:
  1619. ucontrol->value.enumerated.item[0] = 4;
  1620. break;
  1621. case 96000:
  1622. ucontrol->value.enumerated.item[0] = 5;
  1623. break;
  1624. case 128000:
  1625. ucontrol->value.enumerated.item[0] = 7;
  1626. break;
  1627. case 176400:
  1628. ucontrol->value.enumerated.item[0] = 8;
  1629. break;
  1630. case 192000:
  1631. ucontrol->value.enumerated.item[0] = 9;
  1632. break;
  1633. default:
  1634. ucontrol->value.enumerated.item[0] = 6;
  1635. }
  1636. return 0;
  1637. }
  1638. #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
  1639. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1640. .name = xname, \
  1641. .index = xindex, \
  1642. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  1643. .info = snd_hdsp_info_system_clock_mode, \
  1644. .get = snd_hdsp_get_system_clock_mode \
  1645. }
  1646. static int hdsp_system_clock_mode(struct hdsp *hdsp)
  1647. {
  1648. if (hdsp->control_register & HDSP_ClockModeMaster)
  1649. return 0;
  1650. else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
  1651. return 0;
  1652. return 1;
  1653. }
  1654. static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1655. {
  1656. static char *texts[] = {"Master", "Slave" };
  1657. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1658. uinfo->count = 1;
  1659. uinfo->value.enumerated.items = 2;
  1660. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1661. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1662. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1663. return 0;
  1664. }
  1665. static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1666. {
  1667. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1668. ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
  1669. return 0;
  1670. }
  1671. #define HDSP_CLOCK_SOURCE(xname, xindex) \
  1672. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1673. .name = xname, \
  1674. .index = xindex, \
  1675. .info = snd_hdsp_info_clock_source, \
  1676. .get = snd_hdsp_get_clock_source, \
  1677. .put = snd_hdsp_put_clock_source \
  1678. }
  1679. static int hdsp_clock_source(struct hdsp *hdsp)
  1680. {
  1681. if (hdsp->control_register & HDSP_ClockModeMaster) {
  1682. switch (hdsp->system_sample_rate) {
  1683. case 32000:
  1684. return 1;
  1685. case 44100:
  1686. return 2;
  1687. case 48000:
  1688. return 3;
  1689. case 64000:
  1690. return 4;
  1691. case 88200:
  1692. return 5;
  1693. case 96000:
  1694. return 6;
  1695. case 128000:
  1696. return 7;
  1697. case 176400:
  1698. return 8;
  1699. case 192000:
  1700. return 9;
  1701. default:
  1702. return 3;
  1703. }
  1704. } else {
  1705. return 0;
  1706. }
  1707. }
  1708. static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
  1709. {
  1710. int rate;
  1711. switch (mode) {
  1712. case HDSP_CLOCK_SOURCE_AUTOSYNC:
  1713. if (hdsp_external_sample_rate(hdsp) != 0) {
  1714. if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
  1715. hdsp->control_register &= ~HDSP_ClockModeMaster;
  1716. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1717. return 0;
  1718. }
  1719. }
  1720. return -1;
  1721. case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
  1722. rate = 32000;
  1723. break;
  1724. case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
  1725. rate = 44100;
  1726. break;
  1727. case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
  1728. rate = 48000;
  1729. break;
  1730. case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
  1731. rate = 64000;
  1732. break;
  1733. case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
  1734. rate = 88200;
  1735. break;
  1736. case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
  1737. rate = 96000;
  1738. break;
  1739. case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
  1740. rate = 128000;
  1741. break;
  1742. case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
  1743. rate = 176400;
  1744. break;
  1745. case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
  1746. rate = 192000;
  1747. break;
  1748. default:
  1749. rate = 48000;
  1750. }
  1751. hdsp->control_register |= HDSP_ClockModeMaster;
  1752. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1753. hdsp_set_rate(hdsp, rate, 1);
  1754. return 0;
  1755. }
  1756. static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1757. {
  1758. static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
  1759. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1760. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1761. uinfo->count = 1;
  1762. if (hdsp->io_type == H9632)
  1763. uinfo->value.enumerated.items = 10;
  1764. else
  1765. uinfo->value.enumerated.items = 7;
  1766. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1767. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1768. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1769. return 0;
  1770. }
  1771. static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1772. {
  1773. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1774. ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
  1775. return 0;
  1776. }
  1777. static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1778. {
  1779. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1780. int change;
  1781. int val;
  1782. if (!snd_hdsp_use_is_exclusive(hdsp))
  1783. return -EBUSY;
  1784. val = ucontrol->value.enumerated.item[0];
  1785. if (val < 0) val = 0;
  1786. if (hdsp->io_type == H9632) {
  1787. if (val > 9)
  1788. val = 9;
  1789. } else {
  1790. if (val > 6)
  1791. val = 6;
  1792. }
  1793. spin_lock_irq(&hdsp->lock);
  1794. if (val != hdsp_clock_source(hdsp))
  1795. change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
  1796. else
  1797. change = 0;
  1798. spin_unlock_irq(&hdsp->lock);
  1799. return change;
  1800. }
  1801. static int snd_hdsp_info_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1802. {
  1803. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1804. uinfo->count = 1;
  1805. uinfo->value.integer.min = 0;
  1806. uinfo->value.integer.max = 1;
  1807. return 0;
  1808. }
  1809. static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1810. {
  1811. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1812. ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
  1813. return 0;
  1814. }
  1815. static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1816. {
  1817. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1818. int change;
  1819. change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
  1820. if (change)
  1821. hdsp->clock_source_locked = ucontrol->value.integer.value[0];
  1822. return change;
  1823. }
  1824. #define HDSP_DA_GAIN(xname, xindex) \
  1825. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1826. .name = xname, \
  1827. .index = xindex, \
  1828. .info = snd_hdsp_info_da_gain, \
  1829. .get = snd_hdsp_get_da_gain, \
  1830. .put = snd_hdsp_put_da_gain \
  1831. }
  1832. static int hdsp_da_gain(struct hdsp *hdsp)
  1833. {
  1834. switch (hdsp->control_register & HDSP_DAGainMask) {
  1835. case HDSP_DAGainHighGain:
  1836. return 0;
  1837. case HDSP_DAGainPlus4dBu:
  1838. return 1;
  1839. case HDSP_DAGainMinus10dBV:
  1840. return 2;
  1841. default:
  1842. return 1;
  1843. }
  1844. }
  1845. static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
  1846. {
  1847. hdsp->control_register &= ~HDSP_DAGainMask;
  1848. switch (mode) {
  1849. case 0:
  1850. hdsp->control_register |= HDSP_DAGainHighGain;
  1851. break;
  1852. case 1:
  1853. hdsp->control_register |= HDSP_DAGainPlus4dBu;
  1854. break;
  1855. case 2:
  1856. hdsp->control_register |= HDSP_DAGainMinus10dBV;
  1857. break;
  1858. default:
  1859. return -1;
  1860. }
  1861. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1862. return 0;
  1863. }
  1864. static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1865. {
  1866. static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
  1867. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1868. uinfo->count = 1;
  1869. uinfo->value.enumerated.items = 3;
  1870. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1871. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1872. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1873. return 0;
  1874. }
  1875. static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1876. {
  1877. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1878. ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
  1879. return 0;
  1880. }
  1881. static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1882. {
  1883. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1884. int change;
  1885. int val;
  1886. if (!snd_hdsp_use_is_exclusive(hdsp))
  1887. return -EBUSY;
  1888. val = ucontrol->value.enumerated.item[0];
  1889. if (val < 0) val = 0;
  1890. if (val > 2) val = 2;
  1891. spin_lock_irq(&hdsp->lock);
  1892. if (val != hdsp_da_gain(hdsp))
  1893. change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
  1894. else
  1895. change = 0;
  1896. spin_unlock_irq(&hdsp->lock);
  1897. return change;
  1898. }
  1899. #define HDSP_AD_GAIN(xname, xindex) \
  1900. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1901. .name = xname, \
  1902. .index = xindex, \
  1903. .info = snd_hdsp_info_ad_gain, \
  1904. .get = snd_hdsp_get_ad_gain, \
  1905. .put = snd_hdsp_put_ad_gain \
  1906. }
  1907. static int hdsp_ad_gain(struct hdsp *hdsp)
  1908. {
  1909. switch (hdsp->control_register & HDSP_ADGainMask) {
  1910. case HDSP_ADGainMinus10dBV:
  1911. return 0;
  1912. case HDSP_ADGainPlus4dBu:
  1913. return 1;
  1914. case HDSP_ADGainLowGain:
  1915. return 2;
  1916. default:
  1917. return 1;
  1918. }
  1919. }
  1920. static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
  1921. {
  1922. hdsp->control_register &= ~HDSP_ADGainMask;
  1923. switch (mode) {
  1924. case 0:
  1925. hdsp->control_register |= HDSP_ADGainMinus10dBV;
  1926. break;
  1927. case 1:
  1928. hdsp->control_register |= HDSP_ADGainPlus4dBu;
  1929. break;
  1930. case 2:
  1931. hdsp->control_register |= HDSP_ADGainLowGain;
  1932. break;
  1933. default:
  1934. return -1;
  1935. }
  1936. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  1937. return 0;
  1938. }
  1939. static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1940. {
  1941. static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
  1942. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1943. uinfo->count = 1;
  1944. uinfo->value.enumerated.items = 3;
  1945. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1946. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1947. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1948. return 0;
  1949. }
  1950. static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1951. {
  1952. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1953. ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
  1954. return 0;
  1955. }
  1956. static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1957. {
  1958. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  1959. int change;
  1960. int val;
  1961. if (!snd_hdsp_use_is_exclusive(hdsp))
  1962. return -EBUSY;
  1963. val = ucontrol->value.enumerated.item[0];
  1964. if (val < 0) val = 0;
  1965. if (val > 2) val = 2;
  1966. spin_lock_irq(&hdsp->lock);
  1967. if (val != hdsp_ad_gain(hdsp))
  1968. change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
  1969. else
  1970. change = 0;
  1971. spin_unlock_irq(&hdsp->lock);
  1972. return change;
  1973. }
  1974. #define HDSP_PHONE_GAIN(xname, xindex) \
  1975. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1976. .name = xname, \
  1977. .index = xindex, \
  1978. .info = snd_hdsp_info_phone_gain, \
  1979. .get = snd_hdsp_get_phone_gain, \
  1980. .put = snd_hdsp_put_phone_gain \
  1981. }
  1982. static int hdsp_phone_gain(struct hdsp *hdsp)
  1983. {
  1984. switch (hdsp->control_register & HDSP_PhoneGainMask) {
  1985. case HDSP_PhoneGain0dB:
  1986. return 0;
  1987. case HDSP_PhoneGainMinus6dB:
  1988. return 1;
  1989. case HDSP_PhoneGainMinus12dB:
  1990. return 2;
  1991. default:
  1992. return 0;
  1993. }
  1994. }
  1995. static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
  1996. {
  1997. hdsp->control_register &= ~HDSP_PhoneGainMask;
  1998. switch (mode) {
  1999. case 0:
  2000. hdsp->control_register |= HDSP_PhoneGain0dB;
  2001. break;
  2002. case 1:
  2003. hdsp->control_register |= HDSP_PhoneGainMinus6dB;
  2004. break;
  2005. case 2:
  2006. hdsp->control_register |= HDSP_PhoneGainMinus12dB;
  2007. break;
  2008. default:
  2009. return -1;
  2010. }
  2011. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  2012. return 0;
  2013. }
  2014. static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2015. {
  2016. static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
  2017. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2018. uinfo->count = 1;
  2019. uinfo->value.enumerated.items = 3;
  2020. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2021. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2022. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2023. return 0;
  2024. }
  2025. static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2026. {
  2027. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2028. ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
  2029. return 0;
  2030. }
  2031. static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2032. {
  2033. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2034. int change;
  2035. int val;
  2036. if (!snd_hdsp_use_is_exclusive(hdsp))
  2037. return -EBUSY;
  2038. val = ucontrol->value.enumerated.item[0];
  2039. if (val < 0) val = 0;
  2040. if (val > 2) val = 2;
  2041. spin_lock_irq(&hdsp->lock);
  2042. if (val != hdsp_phone_gain(hdsp))
  2043. change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
  2044. else
  2045. change = 0;
  2046. spin_unlock_irq(&hdsp->lock);
  2047. return change;
  2048. }
  2049. #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
  2050. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2051. .name = xname, \
  2052. .index = xindex, \
  2053. .info = snd_hdsp_info_xlr_breakout_cable, \
  2054. .get = snd_hdsp_get_xlr_breakout_cable, \
  2055. .put = snd_hdsp_put_xlr_breakout_cable \
  2056. }
  2057. static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
  2058. {
  2059. if (hdsp->control_register & HDSP_XLRBreakoutCable)
  2060. return 1;
  2061. return 0;
  2062. }
  2063. static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
  2064. {
  2065. if (mode)
  2066. hdsp->control_register |= HDSP_XLRBreakoutCable;
  2067. else
  2068. hdsp->control_register &= ~HDSP_XLRBreakoutCable;
  2069. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  2070. return 0;
  2071. }
  2072. static int snd_hdsp_info_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2073. {
  2074. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2075. uinfo->count = 1;
  2076. uinfo->value.integer.min = 0;
  2077. uinfo->value.integer.max = 1;
  2078. return 0;
  2079. }
  2080. static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2081. {
  2082. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2083. ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
  2084. return 0;
  2085. }
  2086. static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2087. {
  2088. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2089. int change;
  2090. int val;
  2091. if (!snd_hdsp_use_is_exclusive(hdsp))
  2092. return -EBUSY;
  2093. val = ucontrol->value.integer.value[0] & 1;
  2094. spin_lock_irq(&hdsp->lock);
  2095. change = (int)val != hdsp_xlr_breakout_cable(hdsp);
  2096. hdsp_set_xlr_breakout_cable(hdsp, val);
  2097. spin_unlock_irq(&hdsp->lock);
  2098. return change;
  2099. }
  2100. /* (De)activates old RME Analog Extension Board
  2101. These are connected to the internal ADAT connector
  2102. Switching this on desactivates external ADAT
  2103. */
  2104. #define HDSP_AEB(xname, xindex) \
  2105. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2106. .name = xname, \
  2107. .index = xindex, \
  2108. .info = snd_hdsp_info_aeb, \
  2109. .get = snd_hdsp_get_aeb, \
  2110. .put = snd_hdsp_put_aeb \
  2111. }
  2112. static int hdsp_aeb(struct hdsp *hdsp)
  2113. {
  2114. if (hdsp->control_register & HDSP_AnalogExtensionBoard)
  2115. return 1;
  2116. return 0;
  2117. }
  2118. static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
  2119. {
  2120. if (mode)
  2121. hdsp->control_register |= HDSP_AnalogExtensionBoard;
  2122. else
  2123. hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
  2124. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  2125. return 0;
  2126. }
  2127. static int snd_hdsp_info_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2128. {
  2129. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2130. uinfo->count = 1;
  2131. uinfo->value.integer.min = 0;
  2132. uinfo->value.integer.max = 1;
  2133. return 0;
  2134. }
  2135. static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2136. {
  2137. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2138. ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
  2139. return 0;
  2140. }
  2141. static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2142. {
  2143. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2144. int change;
  2145. int val;
  2146. if (!snd_hdsp_use_is_exclusive(hdsp))
  2147. return -EBUSY;
  2148. val = ucontrol->value.integer.value[0] & 1;
  2149. spin_lock_irq(&hdsp->lock);
  2150. change = (int)val != hdsp_aeb(hdsp);
  2151. hdsp_set_aeb(hdsp, val);
  2152. spin_unlock_irq(&hdsp->lock);
  2153. return change;
  2154. }
  2155. #define HDSP_PREF_SYNC_REF(xname, xindex) \
  2156. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2157. .name = xname, \
  2158. .index = xindex, \
  2159. .info = snd_hdsp_info_pref_sync_ref, \
  2160. .get = snd_hdsp_get_pref_sync_ref, \
  2161. .put = snd_hdsp_put_pref_sync_ref \
  2162. }
  2163. static int hdsp_pref_sync_ref(struct hdsp *hdsp)
  2164. {
  2165. /* Notice that this looks at the requested sync source,
  2166. not the one actually in use.
  2167. */
  2168. switch (hdsp->control_register & HDSP_SyncRefMask) {
  2169. case HDSP_SyncRef_ADAT1:
  2170. return HDSP_SYNC_FROM_ADAT1;
  2171. case HDSP_SyncRef_ADAT2:
  2172. return HDSP_SYNC_FROM_ADAT2;
  2173. case HDSP_SyncRef_ADAT3:
  2174. return HDSP_SYNC_FROM_ADAT3;
  2175. case HDSP_SyncRef_SPDIF:
  2176. return HDSP_SYNC_FROM_SPDIF;
  2177. case HDSP_SyncRef_WORD:
  2178. return HDSP_SYNC_FROM_WORD;
  2179. case HDSP_SyncRef_ADAT_SYNC:
  2180. return HDSP_SYNC_FROM_ADAT_SYNC;
  2181. default:
  2182. return HDSP_SYNC_FROM_WORD;
  2183. }
  2184. return 0;
  2185. }
  2186. static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
  2187. {
  2188. hdsp->control_register &= ~HDSP_SyncRefMask;
  2189. switch (pref) {
  2190. case HDSP_SYNC_FROM_ADAT1:
  2191. hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
  2192. break;
  2193. case HDSP_SYNC_FROM_ADAT2:
  2194. hdsp->control_register |= HDSP_SyncRef_ADAT2;
  2195. break;
  2196. case HDSP_SYNC_FROM_ADAT3:
  2197. hdsp->control_register |= HDSP_SyncRef_ADAT3;
  2198. break;
  2199. case HDSP_SYNC_FROM_SPDIF:
  2200. hdsp->control_register |= HDSP_SyncRef_SPDIF;
  2201. break;
  2202. case HDSP_SYNC_FROM_WORD:
  2203. hdsp->control_register |= HDSP_SyncRef_WORD;
  2204. break;
  2205. case HDSP_SYNC_FROM_ADAT_SYNC:
  2206. hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
  2207. break;
  2208. default:
  2209. return -1;
  2210. }
  2211. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  2212. return 0;
  2213. }
  2214. static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2215. {
  2216. static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
  2217. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2218. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2219. uinfo->count = 1;
  2220. switch (hdsp->io_type) {
  2221. case Digiface:
  2222. case H9652:
  2223. uinfo->value.enumerated.items = 6;
  2224. break;
  2225. case Multiface:
  2226. uinfo->value.enumerated.items = 4;
  2227. break;
  2228. case H9632:
  2229. uinfo->value.enumerated.items = 3;
  2230. break;
  2231. default:
  2232. uinfo->value.enumerated.items = 0;
  2233. break;
  2234. }
  2235. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2236. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2237. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2238. return 0;
  2239. }
  2240. static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2241. {
  2242. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2243. ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
  2244. return 0;
  2245. }
  2246. static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2247. {
  2248. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2249. int change, max;
  2250. unsigned int val;
  2251. if (!snd_hdsp_use_is_exclusive(hdsp))
  2252. return -EBUSY;
  2253. switch (hdsp->io_type) {
  2254. case Digiface:
  2255. case H9652:
  2256. max = 6;
  2257. break;
  2258. case Multiface:
  2259. max = 4;
  2260. break;
  2261. case H9632:
  2262. max = 3;
  2263. break;
  2264. default:
  2265. return -EIO;
  2266. }
  2267. val = ucontrol->value.enumerated.item[0] % max;
  2268. spin_lock_irq(&hdsp->lock);
  2269. change = (int)val != hdsp_pref_sync_ref(hdsp);
  2270. hdsp_set_pref_sync_ref(hdsp, val);
  2271. spin_unlock_irq(&hdsp->lock);
  2272. return change;
  2273. }
  2274. #define HDSP_AUTOSYNC_REF(xname, xindex) \
  2275. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2276. .name = xname, \
  2277. .index = xindex, \
  2278. .access = SNDRV_CTL_ELEM_ACCESS_READ, \
  2279. .info = snd_hdsp_info_autosync_ref, \
  2280. .get = snd_hdsp_get_autosync_ref, \
  2281. }
  2282. static int hdsp_autosync_ref(struct hdsp *hdsp)
  2283. {
  2284. /* This looks at the autosync selected sync reference */
  2285. unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
  2286. switch (status2 & HDSP_SelSyncRefMask) {
  2287. case HDSP_SelSyncRef_WORD:
  2288. return HDSP_AUTOSYNC_FROM_WORD;
  2289. case HDSP_SelSyncRef_ADAT_SYNC:
  2290. return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
  2291. case HDSP_SelSyncRef_SPDIF:
  2292. return HDSP_AUTOSYNC_FROM_SPDIF;
  2293. case HDSP_SelSyncRefMask:
  2294. return HDSP_AUTOSYNC_FROM_NONE;
  2295. case HDSP_SelSyncRef_ADAT1:
  2296. return HDSP_AUTOSYNC_FROM_ADAT1;
  2297. case HDSP_SelSyncRef_ADAT2:
  2298. return HDSP_AUTOSYNC_FROM_ADAT2;
  2299. case HDSP_SelSyncRef_ADAT3:
  2300. return HDSP_AUTOSYNC_FROM_ADAT3;
  2301. default:
  2302. return HDSP_AUTOSYNC_FROM_WORD;
  2303. }
  2304. return 0;
  2305. }
  2306. static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2307. {
  2308. static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
  2309. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2310. uinfo->count = 1;
  2311. uinfo->value.enumerated.items = 7;
  2312. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2313. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2314. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2315. return 0;
  2316. }
  2317. static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2318. {
  2319. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2320. ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
  2321. return 0;
  2322. }
  2323. #define HDSP_LINE_OUT(xname, xindex) \
  2324. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2325. .name = xname, \
  2326. .index = xindex, \
  2327. .info = snd_hdsp_info_line_out, \
  2328. .get = snd_hdsp_get_line_out, \
  2329. .put = snd_hdsp_put_line_out \
  2330. }
  2331. static int hdsp_line_out(struct hdsp *hdsp)
  2332. {
  2333. return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
  2334. }
  2335. static int hdsp_set_line_output(struct hdsp *hdsp, int out)
  2336. {
  2337. if (out)
  2338. hdsp->control_register |= HDSP_LineOut;
  2339. else
  2340. hdsp->control_register &= ~HDSP_LineOut;
  2341. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  2342. return 0;
  2343. }
  2344. static int snd_hdsp_info_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2345. {
  2346. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2347. uinfo->count = 1;
  2348. uinfo->value.integer.min = 0;
  2349. uinfo->value.integer.max = 1;
  2350. return 0;
  2351. }
  2352. static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2353. {
  2354. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2355. spin_lock_irq(&hdsp->lock);
  2356. ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
  2357. spin_unlock_irq(&hdsp->lock);
  2358. return 0;
  2359. }
  2360. static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2361. {
  2362. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2363. int change;
  2364. unsigned int val;
  2365. if (!snd_hdsp_use_is_exclusive(hdsp))
  2366. return -EBUSY;
  2367. val = ucontrol->value.integer.value[0] & 1;
  2368. spin_lock_irq(&hdsp->lock);
  2369. change = (int)val != hdsp_line_out(hdsp);
  2370. hdsp_set_line_output(hdsp, val);
  2371. spin_unlock_irq(&hdsp->lock);
  2372. return change;
  2373. }
  2374. #define HDSP_PRECISE_POINTER(xname, xindex) \
  2375. { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
  2376. .name = xname, \
  2377. .index = xindex, \
  2378. .info = snd_hdsp_info_precise_pointer, \
  2379. .get = snd_hdsp_get_precise_pointer, \
  2380. .put = snd_hdsp_put_precise_pointer \
  2381. }
  2382. static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
  2383. {
  2384. if (precise)
  2385. hdsp->precise_ptr = 1;
  2386. else
  2387. hdsp->precise_ptr = 0;
  2388. return 0;
  2389. }
  2390. static int snd_hdsp_info_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2391. {
  2392. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2393. uinfo->count = 1;
  2394. uinfo->value.integer.min = 0;
  2395. uinfo->value.integer.max = 1;
  2396. return 0;
  2397. }
  2398. static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2399. {
  2400. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2401. spin_lock_irq(&hdsp->lock);
  2402. ucontrol->value.integer.value[0] = hdsp->precise_ptr;
  2403. spin_unlock_irq(&hdsp->lock);
  2404. return 0;
  2405. }
  2406. static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2407. {
  2408. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2409. int change;
  2410. unsigned int val;
  2411. if (!snd_hdsp_use_is_exclusive(hdsp))
  2412. return -EBUSY;
  2413. val = ucontrol->value.integer.value[0] & 1;
  2414. spin_lock_irq(&hdsp->lock);
  2415. change = (int)val != hdsp->precise_ptr;
  2416. hdsp_set_precise_pointer(hdsp, val);
  2417. spin_unlock_irq(&hdsp->lock);
  2418. return change;
  2419. }
  2420. #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
  2421. { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
  2422. .name = xname, \
  2423. .index = xindex, \
  2424. .info = snd_hdsp_info_use_midi_tasklet, \
  2425. .get = snd_hdsp_get_use_midi_tasklet, \
  2426. .put = snd_hdsp_put_use_midi_tasklet \
  2427. }
  2428. static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
  2429. {
  2430. if (use_tasklet)
  2431. hdsp->use_midi_tasklet = 1;
  2432. else
  2433. hdsp->use_midi_tasklet = 0;
  2434. return 0;
  2435. }
  2436. static int snd_hdsp_info_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2437. {
  2438. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2439. uinfo->count = 1;
  2440. uinfo->value.integer.min = 0;
  2441. uinfo->value.integer.max = 1;
  2442. return 0;
  2443. }
  2444. static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2445. {
  2446. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2447. spin_lock_irq(&hdsp->lock);
  2448. ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
  2449. spin_unlock_irq(&hdsp->lock);
  2450. return 0;
  2451. }
  2452. static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2453. {
  2454. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2455. int change;
  2456. unsigned int val;
  2457. if (!snd_hdsp_use_is_exclusive(hdsp))
  2458. return -EBUSY;
  2459. val = ucontrol->value.integer.value[0] & 1;
  2460. spin_lock_irq(&hdsp->lock);
  2461. change = (int)val != hdsp->use_midi_tasklet;
  2462. hdsp_set_use_midi_tasklet(hdsp, val);
  2463. spin_unlock_irq(&hdsp->lock);
  2464. return change;
  2465. }
  2466. #define HDSP_MIXER(xname, xindex) \
  2467. { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
  2468. .name = xname, \
  2469. .index = xindex, \
  2470. .device = 0, \
  2471. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  2472. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2473. .info = snd_hdsp_info_mixer, \
  2474. .get = snd_hdsp_get_mixer, \
  2475. .put = snd_hdsp_put_mixer \
  2476. }
  2477. static int snd_hdsp_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2478. {
  2479. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2480. uinfo->count = 3;
  2481. uinfo->value.integer.min = 0;
  2482. uinfo->value.integer.max = 65536;
  2483. uinfo->value.integer.step = 1;
  2484. return 0;
  2485. }
  2486. static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2487. {
  2488. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2489. int source;
  2490. int destination;
  2491. int addr;
  2492. source = ucontrol->value.integer.value[0];
  2493. destination = ucontrol->value.integer.value[1];
  2494. if (source >= hdsp->max_channels)
  2495. addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
  2496. else
  2497. addr = hdsp_input_to_output_key(hdsp,source, destination);
  2498. spin_lock_irq(&hdsp->lock);
  2499. ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
  2500. spin_unlock_irq(&hdsp->lock);
  2501. return 0;
  2502. }
  2503. static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2504. {
  2505. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2506. int change;
  2507. int source;
  2508. int destination;
  2509. int gain;
  2510. int addr;
  2511. if (!snd_hdsp_use_is_exclusive(hdsp))
  2512. return -EBUSY;
  2513. source = ucontrol->value.integer.value[0];
  2514. destination = ucontrol->value.integer.value[1];
  2515. if (source >= hdsp->max_channels)
  2516. addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
  2517. else
  2518. addr = hdsp_input_to_output_key(hdsp,source, destination);
  2519. gain = ucontrol->value.integer.value[2];
  2520. spin_lock_irq(&hdsp->lock);
  2521. change = gain != hdsp_read_gain(hdsp, addr);
  2522. if (change)
  2523. hdsp_write_gain(hdsp, addr, gain);
  2524. spin_unlock_irq(&hdsp->lock);
  2525. return change;
  2526. }
  2527. #define HDSP_WC_SYNC_CHECK(xname, xindex) \
  2528. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2529. .name = xname, \
  2530. .index = xindex, \
  2531. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2532. .info = snd_hdsp_info_sync_check, \
  2533. .get = snd_hdsp_get_wc_sync_check \
  2534. }
  2535. static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2536. {
  2537. static char *texts[] = {"No Lock", "Lock", "Sync" };
  2538. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2539. uinfo->count = 1;
  2540. uinfo->value.enumerated.items = 3;
  2541. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2542. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2543. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2544. return 0;
  2545. }
  2546. static int hdsp_wc_sync_check(struct hdsp *hdsp)
  2547. {
  2548. int status2 = hdsp_read(hdsp, HDSP_status2Register);
  2549. if (status2 & HDSP_wc_lock) {
  2550. if (status2 & HDSP_wc_sync)
  2551. return 2;
  2552. else
  2553. return 1;
  2554. } else
  2555. return 0;
  2556. return 0;
  2557. }
  2558. static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2559. {
  2560. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2561. ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
  2562. return 0;
  2563. }
  2564. #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
  2565. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2566. .name = xname, \
  2567. .index = xindex, \
  2568. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2569. .info = snd_hdsp_info_sync_check, \
  2570. .get = snd_hdsp_get_spdif_sync_check \
  2571. }
  2572. static int hdsp_spdif_sync_check(struct hdsp *hdsp)
  2573. {
  2574. int status = hdsp_read(hdsp, HDSP_statusRegister);
  2575. if (status & HDSP_SPDIFErrorFlag)
  2576. return 0;
  2577. else {
  2578. if (status & HDSP_SPDIFSync)
  2579. return 2;
  2580. else
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2586. {
  2587. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2588. ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
  2589. return 0;
  2590. }
  2591. #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
  2592. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2593. .name = xname, \
  2594. .index = xindex, \
  2595. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2596. .info = snd_hdsp_info_sync_check, \
  2597. .get = snd_hdsp_get_adatsync_sync_check \
  2598. }
  2599. static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
  2600. {
  2601. int status = hdsp_read(hdsp, HDSP_statusRegister);
  2602. if (status & HDSP_TimecodeLock) {
  2603. if (status & HDSP_TimecodeSync)
  2604. return 2;
  2605. else
  2606. return 1;
  2607. } else
  2608. return 0;
  2609. }
  2610. static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2611. {
  2612. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2613. ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
  2614. return 0;
  2615. }
  2616. #define HDSP_ADAT_SYNC_CHECK \
  2617. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2618. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  2619. .info = snd_hdsp_info_sync_check, \
  2620. .get = snd_hdsp_get_adat_sync_check \
  2621. }
  2622. static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
  2623. {
  2624. int status = hdsp_read(hdsp, HDSP_statusRegister);
  2625. if (status & (HDSP_Lock0>>idx)) {
  2626. if (status & (HDSP_Sync0>>idx))
  2627. return 2;
  2628. else
  2629. return 1;
  2630. } else
  2631. return 0;
  2632. }
  2633. static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2634. {
  2635. int offset;
  2636. struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
  2637. offset = ucontrol->id.index - 1;
  2638. snd_assert(offset >= 0);
  2639. switch (hdsp->io_type) {
  2640. case Digiface:
  2641. case H9652:
  2642. if (offset >= 3)
  2643. return -EINVAL;
  2644. break;
  2645. case Multiface:
  2646. case H9632:
  2647. if (offset >= 1)
  2648. return -EINVAL;
  2649. break;
  2650. default:
  2651. return -EIO;
  2652. }
  2653. ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
  2654. return 0;
  2655. }
  2656. static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
  2657. HDSP_DA_GAIN("DA Gain", 0),
  2658. HDSP_AD_GAIN("AD Gain", 0),
  2659. HDSP_PHONE_GAIN("Phones Gain", 0),
  2660. HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
  2661. };
  2662. static struct snd_kcontrol_new snd_hdsp_controls[] = {
  2663. {
  2664. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2665. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  2666. .info = snd_hdsp_control_spdif_info,
  2667. .get = snd_hdsp_control_spdif_get,
  2668. .put = snd_hdsp_control_spdif_put,
  2669. },
  2670. {
  2671. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2672. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2673. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  2674. .info = snd_hdsp_control_spdif_stream_info,
  2675. .get = snd_hdsp_control_spdif_stream_get,
  2676. .put = snd_hdsp_control_spdif_stream_put,
  2677. },
  2678. {
  2679. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  2680. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2681. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  2682. .info = snd_hdsp_control_spdif_mask_info,
  2683. .get = snd_hdsp_control_spdif_mask_get,
  2684. .private_value = IEC958_AES0_NONAUDIO |
  2685. IEC958_AES0_PROFESSIONAL |
  2686. IEC958_AES0_CON_EMPHASIS,
  2687. },
  2688. {
  2689. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  2690. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2691. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  2692. .info = snd_hdsp_control_spdif_mask_info,
  2693. .get = snd_hdsp_control_spdif_mask_get,
  2694. .private_value = IEC958_AES0_NONAUDIO |
  2695. IEC958_AES0_PROFESSIONAL |
  2696. IEC958_AES0_PRO_EMPHASIS,
  2697. },
  2698. HDSP_MIXER("Mixer", 0),
  2699. HDSP_SPDIF_IN("IEC958 Input Connector", 0),
  2700. HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
  2701. HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
  2702. HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
  2703. HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
  2704. /* 'Sample Clock Source' complies with the alsa control naming scheme */
  2705. HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
  2706. {
  2707. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2708. .name = "Sample Clock Source Locking",
  2709. .info = snd_hdsp_info_clock_source_lock,
  2710. .get = snd_hdsp_get_clock_source_lock,
  2711. .put = snd_hdsp_put_clock_source_lock,
  2712. },
  2713. HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
  2714. HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
  2715. HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
  2716. HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
  2717. HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
  2718. /* 'External Rate' complies with the alsa control naming scheme */
  2719. HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
  2720. HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
  2721. HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
  2722. HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
  2723. HDSP_LINE_OUT("Line Out", 0),
  2724. HDSP_PRECISE_POINTER("Precise Pointer", 0),
  2725. HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
  2726. };
  2727. static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
  2728. static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
  2729. static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
  2730. {
  2731. unsigned int idx;
  2732. int err;
  2733. struct snd_kcontrol *kctl;
  2734. for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
  2735. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
  2736. return err;
  2737. if (idx == 1) /* IEC958 (S/PDIF) Stream */
  2738. hdsp->spdif_ctl = kctl;
  2739. }
  2740. /* ADAT SyncCheck status */
  2741. snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
  2742. snd_hdsp_adat_sync_check.index = 1;
  2743. if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
  2744. return err;
  2745. if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
  2746. for (idx = 1; idx < 3; ++idx) {
  2747. snd_hdsp_adat_sync_check.index = idx+1;
  2748. if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
  2749. return err;
  2750. }
  2751. }
  2752. /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
  2753. if (hdsp->io_type == H9632) {
  2754. for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
  2755. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
  2756. return err;
  2757. }
  2758. }
  2759. /* AEB control for H96xx card */
  2760. if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
  2761. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
  2762. return err;
  2763. }
  2764. return 0;
  2765. }
  2766. /*------------------------------------------------------------
  2767. /proc interface
  2768. ------------------------------------------------------------*/
  2769. static void
  2770. snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  2771. {
  2772. struct hdsp *hdsp = (struct hdsp *) entry->private_data;
  2773. unsigned int status;
  2774. unsigned int status2;
  2775. char *pref_sync_ref;
  2776. char *autosync_ref;
  2777. char *system_clock_mode;
  2778. char *clock_source;
  2779. int x;
  2780. if (hdsp_check_for_iobox (hdsp)) {
  2781. snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
  2782. return;
  2783. }
  2784. if (hdsp_check_for_firmware(hdsp, 0)) {
  2785. if (hdsp->state & HDSP_FirmwareCached) {
  2786. if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
  2787. snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
  2788. return;
  2789. }
  2790. } else {
  2791. int err = -EINVAL;
  2792. #ifdef HDSP_FW_LOADER
  2793. err = hdsp_request_fw_loader(hdsp);
  2794. #endif
  2795. if (err < 0) {
  2796. snd_iprintf(buffer,
  2797. "No firmware loaded nor cached, "
  2798. "please upload firmware.\n");
  2799. return;
  2800. }
  2801. }
  2802. }
  2803. status = hdsp_read(hdsp, HDSP_statusRegister);
  2804. status2 = hdsp_read(hdsp, HDSP_status2Register);
  2805. snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
  2806. snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
  2807. hdsp->capture_buffer, hdsp->playback_buffer);
  2808. snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
  2809. hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
  2810. snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
  2811. snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
  2812. snd_iprintf(buffer, "Status register: 0x%x\n", status);
  2813. snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
  2814. snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
  2815. snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
  2816. snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
  2817. snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
  2818. snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
  2819. snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
  2820. snd_iprintf(buffer, "\n");
  2821. x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
  2822. snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
  2823. snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
  2824. snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
  2825. snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
  2826. snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
  2827. snd_iprintf(buffer, "\n");
  2828. switch (hdsp_clock_source(hdsp)) {
  2829. case HDSP_CLOCK_SOURCE_AUTOSYNC:
  2830. clock_source = "AutoSync";
  2831. break;
  2832. case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
  2833. clock_source = "Internal 32 kHz";
  2834. break;
  2835. case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
  2836. clock_source = "Internal 44.1 kHz";
  2837. break;
  2838. case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
  2839. clock_source = "Internal 48 kHz";
  2840. break;
  2841. case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
  2842. clock_source = "Internal 64 kHz";
  2843. break;
  2844. case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
  2845. clock_source = "Internal 88.2 kHz";
  2846. break;
  2847. case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
  2848. clock_source = "Internal 96 kHz";
  2849. break;
  2850. case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
  2851. clock_source = "Internal 128 kHz";
  2852. break;
  2853. case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
  2854. clock_source = "Internal 176.4 kHz";
  2855. break;
  2856. case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
  2857. clock_source = "Internal 192 kHz";
  2858. break;
  2859. default:
  2860. clock_source = "Error";
  2861. }
  2862. snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
  2863. if (hdsp_system_clock_mode(hdsp))
  2864. system_clock_mode = "Slave";
  2865. else
  2866. system_clock_mode = "Master";
  2867. switch (hdsp_pref_sync_ref (hdsp)) {
  2868. case HDSP_SYNC_FROM_WORD:
  2869. pref_sync_ref = "Word Clock";
  2870. break;
  2871. case HDSP_SYNC_FROM_ADAT_SYNC:
  2872. pref_sync_ref = "ADAT Sync";
  2873. break;
  2874. case HDSP_SYNC_FROM_SPDIF:
  2875. pref_sync_ref = "SPDIF";
  2876. break;
  2877. case HDSP_SYNC_FROM_ADAT1:
  2878. pref_sync_ref = "ADAT1";
  2879. break;
  2880. case HDSP_SYNC_FROM_ADAT2:
  2881. pref_sync_ref = "ADAT2";
  2882. break;
  2883. case HDSP_SYNC_FROM_ADAT3:
  2884. pref_sync_ref = "ADAT3";
  2885. break;
  2886. default:
  2887. pref_sync_ref = "Word Clock";
  2888. break;
  2889. }
  2890. snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
  2891. switch (hdsp_autosync_ref (hdsp)) {
  2892. case HDSP_AUTOSYNC_FROM_WORD:
  2893. autosync_ref = "Word Clock";
  2894. break;
  2895. case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
  2896. autosync_ref = "ADAT Sync";
  2897. break;
  2898. case HDSP_AUTOSYNC_FROM_SPDIF:
  2899. autosync_ref = "SPDIF";
  2900. break;
  2901. case HDSP_AUTOSYNC_FROM_NONE:
  2902. autosync_ref = "None";
  2903. break;
  2904. case HDSP_AUTOSYNC_FROM_ADAT1:
  2905. autosync_ref = "ADAT1";
  2906. break;
  2907. case HDSP_AUTOSYNC_FROM_ADAT2:
  2908. autosync_ref = "ADAT2";
  2909. break;
  2910. case HDSP_AUTOSYNC_FROM_ADAT3:
  2911. autosync_ref = "ADAT3";
  2912. break;
  2913. default:
  2914. autosync_ref = "---";
  2915. break;
  2916. }
  2917. snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
  2918. snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
  2919. snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
  2920. snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
  2921. snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
  2922. snd_iprintf(buffer, "\n");
  2923. switch (hdsp_spdif_in(hdsp)) {
  2924. case HDSP_SPDIFIN_OPTICAL:
  2925. snd_iprintf(buffer, "IEC958 input: Optical\n");
  2926. break;
  2927. case HDSP_SPDIFIN_COAXIAL:
  2928. snd_iprintf(buffer, "IEC958 input: Coaxial\n");
  2929. break;
  2930. case HDSP_SPDIFIN_INTERNAL:
  2931. snd_iprintf(buffer, "IEC958 input: Internal\n");
  2932. break;
  2933. case HDSP_SPDIFIN_AES:
  2934. snd_iprintf(buffer, "IEC958 input: AES\n");
  2935. break;
  2936. default:
  2937. snd_iprintf(buffer, "IEC958 input: ???\n");
  2938. break;
  2939. }
  2940. if (hdsp->control_register & HDSP_SPDIFOpticalOut)
  2941. snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
  2942. else
  2943. snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
  2944. if (hdsp->control_register & HDSP_SPDIFProfessional)
  2945. snd_iprintf(buffer, "IEC958 quality: Professional\n");
  2946. else
  2947. snd_iprintf(buffer, "IEC958 quality: Consumer\n");
  2948. if (hdsp->control_register & HDSP_SPDIFEmphasis)
  2949. snd_iprintf(buffer, "IEC958 emphasis: on\n");
  2950. else
  2951. snd_iprintf(buffer, "IEC958 emphasis: off\n");
  2952. if (hdsp->control_register & HDSP_SPDIFNonAudio)
  2953. snd_iprintf(buffer, "IEC958 NonAudio: on\n");
  2954. else
  2955. snd_iprintf(buffer, "IEC958 NonAudio: off\n");
  2956. if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
  2957. snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
  2958. else
  2959. snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
  2960. snd_iprintf(buffer, "\n");
  2961. /* Sync Check */
  2962. x = status & HDSP_Sync0;
  2963. if (status & HDSP_Lock0)
  2964. snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
  2965. else
  2966. snd_iprintf(buffer, "ADAT1: No Lock\n");
  2967. switch (hdsp->io_type) {
  2968. case Digiface:
  2969. case H9652:
  2970. x = status & HDSP_Sync1;
  2971. if (status & HDSP_Lock1)
  2972. snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
  2973. else
  2974. snd_iprintf(buffer, "ADAT2: No Lock\n");
  2975. x = status & HDSP_Sync2;
  2976. if (status & HDSP_Lock2)
  2977. snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
  2978. else
  2979. snd_iprintf(buffer, "ADAT3: No Lock\n");
  2980. break;
  2981. default:
  2982. /* relax */
  2983. break;
  2984. }
  2985. x = status & HDSP_SPDIFSync;
  2986. if (status & HDSP_SPDIFErrorFlag)
  2987. snd_iprintf (buffer, "SPDIF: No Lock\n");
  2988. else
  2989. snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
  2990. x = status2 & HDSP_wc_sync;
  2991. if (status2 & HDSP_wc_lock)
  2992. snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
  2993. else
  2994. snd_iprintf (buffer, "Word Clock: No Lock\n");
  2995. x = status & HDSP_TimecodeSync;
  2996. if (status & HDSP_TimecodeLock)
  2997. snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
  2998. else
  2999. snd_iprintf(buffer, "ADAT Sync: No Lock\n");
  3000. snd_iprintf(buffer, "\n");
  3001. /* Informations about H9632 specific controls */
  3002. if (hdsp->io_type == H9632) {
  3003. char *tmp;
  3004. switch (hdsp_ad_gain(hdsp)) {
  3005. case 0:
  3006. tmp = "-10 dBV";
  3007. break;
  3008. case 1:
  3009. tmp = "+4 dBu";
  3010. break;
  3011. default:
  3012. tmp = "Lo Gain";
  3013. break;
  3014. }
  3015. snd_iprintf(buffer, "AD Gain : %s\n", tmp);
  3016. switch (hdsp_da_gain(hdsp)) {
  3017. case 0:
  3018. tmp = "Hi Gain";
  3019. break;
  3020. case 1:
  3021. tmp = "+4 dBu";
  3022. break;
  3023. default:
  3024. tmp = "-10 dBV";
  3025. break;
  3026. }
  3027. snd_iprintf(buffer, "DA Gain : %s\n", tmp);
  3028. switch (hdsp_phone_gain(hdsp)) {
  3029. case 0:
  3030. tmp = "0 dB";
  3031. break;
  3032. case 1:
  3033. tmp = "-6 dB";
  3034. break;
  3035. default:
  3036. tmp = "-12 dB";
  3037. break;
  3038. }
  3039. snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
  3040. snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
  3041. if (hdsp->control_register & HDSP_AnalogExtensionBoard)
  3042. snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
  3043. else
  3044. snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
  3045. snd_iprintf(buffer, "\n");
  3046. }
  3047. }
  3048. static void __devinit snd_hdsp_proc_init(struct hdsp *hdsp)
  3049. {
  3050. struct snd_info_entry *entry;
  3051. if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
  3052. snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
  3053. }
  3054. static void snd_hdsp_free_buffers(struct hdsp *hdsp)
  3055. {
  3056. snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
  3057. snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
  3058. }
  3059. static int __devinit snd_hdsp_initialize_memory(struct hdsp *hdsp)
  3060. {
  3061. unsigned long pb_bus, cb_bus;
  3062. if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
  3063. snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
  3064. if (hdsp->capture_dma_buf.area)
  3065. snd_dma_free_pages(&hdsp->capture_dma_buf);
  3066. printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
  3067. return -ENOMEM;
  3068. }
  3069. /* Align to bus-space 64K boundary */
  3070. cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
  3071. pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
  3072. /* Tell the card where it is */
  3073. hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
  3074. hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
  3075. hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
  3076. hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
  3077. return 0;
  3078. }
  3079. static int snd_hdsp_set_defaults(struct hdsp *hdsp)
  3080. {
  3081. unsigned int i;
  3082. /* ASSUMPTION: hdsp->lock is either held, or
  3083. there is no need to hold it (e.g. during module
  3084. initalization).
  3085. */
  3086. /* set defaults:
  3087. SPDIF Input via Coax
  3088. Master clock mode
  3089. maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
  3090. which implies 2 4096 sample, 32Kbyte periods).
  3091. Enable line out.
  3092. */
  3093. hdsp->control_register = HDSP_ClockModeMaster |
  3094. HDSP_SPDIFInputCoaxial |
  3095. hdsp_encode_latency(7) |
  3096. HDSP_LineOut;
  3097. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  3098. #ifdef SNDRV_BIG_ENDIAN
  3099. hdsp->control2_register = HDSP_BIGENDIAN_MODE;
  3100. #else
  3101. hdsp->control2_register = 0;
  3102. #endif
  3103. if (hdsp->io_type == H9652)
  3104. snd_hdsp_9652_enable_mixer (hdsp);
  3105. else
  3106. hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
  3107. hdsp_reset_hw_pointer(hdsp);
  3108. hdsp_compute_period_size(hdsp);
  3109. /* silence everything */
  3110. for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
  3111. hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
  3112. for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
  3113. if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
  3114. return -EIO;
  3115. }
  3116. /* H9632 specific defaults */
  3117. if (hdsp->io_type == H9632) {
  3118. hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
  3119. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  3120. }
  3121. /* set a default rate so that the channel map is set up.
  3122. */
  3123. hdsp_set_rate(hdsp, 48000, 1);
  3124. return 0;
  3125. }
  3126. static void hdsp_midi_tasklet(unsigned long arg)
  3127. {
  3128. struct hdsp *hdsp = (struct hdsp *)arg;
  3129. if (hdsp->midi[0].pending)
  3130. snd_hdsp_midi_input_read (&hdsp->midi[0]);
  3131. if (hdsp->midi[1].pending)
  3132. snd_hdsp_midi_input_read (&hdsp->midi[1]);
  3133. }
  3134. static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
  3135. {
  3136. struct hdsp *hdsp = (struct hdsp *) dev_id;
  3137. unsigned int status;
  3138. int audio;
  3139. int midi0;
  3140. int midi1;
  3141. unsigned int midi0status;
  3142. unsigned int midi1status;
  3143. int schedule = 0;
  3144. status = hdsp_read(hdsp, HDSP_statusRegister);
  3145. audio = status & HDSP_audioIRQPending;
  3146. midi0 = status & HDSP_midi0IRQPending;
  3147. midi1 = status & HDSP_midi1IRQPending;
  3148. if (!audio && !midi0 && !midi1)
  3149. return IRQ_NONE;
  3150. hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
  3151. midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
  3152. midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
  3153. if (audio) {
  3154. if (hdsp->capture_substream)
  3155. snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  3156. if (hdsp->playback_substream)
  3157. snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
  3158. }
  3159. if (midi0 && midi0status) {
  3160. if (hdsp->use_midi_tasklet) {
  3161. /* we disable interrupts for this input until processing is done */
  3162. hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
  3163. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  3164. hdsp->midi[0].pending = 1;
  3165. schedule = 1;
  3166. } else {
  3167. snd_hdsp_midi_input_read (&hdsp->midi[0]);
  3168. }
  3169. }
  3170. if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) {
  3171. if (hdsp->use_midi_tasklet) {
  3172. /* we disable interrupts for this input until processing is done */
  3173. hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
  3174. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
  3175. hdsp->midi[1].pending = 1;
  3176. schedule = 1;
  3177. } else {
  3178. snd_hdsp_midi_input_read (&hdsp->midi[1]);
  3179. }
  3180. }
  3181. if (hdsp->use_midi_tasklet && schedule)
  3182. tasklet_hi_schedule(&hdsp->midi_tasklet);
  3183. return IRQ_HANDLED;
  3184. }
  3185. static snd_pcm_uframes_t snd_hdsp_hw_pointer(struct snd_pcm_substream *substream)
  3186. {
  3187. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3188. return hdsp_hw_pointer(hdsp);
  3189. }
  3190. static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
  3191. int stream,
  3192. int channel)
  3193. {
  3194. int mapped_channel;
  3195. snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
  3196. if ((mapped_channel = hdsp->channel_map[channel]) < 0)
  3197. return NULL;
  3198. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  3199. return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
  3200. else
  3201. return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
  3202. }
  3203. static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel,
  3204. snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
  3205. {
  3206. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3207. char *channel_buf;
  3208. snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
  3209. channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
  3210. snd_assert(channel_buf != NULL, return -EIO);
  3211. if (copy_from_user(channel_buf + pos * 4, src, count * 4))
  3212. return -EFAULT;
  3213. return count;
  3214. }
  3215. static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel,
  3216. snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
  3217. {
  3218. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3219. char *channel_buf;
  3220. snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
  3221. channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
  3222. snd_assert(channel_buf != NULL, return -EIO);
  3223. if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
  3224. return -EFAULT;
  3225. return count;
  3226. }
  3227. static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel,
  3228. snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
  3229. {
  3230. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3231. char *channel_buf;
  3232. channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
  3233. snd_assert(channel_buf != NULL, return -EIO);
  3234. memset(channel_buf + pos * 4, 0, count * 4);
  3235. return count;
  3236. }
  3237. static int snd_hdsp_reset(struct snd_pcm_substream *substream)
  3238. {
  3239. struct snd_pcm_runtime *runtime = substream->runtime;
  3240. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3241. struct snd_pcm_substream *other;
  3242. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  3243. other = hdsp->capture_substream;
  3244. else
  3245. other = hdsp->playback_substream;
  3246. if (hdsp->running)
  3247. runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
  3248. else
  3249. runtime->status->hw_ptr = 0;
  3250. if (other) {
  3251. struct list_head *pos;
  3252. struct snd_pcm_substream *s;
  3253. struct snd_pcm_runtime *oruntime = other->runtime;
  3254. snd_pcm_group_for_each(pos, substream) {
  3255. s = snd_pcm_group_substream_entry(pos);
  3256. if (s == other) {
  3257. oruntime->status->hw_ptr = runtime->status->hw_ptr;
  3258. break;
  3259. }
  3260. }
  3261. }
  3262. return 0;
  3263. }
  3264. static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,
  3265. struct snd_pcm_hw_params *params)
  3266. {
  3267. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3268. int err;
  3269. pid_t this_pid;
  3270. pid_t other_pid;
  3271. if (hdsp_check_for_iobox (hdsp))
  3272. return -EIO;
  3273. if (hdsp_check_for_firmware(hdsp, 1))
  3274. return -EIO;
  3275. spin_lock_irq(&hdsp->lock);
  3276. if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3277. hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
  3278. hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
  3279. this_pid = hdsp->playback_pid;
  3280. other_pid = hdsp->capture_pid;
  3281. } else {
  3282. this_pid = hdsp->capture_pid;
  3283. other_pid = hdsp->playback_pid;
  3284. }
  3285. if ((other_pid > 0) && (this_pid != other_pid)) {
  3286. /* The other stream is open, and not by the same
  3287. task as this one. Make sure that the parameters
  3288. that matter are the same.
  3289. */
  3290. if (params_rate(params) != hdsp->system_sample_rate) {
  3291. spin_unlock_irq(&hdsp->lock);
  3292. _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
  3293. return -EBUSY;
  3294. }
  3295. if (params_period_size(params) != hdsp->period_bytes / 4) {
  3296. spin_unlock_irq(&hdsp->lock);
  3297. _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
  3298. return -EBUSY;
  3299. }
  3300. /* We're fine. */
  3301. spin_unlock_irq(&hdsp->lock);
  3302. return 0;
  3303. } else {
  3304. spin_unlock_irq(&hdsp->lock);
  3305. }
  3306. /* how to make sure that the rate matches an externally-set one ?
  3307. */
  3308. spin_lock_irq(&hdsp->lock);
  3309. if (! hdsp->clock_source_locked) {
  3310. if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
  3311. spin_unlock_irq(&hdsp->lock);
  3312. _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
  3313. return err;
  3314. }
  3315. }
  3316. spin_unlock_irq(&hdsp->lock);
  3317. if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
  3318. _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
  3319. return err;
  3320. }
  3321. return 0;
  3322. }
  3323. static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,
  3324. struct snd_pcm_channel_info *info)
  3325. {
  3326. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3327. int mapped_channel;
  3328. snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
  3329. if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
  3330. return -EINVAL;
  3331. info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
  3332. info->first = 0;
  3333. info->step = 32;
  3334. return 0;
  3335. }
  3336. static int snd_hdsp_ioctl(struct snd_pcm_substream *substream,
  3337. unsigned int cmd, void *arg)
  3338. {
  3339. switch (cmd) {
  3340. case SNDRV_PCM_IOCTL1_RESET:
  3341. return snd_hdsp_reset(substream);
  3342. case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
  3343. return snd_hdsp_channel_info(substream, arg);
  3344. default:
  3345. break;
  3346. }
  3347. return snd_pcm_lib_ioctl(substream, cmd, arg);
  3348. }
  3349. static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)
  3350. {
  3351. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3352. struct snd_pcm_substream *other;
  3353. int running;
  3354. if (hdsp_check_for_iobox (hdsp))
  3355. return -EIO;
  3356. if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
  3357. return -EIO;
  3358. spin_lock(&hdsp->lock);
  3359. running = hdsp->running;
  3360. switch (cmd) {
  3361. case SNDRV_PCM_TRIGGER_START:
  3362. running |= 1 << substream->stream;
  3363. break;
  3364. case SNDRV_PCM_TRIGGER_STOP:
  3365. running &= ~(1 << substream->stream);
  3366. break;
  3367. default:
  3368. snd_BUG();
  3369. spin_unlock(&hdsp->lock);
  3370. return -EINVAL;
  3371. }
  3372. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  3373. other = hdsp->capture_substream;
  3374. else
  3375. other = hdsp->playback_substream;
  3376. if (other) {
  3377. struct list_head *pos;
  3378. struct snd_pcm_substream *s;
  3379. snd_pcm_group_for_each(pos, substream) {
  3380. s = snd_pcm_group_substream_entry(pos);
  3381. if (s == other) {
  3382. snd_pcm_trigger_done(s, substream);
  3383. if (cmd == SNDRV_PCM_TRIGGER_START)
  3384. running |= 1 << s->stream;
  3385. else
  3386. running &= ~(1 << s->stream);
  3387. goto _ok;
  3388. }
  3389. }
  3390. if (cmd == SNDRV_PCM_TRIGGER_START) {
  3391. if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
  3392. substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  3393. hdsp_silence_playback(hdsp);
  3394. } else {
  3395. if (running &&
  3396. substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  3397. hdsp_silence_playback(hdsp);
  3398. }
  3399. } else {
  3400. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  3401. hdsp_silence_playback(hdsp);
  3402. }
  3403. _ok:
  3404. snd_pcm_trigger_done(substream, substream);
  3405. if (!hdsp->running && running)
  3406. hdsp_start_audio(hdsp);
  3407. else if (hdsp->running && !running)
  3408. hdsp_stop_audio(hdsp);
  3409. hdsp->running = running;
  3410. spin_unlock(&hdsp->lock);
  3411. return 0;
  3412. }
  3413. static int snd_hdsp_prepare(struct snd_pcm_substream *substream)
  3414. {
  3415. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3416. int result = 0;
  3417. if (hdsp_check_for_iobox (hdsp))
  3418. return -EIO;
  3419. if (hdsp_check_for_firmware(hdsp, 1))
  3420. return -EIO;
  3421. spin_lock_irq(&hdsp->lock);
  3422. if (!hdsp->running)
  3423. hdsp_reset_hw_pointer(hdsp);
  3424. spin_unlock_irq(&hdsp->lock);
  3425. return result;
  3426. }
  3427. static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
  3428. {
  3429. .info = (SNDRV_PCM_INFO_MMAP |
  3430. SNDRV_PCM_INFO_MMAP_VALID |
  3431. SNDRV_PCM_INFO_NONINTERLEAVED |
  3432. SNDRV_PCM_INFO_SYNC_START |
  3433. SNDRV_PCM_INFO_DOUBLE),
  3434. #ifdef SNDRV_BIG_ENDIAN
  3435. .formats = SNDRV_PCM_FMTBIT_S32_BE,
  3436. #else
  3437. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  3438. #endif
  3439. .rates = (SNDRV_PCM_RATE_32000 |
  3440. SNDRV_PCM_RATE_44100 |
  3441. SNDRV_PCM_RATE_48000 |
  3442. SNDRV_PCM_RATE_64000 |
  3443. SNDRV_PCM_RATE_88200 |
  3444. SNDRV_PCM_RATE_96000),
  3445. .rate_min = 32000,
  3446. .rate_max = 96000,
  3447. .channels_min = 14,
  3448. .channels_max = HDSP_MAX_CHANNELS,
  3449. .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
  3450. .period_bytes_min = (64 * 4) * 10,
  3451. .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
  3452. .periods_min = 2,
  3453. .periods_max = 2,
  3454. .fifo_size = 0
  3455. };
  3456. static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
  3457. {
  3458. .info = (SNDRV_PCM_INFO_MMAP |
  3459. SNDRV_PCM_INFO_MMAP_VALID |
  3460. SNDRV_PCM_INFO_NONINTERLEAVED |
  3461. SNDRV_PCM_INFO_SYNC_START),
  3462. #ifdef SNDRV_BIG_ENDIAN
  3463. .formats = SNDRV_PCM_FMTBIT_S32_BE,
  3464. #else
  3465. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  3466. #endif
  3467. .rates = (SNDRV_PCM_RATE_32000 |
  3468. SNDRV_PCM_RATE_44100 |
  3469. SNDRV_PCM_RATE_48000 |
  3470. SNDRV_PCM_RATE_64000 |
  3471. SNDRV_PCM_RATE_88200 |
  3472. SNDRV_PCM_RATE_96000),
  3473. .rate_min = 32000,
  3474. .rate_max = 96000,
  3475. .channels_min = 14,
  3476. .channels_max = HDSP_MAX_CHANNELS,
  3477. .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
  3478. .period_bytes_min = (64 * 4) * 10,
  3479. .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
  3480. .periods_min = 2,
  3481. .periods_max = 2,
  3482. .fifo_size = 0
  3483. };
  3484. static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
  3485. static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
  3486. .count = ARRAY_SIZE(hdsp_period_sizes),
  3487. .list = hdsp_period_sizes,
  3488. .mask = 0
  3489. };
  3490. static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
  3491. static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
  3492. .count = ARRAY_SIZE(hdsp_9632_sample_rates),
  3493. .list = hdsp_9632_sample_rates,
  3494. .mask = 0
  3495. };
  3496. static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params *params,
  3497. struct snd_pcm_hw_rule *rule)
  3498. {
  3499. struct hdsp *hdsp = rule->private;
  3500. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3501. if (hdsp->io_type == H9632) {
  3502. unsigned int list[3];
  3503. list[0] = hdsp->qs_in_channels;
  3504. list[1] = hdsp->ds_in_channels;
  3505. list[2] = hdsp->ss_in_channels;
  3506. return snd_interval_list(c, 3, list, 0);
  3507. } else {
  3508. unsigned int list[2];
  3509. list[0] = hdsp->ds_in_channels;
  3510. list[1] = hdsp->ss_in_channels;
  3511. return snd_interval_list(c, 2, list, 0);
  3512. }
  3513. }
  3514. static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params *params,
  3515. struct snd_pcm_hw_rule *rule)
  3516. {
  3517. unsigned int list[3];
  3518. struct hdsp *hdsp = rule->private;
  3519. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3520. if (hdsp->io_type == H9632) {
  3521. list[0] = hdsp->qs_out_channels;
  3522. list[1] = hdsp->ds_out_channels;
  3523. list[2] = hdsp->ss_out_channels;
  3524. return snd_interval_list(c, 3, list, 0);
  3525. } else {
  3526. list[0] = hdsp->ds_out_channels;
  3527. list[1] = hdsp->ss_out_channels;
  3528. }
  3529. return snd_interval_list(c, 2, list, 0);
  3530. }
  3531. static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
  3532. struct snd_pcm_hw_rule *rule)
  3533. {
  3534. struct hdsp *hdsp = rule->private;
  3535. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3536. struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  3537. if (r->min > 96000 && hdsp->io_type == H9632) {
  3538. struct snd_interval t = {
  3539. .min = hdsp->qs_in_channels,
  3540. .max = hdsp->qs_in_channels,
  3541. .integer = 1,
  3542. };
  3543. return snd_interval_refine(c, &t);
  3544. } else if (r->min > 48000 && r->max <= 96000) {
  3545. struct snd_interval t = {
  3546. .min = hdsp->ds_in_channels,
  3547. .max = hdsp->ds_in_channels,
  3548. .integer = 1,
  3549. };
  3550. return snd_interval_refine(c, &t);
  3551. } else if (r->max < 64000) {
  3552. struct snd_interval t = {
  3553. .min = hdsp->ss_in_channels,
  3554. .max = hdsp->ss_in_channels,
  3555. .integer = 1,
  3556. };
  3557. return snd_interval_refine(c, &t);
  3558. }
  3559. return 0;
  3560. }
  3561. static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
  3562. struct snd_pcm_hw_rule *rule)
  3563. {
  3564. struct hdsp *hdsp = rule->private;
  3565. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3566. struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  3567. if (r->min > 96000 && hdsp->io_type == H9632) {
  3568. struct snd_interval t = {
  3569. .min = hdsp->qs_out_channels,
  3570. .max = hdsp->qs_out_channels,
  3571. .integer = 1,
  3572. };
  3573. return snd_interval_refine(c, &t);
  3574. } else if (r->min > 48000 && r->max <= 96000) {
  3575. struct snd_interval t = {
  3576. .min = hdsp->ds_out_channels,
  3577. .max = hdsp->ds_out_channels,
  3578. .integer = 1,
  3579. };
  3580. return snd_interval_refine(c, &t);
  3581. } else if (r->max < 64000) {
  3582. struct snd_interval t = {
  3583. .min = hdsp->ss_out_channels,
  3584. .max = hdsp->ss_out_channels,
  3585. .integer = 1,
  3586. };
  3587. return snd_interval_refine(c, &t);
  3588. }
  3589. return 0;
  3590. }
  3591. static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
  3592. struct snd_pcm_hw_rule *rule)
  3593. {
  3594. struct hdsp *hdsp = rule->private;
  3595. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3596. struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  3597. if (c->min >= hdsp->ss_out_channels) {
  3598. struct snd_interval t = {
  3599. .min = 32000,
  3600. .max = 48000,
  3601. .integer = 1,
  3602. };
  3603. return snd_interval_refine(r, &t);
  3604. } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
  3605. struct snd_interval t = {
  3606. .min = 128000,
  3607. .max = 192000,
  3608. .integer = 1,
  3609. };
  3610. return snd_interval_refine(r, &t);
  3611. } else if (c->max <= hdsp->ds_out_channels) {
  3612. struct snd_interval t = {
  3613. .min = 64000,
  3614. .max = 96000,
  3615. .integer = 1,
  3616. };
  3617. return snd_interval_refine(r, &t);
  3618. }
  3619. return 0;
  3620. }
  3621. static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
  3622. struct snd_pcm_hw_rule *rule)
  3623. {
  3624. struct hdsp *hdsp = rule->private;
  3625. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  3626. struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  3627. if (c->min >= hdsp->ss_in_channels) {
  3628. struct snd_interval t = {
  3629. .min = 32000,
  3630. .max = 48000,
  3631. .integer = 1,
  3632. };
  3633. return snd_interval_refine(r, &t);
  3634. } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
  3635. struct snd_interval t = {
  3636. .min = 128000,
  3637. .max = 192000,
  3638. .integer = 1,
  3639. };
  3640. return snd_interval_refine(r, &t);
  3641. } else if (c->max <= hdsp->ds_in_channels) {
  3642. struct snd_interval t = {
  3643. .min = 64000,
  3644. .max = 96000,
  3645. .integer = 1,
  3646. };
  3647. return snd_interval_refine(r, &t);
  3648. }
  3649. return 0;
  3650. }
  3651. static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
  3652. {
  3653. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3654. struct snd_pcm_runtime *runtime = substream->runtime;
  3655. if (hdsp_check_for_iobox (hdsp))
  3656. return -EIO;
  3657. if (hdsp_check_for_firmware(hdsp, 1))
  3658. return -EIO;
  3659. spin_lock_irq(&hdsp->lock);
  3660. snd_pcm_set_sync(substream);
  3661. runtime->hw = snd_hdsp_playback_subinfo;
  3662. runtime->dma_area = hdsp->playback_buffer;
  3663. runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
  3664. hdsp->playback_pid = current->pid;
  3665. hdsp->playback_substream = substream;
  3666. spin_unlock_irq(&hdsp->lock);
  3667. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  3668. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
  3669. if (hdsp->clock_source_locked) {
  3670. runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
  3671. } else if (hdsp->io_type == H9632) {
  3672. runtime->hw.rate_max = 192000;
  3673. runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
  3674. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
  3675. }
  3676. if (hdsp->io_type == H9632) {
  3677. runtime->hw.channels_min = hdsp->qs_out_channels;
  3678. runtime->hw.channels_max = hdsp->ss_out_channels;
  3679. }
  3680. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  3681. snd_hdsp_hw_rule_out_channels, hdsp,
  3682. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  3683. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  3684. snd_hdsp_hw_rule_out_channels_rate, hdsp,
  3685. SNDRV_PCM_HW_PARAM_RATE, -1);
  3686. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  3687. snd_hdsp_hw_rule_rate_out_channels, hdsp,
  3688. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  3689. hdsp->creg_spdif_stream = hdsp->creg_spdif;
  3690. hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  3691. snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
  3692. SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
  3693. return 0;
  3694. }
  3695. static int snd_hdsp_playback_release(struct snd_pcm_substream *substream)
  3696. {
  3697. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3698. spin_lock_irq(&hdsp->lock);
  3699. hdsp->playback_pid = -1;
  3700. hdsp->playback_substream = NULL;
  3701. spin_unlock_irq(&hdsp->lock);
  3702. hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  3703. snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
  3704. SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
  3705. return 0;
  3706. }
  3707. static int snd_hdsp_capture_open(struct snd_pcm_substream *substream)
  3708. {
  3709. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3710. struct snd_pcm_runtime *runtime = substream->runtime;
  3711. if (hdsp_check_for_iobox (hdsp))
  3712. return -EIO;
  3713. if (hdsp_check_for_firmware(hdsp, 1))
  3714. return -EIO;
  3715. spin_lock_irq(&hdsp->lock);
  3716. snd_pcm_set_sync(substream);
  3717. runtime->hw = snd_hdsp_capture_subinfo;
  3718. runtime->dma_area = hdsp->capture_buffer;
  3719. runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
  3720. hdsp->capture_pid = current->pid;
  3721. hdsp->capture_substream = substream;
  3722. spin_unlock_irq(&hdsp->lock);
  3723. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  3724. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
  3725. if (hdsp->io_type == H9632) {
  3726. runtime->hw.channels_min = hdsp->qs_in_channels;
  3727. runtime->hw.channels_max = hdsp->ss_in_channels;
  3728. runtime->hw.rate_max = 192000;
  3729. runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
  3730. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
  3731. }
  3732. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  3733. snd_hdsp_hw_rule_in_channels, hdsp,
  3734. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  3735. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  3736. snd_hdsp_hw_rule_in_channels_rate, hdsp,
  3737. SNDRV_PCM_HW_PARAM_RATE, -1);
  3738. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  3739. snd_hdsp_hw_rule_rate_in_channels, hdsp,
  3740. SNDRV_PCM_HW_PARAM_CHANNELS, -1);
  3741. return 0;
  3742. }
  3743. static int snd_hdsp_capture_release(struct snd_pcm_substream *substream)
  3744. {
  3745. struct hdsp *hdsp = snd_pcm_substream_chip(substream);
  3746. spin_lock_irq(&hdsp->lock);
  3747. hdsp->capture_pid = -1;
  3748. hdsp->capture_substream = NULL;
  3749. spin_unlock_irq(&hdsp->lock);
  3750. return 0;
  3751. }
  3752. static int snd_hdsp_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
  3753. {
  3754. /* we have nothing to initialize but the call is required */
  3755. return 0;
  3756. }
  3757. /* helper functions for copying meter values */
  3758. static inline int copy_u32_le(void __user *dest, void __iomem *src)
  3759. {
  3760. u32 val = readl(src);
  3761. return copy_to_user(dest, &val, 4);
  3762. }
  3763. static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
  3764. {
  3765. u32 rms_low, rms_high;
  3766. u64 rms;
  3767. rms_low = readl(src_low);
  3768. rms_high = readl(src_high);
  3769. rms = ((u64)rms_high << 32) | rms_low;
  3770. return copy_to_user(dest, &rms, 8);
  3771. }
  3772. static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
  3773. {
  3774. u32 rms_low, rms_high;
  3775. u64 rms;
  3776. rms_low = readl(src_low) & 0xffffff00;
  3777. rms_high = readl(src_high) & 0xffffff00;
  3778. rms = ((u64)rms_high << 32) | rms_low;
  3779. return copy_to_user(dest, &rms, 8);
  3780. }
  3781. static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
  3782. {
  3783. int doublespeed = 0;
  3784. int i, j, channels, ofs;
  3785. if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
  3786. doublespeed = 1;
  3787. channels = doublespeed ? 14 : 26;
  3788. for (i = 0, j = 0; i < 26; ++i) {
  3789. if (doublespeed && (i & 4))
  3790. continue;
  3791. ofs = HDSP_9652_peakBase - j * 4;
  3792. if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
  3793. return -EFAULT;
  3794. ofs -= channels * 4;
  3795. if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
  3796. return -EFAULT;
  3797. ofs -= channels * 4;
  3798. if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
  3799. return -EFAULT;
  3800. ofs = HDSP_9652_rmsBase + j * 8;
  3801. if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
  3802. hdsp->iobase + ofs + 4))
  3803. return -EFAULT;
  3804. ofs += channels * 8;
  3805. if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
  3806. hdsp->iobase + ofs + 4))
  3807. return -EFAULT;
  3808. ofs += channels * 8;
  3809. if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
  3810. hdsp->iobase + ofs + 4))
  3811. return -EFAULT;
  3812. j++;
  3813. }
  3814. return 0;
  3815. }
  3816. static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
  3817. {
  3818. int i, j;
  3819. struct hdsp_9632_meters __iomem *m;
  3820. int doublespeed = 0;
  3821. if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
  3822. doublespeed = 1;
  3823. m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
  3824. for (i = 0, j = 0; i < 16; ++i, ++j) {
  3825. if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
  3826. return -EFAULT;
  3827. if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
  3828. return -EFAULT;
  3829. if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
  3830. return -EFAULT;
  3831. if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
  3832. &m->input_rms_high[j]))
  3833. return -EFAULT;
  3834. if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
  3835. &m->playback_rms_high[j]))
  3836. return -EFAULT;
  3837. if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
  3838. &m->output_rms_high[j]))
  3839. return -EFAULT;
  3840. if (doublespeed && i == 3) i += 4;
  3841. }
  3842. return 0;
  3843. }
  3844. static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
  3845. {
  3846. int i;
  3847. for (i = 0; i < 26; i++) {
  3848. if (copy_u32_le(&peak_rms->playback_peaks[i],
  3849. hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
  3850. return -EFAULT;
  3851. if (copy_u32_le(&peak_rms->input_peaks[i],
  3852. hdsp->iobase + HDSP_inputPeakLevel + i * 4))
  3853. return -EFAULT;
  3854. }
  3855. for (i = 0; i < 28; i++) {
  3856. if (copy_u32_le(&peak_rms->output_peaks[i],
  3857. hdsp->iobase + HDSP_outputPeakLevel + i * 4))
  3858. return -EFAULT;
  3859. }
  3860. for (i = 0; i < 26; ++i) {
  3861. if (copy_u64_le(&peak_rms->playback_rms[i],
  3862. hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
  3863. hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
  3864. return -EFAULT;
  3865. if (copy_u64_le(&peak_rms->input_rms[i],
  3866. hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
  3867. hdsp->iobase + HDSP_inputRmsLevel + i * 8))
  3868. return -EFAULT;
  3869. }
  3870. return 0;
  3871. }
  3872. static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg)
  3873. {
  3874. struct hdsp *hdsp = (struct hdsp *)hw->private_data;
  3875. void __user *argp = (void __user *)arg;
  3876. switch (cmd) {
  3877. case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
  3878. struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg;
  3879. if (!(hdsp->state & HDSP_FirmwareLoaded)) {
  3880. snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
  3881. return -EINVAL;
  3882. }
  3883. switch (hdsp->io_type) {
  3884. case H9652:
  3885. return hdsp_9652_get_peak(hdsp, peak_rms);
  3886. case H9632:
  3887. return hdsp_9632_get_peak(hdsp, peak_rms);
  3888. default:
  3889. return hdsp_get_peak(hdsp, peak_rms);
  3890. }
  3891. }
  3892. case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
  3893. struct hdsp_config_info info;
  3894. unsigned long flags;
  3895. int i;
  3896. if (!(hdsp->state & HDSP_FirmwareLoaded)) {
  3897. snd_printk(KERN_ERR "Hammerfall-DSP: Firmware needs to be uploaded to the card.\n");
  3898. return -EINVAL;
  3899. }
  3900. spin_lock_irqsave(&hdsp->lock, flags);
  3901. info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
  3902. info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
  3903. if (hdsp->io_type != H9632)
  3904. info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
  3905. info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
  3906. for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
  3907. info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
  3908. info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
  3909. info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
  3910. info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
  3911. info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
  3912. info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
  3913. info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
  3914. info.system_sample_rate = hdsp->system_sample_rate;
  3915. info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
  3916. info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
  3917. info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
  3918. info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
  3919. info.line_out = (unsigned char)hdsp_line_out(hdsp);
  3920. if (hdsp->io_type == H9632) {
  3921. info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
  3922. info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
  3923. info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
  3924. info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
  3925. }
  3926. if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
  3927. info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
  3928. spin_unlock_irqrestore(&hdsp->lock, flags);
  3929. if (copy_to_user(argp, &info, sizeof(info)))
  3930. return -EFAULT;
  3931. break;
  3932. }
  3933. case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
  3934. struct hdsp_9632_aeb h9632_aeb;
  3935. if (hdsp->io_type != H9632) return -EINVAL;
  3936. h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
  3937. h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
  3938. if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
  3939. return -EFAULT;
  3940. break;
  3941. }
  3942. case SNDRV_HDSP_IOCTL_GET_VERSION: {
  3943. struct hdsp_version hdsp_version;
  3944. int err;
  3945. if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
  3946. if (hdsp->io_type == Undefined) {
  3947. if ((err = hdsp_get_iobox_version(hdsp)) < 0)
  3948. return err;
  3949. }
  3950. hdsp_version.io_type = hdsp->io_type;
  3951. hdsp_version.firmware_rev = hdsp->firmware_rev;
  3952. if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
  3953. return -EFAULT;
  3954. break;
  3955. }
  3956. case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
  3957. struct hdsp_firmware __user *firmware;
  3958. u32 __user *firmware_data;
  3959. int err;
  3960. if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
  3961. /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
  3962. if (hdsp->io_type == Undefined) return -EINVAL;
  3963. if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
  3964. return -EBUSY;
  3965. snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
  3966. firmware = (struct hdsp_firmware __user *)argp;
  3967. if (get_user(firmware_data, &firmware->firmware_data))
  3968. return -EFAULT;
  3969. if (hdsp_check_for_iobox (hdsp))
  3970. return -EIO;
  3971. if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
  3972. return -EFAULT;
  3973. hdsp->state |= HDSP_FirmwareCached;
  3974. if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
  3975. return err;
  3976. if (!(hdsp->state & HDSP_InitializationComplete)) {
  3977. if ((err = snd_hdsp_enable_io(hdsp)) < 0)
  3978. return err;
  3979. snd_hdsp_initialize_channels(hdsp);
  3980. snd_hdsp_initialize_midi_flush(hdsp);
  3981. if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
  3982. snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
  3983. return err;
  3984. }
  3985. }
  3986. break;
  3987. }
  3988. case SNDRV_HDSP_IOCTL_GET_MIXER: {
  3989. struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp;
  3990. if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
  3991. return -EFAULT;
  3992. break;
  3993. }
  3994. default:
  3995. return -EINVAL;
  3996. }
  3997. return 0;
  3998. }
  3999. static struct snd_pcm_ops snd_hdsp_playback_ops = {
  4000. .open = snd_hdsp_playback_open,
  4001. .close = snd_hdsp_playback_release,
  4002. .ioctl = snd_hdsp_ioctl,
  4003. .hw_params = snd_hdsp_hw_params,
  4004. .prepare = snd_hdsp_prepare,
  4005. .trigger = snd_hdsp_trigger,
  4006. .pointer = snd_hdsp_hw_pointer,
  4007. .copy = snd_hdsp_playback_copy,
  4008. .silence = snd_hdsp_hw_silence,
  4009. };
  4010. static struct snd_pcm_ops snd_hdsp_capture_ops = {
  4011. .open = snd_hdsp_capture_open,
  4012. .close = snd_hdsp_capture_release,
  4013. .ioctl = snd_hdsp_ioctl,
  4014. .hw_params = snd_hdsp_hw_params,
  4015. .prepare = snd_hdsp_prepare,
  4016. .trigger = snd_hdsp_trigger,
  4017. .pointer = snd_hdsp_hw_pointer,
  4018. .copy = snd_hdsp_capture_copy,
  4019. };
  4020. static int __devinit snd_hdsp_create_hwdep(struct snd_card *card,
  4021. struct hdsp *hdsp)
  4022. {
  4023. struct snd_hwdep *hw;
  4024. int err;
  4025. if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
  4026. return err;
  4027. hdsp->hwdep = hw;
  4028. hw->private_data = hdsp;
  4029. strcpy(hw->name, "HDSP hwdep interface");
  4030. hw->ops.open = snd_hdsp_hwdep_dummy_op;
  4031. hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
  4032. hw->ops.release = snd_hdsp_hwdep_dummy_op;
  4033. return 0;
  4034. }
  4035. static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
  4036. {
  4037. struct snd_pcm *pcm;
  4038. int err;
  4039. if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
  4040. return err;
  4041. hdsp->pcm = pcm;
  4042. pcm->private_data = hdsp;
  4043. strcpy(pcm->name, hdsp->card_name);
  4044. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
  4045. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
  4046. pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
  4047. return 0;
  4048. }
  4049. static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
  4050. {
  4051. hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
  4052. hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
  4053. }
  4054. static int snd_hdsp_enable_io (struct hdsp *hdsp)
  4055. {
  4056. int i;
  4057. if (hdsp_fifo_wait (hdsp, 0, 100)) {
  4058. snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
  4059. return -EIO;
  4060. }
  4061. for (i = 0; i < hdsp->max_channels; ++i) {
  4062. hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
  4063. hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
  4064. }
  4065. return 0;
  4066. }
  4067. static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
  4068. {
  4069. int status, aebi_channels, aebo_channels;
  4070. switch (hdsp->io_type) {
  4071. case Digiface:
  4072. hdsp->card_name = "RME Hammerfall DSP + Digiface";
  4073. hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
  4074. hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
  4075. break;
  4076. case H9652:
  4077. hdsp->card_name = "RME Hammerfall HDSP 9652";
  4078. hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
  4079. hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
  4080. break;
  4081. case H9632:
  4082. status = hdsp_read(hdsp, HDSP_statusRegister);
  4083. /* HDSP_AEBx bits are low when AEB are connected */
  4084. aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
  4085. aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
  4086. hdsp->card_name = "RME Hammerfall HDSP 9632";
  4087. hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
  4088. hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
  4089. hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
  4090. hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
  4091. hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
  4092. hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
  4093. break;
  4094. case Multiface:
  4095. hdsp->card_name = "RME Hammerfall DSP + Multiface";
  4096. hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
  4097. hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
  4098. break;
  4099. default:
  4100. /* should never get here */
  4101. break;
  4102. }
  4103. }
  4104. static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
  4105. {
  4106. snd_hdsp_flush_midi_input (hdsp, 0);
  4107. snd_hdsp_flush_midi_input (hdsp, 1);
  4108. }
  4109. static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
  4110. {
  4111. int err;
  4112. if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
  4113. snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
  4114. return err;
  4115. }
  4116. if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
  4117. snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
  4118. return err;
  4119. }
  4120. if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
  4121. if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
  4122. snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
  4123. return err;
  4124. }
  4125. }
  4126. if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
  4127. snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
  4128. return err;
  4129. }
  4130. snd_hdsp_proc_init(hdsp);
  4131. hdsp->system_sample_rate = -1;
  4132. hdsp->playback_pid = -1;
  4133. hdsp->capture_pid = -1;
  4134. hdsp->capture_substream = NULL;
  4135. hdsp->playback_substream = NULL;
  4136. if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
  4137. snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
  4138. return err;
  4139. }
  4140. if (!(hdsp->state & HDSP_InitializationComplete)) {
  4141. strcpy(card->shortname, "Hammerfall DSP");
  4142. sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
  4143. hdsp->port, hdsp->irq);
  4144. if ((err = snd_card_register(card)) < 0) {
  4145. snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
  4146. return err;
  4147. }
  4148. hdsp->state |= HDSP_InitializationComplete;
  4149. }
  4150. return 0;
  4151. }
  4152. #ifdef HDSP_FW_LOADER
  4153. /* load firmware via hotplug fw loader */
  4154. static int __devinit hdsp_request_fw_loader(struct hdsp *hdsp)
  4155. {
  4156. const char *fwfile;
  4157. const struct firmware *fw;
  4158. int err;
  4159. if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
  4160. return 0;
  4161. if (hdsp->io_type == Undefined) {
  4162. if ((err = hdsp_get_iobox_version(hdsp)) < 0)
  4163. return err;
  4164. if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
  4165. return 0;
  4166. }
  4167. /* caution: max length of firmware filename is 30! */
  4168. switch (hdsp->io_type) {
  4169. case Multiface:
  4170. if (hdsp->firmware_rev == 0xa)
  4171. fwfile = "multiface_firmware.bin";
  4172. else
  4173. fwfile = "multiface_firmware_rev11.bin";
  4174. break;
  4175. case Digiface:
  4176. if (hdsp->firmware_rev == 0xa)
  4177. fwfile = "digiface_firmware.bin";
  4178. else
  4179. fwfile = "digiface_firmware_rev11.bin";
  4180. break;
  4181. default:
  4182. snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
  4183. return -EINVAL;
  4184. }
  4185. if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
  4186. snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile);
  4187. return -ENOENT;
  4188. }
  4189. if (fw->size < sizeof(hdsp->firmware_cache)) {
  4190. snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n",
  4191. (int)fw->size, (int)sizeof(hdsp->firmware_cache));
  4192. release_firmware(fw);
  4193. return -EINVAL;
  4194. }
  4195. memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
  4196. release_firmware(fw);
  4197. hdsp->state |= HDSP_FirmwareCached;
  4198. if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
  4199. return err;
  4200. if (!(hdsp->state & HDSP_InitializationComplete)) {
  4201. if ((err = snd_hdsp_enable_io(hdsp)) < 0)
  4202. return err;
  4203. if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
  4204. snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
  4205. return err;
  4206. }
  4207. snd_hdsp_initialize_channels(hdsp);
  4208. snd_hdsp_initialize_midi_flush(hdsp);
  4209. if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
  4210. snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
  4211. return err;
  4212. }
  4213. }
  4214. return 0;
  4215. }
  4216. #endif
  4217. static int __devinit snd_hdsp_create(struct snd_card *card,
  4218. struct hdsp *hdsp)
  4219. {
  4220. struct pci_dev *pci = hdsp->pci;
  4221. int err;
  4222. int is_9652 = 0;
  4223. int is_9632 = 0;
  4224. hdsp->irq = -1;
  4225. hdsp->state = 0;
  4226. hdsp->midi[0].rmidi = NULL;
  4227. hdsp->midi[1].rmidi = NULL;
  4228. hdsp->midi[0].input = NULL;
  4229. hdsp->midi[1].input = NULL;
  4230. hdsp->midi[0].output = NULL;
  4231. hdsp->midi[1].output = NULL;
  4232. hdsp->midi[0].pending = 0;
  4233. hdsp->midi[1].pending = 0;
  4234. spin_lock_init(&hdsp->midi[0].lock);
  4235. spin_lock_init(&hdsp->midi[1].lock);
  4236. hdsp->iobase = NULL;
  4237. hdsp->control_register = 0;
  4238. hdsp->control2_register = 0;
  4239. hdsp->io_type = Undefined;
  4240. hdsp->max_channels = 26;
  4241. hdsp->card = card;
  4242. spin_lock_init(&hdsp->lock);
  4243. tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
  4244. pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
  4245. hdsp->firmware_rev &= 0xff;
  4246. /* From Martin Bjoernsen :
  4247. "It is important that the card's latency timer register in
  4248. the PCI configuration space is set to a value much larger
  4249. than 0 by the computer's BIOS or the driver.
  4250. The windows driver always sets this 8 bit register [...]
  4251. to its maximum 255 to avoid problems with some computers."
  4252. */
  4253. pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
  4254. strcpy(card->driver, "H-DSP");
  4255. strcpy(card->mixername, "Xilinx FPGA");
  4256. if (hdsp->firmware_rev < 0xa)
  4257. return -ENODEV;
  4258. else if (hdsp->firmware_rev < 0x64)
  4259. hdsp->card_name = "RME Hammerfall DSP";
  4260. else if (hdsp->firmware_rev < 0x96) {
  4261. hdsp->card_name = "RME HDSP 9652";
  4262. is_9652 = 1;
  4263. } else {
  4264. hdsp->card_name = "RME HDSP 9632";
  4265. hdsp->max_channels = 16;
  4266. is_9632 = 1;
  4267. }
  4268. if ((err = pci_enable_device(pci)) < 0)
  4269. return err;
  4270. pci_set_master(hdsp->pci);
  4271. if ((err = pci_request_regions(pci, "hdsp")) < 0)
  4272. return err;
  4273. hdsp->port = pci_resource_start(pci, 0);
  4274. if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
  4275. snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
  4276. return -EBUSY;
  4277. }
  4278. if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
  4279. "hdsp", hdsp)) {
  4280. snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
  4281. return -EBUSY;
  4282. }
  4283. hdsp->irq = pci->irq;
  4284. hdsp->precise_ptr = 0;
  4285. hdsp->use_midi_tasklet = 1;
  4286. hdsp->dds_value = 0;
  4287. if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
  4288. return err;
  4289. if (!is_9652 && !is_9632) {
  4290. /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
  4291. ssleep(2);
  4292. if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
  4293. #ifdef HDSP_FW_LOADER
  4294. if ((err = hdsp_request_fw_loader(hdsp)) < 0)
  4295. /* we don't fail as this can happen
  4296. if userspace is not ready for
  4297. firmware upload
  4298. */
  4299. snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
  4300. else
  4301. /* init is complete, we return */
  4302. return 0;
  4303. #endif
  4304. /* no iobox connected, we defer initialization */
  4305. snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
  4306. if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
  4307. return err;
  4308. return 0;
  4309. } else {
  4310. snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
  4311. if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
  4312. hdsp->io_type = Multiface;
  4313. else
  4314. hdsp->io_type = Digiface;
  4315. }
  4316. }
  4317. if ((err = snd_hdsp_enable_io(hdsp)) != 0)
  4318. return err;
  4319. if (is_9652)
  4320. hdsp->io_type = H9652;
  4321. if (is_9632)
  4322. hdsp->io_type = H9632;
  4323. if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
  4324. return err;
  4325. snd_hdsp_initialize_channels(hdsp);
  4326. snd_hdsp_initialize_midi_flush(hdsp);
  4327. hdsp->state |= HDSP_FirmwareLoaded;
  4328. if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
  4329. return err;
  4330. return 0;
  4331. }
  4332. static int snd_hdsp_free(struct hdsp *hdsp)
  4333. {
  4334. if (hdsp->port) {
  4335. /* stop the audio, and cancel all interrupts */
  4336. tasklet_kill(&hdsp->midi_tasklet);
  4337. hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
  4338. hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
  4339. }
  4340. if (hdsp->irq >= 0)
  4341. free_irq(hdsp->irq, (void *)hdsp);
  4342. snd_hdsp_free_buffers(hdsp);
  4343. if (hdsp->iobase)
  4344. iounmap(hdsp->iobase);
  4345. if (hdsp->port)
  4346. pci_release_regions(hdsp->pci);
  4347. pci_disable_device(hdsp->pci);
  4348. return 0;
  4349. }
  4350. static void snd_hdsp_card_free(struct snd_card *card)
  4351. {
  4352. struct hdsp *hdsp = (struct hdsp *) card->private_data;
  4353. if (hdsp)
  4354. snd_hdsp_free(hdsp);
  4355. }
  4356. static int __devinit snd_hdsp_probe(struct pci_dev *pci,
  4357. const struct pci_device_id *pci_id)
  4358. {
  4359. static int dev;
  4360. struct hdsp *hdsp;
  4361. struct snd_card *card;
  4362. int err;
  4363. if (dev >= SNDRV_CARDS)
  4364. return -ENODEV;
  4365. if (!enable[dev]) {
  4366. dev++;
  4367. return -ENOENT;
  4368. }
  4369. if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct hdsp))))
  4370. return -ENOMEM;
  4371. hdsp = (struct hdsp *) card->private_data;
  4372. card->private_free = snd_hdsp_card_free;
  4373. hdsp->dev = dev;
  4374. hdsp->pci = pci;
  4375. snd_card_set_dev(card, &pci->dev);
  4376. if ((err = snd_hdsp_create(card, hdsp)) < 0) {
  4377. snd_card_free(card);
  4378. return err;
  4379. }
  4380. strcpy(card->shortname, "Hammerfall DSP");
  4381. sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
  4382. hdsp->port, hdsp->irq);
  4383. if ((err = snd_card_register(card)) < 0) {
  4384. snd_card_free(card);
  4385. return err;
  4386. }
  4387. pci_set_drvdata(pci, card);
  4388. dev++;
  4389. return 0;
  4390. }
  4391. static void __devexit snd_hdsp_remove(struct pci_dev *pci)
  4392. {
  4393. snd_card_free(pci_get_drvdata(pci));
  4394. pci_set_drvdata(pci, NULL);
  4395. }
  4396. static struct pci_driver driver = {
  4397. .name = "RME Hammerfall DSP",
  4398. .id_table = snd_hdsp_ids,
  4399. .probe = snd_hdsp_probe,
  4400. .remove = __devexit_p(snd_hdsp_remove),
  4401. };
  4402. static int __init alsa_card_hdsp_init(void)
  4403. {
  4404. return pci_register_driver(&driver);
  4405. }
  4406. static void __exit alsa_card_hdsp_exit(void)
  4407. {
  4408. pci_unregister_driver(&driver);
  4409. }
  4410. module_init(alsa_card_hdsp_init)
  4411. module_exit(alsa_card_hdsp_exit)