12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354 |
- /*
- * 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;
- struct audio_session {
- struct audio_client *ac;
- spinlock_t session_lock;
- };
- /* session id: 0 reserved */
- static struct audio_session 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].ac)) {
- session[n].ac = ac;
- return n;
- }
- }
- pr_err("%s: session not available\n", __func__);
- return -ENOMEM;
- }
- static int q6asm_get_session_id_from_audio_client(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= ASM_ACTIVE_STREAMS_ALLOWED; n++) {
- if (session[n].ac == ac)
- return n;
- }
- return 0;
- }
- static bool q6asm_is_valid_audio_client(struct audio_client *ac)
- {
- return q6asm_get_session_id_from_audio_client(ac) ? 1 : 0;
- }
- static void q6asm_session_free(struct audio_client *ac)
- {
- int session_id;
- pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
- session_id = ac->session;
- rtac_remove_popp_from_adm_devices(ac->session);
- spin_lock_bh(&(session[session_id].session_lock));
- session[ac->session].ac = NULL;
- ac->session = 0;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- ac->cb = NULL;
- ac->priv = NULL;
- kfree(ac);
- ac = NULL;
- spin_unlock_bh(&(session[session_id].session_lock));
- }
- 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;
- }
- /**
- * q6asm_audio_client_buf_free_contiguous -
- * frees the memory buffers for ASM
- *
- * @dir: RX or TX direction
- * @ac: audio client handle
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_free_contiguous);
- /**
- * q6asm_audio_client_free -
- * frees the audio client for ASM
- *
- * @ac: audio client handle
- *
- */
- 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:*/
- mutex_unlock(&session_lock);
- }
- EXPORT_SYMBOL(q6asm_audio_client_free);
- /**
- * q6asm_set_io_mode -
- * Update IO mode for ASM
- *
- * @ac: audio client handle
- * @mode1: IO mode to update
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_io_mode);
- 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;
- }
- /**
- * q6asm_send_stream_cmd -
- * command to send for ASM stream
- *
- * @ac: audio client handle
- * @data: event data
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_stream_cmd);
- /**
- * q6asm_audio_client_alloc -
- * Alloc audio client for ASM
- *
- * @cb: callback fn
- * @priv: private data
- *
- * Returns ac pointer on success or NULL on failure
- */
- 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);
- kfree(ac);
- 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:
- return NULL;
- }
- EXPORT_SYMBOL(q6asm_audio_client_alloc);
- /**
- * q6asm_get_audio_client -
- * Retrieve audio client for ASM
- *
- * @session_id: ASM session id
- *
- * Returns valid pointer on success or NULL on failure
- */
- 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].ac)) {
- pr_err("%s: session not active: %d\n", __func__, session_id);
- goto err;
- }
- return session[session_id].ac;
- err:
- return NULL;
- }
- EXPORT_SYMBOL(q6asm_get_audio_client);
- /**
- * q6asm_audio_client_buf_alloc -
- * Allocs memory from ION for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @bufsz: size of each buffer
- * @bufcnt: number of buffers to alloc
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_alloc);
- /**
- * q6asm_audio_client_buf_alloc_contiguous -
- * Alloc contiguous memory from ION for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @bufsz: size of each buffer
- * @bufcnt: number of buffers to alloc
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_alloc_contiguous);
- 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;
- int session_id;
- 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;
- session_id = asm_token._token.session_id;
- if ((session_id > 0 && session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_lock(&(session[session_id].session_lock));
- ac = q6asm_get_audio_client(session_id);
- dir = q6asm_get_flag_from_token(&asm_token, ASM_DIRECTION_OFFSET);
- if (!ac) {
- pr_debug("%s: session[%d] already freed\n",
- __func__, session_id);
- if ((session_id > 0 &&
- session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock(&(session[session_id].session_lock));
- 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;
- }
- if ((session_id > 0 &&
- session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock(&(session[session_id].session_lock));
- 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);
- if ((session_id > 0 && session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock(&(session[session_id].session_lock));
- 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;
- int session_id;
- if (ac == NULL) {
- pr_err("%s: ac NULL\n", __func__);
- return -EINVAL;
- }
- if (data == NULL) {
- pr_err("%s: data NULL\n", __func__);
- return -EINVAL;
- }
- session_id = q6asm_get_session_id_from_audio_client(ac);
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- session_id);
- return -EINVAL;
- }
- spin_lock(&(session[session_id].session_lock));
- if (!q6asm_is_valid_audio_client(ac)) {
- pr_err("%s: audio client pointer is invalid, ac = %pK\n",
- __func__, ac);
- spin_unlock(&(session[session_id].session_lock));
- 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) {
- spin_unlock(&(session[session_id].session_lock));
- mutex_lock(&ac->cmd_lock);
- spin_lock(&(session[session_id].session_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);
- spin_unlock(&(session[session_id].session_lock));
- 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__);
- spin_unlock(&(session[session_id].session_lock));
- 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);
- spin_unlock(&(session[session_id].session_lock));
- 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);
- }
- spin_unlock(
- &(session[session_id].session_lock));
- 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);
- }
- spin_unlock(
- &(session[session_id].session_lock));
- 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;
- }
- spin_unlock(&(session[session_id].session_lock));
- 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__);
- spin_unlock(
- &(session[session_id].session_lock));
- 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);
- spin_unlock(
- &(session[session_id].session_lock));
- 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__);
- spin_unlock(
- &(session[session_id].session_lock));
- 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) {
- spin_unlock(&(session[session_id].session_lock));
- 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) {
- spin_unlock(&(session[session_id].session_lock));
- 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);
- spin_unlock(&(session[session_id].session_lock));
- 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);
- spin_unlock(&(session[session_id].session_lock));
- return 0;
- }
- /**
- * q6asm_is_cpu_buf_avail -
- * retrieve next CPU buf avail
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @size: size pointer to be updated with size of buffer
- * @index: index pointer to be updated with
- * CPU buffer index available
- *
- * Returns buffer pointer on success or NULL on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_is_cpu_buf_avail);
- /**
- * q6asm_cpu_buf_release -
- * releases cpu buffer for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_cpu_buf_release);
- /**
- * q6asm_is_cpu_buf_avail_nolock -
- * retrieve next CPU buf avail without lock acquire
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @size: size pointer to be updated with size of buffer
- * @index: index pointer to be updated with
- * CPU buffer index available
- *
- * Returns buffer pointer on success or NULL on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_is_cpu_buf_avail_nolock);
- 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;
- }
- /**
- * q6asm_open_read -
- * command to open ASM in read mode
- *
- * @ac: Audio client handle
- * @format: capture format for ASM
- *
- * Returns 0 on success or error on failure
- */
- 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*/);
- }
- EXPORT_SYMBOL(q6asm_open_read);
- 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);
- /**
- * q6asm_open_write_compressed -
- * command to open ASM in compressed write mode
- *
- * @ac: Audio client handle
- * @format: playback format for ASM
- * @passthrough_flag: flag to indicate passthrough option
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_open_write_compressed);
- 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*/);
- }
- EXPORT_SYMBOL(q6asm_open_write);
- 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;
- }
- /**
- * q6asm_open_read_write -
- * command to open ASM in read/write mode
- *
- * @ac: Audio client handle
- * @rd_format: capture format for ASM
- * @wr_format: playback format for ASM
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_open_read_write);
- /**
- * q6asm_open_read_write_v2 -
- * command to open ASM in bi-directional read/write mode
- *
- * @ac: Audio client handle
- * @rd_format: capture format for ASM
- * @wr_format: playback format for ASM
- * @is_meta_data_mode: mode to indicate if meta data present
- * @bits_per_sample: number of bits per sample
- * @overwrite_topology: topology to be overwritten flag
- * @topology: Topology for ASM
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_open_read_write_v2);
- /**
- * q6asm_open_loopback_v2 -
- * command to open ASM in loopback mode
- *
- * @ac: Audio client handle
- * @bits_per_sample: number of bits per sample
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_open_loopback_v2);
- /**
- * q6asm_open_transcode_loopback -
- * command to open ASM in transcode loopback mode
- *
- * @ac: Audio client handle
- * @bits_per_sample: number of bits per sample
- * @source_format: Format of clip
- * @sink_format: end device supported format
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_open_transcode_loopback);
- 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;
- mutex_lock(&ac->cmd_lock);
- if (ac->port[dir].buf) {
- pr_err("%s: Buffer already allocated\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- buf_circ = kzalloc(sizeof(struct audio_buffer), GFP_KERNEL);
- if (!buf_circ) {
- rc = -ENOMEM;
- goto done;
- }
- 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);
- kfree(buf_circ);
- goto done;
- }
- ac->port[dir].buf = buf_circ;
- 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;
- done:
- mutex_unlock(&ac->cmd_lock);
- 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;
- }
- 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;
- }
- EXPORT_SYMBOL(q6asm_get_shared_pos);
- /**
- * q6asm_run -
- * command to set ASM to run state
- *
- * @ac: Audio client handle
- * @flags: Flags for session
- * @msw_ts: upper 32bits timestamp
- * @lsw_ts: lower 32bits timestamp
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_run);
- 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;
- }
- /**
- * q6asm_run_nowait -
- * command to set ASM to run state with no wait for ack
- *
- * @ac: Audio client handle
- * @flags: Flags for session
- * @msw_ts: upper 32bits timestamp
- * @lsw_ts: lower 32bits timestamp
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_run_nowait);
- 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);
- }
- /**
- * q6asm_enc_cfg_blk_aac -
- * command to set encode cfg block for aac
- *
- * @ac: Audio client handle
- * @frames_per_buf: number of frames per buffer
- * @sample_rate: Sample rate
- * @channels: number of ASM channels
- * @bit_rate: Bit rate info
- * @mode: mode of AAC stream encode
- * @format: aac format flag
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_aac);
- /**
- * q6asm_enc_cfg_blk_g711 -
- * command to set encode cfg block for g711
- *
- * @ac: Audio client handle
- * @frames_per_buf: number of frames per buffer
- * @sample_rate: Sample rate
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_g711);
- /**
- * q6asm_set_encdec_chan_map -
- * command to set encdec channel map
- *
- * @ac: Audio client handle
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_encdec_chan_map);
- /*
- * 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);
- /**
- * q6asm_enc_cfg_blk_pcm_v2 -
- * command to set encode config block for pcm_v2
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: number of bits per sample
- * @use_default_chmap: Flag indicating to use default ch_map or not
- * @use_back_flavor: back flavor flag
- * @channel_map: Custom channel map settings
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v2);
- 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);
- }
- /**
- * q6asm_enc_cfg_blk_pcm -
- * command to set encode config block for pcm
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm);
- 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);
- /**
- * q6asm_enc_cfg_blk_pcm_native -
- * command to set encode config block for pcm_native
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_native);
- 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;
- }
- /**
- * q6asm_enable_sbrps -
- * command to enable sbrps for ASM
- *
- * @ac: Audio client handle
- * @sbr_ps_enable: flag for sbr_ps enable or disable
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enable_sbrps);
- /**
- * q6asm_cfg_dual_mono_aac -
- * command to set config for dual mono aac
- *
- * @ac: Audio client handle
- * @sce_left: left sce val
- * @sce_right: right sce val
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_cfg_dual_mono_aac);
- /* 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;
- }
- EXPORT_SYMBOL(q6asm_cfg_aac_sel_mix_coef);
- /**
- * q6asm_enc_cfg_blk_qcelp -
- * command to set encode config block for QCELP
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @min_rate: Minimum Enc rate
- * @max_rate: Maximum Enc rate
- * reduced_rate_level: Reduced rate level
- * @rate_modulation_cmd: rate modulation command
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_qcelp);
- /**
- * q6asm_enc_cfg_blk_evrc -
- * command to set encode config block for EVRC
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @min_rate: Minimum Enc rate
- * @max_rate: Maximum Enc rate
- * @rate_modulation_cmd: rate modulation command
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_evrc);
- /**
- * q6asm_enc_cfg_blk_amrnb -
- * command to set encode config block for AMRNB
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @band_mode: Band mode used
- * @dtx_enable: DTX en flag
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_amrnb);
- /**
- * q6asm_enc_cfg_blk_amrwb -
- * command to set encode config block for AMRWB
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @band_mode: Band mode used
- * @dtx_enable: DTX en flag
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_amrwb);
- 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;
- }
- /**
- * q6asm_media_format_block_pcm -
- * command to set mediafmt block for PCM on ASM stream
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of ASM channels
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm);
- /**
- * q6asm_media_format_block_pcm_format_support -
- * command to set mediafmt block for PCM format support
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of ASM channels
- * @bits_per_sample: number of bits per sample
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support);
- 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;
- }
- /**
- * q6asm_media_format_block_multi_aac -
- * command to set mediafmt block for multi_aac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: multi_aac config
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_aac);
- /**
- * q6asm_media_format_block_aac -
- * command to set mediafmt block for aac on ASM
- *
- * @ac: Audio client handle
- * @cfg: aac config
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_aac);
- /**
- * q6asm_stream_media_format_block_aac -
- * command to set mediafmt block for aac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: aac config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_aac);
- /**
- * q6asm_media_format_block_wma -
- * command to set mediafmt block for wma on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: wma config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_wma);
- /**
- * q6asm_media_format_block_wmapro -
- * command to set mediafmt block for wmapro on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: wmapro config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_wmapro);
- /**
- * q6asm_media_format_block_amrwbplus -
- * command to set mediafmt block for amrwbplus on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: amrwbplus config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_amrwbplus);
- /**
- * q6asm_stream_media_format_block_flac -
- * command to set mediafmt block for flac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: FLAC config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_flac);
- /**
- * q6asm_media_format_block_alac -
- * command to set mediafmt block for alac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: ALAC config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_alac);
- /*
- * 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);
- /**
- * q6asm_stream_media_format_block_vorbis -
- * command to set mediafmt block for vorbis on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: vorbis config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_vorbis);
- /**
- * q6asm_media_format_block_ape -
- * command to set mediafmt block for APE on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: APE config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_ape);
- /*
- * 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);
- /**
- * q6asm_stream_media_format_block_aptx_dec -
- * command to set mediafmt block for APTX dec on ASM stream
- *
- * @ac: Audio client handle
- * @srate: sample rate
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_aptx_dec);
- 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;
- }
- /**
- * q6asm_ds1_set_endp_params -
- * command to set DS1 params for ASM
- *
- * @ac: Audio client handle
- * @param_id: param id
- * @param_value: value of param
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- /**
- * q6asm_ds1_set_stream_endp_params -
- * command to set DS1 params for ASM stream
- *
- * @ac: Audio client handle
- * @param_id: param id
- * @param_value: value of param
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_ds1_set_stream_endp_params);
- /**
- * q6asm_memory_map -
- * command to send memory map for ASM
- *
- * @ac: Audio client handle
- * @buf_add: buffer address to map
- * @dir: RX or TX session
- * @bufsz: size of each buffer
- * @bufcnt: buffer count
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_memory_map);
- /**
- * q6asm_memory_unmap -
- * command to send memory unmap for ASM
- *
- * @ac: Audio client handle
- * @buf_add: buffer address to unmap
- * @dir: RX or TX session
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_memory_unmap);
- /**
- * q6asm_memory_map_regions -
- * command to send memory map regions for ASM
- *
- * @ac: Audio client handle
- * @dir: RX or TX session
- * @bufsz: size of each buffer
- * @bufcnt: buffer count
- * @is_contiguous: alloc contiguous mem or not
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_memory_map_regions);
- /**
- * q6asm_memory_unmap_regions -
- * command to send memory unmap regions for ASM
- *
- * @ac: Audio client handle
- * @dir: RX or TX session
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_memory_unmap_regions);
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_multich_gain);
- /**
- * q6asm_set_mute -
- * command to set mute for ASM
- *
- * @ac: Audio client handle
- * @muteflag: mute value
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_mute);
- 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;
- }
- /**
- * q6asm_set_volume -
- * command to set volume for ASM
- *
- * @ac: Audio client handle
- * @volume: volume level
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_volume(struct audio_client *ac, int volume)
- {
- return __q6asm_set_volume(ac, volume, SOFT_VOLUME_INSTANCE_1);
- }
- EXPORT_SYMBOL(q6asm_set_volume);
- int q6asm_set_volume_v2(struct audio_client *ac, int volume, int instance)
- {
- return __q6asm_set_volume(ac, volume, instance);
- }
- /**
- * q6asm_set_aptx_dec_bt_addr -
- * command to aptx decoder BT addr for ASM
- *
- * @ac: Audio client handle
- * @cfg: APTX decoder bt addr config
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_aptx_dec_bt_addr);
- /**
- * q6asm_send_ion_fd -
- * command to send ION memory map for ASM
- *
- * @ac: Audio client handle
- * @fd: ION file desc
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_ion_fd);
- /**
- * q6asm_send_rtic_event_ack -
- * command to send RTIC event ack
- *
- * @ac: Audio client handle
- * @param: params for event ack
- * @params_length: length of params
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_rtic_event_ack);
- /**
- * q6asm_set_softpause -
- * command to set pause for ASM
- *
- * @ac: Audio client handle
- * @pause_param: params for pause
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_set_softpause);
- 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;
- }
- /**
- * q6asm_set_softvolume -
- * command to set softvolume for ASM
- *
- * @ac: Audio client handle
- * @softvol_param: params for softvol
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_set_softvolume);
- /**
- * q6asm_set_softvolume_v2 -
- * command to set softvolume V2 for ASM
- *
- * @ac: Audio client handle
- * @softvol_param: params for softvol
- * @instance: instance to apply softvol
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_set_softvolume_v2);
- /**
- * q6asm_equalizer -
- * command to set equalizer for ASM
- *
- * @ac: Audio client handle
- * @eq_p: Equalizer params
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_equalizer);
- 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;
- }
- /**
- * q6asm_read -
- * command to read buffer data from DSP
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_read(struct audio_client *ac)
- {
- return __q6asm_read(ac, false/*is_custom_len_reqd*/, 0);
- }
- EXPORT_SYMBOL(q6asm_read);
- /**
- * q6asm_read_v2 -
- * command to read buffer data from DSP
- *
- * @ac: Audio client handle
- * @len: buffer size to read
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_read_v2(struct audio_client *ac, uint32_t len)
- {
- return __q6asm_read(ac, true /*is_custom_len_reqd*/, len);
- }
- EXPORT_SYMBOL(q6asm_read_v2);
- /**
- * q6asm_read_nolock -
- * command to read buffer data from DSP
- * with no wait for ack.
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_read_nolock);
- /**
- * q6asm_async_write -
- * command to write DSP buffer
- *
- * @ac: Audio client handle
- * @param: params for async write
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_async_write);
- /**
- * q6asm_async_read -
- * command to read DSP buffer
- *
- * @ac: Audio client handle
- * @param: params for async read
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_async_read);
- /**
- * q6asm_write -
- * command to write buffer data to DSP
- *
- * @ac: Audio client handle
- * @len: buffer size
- * @msw_ts: upper 32bits of timestamp
- * @lsw_ts: lower 32bits of timestamp
- * @flags: Flags for timestamp mode
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_write);
- /**
- * q6asm_write_nolock -
- * command to write buffer data to DSP
- * with no wait for ack.
- *
- * @ac: Audio client handle
- * @len: buffer size
- * @msw_ts: upper 32bits of timestamp
- * @lsw_ts: lower 32bits of timestamp
- * @flags: Flags for timestamp mode
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_write_nolock);
- /**
- * q6asm_get_session_time -
- * command to retrieve timestamp info
- *
- * @ac: Audio client handle
- * @tstamp: pointer to fill with timestamp info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_get_session_time);
- /**
- * q6asm_get_session_time_legacy -
- * command to retrieve timestamp info
- *
- * @ac: Audio client handle
- * @tstamp: pointer to fill with timestamp info
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_get_session_time_legacy);
- /**
- * q6asm_send_audio_effects_params -
- * command to send audio effects params
- *
- * @ac: Audio client handle
- * @params: audio effects params
- * @params_length: size of params
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_audio_effects_params);
- /**
- * q6asm_send_mtmx_strtr_window -
- * command to send matrix for window params
- *
- * @ac: Audio client handle
- * @window_param: window params
- * @param_id: param id for window
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_window);
- /**
- * q6asm_send_mtmx_strtr_render_mode -
- * command to send matrix for render mode
- *
- * @ac: Audio client handle
- * @render_mode: rendering mode
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_render_mode);
- /**
- * q6asm_send_mtmx_strtr_clk_rec_mode -
- * command to send matrix for clock rec
- *
- * @ac: Audio client handle
- * @clk_rec_mode: mode for clock rec
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_clk_rec_mode);
- /**
- * q6asm_send_mtmx_strtr_enable_adjust_session_clock -
- * command to send matrix for adjust time
- *
- * @ac: Audio client handle
- * @enable: flag to adjust time or not
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_enable_adjust_session_clock);
- 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;
- }
- /**
- * q6asm_cmd -
- * Function used to send commands for
- * ASM with wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_cmd(struct audio_client *ac, int cmd)
- {
- return __q6asm_cmd(ac, cmd, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_cmd);
- /**
- * q6asm_stream_cmd -
- * Function used to send commands for
- * ASM stream with wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- return __q6asm_cmd(ac, cmd, stream_id);
- }
- EXPORT_SYMBOL(q6asm_stream_cmd);
- /**
- * q6asm_cmd_nowait -
- * Function used to send commands for
- * ASM stream without wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_cmd_nowait);
- /**
- * q6asm_stream_cmd_nowait -
- * Function used to send commands for
- * ASM stream without wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_stream_cmd_nowait);
- 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;
- }
- /**
- * q6asm_stream_send_meta_data -
- * command to send meta data for stream
- *
- * @ac: Audio client handle
- * @stream_id: Stream ID
- * @initial_samples: Initial samples of stream
- * @trailing_samples: Trailing samples of stream
- *
- * Returns 0 on success or error on failure
- */
- 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);
- }
- EXPORT_SYMBOL(q6asm_stream_send_meta_data);
- 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);
- }
- }
- /**
- * q6asm_reg_tx_overflow -
- * command to register for TX overflow events
- *
- * @ac: Audio client handle
- * @enable: flag to enable or disable events
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_reg_tx_overflow);
- 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;
- }
- /**
- * q6asm_adjust_session_clock -
- * command to adjust session clock
- *
- * @ac: Audio client handle
- * @adjust_time_lsw: lower 32bits
- * @adjust_time_msw: upper 32bits
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_adjust_session_clock);
- /*
- * 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;
- }
- EXPORT_SYMBOL(q6asm_get_path_delay);
- 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].ac)->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].ac == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- topology = (session[session_id].ac)->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].ac == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- app_type = (session[session_id].ac)->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;
- }
- /**
- * q6asm_send_cal -
- * command to send ASM calibration
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- 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;
- }
- EXPORT_SYMBOL(q6asm_send_cal);
- 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;
- }
- int __init q6asm_init(void)
- {
- int lcnt, ret;
- pr_debug("%s:\n", __func__);
- memset(session, 0, sizeof(struct audio_session) *
- (ASM_ACTIVE_STREAMS_ALLOWED + 1));
- for (lcnt = 0; lcnt <= ASM_ACTIVE_STREAMS_ALLOWED; lcnt++)
- spin_lock_init(&(session[lcnt].session_lock));
- 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;
- }
- void q6asm_exit(void)
- {
- q6asm_delete_cal_data();
- }
|