12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935
#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/moduleparam.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/hwdep.h>
#include <uapi/sound/scarlett2.h>
#include "usbaudio.h"
#include "mixer.h"
#include "helper.h"
#include "mixer_scarlett2.h"
#include "fcp.h"
#define SCARLETT2_MSD_ENABLE 0x02
#define SCARLETT2_DISABLE 0x04
#define SCARLETT2_USE_FCP_DRIVER 0x08
#define SCARLETT2_VOLUME_BIAS 127
#define SCARLETT2_MAX_GAIN_VALUE 70
#define SCARLETT2_MAX_BLUETOOTH_VOLUME 30
#define SCARLETT2_MAX_FP_SLEEP_TIME 86400
#define SCARLETT2_MIXER_MIN_DB -80
#define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
#define SCARLETT2_MIXER_MAX_DB 12
#define SCARLETT2_MIXER_MAX_VALUE \
((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
#define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
16345, 17313, 18339, 19426, 20577, 21796, 23088, 24456, 25905,
27440, 29066, 30788, 32612
};
#define SCARLETT2_ANALOGUE_MAX 10
#define SCARLETT2_LEVEL_SWITCH_MAX 2
#define SCARLETT2_PAD_SWITCH_MAX 8
#define SCARLETT2_AIR_SWITCH_MAX 8
#define SCARLETT2_DSP_SWITCH_MAX 2
#define SCARLETT2_INPUT_MUTE_SWITCH_MAX 2
#define SCARLETT2_PHANTOM_SWITCH_MAX 2
#define SCARLETT2_INPUT_GAIN_MAX 2
#define SCARLETT2_INPUT_MIX_MAX 25
#define SCARLETT2_OUTPUT_MIX_MAX 12
#define SCARLETT2_MIX_MAX (SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX)
#define SCARLETT2_MONITOR_MIX_MAX (2 * 2 * 4)
#define SCARLETT2_MUX_MAX 77
#define SCARLETT2_MAX_SRCS 52
#define SCARLETT2_MAX_METERS 65
struct compressor_param {
const char *name;
snd_ctl_elem_type_t type;
s32 min;
s32 max;
int scale_bits;
};
static const struct compressor_param compressor_params[] = {
{ "Enable", SNDRV_CTL_ELEM_TYPE_BOOLEAN, 0, 1, 0 },
{ "Threshold", SNDRV_CTL_ELEM_TYPE_INTEGER, -40, 0, 24 },
{ "Ratio", SNDRV_CTL_ELEM_TYPE_INTEGER, 2, 100, 23 },
{ "Knee Width", SNDRV_CTL_ELEM_TYPE_INTEGER, 0, 10, 24 },
{ "Attack", SNDRV_CTL_ELEM_TYPE_INTEGER, 30, 127, 24 },
{ "Release", SNDRV_CTL_ELEM_TYPE_INTEGER, 30, 127, 24 },
{ "Makeup Gain", SNDRV_CTL_ELEM_TYPE_INTEGER, 0, 24, 24 },
};
#define SCARLETT2_COMPRESSOR_PARAM_COUNT ARRAY_SIZE(compressor_params)
#define SCARLETT2_COMPRESSOR_CTLS_MAX \
(SCARLETT2_COMPRESSOR_PARAM_COUNT * SCARLETT2_DSP_SWITCH_MAX)
#define SCARLETT2_PRECOMP_FLT_CTLS_MAX (2 * SCARLETT2_DSP_SWITCH_MAX)
#define SCARLETT2_PEQ_FLT_CTLS_MAX (3 * SCARLETT2_DSP_SWITCH_MAX)
#define SCARLETT2_BIQUAD_COEFFS 5
#define SCARLETT2_PRECOMP_FLT_VALUES_MAX \
(SCARLETT2_PRECOMP_FLT_CTLS_MAX * SCARLETT2_BIQUAD_COEFFS)
#define SCARLETT2_PEQ_FLT_VALUES_MAX \
(SCARLETT2_PEQ_FLT_CTLS_MAX * SCARLETT2_BIQUAD_COEFFS)
#define SCARLETT2_PEQ_FLT_SLOTS_MAX 4
enum {
SCARLETT2_PORT_TYPE_NONE,
SCARLETT2_PORT_TYPE_ANALOGUE,
SCARLETT2_PORT_TYPE_SPDIF,
SCARLETT2_PORT_TYPE_ADAT,
SCARLETT2_PORT_TYPE_MIX,
SCARLETT2_PORT_TYPE_PCM,
SCARLETT2_PORT_TYPE_COUNT
};
enum {
SCARLETT2_PORT_IN,
SCARLETT2_PORT_OUT,
SCARLETT2_PORT_DIRNS
};
enum {
SCARLETT2_BUTTON_MUTE,
SCARLETT2_BUTTON_DIM,
SCARLETT2_DIM_MUTE_COUNT
};
#define SCARLETT2_AG_TARGET_MIN (-30)
enum {
SCARLETT2_AG_HOT_TARGET,
SCARLETT2_AG_MEAN_TARGET,
SCARLETT2_AG_PEAK_TARGET,
SCARLETT2_AG_TARGET_COUNT
};
enum {
SCARLETT2_FLASH_WRITE_STATE_IDLE,
SCARLETT2_FLASH_WRITE_STATE_SELECTED,
SCARLETT2_FLASH_WRITE_STATE_ERASING,
SCARLETT2_FLASH_WRITE_STATE_WRITE
};
static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
"Mute Playback Switch", "Dim Playback Switch"
};
static const char *const vocaster_one_sp_hp_mute_names[] = {
"Speaker Mute Playback Switch",
"Headphones Mute Playback Switch",
NULL
};
static const char *const vocaster_two_sp_hp_mute_names[] = {
"Speaker Mute Playback Switch",
"Headphones 1 Mute Playback Switch",
"Headphones 2 Mute Playback Switch",
NULL
};
static const char *const scarlett2_autogain_status_gen4[] = {
"Running",
"Success",
"SuccessDRover",
"WarnMinGainLimit",
"FailDRunder",
"FailMaxGainLimit",
"FailClipped",
"Cancelled",
"Root",
"Invalid",
NULL
};
static const char *const scarlett2_autogain_status_vocaster[] = {
"Running",
"Success",
"FailPG",
"FailRange",
"WarnMaxCap",
"WarnMinCap",
"Cancelled",
"Invalid",
NULL
};
enum {
SCARLETT2_POWER_STATUS_EXT,
SCARLETT2_POWER_STATUS_BUS,
SCARLETT2_POWER_STATUS_FAIL,
SCARLETT2_POWER_STATUS_COUNT
};
struct scarlett2_notification {
u32 mask;
void (*func)(struct usb_mixer_interface *mixer);
};
static void scarlett2_notify_ack(struct usb_mixer_interface *mixer);
static void scarlett2_notify_sync(struct usb_mixer_interface *mixer);
static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_volume(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_dsp(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_mute(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_select(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_gain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_autogain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_safe(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_power_status(struct usb_mixer_interface *mixer);
static void scarlett2_notify_pcm_input_switch(
struct usb_mixer_interface *mixer);
static void scarlett2_notify_bluetooth(struct usb_mixer_interface *mixer);
static const struct scarlett2_notification scarlett2_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_dim_mute },
{ 0x00400000, scarlett2_notify_monitor },
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_monitor_other },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett3a_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0, NULL }
};
static const struct scarlett2_notification vocaster_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_mute },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x04000000, scarlett2_notify_input_dsp },
{ 0x08000000, scarlett2_notify_input_gain },
{ 0x10000000, scarlett2_notify_input_phantom },
{ 0x20000000, scarlett2_notify_bluetooth },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_solo_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00000008, scarlett2_notify_sync },
{ 0x00400000, scarlett2_notify_input_air },
{ 0x00800000, scarlett2_notify_direct_monitor },
{ 0x01000000, scarlett2_notify_input_level },
{ 0x02000000, scarlett2_notify_input_phantom },
{ 0x04000000, scarlett2_notify_pcm_input_switch },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_2i2_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0x02000000, scarlett2_notify_input_select },
{ 0x04000000, scarlett2_notify_input_level },
{ 0x08000000, scarlett2_notify_input_phantom },
{ 0x10000000, NULL },
{ 0x40000000, scarlett2_notify_input_gain },
{ 0x80000000, NULL },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_4i4_notifications[] = {
{ 0x00000001, scarlett2_notify_ack },
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_input_select },
{ 0x02000000, scarlett2_notify_input_level },
{ 0x04000000, scarlett2_notify_input_phantom },
{ 0x08000000, scarlett2_notify_power_status },
{ 0x20000000, scarlett2_notify_input_gain },
{ 0x40000000, scarlett2_notify_power_status },
{ 0x80000000, scarlett2_notify_volume },
{ 0, NULL }
};
enum {
SCARLETT2_CONFIG_DIM_MUTE,
SCARLETT2_CONFIG_LINE_OUT_VOLUME,
SCARLETT2_CONFIG_MUTE_SWITCH,
SCARLETT2_CONFIG_SW_HW_SWITCH,
SCARLETT2_CONFIG_MASTER_VOLUME,
SCARLETT2_CONFIG_HEADPHONE_VOLUME,
SCARLETT2_CONFIG_LEVEL_SWITCH,
SCARLETT2_CONFIG_PAD_SWITCH,
SCARLETT2_CONFIG_MSD_SWITCH,
SCARLETT2_CONFIG_AIR_SWITCH,
SCARLETT2_CONFIG_DSP_SWITCH,
SCARLETT2_CONFIG_COMPRESSOR_PARAMS,
SCARLETT2_CONFIG_PRECOMP_FLT_SWITCH,
SCARLETT2_CONFIG_PRECOMP_FLT_PARAMS,
SCARLETT2_CONFIG_PEQ_FLT_SWITCH,
SCARLETT2_CONFIG_PEQ_FLT_PARAMS,
SCARLETT2_CONFIG_INPUT_MUTE_SWITCH,
SCARLETT2_CONFIG_STANDALONE_SWITCH,
SCARLETT2_CONFIG_PHANTOM_SWITCH,
SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
SCARLETT2_CONFIG_DIRECT_MONITOR,
SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
SCARLETT2_CONFIG_TALKBACK_MAP,
SCARLETT2_CONFIG_AUTOGAIN_SWITCH,
SCARLETT2_CONFIG_AUTOGAIN_STATUS,
SCARLETT2_CONFIG_AG_HOT_TARGET,
SCARLETT2_CONFIG_AG_MEAN_TARGET,
SCARLETT2_CONFIG_AG_PEAK_TARGET,
SCARLETT2_CONFIG_INPUT_GAIN,
SCARLETT2_CONFIG_SAFE_SWITCH,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH,
SCARLETT2_CONFIG_POWER_EXT,
SCARLETT2_CONFIG_POWER_LOW,
SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
SCARLETT2_CONFIG_BLUETOOTH_VOLUME,
SCARLETT2_CONFIG_SPDIF_MODE,
SCARLETT2_CONFIG_SP_HP_MUTE,
SCARLETT2_CONFIG_FP_BRIGHTNESS,
SCARLETT2_CONFIG_FP_SLEEP_TIME,
SCARLETT2_CONFIG_COUNT
};
static const int scarlett2_ag_target_configs[] = {
[SCARLETT2_AG_HOT_TARGET] = SCARLETT2_CONFIG_AG_HOT_TARGET,
[SCARLETT2_AG_MEAN_TARGET] = SCARLETT2_CONFIG_AG_MEAN_TARGET,
[SCARLETT2_AG_PEAK_TARGET] = SCARLETT2_CONFIG_AG_PEAK_TARGET
};
static const char *const scarlett2_ag_target_names[] = {
"Hot", "Mean", "Peak"
};
struct scarlett2_config {
u16 offset;
u8 size;
u8 activate;
u8 pbuf;
u8 mute;
};
struct scarlett2_config_set {
const struct scarlett2_notification *notifications;
u16 param_buf_addr;
const unsigned int *input_gain_tlv;
const char *const *autogain_status_texts;
const struct scarlett2_config items[SCARLETT2_CONFIG_COUNT];
};
struct scarlett2_config_set_entry {
u16 from_firmware_version;
const struct scarlett2_config_set *config_set;
};
static const DECLARE_TLV_DB_MINMAX(
db_scale_vocaster_gain, 0, 70 * 100
);
static const DECLARE_TLV_DB_MINMAX(
db_scale_gen4_gain, 0, 69 * 100
);
static const struct scarlett2_config_set scarlett2_config_set_gen2a = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen2b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen3a = {
.notifications = scarlett3a_notifications,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x04, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x05, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x06, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x07, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x08, .size = 1, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x09, .size = 1, .activate = 8 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen3b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen3c = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
.offset = 0x9f, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
.offset = 0xa0, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_TALKBACK_MAP] = {
.offset = 0xb0, .size = 16, .activate = 10 },
[SCARLETT2_CONFIG_SPDIF_MODE] = {
.offset = 0x94, .size = 8, .activate = 6 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_vocaster = {
.notifications = vocaster_notifications,
.param_buf_addr = 0x1bc,
.input_gain_tlv = db_scale_vocaster_gain,
.autogain_status_texts = scarlett2_autogain_status_vocaster,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x1c0, .size = 8, .activate = 19, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x1c2, .size = 8, },
[SCARLETT2_CONFIG_AG_HOT_TARGET] = {
.offset = 0xc1, .size = 8, .activate = 29, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x9f, .size = 8, .activate = 21, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 20, .pbuf = 1 },
[SCARLETT2_CONFIG_DSP_SWITCH] = {
.offset = 0x1c4, .size = 8, .activate = 22, .pbuf = 1 },
[SCARLETT2_CONFIG_COMPRESSOR_PARAMS] = {
.offset = 0x1c8, .size = 32, .activate = 23 },
[SCARLETT2_CONFIG_PRECOMP_FLT_SWITCH] = {
.offset = 0x7c, .size = 32, .activate = 27 },
[SCARLETT2_CONFIG_PRECOMP_FLT_PARAMS] = {
.offset = 0x200, .size = 32, .activate = 27 },
[SCARLETT2_CONFIG_PEQ_FLT_SWITCH] = {
.offset = 0x84, .size = 32, .activate = 27 },
[SCARLETT2_CONFIG_PEQ_FLT_PARAMS] = {
.offset = 0x250, .size = 32, .activate = 27 },
[SCARLETT2_CONFIG_INPUT_MUTE_SWITCH] = {
.offset = 0x1be, .size = 8, .activate = 17, .pbuf = 1 },
[SCARLETT2_CONFIG_BLUETOOTH_VOLUME] = {
.offset = 0xbf, .size = 8, .activate = 28 },
[SCARLETT2_CONFIG_SP_HP_MUTE] = {
.offset = 0xab, .size = 8, .activate = 10 },
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_solo = {
.notifications = scarlett4_solo_notifications,
.param_buf_addr = 0xd8,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x47, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x108, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x46, .size = 8, .activate = 9, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3d, .size = 8, .activate = 10, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .size = 8, .activate = 11, .pbuf = 1 },
[SCARLETT2_CONFIG_PCM_INPUT_SWITCH] = {
.offset = 0x206, .size = 8, .activate = 25, .pbuf = 1 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x232, .size = 16, .activate = 26 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_solo_2417 = {
.notifications = scarlett4_solo_notifications,
.param_buf_addr = 0xd8,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x47, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x108, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x46, .size = 8, .activate = 9, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3d, .size = 8, .activate = 10, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .size = 8, .activate = 11, .pbuf = 1 },
[SCARLETT2_CONFIG_PCM_INPUT_SWITCH] = {
.offset = 0x206, .size = 8, .activate = 25, .pbuf = 1 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x232, .size = 16, .activate = 26 },
[SCARLETT2_CONFIG_FP_BRIGHTNESS] = {
.offset = 0x243, .size = 8, .activate = 27, .pbuf = 1 },
[SCARLETT2_CONFIG_FP_SLEEP_TIME] = {
.offset = 0x248, .size = 32, .activate = 29 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_2i2 = {
.notifications = scarlett4_2i2_notifications,
.param_buf_addr = 0xfc,
.input_gain_tlv = db_scale_gen4_gain,
.autogain_status_texts = scarlett2_autogain_status_gen4,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x49, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x14a, .size = 8, .activate = 16, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x135, .size = 8, .activate = 10, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x137, .size = 8 },
[SCARLETT2_CONFIG_AG_MEAN_TARGET] = {
.offset = 0x131, .size = 8, .activate = 29, .pbuf = 1 },
[SCARLETT2_CONFIG_AG_PEAK_TARGET] = {
.offset = 0x132, .size = 8, .activate = 30, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x48, .size = 8, .activate = 11, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x4b, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3c, .size = 8, .activate = 13, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x147, .size = 8, .activate = 14, .pbuf = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .size = 8, .activate = 15, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x14b, .size = 8, .activate = 17, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x14e, .size = 8, .activate = 18, .pbuf = 1 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x2a0, .size = 16, .activate = 36 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_2i2_2417 = {
.notifications = scarlett4_2i2_notifications,
.param_buf_addr = 0xfc,
.input_gain_tlv = db_scale_gen4_gain,
.autogain_status_texts = scarlett2_autogain_status_gen4,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x49, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x14a, .size = 8, .activate = 16, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x135, .size = 8, .activate = 10, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x137, .size = 8 },
[SCARLETT2_CONFIG_AG_MEAN_TARGET] = {
.offset = 0x131, .size = 8, .activate = 29, .pbuf = 1 },
[SCARLETT2_CONFIG_AG_PEAK_TARGET] = {
.offset = 0x132, .size = 8, .activate = 30, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x48, .size = 8, .activate = 11, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x4b, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3c, .size = 8, .activate = 13, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x147, .size = 8, .activate = 14, .pbuf = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .size = 8, .activate = 15, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x14b, .size = 8, .activate = 17, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x14e, .size = 8, .activate = 18, .pbuf = 1 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x2a4, .size = 16, .activate = 36 },
[SCARLETT2_CONFIG_FP_BRIGHTNESS] = {
.offset = 0x2c7, .size = 8, .activate = 37, .pbuf = 1 },
[SCARLETT2_CONFIG_FP_SLEEP_TIME] = {
.offset = 0x2cc, .size = 32, .activate = 39 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_4i4 = {
.notifications = scarlett4_4i4_notifications,
.param_buf_addr = 0x130,
.input_gain_tlv = db_scale_gen4_gain,
.autogain_status_texts = scarlett2_autogain_status_gen4,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x13e, .size = 8, .activate = 10, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x140, .size = 8 },
[SCARLETT2_CONFIG_AG_MEAN_TARGET] = {
.offset = 0x13a, .size = 8, .activate = 23, .pbuf = 1 },
[SCARLETT2_CONFIG_AG_PEAK_TARGET] = {
.offset = 0x13b, .size = 8, .activate = 24, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x5a, .size = 8, .activate = 11, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x5e, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x4e, .size = 8, .activate = 13, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x150, .size = 8, .activate = 14, .pbuf = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x50, .size = 8, .activate = 15, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x153, .size = 8, .activate = 16, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x156, .size = 8, .activate = 17, .pbuf = 1 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x32, .size = 16 },
[SCARLETT2_CONFIG_HEADPHONE_VOLUME] = {
.offset = 0x3a, .size = 16 },
[SCARLETT2_CONFIG_POWER_EXT] = {
.offset = 0x168, .size = 8 },
[SCARLETT2_CONFIG_POWER_LOW] = {
.offset = 0x16d, .size = 8 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_gen4_4i4_2417 = {
.notifications = scarlett4_4i4_notifications,
.param_buf_addr = 0x130,
.input_gain_tlv = db_scale_gen4_gain,
.autogain_status_texts = scarlett2_autogain_status_gen4,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x13e, .size = 8, .activate = 10, .pbuf = 1 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x140, .size = 8 },
[SCARLETT2_CONFIG_AG_MEAN_TARGET] = {
.offset = 0x13a, .size = 8, .activate = 23, .pbuf = 1 },
[SCARLETT2_CONFIG_AG_PEAK_TARGET] = {
.offset = 0x13b, .size = 8, .activate = 24, .pbuf = 1 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x5a, .size = 8, .activate = 11, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x5e, .size = 8, .activate = 12, .pbuf = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x4e, .size = 8, .activate = 13, .pbuf = 1,
.mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x150, .size = 8, .activate = 14, .pbuf = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x50, .size = 8, .activate = 15, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x153, .size = 8, .activate = 16, .pbuf = 1 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x156, .size = 8, .activate = 17, .pbuf = 1 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x32, .size = 16 },
[SCARLETT2_CONFIG_HEADPHONE_VOLUME] = {
.offset = 0x3a, .size = 16 },
[SCARLETT2_CONFIG_POWER_EXT] = {
.offset = 0x168, .size = 8 },
[SCARLETT2_CONFIG_POWER_LOW] = {
.offset = 0x16d, .size = 8 },
[SCARLETT2_CONFIG_FP_BRIGHTNESS] = {
.offset = 0x3a9, .size = 8, .activate = 36, .pbuf = 1 },
[SCARLETT2_CONFIG_FP_SLEEP_TIME] = {
.offset = 0x3ac, .size = 32, .activate = 38 }
}
};
static const struct scarlett2_config_set scarlett2_config_set_clarett = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_SPDIF_MODE] = {
.offset = 0x9e, .size = 8, .activate = 4 },
}
};
struct scarlett2_port {
u16 id;
const char * const src_descr;
int src_num_offset;
const char * const dst_descr;
const char * const dsp_src_descr;
const char * const dsp_dst_descr;
};
static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
[SCARLETT2_PORT_TYPE_NONE] = {
.id = 0x000,
.src_descr = "Off"
},
[SCARLETT2_PORT_TYPE_ANALOGUE] = {
.id = 0x080,
.src_descr = "Analogue %d",
.src_num_offset = 1,
.dst_descr = "Analogue Output %02d Playback"
},
[SCARLETT2_PORT_TYPE_SPDIF] = {
.id = 0x180,
.src_descr = "S/PDIF %d",
.src_num_offset = 1,
.dst_descr = "S/PDIF Output %d Playback"
},
[SCARLETT2_PORT_TYPE_ADAT] = {
.id = 0x200,
.src_descr = "ADAT %d",
.src_num_offset = 1,
.dst_descr = "ADAT Output %d Playback"
},
[SCARLETT2_PORT_TYPE_MIX] = {
.id = 0x300,
.src_descr = "Mix %c",
.src_num_offset = 'A',
.dst_descr = "Mixer Input %02d Capture",
.dsp_src_descr = "DSP %d",
.dsp_dst_descr = "DSP Input %d Capture"
},
[SCARLETT2_PORT_TYPE_PCM] = {
.id = 0x600,
.src_descr = "PCM %d",
.src_num_offset = 1,
.dst_descr = "PCM %02d Capture"
},
};
#define SCARLETT2_MUX_TABLES 3
#define SCARLETT2_MAX_MUX_ENTRIES 10
struct scarlett2_mux_entry {
u8 port_type;
u8 start;
u8 count;
};
#define SCARLETT2_MAX_METER_ENTRIES 9
struct scarlett2_meter_entry {
u8 start;
u8 count;
};
struct scarlett2_device_info {
const struct scarlett2_config_set_entry *config_sets;
u8 has_devmap;
u8 has_speaker_switching;
u8 has_talkback;
u8 level_input_count;
u8 level_input_first;
u8 pad_input_count;
u8 air_input_count;
u8 air_input_first;
u8 air_option;
u8 dsp_input_count;
u8 precomp_flt_count;
u8 peq_flt_count;
u8 peq_flt_total_count;
u8 mute_input_count;
u8 phantom_count;
u8 phantom_first;
u8 inputs_per_phantom;
u8 gain_input_count;
u8 safe_input_count;
u8 direct_monitor;
u8 dsp_count;
u8 has_bluetooth;
const char * const spdif_mode_control_name;
const u8 *spdif_mode_values;
const char * const *spdif_mode_texts;
u8 line_out_remap_enable;
u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
u8 line_out_unmap[SCARLETT2_ANALOGUE_MAX];
const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
const char * const *sp_hp_mute_names;
const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
[SCARLETT2_MAX_MUX_ENTRIES];
struct scarlett2_meter_entry meter_map[SCARLETT2_MAX_METER_ENTRIES];
};
struct scarlett2_data {
struct usb_mixer_interface *mixer;
struct mutex usb_mutex;
struct completion cmd_done;
struct urb *urb;
struct mutex data_mutex;
u8 running;
u8 hwdep_in_use;
u8 selected_flash_segment_id;
u8 flash_write_state;
struct delayed_work work;
const struct scarlett2_device_info *info;
const struct scarlett2_config_set *config_set;
const char *series_name;
__u8 bInterfaceNumber;
__u8 bEndpointAddress;
__u16 wMaxPacketSize;
__u8 bInterval;
u8 num_mux_srcs;
u8 num_mux_dsts;
u8 num_mix_in;
u8 num_mix_out;
u8 num_line_out;
u8 num_monitor_mix_ctls;
u8 num_autogain_status_texts;
u32 firmware_version;
u8 flash_segment_nums[SCARLETT2_SEGMENT_ID_COUNT];
u8 flash_segment_blocks[SCARLETT2_SEGMENT_ID_COUNT];
u16 scarlett2_seq;
u8 sync_updated;
u8 vol_updated;
u8 dim_mute_updated;
u8 input_level_updated;
u8 input_pad_updated;
u8 input_air_updated;
u8 input_dsp_updated;
u8 input_mute_updated;
u8 input_phantom_updated;
u8 input_select_updated;
u8 input_gain_updated;
u8 autogain_updated;
u8 input_safe_updated;
u8 pcm_input_switch_updated;
u8 monitor_other_updated;
u8 direct_monitor_updated;
u8 mux_updated;
u8 mix_updated;
u8 speaker_switching_switched;
u8 power_status_updated;
u8 bluetooth_updated;
u8 sync;
u8 master_vol;
u8 headphone_vol;
u8 vol[SCARLETT2_ANALOGUE_MAX];
u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
u8 sp_hp_mute;
u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
u8 dsp_switch[SCARLETT2_DSP_SWITCH_MAX];
s32 compressor_values[SCARLETT2_COMPRESSOR_CTLS_MAX];
s32 precomp_flt_values[SCARLETT2_PRECOMP_FLT_VALUES_MAX];
s32 peq_flt_values[SCARLETT2_PEQ_FLT_VALUES_MAX];
u8 precomp_flt_switch[SCARLETT2_DSP_SWITCH_MAX];
u8 peq_flt_switch[SCARLETT2_DSP_SWITCH_MAX];
u8 input_mute_switch[SCARLETT2_INPUT_MUTE_SWITCH_MAX];
u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
u8 phantom_persistence;
u8 input_select_switch;
u8 input_link_switch[SCARLETT2_INPUT_GAIN_MAX];
u8 gain[SCARLETT2_INPUT_GAIN_MAX];
u8 autogain_switch[SCARLETT2_INPUT_GAIN_MAX];
u8 autogain_status[SCARLETT2_INPUT_GAIN_MAX];
s8 ag_targets[SCARLETT2_AG_TARGET_COUNT];
u8 safe_switch[SCARLETT2_INPUT_GAIN_MAX];
u8 pcm_input_switch;
u8 direct_monitor_switch;
u8 speaker_switching_switch;
u8 talkback_switch;
u8 talkback_map[SCARLETT2_OUTPUT_MIX_MAX];
u8 msd_switch;
u8 standalone_switch;
u8 power_status;
u8 bluetooth_volume;
u8 spdif_mode;
u8 meter_level_map[SCARLETT2_MAX_METERS];
struct snd_kcontrol *sync_ctl;
struct snd_kcontrol *master_vol_ctl;
struct snd_kcontrol *headphone_vol_ctl;
struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *sw_hw_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *mute_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *dim_mute_ctls[SCARLETT2_DIM_MUTE_COUNT];
struct snd_kcontrol *level_ctls[SCARLETT2_LEVEL_SWITCH_MAX];
struct snd_kcontrol *pad_ctls[SCARLETT2_PAD_SWITCH_MAX];
struct snd_kcontrol *air_ctls[SCARLETT2_AIR_SWITCH_MAX];
struct snd_kcontrol *dsp_ctls[SCARLETT2_DSP_SWITCH_MAX];
struct snd_kcontrol *input_mute_ctls[SCARLETT2_INPUT_MUTE_SWITCH_MAX];
struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX];
struct snd_kcontrol *input_select_ctl;
struct snd_kcontrol *input_link_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *input_gain_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *autogain_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *autogain_status_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *ag_target_ctls[SCARLETT2_AG_TARGET_COUNT];
struct snd_kcontrol *safe_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *pcm_input_switch_ctl;
struct snd_kcontrol *mux_ctls[SCARLETT2_MUX_MAX];
struct snd_kcontrol *mix_ctls[SCARLETT2_MIX_MAX];
struct snd_kcontrol *compressor_ctls[SCARLETT2_COMPRESSOR_CTLS_MAX];
struct snd_kcontrol *precomp_flt_switch_ctls[SCARLETT2_DSP_SWITCH_MAX];
struct snd_kcontrol *peq_flt_switch_ctls[SCARLETT2_DSP_SWITCH_MAX];
struct snd_kcontrol *direct_monitor_ctl;
struct snd_kcontrol *speaker_switching_ctl;
struct snd_kcontrol *talkback_ctl;
struct snd_kcontrol *power_status_ctl;
struct snd_kcontrol *bluetooth_volume_ctl;
u8 fp_brightness;
u32 fp_sleep_time;
u8 mux[SCARLETT2_MUX_MAX];
u8 mix[SCARLETT2_MIX_MAX];
u8 monitor_mix[SCARLETT2_MONITOR_MIX_MAX];
};
static const struct scarlett2_device_info s6i6_gen2_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen2a },
{ }
},
.level_input_count = 2,
.pad_input_count = 2,
.line_out_descrs = {
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 24, 6 },
{ 0, 24 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s18i8_gen2_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen2a },
{ }
},
.level_input_count = 2,
.pad_input_count = 4,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 4 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 26, 18 },
{ 0, 26 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s18i20_gen2_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen2b },
{ }
},
.line_out_descrs = {
"Monitor L",
"Monitor R",
NULL,
NULL,
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 6 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 38, 18 },
{ 0, 38 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info solo_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3a },
{ }
},
.level_input_count = 1,
.level_input_first = 1,
.air_input_count = 1,
.phantom_count = 1,
.inputs_per_phantom = 1,
.direct_monitor = 1,
};
static const struct scarlett2_device_info s2i2_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3a },
{ }
},
.level_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.direct_monitor = 2,
};
static const struct scarlett2_device_info s4i4_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3b },
{ }
},
.level_input_count = 2,
.pad_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones L",
"Headphones R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
[SCARLETT2_PORT_TYPE_MIX] = { 6, 8 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 12, 6 },
{ 0, 12 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s8i6_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3b },
{ }
},
.level_input_count = 2,
.pad_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.line_out_descrs = {
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 8 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 10 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 14, 8 },
{ 0, 6 },
{ 22, 2 },
{ 6, 8 },
{ 0, 0 },
}
};
static const u8 scarlett2_spdif_s18i8_gen3_values[] = { 0, 2, 0xff };
static const char * const scarlett2_spdif_s18i8_gen3_texts[] = {
"RCA",
"Optical",
NULL
};
static const struct scarlett2_device_info s18i8_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3c },
{ }
},
.has_speaker_switching = 1,
.level_input_count = 2,
.pad_input_count = 4,
.air_input_count = 4,
.phantom_count = 2,
.inputs_per_phantom = 2,
.spdif_mode_control_name = "S/PDIF Mode Capture Enum",
.spdif_mode_values = scarlett2_spdif_s18i8_gen3_values,
.spdif_mode_texts = scarlett2_spdif_s18i8_gen3_texts,
.line_out_remap_enable = 1,
.line_out_remap = { 0, 1, 6, 7, 2, 3, 4, 5 },
.line_out_unmap = { 0, 1, 4, 5, 6, 7, 2, 3 },
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Alt Monitor L",
"Alt Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 8 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 20 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 20 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_PCM, 12, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_PCM, 12, 4 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 30, 10 },
{ 42, 8 },
{ 0, 2 },
{ 6, 2 },
{ 2, 4 },
{ 8, 2 },
{ 40, 2 },
{ 10, 20 },
{ 0, 0 }
}
};
static const u8 scarlett2_spdif_s18i20_gen3_values[] = { 0, 6, 1, 0xff };
static const char * const scarlett2_spdif_s18i20_gen3_texts[] = {
"S/PDIF RCA",
"S/PDIF Optical",
"Dual ADAT",
NULL
};
static const struct scarlett2_device_info s18i20_gen3_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_gen3c },
{ }
},
.has_speaker_switching = 1,
.has_talkback = 1,
.level_input_count = 2,
.pad_input_count = 8,
.air_input_count = 8,
.phantom_count = 2,
.inputs_per_phantom = 4,
.spdif_mode_control_name = "Digital I/O Mode Capture Enum",
.spdif_mode_values = scarlett2_spdif_s18i20_gen3_values,
.spdif_mode_texts = scarlett2_spdif_s18i20_gen3_texts,
.line_out_descrs = {
"Monitor 1 L",
"Monitor 1 R",
"Monitor 2 L",
"Monitor 2 R",
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 9, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 12, 25 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 20 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 25 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 12 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 25 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 24 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 45, 8 },
{ 55, 10 },
{ 0, 20 },
{ 53, 2 },
{ 20, 25 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info vocaster_one_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 1769, &scarlett2_config_set_vocaster },
{ }
},
.has_devmap = 1,
.phantom_count = 1,
.inputs_per_phantom = 1,
.dsp_count = 1,
.dsp_input_count = 1,
.precomp_flt_count = 2,
.peq_flt_count = 3,
.peq_flt_total_count = 4,
.mute_input_count = 1,
.gain_input_count = 1,
.sp_hp_mute_names = vocaster_one_sp_hp_mute_names,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 4 },
[SCARLETT2_PORT_TYPE_MIX] = { 9, 9 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 10 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 8, 1 },
{ SCARLETT2_PORT_TYPE_PCM, 5, 5 },
{ SCARLETT2_PORT_TYPE_MIX, 6, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 5 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 12, 1 },
{ 18, 5 },
{ 10, 2 },
{ 13, 5 },
{ 4, 6 },
{ 0, 4 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info vocaster_two_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 1769, &scarlett2_config_set_vocaster },
{ }
},
.has_devmap = 1,
.phantom_count = 2,
.inputs_per_phantom = 1,
.dsp_count = 2,
.dsp_input_count = 2,
.precomp_flt_count = 2,
.peq_flt_count = 3,
.peq_flt_total_count = 4,
.mute_input_count = 2,
.gain_input_count = 2,
.has_bluetooth = 1,
.sp_hp_mute_names = vocaster_two_sp_hp_mute_names,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 6 },
[SCARLETT2_PORT_TYPE_MIX] = { 12, 14 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 14 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 12, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 6, 8 },
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 18, 2 },
{ 26, 8 },
{ 16, 2 },
{ 20, 6 },
{ 6, 10 },
{ 0, 6 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info solo_gen4_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 2115, &scarlett2_config_set_gen4_solo },
{ 2417, &scarlett2_config_set_gen4_solo_2417 },
{ }
},
.has_devmap = 1,
.level_input_count = 1,
.air_input_count = 1,
.air_input_first = 1,
.air_option = 1,
.phantom_count = 1,
.phantom_first = 1,
.inputs_per_phantom = 1,
.direct_monitor = 1,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 6 },
[SCARLETT2_PORT_TYPE_PCM] = { 2, 4 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 6, 2 },
{ 4, 2 },
{ 8, 4 },
{ 2, 2 },
{ 0, 2 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info s2i2_gen4_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 2115, &scarlett2_config_set_gen4_2i2 },
{ 2417, &scarlett2_config_set_gen4_2i2_2417 },
{ }
},
.has_devmap = 1,
.level_input_count = 2,
.air_input_count = 2,
.air_option = 1,
.phantom_count = 1,
.inputs_per_phantom = 2,
.gain_input_count = 2,
.safe_input_count = 2,
.direct_monitor = 2,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 6, 6 },
[SCARLETT2_PORT_TYPE_PCM] = { 2, 4 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 6, 2 },
{ 4, 2 },
{ 8, 4 },
{ 2, 2 },
{ 0, 2 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info s4i4_gen4_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 2089, &scarlett2_config_set_gen4_4i4 },
{ 2417, &scarlett2_config_set_gen4_4i4_2417 },
{ }
},
.has_devmap = 1,
.level_input_count = 2,
.air_input_count = 2,
.air_option = 1,
.phantom_count = 2,
.inputs_per_phantom = 1,
.gain_input_count = 2,
.safe_input_count = 2,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 6 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 12 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 16, 8 },
{ 6, 10 },
{ 0, 6 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info clarett_2pre_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_clarett },
{ }
},
.level_input_count = 2,
.air_input_count = 2,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones L",
"Headphones R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 0 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 12 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 26 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 22, 12 },
{ 0, 22 },
{ 0, 0 }
}
};
static const u8 scarlett2_spdif_clarett_values[] = { 0, 1, 2, 0xff };
static const char * const scarlett2_spdif_clarett_texts[] = {
"None",
"Optical",
"RCA",
NULL
};
static const struct scarlett2_device_info clarett_4pre_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_clarett },
{ }
},
.level_input_count = 2,
.air_input_count = 4,
.spdif_mode_control_name = "S/PDIF Source Capture Enum",
.spdif_mode_values = scarlett2_spdif_clarett_values,
.spdif_mode_texts = scarlett2_spdif_clarett_texts,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 24 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 26, 18 },
{ 0, 26 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info clarett_8pre_info = {
.config_sets = (const struct scarlett2_config_set_entry[]) {
{ 0, &scarlett2_config_set_clarett },
{ }
},
.level_input_count = 2,
.air_input_count = 8,
.spdif_mode_control_name = "S/PDIF Source Capture Enum",
.spdif_mode_values = scarlett2_spdif_clarett_values,
.spdif_mode_texts = scarlett2_spdif_clarett_texts,
.line_out_descrs = {
"Monitor L",
"Monitor R",
NULL,
NULL,
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 22 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 38, 18 },
{ 0, 38 },
{ 0, 0 }
}
};
struct scarlett2_device_entry {
const u32 usb_id;
const struct scarlett2_device_info *info;
const char *series_name;
};
static const struct scarlett2_device_entry scarlett2_devices[] = {
{ USB_ID(0x1235, 0x8203), &s6i6_gen2_info, "Scarlett Gen 2" },
{ USB_ID(0x1235, 0x8204), &s18i8_gen2_info, "Scarlett Gen 2" },
{ USB_ID(0x1235, 0x8201), &s18i20_gen2_info, "Scarlett Gen 2" },
{ USB_ID(0x1235, 0x8211), &solo_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8210), &s2i2_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8212), &s4i4_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8213), &s8i6_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8214), &s18i8_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8215), &s18i20_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8216), &vocaster_one_info, "Vocaster" },
{ USB_ID(0x1235, 0x8217), &vocaster_two_info, "Vocaster" },
{ USB_ID(0x1235, 0x8218), &solo_gen4_info, "Scarlett Gen 4" },
{ USB_ID(0x1235, 0x8219), &s2i2_gen4_info, "Scarlett Gen 4" },
{ USB_ID(0x1235, 0x821a), &s4i4_gen4_info, "Scarlett Gen 4" },
{ USB_ID(0x1235, 0x8206), &clarett_2pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x8207), &clarett_4pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x8208), &clarett_8pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x820a), &clarett_2pre_info, "Clarett+" },
{ USB_ID(0x1235, 0x820b), &clarett_4pre_info, "Clarett+" },
{ USB_ID(0x1235, 0x820c), &clarett_8pre_info, "Clarett+" },
{ 0, NULL, NULL },
};
static int scarlett2_get_port_start_num(
const int port_count[][SCARLETT2_PORT_DIRNS],
int direction, int port_type)
{
int i, num = 0;
for (i = 0; i < port_type; i++)
num += port_count[i][direction];
return num;
}
#define SCARLETT2_USB_CMD_INIT 0
#define SCARLETT2_USB_CMD_REQ 2
#define SCARLETT2_USB_CMD_RESP 3
#define SCARLETT2_USB_INIT_1 0x00000000
#define SCARLETT2_USB_INIT_2 0x00000002
#define SCARLETT2_USB_REBOOT 0x00000003
#define SCARLETT2_USB_GET_METER 0x00001001
#define SCARLETT2_USB_GET_MIX 0x00002001
#define SCARLETT2_USB_SET_MIX 0x00002002
#define SCARLETT2_USB_GET_MUX 0x00003001
#define SCARLETT2_USB_SET_MUX 0x00003002
#define SCARLETT2_USB_INFO_FLASH 0x00004000
#define SCARLETT2_USB_INFO_SEGMENT 0x00004001
#define SCARLETT2_USB_ERASE_SEGMENT 0x00004002
#define SCARLETT2_USB_GET_ERASE 0x00004003
#define SCARLETT2_USB_WRITE_SEGMENT 0x00004004
#define SCARLETT2_USB_READ_SEGMENT 0x00004005
#define SCARLETT2_USB_GET_SYNC 0x00006004
#define SCARLETT2_USB_GET_DATA 0x00800000
#define SCARLETT2_USB_SET_DATA 0x00800001
#define SCARLETT2_USB_DATA_CMD 0x00800002
#define SCARLETT2_USB_INFO_DEVMAP 0x0080000c
#define SCARLETT2_USB_GET_DEVMAP 0x0080000d
#define SCARLETT2_USB_CONFIG_SAVE 6
#define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
#define SCARLETT2_FLASH_BLOCK_SIZE 4096
#define SCARLETT2_FLASH_RW_MAX 1024
#define SCARLETT2_SEGMENT_NUM_MIN 1
#define SCARLETT2_SEGMENT_NUM_MAX 4
#define SCARLETT2_SEGMENT_SETTINGS_NAME "App_Settings"
#define SCARLETT2_SEGMENT_FIRMWARE_NAME "App_Upgrade"
#define SCARLETT2_DEVMAP_BLOCK_SIZE 1024
#define SCARLETT2_DEVMAP_FILENAME "device-map.json.zz.b64"
struct scarlett2_usb_packet {
__le32 cmd;
__le16 size;
__le16 seq;
__le32 error;
__le32 pad;
u8 data[];
};
static void scarlett2_fill_request_header(struct scarlett2_data *private,
struct scarlett2_usb_packet *req,
u32 cmd, u16 req_size)
{
u16 seq = private->scarlett2_seq++;
req->cmd = cpu_to_le32(cmd);
req->size = cpu_to_le16(req_size);
req->seq = cpu_to_le16(seq);
req->error = 0;
req->pad = 0;
}
static int scarlett2_usb_tx(struct usb_device *dev, int interface,
void *buf, u16 size)
{
return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
SCARLETT2_USB_CMD_REQ,
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
0, interface, buf, size);
}
static int scarlett2_usb_rx(struct usb_device *dev, int interface,
u32 usb_req, void *buf, u16 size)
{
return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
usb_req,
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
0, interface, buf, size);
}
static int scarlett2_usb_nopm(struct usb_mixer_interface *mixer, u32 cmd,
void *req_data, u16 req_size,
void *resp_data, u16 resp_size)
{
struct scarlett2_data *private = mixer->private_data;
struct usb_device *dev = mixer->chip->dev;
int retries = 0;
const int max_retries = 5;
int err;
struct scarlett2_usb_packet *req __free(kfree) = NULL;
size_t req_buf_size = struct_size(req, data, req_size);
req = kmalloc_flex(*req, data, req_size);
if (!req)
return -ENOMEM;
struct scarlett2_usb_packet *resp __free(kfree) = NULL;
size_t resp_buf_size = struct_size(resp, data, resp_size);
resp = kmalloc_flex(*resp, data, resp_size);
if (!resp)
return -ENOMEM;
guard(mutex)(&private->usb_mutex);
scarlett2_fill_request_header(private, req, cmd, req_size);
if (req_size)
memcpy(req->data, req_data, req_size);
retry:
err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
req, req_buf_size);
if (err != req_buf_size) {
if (err == -EPROTO && ++retries <= max_retries) {
msleep(5 * (1 << (retries - 1)));
goto retry;
}
usb_audio_err(
mixer->chip,
"%s USB request result cmd %x was %d\n",
private->series_name, cmd, err);
return -EINVAL;
}
if (!wait_for_completion_timeout(&private->cmd_done,
msecs_to_jiffies(1000))) {
usb_audio_err(
mixer->chip,
"%s USB request timed out, cmd %x\n",
private->series_name, cmd);
return -ETIMEDOUT;
}
err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
SCARLETT2_USB_CMD_RESP,
resp, resp_buf_size);
if (err != resp_buf_size) {
if (cmd == SCARLETT2_USB_REBOOT &&
(err == -ESHUTDOWN || err == -EPROTO))
return 0;
usb_audio_err(
mixer->chip,
"%s USB response result cmd %x was %d expected %zu\n",
private->series_name, cmd, err, resp_buf_size);
return -EINVAL;
}
if (resp->cmd != req->cmd ||
(resp->seq != req->seq &&
(le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
resp_size != le16_to_cpu(resp->size) ||
resp->error ||
resp->pad) {
usb_audio_err(
mixer->chip,
"%s USB invalid response; "
"cmd tx/rx %d/%d seq %d/%d size %d/%d "
"error %d pad %d\n",
private->series_name,
le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
resp_size, le16_to_cpu(resp->size),
le32_to_cpu(resp->error),
le32_to_cpu(resp->pad));
return -EINVAL;
}
if (resp_data && resp_size > 0)
memcpy(resp_data, resp->data, resp_size);
return err;
}
static int scarlett2_usb(struct usb_mixer_interface *mixer, u32 cmd,
void *req_data, u16 req_size,
void *resp_data, u16 resp_size)
{
CLASS(snd_usb_lock, pm)(mixer->chip);
if (pm.err < 0)
return -EIO;
return scarlett2_usb_nopm(mixer, cmd, req_data, req_size,
resp_data, resp_size);
}
static int scarlett2_usb_get(
struct usb_mixer_interface *mixer,
int offset, void *buf, int size)
{
struct {
__le32 offset;
__le32 size;
} __packed req;
req.offset = cpu_to_le32(offset);
req.size = cpu_to_le32(size);
return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
&req, sizeof(req), buf, size);
}
static int scarlett2_has_config_item(
struct scarlett2_data *private, int config_item_num)
{
return !!private->config_set->items[config_item_num].offset;
}
static int scarlett2_usb_get_config(
struct usb_mixer_interface *mixer,
int config_item_num, int count, void *buf)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config *config_item =
&private->config_set->items[config_item_num];
int size, err, i;
u8 *buf_8;
u8 value;
if (!config_item->offset)
return -EFAULT;
size = config_item->size ? config_item->size : 8;
if (size >= 8) {
size = size / 8 * count;
err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
if (err < 0)
return err;
if (config_item->size == 16) {
u16 *buf_16 = buf;
for (i = 0; i < count; i++, buf_16++)
*buf_16 = le16_to_cpu(*(__le16 *)buf_16);
} else if (config_item->size == 32) {
u32 *buf_32 = (u32 *)buf;
for (i = 0; i < count; i++, buf_32++)
*buf_32 = le32_to_cpu(*(__le32 *)buf_32);
}
return 0;
}
err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
if (err < 0)
return err;
buf_8 = buf;
for (i = 0; i < 8 && i < count; i++, value >>= 1)
*buf_8++ = value & 1;
return 0;
}
static int scarlett2_usb_set_data(
struct usb_mixer_interface *mixer,
int offset, int size, int value)
{
struct scarlett2_data *private = mixer->private_data;
struct {
__le32 offset;
__le32 size;
__le32 value;
} __packed req;
req.offset = cpu_to_le32(offset);
req.size = cpu_to_le32(size);
req.value = cpu_to_le32(value);
return scarlett2_usb(private->mixer, SCARLETT2_USB_SET_DATA,
&req, sizeof(u32) * 2 + size, NULL, 0);
}
static int scarlett2_usb_set_data_buf(
struct usb_mixer_interface *mixer,
int offset, int size, int count, void *buf)
{
struct scarlett2_data *private = mixer->private_data;
int bytes = size * count;
struct {
__le32 offset;
__le32 size;
u8 data[];
} __packed *req;
int err;
size_t buf_size = struct_size(req, data, bytes);
req = kmalloc_flex(*req, data, bytes);
if (!req)
return -ENOMEM;
req->offset = cpu_to_le32(offset);
req->size = cpu_to_le32(bytes);
if (size == 1) {
memcpy(req->data, buf, count);
} else if (size == 2) {
u16 *buf_16 = buf;
int i;
for (i = 0; i < count; i++)
((__le16 *)req->data)[i] = cpu_to_le16(buf_16[i]);
} else {
u32 *buf_32 = buf;
int i;
for (i = 0; i < count; i++)
((__le32 *)req->data)[i] = cpu_to_le32(buf_32[i]);
}
err = scarlett2_usb(private->mixer, SCARLETT2_USB_SET_DATA,
req, buf_size, NULL, 0);
kfree(req);
return err;
}
static int scarlett2_usb_activate_config(
struct usb_mixer_interface *mixer, int activate)
{
__le32 req;
req = cpu_to_le32(activate);
return scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
&req, sizeof(req), NULL, 0);
}
static int scarlett2_usb_set_config(
struct usb_mixer_interface *mixer,
int config_item_num, int index, int value)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config_set *config_set = private->config_set;
const struct scarlett2_config *config_item =
&config_set->items[config_item_num];
int offset, size;
int err;
if (!config_item->offset)
return -EFAULT;
if (config_item->pbuf) {
if (!config_set->param_buf_addr)
return -EFAULT;
err = scarlett2_usb_set_data(
mixer, config_set->param_buf_addr + 1, 1, index);
if (err < 0)
return err;
err = scarlett2_usb_set_data(
mixer, config_set->param_buf_addr, 1, value);
if (err < 0)
return err;
return scarlett2_usb_activate_config(
mixer, config_item->activate);
}
cancel_delayed_work_sync(&private->work);
if (config_item->size >= 8) {
size = config_item->size / 8;
offset = config_item->offset + index * size;
} else {
u8 tmp;
size = 1;
offset = config_item->offset;
err = scarlett2_usb_get(mixer, offset, &tmp, 1);
if (err < 0)
return err;
if (value)
tmp |= (1 << index);
else
tmp &= ~(1 << index);
value = tmp;
}
err = scarlett2_usb_set_data(mixer, offset, size, value);
if (err < 0)
return err;
err = scarlett2_usb_activate_config(mixer, config_item->activate);
if (err < 0)
return err;
if (config_set->param_buf_addr)
return 0;
if (config_item->activate != SCARLETT2_USB_CONFIG_SAVE)
schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
return 0;
}
static int scarlett2_usb_set_config_buf(
struct usb_mixer_interface *mixer,
int config_item_num, int index, int count, void *buf)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config_set *config_set = private->config_set;
const struct scarlett2_config *config_item =
&config_set->items[config_item_num];
int offset, size;
int err;
if (!config_item->offset)
return -EFAULT;
if (config_item->size >= 8) {
size = config_item->size / 8;
offset = config_item->offset + index * size;
} else {
return -EFAULT;
}
err = scarlett2_usb_set_data_buf(mixer, offset, size, count, buf);
if (err < 0)
return err;
return scarlett2_usb_activate_config(mixer, config_item->activate);
}
static void scarlett2_config_save(struct usb_mixer_interface *mixer)
{
__le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
int err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
&req, sizeof(req), NULL, 0);
if (err < 0)
usb_audio_err(mixer->chip, "config save failed: %d\n", err);
}
static void scarlett2_config_save_nopm(struct usb_mixer_interface *mixer)
{
__le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
int err = scarlett2_usb_nopm(mixer, SCARLETT2_USB_DATA_CMD,
&req, sizeof(req), NULL, 0);
if (err < 0)
usb_audio_err(mixer->chip, "config save failed: %d\n", err);
}
static void scarlett2_config_save_work(struct work_struct *work)
{
struct scarlett2_data *private =
container_of(work, struct scarlett2_data, work.work);
scarlett2_config_save(private->mixer);
}
static int scarlett2_usb_get_sync_status(
struct usb_mixer_interface *mixer,
u8 *sync)
{
__le32 data;
int err;
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_SYNC,
NULL, 0, &data, sizeof(data));
if (err < 0)
return err;
*sync = !!data;
return 0;
}
static int scarlett2_has_mixer(struct scarlett2_data *private)
{
return !!private->info->mux_assignment[0][0].count;
}
static int scarlett2_mixer_value_to_db(int value)
{
int i;
for (i = 0; i < SCARLETT2_MIXER_VALUE_COUNT; i++)
if (scarlett2_mixer_values[i] >= value)
return i;
return SCARLETT2_MIXER_MAX_VALUE;
}
static int scarlett2_usb_get_mix(struct usb_mixer_interface *mixer,
int mix_num)
{
struct scarlett2_data *private = mixer->private_data;
int num_mixer_in = private->num_mix_in;
int err, i, j;
struct {
__le16 mix_num;
__le16 count;
} __packed req;
__le16 data[SCARLETT2_INPUT_MIX_MAX];
req.mix_num = cpu_to_le16(mix_num);
req.count = cpu_to_le16(num_mixer_in);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MIX,
&req, sizeof(req),
data, num_mixer_in * sizeof(u16));
if (err < 0)
return err;
for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
private->mix[j] = scarlett2_mixer_value_to_db(
le16_to_cpu(data[i]));
return 0;
}
static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
int mix_num)
{
struct scarlett2_data *private = mixer->private_data;
struct {
__le16 mix_num;
__le16 data[SCARLETT2_INPUT_MIX_MAX];
} __packed req;
int i, j;
int num_mixer_in = private->num_mix_in;
req.mix_num = cpu_to_le16(mix_num);
for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
req.data[i] = cpu_to_le16(
scarlett2_mixer_values[private->mix[j]]
);
return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
&req, (num_mixer_in + 1) * sizeof(u16),
NULL, 0);
}
static u32 scarlett2_mux_src_num_to_id(
const int port_count[][SCARLETT2_PORT_DIRNS], int num)
{
int port_type;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
if (num < port_count[port_type][SCARLETT2_PORT_IN])
return scarlett2_ports[port_type].id | num;
num -= port_count[port_type][SCARLETT2_PORT_IN];
}
return 0;
}
static u32 scarlett2_mux_id_to_num(
const int port_count[][SCARLETT2_PORT_DIRNS], int direction, u32 id)
{
int port_type;
int port_num = 0;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
int base = scarlett2_ports[port_type].id;
int count = port_count[port_type][direction];
if (id >= base && id < base + count)
return port_num + id - base;
port_num += count;
}
return -1;
}
static void scarlett2_usb_populate_mux(struct scarlett2_data *private,
u32 mux_entry)
{
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int dst_idx, src_idx;
dst_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_OUT,
mux_entry & 0xFFF);
if (dst_idx < 0)
return;
if (dst_idx >= private->num_mux_dsts) {
usb_audio_err(private->mixer->chip,
"BUG: scarlett2_mux_id_to_num(%06x, OUT): %d >= %d",
mux_entry, dst_idx, private->num_mux_dsts);
return;
}
src_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_IN,
mux_entry >> 12);
if (src_idx < 0)
return;
if (src_idx >= private->num_mux_srcs) {
usb_audio_err(private->mixer->chip,
"BUG: scarlett2_mux_id_to_num(%06x, IN): %d >= %d",
mux_entry, src_idx, private->num_mux_srcs);
return;
}
private->mux[dst_idx] = src_idx;
}
static void scarlett2_update_meter_level_map(struct scarlett2_data *private)
{
const struct scarlett2_device_info *info = private->info;
const struct scarlett2_meter_entry *entry;
u8 seen_src[SCARLETT2_MAX_SRCS] = { 1 };
u8 seen_src_value[SCARLETT2_MAX_SRCS] = { 255 };
int i = 0;
for (entry = info->meter_map;
entry->count;
entry++) {
int j, mux_idx;
for (j = 0, mux_idx = entry->start;
j < entry->count;
i++, j++, mux_idx++) {
int map_mux_idx = (
info->line_out_remap_enable &&
mux_idx < private->num_line_out
) ? info->line_out_unmap[mux_idx]
: mux_idx;
int mux_src = private->mux[mux_idx];
if (!seen_src[mux_src]) {
seen_src[mux_src] = 1;
seen_src_value[mux_src] = i;
}
private->meter_level_map[map_mux_idx] =
seen_src_value[mux_src];
}
}
}
static int scarlett2_usb_get_mux(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int count = private->num_mux_dsts;
int err, i;
struct {
__le16 num;
__le16 count;
} __packed req;
__le32 data[SCARLETT2_MUX_MAX];
private->mux_updated = 0;
req.num = 0;
req.count = cpu_to_le16(count);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MUX,
&req, sizeof(req),
data, count * sizeof(u32));
if (err < 0)
return err;
for (i = 0; i < count; i++)
scarlett2_usb_populate_mux(private, le32_to_cpu(data[i]));
scarlett2_update_meter_level_map(private);
return 0;
}
static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int table;
struct {
__le16 pad;
__le16 num;
__le32 data[SCARLETT2_MUX_MAX];
} __packed req;
req.pad = 0;
for (table = 0; table < SCARLETT2_MUX_TABLES; table++) {
const struct scarlett2_mux_entry *entry;
int i = 0, err;
req.num = cpu_to_le16(table);
for (entry = info->mux_assignment[table];
entry->count;
entry++) {
int j;
int port_type = entry->port_type;
int port_idx = entry->start;
int mux_idx = scarlett2_get_port_start_num(port_count,
SCARLETT2_PORT_OUT, port_type) + port_idx;
int dst_id = scarlett2_ports[port_type].id + port_idx;
if (!dst_id) {
for (j = 0; j < entry->count; j++)
req.data[i++] = 0;
continue;
}
for (j = 0; j < entry->count; j++) {
int src_id = scarlett2_mux_src_num_to_id(
port_count, private->mux[mux_idx++]);
req.data[i++] = cpu_to_le32(dst_id |
src_id << 12);
dst_id++;
}
}
err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
&req, (i + 1) * sizeof(u32),
NULL, 0);
if (err < 0)
return err;
}
scarlett2_update_meter_level_map(private);
return 0;
}
static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
u16 num_meters, u16 *levels)
{
struct {
__le16 pad;
__le16 num_meters;
__le32 magic;
} __packed req;
__le32 resp[SCARLETT2_MAX_METERS];
int i, err;
req.pad = 0;
req.num_meters = cpu_to_le16(num_meters);
req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER,
&req, sizeof(req), resp, num_meters * sizeof(u32));
if (err < 0)
return err;
for (i = 0; i < num_meters; i++)
levels[i] = le32_to_cpu(resp[i]);
return 0;
}
static uint8_t scarlett2_decode_muteable(uint8_t v)
{
return (v ^ (v >> 1)) & 1;
}
static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
const struct snd_kcontrol_new *ncontrol,
int index, int channels, const char *name,
struct snd_kcontrol **kctl_return)
{
struct snd_kcontrol *kctl;
struct usb_mixer_elem_info *elem;
int err;
elem = kzalloc_obj(*elem);
if (!elem)
return -ENOMEM;
elem->head.mixer = mixer;
elem->control = index;
elem->head.id = 0;
elem->channels = channels;
elem->val_type = USB_MIXER_BESPOKEN;
kctl = snd_ctl_new1(ncontrol, elem);
if (!kctl) {
kfree(elem);
return -ENOMEM;
}
kctl->private_free = snd_usb_mixer_elem_free;
strscpy(kctl->id.name, name, sizeof(kctl->id.name));
err = snd_usb_mixer_add_control(&elem->head, kctl);
if (err < 0)
return err;
if (kctl_return)
*kctl_return = kctl;
return 0;
}
static int scarlett2_firmware_version_ctl_get(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->firmware_version;
return 0;
}
static int scarlett2_firmware_version_ctl_info(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_firmware_version_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_firmware_version_ctl_info,
.get = scarlett2_firmware_version_ctl_get
};
static int scarlett2_add_firmware_version_ctl(
struct usb_mixer_interface *mixer)
{
return scarlett2_add_new_ctl(mixer, &scarlett2_firmware_version_ctl,
0, 0, "Firmware Version", NULL);
}
static int scarlett2_min_firmware_version_ctl_get(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] =
private->info->config_sets[0].from_firmware_version;
return 0;
}
static int scarlett2_min_firmware_version_ctl_info(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_min_firmware_version_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_min_firmware_version_ctl_info,
.get = scarlett2_min_firmware_version_ctl_get
};
static int scarlett2_add_min_firmware_version_ctl(
struct usb_mixer_interface *mixer)
{
return scarlett2_add_new_ctl(mixer, &scarlett2_min_firmware_version_ctl,
0, 0, "Minimum Firmware Version", NULL);
}
static int scarlett2_update_sync(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
private->sync_updated = 0;
return scarlett2_usb_get_sync_status(mixer, &private->sync);
}
static int scarlett2_sync_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
static const char *texts[2] = {
"Unlocked", "Locked"
};
return snd_ctl_enum_info(uinfo, 1, 2, texts);
}
static int scarlett2_sync_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->sync_updated) {
err = scarlett2_update_sync(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->sync;
return 0;
}
static const struct snd_kcontrol_new scarlett2_sync_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_sync_ctl_info,
.get = scarlett2_sync_ctl_get
};
static int scarlett2_add_sync_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!scarlett2_has_mixer(private))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
0, 1, "Sync Status", &private->sync_ctl);
}
static int scarlett2_check_input_phantom_updated(struct usb_mixer_interface *);
static int scarlett2_phantom_is_switching(struct scarlett2_data *, int);
static void scarlett2_set_ctl_access(struct snd_kcontrol *kctl, int val)
{
if (val)
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
else
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
}
static int scarlett2_autogain_is_running(struct scarlett2_data *private)
{
int i;
for (i = 0; i < private->info->gain_input_count; i++)
if (!private->autogain_status[i])
return 1;
return 0;
}
static int scarlett2_update_autogain(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i;
u8 raw_autogain_status[SCARLETT2_INPUT_GAIN_MAX];
s8 ag_target_values[SCARLETT2_AG_TARGET_COUNT];
private->autogain_updated = 0;
if (!info->gain_input_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_AUTOGAIN_SWITCH,
info->gain_input_count, private->autogain_switch);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_AUTOGAIN_STATUS,
info->gain_input_count, raw_autogain_status);
if (err < 0)
return err;
for (i = 0; i < info->gain_input_count; i++)
if (private->autogain_switch[i])
private->autogain_status[i] = 0;
else if (raw_autogain_status[i] <
private->num_autogain_status_texts - 1)
private->autogain_status[i] =
raw_autogain_status[i] + 1;
else
private->autogain_status[i] =
private->num_autogain_status_texts - 1;
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
if (scarlett2_has_config_item(private,
scarlett2_ag_target_configs[i])) {
err = scarlett2_usb_get_config(
mixer, scarlett2_ag_target_configs[i],
1, &ag_target_values[i]);
if (err < 0)
return err;
}
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
private->ag_targets[i] = -ag_target_values[i];
return 0;
}
static void scarlett2_autogain_update_access(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int val = !scarlett2_autogain_is_running(private);
int i;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH))
scarlett2_set_ctl_access(private->input_select_ctl, val);
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH))
for (i = 0; i < info->gain_input_count; i++)
scarlett2_set_ctl_access(private->input_link_ctls[i],
val);
for (i = 0; i < info->gain_input_count; i++)
scarlett2_set_ctl_access(private->input_gain_ctls[i], val);
for (i = 0; i < info->safe_input_count; i++)
scarlett2_set_ctl_access(private->safe_ctls[i], val);
for (i = 0; i < info->level_input_count; i++)
scarlett2_set_ctl_access(private->level_ctls[i], val);
for (i = 0; i < info->air_input_count; i++)
scarlett2_set_ctl_access(private->air_ctls[i], val);
for (i = 0; i < info->mute_input_count; i++)
scarlett2_set_ctl_access(private->input_mute_ctls[i], val);
for (i = 0; i < info->phantom_count; i++)
scarlett2_set_ctl_access(private->phantom_ctls[i], val);
for (i = 0; i < info->dsp_input_count; i++)
scarlett2_set_ctl_access(private->dsp_ctls[i], val);
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
if (scarlett2_has_config_item(private,
scarlett2_ag_target_configs[i]))
scarlett2_set_ctl_access(
private->ag_target_ctls[i], val);
}
static void scarlett2_autogain_notify_access(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH))
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->input_select_ctl->id);
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH))
for (i = 0; i < info->gain_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->input_link_ctls[i]->id);
for (i = 0; i < info->gain_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->input_gain_ctls[i]->id);
for (i = 0; i < info->safe_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->safe_ctls[i]->id);
for (i = 0; i < info->level_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->level_ctls[i]->id);
for (i = 0; i < info->air_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->air_ctls[i]->id);
for (i = 0; i < info->dsp_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->dsp_ctls[i]->id);
for (i = 0; i < info->mute_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->input_mute_ctls[i]->id);
for (i = 0; i < info->phantom_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->phantom_ctls[i]->id);
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
if (scarlett2_has_config_item(private,
scarlett2_ag_target_configs[i]))
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->ag_target_ctls[i]->id);
}
static int scarlett2_check_autogain_updated(
struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
if (!private->autogain_updated)
return 0;
err = scarlett2_update_autogain(mixer);
if (err < 0)
return err;
scarlett2_autogain_update_access(mixer);
return 0;
}
static int scarlett2_check_put_during_autogain(
struct usb_mixer_interface *mixer)
{
int err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
if (scarlett2_autogain_is_running(mixer->private_data))
return -EPERM;
return 0;
}
static int scarlett2_autogain_switch_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
err = scarlett2_check_input_phantom_updated(mixer);
if (err < 0)
return err;
return snd_ctl_boolean_mono_info(kctl, uinfo);
}
static int scarlett2_autogain_switch_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
ucontrol->value.enumerated.item[0] =
private->autogain_switch[elem->control];
return 0;
}
static int scarlett2_autogain_status_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
ucontrol->value.enumerated.item[0] =
private->autogain_status[elem->control];
return 0;
}
static int scarlett2_autogain_switch_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_input_phantom_updated(mixer);
if (err < 0)
return err;
if (scarlett2_phantom_is_switching(private, index))
return -EPERM;
oval = private->autogain_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->autogain_switch[index] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_AUTOGAIN_SWITCH, index, val);
scarlett2_autogain_update_access(mixer);
scarlett2_autogain_notify_access(mixer);
return err < 0 ? err : 1;
}
static int scarlett2_autogain_status_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
return snd_ctl_enum_info(
uinfo, 1,
private->num_autogain_status_texts,
private->config_set->autogain_status_texts);
}
static const struct snd_kcontrol_new scarlett2_autogain_switch_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_switch_ctl_info,
.get = scarlett2_autogain_switch_ctl_get,
.put = scarlett2_autogain_switch_ctl_put
};
static const struct snd_kcontrol_new scarlett2_autogain_status_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_autogain_status_ctl_info,
.get = scarlett2_autogain_status_ctl_get,
};
static int scarlett2_ag_target_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = SCARLETT2_AG_TARGET_MIN;
uinfo->value.integer.max = 0;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_ag_target_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->autogain_updated) {
err = scarlett2_update_autogain(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->ag_targets[elem->control];
return 0;
}
static int scarlett2_ag_target_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->ag_targets[index];
val = clamp(ucontrol->value.integer.value[0],
(long)SCARLETT2_AG_TARGET_MIN, 0L);
if (oval == val)
return 0;
private->ag_targets[index] = val;
err = scarlett2_usb_set_config(
mixer, scarlett2_ag_target_configs[index], 1, -val);
return err < 0 ? err : 1;
}
static const DECLARE_TLV_DB_MINMAX(
db_scale_ag_target, SCARLETT2_AG_TARGET_MIN * 100, 0
);
static const struct snd_kcontrol_new scarlett2_ag_target_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_ag_target_ctl_info,
.get = scarlett2_ag_target_ctl_get,
.put = scarlett2_ag_target_ctl_put,
.tlv = { .p = db_scale_ag_target }
};
static int scarlett2_update_input_select(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int link_count = info->gain_input_count;
int err;
private->input_select_updated = 0;
if (!scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH) ||
!link_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
1, &private->input_select_switch);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_INPUT_LINK_SWITCH,
link_count, private->input_link_switch);
if (err < 0)
return err;
return 0;
}
static int scarlett2_input_select_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_select_updated) {
err = scarlett2_update_input_select(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->input_select_switch;
return 0;
}
static int scarlett2_input_select_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->input_select_switch;
val = ucontrol->value.integer.value[0];
if (val < 0)
val = 0;
else if (val >= info->gain_input_count)
val = info->gain_input_count - 1;
if (oval == val)
return 0;
private->input_select_switch = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
0, val);
return err < 0 ? err : 1;
}
static int scarlett2_input_select_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int inputs = private->info->gain_input_count;
int i, err;
char **values __free(kfree) =
kcalloc(inputs, sizeof(char *), GFP_KERNEL);
if (!values)
return -ENOMEM;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
for (i = 0; i < inputs; i++) {
values[i] = kasprintf(GFP_KERNEL, "Input %d", i + 1);
if (!values[i]) {
err = -ENOMEM;
goto clear;
}
}
err = snd_ctl_enum_info(uinfo, 1, i,
(const char * const *)values);
clear:
for (i = 0; i < inputs; i++)
kfree(values[i]);
return err;
}
static const struct snd_kcontrol_new scarlett2_input_select_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_input_select_ctl_info,
.get = scarlett2_input_select_ctl_get,
.put = scarlett2_input_select_ctl_put,
};
static int scarlett2_autogain_disables_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
return snd_ctl_boolean_mono_info(kctl, uinfo);
}
static int scarlett2_input_link_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_select_updated) {
err = scarlett2_update_input_select(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] =
private->input_link_switch[elem->control];
return 0;
}
static int scarlett2_input_link_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->input_link_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->input_link_switch[index] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_INPUT_LINK_SWITCH, index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_input_link_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_disables_ctl_info,
.get = scarlett2_input_link_ctl_get,
.put = scarlett2_input_link_ctl_put
};
static int scarlett2_update_input_gain(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_gain_updated = 0;
if (!info->gain_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_INPUT_GAIN,
info->gain_input_count, private->gain);
}
static int scarlett2_input_gain_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = elem->channels;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = SCARLETT2_MAX_GAIN_VALUE;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_input_gain_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_gain_updated) {
err = scarlett2_update_input_gain(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] =
private->gain[elem->control];
return 0;
}
static int scarlett2_input_gain_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->gain[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->gain[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_INPUT_GAIN,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_input_gain_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_input_gain_ctl_info,
.get = scarlett2_input_gain_ctl_get,
.put = scarlett2_input_gain_ctl_put,
.private_value = 0,
};
static int scarlett2_update_input_safe(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_safe_updated = 0;
if (!info->safe_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_SAFE_SWITCH,
info->safe_input_count, private->safe_switch);
}
static int scarlett2_safe_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_safe_updated) {
err = scarlett2_update_input_safe(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] =
private->safe_switch[elem->control];
return 0;
}
static int scarlett2_safe_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->safe_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->safe_switch[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SAFE_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_safe_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_disables_ctl_info,
.get = scarlett2_safe_ctl_get,
.put = scarlett2_safe_ctl_put,
};
static int scarlett2_update_pcm_input_switch(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
private->pcm_input_switch_updated = 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
1, &private->pcm_input_switch);
if (err < 0)
return err;
return 0;
}
static int scarlett2_pcm_input_switch_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = elem->head.mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->pcm_input_switch_updated) {
err = scarlett2_update_pcm_input_switch(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->pcm_input_switch;
return 0;
}
static int scarlett2_pcm_input_switch_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->pcm_input_switch;
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->pcm_input_switch = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
0, val);
return err < 0 ? err : 1;
}
static int scarlett2_pcm_input_switch_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[2] = {
"Direct", "Mixer"
};
return snd_ctl_enum_info(
uinfo, 1, 2, values);
}
static const struct snd_kcontrol_new scarlett2_pcm_input_switch_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_pcm_input_switch_ctl_info,
.get = scarlett2_pcm_input_switch_ctl_get,
.put = scarlett2_pcm_input_switch_ctl_put
};
static int scarlett2_update_volumes(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
s16 vol;
int err, i;
private->vol_updated = 0;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_MASTER_VOLUME)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_MASTER_VOLUME,
1, &vol);
if (err < 0)
return err;
private->master_vol = clamp(vol + SCARLETT2_VOLUME_BIAS,
0, SCARLETT2_VOLUME_BIAS);
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_SW_HW_SWITCH))
for (i = 0; i < private->num_line_out; i++)
if (private->vol_sw_hw_switch[i])
private->vol[i] = private->master_vol;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_HEADPHONE_VOLUME)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_HEADPHONE_VOLUME,
1, &vol);
if (err < 0)
return err;
private->headphone_vol = clamp(vol + SCARLETT2_VOLUME_BIAS,
0, SCARLETT2_VOLUME_BIAS);
}
return 0;
}
static int scarlett2_volume_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = elem->channels;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->vol_updated) {
err = scarlett2_update_volumes(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->master_vol;
return 0;
}
static int scarlett2_headphone_volume_ctl_get(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->vol_updated) {
err = scarlett2_update_volumes(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->headphone_vol;
return 0;
}
static int line_out_remap(struct scarlett2_data *private, int index)
{
const struct scarlett2_device_info *info = private->info;
if (!info->line_out_remap_enable)
return index;
if (index >= private->num_line_out)
return index;
return info->line_out_remap[index];
}
static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->vol_updated) {
err = scarlett2_update_volumes(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->vol[index];
return 0;
}
static int scarlett2_volume_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->vol[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->vol[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
index, val - SCARLETT2_VOLUME_BIAS);
return err < 0 ? err : 1;
}
static const DECLARE_TLV_DB_MINMAX(
db_scale_scarlett2_volume, -SCARLETT2_VOLUME_BIAS * 100, 0
);
static const struct snd_kcontrol_new scarlett2_master_volume_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READ |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_volume_ctl_info,
.get = scarlett2_master_volume_ctl_get,
.private_value = 0,
.tlv = { .p = db_scale_scarlett2_volume }
};
static const struct snd_kcontrol_new scarlett2_headphone_volume_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READ |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_volume_ctl_info,
.get = scarlett2_headphone_volume_ctl_get,
.private_value = 0,
.tlv = { .p = db_scale_scarlett2_volume }
};
static const struct snd_kcontrol_new scarlett2_line_out_volume_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_volume_ctl_info,
.get = scarlett2_volume_ctl_get,
.put = scarlett2_volume_ctl_put,
.private_value = 0,
.tlv = { .p = db_scale_scarlett2_volume }
};
static int scarlett2_update_dim_mute(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err, i;
u8 mute;
private->dim_mute_updated = 0;
if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_DIM_MUTE,
SCARLETT2_DIM_MUTE_COUNT, private->dim_mute);
if (err < 0)
return err;
for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
private->dim_mute[i] = !!private->dim_mute[i];
mute = private->dim_mute[SCARLETT2_BUTTON_MUTE];
for (i = 0; i < private->num_line_out; i++)
if (private->vol_sw_hw_switch[i])
private->mute_switch[i] = mute;
return 0;
}
static int scarlett2_mute_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->dim_mute_updated) {
err = scarlett2_update_dim_mute(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->mute_switch[index];
return 0;
}
static int scarlett2_mute_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->mute_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->mute_switch[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_mute_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_mute_ctl_get,
.put = scarlett2_mute_ctl_put,
};
static void scarlett2_sw_hw_ctl_ro(struct scarlett2_data *private, int index)
{
private->sw_hw_ctls[index]->vd[0].access &=
~SNDRV_CTL_ELEM_ACCESS_WRITE;
}
static void scarlett2_sw_hw_ctl_rw(struct scarlett2_data *private, int index)
{
private->sw_hw_ctls[index]->vd[0].access |=
SNDRV_CTL_ELEM_ACCESS_WRITE;
}
static int scarlett2_sw_hw_enum_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
static const char *const values[2] = {
"SW", "HW"
};
return snd_ctl_enum_info(uinfo, 1, 2, values);
}
static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
int index = line_out_remap(private, elem->control);
ucontrol->value.enumerated.item[0] = private->vol_sw_hw_switch[index];
return 0;
}
static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer,
int index, int value)
{
struct scarlett2_data *private = mixer->private_data;
struct snd_card *card = mixer->chip->card;
if (value) {
private->vol_ctls[index]->vd[0].access |=
SNDRV_CTL_ELEM_ACCESS_WRITE;
private->mute_ctls[index]->vd[0].access |=
SNDRV_CTL_ELEM_ACCESS_WRITE;
} else {
private->vol_ctls[index]->vd[0].access &=
~SNDRV_CTL_ELEM_ACCESS_WRITE;
private->mute_ctls[index]->vd[0].access &=
~SNDRV_CTL_ELEM_ACCESS_WRITE;
}
snd_ctl_notify(card,
SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
&private->vol_ctls[index]->id);
snd_ctl_notify(card,
SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
&private->mute_ctls[index]->id);
}
static int scarlett2_sw_hw_change(struct usb_mixer_interface *mixer,
int ctl_index, int val)
{
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, ctl_index);
int err;
private->vol_sw_hw_switch[index] = val;
scarlett2_vol_ctl_set_writable(mixer, ctl_index, !val);
private->vol[index] = private->master_vol;
private->mute_switch[index] = private->dim_mute[SCARLETT2_BUTTON_MUTE];
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
index, private->master_vol - SCARLETT2_VOLUME_BIAS);
if (err < 0)
return err;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
index, private->dim_mute[SCARLETT2_BUTTON_MUTE]);
if (err < 0)
return err;
return scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
index, val);
}
static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int ctl_index = elem->control;
int index = line_out_remap(private, ctl_index);
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->vol_sw_hw_switch[index];
val = !!ucontrol->value.enumerated.item[0];
if (oval == val)
return 0;
err = scarlett2_sw_hw_change(mixer, ctl_index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_sw_hw_enum_ctl_info,
.get = scarlett2_sw_hw_enum_ctl_get,
.put = scarlett2_sw_hw_enum_ctl_put,
};
static int scarlett2_update_input_level(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_level_updated = 0;
if (!info->level_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
info->level_input_count + info->level_input_first,
private->level_switch);
}
static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
static const char *const values[2] = {
"Line", "Inst"
};
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
return snd_ctl_enum_info(uinfo, 1, 2, values);
}
static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int index = elem->control + info->level_input_first;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_level_updated) {
err = scarlett2_update_input_level(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = scarlett2_decode_muteable(
private->level_switch[index]);
return 0;
}
static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int index = elem->control + info->level_input_first;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->level_switch[index];
val = !!ucontrol->value.enumerated.item[0];
if (oval == val)
return 0;
private->level_switch[index] = val;
if (private->config_set->items[SCARLETT2_CONFIG_LEVEL_SWITCH].mute)
val = (!val) | 0x02;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_level_enum_ctl_info,
.get = scarlett2_level_enum_ctl_get,
.put = scarlett2_level_enum_ctl_put,
};
static int scarlett2_update_input_pad(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_pad_updated = 0;
if (!info->pad_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PAD_SWITCH,
info->pad_input_count, private->pad_switch);
}
static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_pad_updated) {
err = scarlett2_update_input_pad(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] =
private->pad_switch[elem->control];
return 0;
}
static int scarlett2_pad_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->pad_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->pad_switch[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PAD_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_pad_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_pad_ctl_get,
.put = scarlett2_pad_ctl_put,
};
static int scarlett2_update_input_air(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_air_updated = 0;
if (!info->air_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_AIR_SWITCH,
info->air_input_count, private->air_switch);
}
static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_air_updated) {
err = scarlett2_update_input_air(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->air_switch[elem->control];
return 0;
}
static int scarlett2_air_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->air_switch[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->air_switch[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_AIR_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static int scarlett2_air_with_drive_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[3] = {
"Off", "Presence", "Presence + Drive"
};
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_autogain_updated(mixer);
if (err < 0)
return err;
return snd_ctl_enum_info(uinfo, 1, 3, values);
}
static const struct snd_kcontrol_new scarlett2_air_ctl[2] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_air_ctl_get,
.put = scarlett2_air_ctl_put,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_air_with_drive_ctl_info,
.get = scarlett2_air_ctl_get,
.put = scarlett2_air_ctl_put,
}
};
static int scarlett2_update_input_dsp(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_dsp_updated = 0;
if (!info->dsp_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_DSP_SWITCH,
info->dsp_input_count, private->dsp_switch);
}
static int scarlett2_dsp_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_dsp_updated) {
err = scarlett2_update_input_dsp(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->dsp_switch[elem->control];
return 0;
}
static int scarlett2_dsp_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->dsp_switch[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->dsp_switch[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_DSP_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_dsp_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_disables_ctl_info,
.get = scarlett2_dsp_ctl_get,
.put = scarlett2_dsp_ctl_put,
};
static int scarlett2_update_compressor_values(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i, j;
if (!info->dsp_input_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_COMPRESSOR_PARAMS,
SCARLETT2_COMPRESSOR_PARAM_COUNT * info->dsp_input_count,
private->compressor_values);
if (err < 0)
return err;
for (i = 0; i < SCARLETT2_COMPRESSOR_PARAM_COUNT; i++) {
const struct compressor_param *param = &compressor_params[i];
for (j = 0; j < info->dsp_input_count; j++) {
int idx = i + j * SCARLETT2_COMPRESSOR_PARAM_COUNT;
int val = private->compressor_values[idx];
val >>= param->scale_bits;
val = clamp(val, param->min, param->max);
private->compressor_values[idx] = val;
}
}
return 0;
}
static int scarlett2_compressor_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] =
private->compressor_values[elem->control];
return 0;
}
static int scarlett2_compressor_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int channel = index / SCARLETT2_COMPRESSOR_PARAM_COUNT;
int param_index = index % SCARLETT2_COMPRESSOR_PARAM_COUNT;
const struct compressor_param *param = &compressor_params[param_index];
int oval, val, err;
s32 scaled_val;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->compressor_values[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->compressor_values[index] = val;
scaled_val = val << param->scale_bits;
err = scarlett2_usb_set_data(
mixer, private->config_set->param_buf_addr + 1, 1, channel);
if (err < 0)
return err;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_COMPRESSOR_PARAMS, index, scaled_val);
return err < 0 ? err : 1;
}
static int scarlett2_compressor_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
int control = elem->control % SCARLETT2_COMPRESSOR_PARAM_COUNT;
uinfo->type = compressor_params[control].type;
uinfo->count = 1;
uinfo->value.integer.min = compressor_params[control].min;
uinfo->value.integer.max = compressor_params[control].max;
uinfo->value.integer.step = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_compressor_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = scarlett2_compressor_ctl_info,
.get = scarlett2_compressor_ctl_get,
.put = scarlett2_compressor_ctl_put,
};
static int scarlett2_precomp_flt_switch_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->precomp_flt_switch[elem->control];
return 0;
}
static int scarlett2_peq_flt_switch_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] =
private->peq_flt_switch[elem->control];
return 0;
}
static int scarlett2_precomp_flt_switch_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->precomp_flt_switch[elem->control];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->precomp_flt_switch[elem->control] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_PRECOMP_FLT_SWITCH,
elem->control, val);
return err < 0 ? err : 1;
}
static int scarlett2_peq_flt_switch_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->peq_flt_switch[elem->control];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->peq_flt_switch[elem->control] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_PEQ_FLT_SWITCH,
elem->control, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_precomp_flt_switch_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_precomp_flt_switch_ctl_get,
.put = scarlett2_precomp_flt_switch_ctl_put,
};
static const struct snd_kcontrol_new scarlett2_peq_flt_switch_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_peq_flt_switch_ctl_get,
.put = scarlett2_peq_flt_switch_ctl_put,
};
static int scarlett2_update_filter_values(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i, j, k, src_idx, dst_idx;
s32 peq_flt_values[SCARLETT2_DSP_SWITCH_MAX *
SCARLETT2_PEQ_FLT_SLOTS_MAX *
SCARLETT2_BIQUAD_COEFFS];
if (!info->dsp_input_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PRECOMP_FLT_SWITCH,
info->dsp_input_count, private->precomp_flt_switch);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PEQ_FLT_SWITCH,
info->dsp_input_count, private->peq_flt_switch);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PRECOMP_FLT_PARAMS,
info->dsp_input_count *
info->precomp_flt_count *
SCARLETT2_BIQUAD_COEFFS,
private->precomp_flt_values);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PEQ_FLT_PARAMS,
info->dsp_input_count *
info->peq_flt_total_count *
SCARLETT2_BIQUAD_COEFFS,
peq_flt_values);
if (err < 0)
return err;
for (i = 0, dst_idx = 0; i < info->dsp_input_count; i++) {
src_idx = i *
info->peq_flt_total_count *
SCARLETT2_BIQUAD_COEFFS;
for (j = 0; j < info->peq_flt_count; j++)
for (k = 0;
k < SCARLETT2_BIQUAD_COEFFS;
k++, src_idx++, dst_idx++)
private->peq_flt_values[dst_idx] =
peq_flt_values[src_idx];
}
return 0;
}
static int scarlett2_precomp_flt_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
int i, idx;
for (i = 0, idx = elem->control * SCARLETT2_BIQUAD_COEFFS;
i < SCARLETT2_BIQUAD_COEFFS;
i++, idx++)
ucontrol->value.integer.value[i] =
private->precomp_flt_values[idx];
return 0;
}
static int scarlett2_peq_flt_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
int i, idx;
for (i = 0, idx = elem->control * SCARLETT2_BIQUAD_COEFFS;
i < SCARLETT2_BIQUAD_COEFFS;
i++, idx++)
ucontrol->value.integer.value[i] =
private->peq_flt_values[idx];
return 0;
}
static int scarlett2_precomp_flt_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control * SCARLETT2_BIQUAD_COEFFS;
int i, oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
for (i = 0; i < SCARLETT2_BIQUAD_COEFFS; i++) {
oval = private->precomp_flt_values[index + i];
val = ucontrol->value.integer.value[i];
if (oval != val)
break;
}
if (i == SCARLETT2_BIQUAD_COEFFS)
return 0;
for (i = 0; i < SCARLETT2_BIQUAD_COEFFS; i++)
private->precomp_flt_values[index + i] =
ucontrol->value.integer.value[i];
err = scarlett2_usb_set_data(
mixer, private->config_set->param_buf_addr, 1, index);
if (err < 0)
return err;
err = scarlett2_usb_set_config_buf(
mixer, SCARLETT2_CONFIG_PRECOMP_FLT_PARAMS,
index, SCARLETT2_BIQUAD_COEFFS,
&private->precomp_flt_values[index]);
return err < 0 ? err : 1;
}
static int scarlett2_peq_flt_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int src_index = elem->control * SCARLETT2_BIQUAD_COEFFS;
int dst_index = (
elem->control /
info->peq_flt_count *
info->peq_flt_total_count +
elem->control % info->peq_flt_count
) * SCARLETT2_BIQUAD_COEFFS;
int i, oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
for (i = 0; i < SCARLETT2_BIQUAD_COEFFS; i++) {
oval = private->peq_flt_values[src_index + i];
val = ucontrol->value.integer.value[i];
if (oval != val)
break;
}
if (i == SCARLETT2_BIQUAD_COEFFS)
return 0;
for (i = 0; i < SCARLETT2_BIQUAD_COEFFS; i++)
private->peq_flt_values[src_index + i] =
ucontrol->value.integer.value[i];
err = scarlett2_usb_set_data(
mixer, private->config_set->param_buf_addr, 1, dst_index);
if (err < 0)
return err;
err = scarlett2_usb_set_config_buf(
mixer, SCARLETT2_CONFIG_PEQ_FLT_PARAMS,
dst_index, SCARLETT2_BIQUAD_COEFFS,
&private->peq_flt_values[src_index]);
return err < 0 ? err : 1;
}
static int scarlett2_flt_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = SCARLETT2_BIQUAD_COEFFS;
uinfo->value.integer.min = INT_MIN;
uinfo->value.integer.max = INT_MAX;
uinfo->value.integer.step = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_precomp_flt_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = scarlett2_flt_ctl_info,
.get = scarlett2_precomp_flt_ctl_get,
.put = scarlett2_precomp_flt_ctl_put,
};
static const struct snd_kcontrol_new scarlett2_peq_flt_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = scarlett2_flt_ctl_info,
.get = scarlett2_peq_flt_ctl_get,
.put = scarlett2_peq_flt_ctl_put,
};
static int scarlett2_update_input_mute(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->input_mute_updated = 0;
if (!info->mute_input_count)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_INPUT_MUTE_SWITCH,
info->mute_input_count, private->input_mute_switch);
}
static int scarlett2_input_mute_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->input_mute_updated) {
err = scarlett2_update_input_mute(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] =
private->input_mute_switch[elem->control];
return 0;
}
static int scarlett2_input_mute_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->input_mute_switch[index];
val = ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->input_mute_switch[index] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_INPUT_MUTE_SWITCH,
index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_input_mute_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_disables_ctl_info,
.get = scarlett2_input_mute_ctl_get,
.put = scarlett2_input_mute_ctl_put,
};
static int scarlett2_update_input_phantom(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err;
private->input_phantom_updated = 0;
if (!info->phantom_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
info->phantom_count, private->phantom_switch);
if (err < 0)
return err;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
1, &private->phantom_persistence);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_phantom_is_switching(
struct scarlett2_data *private, int line_num)
{
const struct scarlett2_device_info *info = private->info;
int index = line_num / info->inputs_per_phantom;
return !!(private->phantom_switch[index] & 0x02);
}
static void scarlett2_phantom_update_access(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
for (i = 0; i < info->gain_input_count; i++) {
int val = !scarlett2_phantom_is_switching(private, i);
scarlett2_set_ctl_access(private->autogain_ctls[i], val);
}
}
static void scarlett2_phantom_notify_access(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
for (i = 0; i < info->gain_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->autogain_ctls[i]->id);
}
static int scarlett2_check_input_phantom_updated(
struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
if (!private->input_phantom_updated)
return 0;
err = scarlett2_update_input_phantom(mixer);
if (err < 0)
return err;
scarlett2_phantom_update_access(mixer);
return 0;
}
static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_input_phantom_updated(mixer);
if (err < 0)
return err;
ucontrol->value.integer.value[0] = scarlett2_decode_muteable(
private->phantom_switch[elem->control]);
return 0;
}
static int scarlett2_phantom_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_check_put_during_autogain(mixer);
if (err < 0)
return err;
oval = private->phantom_switch[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->phantom_switch[index] = val;
if (private->config_set->items[SCARLETT2_CONFIG_PHANTOM_SWITCH].mute)
val = (!val) | 0x02;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
index + info->phantom_first, val);
scarlett2_phantom_update_access(mixer);
scarlett2_phantom_notify_access(mixer);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_phantom_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_autogain_disables_ctl_info,
.get = scarlett2_phantom_ctl_get,
.put = scarlett2_phantom_ctl_put,
};
static int scarlett2_phantom_persistence_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->phantom_persistence;
return 0;
}
static int scarlett2_phantom_persistence_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->phantom_persistence;
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->phantom_persistence = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE, index, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_phantom_persistence_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_phantom_persistence_ctl_get,
.put = scarlett2_phantom_persistence_ctl_put,
};
static int scarlett2_update_monitor_other(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err;
u8 monitor_other_enable[2];
u8 monitor_other_switch[2];
private->monitor_other_updated = 0;
if (!info->has_speaker_switching)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
2, monitor_other_enable);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
2, monitor_other_switch);
if (err < 0)
return err;
if (!monitor_other_enable[0])
private->speaker_switching_switch = 0;
else
private->speaker_switching_switch = monitor_other_switch[0] + 1;
if (info->has_talkback) {
u16 bitmap;
int i;
if (!monitor_other_enable[1])
private->talkback_switch = 0;
else
private->talkback_switch = monitor_other_switch[1] + 1;
err = scarlett2_usb_get_config(mixer,
SCARLETT2_CONFIG_TALKBACK_MAP,
1, &bitmap);
if (err < 0)
return err;
for (i = 0; i < private->num_mix_out; i++, bitmap >>= 1)
private->talkback_map[i] = bitmap & 1;
}
return 0;
}
static int scarlett2_speaker_switch_enum_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[3] = {
"Off", "Main", "Alt"
};
return snd_ctl_enum_info(uinfo, 1, 3, values);
}
static int scarlett2_speaker_switch_enum_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->monitor_other_updated) {
err = scarlett2_update_monitor_other(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->speaker_switching_switch;
return 0;
}
static int scarlett2_speaker_switch_enable(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int i, err;
for (i = 0; i < 4; i++) {
int index = line_out_remap(private, i);
if (!private->vol_sw_hw_switch[index]) {
err = scarlett2_sw_hw_change(private->mixer, i, 1);
if (err < 0)
return err;
}
scarlett2_sw_hw_ctl_ro(private, i);
snd_ctl_notify(card,
SNDRV_CTL_EVENT_MASK_VALUE |
SNDRV_CTL_EVENT_MASK_INFO,
&private->sw_hw_ctls[i]->id);
}
private->speaker_switching_switched = 1;
return 0;
}
static void scarlett2_speaker_switch_disable(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int i;
for (i = 0; i < 4; i++) {
scarlett2_sw_hw_ctl_rw(private, i);
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->sw_hw_ctls[i]->id);
}
private->speaker_switching_switched = 1;
}
static int scarlett2_speaker_switch_enum_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->speaker_switching_switch;
val = min(ucontrol->value.enumerated.item[0], 2U);
if (oval == val)
return 0;
private->speaker_switching_switch = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
0, !!val);
if (err < 0)
return err;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
0, val == 2);
if (err < 0)
return err;
if (!oval && val)
err = scarlett2_speaker_switch_enable(mixer);
else if (oval && !val)
scarlett2_speaker_switch_disable(mixer);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_speaker_switch_enum_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_speaker_switch_enum_ctl_info,
.get = scarlett2_speaker_switch_enum_ctl_get,
.put = scarlett2_speaker_switch_enum_ctl_put,
};
static int scarlett2_add_speaker_switch_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
if (!info->has_speaker_switching)
return 0;
return scarlett2_add_new_ctl(
mixer, &scarlett2_speaker_switch_enum_ctl,
0, 1, "Speaker Switching Playback Enum",
&private->speaker_switching_ctl);
}
static int scarlett2_talkback_enum_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[3] = {
"Disabled", "Off", "On"
};
return snd_ctl_enum_info(uinfo, 1, 3, values);
}
static int scarlett2_talkback_enum_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->monitor_other_updated) {
err = scarlett2_update_monitor_other(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->talkback_switch;
return 0;
}
static int scarlett2_talkback_enum_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->talkback_switch;
val = min(ucontrol->value.enumerated.item[0], 2U);
if (oval == val)
return 0;
private->talkback_switch = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
1, !!val);
if (err < 0)
return err;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
1, val == 2);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_talkback_enum_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_talkback_enum_ctl_info,
.get = scarlett2_talkback_enum_ctl_get,
.put = scarlett2_talkback_enum_ctl_put,
};
static int scarlett2_talkback_map_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
ucontrol->value.integer.value[0] = private->talkback_map[index];
return 0;
}
static int scarlett2_talkback_map_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err, i;
u16 bitmap = 0;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->talkback_map[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->talkback_map[index] = val;
for (i = 0; i < private->num_mix_out; i++)
bitmap |= private->talkback_map[i] << i;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_TALKBACK_MAP,
0, bitmap);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_talkback_map_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_talkback_map_ctl_get,
.put = scarlett2_talkback_map_ctl_put,
};
static int scarlett2_add_talkback_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
if (!info->has_talkback)
return 0;
err = scarlett2_add_new_ctl(
mixer, &scarlett2_talkback_enum_ctl,
0, 1, "Talkback Playback Enum",
&private->talkback_ctl);
if (err < 0)
return err;
for (i = 0; i < private->num_mix_out; i++) {
snprintf(s, sizeof(s),
"Talkback Mix %c Playback Switch", i + 'A');
err = scarlett2_add_new_ctl(mixer, &scarlett2_talkback_map_ctl,
i, 1, s, NULL);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->dim_mute_updated) {
err = scarlett2_update_dim_mute(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->dim_mute[elem->control];
return 0;
}
static int scarlett2_dim_mute_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err, i;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->dim_mute[index];
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->dim_mute[index] = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_DIM_MUTE,
index, val);
if (index == SCARLETT2_BUTTON_MUTE)
for (i = 0; i < private->num_line_out; i++) {
int line_index = line_out_remap(private, i);
if (private->vol_sw_hw_switch[line_index]) {
private->mute_switch[line_index] = val;
snd_ctl_notify(mixer->chip->card,
SNDRV_CTL_EVENT_MASK_VALUE,
&private->mute_ctls[i]->id);
}
}
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_dim_mute_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_dim_mute_ctl_get,
.put = scarlett2_dim_mute_ctl_put
};
static int scarlett2_sp_hp_mute_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] =
!!(private->sp_hp_mute & (1 << elem->control));
return 0;
}
static int scarlett2_sp_hp_mute_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
val = private->sp_hp_mute;
if (ucontrol->value.integer.value[0])
val |= (1 << index);
else
val &= ~(1 << index);
if (val == private->sp_hp_mute)
return 0;
private->sp_hp_mute = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SP_HP_MUTE,
0, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_sp_hp_mute_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_sp_hp_mute_ctl_get,
.put = scarlett2_sp_hp_mute_ctl_put
};
static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_MASTER_VOLUME)) {
snprintf(s, sizeof(s), "Master HW Playback Volume");
err = scarlett2_add_new_ctl(mixer,
&scarlett2_master_volume_ctl,
0, 1, s, &private->master_vol_ctl);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_HEADPHONE_VOLUME)) {
snprintf(s, sizeof(s), "Headphone Playback Volume");
err = scarlett2_add_new_ctl(mixer,
&scarlett2_headphone_volume_ctl,
0, 1, s,
&private->headphone_vol_ctl);
if (err < 0)
return err;
}
if (private->info->sp_hp_mute_names)
for (i = 0; private->info->sp_hp_mute_names[i]; i++) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_sp_hp_mute_ctl,
i, 1, private->info->sp_hp_mute_names[i],
NULL);
if (err < 0)
return err;
}
if (!scarlett2_has_config_item(private,
SCARLETT2_CONFIG_LINE_OUT_VOLUME))
return 0;
for (i = 0; i < private->num_line_out; i++) {
int index = line_out_remap(private, i);
if (info->line_out_descrs[i])
snprintf(s, sizeof(s),
"Line %02d (%s) Playback Volume",
i + 1, info->line_out_descrs[i]);
else
snprintf(s, sizeof(s),
"Line %02d Playback Volume",
i + 1);
err = scarlett2_add_new_ctl(mixer,
&scarlett2_line_out_volume_ctl,
i, 1, s, &private->vol_ctls[i]);
if (err < 0)
return err;
snprintf(s, sizeof(s),
"Line %02d Mute Playback Switch",
i + 1);
err = scarlett2_add_new_ctl(mixer,
&scarlett2_mute_ctl,
i, 1, s,
&private->mute_ctls[i]);
if (err < 0)
return err;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_SW_HW_SWITCH)) {
if (private->vol_sw_hw_switch[index])
scarlett2_vol_ctl_set_writable(mixer, i, 0);
scnprintf(s, sizeof(s),
"Line Out %02d Volume Control Playback Enum",
i + 1);
err = scarlett2_add_new_ctl(mixer,
&scarlett2_sw_hw_enum_ctl,
i, 1, s,
&private->sw_hw_ctls[i]);
if (err < 0)
return err;
if (private->speaker_switching_switch && i < 4)
scarlett2_sw_hw_ctl_ro(private, i);
}
}
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_DIM_MUTE))
for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_dim_mute_ctl,
i, 1, scarlett2_dim_mute_names[i],
&private->dim_mute_ctls[i]);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_add_dsp_ctls(struct usb_mixer_interface *mixer, int i)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int j, err;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
const char *compr_fmt = "Line In %d Compressor %s";
const char *flt_switch_fmt = "Line In %d %s Filter Enable";
const char *flt_fmt = "Line In %d %s Coefficients %d";
for (j = 0; j < SCARLETT2_COMPRESSOR_PARAM_COUNT; j++) {
const struct compressor_param *param = &compressor_params[j];
int idx = i * SCARLETT2_COMPRESSOR_PARAM_COUNT + j;
scnprintf(s, sizeof(s), compr_fmt, i + 1, param->name);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_compressor_ctl,
i * SCARLETT2_COMPRESSOR_PARAM_COUNT + j,
1, s, &private->compressor_ctls[idx]);
if (err < 0)
return err;
}
scnprintf(s, sizeof(s), flt_switch_fmt, i + 1, "Pre-Comp");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_precomp_flt_switch_ctl,
i, 1, s, &private->precomp_flt_switch_ctls[i]);
if (err < 0)
return err;
scnprintf(s, sizeof(s), flt_switch_fmt, i + 1, "PEQ");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_peq_flt_switch_ctl,
i, 1, s, &private->peq_flt_switch_ctls[i]);
if (err < 0)
return err;
for (j = 0; j < info->precomp_flt_count; j++) {
scnprintf(s, sizeof(s), flt_fmt, i + 1, "Pre-Comp", j + 1);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_precomp_flt_ctl,
i * info->precomp_flt_count + j,
1, s, NULL);
if (err < 0)
return err;
}
for (j = 0; j < info->peq_flt_count; j++) {
scnprintf(s, sizeof(s), flt_fmt, i + 1, "PEQ", j + 1);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_peq_flt_ctl,
i * info->peq_flt_count + j,
1, s, NULL);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
const char *fmt = "Line In %d %s Capture %s";
const char *fmt2 = "Line In %d-%d %s Capture %s";
for (i = 0; i < info->level_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1 + info->level_input_first,
"Level", "Enum");
err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
i, 1, s, &private->level_ctls[i]);
if (err < 0)
return err;
}
for (i = 0; i < info->pad_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1, "Pad", "Switch");
err = scarlett2_add_new_ctl(mixer, &scarlett2_pad_ctl,
i, 1, s, &private->pad_ctls[i]);
if (err < 0)
return err;
}
for (i = 0; i < info->air_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1 + info->air_input_first,
"Air", info->air_option ? "Enum" : "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_air_ctl[info->air_option],
i, 1, s, &private->air_ctls[i]);
if (err < 0)
return err;
}
for (i = 0; i < info->dsp_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1, "DSP", "Switch");
err = scarlett2_add_new_ctl(mixer, &scarlett2_dsp_ctl,
i, 1, s, &private->dsp_ctls[i]);
if (err < 0)
return err;
err = scarlett2_add_dsp_ctls(mixer, i);
if (err < 0)
return err;
}
for (i = 0; i < info->mute_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1, "Mute", "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_input_mute_ctl,
i, 1, s, &private->input_mute_ctls[i]);
if (err < 0)
return err;
}
if (info->inputs_per_phantom == 1) {
for (i = 0; i < info->phantom_count; i++) {
scnprintf(s, sizeof(s), fmt,
i + 1 + info->phantom_first,
"Phantom Power", "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_phantom_ctl,
i, 1, s, &private->phantom_ctls[i]);
if (err < 0)
return err;
}
} else if (info->inputs_per_phantom > 1) {
for (i = 0; i < info->phantom_count; i++) {
int from = i * info->inputs_per_phantom + 1;
int to = (i + 1) * info->inputs_per_phantom;
scnprintf(s, sizeof(s), fmt2, from, to,
"Phantom Power", "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_phantom_ctl,
i, 1, s, &private->phantom_ctls[i]);
if (err < 0)
return err;
}
}
if (info->phantom_count &&
scarlett2_has_config_item(private,
SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_phantom_persistence_ctl, 0, 1,
"Phantom Power Persistence Capture Switch", NULL);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH)) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_input_select_ctl, 0, 1,
"Input Select Capture Enum",
&private->input_select_ctl);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH)) {
for (i = 0; i < info->gain_input_count; i++) {
scnprintf(s, sizeof(s),
"Line In %d Link Capture Switch", i + 1);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_input_link_ctl,
i, 1, s, &private->input_link_ctls[i]);
if (err < 0)
return err;
}
}
for (i = 0; i < info->gain_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1,
"Gain", "Volume");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_input_gain_ctl,
i, 1, s, &private->input_gain_ctls[i]);
if (err < 0)
return err;
private->input_gain_ctls[i]->tlv.p =
private->config_set->input_gain_tlv;
scnprintf(s, sizeof(s), fmt, i + 1,
"Autogain", "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_autogain_switch_ctl,
i, 1, s, &private->autogain_ctls[i]);
if (err < 0)
return err;
scnprintf(s, sizeof(s), fmt, i + 1,
"Autogain Status", "Enum");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_autogain_status_ctl,
i, 1, s, &private->autogain_status_ctls[i]);
if (err < 0)
return err;
}
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
if (scarlett2_has_config_item(private,
scarlett2_ag_target_configs[i])) {
scnprintf(s, sizeof(s), "Autogain %s Target",
scarlett2_ag_target_names[i]);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_ag_target_ctl,
i, 1, s, &private->ag_target_ctls[i]);
if (err < 0)
return err;
}
for (i = 0; i < info->safe_input_count; i++) {
scnprintf(s, sizeof(s), fmt, i + 1,
"Safe", "Switch");
err = scarlett2_add_new_ctl(
mixer, &scarlett2_safe_ctl,
i, 1, s, &private->safe_ctls[i]);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_PCM_INPUT_SWITCH)) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_pcm_input_switch_ctl, 0, 1,
"PCM Input Capture Switch",
&private->pcm_input_switch_ctl);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_update_mix(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int i, err;
private->mix_updated = 0;
for (i = 0; i < private->num_mix_out; i++) {
err = scarlett2_usb_get_mix(mixer, i);
if (err < 0)
return err;
}
return 1;
}
static int scarlett2_mixer_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = elem->channels;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_mixer_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->mix_updated) {
err = scarlett2_update_mix(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->mix[elem->control];
return 0;
}
static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, mix_num, err;
int index = elem->control;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->mix[index];
val = clamp(ucontrol->value.integer.value[0],
0L, (long)SCARLETT2_MIXER_MAX_VALUE);
mix_num = index / private->num_mix_in;
if (oval == val)
return 0;
private->mix[index] = val;
err = scarlett2_usb_set_mix(mixer, mix_num);
return err < 0 ? err : 1;
}
static const DECLARE_TLV_DB_MINMAX(
db_scale_scarlett2_mixer,
SCARLETT2_MIXER_MIN_DB * 100,
SCARLETT2_MIXER_MAX_DB * 100
);
static const struct snd_kcontrol_new scarlett2_mixer_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_mixer_ctl_info,
.get = scarlett2_mixer_ctl_get,
.put = scarlett2_mixer_ctl_put,
.private_value = SCARLETT2_MIXER_MAX_DB,
.tlv = { .p = db_scale_scarlett2_mixer }
};
static int scarlett2_add_mixer_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err, i, j;
int index;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
for (i = 0, index = 0; i < private->num_mix_out; i++)
for (j = 0; j < private->num_mix_in; j++, index++) {
snprintf(s, sizeof(s),
"Mix %c Input %02d Playback Volume",
'A' + i, j + 1);
err = scarlett2_add_new_ctl(mixer, &scarlett2_mixer_ctl,
index, 1, s,
&private->mix_ctls[index]);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_update_direct_monitor(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
private->direct_monitor_updated = 0;
if (!private->info->direct_monitor)
return 0;
return scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_DIRECT_MONITOR,
1, &private->direct_monitor_switch);
}
static int scarlett2_update_monitor_mix(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err, i;
u16 mix_values[SCARLETT2_MONITOR_MIX_MAX];
if (!private->num_monitor_mix_ctls)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
private->num_monitor_mix_ctls, mix_values);
if (err < 0)
return err;
for (i = 0; i < private->num_monitor_mix_ctls; i++)
private->monitor_mix[i] = scarlett2_mixer_value_to_db(
mix_values[i]);
return 0;
}
static int scarlett2_direct_monitor_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->direct_monitor_updated) {
err = scarlett2_update_direct_monitor(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->direct_monitor_switch;
return 0;
}
static int scarlett2_direct_monitor_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = elem->control;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->direct_monitor_switch;
val = min(ucontrol->value.enumerated.item[0], 2U);
if (oval == val)
return 0;
private->direct_monitor_switch = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_DIRECT_MONITOR, index, val);
return err < 0 ? err : 1;
}
static int scarlett2_direct_monitor_stereo_enum_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[3] = {
"Off", "Mono", "Stereo"
};
return snd_ctl_enum_info(uinfo, 1, 3, values);
}
static const struct snd_kcontrol_new scarlett2_direct_monitor_ctl[2] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_direct_monitor_ctl_get,
.put = scarlett2_direct_monitor_ctl_put,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_direct_monitor_stereo_enum_ctl_info,
.get = scarlett2_direct_monitor_ctl_get,
.put = scarlett2_direct_monitor_ctl_put,
}
};
static int scarlett2_monitor_mix_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->monitor_mix[elem->control];
return 0;
}
static int scarlett2_monitor_mix_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
int index = elem->control;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->monitor_mix[index];
val = clamp(ucontrol->value.integer.value[0],
0L, (long)SCARLETT2_MIXER_MAX_VALUE);
if (oval == val)
return 0;
private->monitor_mix[index] = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
index, scarlett2_mixer_values[val]);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_monitor_mix_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.name = "",
.info = scarlett2_mixer_ctl_info,
.get = scarlett2_monitor_mix_ctl_get,
.put = scarlett2_monitor_mix_ctl_put,
.private_value = SCARLETT2_MIXER_MAX_DB,
.tlv = { .p = db_scale_scarlett2_mixer }
};
static int scarlett2_add_direct_monitor_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
const char *s;
int err, i, j, k, index;
if (!info->direct_monitor)
return 0;
s = info->direct_monitor == 1
? "Direct Monitor Playback Switch"
: "Direct Monitor Playback Enum";
err = scarlett2_add_new_ctl(
mixer, &scarlett2_direct_monitor_ctl[info->direct_monitor - 1],
0, 1, s, &private->direct_monitor_ctl);
if (err < 0)
return err;
if (!private->num_monitor_mix_ctls)
return 0;
for (i = 0, index = 0; i < info->direct_monitor; i++) {
const char * const format =
"Monitor %sMix %c Input %02d Playback Volume";
const char *mix_type;
if (info->direct_monitor == 1)
mix_type = "";
else if (i == 0)
mix_type = "1 ";
else
mix_type = "2 ";
for (j = 0; j < 2; j++)
for (k = 0; k < private->num_mix_in; k++, index++) {
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
scnprintf(name, sizeof(name), format,
mix_type, 'A' + j, k + 1);
err = scarlett2_add_new_ctl(
mixer, &scarlett2_monitor_mix_ctl,
index, 1, name, NULL);
if (err < 0)
return err;
}
}
return 0;
}
static int scarlett2_mux_src_enum_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
unsigned int item = uinfo->value.enumerated.item;
int items = private->num_mux_srcs;
int port_type;
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = elem->channels;
uinfo->value.enumerated.items = items;
if (item >= items)
item = uinfo->value.enumerated.item = items - 1;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
if (item < port_count[port_type][SCARLETT2_PORT_IN]) {
const struct scarlett2_port *port =
&scarlett2_ports[port_type];
if (port_type == SCARLETT2_PORT_TYPE_MIX &&
item >= private->num_mix_out)
scnprintf(uinfo->value.enumerated.name,
sizeof(uinfo->value.enumerated.name),
port->dsp_src_descr,
item - private->num_mix_out + 1);
else
scnprintf(uinfo->value.enumerated.name,
sizeof(uinfo->value.enumerated.name),
port->src_descr,
item + port->src_num_offset);
return 0;
}
item -= port_count[port_type][SCARLETT2_PORT_IN];
}
return -EINVAL;
}
static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->mux_updated) {
err = scarlett2_usb_get_mux(mixer);
if (err < 0)
return err;
}
ucontrol->value.enumerated.item[0] = private->mux[index];
return 0;
}
static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int index = line_out_remap(private, elem->control);
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->mux[index];
val = min(ucontrol->value.enumerated.item[0],
private->num_mux_srcs - 1U);
if (oval == val)
return 0;
private->mux[index] = val;
err = scarlett2_usb_set_mux(mixer);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_mux_src_enum_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_mux_src_enum_ctl_info,
.get = scarlett2_mux_src_enum_ctl_get,
.put = scarlett2_mux_src_enum_ctl_put,
};
static int scarlett2_add_mux_enums(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int port_type, channel, i;
for (i = 0, port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
for (channel = 0;
channel < port_count[port_type][SCARLETT2_PORT_OUT];
channel++, i++) {
int err;
char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
int channel_num = channel + 1;
const struct scarlett2_port *port =
&scarlett2_ports[port_type];
const char *descr = port->dst_descr;
if (port_type == SCARLETT2_PORT_TYPE_MIX &&
channel >= private->num_mix_in) {
channel_num -= private->num_mix_in;
descr = port->dsp_dst_descr;
}
snprintf(s, sizeof(s) - 5, descr, channel_num);
strcat(s, " Enum");
err = scarlett2_add_new_ctl(mixer,
&scarlett2_mux_src_enum_ctl,
i, 1, s,
&private->mux_ctls[i]);
if (err < 0)
return err;
}
}
return 0;
}
static int scarlett2_meter_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = elem->channels;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 4095;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_meter_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
u8 *meter_level_map = private->meter_level_map;
u16 meter_levels[SCARLETT2_MAX_METERS];
int i, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
err = scarlett2_usb_get_meter_levels(mixer, elem->channels,
meter_levels);
if (err < 0)
return err;
for (i = 0; i < elem->channels; i++) {
int idx = meter_level_map[i];
int value;
if (idx == 255)
value = 0;
else
value = meter_levels[idx];
ucontrol->value.integer.value[i] = value;
}
return 0;
}
static const struct snd_kcontrol_new scarlett2_meter_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.name = "",
.info = scarlett2_meter_ctl_info,
.get = scarlett2_meter_ctl_get
};
static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!scarlett2_has_mixer(private))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
0, private->num_mux_dsts,
"Level Meter", NULL);
}
static int scarlett2_msd_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->msd_switch;
return 0;
}
static int scarlett2_msd_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->msd_switch;
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->msd_switch = val;
err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MSD_SWITCH,
0, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_msd_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_msd_ctl_get,
.put = scarlett2_msd_ctl_put,
};
static int scarlett2_add_msd_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_MSD_SWITCH))
return 0;
if (!private->msd_switch && !(mixer->chip->setup & SCARLETT2_MSD_ENABLE))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_msd_ctl,
0, 1, "MSD Mode Switch", NULL);
}
static int scarlett2_standalone_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->standalone_switch;
return 0;
}
static int scarlett2_standalone_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->standalone_switch;
val = !!ucontrol->value.integer.value[0];
if (oval == val)
return 0;
private->standalone_switch = val;
err = scarlett2_usb_set_config(mixer,
SCARLETT2_CONFIG_STANDALONE_SWITCH,
0, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_standalone_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = snd_ctl_boolean_mono_info,
.get = scarlett2_standalone_ctl_get,
.put = scarlett2_standalone_ctl_put,
};
static int scarlett2_add_standalone_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!scarlett2_has_config_item(private,
SCARLETT2_CONFIG_STANDALONE_SWITCH))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_standalone_ctl,
0, 1, "Standalone Switch", NULL);
}
static int scarlett2_update_power_status(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
u8 power_ext, power_low;
private->power_status_updated = 0;
err = scarlett2_usb_get_config(mixer, SCARLETT2_CONFIG_POWER_EXT,
1, &power_ext);
if (err < 0)
return err;
err = scarlett2_usb_get_config(mixer, SCARLETT2_CONFIG_POWER_LOW,
1, &power_low);
if (err < 0)
return err;
if (power_low)
private->power_status = SCARLETT2_POWER_STATUS_FAIL;
else if (power_ext)
private->power_status = SCARLETT2_POWER_STATUS_EXT;
else
private->power_status = SCARLETT2_POWER_STATUS_BUS;
return 0;
}
static int scarlett2_power_status_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->power_status_updated) {
err = scarlett2_update_power_status(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->power_status;
return 0;
}
static int scarlett2_power_status_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
static const char *const values[3] = {
"External", "Bus", "Fail"
};
return snd_ctl_enum_info(uinfo, 1, 3, values);
}
static const struct snd_kcontrol_new scarlett2_power_status_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_power_status_ctl_info,
.get = scarlett2_power_status_ctl_get,
};
static int scarlett2_add_power_status_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!scarlett2_has_config_item(private,
SCARLETT2_CONFIG_POWER_EXT))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_power_status_ctl,
0, 1, "Power Status Card Enum",
&private->power_status_ctl);
}
static int scarlett2_update_bluetooth_volume(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
private->bluetooth_updated = 0;
if (!private->info->has_bluetooth)
return 0;
err = scarlett2_usb_get_config(mixer,
SCARLETT2_CONFIG_BLUETOOTH_VOLUME,
1, &private->bluetooth_volume);
if (err < 0)
return err;
return 0;
}
static int scarlett2_bluetooth_volume_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
if (private->bluetooth_updated) {
err = scarlett2_update_bluetooth_volume(mixer);
if (err < 0)
return err;
}
ucontrol->value.integer.value[0] = private->bluetooth_volume;
return 0;
}
static int scarlett2_bluetooth_volume_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->bluetooth_volume;
val = clamp(ucontrol->value.integer.value[0],
0L, (long)SCARLETT2_MAX_BLUETOOTH_VOLUME);
if (oval == val)
return 0;
private->bluetooth_volume = val;
err = scarlett2_usb_set_config(mixer,
SCARLETT2_CONFIG_BLUETOOTH_VOLUME,
0, val);
return err < 0 ? err : 1;
}
static int scarlett2_bluetooth_volume_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = SCARLETT2_MAX_BLUETOOTH_VOLUME;
uinfo->value.integer.step = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_bluetooth_volume_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_bluetooth_volume_ctl_info,
.get = scarlett2_bluetooth_volume_ctl_get,
.put = scarlett2_bluetooth_volume_ctl_put,
};
static int scarlett2_add_bluetooth_volume_ctl(
struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!private->info->has_bluetooth)
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_bluetooth_volume_ctl,
0, 1, "Bluetooth Capture Volume",
&private->bluetooth_volume_ctl);
}
static int scarlett2_update_fp(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_FP_BRIGHTNESS)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_FP_BRIGHTNESS,
1, &private->fp_brightness);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_FP_SLEEP_TIME)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_FP_SLEEP_TIME,
1, &private->fp_sleep_time);
if (err < 0)
return err;
}
return 0;
}
static const char * const scarlett2_fp_brightness_texts[] = {
"High", "Medium", "Low"
};
static int scarlett2_fp_brightness_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
return snd_ctl_enum_info(uinfo, 1,
ARRAY_SIZE(scarlett2_fp_brightness_texts),
scarlett2_fp_brightness_texts);
}
static int scarlett2_fp_brightness_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.enumerated.item[0] = private->fp_brightness;
return 0;
}
static int scarlett2_fp_brightness_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->fp_brightness;
val = min(ucontrol->value.enumerated.item[0],
ARRAY_SIZE(scarlett2_fp_brightness_texts) - 1);
if (oval == val)
return 0;
private->fp_brightness = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_FP_BRIGHTNESS, 0, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_fp_brightness_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = scarlett2_fp_brightness_ctl_info,
.get = scarlett2_fp_brightness_ctl_get,
.put = scarlett2_fp_brightness_ctl_put,
};
static int scarlett2_fp_sleep_time_ctl_info(
struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = SCARLETT2_MAX_FP_SLEEP_TIME;
uinfo->value.integer.step = 1;
return 0;
}
static int scarlett2_fp_sleep_time_ctl_get(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->fp_sleep_time;
return 0;
}
static int scarlett2_fp_sleep_time_ctl_put(
struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
u32 oval, val;
int err;
guard(mutex)(&private->data_mutex);
if (private->hwdep_in_use)
return -EBUSY;
oval = private->fp_sleep_time;
val = clamp(ucontrol->value.integer.value[0],
0L, (long)SCARLETT2_MAX_FP_SLEEP_TIME);
if (oval == val)
return 0;
private->fp_sleep_time = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_FP_SLEEP_TIME, 0, val);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_fp_sleep_time_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.name = "",
.info = scarlett2_fp_sleep_time_ctl_info,
.get = scarlett2_fp_sleep_time_ctl_get,
.put = scarlett2_fp_sleep_time_ctl_put,
};
static int scarlett2_add_fp_ctls(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err;
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_FP_BRIGHTNESS)) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_fp_brightness_ctl, 0, 1,
"Front Panel Brightness", NULL);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_FP_SLEEP_TIME)) {
err = scarlett2_add_new_ctl(
mixer, &scarlett2_fp_sleep_time_ctl, 0, 1,
"Front Panel Sleep Time", NULL);
if (err < 0)
return err;
}
return 0;
}
static int scarlett2_update_spdif_mode(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err, i;
u8 mode;
const u8 *mode_values = private->info->spdif_mode_values;
if (!private->info->spdif_mode_control_name)
return 0;
err = scarlett2_usb_get_config(mixer, SCARLETT2_CONFIG_SPDIF_MODE,
1, &mode);
if (err < 0)
return err;
private->spdif_mode = 0;
for (i = 0; *mode_values != 0xff; i++, mode_values++)
if (*mode_values == mode) {
private->spdif_mode = i;
break;
}
return 0;
}
static int scarlett2_spdif_mode_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
const char * const *mode_texts = private->info->spdif_mode_texts;
int count = 0;
while (*mode_texts++)
count++;
return snd_ctl_enum_info(uinfo, 1, count,
private->info->spdif_mode_texts);
}
static int scarlett2_spdif_mode_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.enumerated.item[0] = private->spdif_mode;
return 0;
}
static int scarlett2_spdif_mode_ctl_put(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int oval, val, err;
int i;
guard(mutex)(&private->data_mutex);
oval = private->spdif_mode;
val = ucontrol->value.enumerated.item[0];
if (val < 0)
return -EINVAL;
for (i = 0; i <= val; i++)
if (private->info->spdif_mode_values[i] == 0xff)
return -EINVAL;
if (oval == val)
return 0;
private->spdif_mode = val;
err = scarlett2_usb_set_config(
mixer, SCARLETT2_CONFIG_SPDIF_MODE, 0,
private->info->spdif_mode_values[val]);
return err < 0 ? err : 1;
}
static const struct snd_kcontrol_new scarlett2_spdif_mode_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "",
.info = scarlett2_spdif_mode_ctl_info,
.get = scarlett2_spdif_mode_ctl_get,
.put = scarlett2_spdif_mode_ctl_put,
};
static int scarlett2_add_spdif_mode_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!private->info->spdif_mode_control_name)
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_spdif_mode_ctl,
0, 1,
private->info->spdif_mode_control_name,
NULL);
}
static void scarlett2_notify_sync(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
private->sync_updated = 1;
snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->sync_ctl->id);
}
static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int i;
if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
return;
private->vol_updated = 1;
snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->master_vol_ctl->id);
for (i = 0; i < private->num_line_out; i++)
if (private->vol_sw_hw_switch[line_out_remap(private, i)])
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->vol_ctls[i]->id);
}
static void scarlett2_notify_volume(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
private->vol_updated = 1;
snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->master_vol_ctl->id);
snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->headphone_vol_ctl->id);
}
static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int i;
if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
return;
private->dim_mute_updated = 1;
for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->dim_mute_ctls[i]->id);
for (i = 0; i < private->num_line_out; i++)
if (private->vol_sw_hw_switch[line_out_remap(private, i)])
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->mute_ctls[i]->id);
}
static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_level_updated = 1;
for (i = 0; i < info->level_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->level_ctls[i]->id);
}
static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_pad_updated = 1;
for (i = 0; i < info->pad_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->pad_ctls[i]->id);
}
static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_air_updated = 1;
for (i = 0; i < info->air_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->air_ctls[i]->id);
}
static void scarlett2_notify_input_dsp(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_dsp_updated = 1;
for (i = 0; i < info->dsp_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->dsp_ctls[i]->id);
}
static void scarlett2_notify_input_mute(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_mute_updated = 1;
for (i = 0; i < info->mute_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->input_mute_ctls[i]->id);
}
static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
private->input_phantom_updated = 1;
for (i = 0; i < info->phantom_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->phantom_ctls[i]->id);
scarlett2_phantom_notify_access(mixer);
}
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer)
{
scarlett2_notify_input_level(mixer);
scarlett2_notify_input_pad(mixer);
scarlett2_notify_input_air(mixer);
scarlett2_notify_input_phantom(mixer);
}
static void scarlett2_notify_input_select(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
if (!scarlett2_has_config_item(private,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH))
return;
private->input_select_updated = 1;
snd_ctl_notify(card,
SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
&private->input_select_ctl->id);
for (i = 0; i < info->gain_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->input_link_ctls[i]->id);
}
static void scarlett2_notify_input_gain(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
if (!info->gain_input_count)
return;
private->input_gain_updated = 1;
for (i = 0; i < info->gain_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->input_gain_ctls[i]->id);
}
static void scarlett2_notify_autogain(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
if (!info->gain_input_count)
return;
private->autogain_updated = 1;
for (i = 0; i < info->gain_input_count; i++) {
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->autogain_ctls[i]->id);
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->autogain_status_ctls[i]->id);
}
for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++)
if (scarlett2_has_config_item(private,
scarlett2_ag_target_configs[i]))
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
&private->ag_target_ctls[i]->id);
scarlett2_autogain_notify_access(mixer);
}
static void scarlett2_notify_input_safe(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int i;
if (!info->safe_input_count)
return;
private->input_safe_updated = 1;
for (i = 0; i < info->safe_input_count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->safe_ctls[i]->id);
}
static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
private->monitor_other_updated = 1;
if (info->has_speaker_switching)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->speaker_switching_ctl->id);
if (info->has_talkback)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->talkback_ctl->id);
if (private->speaker_switching_switched) {
int i;
scarlett2_notify_dim_mute(mixer);
private->speaker_switching_switched = 0;
private->mux_updated = 1;
for (i = 0; i < private->num_mux_dsts; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->mux_ctls[i]->id);
}
}
static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int count = private->num_mix_in * private->num_mix_out;
int i;
private->direct_monitor_updated = 1;
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->direct_monitor_ctl->id);
if (!scarlett2_has_mixer(private))
return;
private->mix_updated = 1;
for (i = 0; i < count; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->mix_ctls[i]->id);
}
static void scarlett2_notify_power_status(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
private->power_status_updated = 1;
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->power_status_ctl->id);
}
static void scarlett2_notify_mux(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
int i;
private->mux_updated = 1;
for (i = 0; i < private->num_mux_dsts; i++)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->mux_ctls[i]->id);
}
static void scarlett2_notify_pcm_input_switch(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
private->pcm_input_switch_updated = 1;
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->pcm_input_switch_ctl->id);
scarlett2_notify_mux(mixer);
}
static void scarlett2_notify_bluetooth(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
if (!private->info->has_bluetooth)
return;
private->bluetooth_updated = 1;
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
&private->bluetooth_volume_ctl->id);
}
static void scarlett2_notify_ack(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (private->running)
complete(&private->cmd_done);
}
static void scarlett2_notify(struct urb *urb)
{
struct usb_mixer_interface *mixer = urb->context;
int len = urb->actual_length;
int ustatus = urb->status;
u32 data;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_notification *notifications =
private->config_set->notifications;
if (ustatus != 0 || len != 8)
goto requeue;
data = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
if (private->running < 2)
data &= 1;
while (data && notifications->mask) {
if (data & notifications->mask) {
data &= ~notifications->mask;
if (notifications->func)
notifications->func(mixer);
}
notifications++;
}
if (data)
usb_audio_warn(mixer->chip,
"%s: Unhandled notification: 0x%08x\n",
__func__, data);
requeue:
if (ustatus != -ENOENT &&
ustatus != -ECONNRESET &&
ustatus != -ESHUTDOWN) {
urb->dev = mixer->chip->dev;
usb_submit_urb(urb, GFP_ATOMIC);
} else {
complete(&private->cmd_done);
}
}
static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
{
struct usb_device *dev = mixer->chip->dev;
struct scarlett2_data *private = mixer->private_data;
unsigned int pipe = usb_rcvintpipe(dev, private->bEndpointAddress);
void *transfer_buffer;
int err;
if (private->urb)
return 0;
if (usb_pipe_type_check(dev, pipe))
return -EINVAL;
private->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!private->urb)
return -ENOMEM;
transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
if (!transfer_buffer) {
usb_free_urb(private->urb);
private->urb = NULL;
return -ENOMEM;
}
usb_fill_int_urb(private->urb, dev, pipe,
transfer_buffer, private->wMaxPacketSize,
scarlett2_notify, mixer, private->bInterval);
reinit_completion(&private->cmd_done);
err = usb_submit_urb(private->urb, GFP_KERNEL);
if (err) {
kfree(transfer_buffer);
usb_free_urb(private->urb);
private->urb = NULL;
}
return err;
}
static void scarlett2_cleanup_urb(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (!private->urb)
return;
usb_kill_urb(private->urb);
kfree(private->urb->transfer_buffer);
usb_free_urb(private->urb);
private->urb = NULL;
}
static void scarlett2_private_free(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
cancel_delayed_work_sync(&private->work);
scarlett2_cleanup_urb(mixer);
kfree(private);
mixer->private_data = NULL;
}
static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (cancel_delayed_work_sync(&private->work))
scarlett2_config_save_nopm(private->mixer);
scarlett2_cleanup_urb(mixer);
}
static void scarlett2_resolve_config_set(struct scarlett2_data *private)
{
const struct scarlett2_config_set_entry *entry =
private->info->config_sets;
private->config_set = entry->config_set;
for (entry++; entry->config_set; entry++)
if (entry->from_firmware_version <= private->firmware_version)
private->config_set = entry->config_set;
}
static void scarlett2_count_io(struct scarlett2_data *private)
{
const struct scarlett2_device_info *info = private->info;
const struct scarlett2_config_set *config_set = private->config_set;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int port_type, srcs = 0, dsts = 0, i;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
srcs += port_count[port_type][SCARLETT2_PORT_IN];
dsts += port_count[port_type][SCARLETT2_PORT_OUT];
}
private->num_mux_srcs = srcs;
private->num_mux_dsts = dsts;
private->num_mix_in =
port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT] -
info->dsp_count;
private->num_mix_out =
port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN] -
info->dsp_count;
private->num_line_out =
port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
private->num_monitor_mix_ctls =
info->direct_monitor * 2 * private->num_mix_in;
if (config_set->autogain_status_texts) {
const char * const *texts = config_set->autogain_status_texts;
for (i = 0; texts[i]; i++)
;
private->num_autogain_status_texts = i;
}
}
static int scarlett2_find_fc_interface(struct usb_device *dev,
struct scarlett2_data *private)
{
struct usb_host_config *config = dev->actconfig;
int i;
for (i = 0; i < config->desc.bNumInterfaces; i++) {
struct usb_interface *intf = config->interface[i];
struct usb_interface_descriptor *desc =
&intf->altsetting[0].desc;
struct usb_endpoint_descriptor *epd;
if (desc->bInterfaceClass != 255)
continue;
if (desc->bNumEndpoints < 1)
continue;
epd = get_endpoint(intf->altsetting, 0);
private->bInterfaceNumber = desc->bInterfaceNumber;
private->bEndpointAddress = usb_endpoint_num(epd);
private->wMaxPacketSize = le16_to_cpu(epd->wMaxPacketSize);
private->bInterval = epd->bInterval;
return 0;
}
return -EINVAL;
}
static int scarlett2_init_private(struct usb_mixer_interface *mixer,
const struct scarlett2_device_entry *entry)
{
struct scarlett2_data *private =
kzalloc_obj(struct scarlett2_data);
if (!private)
return -ENOMEM;
mutex_init(&private->usb_mutex);
mutex_init(&private->data_mutex);
init_completion(&private->cmd_done);
INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work);
mixer->private_data = private;
mixer->private_free = scarlett2_private_free;
mixer->private_suspend = scarlett2_private_suspend;
mixer->private_resume = scarlett2_init_notify;
private->info = entry->info;
private->config_set = entry->info->config_sets[0].config_set;
private->series_name = entry->series_name;
private->scarlett2_seq = 0;
private->mixer = mixer;
return scarlett2_find_fc_interface(mixer->chip->dev, private);
}
static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
{
struct usb_device *dev = mixer->chip->dev;
struct scarlett2_data *private = mixer->private_data;
u8 step0_buf[24];
u8 step2_buf[84];
int err;
if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
return -EINVAL;
err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
SCARLETT2_USB_CMD_INIT,
step0_buf, sizeof(step0_buf));
if (err < 0)
return err;
err = scarlett2_init_notify(mixer);
if (err < 0)
return err;
msleep(20);
private->running = 1;
private->scarlett2_seq = 1;
err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_1, NULL, 0, NULL, 0);
if (err < 0)
return err;
private->scarlett2_seq = 1;
err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_2,
NULL, 0,
step2_buf, sizeof(step2_buf));
if (err < 0)
return err;
private->firmware_version = le32_to_cpu(*(__le32 *)(step2_buf + 8));
usb_audio_info(mixer->chip,
"Firmware version %d\n",
private->firmware_version);
return 0;
}
static int scarlett2_get_flash_segment_nums(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int err, count, i;
struct {
__le32 size;
__le32 count;
u8 unknown[8];
} __packed flash_info;
struct {
__le32 size;
__le32 flags;
char name[16];
} __packed segment_info;
err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_FLASH,
NULL, 0,
&flash_info, sizeof(flash_info));
if (err < 0)
return err;
count = le32_to_cpu(flash_info.count);
if (count < SCARLETT2_SEGMENT_NUM_MIN ||
count > SCARLETT2_SEGMENT_NUM_MAX + 1) {
usb_audio_err(mixer->chip,
"invalid flash segment count: %d\n", count);
return -EINVAL;
}
for (i = 0; i < count; i++) {
__le32 segment_num_req = cpu_to_le32(i);
int flash_segment_id;
err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_SEGMENT,
&segment_num_req, sizeof(segment_num_req),
&segment_info, sizeof(segment_info));
if (err < 0) {
usb_audio_err(mixer->chip,
"failed to get flash segment info %d: %d\n",
i, err);
return err;
}
if (!strncmp(segment_info.name,
SCARLETT2_SEGMENT_SETTINGS_NAME, 16))
flash_segment_id = SCARLETT2_SEGMENT_ID_SETTINGS;
else if (!strncmp(segment_info.name,
SCARLETT2_SEGMENT_FIRMWARE_NAME, 16))
flash_segment_id = SCARLETT2_SEGMENT_ID_FIRMWARE;
else
continue;
private->flash_segment_nums[flash_segment_id] = i;
private->flash_segment_blocks[flash_segment_id] =
le32_to_cpu(segment_info.size) /
SCARLETT2_FLASH_BLOCK_SIZE;
}
if (!private->flash_segment_nums[SCARLETT2_SEGMENT_ID_SETTINGS]) {
usb_audio_err(mixer->chip,
"failed to find flash segment %s\n",
SCARLETT2_SEGMENT_SETTINGS_NAME);
return -EINVAL;
}
if (!private->flash_segment_nums[SCARLETT2_SEGMENT_ID_FIRMWARE]) {
usb_audio_err(mixer->chip,
"failed to find flash segment %s\n",
SCARLETT2_SEGMENT_FIRMWARE_NAME);
return -EINVAL;
}
return 0;
}
static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
u16 min_firmware_version = info->config_sets[0].from_firmware_version;
int err, i;
if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_MSD_SWITCH)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_MSD_SWITCH,
1, &private->msd_switch);
if (err < 0)
return err;
}
if (private->firmware_version < min_firmware_version) {
usb_audio_err(mixer->chip,
"Focusrite %s firmware version %d is too old; "
"need %d",
private->series_name,
private->firmware_version,
min_firmware_version);
return 0;
}
if (private->msd_switch)
return 0;
err = scarlett2_update_input_level(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_pad(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_air(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_dsp(mixer);
if (err < 0)
return err;
err = scarlett2_update_compressor_values(mixer);
if (err < 0)
return err;
err = scarlett2_update_filter_values(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_mute(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_phantom(mixer);
if (err < 0)
return err;
err = scarlett2_update_direct_monitor(mixer);
if (err < 0)
return err;
if (!scarlett2_has_mixer(private))
return 0;
err = scarlett2_update_monitor_mix(mixer);
if (err < 0)
return err;
err = scarlett2_update_monitor_other(mixer);
if (err < 0)
return err;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_STANDALONE_SWITCH)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_STANDALONE_SWITCH,
1, &private->standalone_switch);
if (err < 0)
return err;
}
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_POWER_EXT)) {
err = scarlett2_update_power_status(mixer);
if (err < 0)
return err;
}
err = scarlett2_update_sync(mixer);
if (err < 0)
return err;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_LINE_OUT_VOLUME)) {
s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
private->num_line_out, &sw_vol);
if (err < 0)
return err;
for (i = 0; i < private->num_line_out; i++)
private->vol[i] = clamp(
sw_vol[i] + SCARLETT2_VOLUME_BIAS,
0, SCARLETT2_VOLUME_BIAS);
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
private->num_line_out, &private->mute_switch);
if (err < 0)
return err;
for (i = 0; i < private->num_line_out; i++)
private->mute_switch[i] =
!!private->mute_switch[i];
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_SW_HW_SWITCH)) {
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
private->num_line_out,
&private->vol_sw_hw_switch);
if (err < 0)
return err;
for (i = 0; i < private->num_line_out; i++)
private->vol_sw_hw_switch[i] =
!!private->vol_sw_hw_switch[i];
}
}
err = scarlett2_update_volumes(mixer);
if (err < 0)
return err;
err = scarlett2_update_dim_mute(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_select(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_gain(mixer);
if (err < 0)
return err;
err = scarlett2_update_autogain(mixer);
if (err < 0)
return err;
err = scarlett2_update_input_safe(mixer);
if (err < 0)
return err;
if (scarlett2_has_config_item(private,
SCARLETT2_CONFIG_PCM_INPUT_SWITCH)) {
err = scarlett2_update_pcm_input_switch(mixer);
if (err < 0)
return err;
}
err = scarlett2_update_bluetooth_volume(mixer);
if (err < 0)
return err;
err = scarlett2_update_fp(mixer);
if (err < 0)
return err;
err = scarlett2_update_spdif_mode(mixer);
if (err < 0)
return err;
err = scarlett2_update_mix(mixer);
if (err < 0)
return err;
return scarlett2_usb_get_mux(mixer);
}
static const struct scarlett2_device_entry *get_scarlett2_device_entry(
struct usb_mixer_interface *mixer)
{
const struct scarlett2_device_entry *entry = scarlett2_devices;
while (entry->usb_id && entry->usb_id != mixer->chip->usb_id)
entry++;
if (!entry->usb_id)
return NULL;
return entry;
}
static int snd_scarlett2_controls_create(
struct usb_mixer_interface *mixer,
const struct scarlett2_device_entry *entry)
{
struct scarlett2_data *private;
u16 min_firmware_version;
int err;
err = scarlett2_init_private(mixer, entry);
if (err < 0)
return err;
private = mixer->private_data;
min_firmware_version =
private->info->config_sets[0].from_firmware_version;
err = scarlett2_usb_init(mixer);
if (err < 0)
return err;
scarlett2_resolve_config_set(private);
scarlett2_count_io(private);
err = scarlett2_get_flash_segment_nums(mixer);
if (err < 0)
return err;
err = scarlett2_add_firmware_version_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_min_firmware_version_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_read_configs(mixer);
if (err < 0)
return err;
err = scarlett2_add_msd_ctl(mixer);
if (err < 0)
return err;
if (private->msd_switch ||
private->firmware_version < min_firmware_version)
return 0;
err = scarlett2_add_line_out_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_line_in_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_mux_enums(mixer);
if (err < 0)
return err;
err = scarlett2_add_mixer_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_meter_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_sync_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_direct_monitor_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_speaker_switch_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_talkback_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_standalone_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_power_status_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_bluetooth_volume_ctl(mixer);
if (err < 0)
return err;
err = scarlett2_add_fp_ctls(mixer);
if (err < 0)
return err;
err = scarlett2_add_spdif_mode_ctl(mixer);
if (err < 0)
return err;
if (private->info->gain_input_count) {
scarlett2_autogain_update_access(mixer);
scarlett2_phantom_update_access(mixer);
}
private->running = 2;
return 0;
}
static void scarlett2_lock(struct scarlett2_data *private)
{
guard(mutex)(&private->data_mutex);
private->hwdep_in_use = 1;
}
static int scarlett2_get_erase_progress(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int segment_id, segment_num, err;
u8 erase_resp;
struct {
__le32 segment_num;
__le32 pad;
} __packed erase_req;
segment_id = private->selected_flash_segment_id;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX)
return -EFAULT;
erase_req.segment_num = cpu_to_le32(segment_num);
erase_req.pad = 0;
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_ERASE,
&erase_req, sizeof(erase_req),
&erase_resp, sizeof(erase_resp));
if (err < 0)
return err;
return erase_resp;
}
static int scarlett2_wait_for_erase(struct usb_mixer_interface *mixer)
{
int i, err;
for (i = 0; i < 100; i++) {
err = scarlett2_get_erase_progress(mixer);
if (err < 0)
return err;
if (err == 0xff)
return 0;
msleep(100);
}
return -ETIMEDOUT;
}
static int scarlett2_reboot(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
if (private->flash_write_state ==
SCARLETT2_FLASH_WRITE_STATE_ERASING) {
int err = scarlett2_wait_for_erase(mixer);
if (err < 0)
return err;
}
return scarlett2_usb(mixer, SCARLETT2_USB_REBOOT, NULL, 0, NULL, 0);
}
static int scarlett2_ioctl_select_flash_segment(
struct usb_mixer_interface *mixer,
unsigned long arg)
{
struct scarlett2_data *private = mixer->private_data;
int segment_id, segment_num;
if (get_user(segment_id, (int __user *)arg))
return -EFAULT;
if (segment_id < 0 || segment_id >= SCARLETT2_SEGMENT_ID_COUNT)
return -EINVAL;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX) {
usb_audio_err(mixer->chip,
"%s: invalid segment number %d\n",
__func__, segment_id);
return -EFAULT;
}
if (private->flash_write_state == SCARLETT2_FLASH_WRITE_STATE_ERASING) {
int err = scarlett2_wait_for_erase(mixer);
if (err < 0)
return err;
}
private->selected_flash_segment_id = segment_id;
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_SELECTED;
return 0;
}
static int scarlett2_ioctl_erase_flash_segment(
struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int segment_id, segment_num, err;
struct {
__le32 segment_num;
__le32 pad;
} __packed erase_req;
if (private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_SELECTED)
return -EINVAL;
segment_id = private->selected_flash_segment_id;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX)
return -EFAULT;
scarlett2_lock(private);
erase_req.segment_num = cpu_to_le32(segment_num);
erase_req.pad = 0;
err = scarlett2_usb(mixer, SCARLETT2_USB_ERASE_SEGMENT,
&erase_req, sizeof(erase_req),
NULL, 0);
if (err < 0)
return err;
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_ERASING;
return 0;
}
static int scarlett2_ioctl_get_erase_progress(
struct usb_mixer_interface *mixer,
unsigned long arg)
{
struct scarlett2_data *private = mixer->private_data;
struct scarlett2_flash_segment_erase_progress progress;
int segment_id, segment_num, err;
u8 erase_resp;
struct {
__le32 segment_num;
__le32 pad;
} __packed erase_req;
if (private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_ERASING)
return -EINVAL;
segment_id = private->selected_flash_segment_id;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX)
return -EFAULT;
erase_req.segment_num = cpu_to_le32(segment_num);
erase_req.pad = 0;
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_ERASE,
&erase_req, sizeof(erase_req),
&erase_resp, sizeof(erase_resp));
if (err < 0)
return err;
progress.progress = erase_resp;
progress.num_blocks = private->flash_segment_blocks[segment_id];
if (copy_to_user((void __user *)arg, &progress, sizeof(progress)))
return -EFAULT;
if (progress.progress == 0xff)
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_WRITE;
return 0;
}
static int scarlett2_hwdep_open(struct snd_hwdep *hw, struct file *file)
{
struct usb_mixer_interface *mixer = hw->private_data;
struct scarlett2_data *private = mixer->private_data;
if (private->flash_write_state ==
SCARLETT2_FLASH_WRITE_STATE_ERASING) {
int err = scarlett2_wait_for_erase(mixer);
if (err < 0)
return err;
}
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_IDLE;
return 0;
}
static int scarlett2_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct usb_mixer_interface *mixer = hw->private_data;
switch (cmd) {
case SCARLETT2_IOCTL_PVERSION:
return put_user(SCARLETT2_HWDEP_VERSION,
(int __user *)arg) ? -EFAULT : 0;
case SCARLETT2_IOCTL_REBOOT:
return scarlett2_reboot(mixer);
case SCARLETT2_IOCTL_SELECT_FLASH_SEGMENT:
return scarlett2_ioctl_select_flash_segment(mixer, arg);
case SCARLETT2_IOCTL_ERASE_FLASH_SEGMENT:
return scarlett2_ioctl_erase_flash_segment(mixer);
case SCARLETT2_IOCTL_GET_ERASE_PROGRESS:
return scarlett2_ioctl_get_erase_progress(mixer, arg);
default:
return -ENOIOCTLCMD;
}
}
static long scarlett2_hwdep_read(struct snd_hwdep *hw,
char __user *buf,
long count, loff_t *offset)
{
struct usb_mixer_interface *mixer = hw->private_data;
struct scarlett2_data *private = mixer->private_data;
int segment_id, segment_num, err;
int flash_size;
struct {
__le32 segment_num;
__le32 offset;
__le32 len;
} __packed req;
if (private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_SELECTED)
return -EINVAL;
segment_id = private->selected_flash_segment_id;
if (segment_id < 0 || segment_id >= SCARLETT2_SEGMENT_ID_COUNT)
return -EINVAL;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < 0 ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX)
return -EFAULT;
if (count < 0 || *offset < 0)
return -EINVAL;
flash_size = private->flash_segment_blocks[segment_id] *
SCARLETT2_FLASH_BLOCK_SIZE;
if (!count || *offset >= flash_size)
return 0;
if (count > SCARLETT2_FLASH_RW_MAX)
count = SCARLETT2_FLASH_RW_MAX;
if (*offset + count >= flash_size)
count = flash_size - *offset;
req.segment_num = cpu_to_le32(segment_num);
req.offset = cpu_to_le32(*offset);
req.len = cpu_to_le32(count);
u8 *resp __free(kfree) =
kzalloc(count, GFP_KERNEL);
if (!resp)
return -ENOMEM;
err = scarlett2_usb(mixer, SCARLETT2_USB_READ_SEGMENT,
&req, sizeof(req), resp, count);
if (err < 0)
return err;
if (copy_to_user(buf, resp, count))
return -EFAULT;
*offset += count;
return count;
}
static long scarlett2_hwdep_write(struct snd_hwdep *hw,
const char __user *buf,
long count, loff_t *offset)
{
struct usb_mixer_interface *mixer = hw->private_data;
struct scarlett2_data *private = mixer->private_data;
int segment_id, segment_num, err, len;
int flash_size;
struct {
__le32 segment_num;
__le32 offset;
__le32 pad;
u8 data[];
} __packed *req __free(kfree) = NULL;
const size_t max_data_size = SCARLETT2_FLASH_RW_MAX -
offsetof(typeof(*req), data);
if (private->flash_write_state ==
SCARLETT2_FLASH_WRITE_STATE_ERASING) {
err = scarlett2_wait_for_erase(mixer);
if (err < 0)
return err;
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_WRITE;
} else if (private->flash_write_state !=
SCARLETT2_FLASH_WRITE_STATE_WRITE) {
return -EINVAL;
}
segment_id = private->selected_flash_segment_id;
if (segment_id != SCARLETT2_SEGMENT_ID_FIRMWARE)
return -EINVAL;
segment_num = private->flash_segment_nums[segment_id];
if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
segment_num > SCARLETT2_SEGMENT_NUM_MAX)
return -EFAULT;
flash_size = private->flash_segment_blocks[segment_id] *
SCARLETT2_FLASH_BLOCK_SIZE;
if (count < 0 || *offset < 0)
return -EINVAL;
if (!count)
return 0;
if (*offset >= flash_size || count > flash_size - *offset)
return -ENOSPC;
if (count > max_data_size)
count = max_data_size;
len = struct_size(req, data, count);
req = kzalloc_flex(*req, data, count);
if (!req)
return -ENOMEM;
req->segment_num = cpu_to_le32(segment_num);
req->offset = cpu_to_le32(*offset);
req->pad = 0;
if (copy_from_user(req->data, buf, count))
return -EFAULT;
err = scarlett2_usb(mixer, SCARLETT2_USB_WRITE_SEGMENT,
req, len, NULL, 0);
if (err < 0)
return err;
*offset += count;
return count;
}
static int scarlett2_hwdep_release(struct snd_hwdep *hw, struct file *file)
{
struct usb_mixer_interface *mixer = hw->private_data;
struct scarlett2_data *private = mixer->private_data;
if (private &&
private->hwdep_in_use &&
private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_ERASING)
private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_IDLE;
return 0;
}
static int scarlett2_hwdep_init(struct usb_mixer_interface *mixer)
{
struct snd_hwdep *hw;
int err;
err = snd_hwdep_new(mixer->chip->card, "Focusrite Control", 0, &hw);
if (err < 0)
return err;
hw->private_data = mixer;
hw->exclusive = 1;
hw->ops.open = scarlett2_hwdep_open;
hw->ops.ioctl = scarlett2_hwdep_ioctl;
hw->ops.read = scarlett2_hwdep_read;
hw->ops.write = scarlett2_hwdep_write;
hw->ops.release = scarlett2_hwdep_release;
return 0;
}
static ssize_t scarlett2_devmap_read(
struct snd_info_entry *entry,
void *file_private_data,
struct file *file,
char __user *buf,
size_t count,
loff_t pos)
{
struct usb_mixer_interface *mixer = entry->private_data;
const size_t block_size = SCARLETT2_DEVMAP_BLOCK_SIZE;
size_t copied = 0;
if (pos >= entry->size)
return 0;
if (pos + count > entry->size)
count = entry->size - pos;
u8 *resp_buf __free(kfree) =
kmalloc(block_size, GFP_KERNEL);
if (!resp_buf)
return -ENOMEM;
while (count > 0) {
__le32 req;
int err;
size_t offset = pos % block_size;
size_t block_start = pos - offset;
size_t read_size = min_t(size_t,
block_size,
entry->size - block_start);
size_t copy_size = min_t(size_t, count, read_size - offset);
req = cpu_to_le32(pos / block_size);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_DEVMAP,
&req, sizeof(req), resp_buf, read_size);
if (err < 0)
return copied ? copied : err;
if (copy_to_user(buf, resp_buf + offset, copy_size))
return -EFAULT;
buf += copy_size;
pos += copy_size;
copied += copy_size;
count -= copy_size;
}
return copied;
}
static const struct snd_info_entry_ops scarlett2_devmap_ops = {
.read = scarlett2_devmap_read,
};
static int scarlett2_devmap_init(struct usb_mixer_interface *mixer)
{
struct snd_card *card = mixer->chip->card;
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
__le16 config_len_buf[2];
int config_len;
struct snd_info_entry *entry;
int err;
if (!info->has_devmap)
return 0;
err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_DEVMAP,
NULL, 0, &config_len_buf, sizeof(config_len_buf));
if (err < 0)
return err;
config_len = le16_to_cpu(config_len_buf[1]);
err = snd_card_proc_new(card, SCARLETT2_DEVMAP_FILENAME, &entry);
if (err < 0)
return err;
entry->content = SNDRV_INFO_CONTENT_DATA;
entry->private_data = mixer;
entry->c.ops = &scarlett2_devmap_ops;
entry->size = config_len;
entry->mode = S_IFREG | 0444;
return 0;
}
int snd_scarlett2_init(struct usb_mixer_interface *mixer)
{
struct snd_usb_audio *chip = mixer->chip;
const struct scarlett2_device_entry *entry;
int err;
if (!mixer->protocol)
return 0;
if (chip->setup & SCARLETT2_USE_FCP_DRIVER)
return snd_fcp_init(mixer);
entry = get_scarlett2_device_entry(mixer);
if (!entry) {
usb_audio_err(mixer->chip,
"%s: missing device entry for %04x:%04x\n",
__func__,
USB_ID_VENDOR(chip->usb_id),
USB_ID_PRODUCT(chip->usb_id));
return 0;
}
if (chip->setup & SCARLETT2_DISABLE) {
usb_audio_info(chip,
"Focusrite %s Mixer Driver disabled "
"by modprobe options (snd_usb_audio "
"vid=0x%04x pid=0x%04x device_setup=%d)\n",
entry->series_name,
USB_ID_VENDOR(chip->usb_id),
USB_ID_PRODUCT(chip->usb_id),
SCARLETT2_DISABLE);
return 0;
}
usb_audio_info(chip,
"Focusrite %s Mixer Driver enabled (pid=0x%04x); "
"report any issues to "
"https://github.com/geoffreybennett/scarlett-gen2/issues",
entry->series_name,
USB_ID_PRODUCT(chip->usb_id));
err = snd_scarlett2_controls_create(mixer, entry);
if (err < 0) {
usb_audio_err(mixer->chip,
"Error initialising %s Mixer Driver: %d",
entry->series_name,
err);
return err;
}
err = scarlett2_hwdep_init(mixer);
if (err < 0) {
usb_audio_err(mixer->chip,
"Error creating %s hwdep device: %d",
entry->series_name,
err);
return err;
}
err = scarlett2_devmap_init(mixer);
if (err < 0)
usb_audio_err(mixer->chip,
"Error creating %s devmap entry: %d",
entry->series_name,
err);
return err;
}