123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396 |
- /*
- * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
- * Author: Brian Swetland <[email protected]>
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
- #include <linux/fs.h>
- #include <linux/mutex.h>
- #include <linux/wait.h>
- #include <linux/miscdevice.h>
- #include <linux/uaccess.h>
- #include <linux/sched.h>
- #include <linux/dma-mapping.h>
- #include <linux/miscdevice.h>
- #include <linux/delay.h>
- #include <linux/slab.h>
- #include <linux/debugfs.h>
- #include <linux/time.h>
- #include <linux/atomic.h>
- #include <linux/mm.h>
- #include <asm/ioctls.h>
- #include <linux/memory.h>
- #include <sound/compress_params.h>
- #include <dsp/msm_audio_ion.h>
- #include <dsp/apr_audio-v2.h>
- #include <dsp/audio_cal_utils.h>
- #include <dsp/q6asm-v2.h>
- #include <dsp/q6audio-v2.h>
- #include "adsp_err.h"
- #define TRUE 0x01
- #define FALSE 0x00
- #define SESSION_MAX 8
- enum {
- ASM_TOPOLOGY_CAL = 0,
- ASM_CUSTOM_TOP_CAL,
- ASM_AUDSTRM_CAL,
- ASM_RTAC_APR_CAL,
- ASM_MAX_CAL_TYPES
- };
- union asm_token_struct {
- struct {
- u8 stream_id;
- u8 session_id;
- u8 buf_index;
- u8 flags;
- } _token;
- u32 token;
- } __packed;
- enum {
- ASM_DIRECTION_OFFSET,
- ASM_CMD_NO_WAIT_OFFSET,
- /*
- * Offset is limited to 7 because flags is stored in u8
- * field in asm_token_structure defined above. The offset
- * starts from 0.
- */
- ASM_MAX_OFFSET = 7,
- };
- enum {
- WAIT_CMD,
- NO_WAIT_CMD
- };
- #define ASM_SET_BIT(n, x) (n |= 1 << x)
- #define ASM_TEST_BIT(n, x) ((n >> x) & 1)
- /* TODO, combine them together */
- static DEFINE_MUTEX(session_lock);
- struct asm_mmap {
- atomic_t ref_cnt;
- void *apr;
- };
- static struct asm_mmap this_mmap;
- /* session id: 0 reserved */
- static struct audio_client *session[ASM_ACTIVE_STREAMS_ALLOWED + 1];
- struct asm_buffer_node {
- struct list_head list;
- phys_addr_t buf_phys_addr;
- uint32_t mmap_hdl;
- };
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv);
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size);
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous);
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir);
- static void q6asm_reset_buf_state(struct audio_client *ac);
- static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels,
- bool use_back_flavor);
- void *q6asm_mmap_apr_reg(void);
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv);
- static int q6asm_get_asm_topology_cal(void);
- static int q6asm_get_asm_app_type_cal(void);
- /* for ASM custom topology */
- static struct cal_type_data *cal_data[ASM_MAX_CAL_TYPES];
- static struct audio_buffer common_buf[2];
- static struct audio_client common_client;
- static int set_custom_topology;
- static int topology_map_handle;
- struct generic_get_data_ {
- int valid;
- int is_inband;
- int size_in_ints;
- int ints[];
- };
- static struct generic_get_data_ *generic_get_data;
- #ifdef CONFIG_DEBUG_FS
- #define OUT_BUFFER_SIZE 56
- #define IN_BUFFER_SIZE 24
- static struct timeval out_cold_tv;
- static struct timeval out_warm_tv;
- static struct timeval out_cont_tv;
- static struct timeval in_cont_tv;
- static long out_enable_flag;
- static long in_enable_flag;
- static struct dentry *out_dentry;
- static struct dentry *in_dentry;
- static int in_cont_index;
- /*This var is used to keep track of first write done for cold output latency */
- static int out_cold_index;
- static char *out_buffer;
- static char *in_buffer;
- static uint32_t adsp_reg_event_opcode[] = {
- ASM_STREAM_CMD_REGISTER_PP_EVENTS,
- ASM_STREAM_CMD_REGISTER_ENCDEC_EVENTS,
- ASM_STREAM_CMD_REGISTER_IEC_61937_FMT_UPDATE };
- static uint32_t adsp_raise_event_opcode[] = {
- ASM_STREAM_PP_EVENT,
- ASM_STREAM_CMD_ENCDEC_EVENTS,
- ASM_IEC_61937_MEDIA_FMT_EVENT };
- static int is_adsp_reg_event(uint32_t cmd)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(adsp_reg_event_opcode); i++) {
- if (cmd == adsp_reg_event_opcode[i])
- return i;
- }
- return -EINVAL;
- }
- static int is_adsp_raise_event(uint32_t cmd)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(adsp_raise_event_opcode); i++) {
- if (cmd == adsp_raise_event_opcode[i])
- return i;
- }
- return -EINVAL;
- }
- static inline void q6asm_set_flag_in_token(union asm_token_struct *asm_token,
- int flag, int flag_offset)
- {
- if (flag)
- ASM_SET_BIT(asm_token->_token.flags, flag_offset);
- }
- static inline int q6asm_get_flag_from_token(union asm_token_struct *asm_token,
- int flag_offset)
- {
- return ASM_TEST_BIT(asm_token->_token.flags, flag_offset);
- }
- static inline void q6asm_update_token(u32 *token, u8 session_id, u8 stream_id,
- u8 buf_index, u8 dir, u8 nowait_flag)
- {
- union asm_token_struct asm_token;
- asm_token.token = 0;
- asm_token._token.session_id = session_id;
- asm_token._token.stream_id = stream_id;
- asm_token._token.buf_index = buf_index;
- q6asm_set_flag_in_token(&asm_token, dir, ASM_DIRECTION_OFFSET);
- q6asm_set_flag_in_token(&asm_token, nowait_flag,
- ASM_CMD_NO_WAIT_OFFSET);
- *token = asm_token.token;
- }
- static inline uint32_t q6asm_get_pcm_format_id(uint32_t media_format_block_ver)
- {
- uint32_t pcm_format_id;
- switch (media_format_block_ver) {
- case PCM_MEDIA_FORMAT_V4:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V4;
- break;
- case PCM_MEDIA_FORMAT_V3:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- case PCM_MEDIA_FORMAT_V2:
- default:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- }
- return pcm_format_id;
- }
- /*
- * q6asm_get_buf_index_from_token:
- * Retrieve buffer index from token.
- *
- * @token: token value sent to ASM service on q6.
- * Returns buffer index in the read/write commands.
- */
- uint8_t q6asm_get_buf_index_from_token(uint32_t token)
- {
- union asm_token_struct asm_token;
- asm_token.token = token;
- return asm_token._token.buf_index;
- }
- EXPORT_SYMBOL(q6asm_get_buf_index_from_token);
- /*
- * q6asm_get_stream_id_from_token:
- * Retrieve stream id from token.
- *
- * @token: token value sent to ASM service on q6.
- * Returns stream id.
- */
- uint8_t q6asm_get_stream_id_from_token(uint32_t token)
- {
- union asm_token_struct asm_token;
- asm_token.token = token;
- return asm_token._token.stream_id;
- }
- EXPORT_SYMBOL(q6asm_get_stream_id_from_token);
- static int audio_output_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_output_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (out_buffer == NULL) {
- pr_err("%s: out_buffer is null\n", __func__);
- return 0;
- }
- snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",
- out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,
- out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
- out_buffer, OUT_BUFFER_SIZE);
- }
- static ssize_t audio_output_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char)) {
- pr_err("%s: err count is more %zd\n", __func__, count);
- return -EINVAL;
- }
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- out_cold_index = 0;
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- pr_err("%s: copy from user failed for size %zd\n",
- __func__, 2*sizeof(char));
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &out_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_output_latency_debug_fops = {
- .open = audio_output_latency_dbgfs_open,
- .read = audio_output_latency_dbgfs_read,
- .write = audio_output_latency_dbgfs_write
- };
- static int audio_input_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_input_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (in_buffer == NULL) {
- pr_err("%s: in_buffer is null\n", __func__);
- return 0;
- }
- snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
- in_buffer, IN_BUFFER_SIZE);
- }
- static ssize_t audio_input_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char)) {
- pr_err("%s: err count is more %zd\n", __func__, count);
- return -EINVAL;
- }
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- pr_err("%s: copy from user failed for size %zd\n",
- __func__, 2*sizeof(char));
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &in_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_input_latency_debug_fops = {
- .open = audio_input_latency_dbgfs_open,
- .read = audio_input_latency_dbgfs_read,
- .write = audio_input_latency_dbgfs_write
- };
- static void config_debug_fs_write_cb(void)
- {
- if (out_enable_flag) {
- /* For first Write done log the time and reset
- * out_cold_index
- */
- if (out_cold_index != 1) {
- do_gettimeofday(&out_cold_tv);
- pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
- out_cold_tv.tv_sec,
- out_cold_tv.tv_usec);
- out_cold_index = 1;
- }
- pr_debug("%s: out_enable_flag %ld\n",
- __func__, out_enable_flag);
- }
- }
- static void config_debug_fs_read_cb(void)
- {
- if (in_enable_flag) {
- /* when in_cont_index == 7, DSP would be
- * writing into the 8th 512 byte buffer and this
- * timestamp is tapped here.Once done it then writes
- * to 9th 512 byte buffer.These two buffers(8th, 9th)
- * reach the test application in 5th iteration and that
- * timestamp is tapped at user level. The difference
- * of these two timestamps gives us the time between
- * the time at which dsp started filling the sample
- * required and when it reached the test application.
- * Hence continuous input latency
- */
- if (in_cont_index == 7) {
- do_gettimeofday(&in_cont_tv);
- pr_info("%s: read buffer at %ld sec %ld microsec\n",
- __func__,
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- }
- in_cont_index++;
- }
- }
- static void config_debug_fs_reset_index(void)
- {
- in_cont_index = 0;
- }
- static void config_debug_fs_run(void)
- {
- if (out_enable_flag) {
- do_gettimeofday(&out_cold_tv);
- pr_debug("%s: COLD apr_send_pkt at %ld sec %ld microsec\n",
- __func__, out_cold_tv.tv_sec, out_cold_tv.tv_usec);
- }
- }
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- if (out_enable_flag) {
- char zero_pattern[2] = {0x00, 0x00};
- /* If First two byte is non zero and last two byte
- * is zero then it is warm output pattern
- */
- if ((strcmp(((char *)ab->data), zero_pattern)) &&
- (!strcmp(((char *)ab->data + 2), zero_pattern))) {
- do_gettimeofday(&out_warm_tv);
- pr_debug("%s: WARM:apr_send_pkt at %ld sec %ld microsec\n",
- __func__,
- out_warm_tv.tv_sec,
- out_warm_tv.tv_usec);
- pr_debug("%s: Warm Pattern Matched\n", __func__);
- }
- /* If First two byte is zero and last two byte is
- * non zero then it is cont output pattern
- */
- else if ((!strcmp(((char *)ab->data), zero_pattern))
- && (strcmp(((char *)ab->data + 2), zero_pattern))) {
- do_gettimeofday(&out_cont_tv);
- pr_debug("%s: CONT:apr_send_pkt at %ld sec %ld microsec\n",
- __func__,
- out_cont_tv.tv_sec,
- out_cont_tv.tv_usec);
- pr_debug("%s: Cont Pattern Matched\n", __func__);
- }
- }
- }
- static void config_debug_fs_init(void)
- {
- out_buffer = kzalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
- if (out_buffer == NULL)
- goto outbuf_fail;
- in_buffer = kzalloc(IN_BUFFER_SIZE, GFP_KERNEL);
- if (in_buffer == NULL)
- goto inbuf_fail;
- out_dentry = debugfs_create_file("audio_out_latency_measurement_node",
- 0664,
- NULL, NULL, &audio_output_latency_debug_fops);
- if (IS_ERR(out_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- in_dentry = debugfs_create_file("audio_in_latency_measurement_node",
- 0664,
- NULL, NULL, &audio_input_latency_debug_fops);
- if (IS_ERR(in_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- return;
- file_fail:
- kfree(in_buffer);
- inbuf_fail:
- kfree(out_buffer);
- outbuf_fail:
- in_buffer = NULL;
- out_buffer = NULL;
- }
- #else
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- }
- static void config_debug_fs_run(void)
- {
- }
- static void config_debug_fs_reset_index(void)
- {
- }
- static void config_debug_fs_read_cb(void)
- {
- }
- static void config_debug_fs_write_cb(void)
- {
- }
- static void config_debug_fs_init(void)
- {
- }
- #endif
- int q6asm_mmap_apr_dereg(void)
- {
- int c;
- c = atomic_sub_return(1, &this_mmap.ref_cnt);
- if (c == 0) {
- apr_deregister(this_mmap.apr);
- common_client.mmap_apr = NULL;
- pr_debug("%s: APR De-Register common port\n", __func__);
- } else if (c < 0) {
- pr_err("%s: APR Common Port Already Closed %d\n",
- __func__, c);
- atomic_set(&this_mmap.ref_cnt, 0);
- }
- return 0;
- }
- static int q6asm_session_alloc(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= ASM_ACTIVE_STREAMS_ALLOWED; n++) {
- if (!session[n]) {
- session[n] = ac;
- return n;
- }
- }
- pr_err("%s: session not available\n", __func__);
- return -ENOMEM;
- }
- static bool q6asm_is_valid_audio_client(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= ASM_ACTIVE_STREAMS_ALLOWED; n++) {
- if (session[n] == ac)
- return 1;
- }
- return 0;
- }
- static void q6asm_session_free(struct audio_client *ac)
- {
- pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
- rtac_remove_popp_from_adm_devices(ac->session);
- session[ac->session] = 0;
- ac->session = 0;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- }
- static uint32_t q6asm_get_next_buf(struct audio_client *ac,
- uint32_t curr_buf, uint32_t max_buf_cnt)
- {
- dev_vdbg(ac->dev, "%s: curr_buf = %d, max_buf_cnt = %d\n",
- __func__, curr_buf, max_buf_cnt);
- curr_buf += 1;
- return (curr_buf >= max_buf_cnt) ? 0 : curr_buf;
- }
- static int q6asm_map_cal_memory(int32_t cal_type,
- struct cal_block_data *cal_block)
- {
- int result = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- goto done;
- }
- if (cal_block->cal_data.paddr == 0) {
- pr_debug("%s: No address to map!\n",
- __func__);
- goto done;
- }
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- common_client.apr = common_client.mmap_apr;
- if (cal_block->map_data.map_size == 0) {
- pr_debug("%s: map size is 0!\n",
- __func__);
- goto done;
- }
- /* Use second asm buf to map memory */
- if (common_client.port[IN].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- common_client.port[IN].buf->phys = cal_block->cal_data.paddr;
- result = q6asm_memory_map_regions(&common_client,
- IN, cal_block->map_data.map_size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! size = %zd result %d\n",
- __func__,
- cal_block->map_data.map_size, result);
- pr_debug("%s: mmap did not work! addr = 0x%pK, size = %zd\n",
- __func__,
- &cal_block->cal_data.paddr,
- cal_block->map_data.map_size);
- goto done;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == cal_block->cal_data.paddr) {
- cal_block->map_data.q6map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- done:
- return result;
- }
- static int remap_cal_data(int32_t cal_type, struct cal_block_data *cal_block)
- {
- int ret = 0;
- if (cal_block->map_data.ion_client == NULL) {
- pr_err("%s: No ION allocation for cal type %d!\n",
- __func__, cal_type);
- ret = -EINVAL;
- goto done;
- }
- if ((cal_block->map_data.map_size > 0) &&
- (cal_block->map_data.q6map_handle == 0)) {
- ret = q6asm_map_cal_memory(cal_type, cal_block);
- if (ret < 0) {
- pr_err("%s: mmap did not work! size = %zd ret %d\n",
- __func__, cal_block->map_data.map_size, ret);
- goto done;
- }
- }
- done:
- return ret;
- }
- static int q6asm_unmap_cal_memory(int32_t cal_type,
- struct cal_block_data *cal_block)
- {
- int result = 0;
- int result2 = 0;
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (cal_block->map_data.q6map_handle == 0) {
- pr_debug("%s: No address to unmap!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, IN);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- }
- cal_block->map_data.q6map_handle = 0;
- done:
- return result;
- }
- int q6asm_unmap_cal_data(int cal_type, struct cal_block_data *cal_block)
- {
- int ret = 0;
- if ((cal_block->map_data.map_size > 0) &&
- (cal_block->map_data.q6map_handle != 0)) {
- ret = q6asm_unmap_cal_memory(cal_type, cal_block);
- if (ret < 0) {
- pr_err("%s: unmap did not work! size = %zd ret %d\n",
- __func__, cal_block->map_data.map_size, ret);
- goto done;
- }
- }
- done:
- return ret;
- }
- int send_asm_custom_topology(struct audio_client *ac)
- {
- struct cal_block_data *cal_block = NULL;
- struct cmd_set_topologies asm_top;
- int result = 0;
- int result1 = 0;
- if (cal_data[ASM_CUSTOM_TOP_CAL] == NULL)
- goto done;
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- if (!set_custom_topology)
- goto unlock;
- set_custom_topology = 0;
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_CUSTOM_TOP_CAL]);
- if (cal_block == NULL)
- goto unlock;
- if (cal_block->cal_data.size == 0) {
- pr_debug("%s: No cal to send!\n", __func__);
- goto unlock;
- }
- pr_debug("%s: Sending cal_index %d\n", __func__, ASM_CUSTOM_TOP_CAL);
- result = remap_cal_data(ASM_CUST_TOPOLOGY_CAL_TYPE, cal_block);
- if (result) {
- pr_err("%s: Remap_cal_data failed for cal %d!\n",
- __func__, ASM_CUSTOM_TOP_CAL);
- goto unlock;
- }
- q6asm_add_hdr_custom_topology(ac, &asm_top.hdr, sizeof(asm_top));
- atomic_set(&ac->mem_state, -1);
- asm_top.hdr.opcode = ASM_CMD_ADD_TOPOLOGIES;
- asm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
- asm_top.payload_addr_msw = msm_audio_populate_upper_32_bits(
- cal_block->cal_data.paddr);
- asm_top.mem_map_handle = cal_block->map_data.q6map_handle;
- asm_top.payload_size = cal_block->cal_data.size;
- pr_debug("%s: Sending ASM_CMD_ADD_TOPOLOGIES payload = %pK, size = %d, map handle = 0x%x\n",
- __func__, &cal_block->cal_data.paddr,
- asm_top.payload_size, asm_top.mem_map_handle);
- result = apr_send_pkt(ac->apr, (uint32_t *) &asm_top);
- if (result < 0) {
- pr_err("%s: Set topologies failed result %d\n",
- __func__, result);
- pr_debug("%s: Set topologies failed payload = 0x%pK\n",
- __func__, &cal_block->cal_data.paddr);
- goto unmap;
- }
- result = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0), 5*HZ);
- if (!result) {
- pr_err("%s: Set topologies failed timeout\n", __func__);
- pr_debug("%s: Set topologies failed after timedout payload = 0x%pK\n",
- __func__, &cal_block->cal_data.paddr);
- result = -ETIMEDOUT;
- goto unmap;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- result = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto unmap;
- }
- unmap:
- result1 = q6asm_unmap_cal_memory(ASM_CUST_TOPOLOGY_CAL_TYPE,
- cal_block);
- if (result1 < 0) {
- result = result1;
- pr_debug("%s: unmap cal failed! %d\n", __func__, result);
- }
- unlock:
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- done:
- return result;
- }
- int q6asm_map_rtac_block(struct rtac_cal_block_data *cal_block)
- {
- int result = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- pr_debug("%s:\n", __func__);
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (cal_block->cal_data.paddr == 0) {
- pr_debug("%s: No address to map!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- if (cal_block->map_data.map_size == 0) {
- pr_debug("%s: map size is 0!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- /* Use second asm buf to map memory */
- if (common_client.port[OUT].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- common_client.port[OUT].buf->phys = cal_block->cal_data.paddr;
- result = q6asm_memory_map_regions(&common_client,
- OUT, cal_block->map_data.map_size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! size = %d result %d\n",
- __func__,
- cal_block->map_data.map_size, result);
- pr_debug("%s: mmap did not work! addr = 0x%pK, size = %d\n",
- __func__,
- &cal_block->cal_data.paddr,
- cal_block->map_data.map_size);
- goto done;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == cal_block->cal_data.paddr) {
- cal_block->map_data.map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- done:
- return result;
- }
- int q6asm_unmap_rtac_block(uint32_t *mem_map_handle)
- {
- int result = 0;
- int result2 = 0;
- pr_debug("%s:\n", __func__);
- if (mem_map_handle == NULL) {
- pr_debug("%s: Map handle is NULL, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (*mem_map_handle == 0) {
- pr_debug("%s: Map handle is 0, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, OUT);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- mem_map_handle = 0;
- }
- result2 = q6asm_mmap_apr_dereg();
- if (result2 < 0) {
- pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
- __func__, result2);
- result = result2;
- }
- done:
- return result;
- }
- int q6asm_audio_client_buf_free(unsigned int dir,
- struct audio_client *ac)
- {
- struct audio_port_data *port;
- int cnt = 0;
- int rc = 0;
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- mutex_lock(&ac->cmd_lock);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- if (!port->buf) {
- pr_err("%s: buf NULL\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- cnt = port->max_buf_cnt - 1;
- if (cnt >= 0) {
- rc = q6asm_memory_unmap_regions(ac, dir);
- if (rc < 0)
- pr_err("%s: Memory_unmap_regions failed %d\n",
- __func__, rc);
- }
- while (cnt >= 0) {
- if (port->buf[cnt].data) {
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(
- port->buf[cnt].client,
- port->buf[cnt].handle);
- port->buf[cnt].client = NULL;
- port->buf[cnt].handle = NULL;
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- --(port->max_buf_cnt);
- }
- --cnt;
- }
- kfree(port->buf);
- port->buf = NULL;
- }
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
- struct audio_client *ac)
- {
- struct audio_port_data *port;
- int cnt = 0;
- int rc = 0;
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- mutex_lock(&ac->cmd_lock);
- port = &ac->port[dir];
- if (!port->buf) {
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- cnt = port->max_buf_cnt - 1;
- if (cnt >= 0) {
- rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
- if (rc < 0)
- pr_err("%s: Memory_unmap_regions failed %d\n",
- __func__, rc);
- }
- if (port->buf[0].data) {
- pr_debug("%s: data[%pK]phys[%pK][%pK] , client[%pK] handle[%pK]\n",
- __func__,
- port->buf[0].data,
- &port->buf[0].phys,
- &port->buf[0].phys,
- port->buf[0].client,
- port->buf[0].handle);
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(port->buf[0].client,
- port->buf[0].handle);
- port->buf[0].client = NULL;
- port->buf[0].handle = NULL;
- }
- while (cnt >= 0) {
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- cnt--;
- }
- port->max_buf_cnt = 0;
- kfree(port->buf);
- port->buf = NULL;
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- void q6asm_audio_client_free(struct audio_client *ac)
- {
- int loopcnt;
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: ac %pK\n", __func__, ac);
- return;
- }
- if (!ac->session) {
- pr_err("%s: ac session invalid\n", __func__);
- return;
- }
- mutex_lock(&session_lock);
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- if (ac->io_mode & SYNC_IO_MODE) {
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- if (!port->buf)
- continue;
- pr_debug("%s: loopcnt = %d\n",
- __func__, loopcnt);
- q6asm_audio_client_buf_free(loopcnt, ac);
- }
- }
- rtac_set_asm_handle(ac->session, NULL);
- apr_deregister(ac->apr2);
- apr_deregister(ac->apr);
- q6asm_mmap_apr_dereg();
- ac->apr2 = NULL;
- ac->apr = NULL;
- ac->mmap_apr = NULL;
- q6asm_session_free(ac);
- pr_debug("%s: APR De-Register\n", __func__);
- /*done:*/
- kfree(ac);
- ac = NULL;
- mutex_unlock(&session_lock);
- }
- int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode1)
- {
- uint32_t mode;
- int ret = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- ac->io_mode &= 0xFF00;
- mode = (mode1 & 0xF);
- pr_debug("%s: ac->mode after anding with FF00:0x%x,\n",
- __func__, ac->io_mode);
- if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
- ac->io_mode |= mode1;
- pr_debug("%s: Set Mode to 0x%x\n", __func__, ac->io_mode);
- } else {
- pr_err("%s: Not an valid IO Mode:%d\n", __func__, ac->io_mode);
- ret = -EINVAL;
- }
- return ret;
- }
- void *q6asm_mmap_apr_reg(void)
- {
- if ((atomic_read(&this_mmap.ref_cnt) == 0) ||
- (this_mmap.apr == NULL)) {
- this_mmap.apr = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_srvc_callback,
- 0x0FFFFFFFF, &this_mmap);
- if (this_mmap.apr == NULL) {
- pr_debug("%s: Unable to register APR ASM common port\n",
- __func__);
- goto fail;
- }
- }
- atomic_inc(&this_mmap.ref_cnt);
- return this_mmap.apr;
- fail:
- return NULL;
- }
- int q6asm_send_stream_cmd(struct audio_client *ac,
- struct msm_adsp_event_data *data)
- {
- char *asm_params = NULL;
- struct apr_hdr hdr;
- int sz, rc;
- if (!data || !ac) {
- pr_err("%s: %s is NULL\n", __func__,
- (!data) ? "data" : "ac");
- rc = -EINVAL;
- goto done;
- }
- if (data->event_type >= ARRAY_SIZE(adsp_reg_event_opcode)) {
- pr_err("%s: event %u out of boundary of array size of (%lu)\n",
- __func__, data->event_type,
- (long)ARRAY_SIZE(adsp_reg_event_opcode));
- rc = -EINVAL;
- goto done;
- }
- sz = sizeof(struct apr_hdr) + data->payload_len;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- rc = -ENOMEM;
- goto done;
- }
- q6asm_add_hdr_async(ac, &hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- hdr.opcode = adsp_reg_event_opcode[data->event_type];
- memcpy(asm_params, &hdr, sizeof(struct apr_hdr));
- memcpy(asm_params + sizeof(struct apr_hdr),
- data->payload, data->payload_len);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: stream event cmd apr pkt failed\n", __func__);
- rc = -EINVAL;
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 1 * HZ);
- if (!rc) {
- pr_err("%s: timeout for stream event cmd resp\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_send_param;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] for stream event cmd\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- kfree(asm_params);
- done:
- return rc;
- }
- struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
- {
- struct audio_client *ac;
- int n;
- int lcnt = 0;
- int rc = 0;
- ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
- if (!ac)
- return NULL;
- mutex_lock(&session_lock);
- n = q6asm_session_alloc(ac);
- if (n <= 0) {
- pr_err("%s: ASM Session alloc fail n=%d\n", __func__, n);
- mutex_unlock(&session_lock);
- goto fail_session;
- }
- ac->session = n;
- ac->cb = cb;
- ac->path_delay = UINT_MAX;
- ac->priv = priv;
- ac->io_mode = SYNC_IO_MODE;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- /* DSP expects stream id from 1 */
- ac->stream_id = 1;
- ac->apr = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_callback,
- ((ac->session) << 8 | 0x0001),
- ac);
- if (ac->apr == NULL) {
- pr_err("%s: Registration with APR failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr1;
- }
- ac->apr2 = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_callback,
- ((ac->session) << 8 | 0x0002),
- ac);
- if (ac->apr2 == NULL) {
- pr_err("%s: Registration with APR-2 failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr2;
- }
- rtac_set_asm_handle(n, ac->apr);
- pr_debug("%s: Registering the common port with APR\n", __func__);
- ac->mmap_apr = q6asm_mmap_apr_reg();
- if (ac->mmap_apr == NULL) {
- mutex_unlock(&session_lock);
- goto fail_mmap;
- }
- init_waitqueue_head(&ac->cmd_wait);
- init_waitqueue_head(&ac->time_wait);
- init_waitqueue_head(&ac->mem_wait);
- atomic_set(&ac->time_flag, 1);
- atomic_set(&ac->reset, 0);
- INIT_LIST_HEAD(&ac->port[0].mem_map_handle);
- INIT_LIST_HEAD(&ac->port[1].mem_map_handle);
- pr_debug("%s: mem_map_handle list init'ed\n", __func__);
- mutex_init(&ac->cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&ac->port[lcnt].lock);
- spin_lock_init(&ac->port[lcnt].dsp_lock);
- }
- atomic_set(&ac->cmd_state, 0);
- atomic_set(&ac->cmd_state_pp, 0);
- atomic_set(&ac->mem_state, 0);
- rc = send_asm_custom_topology(ac);
- if (rc < 0) {
- mutex_unlock(&session_lock);
- goto fail_mmap;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- mutex_unlock(&session_lock);
- return ac;
- fail_mmap:
- apr_deregister(ac->apr2);
- fail_apr2:
- apr_deregister(ac->apr);
- fail_apr1:
- q6asm_session_free(ac);
- fail_session:
- kfree(ac);
- return NULL;
- }
- struct audio_client *q6asm_get_audio_client(int session_id)
- {
- if (session_id == ASM_CONTROL_SESSION)
- return &common_client;
- if ((session_id <= 0) || (session_id > ASM_ACTIVE_STREAMS_ALLOWED)) {
- pr_err("%s: invalid session: %d\n", __func__, session_id);
- goto err;
- }
- if (!session[session_id]) {
- pr_err("%s: session not active: %d\n", __func__, session_id);
- goto err;
- }
- return session[session_id];
- err:
- return NULL;
- }
- int q6asm_audio_client_buf_alloc(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- uint32_t bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- if (!(ac) || !(bufsz) || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK bufsz %d dir %d\n", __func__, ac, bufsz,
- dir);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > 8) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- ac->session);
- goto fail;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- if (ac->port[dir].buf) {
- pr_debug("%s: buffer already allocated\n", __func__);
- return 0;
- }
- mutex_lock(&ac->cmd_lock);
- if (bufcnt > (U32_MAX/sizeof(struct audio_buffer))) {
- pr_err("%s: Buffer size overflows", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- if (!buf[cnt].data) {
- rc = msm_audio_ion_alloc("asm_client",
- &buf[cnt].client, &buf[cnt].handle,
- bufsz,
- (ion_phys_addr_t *)&buf[cnt].phys,
- &len,
- &buf[cnt].data);
- if (rc) {
- pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s: data[%pK]phys[%pK][%pK]\n",
- __func__,
- buf[cnt].data,
- &buf[cnt].phys,
- &buf[cnt].phys);
- cnt++;
- }
- }
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 0);
- if (rc < 0) {
- pr_err("%s: CMD Memory_map_regions failed %d for size %d\n",
- __func__, rc, bufsz);
- goto fail;
- }
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free(dir, ac);
- return -EINVAL;
- }
- int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- unsigned int bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- int bytes_to_alloc;
- if (!(ac) || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
- __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > 8) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- ac->session);
- goto fail;
- }
- if (ac->port[dir].buf) {
- pr_err("%s: buffer already allocated\n", __func__);
- return 0;
- }
- mutex_lock(&ac->cmd_lock);
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- pr_err("%s: buffer allocation failed\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- /* check for integer overflow */
- if ((bufcnt > 0) && ((INT_MAX / bufcnt) < bufsz)) {
- pr_err("%s: integer overflow\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- bytes_to_alloc = bufsz * bufcnt;
- /* The size to allocate should be multiple of 4K bytes */
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc("asm_client", &buf[0].client, &buf[0].handle,
- bytes_to_alloc,
- (ion_phys_addr_t *)&buf[0].phys, &len,
- &buf[0].data);
- if (rc) {
- pr_err("%s: Audio ION alloc is failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].used = dir ^ 1;
- buf[0].size = bufsz;
- buf[0].actual_size = bufsz;
- cnt = 1;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- buf[cnt].data = buf[0].data + (cnt * bufsz);
- buf[cnt].phys = buf[0].phys + (cnt * bufsz);
- if (!buf[cnt].data) {
- pr_err("%s: Buf alloc failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = dir ^ 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s: data[%pK]phys[%pK][%pK]\n",
- __func__,
- buf[cnt].data,
- &buf[cnt].phys,
- &buf[cnt].phys);
- }
- cnt++;
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 1);
- if (rc < 0) {
- pr_err("%s: CMD Memory_map_regions failed %d for size %d\n",
- __func__, rc, bufsz);
- goto fail;
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free_contiguous(dir, ac);
- return -EINVAL;
- }
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv)
- {
- uint32_t dir = 0;
- uint32_t i = IN;
- uint32_t *payload;
- unsigned long dsp_flags;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- union asm_token_struct asm_token;
- struct audio_client *ac = NULL;
- struct audio_port_data *port;
- if (!data) {
- pr_err("%s: Invalid CB\n", __func__);
- return 0;
- }
- payload = data->payload;
- if (data->opcode == RESET_EVENTS) {
- pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
- __func__,
- data->reset_event,
- data->reset_proc,
- this_mmap.apr);
- atomic_set(&this_mmap.ref_cnt, 0);
- apr_reset(this_mmap.apr);
- this_mmap.apr = NULL;
- for (; i <= OUT; i++) {
- list_for_each_safe(ptr, next,
- &common_client.port[i].mem_map_handle) {
- buf_node = list_entry(ptr,
- struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr ==
- common_client.port[i].buf->phys) {
- list_del(&buf_node->list);
- kfree(buf_node);
- }
- }
- pr_debug("%s: Clearing custom topology\n", __func__);
- }
- cal_utils_clear_cal_block_q6maps(ASM_MAX_CAL_TYPES, cal_data);
- common_client.mmap_apr = NULL;
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- set_custom_topology = 1;
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- topology_map_handle = 0;
- rtac_clear_mapping(ASM_RTAC_CAL);
- return 0;
- }
- asm_token.token = data->token;
- ac = q6asm_get_audio_client(asm_token._token.session_id);
- dir = q6asm_get_flag_from_token(&asm_token, ASM_DIRECTION_OFFSET);
- if (!ac) {
- pr_debug("%s: session[%d] already freed\n",
- __func__, asm_token._token.session_id);
- return 0;
- }
- if (data->payload_size > sizeof(int)) {
- pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
- __func__, payload[0], payload[1], data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port, asm_token._token.session_id, dir);
- pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- } else if (data->payload_size == sizeof(int)) {
- pr_debug("%s:ptr0[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
- __func__, payload[0], data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port, asm_token._token.session_id, dir);
- pr_debug("%s:Payload = [0x%x]\n",
- __func__, payload[0]);
- }
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- switch (payload[0]) {
- case ASM_CMD_SHARED_MEM_MAP_REGIONS:
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:
- case ASM_CMD_ADD_TOPOLOGIES:
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x sid:%d\n",
- __func__, payload[0], payload[1],
- asm_token._token.session_id);
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 0);
- atomic_set(&ac->mem_state, payload[1]);
- wake_up(&ac->mem_wait);
- } else {
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 1);
- }
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1)
- wake_up(&ac->mem_wait);
- dev_vdbg(ac->dev, "%s: Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- break;
- default:
- pr_debug("%s: command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- return 0;
- }
- port = &ac->port[dir];
- switch (data->opcode) {
- case ASM_CMDRSP_SHARED_MEM_MAP_REGIONS:{
- pr_debug("%s:PL#0[0x%x] dir=0x%x s_id=0x%x\n",
- __func__, payload[0], dir, asm_token._token.session_id);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1) {
- ac->port[dir].tmp_hdl = payload[0];
- wake_up(&ac->mem_wait);
- }
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:{
- pr_debug("%s: PL#0[0x%x]PL#1 [0x%x]\n",
- __func__, payload[0], payload[1]);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1)
- wake_up(&ac->mem_wait);
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- default:
- pr_debug("%s: command[0x%x]success [0x%x]\n",
- __func__, payload[0], payload[1]);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- return 0;
- }
- static void q6asm_process_mtmx_get_param_rsp(struct audio_client *ac,
- struct asm_mtmx_strtr_get_params_cmdrsp *cmdrsp)
- {
- struct asm_session_mtmx_strtr_param_session_time_v3_t *time;
- if (cmdrsp->err_code) {
- dev_err_ratelimited(ac->dev,
- "%s: err=%x, mod_id=%x, param_id=%x\n",
- __func__, cmdrsp->err_code,
- cmdrsp->param_info.module_id,
- cmdrsp->param_info.param_id);
- return;
- }
- dev_dbg_ratelimited(ac->dev,
- "%s: mod_id=%x, param_id=%x\n", __func__,
- cmdrsp->param_info.module_id,
- cmdrsp->param_info.param_id);
- switch (cmdrsp->param_info.module_id) {
- case ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC:
- switch (cmdrsp->param_info.param_id) {
- case ASM_SESSION_MTMX_STRTR_PARAM_SESSION_TIME_V3:
- time = &cmdrsp->param_data.session_time;
- dev_vdbg(ac->dev, "%s: GET_TIME_V3, time_lsw=%x, time_msw=%x\n",
- __func__, time->session_time_lsw,
- time->session_time_msw);
- ac->time_stamp = (uint64_t)(((uint64_t)
- time->session_time_msw << 32) |
- time->session_time_lsw);
- if (time->flags &
- ASM_SESSION_MTMX_STRTR_PARAM_STIME_TSTMP_FLG_BMASK)
- dev_warn_ratelimited(ac->dev,
- "%s: recv inval tstmp\n",
- __func__);
- if (atomic_cmpxchg(&ac->time_flag, 1, 0))
- wake_up(&ac->time_wait);
- break;
- default:
- dev_err(ac->dev, "%s: unexpected param_id %x\n",
- __func__, cmdrsp->param_info.param_id);
- break;
- }
- break;
- default:
- dev_err(ac->dev, "%s: unexpected mod_id %x\n", __func__,
- cmdrsp->param_info.module_id);
- break;
- }
- }
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
- {
- int i = 0;
- struct audio_client *ac = (struct audio_client *)priv;
- unsigned long dsp_flags;
- uint32_t *payload;
- uint32_t wakeup_flag = 1;
- int32_t ret = 0;
- union asm_token_struct asm_token;
- uint8_t buf_index;
- struct msm_adsp_event_data *pp_event_package = NULL;
- uint32_t payload_size = 0;
- if (ac == NULL) {
- pr_err("%s: ac NULL\n", __func__);
- return -EINVAL;
- }
- if (data == NULL) {
- pr_err("%s: data NULL\n", __func__);
- return -EINVAL;
- }
- if (!q6asm_is_valid_audio_client(ac)) {
- pr_err("%s: audio client pointer is invalid, ac = %pK\n",
- __func__, ac);
- return -EINVAL;
- }
- if (ac->session <= 0 || ac->session > 8) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- ac->session);
- return -EINVAL;
- }
- payload = data->payload;
- asm_token.token = data->token;
- if (q6asm_get_flag_from_token(&asm_token, ASM_CMD_NO_WAIT_OFFSET)) {
- pr_debug("%s: No wait command opcode[0x%x] cmd_opcode:%x\n",
- __func__, data->opcode, payload ? payload[0] : 0);
- wakeup_flag = 0;
- }
- if (data->opcode == RESET_EVENTS) {
- mutex_lock(&ac->cmd_lock);
- atomic_set(&ac->reset, 1);
- if (ac->apr == NULL) {
- ac->apr = ac->apr2;
- ac->apr2 = NULL;
- }
- pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
- __func__,
- data->reset_event, data->reset_proc, ac->apr);
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- apr_reset(ac->apr);
- ac->apr = NULL;
- atomic_set(&ac->time_flag, 0);
- atomic_set(&ac->cmd_state, 0);
- atomic_set(&ac->mem_state, 0);
- atomic_set(&ac->cmd_state_pp, 0);
- wake_up(&ac->time_wait);
- wake_up(&ac->cmd_wait);
- wake_up(&ac->mem_wait);
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- dev_vdbg(ac->dev, "%s: session[%d]opcode[0x%x] token[0x%x]payload_size[%d] src[%d] dest[%d]\n",
- __func__,
- ac->session, data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port);
- if ((data->opcode != ASM_DATA_EVENT_RENDERED_EOS) &&
- (data->opcode != ASM_DATA_EVENT_EOS) &&
- (data->opcode != ASM_SESSION_EVENT_RX_UNDERFLOW)) {
- if (payload == NULL) {
- pr_err("%s: payload is null\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: Payload = [0x%x] status[0x%x] opcode 0x%x\n",
- __func__, payload[0], payload[1], data->opcode);
- }
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- switch (payload[0]) {
- case ASM_STREAM_CMD_SET_PP_PARAMS_V2:
- if (rtac_make_asm_callback(ac->session, payload,
- data->payload_size))
- break;
- case ASM_SESSION_CMD_PAUSE:
- case ASM_SESSION_CMD_SUSPEND:
- case ASM_DATA_CMD_EOS:
- case ASM_STREAM_CMD_CLOSE:
- case ASM_STREAM_CMD_FLUSH:
- case ASM_SESSION_CMD_RUN_V2:
- case ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS:
- case ASM_STREAM_CMD_FLUSH_READBUFS:
- pr_debug("%s: session %d opcode 0x%x token 0x%x Payload = [0x%x] src %d dest %d\n",
- __func__, ac->session, data->opcode, data->token,
- payload[0], data->src_port, data->dest_port);
- ret = q6asm_is_valid_session(data, priv);
- if (ret != 0) {
- pr_err("%s: session invalid %d\n", __func__, ret);
- return ret;
- }
- case ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2:
- case ASM_STREAM_CMD_OPEN_READ_V3:
- case ASM_STREAM_CMD_OPEN_WRITE_V3:
- case ASM_STREAM_CMD_OPEN_PULL_MODE_WRITE:
- case ASM_STREAM_CMD_OPEN_PUSH_MODE_READ:
- case ASM_STREAM_CMD_OPEN_READWRITE_V2:
- case ASM_STREAM_CMD_OPEN_LOOPBACK_V2:
- case ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK:
- case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
- case ASM_DATA_CMD_IEC_60958_MEDIA_FMT:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2:
- case ASM_STREAM_CMD_REGISTER_ENCDEC_EVENTS:
- case ASM_STREAM_CMD_REGISTER_IEC_61937_FMT_UPDATE:
- case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
- case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
- case ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS:
- case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
- pr_debug("%s: session %d opcode 0x%x token 0x%x Payload = [0x%x] stat 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- payload[0], payload[1],
- data->src_port, data->dest_port);
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
- __func__, payload[0], payload[1]);
- if (wakeup_flag) {
- if ((is_adsp_reg_event(payload[0]) >= 0)
- || (payload[0] ==
- ASM_STREAM_CMD_SET_PP_PARAMS_V2))
- atomic_set(&ac->cmd_state_pp,
- payload[1]);
- else
- atomic_set(&ac->cmd_state,
- payload[1]);
- wake_up(&ac->cmd_wait);
- }
- return 0;
- }
- if ((is_adsp_reg_event(payload[0]) >= 0) ||
- (payload[0] == ASM_STREAM_CMD_SET_PP_PARAMS_V2)) {
- if (atomic_read(&ac->cmd_state_pp) &&
- wakeup_flag) {
- atomic_set(&ac->cmd_state_pp, 0);
- wake_up(&ac->cmd_wait);
- }
- } else {
- if (atomic_read(&ac->cmd_state) &&
- wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->cmd_wait);
- }
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_CMD_ADD_TOPOLOGIES:
- pr_debug("%s:Payload = [0x%x]stat[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
- __func__, payload[0], payload[1]);
- if (wakeup_flag) {
- atomic_set(&ac->mem_state, payload[1]);
- wake_up(&ac->mem_wait);
- }
- return 0;
- }
- if (atomic_read(&ac->mem_state) && wakeup_flag) {
- atomic_set(&ac->mem_state, 0);
- wake_up(&ac->mem_wait);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_DATA_EVENT_WATERMARK: {
- pr_debug("%s: Watermark opcode[0x%x] status[0x%x]",
- __func__, payload[0], payload[1]);
- break;
- }
- case ASM_STREAM_CMD_GET_PP_PARAMS_V2:
- pr_debug("%s: ASM_STREAM_CMD_GET_PP_PARAMS_V2 session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- /* Should only come here if there is an APR */
- /* error or malformed APR packet. Otherwise */
- /* response will be returned as */
- /* ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 */
- if (payload[1] != 0) {
- pr_err("%s: ASM get param error = %d, resuming\n",
- __func__, payload[1]);
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- }
- break;
- case ASM_STREAM_CMD_REGISTER_PP_EVENTS:
- pr_debug("%s: ASM_STREAM_CMD_REGISTER_PP_EVENTS session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- if (payload[1] != 0)
- pr_err("%s: ASM get param error = %d, resuming\n",
- __func__, payload[1]);
- atomic_set(&ac->cmd_state_pp, payload[1]);
- wake_up(&ac->cmd_wait);
- break;
- default:
- pr_debug("%s: command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- return 0;
- }
- switch (data->opcode) {
- case ASM_DATA_EVENT_WRITE_DONE_V2:{
- struct audio_port_data *port = &ac->port[IN];
- dev_vdbg(ac->dev, "%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
- __func__, payload[0], payload[1],
- data->token);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Write Done\n",
- __func__);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- buf_index = asm_token._token.buf_index;
- if (lower_32_bits(port->buf[buf_index].phys) !=
- payload[0] ||
- msm_audio_populate_upper_32_bits(
- port->buf[buf_index].phys) != payload[1]) {
- pr_debug("%s: Expected addr %pK\n",
- __func__, &port->buf[buf_index].phys);
- pr_err("%s: rxedl[0x%x] rxedu [0x%x]\n",
- __func__, payload[0], payload[1]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- return -EINVAL;
- }
- port->buf[buf_index].used = 1;
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- config_debug_fs_write_cb();
- for (i = 0; i < port->max_buf_cnt; i++)
- dev_vdbg(ac->dev, "%s %d\n",
- __func__, port->buf[i].used);
- }
- break;
- }
- case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
- pr_debug("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session, data->opcode,
- data->token,
- data->src_port, data->dest_port);
- if (payload[0] != 0) {
- pr_err("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 returned error = 0x%x\n",
- __func__, payload[0]);
- } else if (generic_get_data) {
- generic_get_data->valid = 1;
- if (generic_get_data->is_inband) {
- pr_debug("%s: payload[1] = 0x%x, payload[2]=0x%x, payload[3]=0x%x\n",
- __func__, payload[1], payload[2], payload[3]);
- generic_get_data->size_in_ints = payload[3]>>2;
- for (i = 0; i < payload[3]>>2; i++) {
- generic_get_data->ints[i] =
- payload[4+i];
- pr_debug("%s: ASM callback val %i = %i\n",
- __func__, i, payload[4+i]);
- }
- pr_debug("%s: callback size in ints = %i\n",
- __func__,
- generic_get_data->size_in_ints);
- }
- if (atomic_read(&ac->cmd_state) && wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->cmd_wait);
- }
- break;
- }
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- break;
- case ASM_DATA_EVENT_READ_DONE_V2:{
- struct audio_port_data *port = &ac->port[OUT];
- config_debug_fs_read_cb();
- dev_vdbg(ac->dev, "%s: ReadDone: status=%d buff_add=0x%x act_size=%d offset=%d\n",
- __func__, payload[READDONE_IDX_STATUS],
- payload[READDONE_IDX_BUFADD_LSW],
- payload[READDONE_IDX_SIZE],
- payload[READDONE_IDX_OFFSET]);
- dev_vdbg(ac->dev, "%s: ReadDone:msw_ts=%d lsw_ts=%d memmap_hdl=0x%x flags=%d id=%d num=%d\n",
- __func__, payload[READDONE_IDX_MSW_TS],
- payload[READDONE_IDX_LSW_TS],
- payload[READDONE_IDX_MEMMAP_HDL],
- payload[READDONE_IDX_FLAGS],
- payload[READDONE_IDX_SEQ_ID],
- payload[READDONE_IDX_NUMFRAMES]);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Write Done\n", __func__);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- buf_index = asm_token._token.buf_index;
- port->buf[buf_index].used = 0;
- if (lower_32_bits(port->buf[buf_index].phys) !=
- payload[READDONE_IDX_BUFADD_LSW] ||
- msm_audio_populate_upper_32_bits(
- port->buf[buf_index].phys) !=
- payload[READDONE_IDX_BUFADD_MSW]) {
- dev_vdbg(ac->dev, "%s: Expected addr %pK\n",
- __func__, &port->buf[buf_index].phys);
- pr_err("%s: rxedl[0x%x] rxedu[0x%x]\n",
- __func__,
- payload[READDONE_IDX_BUFADD_LSW],
- payload[READDONE_IDX_BUFADD_MSW]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- break;
- }
- port->buf[buf_index].actual_size =
- payload[READDONE_IDX_SIZE];
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- }
- break;
- }
- case ASM_DATA_EVENT_EOS:
- case ASM_DATA_EVENT_RENDERED_EOS:
- pr_debug("%s: EOS ACK received: rxed session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_EVENTX_OVERFLOW:
- pr_debug("%s: ASM_SESSION_EVENTX_OVERFLOW session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_EVENT_RX_UNDERFLOW:
- pr_debug("%s: ASM_SESSION_EVENT_RX_UNDERFLOW session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3:
- dev_vdbg(ac->dev, "%s: ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
- __func__,
- payload[0], payload[1], payload[2]);
- ac->time_stamp = (uint64_t)(((uint64_t)payload[2] << 32) |
- payload[1]);
- if (atomic_cmpxchg(&ac->time_flag, 1, 0))
- wake_up(&ac->time_wait);
- break;
- case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
- case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
- pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
- __func__,
- payload[0], payload[1], payload[2],
- payload[3]);
- break;
- case ASM_SESSION_CMDRSP_GET_MTMX_STRTR_PARAMS_V2:
- q6asm_process_mtmx_get_param_rsp(ac, (void *) payload);
- break;
- case ASM_STREAM_PP_EVENT:
- case ASM_STREAM_CMD_ENCDEC_EVENTS:
- case ASM_STREAM_CMD_REGISTER_IEC_61937_FMT_UPDATE:
- pr_debug("%s: ASM_STREAM_EVENT payload[0][0x%x] payload[1][0x%x]",
- __func__, payload[0], payload[1]);
- i = is_adsp_raise_event(data->opcode);
- if (i < 0)
- return 0;
- /* repack payload for asm_stream_pp_event
- * package is composed of event type + size + actual payload
- */
- payload_size = data->payload_size;
- pp_event_package = kzalloc(payload_size
- + sizeof(struct msm_adsp_event_data),
- GFP_ATOMIC);
- if (!pp_event_package)
- return -ENOMEM;
- pp_event_package->event_type = i;
- pp_event_package->payload_len = payload_size;
- memcpy((void *)pp_event_package->payload,
- data->payload, payload_size);
- ac->cb(data->opcode, data->token,
- (void *)pp_event_package, ac->priv);
- kfree(pp_event_package);
- return 0;
- case ASM_SESSION_CMDRSP_ADJUST_SESSION_CLOCK_V2:
- pr_debug("%s: ASM_SESSION_CMDRSP_ADJUST_SESSION_CLOCK_V2 sesion %d status 0x%x msw %u lsw %u\n",
- __func__, ac->session, payload[0], payload[2],
- payload[1]);
- wake_up(&ac->cmd_wait);
- break;
- case ASM_SESSION_CMDRSP_GET_PATH_DELAY_V2:
- pr_debug("%s: ASM_SESSION_CMDRSP_GET_PATH_DELAY_V2 session %d status 0x%x msw %u lsw %u\n",
- __func__, ac->session, payload[0], payload[2],
- payload[1]);
- if (payload[0] == 0) {
- atomic_set(&ac->cmd_state, 0);
- /* ignore msw, as a delay that large shouldn't happen */
- ac->path_delay = payload[1];
- } else {
- atomic_set(&ac->cmd_state, payload[0]);
- ac->path_delay = UINT_MAX;
- }
- wake_up(&ac->cmd_wait);
- break;
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- return 0;
- }
- void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
- uint32_t *index)
- {
- void *data;
- unsigned char idx;
- struct audio_port_data *port;
- if (!ac || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return NULL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->cpu_buf;
- if (port->buf == NULL) {
- pr_err("%s: Buffer pointer null\n", __func__);
- mutex_unlock(&port->lock);
- return NULL;
- }
- /* dir 0: used = 0 means buf in use
- * dir 1: used = 1 means buf in use
- */
- if (port->buf[idx].used == dir) {
- /* To make it more robust, we could loop and get the
- * next avail buf, its risky though
- */
- pr_err("%s: Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- mutex_unlock(&port->lock);
- return NULL;
- }
- *size = port->buf[idx].actual_size;
- *index = port->cpu_buf;
- data = port->buf[idx].data;
- dev_vdbg(ac->dev, "%s: session[%d]index[%d] data[%pK]size[%d]\n",
- __func__,
- ac->session,
- port->cpu_buf,
- data, *size);
- /* By default increase the cpu_buf cnt
- * user accesses this function,increase cpu
- * buf(to avoid another api)
- */
- port->buf[idx].used = dir;
- port->cpu_buf = q6asm_get_next_buf(ac, port->cpu_buf,
- port->max_buf_cnt);
- mutex_unlock(&port->lock);
- return data;
- }
- return NULL;
- }
- int q6asm_cpu_buf_release(int dir, struct audio_client *ac)
- {
- struct audio_port_data *port;
- int ret = 0;
- int idx;
- if (!ac || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- ret = -EINVAL;
- goto exit;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->cpu_buf;
- if (port->cpu_buf == 0) {
- port->cpu_buf = port->max_buf_cnt - 1;
- } else if (port->cpu_buf < port->max_buf_cnt) {
- port->cpu_buf = port->cpu_buf - 1;
- } else {
- pr_err("%s: buffer index(%d) out of range\n",
- __func__, port->cpu_buf);
- ret = -EINVAL;
- mutex_unlock(&port->lock);
- goto exit;
- }
- port->buf[port->cpu_buf].used = dir ^ 1;
- mutex_unlock(&port->lock);
- }
- exit:
- return ret;
- }
- void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
- uint32_t *size, uint32_t *index)
- {
- void *data;
- unsigned char idx;
- struct audio_port_data *port;
- if (!ac || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return NULL;
- }
- port = &ac->port[dir];
- idx = port->cpu_buf;
- if (port->buf == NULL) {
- pr_err("%s: Buffer pointer null\n", __func__);
- return NULL;
- }
- /*
- * dir 0: used = 0 means buf in use
- * dir 1: used = 1 means buf in use
- */
- if (port->buf[idx].used == dir) {
- /*
- * To make it more robust, we could loop and get the
- * next avail buf, its risky though
- */
- pr_err("%s: Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- return NULL;
- }
- *size = port->buf[idx].actual_size;
- *index = port->cpu_buf;
- data = port->buf[idx].data;
- dev_vdbg(ac->dev, "%s: session[%d]index[%d] data[%pK]size[%d]\n",
- __func__, ac->session, port->cpu_buf,
- data, *size);
- /*
- * By default increase the cpu_buf cnt
- * user accesses this function,increase cpu
- * buf(to avoid another api)
- */
- port->buf[idx].used = dir;
- port->cpu_buf = q6asm_get_next_buf(ac, port->cpu_buf,
- port->max_buf_cnt);
- return data;
- }
- int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
- {
- int ret = -1;
- struct audio_port_data *port;
- uint32_t idx;
- if (!ac || (dir != OUT)) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return ret;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->dsp_buf;
- if (port->buf[idx].used == (dir ^ 1)) {
- /* To make it more robust, we could loop and get the
- * next avail buf, its risky though
- */
- pr_err("%s: Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- mutex_unlock(&port->lock);
- return ret;
- }
- dev_vdbg(ac->dev, "%s: session[%d]dsp_buf=%d cpu_buf=%d\n",
- __func__,
- ac->session, port->dsp_buf, port->cpu_buf);
- ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
- mutex_unlock(&port->lock);
- }
- return ret;
- }
- static void __q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, uint32_t stream_id)
- {
- dev_vdbg(ac->dev, "%s: pkt_size=%d cmd_flg=%d session=%d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- mutex_lock(&ac->cmd_lock);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL", __func__);
- mutex_unlock(&ac->cmd_lock);
- return;
- }
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg)
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- }
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, ac->stream_id);
- }
- static void q6asm_stream_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, stream_id);
- }
- static void __q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg,
- uint32_t stream_id, u8 no_wait_flag)
- {
- dev_vdbg(ac->dev, "%s: pkt_size = %d, cmd_flg = %d, session = %d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR is NULL", __func__);
- return;
- }
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg) {
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- no_wait_flag);
- }
- hdr->pkt_size = pkt_size;
- }
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg,
- ac->stream_id, WAIT_CMD);
- }
- static void q6asm_stream_add_hdr_async(struct audio_client *ac,
- struct apr_hdr *hdr, uint32_t pkt_size,
- uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg,
- stream_id, NO_WAIT_CMD);
- }
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size)
- {
- pr_debug("%s: pkt_size=%d session=%d\n",
- __func__, pkt_size, ac->session);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return;
- }
- mutex_lock(&ac->cmd_lock);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
- hdr->dest_port = 0;
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- }
- static void q6asm_add_mmaphdr(struct audio_client *ac, struct apr_hdr *hdr,
- u32 pkt_size, int dir)
- {
- pr_debug("%s: pkt size=%d\n",
- __func__, pkt_size);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
- hdr->src_port = 0;
- hdr->dest_port = 0;
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- dir,
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- }
- static int __q6asm_open_read(struct audio_client *ac,
- uint32_t format, uint16_t bits_per_sample,
- uint32_t pcm_format_block_ver,
- bool ts_mode)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read_v3 open;
- config_debug_fs_reset_index();
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V3;
- /* Stream prio : High, provide meta info with encoded frames */
- open.src_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- open.preprocopo_id = q6asm_get_asm_topology_cal();
- open.bits_per_sample = bits_per_sample;
- open.mode_flags = 0x0;
- ac->topology = open.preprocopo_id;
- ac->app_type = q6asm_get_asm_app_type_cal();
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE) {
- open.mode_flags |= ASM_LOW_LATENCY_TX_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- } else {
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- }
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.mode_flags |= 0x00;
- open.enc_cfg_id = q6asm_get_pcm_format_id(pcm_format_block_ver);
- if (ts_mode)
- open.mode_flags |= ABSOLUTE_TIMESTAMP_ENABLE;
- break;
- case FORMAT_MPEG4_AAC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_G711_ALAW_FS:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- case FORMAT_V13K:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open read\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ac->io_mode |= TUN_READ_IO_MODE;
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_open_read(struct audio_client *ac,
- uint32_t format)
- {
- return __q6asm_open_read(ac, format, 16,
- PCM_MEDIA_FORMAT_V2 /*media fmt block ver*/,
- false/*ts_mode*/);
- }
- int q6asm_open_read_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V2 /*media fmt block ver*/,
- false/*ts_mode*/);
- }
- /*
- * asm_open_read_v3 - Opens audio capture session
- *
- * @ac: Client session handle
- * @format: encoder format
- * @bits_per_sample: bit width of capture session
- */
- int q6asm_open_read_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V3/*media fmt block ver*/,
- false/*ts_mode*/);
- }
- EXPORT_SYMBOL(q6asm_open_read_v3);
- /*
- * asm_open_read_v4 - Opens audio capture session
- *
- * @ac: Client session handle
- * @format: encoder format
- * @bits_per_sample: bit width of capture session
- * @ts_mode: timestamp mode
- */
- int q6asm_open_read_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, bool ts_mode)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V4 /*media fmt block ver*/,
- ts_mode);
- }
- EXPORT_SYMBOL(q6asm_open_read_v4);
- int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format,
- uint32_t passthrough_flag)
- {
- int rc = 0;
- struct asm_stream_cmd_open_write_compressed open;
- if (ac == NULL) {
- pr_err("%s: ac[%pK] NULL\n", __func__, ac);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: APR handle[%pK] NULL\n", __func__, ac->apr);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
- format);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
- atomic_set(&ac->cmd_state, -1);
- switch (format) {
- case FORMAT_AC3:
- open.fmt_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.fmt_id = ASM_MEDIA_FMT_EAC3;
- break;
- case FORMAT_DTS:
- open.fmt_id = ASM_MEDIA_FMT_DTS;
- break;
- case FORMAT_DSD:
- open.fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_GEN_COMPR:
- open.fmt_id = ASM_MEDIA_FMT_GENERIC_COMPRESSED;
- break;
- case FORMAT_TRUEHD:
- open.fmt_id = ASM_MEDIA_FMT_TRUEHD;
- break;
- case FORMAT_IEC61937:
- open.fmt_id = ASM_MEDIA_FMT_IEC;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- /* Below flag indicates the DSP that Compressed audio input
- * stream is not IEC 61937 or IEC 60958 packetizied
- */
- if (passthrough_flag == COMPRESSED_PASSTHROUGH ||
- passthrough_flag == COMPRESSED_PASSTHROUGH_DSD ||
- passthrough_flag == COMPRESSED_PASSTHROUGH_GEN) {
- open.flags = 0x0;
- pr_debug("%s: Flag 0 COMPRESSED_PASSTHROUGH\n", __func__);
- } else if (passthrough_flag == COMPRESSED_PASSTHROUGH_CONVERT) {
- open.flags = 0x8;
- pr_debug("%s: Flag 8 - COMPRESSED_PASSTHROUGH_CONVERT\n",
- __func__);
- } else if (passthrough_flag == COMPRESSED_PASSTHROUGH_IEC61937) {
- open.flags = 0x1;
- pr_debug("%s: Flag 1 - COMPRESSED_PASSTHROUGH_IEC61937\n",
- __func__);
- } else {
- pr_err("%s: Invalid passthrough type[%d]\n",
- __func__, passthrough_flag);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 1*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for OPEN_WRITE_COMPR rc[%d]\n",
- __func__, rc);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_open_write(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, uint32_t stream_id,
- bool is_gapless_mode,
- uint32_t pcm_format_block_ver)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_write_v3 open;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] wr_format[0x%x]\n",
- __func__, ac->session, format);
- q6asm_stream_add_hdr(ac, &open.hdr, sizeof(open), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&open.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- dev_vdbg(ac->dev, "%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, open.hdr.token, stream_id, ac->session);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
- open.mode_flags = 0x00;
- if (ac->perf_mode == ULL_POST_PROCESSING_PCM_MODE)
- open.mode_flags |= ASM_ULL_POST_PROCESSING_STREAM_SESSION;
- else if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_ULTRA_LOW_LATENCY_STREAM_SESSION;
- else if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else {
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- if (is_gapless_mode)
- open.mode_flags |= 1 << ASM_SHIFT_GAPLESS_MODE_FLAG;
- }
- /* source endpoint : matrix */
- open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- open.bits_per_sample = bits_per_sample;
- open.postprocopo_id = q6asm_get_asm_topology_cal();
- if (ac->perf_mode != LEGACY_PCM_MODE)
- open.postprocopo_id = ASM_STREAM_POSTPROCOPO_ID_NONE;
- pr_debug("%s: perf_mode %d asm_topology 0x%x bps %d\n", __func__,
- ac->perf_mode, open.postprocopo_id, open.bits_per_sample);
- /*
- * For Gapless playback it will use the same session for next stream,
- * So use the same topology
- */
- if (!ac->topology) {
- ac->topology = open.postprocopo_id;
- ac->app_type = q6asm_get_asm_app_type_cal();
- }
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.dec_fmt_id = q6asm_get_pcm_format_id(pcm_format_block_ver);
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- case FORMAT_AC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_EAC3;
- break;
- case FORMAT_MP2:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP2;
- break;
- case FORMAT_FLAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_FLAC;
- break;
- case FORMAT_ALAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_VORBIS:
- open.dec_fmt_id = ASM_MEDIA_FMT_VORBIS;
- break;
- case FORMAT_APE:
- open.dec_fmt_id = ASM_MEDIA_FMT_APE;
- break;
- case FORMAT_DSD:
- open.dec_fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_APTX:
- open.dec_fmt_id = ASM_MEDIA_FMT_APTX;
- break;
- case FORMAT_GEN_COMPR:
- open.dec_fmt_id = ASM_MEDIA_FMT_GENERIC_COMPRESSED;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n", __func__, format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open write\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_open_write(struct audio_client *ac, uint32_t format)
- {
- return __q6asm_open_write(ac, format, 16, ac->stream_id,
- false /*gapless*/,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- int q6asm_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- /*
- * q6asm_open_write_v3 - Opens audio playback session
- *
- * @ac: Client session handle
- * @format: decoder format
- * @bits_per_sample: bit width of playback session
- */
- int q6asm_open_write_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V3 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write_v3);
- /*
- * q6asm_open_write_v4 - Opens audio playback session
- *
- * @ac: Client session handle
- * @format: decoder format
- * @bits_per_sample: bit width of playback session
- */
- int q6asm_open_write_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V4 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write_v4);
- int q6asm_stream_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- /*
- * q6asm_stream_open_write_v3 - Creates audio stream for playback
- *
- * @ac: Client session handle
- * @format: asm playback format
- * @bits_per_sample: bit width of requested stream
- * @stream_id: stream id of stream to be associated with this session
- * @is_gapless_mode: true if gapless mode needs to be enabled
- */
- int q6asm_stream_open_write_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V3 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_stream_open_write_v3);
- /*
- * q6asm_stream_open_write_v4 - Creates audio stream for playback
- *
- * @ac: Client session handle
- * @format: asm playback format
- * @bits_per_sample: bit width of requested stream
- * @stream_id: stream id of stream to be associated with this session
- * @is_gapless_mode: true if gapless mode needs to be enabled
- */
- int q6asm_stream_open_write_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V4 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_stream_open_write_v4);
- static int __q6asm_open_read_write(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format, bool is_meta_data_mode,
- uint32_t bits_per_sample,
- bool overwrite_topology, int topology)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_readwrite_v2 open;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- pr_debug("%s: wr_format[0x%x]rd_format[0x%x]\n",
- __func__, wr_format, rd_format);
- ac->io_mode |= NT_MODE;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE_V2;
- open.mode_flags = is_meta_data_mode ? BUFFER_META_ENABLE : 0;
- open.bits_per_sample = bits_per_sample;
- /* source endpoint : matrix */
- open.postprocopo_id = q6asm_get_asm_topology_cal();
- open.postprocopo_id = overwrite_topology ?
- topology : open.postprocopo_id;
- ac->topology = open.postprocopo_id;
- ac->app_type = q6asm_get_asm_app_type_cal();
- switch (wr_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_AMRNB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMR_WB_PLUS_V2;
- break;
- case FORMAT_V13K:
- open.dec_fmt_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_EVRCB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCB_FS;
- break;
- case FORMAT_EVRCWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCWB_FS;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- case FORMAT_ALAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_APE:
- open.dec_fmt_id = ASM_MEDIA_FMT_APE;
- break;
- case FORMAT_DSD:
- open.dec_fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_G711_ALAW_FS:
- open.dec_fmt_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.dec_fmt_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, wr_format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- switch (rd_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_G711_ALAW_FS:
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- case FORMAT_V13K:
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_ALAC:
- open.enc_cfg_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_APE:
- open.enc_cfg_id = ASM_MEDIA_FMT_APE;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, rd_format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- dev_vdbg(ac->dev, "%s: rdformat[0x%x]wrformat[0x%x]\n", __func__,
- open.enc_cfg_id, open.dec_fmt_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open read-write\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_open_read_write(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format)
- {
- return __q6asm_open_read_write(ac, rd_format, wr_format,
- true/*meta data mode*/,
- 16 /*bits_per_sample*/,
- false /*overwrite_topology*/, 0);
- }
- int q6asm_open_read_write_v2(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format, bool is_meta_data_mode,
- uint32_t bits_per_sample, bool overwrite_topology,
- int topology)
- {
- return __q6asm_open_read_write(ac, rd_format, wr_format,
- is_meta_data_mode, bits_per_sample,
- overwrite_topology, topology);
- }
- int q6asm_open_loopback_v2(struct audio_client *ac, uint16_t bits_per_sample)
- {
- int rc = 0x00;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE) {
- struct asm_stream_cmd_open_transcode_loopback_t open;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK;
- open.mode_flags = 0;
- open.src_endpoint_type = 0;
- open.sink_endpoint_type = 0;
- open.src_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- open.sink_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- /* source endpoint : matrix */
- open.audproc_topo_id = q6asm_get_asm_topology_cal();
- ac->app_type = q6asm_get_asm_app_type_cal();
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- ac->topology = open.audproc_topo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a transcode_loopback with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {/*if(ac->perf_mode == LEGACY_PCM_MODE)*/
- struct asm_stream_cmd_open_loopback_v2 open;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK_V2;
- open.mode_flags = 0;
- open.src_endpointype = 0;
- open.sink_endpointype = 0;
- /* source endpoint : matrix */
- open.postprocopo_id = q6asm_get_asm_topology_cal();
- ac->app_type = q6asm_get_asm_app_type_cal();
- ac->topology = open.postprocopo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a loopback_v2 with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open_loopback\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_open_transcode_loopback(struct audio_client *ac,
- uint16_t bits_per_sample,
- uint32_t source_format, uint32_t sink_format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_transcode_loopback_t open;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK;
- open.mode_flags = 0;
- open.src_endpoint_type = 0;
- open.sink_endpoint_type = 0;
- switch (source_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.src_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- case FORMAT_AC3:
- open.src_format_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.src_format_id = ASM_MEDIA_FMT_EAC3;
- break;
- default:
- pr_err("%s: Unsupported src fmt [%d]\n",
- __func__, source_format);
- return -EINVAL;
- }
- switch (sink_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.sink_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- default:
- pr_err("%s: Unsupported sink fmt [%d]\n",
- __func__, sink_format);
- return -EINVAL;
- }
- /* source endpoint : matrix */
- open.audproc_topo_id = q6asm_get_asm_topology_cal();
- ac->app_type = q6asm_get_asm_app_type_cal();
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- ac->topology = open.audproc_topo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a transcode_loopback with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open_transcode_loopback\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static
- int q6asm_set_shared_circ_buff(struct audio_client *ac,
- struct asm_stream_cmd_open_shared_io *open,
- int bufsz, int bufcnt,
- int dir)
- {
- struct audio_buffer *buf_circ;
- int bytes_to_alloc, rc;
- size_t len;
- buf_circ = kzalloc(sizeof(struct audio_buffer), GFP_KERNEL);
- if (!buf_circ) {
- rc = -ENOMEM;
- goto done;
- }
- mutex_lock(&ac->cmd_lock);
- ac->port[dir].buf = buf_circ;
- bytes_to_alloc = bufsz * bufcnt;
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc("audio_client", &buf_circ->client,
- &buf_circ->handle, bytes_to_alloc,
- (ion_phys_addr_t *)&buf_circ->phys,
- &len, &buf_circ->data);
- if (rc) {
- pr_err("%s: Audio ION alloc is failed, rc = %d\n", __func__,
- rc);
- mutex_unlock(&ac->cmd_lock);
- kfree(buf_circ);
- goto done;
- }
- buf_circ->used = dir ^ 1;
- buf_circ->size = bytes_to_alloc;
- buf_circ->actual_size = bytes_to_alloc;
- memset(buf_circ->data, 0, buf_circ->actual_size);
- ac->port[dir].max_buf_cnt = 1;
- open->shared_circ_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- open->shared_circ_buf_num_regions = 1;
- open->shared_circ_buf_property_flag = 0x00;
- open->shared_circ_buf_start_phy_addr_lsw =
- lower_32_bits(buf_circ->phys);
- open->shared_circ_buf_start_phy_addr_msw =
- msm_audio_populate_upper_32_bits(buf_circ->phys);
- open->shared_circ_buf_size = bufsz * bufcnt;
- open->map_region_circ_buf.shm_addr_lsw = lower_32_bits(buf_circ->phys);
- open->map_region_circ_buf.shm_addr_msw =
- msm_audio_populate_upper_32_bits(buf_circ->phys);
- open->map_region_circ_buf.mem_size_bytes = bytes_to_alloc;
- mutex_unlock(&ac->cmd_lock);
- done:
- return rc;
- }
- static
- int q6asm_set_shared_pos_buff(struct audio_client *ac,
- struct asm_stream_cmd_open_shared_io *open,
- int dir)
- {
- struct audio_buffer *buf_pos = &ac->shared_pos_buf;
- int rc;
- size_t len;
- int bytes_to_alloc = sizeof(struct asm_shared_position_buffer);
- mutex_lock(&ac->cmd_lock);
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc("audio_client", &buf_pos->client,
- &buf_pos->handle, bytes_to_alloc,
- (ion_phys_addr_t *)&buf_pos->phys, &len,
- &buf_pos->data);
- if (rc) {
- pr_err("%s: Audio pos buf ION alloc is failed, rc = %d\n",
- __func__, rc);
- goto done;
- }
- buf_pos->used = dir ^ 1;
- buf_pos->size = bytes_to_alloc;
- buf_pos->actual_size = bytes_to_alloc;
- open->shared_pos_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- open->shared_pos_buf_num_regions = 1;
- open->shared_pos_buf_property_flag = 0x00;
- open->shared_pos_buf_phy_addr_lsw = lower_32_bits(buf_pos->phys);
- open->shared_pos_buf_phy_addr_msw =
- msm_audio_populate_upper_32_bits(buf_pos->phys);
- open->map_region_pos_buf.shm_addr_lsw = lower_32_bits(buf_pos->phys);
- open->map_region_pos_buf.shm_addr_msw =
- msm_audio_populate_upper_32_bits(buf_pos->phys);
- open->map_region_pos_buf.mem_size_bytes = bytes_to_alloc;
- done:
- mutex_unlock(&ac->cmd_lock);
- return rc;
- }
- /*
- * q6asm_open_shared_io: Open an ASM session for pull mode (playback)
- * or push mode (capture).
- * parameters
- * config - session parameters (channels, bits_per_sample, sr)
- * dir - stream direction (IN for playback, OUT for capture)
- * returns 0 if successful, error code otherwise
- */
- int q6asm_open_shared_io(struct audio_client *ac,
- struct shared_io_config *config,
- int dir)
- {
- struct asm_stream_cmd_open_shared_io *open;
- u8 *channel_mapping;
- int i, size_of_open, num_watermarks, bufsz, bufcnt, rc, flags = 0;
- if (!ac || !config)
- return -EINVAL;
- bufsz = config->bufsz;
- bufcnt = config->bufcnt;
- num_watermarks = 0;
- ac->config = *config;
- if (ac->session <= 0 || ac->session > SESSION_MAX) {
- pr_err("%s: Session %d is out of bounds\n",
- __func__, ac->session);
- return -EINVAL;
- }
- size_of_open = sizeof(struct asm_stream_cmd_open_shared_io) +
- (sizeof(struct asm_shared_watermark_level) * num_watermarks);
- open = kzalloc(PAGE_ALIGN(size_of_open), GFP_KERNEL);
- if (!open)
- return -ENOMEM;
- q6asm_stream_add_hdr(ac, &open->hdr, size_of_open, TRUE,
- ac->stream_id);
- atomic_set(&ac->cmd_state, 1);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x, perf %d\n",
- __func__, open->hdr.token, ac->stream_id, ac->session,
- ac->perf_mode);
- open->hdr.opcode =
- dir == IN ? ASM_STREAM_CMD_OPEN_PULL_MODE_WRITE :
- ASM_STREAM_CMD_OPEN_PUSH_MODE_READ;
- pr_debug("%s perf_mode %d\n", __func__, ac->perf_mode);
- if (dir == IN)
- if (ac->perf_mode == ULL_POST_PROCESSING_PCM_MODE)
- flags = 4 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE)
- flags = 2 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- flags = 1 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else
- pr_err("Invalid perf mode for pull write\n");
- else
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- flags = ASM_LOW_LATENCY_TX_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_FLAG_PUSH_MODE_READ;
- else
- pr_err("Invalid perf mode for push read\n");
- if (flags == 0) {
- pr_err("%s: Invalid mode[%d]\n", __func__,
- ac->perf_mode);
- kfree(open);
- return -EINVAL;
- }
- pr_debug("open.mode_flags = 0x%x\n", flags);
- open->mode_flags = flags;
- open->endpoint_type = ASM_END_POINT_DEVICE_MATRIX;
- open->topo_bits_per_sample = config->bits_per_sample;
- open->topo_id = q6asm_get_asm_topology_cal();
- if (config->format == FORMAT_LINEAR_PCM)
- open->fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- else {
- pr_err("%s: Invalid format[%d]\n", __func__, config->format);
- rc = -EINVAL;
- goto done;
- }
- if (ac->port[dir].buf) {
- pr_err("%s: Buffer already allocated\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- rc = q6asm_set_shared_circ_buff(ac, open, bufsz, bufcnt, dir);
- if (rc)
- goto done;
- ac->port[dir].tmp_hdl = 0;
- rc = q6asm_set_shared_pos_buff(ac, open, dir);
- if (rc)
- goto done;
- /* asm_multi_channel_pcm_fmt_blk_v3 */
- open->fmt.num_channels = config->channels;
- open->fmt.bits_per_sample = config->bits_per_sample;
- open->fmt.sample_rate = config->rate;
- open->fmt.is_signed = 1;
- open->fmt.sample_word_size = config->sample_word_size;
- channel_mapping = open->fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- rc = q6asm_map_channels(channel_mapping, config->channels, false);
- if (rc) {
- pr_err("%s: Map channels failed, ret: %d\n", __func__, rc);
- goto done;
- }
- open->num_watermark_levels = num_watermarks;
- for (i = 0; i < num_watermarks; i++) {
- open->watermark[i].watermark_level_bytes = i *
- ((bufsz * bufcnt) / num_watermarks);
- pr_debug("%s: Watermark level set for %i\n",
- __func__,
- open->watermark[i].watermark_level_bytes);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) open);
- if (rc < 0) {
- pr_err("%s: Open failed op[0x%x]rc[%d]\n",
- __func__, open->hdr.opcode, rc);
- goto done;
- }
- pr_debug("%s: sent open apr pkt\n", __func__);
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) <= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: Timeout. Waited for open write apr pkt rc[%d]\n",
- __func__, rc);
- rc = -ETIMEDOUT;
- goto done;
- }
- if (atomic_read(&ac->cmd_state) < 0) {
- pr_err("%s: DSP returned error [%d]\n", __func__,
- atomic_read(&ac->cmd_state));
- rc = -EINVAL;
- goto done;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- rc = 0;
- done:
- kfree(open);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_shared_io);
- /*
- * q6asm_shared_io_buf: Returns handle to the shared circular buffer being
- * used for pull/push mode.
- * parameters
- * dir - used to identify input/output port
- * returns buffer handle
- */
- struct audio_buffer *q6asm_shared_io_buf(struct audio_client *ac,
- int dir)
- {
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: ac is null\n", __func__);
- return NULL;
- }
- port = &ac->port[dir];
- return port->buf;
- }
- EXPORT_SYMBOL(q6asm_shared_io_buf);
- /*
- * q6asm_shared_io_free: Frees memory allocated for a pull/push session
- * parameters
- * dir - port direction
- * returns 0 if successful, error otherwise
- */
- int q6asm_shared_io_free(struct audio_client *ac, int dir)
- {
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- port = &ac->port[dir];
- mutex_lock(&ac->cmd_lock);
- if (port->buf && port->buf->data) {
- msm_audio_ion_free(port->buf->client, port->buf->handle);
- port->buf->client = NULL;
- port->buf->handle = NULL;
- port->max_buf_cnt = 0;
- kfree(port->buf);
- port->buf = NULL;
- }
- if (ac->shared_pos_buf.data) {
- msm_audio_ion_free(ac->shared_pos_buf.client,
- ac->shared_pos_buf.handle);
- ac->shared_pos_buf.client = NULL;
- ac->shared_pos_buf.handle = NULL;
- }
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- EXPORT_SYMBOL(q6asm_shared_io_free);
- /*
- * q6asm_get_shared_pos: Returns current read index/write index as observed
- * by the DSP. Note that this is an offset and iterates from [0,BUF_SIZE - 1]
- * parameters - (all output)
- * read_index - offset
- * wall_clk_msw1 - ADSP wallclock msw
- * wall_clk_lsw1 - ADSP wallclock lsw
- * returns 0 if successful, -EAGAIN if DSP failed to update after some
- * retries
- */
- int q6asm_get_shared_pos(struct audio_client *ac, uint32_t *read_index,
- uint32_t *wall_clk_msw1, uint32_t *wall_clk_lsw1)
- {
- struct asm_shared_position_buffer *pos_buf;
- uint32_t frame_cnt1, frame_cnt2;
- int i, j;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- pos_buf = ac->shared_pos_buf.data;
- /* always try to get the latest update in the shared pos buffer */
- for (i = 0; i < 2; i++) {
- /* retry until there is an update from DSP */
- for (j = 0; j < 5; j++) {
- frame_cnt1 = pos_buf->frame_counter;
- if (frame_cnt1 != 0)
- break;
- }
- *wall_clk_msw1 = pos_buf->wall_clock_us_msw;
- *wall_clk_lsw1 = pos_buf->wall_clock_us_lsw;
- *read_index = pos_buf->index;
- frame_cnt2 = pos_buf->frame_counter;
- if (frame_cnt1 != frame_cnt2)
- continue;
- return 0;
- }
- pr_err("%s out of tries trying to get a good read, try again\n",
- __func__);
- return -EAGAIN;
- }
- int q6asm_run(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
- atomic_set(&ac->cmd_state, -1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- config_debug_fs_run();
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("%s: Commmand run failed[%d]",
- __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for run success",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_stream_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("%s: Commmand run failed[%d]", __func__, rc);
- return -EINVAL;
- }
- return 0;
- }
- int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, ac->stream_id);
- }
- int q6asm_stream_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, stream_id);
- }
- int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
- uint32_t frames_per_buf,
- uint32_t sample_rate, uint32_t channels,
- uint32_t bit_rate, uint32_t mode, uint32_t format)
- {
- struct asm_aac_enc_cfg_v2 enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]\n",
- __func__, ac->session, frames_per_buf,
- sample_rate, channels, bit_rate, mode, format);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_aac_enc_cfg_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.bit_rate = bit_rate;
- enc_cfg.enc_mode = mode;
- enc_cfg.aac_fmt_flag = format;
- enc_cfg.channel_cfg = channels;
- enc_cfg.sample_rate = sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_g711(struct audio_client *ac,
- uint32_t frames_per_buf,
- uint32_t sample_rate)
- {
- struct asm_g711_enc_cfg_v2 enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]SR[%d]\n",
- __func__, ac->session, frames_per_buf,
- sample_rate);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_g711_enc_cfg_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.sample_rate = sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_encdec_chan_map(struct audio_client *ac,
- uint32_t num_channels)
- {
- struct asm_dec_out_chan_map_param chan_map;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: Session %d, num_channels = %d\n",
- __func__, ac->session, num_channels);
- q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
- atomic_set(&ac->cmd_state, -1);
- chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- chan_map.encdec.param_id = ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP;
- chan_map.encdec.param_size = sizeof(struct asm_dec_out_chan_map_param) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- chan_map.num_channels = num_channels;
- channel_mapping = chan_map.channel_mapping;
- memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
- if (q6asm_map_channels(channel_mapping, num_channels, false)) {
- pr_err("%s: map channels failed %d\n", __func__, num_channels);
- return -EINVAL;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- chan_map.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /*
- * q6asm_enc_cfg_blk_pcm_v4 - sends encoder configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @use_back_flavor: to configure back left and right channel
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_enc_cfg_blk_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, bool use_default_chmap,
- bool use_back_flavor, u8 *channel_map,
- uint16_t sample_word_size, uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_enc_cfg_v4 enc_cfg;
- struct asm_enc_cfg_blk_param_v2 enc_fg_blk;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&enc_cfg, 0, sizeof(enc_cfg));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(enc_fg_blk);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- enc_cfg.sample_word_size = sample_word_size;
- enc_cfg.endianness = endianness;
- enc_cfg.mode = mode;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Command open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v4);
- /*
- * q6asm_enc_cfg_blk_pcm_v3 - sends encoder configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @use_back_flavor: to configure back left and right channel
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_enc_cfg_blk_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, bool use_default_chmap,
- bool use_back_flavor, u8 *channel_map,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_enc_cfg_v3 enc_cfg;
- struct asm_enc_cfg_blk_param_v2 enc_fg_blk;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&enc_cfg, 0, sizeof(enc_cfg));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(enc_fg_blk);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- enc_cfg.sample_word_size = sample_word_size;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v3);
- int q6asm_enc_cfg_blk_pcm_v2(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample,
- bool use_default_chmap, bool use_back_flavor, u8 *channel_map)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_enc_cfg_blk_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return q6asm_enc_cfg_blk_pcm_v4(ac, rate, channels,
- bits_per_sample, true, false, NULL,
- sample_word_size, endianness, mode);
- }
- static int __q6asm_enc_cfg_blk_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return q6asm_enc_cfg_blk_pcm_v3(ac, rate, channels,
- bits_per_sample, true, false, NULL,
- sample_word_size);
- }
- static int __q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- return q6asm_enc_cfg_blk_pcm_v2(ac, rate, channels,
- bits_per_sample, true, false, NULL);
- }
- int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, 16);
- }
- int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, bits_per_sample);
- }
- /*
- * q6asm_enc_cfg_blk_pcm_format_support_v3 - sends encoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_enc_cfg_blk_pcm_format_support_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return __q6asm_enc_cfg_blk_pcm_v3(ac, rate, channels,
- bits_per_sample, sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_format_support_v3);
- /*
- * q6asm_enc_cfg_blk_pcm_format_support_v4 - sends encoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_enc_cfg_blk_pcm_format_support_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_enc_cfg_blk_pcm_v4(ac, rate, channels,
- bits_per_sample, sample_word_size,
- endianness, mode);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_format_support_v4);
- int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = 0;/*channels;*/
- enc_cfg.bits_per_sample = 16;
- enc_cfg.sample_rate = 0;/*rate;*/
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n", __func__, channels);
- return -EINVAL;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels,
- bool use_back_flavor)
- {
- u8 *lchannel_mapping;
- lchannel_mapping = channel_mapping;
- pr_debug("%s: channels passed: %d\n", __func__, channels);
- if (channels == 1) {
- lchannel_mapping[0] = PCM_CHANNEL_FC;
- } else if (channels == 2) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- } else if (channels == 3) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- } else if (channels == 4) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[3] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 5) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 6) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[5] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 7) {
- /*
- * Configured for 5.1 channel mapping + 1 channel for debug
- * Can be customized based on DSP.
- */
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[5] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- lchannel_mapping[6] = PCM_CHANNEL_CS;
- } else if (channels == 8) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- } else {
- pr_err("%s: ERROR.unsupported num_ch = %u\n",
- __func__, channels);
- return -EINVAL;
- }
- return 0;
- }
- int q6asm_enable_sbrps(struct audio_client *ac,
- uint32_t sbr_ps_enable)
- {
- struct asm_aac_sbr_ps_flag_param sbrps;
- u32 frames_per_buf = 0;
- int rc = 0;
- pr_debug("%s: Session %d\n", __func__, ac->session);
- q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
- atomic_set(&ac->cmd_state, -1);
- sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- sbrps.encdec.param_id = ASM_PARAM_ID_AAC_SBR_PS_FLAG;
- sbrps.encdec.param_size = sizeof(struct asm_aac_sbr_ps_flag_param) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- sbrps.encblk.frames_per_buf = frames_per_buf;
- sbrps.encblk.enc_cfg_blk_size = sbrps.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- sbrps.sbr_ps_flag = sbr_ps_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__,
- ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_SBR_PS_FLAG, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x] ", __func__, sbrps.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
- uint16_t sce_left, uint16_t sce_right)
- {
- struct asm_aac_dual_mono_mapping_param dual_mono;
- int rc = 0;
- pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
- __func__, ac->session, sce_left, sce_right);
- q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
- atomic_set(&ac->cmd_state, -1);
- dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- dual_mono.encdec.param_id = ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING;
- dual_mono.encdec.param_size = sizeof(dual_mono.left_channel_sce) +
- sizeof(dual_mono.right_channel_sce);
- dual_mono.left_channel_sce = sce_left;
- dual_mono.right_channel_sce = sce_right;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- dual_mono.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /* Support for selecting stereo mixing coefficients for B family not done */
- int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
- {
- struct asm_aac_stereo_mix_coeff_selection_param_v2 aac_mix_coeff;
- int rc = 0;
- q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
- atomic_set(&ac->cmd_state, -1);
- aac_mix_coeff.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- aac_mix_coeff.param_id =
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2;
- aac_mix_coeff.param_size =
- sizeof(struct asm_aac_stereo_mix_coeff_selection_param_v2);
- aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
- pr_debug("%s: mix_coeff = %u\n", __func__, mix_coeff);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2,
- rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, aac_mix_coeff.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
- {
- struct asm_v13k_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]\n",
- __func__,
- ac->session, frames_per_buf, min_rate, max_rate,
- reduced_rate_level, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_v13k_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.reduced_rate_cmd = reduced_rate_level;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for setencdec v13k resp\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t rate_modulation_cmd)
- {
- struct asm_evrc_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]\n",
- __func__, ac->session,
- frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_evrc_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- enc_cfg.reserved = 0;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for encdec evrc\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrnb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]\n",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrnb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for set encdec amrnb\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrwb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]\n",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrwb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, int stream_id,
- bool use_default_chmap, char *channel_map)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&fmt.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v3 fmt;
- u8 *channel_mapping;
- int rc;
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v4 fmt;
- u8 *channel_mapping;
- int rc;
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, 16, ac->stream_id,
- true, NULL);
- }
- int q6asm_media_format_block_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, bits_per_sample, ac->stream_id,
- true, NULL);
- }
- int q6asm_media_format_block_pcm_format_support_v2(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, int stream_id,
- bool use_default_chmap, char *channel_map)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map);
- }
- /*
- * q6asm_media_format_block_pcm_format_support_v3- sends pcm decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @stream_id: stream id of stream to be associated with this session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_media_format_block_pcm_format_support_v3(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm_v3(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map,
- sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support_v3);
- /*
- * q6asm_media_format_block_pcm_format_support_v4- sends pcm decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @stream_id: stream id of stream to be associated with this session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_pcm_format_support_v4(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm_v4(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map,
- sample_word_size, endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support_v4);
- static int __q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_multi_ch_pcm_v3(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v3 fmt;
- u8 *channel_mapping;
- int rc;
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_multi_ch_pcm_v4(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v4 fmt;
- u8 *channel_mapping;
- int rc;
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map, 16);
- }
- int q6asm_media_format_block_multi_ch_pcm_v2(
- struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map,
- bits_per_sample);
- }
- /*
- * q6asm_media_format_block_multi_ch_pcm_v3 - sends pcm decoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_media_format_block_multi_ch_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return __q6asm_media_format_block_multi_ch_pcm_v3(ac, rate, channels,
- use_default_chmap,
- channel_map,
- bits_per_sample,
- sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_ch_pcm_v3);
- /*
- * q6asm_media_format_block_multi_ch_pcm_v4 - sends pcm decoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_multi_ch_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_media_format_block_multi_ch_pcm_v4(ac, rate, channels,
- use_default_chmap,
- channel_map,
- bits_per_sample,
- sample_word_size,
- endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_ch_pcm_v4);
- /*
- * q6asm_media_format_block_gen_compr - set up generic compress format params
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @bits_per_sample: bit width of gen compress stream
- */
- int q6asm_media_format_block_gen_compr(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- struct asm_generic_compressed_fmt_blk_t fmt;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]\n",
- __func__, ac->session, rate,
- channels, bits_per_sample);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sampling_rate = rate;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_gen_compr);
- /*
- * q6asm_media_format_block_iec - set up IEC61937 (compressed) or IEC60958
- * (pcm) format params. Both audio standards
- * use the same format and are used for
- * HDMI or SPDIF.
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- */
- int q6asm_media_format_block_iec(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_iec_compressed_fmt_blk_t fmt;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n",
- __func__, ac->session, rate,
- channels);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_IEC_60958_MEDIA_FMT;
- fmt.num_channels = channels;
- fmt.sampling_rate = rate;
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_iec);
- static int __q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- struct asm_aac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
- cfg->sample_rate, cfg->ch_cfg);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&fmt.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.aac_fmt_flag = cfg->format;
- fmt.audio_objype = cfg->aot;
- /* If zero, PCE is assumed to be available in bitstream*/
- fmt.total_size_of_PCE_bits = 0;
- fmt.channel_config = cfg->ch_cfg;
- fmt.sample_rate = cfg->sample_rate;
- pr_debug("%s: format=0x%x cfg_size=%d aac-cfg=0x%x aot=%d ch=%d sr=%d\n",
- __func__, fmt.aac_fmt_flag, fmt.fmt_blk.fmt_blk_size,
- fmt.aac_fmt_flag,
- fmt.audio_objype,
- fmt.channel_config,
- fmt.sample_rate);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- int q6asm_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- int q6asm_stream_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, stream_id);
- }
- int q6asm_media_format_block_wma(struct audio_client *ac,
- void *cfg, int stream_id)
- {
- struct asm_wmastdv9_fmt_blk_v2 fmt;
- struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
- int rc = 0;
- pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
- ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
- wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
- wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
- wma_cfg->ch_mask, wma_cfg->encode_opt);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wma_cfg->format_tag;
- fmt.num_channels = wma_cfg->ch_cfg;
- fmt.sample_rate = wma_cfg->sample_rate;
- fmt.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
- fmt.blk_align = wma_cfg->block_align;
- fmt.bits_per_sample =
- wma_cfg->valid_bits_per_sample;
- fmt.channel_mask = wma_cfg->ch_mask;
- fmt.enc_options = wma_cfg->encode_opt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_wmapro(struct audio_client *ac,
- void *cfg, int stream_id)
- {
- struct asm_wmaprov10_fmt_blk_v2 fmt;
- struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
- int rc = 0;
- pr_debug("%s: session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x], adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
- __func__,
- ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
- wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
- wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
- wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
- wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wmapro_cfg->format_tag;
- fmt.num_channels = wmapro_cfg->ch_cfg;
- fmt.sample_rate = wmapro_cfg->sample_rate;
- fmt.avg_bytes_per_sec =
- wmapro_cfg->avg_bytes_per_sec;
- fmt.blk_align = wmapro_cfg->block_align;
- fmt.bits_per_sample = wmapro_cfg->valid_bits_per_sample;
- fmt.channel_mask = wmapro_cfg->ch_mask;
- fmt.enc_options = wmapro_cfg->encode_opt;
- fmt.usAdvancedEncodeOpt = wmapro_cfg->adv_encode_opt;
- fmt.advanced_enc_options2 = wmapro_cfg->adv_encode_opt2;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
- struct asm_amrwbplus_cfg *cfg)
- {
- struct asm_amrwbplus_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s: session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
- __func__,
- ac->session,
- cfg->amr_band_mode,
- cfg->amr_frame_fmt,
- cfg->num_channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.amr_frame_fmt = cfg->amr_frame_fmt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd media format update failed.. %d\n",
- __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_stream_media_format_block_flac(struct audio_client *ac,
- struct asm_flac_cfg *cfg, int stream_id)
- {
- struct asm_flac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d] rate[%d] ch[%d] size[%d] stream_id[%d]\n",
- __func__, ac->session, cfg->sample_rate, cfg->ch_cfg,
- cfg->sample_size, stream_id);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.is_stream_info_present = cfg->stream_info_present;
- fmt.num_channels = cfg->ch_cfg;
- fmt.min_blk_size = cfg->min_blk_size;
- fmt.max_blk_size = cfg->max_blk_size;
- fmt.sample_rate = cfg->sample_rate;
- fmt.min_frame_size = cfg->min_frame_size;
- fmt.max_frame_size = cfg->max_frame_size;
- fmt.sample_size = cfg->sample_size;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_alac(struct audio_client *ac,
- struct asm_alac_cfg *cfg, int stream_id)
- {
- struct asm_alac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d]rate[%d]ch[%d]\n", __func__,
- ac->session, cfg->sample_rate, cfg->num_channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.frame_length = cfg->frame_length;
- fmt.compatible_version = cfg->compatible_version;
- fmt.bit_depth = cfg->bit_depth;
- fmt.pb = cfg->pb;
- fmt.mb = cfg->mb;
- fmt.kb = cfg->kb;
- fmt.num_channels = cfg->num_channels;
- fmt.max_run = cfg->max_run;
- fmt.max_frame_bytes = cfg->max_frame_bytes;
- fmt.avg_bit_rate = cfg->avg_bit_rate;
- fmt.sample_rate = cfg->sample_rate;
- fmt.channel_layout_tag = cfg->channel_layout_tag;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /*
- * q6asm_media_format_block_g711 - sends g711 decoder configuration
- * parameters
- * @ac: Client session handle
- * @cfg: Audio stream manager configuration parameters
- * @stream_id: Stream id
- */
- int q6asm_media_format_block_g711(struct audio_client *ac,
- struct asm_g711_dec_cfg *cfg, int stream_id)
- {
- struct asm_g711_dec_fmt_blk_v2 fmt;
- int rc = 0;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- if (!cfg) {
- pr_err("%s: Invalid ASM config\n", __func__);
- return -EINVAL;
- }
- if (stream_id <= 0) {
- pr_err("%s: Invalid stream id\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s :session[%d]rate[%d]\n", __func__,
- ac->session, cfg->sample_rate);
- memset(&fmt, 0, sizeof(struct asm_g711_dec_fmt_blk_v2));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.sample_rate = cfg->sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Command media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_g711);
- int q6asm_stream_media_format_block_vorbis(struct audio_client *ac,
- struct asm_vorbis_cfg *cfg, int stream_id)
- {
- struct asm_vorbis_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d] bit_stream_fmt[%d] stream_id[%d]\n",
- __func__, ac->session, cfg->bit_stream_fmt, stream_id);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.bit_stream_fmt = cfg->bit_stream_fmt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_ape(struct audio_client *ac,
- struct asm_ape_cfg *cfg, int stream_id)
- {
- struct asm_ape_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d]rate[%d]ch[%d]\n", __func__,
- ac->session, cfg->sample_rate, cfg->num_channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.compatible_version = cfg->compatible_version;
- fmt.compression_level = cfg->compression_level;
- fmt.format_flags = cfg->format_flags;
- fmt.blocks_per_frame = cfg->blocks_per_frame;
- fmt.final_frame_blocks = cfg->final_frame_blocks;
- fmt.total_frames = cfg->total_frames;
- fmt.bits_per_sample = cfg->bits_per_sample;
- fmt.num_channels = cfg->num_channels;
- fmt.sample_rate = cfg->sample_rate;
- fmt.seek_table_present = cfg->seek_table_present;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /*
- * q6asm_media_format_block_dsd- Sends DSD Decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @cfg: DSD Media Format Configuration.
- * @stream_id: stream id of stream to be associated with this session
- *
- * Return 0 on success or negative error code on failure
- */
- int q6asm_media_format_block_dsd(struct audio_client *ac,
- struct asm_dsd_cfg *cfg, int stream_id)
- {
- struct asm_dsd_fmt_blk_v2 fmt;
- int rc;
- pr_debug("%s: session[%d] data_rate[%d] ch[%d]\n", __func__,
- ac->session, cfg->dsd_data_rate, cfg->num_channels);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.num_version = cfg->num_version;
- fmt.is_bitwise_big_endian = cfg->is_bitwise_big_endian;
- fmt.dsd_channel_block_size = cfg->dsd_channel_block_size;
- fmt.num_channels = cfg->num_channels;
- fmt.dsd_data_rate = cfg->dsd_data_rate;
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Command DSD media format update failed, err: %d\n",
- __func__, rc);
- goto done;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for DSD FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto done;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto done;
- }
- return 0;
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_dsd);
- int q6asm_stream_media_format_block_aptx_dec(struct audio_client *ac,
- uint32_t srate, int stream_id)
- {
- struct asm_aptx_dec_fmt_blk_v2 aptx_fmt;
- int rc = 0;
- if (!ac->session) {
- pr_err("%s: ac session invalid\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s :session[%d] rate[%d] stream_id[%d]\n",
- __func__, ac->session, srate, stream_id);
- q6asm_stream_add_hdr(ac, &aptx_fmt.hdr, sizeof(aptx_fmt), TRUE,
- stream_id);
- atomic_set(&ac->cmd_state, -1);
- aptx_fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- aptx_fmt.fmtblk.fmt_blk_size = sizeof(aptx_fmt) - sizeof(aptx_fmt.hdr) -
- sizeof(aptx_fmt.fmtblk);
- aptx_fmt.sample_rate = srate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &aptx_fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_ds1_set_endp_params(struct audio_client *ac, int param_id,
- int param_value, int stream_id)
- {
- struct asm_dec_ddp_endp_param_v2 ddp_cfg;
- int rc = 0;
- pr_debug("%s: session[%d] stream[%d],param_id[%d]param_value[%d]",
- __func__, ac->session, stream_id, param_id, param_value);
- q6asm_stream_add_hdr(ac, &ddp_cfg.hdr, sizeof(ddp_cfg), TRUE,
- stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&ddp_cfg.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- ddp_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- ddp_cfg.encdec.param_id = param_id;
- ddp_cfg.encdec.param_size = sizeof(struct asm_dec_ddp_endp_param_v2) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- ddp_cfg.endp_param_value = param_value;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &ddp_cfg);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- ddp_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_ds1_set_endp_params(struct audio_client *ac,
- int param_id, int param_value)
- {
- return __q6asm_ds1_set_endp_params(ac, param_id, param_value,
- ac->stream_id);
- }
- int q6asm_ds1_set_stream_endp_params(struct audio_client *ac,
- int param_id, int param_value,
- int stream_id)
- {
- return __q6asm_ds1_set_endp_params(ac, param_id, param_value,
- stream_id);
- }
- int q6asm_memory_map(struct audio_client *ac, phys_addr_t buf_add, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int cmd_size = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- buffer_node = kmalloc(sizeof(struct asm_buffer_node), GFP_KERNEL);
- if (!buffer_node)
- return -ENOMEM;
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + sizeof(struct avs_shared_map_region_payload) * bufcnt;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt & 0x00ff;
- mmap_regions->property_flag = 0x00;
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- pr_debug("%s: buf_add 0x%pK, bufsz: %d\n", __func__,
- &buf_add, bufsz);
- mregions->shm_addr_lsw = lower_32_bits(buf_add);
- mregions->shm_addr_msw = msm_audio_populate_upper_32_bits(buf_add);
- mregions->mem_size_bytes = bufsz;
- ++mregions;
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("%s: mmap op[0x%x]rc[%d]\n", __func__,
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0 &&
- ac->port[dir].tmp_hdl), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for memory_map\n", __func__);
- rc = -ETIMEDOUT;
- kfree(buffer_node);
- goto fail_cmd;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s] for memory_map\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- kfree(buffer_node);
- goto fail_cmd;
- }
- buffer_node->buf_phys_addr = buf_add;
- buffer_node->mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node->list, &ac->port[dir].mem_map_handle);
- ac->port[dir].tmp_hdl = 0;
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- int q6asm_memory_unmap(struct audio_client *ac, phys_addr_t buf_add, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- int rc = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (this_mmap.apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr,
- sizeof(struct avs_cmd_shared_mem_unmap_regions),
- dir);
- atomic_set(&ac->mem_state, -1);
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s: Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("%s: mem_unmap op[0x%x]rc[%d]\n", __func__,
- mem_unmap.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0), 5 * HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s DSP returned error [%s] map handle 0x%x\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)),
- mem_unmap.mem_map_handle);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s: Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- struct audio_buffer *ab = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int i = 0;
- uint32_t cmd_size = 0;
- uint32_t bufcnt_t;
- uint32_t bufsz_t;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- bufcnt_t = (is_contiguous) ? 1 : bufcnt;
- bufsz_t = (is_contiguous) ? (bufsz * bufcnt) : bufsz;
- if (is_contiguous) {
- /* The size to memory map should be multiple of 4K bytes */
- bufsz_t = PAGE_ALIGN(bufsz_t);
- }
- if (bufcnt_t > (UINT_MAX
- - sizeof(struct avs_cmd_shared_mem_map_regions))
- / sizeof(struct avs_shared_map_region_payload)) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt_t = %u\n",
- __func__, bufcnt_t);
- return -EINVAL;
- }
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + (sizeof(struct avs_shared_map_region_payload)
- * bufcnt_t);
- if (bufcnt > (UINT_MAX / sizeof(struct asm_buffer_node))) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt = %u\n",
- __func__, bufcnt);
- return -EINVAL;
- }
- buffer_node = kzalloc(sizeof(struct asm_buffer_node) * bufcnt,
- GFP_KERNEL);
- if (!buffer_node)
- return -ENOMEM;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- pr_debug("%s: mmap_region=0x%pK token=0x%x\n", __func__,
- mmap_regions, ((ac->session << 8) | dir));
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt_t; /*bufcnt & 0x00ff; */
- mmap_regions->property_flag = 0x00;
- pr_debug("%s: map_regions->nregions = %d\n", __func__,
- mmap_regions->num_regions);
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- for (i = 0; i < bufcnt_t; i++) {
- ab = &port->buf[i];
- mregions->shm_addr_lsw = lower_32_bits(ab->phys);
- mregions->shm_addr_msw =
- msm_audio_populate_upper_32_bits(ab->phys);
- mregions->mem_size_bytes = bufsz_t;
- ++mregions;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0)
- , 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for memory_map\n", __func__);
- rc = -ETIMEDOUT;
- kfree(buffer_node);
- goto fail_cmd;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s DSP returned error for memory_map [%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- kfree(buffer_node);
- goto fail_cmd;
- }
- mutex_lock(&ac->cmd_lock);
- for (i = 0; i < bufcnt; i++) {
- ab = &port->buf[i];
- buffer_node[i].buf_phys_addr = ab->phys;
- buffer_node[i].mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node[i].list,
- &ac->port[dir].mem_map_handle);
- pr_debug("%s: i=%d, bufadd[i] = 0x%pK, maphdl[i] = 0x%x\n",
- __func__, i, &buffer_node[i].buf_phys_addr,
- buffer_node[i].mmap_hdl);
- }
- ac->port[dir].tmp_hdl = 0;
- mutex_unlock(&ac->cmd_lock);
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct audio_port_data *port = NULL;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- phys_addr_t buf_add;
- int rc = 0;
- int cmd_size = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- cmd_size = sizeof(struct avs_cmd_shared_mem_unmap_regions);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- port = &ac->port[dir];
- buf_add = port->buf->phys;
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s: Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("mmap_regions op[0x%x]rc[%d]\n",
- mem_unmap.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s: Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
- {
- struct asm_volume_ctrl_multichannel_gain multi_ch_gain;
- int sz = 0;
- int rc = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- memset(&multi_ch_gain, 0, sizeof(multi_ch_gain));
- sz = sizeof(struct asm_volume_ctrl_multichannel_gain);
- q6asm_add_hdr_async(ac, &multi_ch_gain.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- multi_ch_gain.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- multi_ch_gain.param.data_payload_addr_lsw = 0;
- multi_ch_gain.param.data_payload_addr_msw = 0;
- multi_ch_gain.param.mem_map_handle = 0;
- multi_ch_gain.param.data_payload_size = sizeof(multi_ch_gain) -
- sizeof(multi_ch_gain.hdr) - sizeof(multi_ch_gain.param);
- multi_ch_gain.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- multi_ch_gain.data.param_id = ASM_PARAM_ID_MULTICHANNEL_GAIN;
- multi_ch_gain.data.param_size = multi_ch_gain.param.data_payload_size -
- sizeof(multi_ch_gain.data);
- multi_ch_gain.data.reserved = 0;
- multi_ch_gain.gain_data[0].channeltype = PCM_CHANNEL_FL;
- multi_ch_gain.gain_data[0].gain = left_gain << 15;
- multi_ch_gain.gain_data[1].channeltype = PCM_CHANNEL_FR;
- multi_ch_gain.gain_data[1].gain = right_gain << 15;
- multi_ch_gain.num_channels = 2;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &multi_ch_gain);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, multi_ch_gain.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- multi_ch_gain.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] , set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- multi_ch_gain.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- /*
- * q6asm_set_multich_gain: set multiple channel gains on an ASM session
- * @ac: audio client handle
- * @channels: number of channels caller intends to set gains
- * @gains: list of gains of audio channels
- * @ch_map: list of channel mapping. Only valid if use_default is false
- * @use_default: flag to indicate whether to use default mapping
- */
- int q6asm_set_multich_gain(struct audio_client *ac, uint32_t channels,
- uint32_t *gains, uint8_t *ch_map, bool use_default)
- {
- struct asm_volume_ctrl_multichannel_gain multich_gain;
- int sz = 0;
- int rc = 0;
- int i;
- u8 default_chmap[VOLUME_CONTROL_MAX_CHANNELS];
- if (ac == NULL) {
- pr_err("%s: ac is NULL\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- if (ac->apr == NULL) {
- dev_err(ac->dev, "%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- if (gains == NULL) {
- dev_err(ac->dev, "%s: gain_list is NULL\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- if (channels > VOLUME_CONTROL_MAX_CHANNELS) {
- dev_err(ac->dev, "%s: Invalid channel count %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto done;
- }
- if (!use_default && ch_map == NULL) {
- dev_err(ac->dev, "%s: NULL channel map\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- memset(&multich_gain, 0, sizeof(multich_gain));
- sz = sizeof(struct asm_volume_ctrl_multichannel_gain);
- q6asm_add_hdr_async(ac, &multich_gain.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- multich_gain.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- multich_gain.param.data_payload_addr_lsw = 0;
- multich_gain.param.data_payload_addr_msw = 0;
- multich_gain.param.mem_map_handle = 0;
- multich_gain.param.data_payload_size = sizeof(multich_gain) -
- sizeof(multich_gain.hdr) - sizeof(multich_gain.param);
- multich_gain.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- multich_gain.data.param_id = ASM_PARAM_ID_MULTICHANNEL_GAIN;
- multich_gain.data.param_size = multich_gain.param.data_payload_size -
- sizeof(multich_gain.data);
- multich_gain.data.reserved = 0;
- if (use_default) {
- rc = q6asm_map_channels(default_chmap, channels, false);
- if (rc < 0)
- goto done;
- for (i = 0; i < channels; i++) {
- multich_gain.gain_data[i].channeltype =
- default_chmap[i];
- multich_gain.gain_data[i].gain = gains[i] << 15;
- }
- } else {
- for (i = 0; i < channels; i++) {
- multich_gain.gain_data[i].channeltype = ch_map[i];
- multich_gain.gain_data[i].gain = gains[i] << 15;
- }
- }
- multich_gain.num_channels = channels;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &multich_gain);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, multich_gain.data.param_id, rc);
- goto done;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- multich_gain.data.param_id);
- rc = -EINVAL;
- goto done;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%d] , set-params paramid[0x%x]\n",
- __func__, atomic_read(&ac->cmd_state_pp),
- multich_gain.data.param_id);
- rc = -EINVAL;
- goto done;
- }
- rc = 0;
- done:
- return rc;
- }
- int q6asm_set_mute(struct audio_client *ac, int muteflag)
- {
- struct asm_volume_ctrl_mute_config mute;
- int sz = 0;
- int rc = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_volume_ctrl_mute_config);
- q6asm_add_hdr_async(ac, &mute.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- mute.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- mute.param.data_payload_addr_lsw = 0;
- mute.param.data_payload_addr_msw = 0;
- mute.param.mem_map_handle = 0;
- mute.param.data_payload_size = sizeof(mute) -
- sizeof(mute.hdr) - sizeof(mute.param);
- mute.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- mute.data.param_id = ASM_PARAM_ID_VOL_CTRL_MUTE_CONFIG;
- mute.data.param_size = mute.param.data_payload_size - sizeof(mute.data);
- mute.data.reserved = 0;
- mute.mute_flag = muteflag;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &mute);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, mute.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- mute.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- mute.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_set_volume(struct audio_client *ac, int volume, int instance)
- {
- struct asm_volume_ctrl_master_gain vol;
- int sz = 0;
- int rc = 0;
- int module_id;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- switch (instance) {
- case SOFT_VOLUME_INSTANCE_2:
- module_id = ASM_MODULE_ID_VOL_CTRL2;
- break;
- case SOFT_VOLUME_INSTANCE_1:
- default:
- module_id = ASM_MODULE_ID_VOL_CTRL;
- break;
- }
- sz = sizeof(struct asm_volume_ctrl_master_gain);
- q6asm_add_hdr_async(ac, &vol.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- vol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- vol.param.data_payload_addr_lsw = 0;
- vol.param.data_payload_addr_msw = 0;
- vol.param.mem_map_handle = 0;
- vol.param.data_payload_size = sizeof(vol) -
- sizeof(vol.hdr) - sizeof(vol.param);
- vol.data.module_id = module_id;
- vol.data.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
- vol.data.param_size = vol.param.data_payload_size - sizeof(vol.data);
- vol.data.reserved = 0;
- vol.master_gain = volume;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &vol);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, vol.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- vol.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- vol.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_volume(struct audio_client *ac, int volume)
- {
- return __q6asm_set_volume(ac, volume, SOFT_VOLUME_INSTANCE_1);
- }
- int q6asm_set_volume_v2(struct audio_client *ac, int volume, int instance)
- {
- return __q6asm_set_volume(ac, volume, instance);
- }
- int q6asm_set_aptx_dec_bt_addr(struct audio_client *ac,
- struct aptx_dec_bt_addr_cfg *cfg)
- {
- struct aptx_dec_bt_dev_addr paylod;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: BT addr nap %d, uap %d, lap %d\n", __func__, cfg->nap,
- cfg->uap, cfg->lap);
- if (ac == NULL) {
- pr_err("%s: AC handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct aptx_dec_bt_dev_addr);
- q6asm_add_hdr_async(ac, &paylod.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- paylod.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- paylod.encdec.param_id = APTX_DECODER_BT_ADDRESS;
- paylod.encdec.param_size = sz - sizeof(paylod.hdr)
- - sizeof(paylod.encdec);
- paylod.bt_addr_cfg.lap = cfg->lap;
- paylod.bt_addr_cfg.uap = cfg->uap;
- paylod.bt_addr_cfg.nap = cfg->nap;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &paylod);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, paylod.encdec.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- paylod.encdec.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)),
- paylod.encdec.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- pr_debug("%s: set BT addr is success\n", __func__);
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_send_ion_fd(struct audio_client *ac, int fd)
- {
- struct ion_client *client;
- struct ion_handle *handle;
- ion_phys_addr_t paddr;
- size_t pa_len = 0;
- void *vaddr;
- int ret;
- int sz = 0;
- struct avs_rtic_shared_mem_addr shm;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- ret = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- ret = -EINVAL;
- goto fail_cmd;
- }
- ret = msm_audio_ion_import("audio_mem_client",
- &client,
- &handle,
- fd,
- NULL,
- 0,
- &paddr,
- &pa_len,
- &vaddr);
- if (ret) {
- pr_err("%s: audio ION import failed, rc = %d\n",
- __func__, ret);
- ret = -ENOMEM;
- goto fail_cmd;
- }
- /* get payload length */
- sz = sizeof(struct avs_rtic_shared_mem_addr);
- q6asm_add_hdr_async(ac, &shm.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- shm.shm_buf_addr_lsw = lower_32_bits(paddr);
- shm.shm_buf_addr_msw = msm_audio_populate_upper_32_bits(paddr);
- shm.buf_size = pa_len;
- shm.shm_buf_num_regions = 1;
- shm.shm_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- shm.shm_buf_flag = 0x00;
- shm.encdec.param_id = AVS_PARAM_ID_RTIC_SHARED_MEMORY_ADDR;
- shm.encdec.param_size = sizeof(struct avs_rtic_shared_mem_addr) -
- sizeof(struct apr_hdr) -
- sizeof(struct asm_stream_cmd_set_encdec_param_v2);
- shm.encdec.service_id = OUT;
- shm.encdec.reserved = 0;
- shm.map_region.shm_addr_lsw = shm.shm_buf_addr_lsw;
- shm.map_region.shm_addr_msw = shm.shm_buf_addr_msw;
- shm.map_region.mem_size_bytes = pa_len;
- shm.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2;
- ret = apr_send_pkt(ac->apr, (uint32_t *) &shm);
- if (ret < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, shm.encdec.param_id, ret);
- ret = -EINVAL;
- goto fail_cmd;
- }
- ret = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 1*HZ);
- if (!ret) {
- pr_err("%s: timeout, shm.encdec paramid[0x%x]\n", __func__,
- shm.encdec.param_id);
- ret = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] shm.encdec paramid[0x%x]\n",
- __func__,
- adsp_err_get_err_str(atomic_read(&ac->cmd_state)),
- shm.encdec.param_id);
- ret = adsp_err_get_lnx_err_code(atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ret = 0;
- fail_cmd:
- return ret;
- }
- int q6asm_send_rtic_event_ack(struct audio_client *ac,
- void *param, uint32_t params_length)
- {
- char *asm_params = NULL;
- int sz, rc;
- struct avs_param_rtic_event_ack ack;
- if (!param || !ac) {
- pr_err("%s: %s is NULL\n", __func__,
- (!param) ? "param" : "ac");
- rc = -EINVAL;
- goto done;
- }
- sz = sizeof(struct avs_param_rtic_event_ack) + params_length;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- rc = -ENOMEM;
- goto done;
- }
- q6asm_add_hdr_async(ac, &ack.hdr,
- sizeof(struct avs_param_rtic_event_ack) +
- params_length, TRUE);
- atomic_set(&ac->cmd_state, -1);
- ack.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2;
- ack.encdec.param_id = AVS_PARAM_ID_RTIC_EVENT_ACK;
- ack.encdec.param_size = params_length;
- ack.encdec.reserved = 0;
- ack.encdec.service_id = OUT;
- memcpy(asm_params, &ack, sizeof(struct avs_param_rtic_event_ack));
- memcpy(asm_params + sizeof(struct avs_param_rtic_event_ack),
- param, params_length);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: apr pkt failed for rtic event ack\n", __func__);
- rc = -EINVAL;
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 1 * HZ);
- if (!rc) {
- pr_err("%s: timeout for rtic event ack cmd\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_send_param;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] for rtic event ack cmd\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- kfree(asm_params);
- done:
- return rc;
- }
- int q6asm_set_softpause(struct audio_client *ac,
- struct asm_softpause_params *pause_param)
- {
- struct asm_soft_pause_params softpause;
- int sz = 0;
- int rc = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_soft_pause_params);
- q6asm_add_hdr_async(ac, &softpause.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- softpause.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- softpause.param.data_payload_addr_lsw = 0;
- softpause.param.data_payload_addr_msw = 0;
- softpause.param.mem_map_handle = 0;
- softpause.param.data_payload_size = sizeof(softpause) -
- sizeof(softpause.hdr) - sizeof(softpause.param);
- softpause.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- softpause.data.param_id = ASM_PARAM_ID_SOFT_PAUSE_PARAMETERS;
- softpause.data.param_size = softpause.param.data_payload_size -
- sizeof(softpause.data);
- softpause.data.reserved = 0;
- softpause.enable_flag = pause_param->enable;
- softpause.period = pause_param->period;
- softpause.step = pause_param->step;
- softpause.ramping_curve = pause_param->rampingcurve;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &softpause);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, softpause.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- softpause.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- softpause.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param,
- int instance)
- {
- struct asm_soft_step_volume_params softvol;
- int sz = 0;
- int rc = 0;
- int module_id;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- switch (instance) {
- case SOFT_VOLUME_INSTANCE_2:
- module_id = ASM_MODULE_ID_VOL_CTRL2;
- break;
- case SOFT_VOLUME_INSTANCE_1:
- default:
- module_id = ASM_MODULE_ID_VOL_CTRL;
- break;
- }
- sz = sizeof(struct asm_soft_step_volume_params);
- q6asm_add_hdr_async(ac, &softvol.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- softvol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- softvol.param.data_payload_addr_lsw = 0;
- softvol.param.data_payload_addr_msw = 0;
- softvol.param.mem_map_handle = 0;
- softvol.param.data_payload_size = sizeof(softvol) -
- sizeof(softvol.hdr) - sizeof(softvol.param);
- softvol.data.module_id = module_id;
- softvol.data.param_id = ASM_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
- softvol.data.param_size = softvol.param.data_payload_size -
- sizeof(softvol.data);
- softvol.data.reserved = 0;
- softvol.period = softvol_param->period;
- softvol.step = softvol_param->step;
- softvol.ramping_curve = softvol_param->rampingcurve;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &softvol);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, softvol.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- softvol.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- softvol.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param)
- {
- return __q6asm_set_softvolume(ac, softvol_param,
- SOFT_VOLUME_INSTANCE_1);
- }
- int q6asm_set_softvolume_v2(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param,
- int instance)
- {
- return __q6asm_set_softvolume(ac, softvol_param, instance);
- }
- int q6asm_equalizer(struct audio_client *ac, void *eq_p)
- {
- struct asm_eq_params eq;
- struct msm_audio_eq_stream_config *eq_params = NULL;
- int i = 0;
- int sz = 0;
- int rc = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (eq_p == NULL) {
- pr_err("%s: [%d]: Invalid Eq param\n", __func__, ac->session);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_eq_params);
- eq_params = (struct msm_audio_eq_stream_config *) eq_p;
- q6asm_add_hdr(ac, &eq.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- eq.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- eq.param.data_payload_addr_lsw = 0;
- eq.param.data_payload_addr_msw = 0;
- eq.param.mem_map_handle = 0;
- eq.param.data_payload_size = sizeof(eq) -
- sizeof(eq.hdr) - sizeof(eq.param);
- eq.data.module_id = ASM_MODULE_ID_EQUALIZER;
- eq.data.param_id = ASM_PARAM_ID_EQUALIZER_PARAMETERS;
- eq.data.param_size = eq.param.data_payload_size - sizeof(eq.data);
- eq.enable_flag = eq_params->enable;
- eq.num_bands = eq_params->num_bands;
- pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
- eq_params->num_bands);
- for (i = 0; i < eq_params->num_bands; i++) {
- eq.eq_bands[i].band_idx =
- eq_params->eq_bands[i].band_idx;
- eq.eq_bands[i].filterype =
- eq_params->eq_bands[i].filter_type;
- eq.eq_bands[i].center_freq_hz =
- eq_params->eq_bands[i].center_freq_hz;
- eq.eq_bands[i].filter_gain =
- eq_params->eq_bands[i].filter_gain;
- eq.eq_bands[i].q_factor =
- eq_params->eq_bands[i].q_factor;
- pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_type, i);
- pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].center_freq_hz, i);
- pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_gain, i);
- pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].q_factor, i);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *)&eq);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, eq.data.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- eq.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)),
- eq.data.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_read(struct audio_client *ac, bool is_custom_len_reqd,
- int len)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
- mutex_lock(&port->lock);
- dsp_buf = port->dsp_buf;
- if (port->buf == NULL) {
- pr_err("%s: buf is NULL\n", __func__);
- mutex_unlock(&port->lock);
- return -EINVAL;
- }
- ab = &port->buf[dsp_buf];
- dev_vdbg(ac->dev, "%s: session[%d]dsp-buf[%d][%pK]cpu_buf[%d][%pK]\n",
- __func__,
- ac->session,
- dsp_buf,
- port->buf[dsp_buf].data,
- port->cpu_buf,
- &port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(ab->phys);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == ab->phys)
- read.mem_map_handle = buf_node->mmap_hdl;
- }
- dev_vdbg(ac->dev, "memory_map handle in q6asm_read: [%0x]:",
- read.mem_map_handle);
- read.buf_size = is_custom_len_reqd ? len : ab->size;
- read.seq_id = port->dsp_buf;
- q6asm_update_token(&read.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- WAIT_CMD);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- mutex_unlock(&port->lock);
- dev_vdbg(ac->dev, "%s: buf add[%pK] token[0x%x] uid[%d]\n",
- __func__, &ab->phys, read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("%s: read op[0x%x]rc[%d]\n",
- __func__, read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_read(struct audio_client *ac)
- {
- return __q6asm_read(ac, false/*is_custom_len_reqd*/, 0);
- }
- int q6asm_read_v2(struct audio_client *ac, uint32_t len)
- {
- return __q6asm_read(ac, true /*is_custom_len_reqd*/, len);
- }
- int q6asm_read_nolock(struct audio_client *ac)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- dev_vdbg(ac->dev, "%s: session[%d]dsp-buf[%d][%pK]cpu_buf[%d][%pK]\n",
- __func__,
- ac->session,
- dsp_buf,
- port->buf[dsp_buf].data,
- port->cpu_buf,
- &port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(ab->phys);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- read.buf_size = ab->size;
- read.seq_id = port->dsp_buf;
- q6asm_update_token(&read.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- WAIT_CMD);
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == ab->phys) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- dev_vdbg(ac->dev, "%s: buf add[%pK] token[0x%x] uid[%d]\n",
- __func__, &ab->phys, read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("%s: read op[0x%x]rc[%d]\n",
- __func__, read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_async_write(struct audio_client *ac,
- struct audio_aio_write_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- struct audio_port_data *port;
- phys_addr_t lbuf_phys_addr;
- u32 liomode;
- u32 io_compressed;
- u32 io_compressed_stream;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(
- ac, &write.hdr, sizeof(write), TRUE, ac->stream_id);
- port = &ac->port[IN];
- ab = &port->buf[port->dsp_buf];
- /* Pass session id as token for AIO scheme */
- write.hdr.token = param->uid;
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(param->paddr);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(param->paddr);
- write.buf_size = param->len;
- write.timestamp_msw = param->msw_ts;
- write.timestamp_lsw = param->lsw_ts;
- liomode = (ASYNC_IO_MODE | NT_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- io_compressed_stream = (ASYNC_IO_MODE | COMPRESSED_STREAM_IO);
- if (ac->io_mode == liomode)
- lbuf_phys_addr = (param->paddr - 32);
- else if (ac->io_mode == io_compressed ||
- ac->io_mode == io_compressed_stream)
- lbuf_phys_addr = (param->paddr - param->metadata_len);
- else {
- if (param->flags & SET_TIMESTAMP)
- lbuf_phys_addr = param->paddr -
- sizeof(struct snd_codec_metadata);
- else
- lbuf_phys_addr = param->paddr;
- }
- dev_vdbg(ac->dev, "%s: token[0x%x], buf_addr[%pK], buf_size[0x%x], ts_msw[0x%x], ts_lsw[0x%x], lbuf_phys_addr: 0x[%pK]\n",
- __func__,
- write.hdr.token, ¶m->paddr,
- write.buf_size, write.timestamp_msw,
- write.timestamp_lsw, &lbuf_phys_addr);
- /* Use 0xFF00 for disabling timestamps */
- if (param->flags == 0xFF00)
- write.flags = (0x00000000 | (param->flags & 0x800000FF));
- else
- write.flags = (0x80000000 | param->flags);
- write.flags |= param->last_buffer << ASM_SHIFT_LAST_BUFFER_FLAG;
- write.seq_id = param->uid;
- list_for_each_safe(ptr, next, &ac->port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == lbuf_phys_addr) {
- write.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n", __func__,
- write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_async_read(struct audio_client *ac,
- struct audio_aio_read_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- phys_addr_t lbuf_phys_addr;
- u32 liomode;
- u32 io_compressed;
- int dir = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- /* Pass session id as token for AIO scheme */
- read.hdr.token = param->uid;
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(param->paddr);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(param->paddr);
- read.buf_size = param->len;
- read.seq_id = param->uid;
- liomode = (NT_MODE | ASYNC_IO_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- if (ac->io_mode == liomode) {
- lbuf_phys_addr = (param->paddr - 32);
- /*legacy wma driver case*/
- dir = IN;
- } else if (ac->io_mode == io_compressed) {
- lbuf_phys_addr = (param->paddr - 64);
- dir = OUT;
- } else {
- if (param->flags & COMPRESSED_TIMESTAMP_FLAG)
- lbuf_phys_addr = param->paddr -
- sizeof(struct snd_codec_metadata);
- else
- lbuf_phys_addr = param->paddr;
- dir = OUT;
- }
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == lbuf_phys_addr) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("%s: read op[0x%x]rc[%d]\n", __func__,
- read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] len=%d\n",
- __func__, ac->session, len);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[IN];
- q6asm_add_hdr(ac, &write.hdr, sizeof(write),
- FALSE);
- mutex_lock(&port->lock);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- q6asm_update_token(&write.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(ab->phys);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- dev_vdbg(ac->dev, "%s: ab->phys[%pK]bufadd[0x%x] token[0x%x]buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- &ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- mutex_unlock(&port->lock);
- config_debug_fs_write(ab);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n",
- __func__, write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] len=%d\n",
- __func__, ac->session, len);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[IN];
- q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
- FALSE);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- q6asm_update_token(&write.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(ab->phys);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- dev_vdbg(ac->dev, "%s: ab->phys[%pK]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- &ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n",
- __func__, write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
- {
- struct asm_mtmx_strtr_get_params mtmx_params;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (tstamp == NULL) {
- pr_err("%s: tstamp NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &mtmx_params.hdr, sizeof(mtmx_params), TRUE);
- mtmx_params.hdr.opcode = ASM_SESSION_CMD_GET_MTMX_STRTR_PARAMS_V2;
- mtmx_params.param_info.data_payload_addr_lsw = 0;
- mtmx_params.param_info.data_payload_addr_msw = 0;
- mtmx_params.param_info.mem_map_handle = 0;
- mtmx_params.param_info.direction = (ac->io_mode & TUN_READ_IO_MODE
- ? 1 : 0);
- mtmx_params.param_info.module_id =
- ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- mtmx_params.param_info.param_id =
- ASM_SESSION_MTMX_STRTR_PARAM_SESSION_TIME_V3;
- mtmx_params.param_info.param_max_size =
- sizeof(struct asm_stream_param_data_v2) +
- sizeof(struct asm_session_mtmx_strtr_param_session_time_v3_t);
- atomic_set(&ac->time_flag, 1);
- dev_vdbg(ac->dev, "%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session, mtmx_params.hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &mtmx_params);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n", __func__,
- mtmx_params.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->time_wait,
- (atomic_read(&ac->time_flag) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout in getting session time from DSP\n",
- __func__);
- goto fail_cmd;
- }
- *tstamp = ac->time_stamp;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_get_session_time_legacy(struct audio_client *ac, uint64_t *tstamp)
- {
- struct apr_hdr hdr;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (tstamp == NULL) {
- pr_err("%s: tstamp NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- hdr.opcode = ASM_SESSION_CMD_GET_SESSIONTIME_V3;
- atomic_set(&ac->time_flag, 1);
- dev_vdbg(ac->dev, "%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->time_wait,
- (atomic_read(&ac->time_flag) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout in getting session time from DSP\n",
- __func__);
- goto fail_cmd;
- }
- *tstamp = ac->time_stamp;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_send_audio_effects_params(struct audio_client *ac, char *params,
- uint32_t params_length)
- {
- char *asm_params = NULL;
- struct apr_hdr hdr;
- struct asm_stream_cmd_set_pp_params_v2 payload_params;
- int sz, rc;
- pr_debug("%s:\n", __func__);
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (params == NULL) {
- pr_err("%s: params NULL\n", __func__);
- return -EINVAL;
- }
- sz = sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2) +
- params_length;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- pr_err("%s, asm params memory alloc failed", __func__);
- return -ENOMEM;
- }
- q6asm_add_hdr_async(ac, &hdr, (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2) +
- params_length), TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- payload_params.data_payload_addr_lsw = 0;
- payload_params.data_payload_addr_msw = 0;
- payload_params.mem_map_handle = 0;
- payload_params.data_payload_size = params_length;
- memcpy(((u8 *)asm_params), &hdr, sizeof(struct apr_hdr));
- memcpy(((u8 *)asm_params + sizeof(struct apr_hdr)), &payload_params,
- sizeof(struct asm_stream_cmd_set_pp_params_v2));
- memcpy(((u8 *)asm_params + sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2)),
- params, params_length);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: audio effects set-params send failed\n", __func__);
- rc = -EINVAL;
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 1*HZ);
- if (!rc) {
- pr_err("%s: timeout, audio effects set-params\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_send_param;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] set-params\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- kfree(asm_params);
- return rc;
- }
- int q6asm_send_mtmx_strtr_window(struct audio_client *ac,
- struct asm_session_mtmx_strtr_param_window_v2_t *window_param,
- uint32_t param_id)
- {
- struct asm_mtmx_strtr_params matrix;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: Window lsw is %d, window msw is %d\n", __func__,
- window_param->window_lsw, window_param->window_msw);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct asm_stream_param_data_v2) +
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = param_id;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.window_param),
- window_param,
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: Render window start send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, Render window start paramid[0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_send_mtmx_strtr_render_mode(struct audio_client *ac,
- uint32_t render_mode)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_strtr_param_render_mode_t render_param;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: render mode is %d\n", __func__, render_mode);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if ((render_mode != ASM_SESSION_MTMX_STRTR_PARAM_RENDER_DEFAULT) &&
- (render_mode != ASM_SESSION_MTMX_STRTR_PARAM_RENDER_LOCAL_STC)) {
- pr_err("%s: Invalid render mode %d\n", __func__, render_mode);
- rc = -EINVAL;
- goto exit;
- }
- memset(&render_param, 0,
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t));
- render_param.flags = render_mode;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct asm_stream_param_data_v2) +
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_MODE_CMD;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.render_param),
- &render_param,
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: Render mode send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, Render mode send paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- int q6asm_send_mtmx_strtr_clk_rec_mode(struct audio_client *ac,
- uint32_t clk_rec_mode)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_strtr_param_clk_rec_t clk_rec_param;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: clk rec mode is %d\n", __func__, clk_rec_mode);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if ((clk_rec_mode != ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_NONE) &&
- (clk_rec_mode != ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_AUTO)) {
- pr_err("%s: Invalid clk rec mode %d\n", __func__, clk_rec_mode);
- rc = -EINVAL;
- goto exit;
- }
- memset(&clk_rec_param, 0,
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t));
- clk_rec_param.flags = clk_rec_mode;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct asm_stream_param_data_v2) +
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_CMD;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.clk_rec_param),
- &clk_rec_param,
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: clk rec mode send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, clk rec mode send paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- int q6asm_send_mtmx_strtr_enable_adjust_session_clock(struct audio_client *ac,
- bool enable)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_param_adjust_session_time_ctl_t adjust_time;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: adjust session enable %d\n", __func__, enable);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- adjust_time.enable = enable;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct asm_stream_param_data_v2) +
- sizeof(struct asm_session_mtmx_param_adjust_session_time_ctl_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_PARAM_ADJUST_SESSION_TIME_CTL;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_param_adjust_session_time_ctl_t);
- matrix.data.reserved = 0;
- matrix.config.adj_time_param.enable = adjust_time.enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: enable adjust session failed failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: enable adjust session failed failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- static int __q6asm_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- atomic_t *state;
- int cnt = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s: CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- state = &ac->cmd_state;
- break;
- case CMD_SUSPEND:
- pr_debug("%s: CMD_SUSPEND\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_SUSPEND;
- state = &ac->cmd_state;
- break;
- case CMD_FLUSH:
- pr_debug("%s: CMD_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH;
- state = &ac->cmd_state;
- break;
- case CMD_OUT_FLUSH:
- pr_debug("%s: CMD_OUT_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
- state = &ac->cmd_state;
- break;
- case CMD_EOS:
- pr_debug("%s: CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- atomic_set(&ac->cmd_state, 0);
- state = &ac->cmd_state;
- break;
- case CMD_CLOSE:
- pr_debug("%s: CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- state = &ac->cmd_state;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, cmd);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for response opcode[0x%x]\n",
- __func__, hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(state) > 0) {
- pr_err("%s: DSP returned error[%s] opcode %d\n",
- __func__, adsp_err_get_err_str(
- atomic_read(state)),
- hdr.opcode);
- rc = adsp_err_get_lnx_err_code(atomic_read(state));
- goto fail_cmd;
- }
- if (cmd == CMD_FLUSH)
- q6asm_reset_buf_state(ac);
- if (cmd == CMD_CLOSE) {
- /* check if DSP return all buffers */
- if (ac->port[IN].buf) {
- for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
- cnt++) {
- if (ac->port[IN].buf[cnt].used == IN) {
- dev_vdbg(ac->dev, "Write Buf[%d] not returned\n",
- cnt);
- }
- }
- }
- if (ac->port[OUT].buf) {
- for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
- if (ac->port[OUT].buf[cnt].used == OUT) {
- dev_vdbg(ac->dev, "Read Buf[%d] not returned\n",
- cnt);
- }
- }
- }
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_cmd(struct audio_client *ac, int cmd)
- {
- return __q6asm_cmd(ac, cmd, ac->stream_id);
- }
- int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- return __q6asm_cmd(ac, cmd, stream_id);
- }
- static int __q6asm_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s: CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- break;
- case CMD_EOS:
- pr_debug("%s: CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- break;
- case CMD_CLOSE:
- pr_debug("%s: CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, cmd);
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
- {
- pr_debug("%s: stream_id: %d\n", __func__, ac->stream_id);
- return __q6asm_cmd_nowait(ac, cmd, ac->stream_id);
- }
- int q6asm_stream_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- pr_debug("%s: stream_id: %d\n", __func__, stream_id);
- return __q6asm_cmd_nowait(ac, cmd, stream_id);
- }
- int __q6asm_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- struct asm_data_cmd_remove_silence silence;
- int rc = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_stream_add_hdr_async(ac, &silence.hdr, sizeof(silence), TRUE,
- stream_id);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&silence.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, silence.hdr.token, stream_id, ac->session);
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_INITIAL_SILENCE;
- silence.num_samples_to_remove = initial_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("%s: Commmand silence failed[%d]", __func__, rc);
- goto fail_cmd;
- }
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_TRAILING_SILENCE;
- silence.num_samples_to_remove = trailing_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("%s: Commmand silence failed[%d]", __func__, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_stream_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, stream_id, initial_samples,
- trailing_samples);
- }
- int q6asm_send_meta_data(struct audio_client *ac, uint32_t initial_samples,
- uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, ac->stream_id, initial_samples,
- trailing_samples);
- }
- static void q6asm_reset_buf_state(struct audio_client *ac)
- {
- int cnt = 0;
- int loopcnt = 0;
- int used;
- struct audio_port_data *port = NULL;
- if (ac->io_mode & SYNC_IO_MODE) {
- used = (ac->io_mode & TUN_WRITE_IO_MODE ? 1 : 0);
- mutex_lock(&ac->cmd_lock);
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- cnt = port->max_buf_cnt - 1;
- port->dsp_buf = 0;
- port->cpu_buf = 0;
- while (cnt >= 0) {
- if (!port->buf)
- continue;
- port->buf[cnt].used = used;
- cnt--;
- }
- }
- mutex_unlock(&ac->cmd_lock);
- }
- }
- int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_regx_overflow tx_overflow;
- int rc;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
- atomic_set(&ac->cmd_state, -1);
- tx_overflow.hdr.opcode =
- ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS;
- /* tx overflow event: enable */
- tx_overflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
- if (rc < 0) {
- pr_err("%s: tx overflow op[0x%x]rc[%d]\n",
- __func__, tx_overflow.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for tx overflow\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_reg_rx_underflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_rgstr_rx_underflow rx_underflow;
- int rc;
- if (!ac) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr_async(ac, &rx_underflow.hdr, sizeof(rx_underflow), FALSE);
- rx_underflow.hdr.opcode =
- ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS;
- /* tx overflow event: enable */
- rx_underflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &rx_underflow);
- if (rc < 0) {
- pr_err("%s: tx overflow op[0x%x]rc[%d]\n",
- __func__, rx_underflow.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_adjust_session_clock(struct audio_client *ac,
- uint32_t adjust_time_lsw,
- uint32_t adjust_time_msw)
- {
- int rc = 0;
- int sz = 0;
- struct asm_session_cmd_adjust_session_clock_v2 adjust_clock;
- pr_debug("%s: adjust_time_lsw is %x, adjust_time_msw is %x\n", __func__,
- adjust_time_lsw, adjust_time_msw);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_session_cmd_adjust_session_clock_v2);
- q6asm_add_hdr(ac, &adjust_clock.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- adjust_clock.hdr.opcode = ASM_SESSION_CMD_ADJUST_SESSION_CLOCK_V2;
- adjust_clock.adjustime_lsw = adjust_time_lsw;
- adjust_clock.adjustime_msw = adjust_time_msw;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &adjust_clock);
- if (rc < 0) {
- pr_err("%s: adjust_clock send failed paramid [0x%x]\n",
- __func__, adjust_clock.hdr.opcode);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, adjust_clock paramid[0x%x]\n",
- __func__, adjust_clock.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- /*
- * q6asm_get_path_delay() - get the path delay for an audio session
- * @ac: audio client handle
- *
- * Retrieves the current audio DSP path delay for the given audio session.
- *
- * Return: 0 on success, error code otherwise
- */
- int q6asm_get_path_delay(struct audio_client *ac)
- {
- int rc = 0;
- struct apr_hdr hdr;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: invalid audio client\n", __func__);
- return -EINVAL;
- }
- hdr.opcode = ASM_SESSION_CMD_GET_PATH_DELAY_V2;
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n", __func__,
- hdr.opcode, rc);
- return rc;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0), 5 * HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for response opcode[0x%x]\n",
- __func__, hdr.opcode);
- return -ETIMEDOUT;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- return rc;
- }
- return 0;
- }
- int q6asm_get_apr_service_id(int session_id)
- {
- pr_debug("%s:\n", __func__);
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- return -EINVAL;
- }
- return ((struct apr_svc *)session[session_id]->apr)->id;
- }
- int q6asm_get_asm_topology(int session_id)
- {
- int topology = -EINVAL;
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- goto done;
- }
- if (session[session_id] == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- topology = session[session_id]->topology;
- done:
- return topology;
- }
- int q6asm_get_asm_app_type(int session_id)
- {
- int app_type = -EINVAL;
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- goto done;
- }
- if (session[session_id] == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- app_type = session[session_id]->app_type;
- done:
- return app_type;
- }
- static int q6asm_get_asm_topology_cal(void)
- {
- int topology = DEFAULT_POPP_TOPOLOGY;
- struct cal_block_data *cal_block = NULL;
- if (cal_data[ASM_TOPOLOGY_CAL] == NULL)
- goto done;
- mutex_lock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_TOPOLOGY_CAL]);
- if (cal_block == NULL)
- goto unlock;
- topology = ((struct audio_cal_info_asm_top *)
- cal_block->cal_info)->topology;
- unlock:
- mutex_unlock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- done:
- pr_debug("%s: Using topology %d\n", __func__, topology);
- return topology;
- }
- static int q6asm_get_asm_app_type_cal(void)
- {
- int app_type = DEFAULT_APP_TYPE;
- struct cal_block_data *cal_block = NULL;
- if (cal_data[ASM_TOPOLOGY_CAL] == NULL)
- goto done;
- mutex_lock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_TOPOLOGY_CAL]);
- if (cal_block == NULL)
- goto unlock;
- app_type = ((struct audio_cal_info_asm_top *)
- cal_block->cal_info)->app_type;
- if (app_type == 0)
- app_type = DEFAULT_APP_TYPE;
- unlock:
- mutex_unlock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- done:
- pr_debug("%s: Using app_type %d\n", __func__, app_type);
- return app_type;
- }
- int q6asm_send_cal(struct audio_client *ac)
- {
- struct cal_block_data *cal_block = NULL;
- struct apr_hdr hdr;
- char *asm_params = NULL;
- struct asm_stream_cmd_set_pp_params_v2 payload_params;
- int sz, rc = -EINVAL;
- pr_debug("%s:\n", __func__);
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- goto done;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- goto done;
- }
- if (ac->io_mode & NT_MODE) {
- pr_debug("%s: called for NT MODE, exiting\n", __func__);
- goto done;
- }
- if (cal_data[ASM_AUDSTRM_CAL] == NULL)
- goto done;
- if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
- rc = 0; /* no cal is required, not error case */
- goto done;
- }
- mutex_lock(&cal_data[ASM_AUDSTRM_CAL]->lock);
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_AUDSTRM_CAL]);
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL\n",
- __func__);
- goto unlock;
- }
- if (cal_block->cal_data.size == 0) {
- rc = 0; /* not error case */
- pr_debug("%s: cal_data.size is 0, don't send cal data\n",
- __func__);
- goto unlock;
- }
- rc = remap_cal_data(ASM_AUDSTRM_CAL_TYPE, cal_block);
- if (rc) {
- pr_err("%s: Remap_cal_data failed for cal %d!\n",
- __func__, ASM_AUDSTRM_CAL);
- goto unlock;
- }
- sz = sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2);
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- pr_err("%s, asm params memory alloc failed", __func__);
- rc = -ENOMEM;
- goto unlock;
- }
- /* asm_stream_cmd_set_pp_params_v2 has no APR header in it */
- q6asm_add_hdr_async(ac, &hdr, (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2)), TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- payload_params.data_payload_addr_lsw =
- lower_32_bits(cal_block->cal_data.paddr);
- payload_params.data_payload_addr_msw =
- msm_audio_populate_upper_32_bits(
- cal_block->cal_data.paddr);
- payload_params.mem_map_handle = cal_block->map_data.q6map_handle;
- payload_params.data_payload_size = cal_block->cal_data.size;
- memcpy(((u8 *)asm_params), &hdr, sizeof(struct apr_hdr));
- memcpy(((u8 *)asm_params + sizeof(struct apr_hdr)), &payload_params,
- sizeof(struct asm_stream_cmd_set_pp_params_v2));
- pr_debug("%s: phyaddr lsw = %x msw = %x, maphdl = %x calsize = %d\n",
- __func__, payload_params.data_payload_addr_lsw,
- payload_params.data_payload_addr_msw,
- payload_params.mem_map_handle,
- payload_params.data_payload_size);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: audio audstrm cal send failed\n", __func__);
- rc = -EINVAL;
- goto free;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0), 5 * HZ);
- if (!rc) {
- pr_err("%s: timeout, audio audstrm cal send\n", __func__);
- rc = -ETIMEDOUT;
- goto free;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%d] audio audstrm cal send\n",
- __func__, atomic_read(&ac->cmd_state_pp));
- rc = -EINVAL;
- goto free;
- }
- rc = 0;
- free:
- kfree(asm_params);
- unlock:
- mutex_unlock(&cal_data[ASM_AUDSTRM_CAL]->lock);
- done:
- return rc;
- }
- static int get_cal_type_index(int32_t cal_type)
- {
- int ret = -EINVAL;
- switch (cal_type) {
- case ASM_TOPOLOGY_CAL_TYPE:
- ret = ASM_TOPOLOGY_CAL;
- break;
- case ASM_CUST_TOPOLOGY_CAL_TYPE:
- ret = ASM_CUSTOM_TOP_CAL;
- break;
- case ASM_AUDSTRM_CAL_TYPE:
- ret = ASM_AUDSTRM_CAL;
- break;
- case ASM_RTAC_APR_CAL_TYPE:
- ret = ASM_RTAC_APR_CAL;
- break;
- default:
- pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
- }
- return ret;
- }
- static int q6asm_alloc_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_alloc_cal(data_size, data,
- cal_data[cal_index], 0, NULL);
- if (ret < 0) {
- pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- done:
- return ret;
- }
- static int q6asm_dealloc_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_dealloc_cal(data_size, data,
- cal_data[cal_index]);
- if (ret < 0) {
- pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- done:
- return ret;
- }
- static int q6asm_set_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_set_cal(data_size, data,
- cal_data[cal_index], 0, NULL);
- if (ret < 0) {
- pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- if (cal_index == ASM_CUSTOM_TOP_CAL) {
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- set_custom_topology = 1;
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- }
- done:
- return ret;
- }
- static void q6asm_delete_cal_data(void)
- {
- pr_debug("%s:\n", __func__);
- cal_utils_destroy_cal_types(ASM_MAX_CAL_TYPES, cal_data);
- }
- static int q6asm_init_cal_data(void)
- {
- int ret = 0;
- struct cal_type_info cal_type_info[] = {
- {{ASM_TOPOLOGY_CAL_TYPE,
- {NULL, NULL, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, NULL, cal_utils_match_buf_num} },
- {{ASM_CUST_TOPOLOGY_CAL_TYPE,
- {q6asm_alloc_cal, q6asm_dealloc_cal, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, q6asm_unmap_cal_memory, cal_utils_match_buf_num} },
- {{ASM_AUDSTRM_CAL_TYPE,
- {q6asm_alloc_cal, q6asm_dealloc_cal, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, q6asm_unmap_cal_memory, cal_utils_match_buf_num} },
- {{ASM_RTAC_APR_CAL_TYPE,
- {NULL, NULL, NULL, NULL, NULL, NULL} },
- {NULL, NULL, cal_utils_match_buf_num} }
- };
- pr_debug("%s\n", __func__);
- ret = cal_utils_create_cal_types(ASM_MAX_CAL_TYPES, cal_data,
- cal_type_info);
- if (ret < 0) {
- pr_err("%s: could not create cal type! %d\n",
- __func__, ret);
- ret = -EINVAL;
- goto err;
- }
- return ret;
- err:
- q6asm_delete_cal_data();
- return ret;
- }
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv)
- {
- struct audio_client *ac = (struct audio_client *)priv;
- union asm_token_struct asm_token;
- asm_token.token = data->token;
- if (asm_token._token.session_id != ac->session) {
- pr_err("%s: Invalid session[%d] rxed expected[%d]",
- __func__, asm_token._token.session_id, ac->session);
- return -EINVAL;
- }
- return 0;
- }
- static int __init q6asm_init(void)
- {
- int lcnt, ret;
- pr_debug("%s:\n", __func__);
- memset(session, 0, sizeof(session));
- set_custom_topology = 1;
- /*setup common client used for cal mem map */
- common_client.session = ASM_CONTROL_SESSION;
- common_client.port[0].buf = &common_buf[0];
- common_client.port[1].buf = &common_buf[1];
- init_waitqueue_head(&common_client.cmd_wait);
- init_waitqueue_head(&common_client.time_wait);
- init_waitqueue_head(&common_client.mem_wait);
- atomic_set(&common_client.time_flag, 1);
- INIT_LIST_HEAD(&common_client.port[0].mem_map_handle);
- INIT_LIST_HEAD(&common_client.port[1].mem_map_handle);
- mutex_init(&common_client.cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&common_client.port[lcnt].lock);
- spin_lock_init(&common_client.port[lcnt].dsp_lock);
- }
- atomic_set(&common_client.cmd_state, 0);
- atomic_set(&common_client.mem_state, 0);
- ret = q6asm_init_cal_data();
- if (ret)
- pr_err("%s: could not init cal data! ret %d\n",
- __func__, ret);
- config_debug_fs_init();
- return 0;
- }
- static void __exit q6asm_exit(void)
- {
- q6asm_delete_cal_data();
- }
- device_initcall(q6asm_init);
- __exitcall(q6asm_exit);
|