q6voice.c 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661
  1. /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/kthread.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/wait.h>
  18. #include <linux/mutex.h>
  19. #include <soc/qcom/socinfo.h>
  20. #include <dsp/msm_audio_ion.h>
  21. #include <dsp/q6audio-v2.h>
  22. #include <dsp/apr_audio-v2.h>
  23. #include <dsp/q6afe-v2.h>
  24. #include <dsp/audio_cal_utils.h>
  25. #include <ipc/apr_tal.h>
  26. #include <dsp/q6voice.h>
  27. #include "adsp_err.h"
  28. #define TIMEOUT_MS 300
  29. #define CMD_STATUS_SUCCESS 0
  30. #define CMD_STATUS_FAIL 1
  31. enum {
  32. VOC_TOKEN_NONE,
  33. VOIP_MEM_MAP_TOKEN,
  34. VOC_CAL_MEM_MAP_TOKEN,
  35. VOC_VOICE_HOST_PCM_MAP_TOKEN,
  36. VOC_RTAC_MEM_MAP_TOKEN,
  37. VOC_SOURCE_TRACKING_MEM_MAP_TOKEN
  38. };
  39. struct cvd_version_table cvd_version_table_mapping[CVD_INT_VERSION_MAX] = {
  40. {CVD_VERSION_DEFAULT, CVD_INT_VERSION_DEFAULT},
  41. {CVD_VERSION_0_0, CVD_INT_VERSION_0_0},
  42. {CVD_VERSION_2_1, CVD_INT_VERSION_2_1},
  43. {CVD_VERSION_2_2, CVD_INT_VERSION_2_2},
  44. {CVD_VERSION_2_3, CVD_INT_VERSION_2_3},
  45. };
  46. static struct common_data common;
  47. static bool module_initialized;
  48. static int voice_send_enable_vocproc_cmd(struct voice_data *v);
  49. static int voice_send_netid_timing_cmd(struct voice_data *v);
  50. static int voice_send_attach_vocproc_cmd(struct voice_data *v);
  51. static int voice_send_set_device_cmd(struct voice_data *v);
  52. static int voice_send_vol_step_cmd(struct voice_data *v);
  53. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  54. uint32_t mem_handle);
  55. static int voice_send_mvm_cal_network_cmd(struct voice_data *v);
  56. static int voice_send_mvm_media_type_cmd(struct voice_data *v);
  57. static int voice_send_mvm_cvd_version_cmd(struct voice_data *v);
  58. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v);
  59. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v);
  60. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  61. uint32_t mode);
  62. static int voice_send_cvs_register_cal_cmd(struct voice_data *v);
  63. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v);
  64. static int voice_send_cvp_create_cmd(struct voice_data *v);
  65. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v);
  66. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v);
  67. static int voice_send_cvp_register_cal_cmd(struct voice_data *v);
  68. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v);
  69. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v);
  70. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v);
  71. static int voice_send_cvp_media_fmt_info_cmd(struct voice_data *v);
  72. static int voice_send_cvp_device_channels_cmd(struct voice_data *v);
  73. static int voice_send_cvp_media_format_cmd(struct voice_data *v,
  74. uint32_t param_type);
  75. static int voice_send_cvp_topology_commit_cmd(struct voice_data *v);
  76. static int voice_cvs_stop_playback(struct voice_data *v);
  77. static int voice_cvs_start_playback(struct voice_data *v);
  78. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode);
  79. static int voice_cvs_stop_record(struct voice_data *v);
  80. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
  81. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
  82. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
  83. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  84. uint32_t module_id, int enable);
  85. static int is_cal_memory_allocated(void);
  86. static bool is_cvd_version_queried(void);
  87. static int is_voip_memory_allocated(void);
  88. static int voice_get_cvd_int_version(char *cvd_ver_string);
  89. static int voice_alloc_cal_mem_map_table(void);
  90. static int voice_alloc_rtac_mem_map_table(void);
  91. static int voice_alloc_oob_shared_mem(void);
  92. static int voice_free_oob_shared_mem(void);
  93. static int voice_alloc_oob_mem_table(void);
  94. static int voice_alloc_and_map_oob_mem(struct voice_data *v);
  95. static struct voice_data *voice_get_session_by_idx(int idx);
  96. static int remap_cal_data(struct cal_block_data *cal_block,
  97. uint32_t session_id);
  98. static int voice_unmap_cal_memory(int32_t cal_type,
  99. struct cal_block_data *cal_block);
  100. static int is_source_tracking_shared_memomry_allocated(void);
  101. static int voice_alloc_source_tracking_shared_memory(void);
  102. static int voice_alloc_and_map_source_tracking_shared_memory(
  103. struct voice_data *v);
  104. static int voice_unmap_and_free_source_tracking_shared_memory(
  105. struct voice_data *v);
  106. static int voice_send_set_sound_focus_cmd(struct voice_data *v,
  107. struct sound_focus_param soundFocusData);
  108. static int voice_send_get_sound_focus_cmd(struct voice_data *v,
  109. struct sound_focus_param *soundFocusData);
  110. static int voice_send_get_source_tracking_cmd(struct voice_data *v,
  111. struct source_tracking_param *sourceTrackingData);
  112. static void voice_itr_init(struct voice_session_itr *itr,
  113. u32 session_id)
  114. {
  115. if (itr == NULL)
  116. return;
  117. itr->session_idx = voice_get_idx_for_session(session_id);
  118. if (session_id == ALL_SESSION_VSID)
  119. itr->cur_idx = 0;
  120. else
  121. itr->cur_idx = itr->session_idx;
  122. }
  123. static bool voice_itr_get_next_session(struct voice_session_itr *itr,
  124. struct voice_data **voice)
  125. {
  126. bool ret = false;
  127. if (itr == NULL)
  128. return false;
  129. pr_debug("%s : cur idx = %d session idx = %d\n",
  130. __func__, itr->cur_idx, itr->session_idx);
  131. if (itr->cur_idx <= itr->session_idx) {
  132. ret = true;
  133. *voice = voice_get_session_by_idx(itr->cur_idx);
  134. itr->cur_idx++;
  135. } else {
  136. *voice = NULL;
  137. }
  138. return ret;
  139. }
  140. static bool voice_is_valid_session_id(uint32_t session_id)
  141. {
  142. bool ret = false;
  143. switch (session_id) {
  144. case VOICE_SESSION_VSID:
  145. case VOICE2_SESSION_VSID:
  146. case VOLTE_SESSION_VSID:
  147. case VOIP_SESSION_VSID:
  148. case QCHAT_SESSION_VSID:
  149. case VOWLAN_SESSION_VSID:
  150. case VOICEMMODE1_VSID:
  151. case VOICEMMODE2_VSID:
  152. case ALL_SESSION_VSID:
  153. ret = true;
  154. break;
  155. default:
  156. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  157. break;
  158. }
  159. return ret;
  160. }
  161. static u16 voice_get_mvm_handle(struct voice_data *v)
  162. {
  163. if (v == NULL) {
  164. pr_err("%s: v is NULL\n", __func__);
  165. return 0;
  166. }
  167. pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
  168. return v->mvm_handle;
  169. }
  170. static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
  171. {
  172. pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
  173. if (v == NULL) {
  174. pr_err("%s: v is NULL\n", __func__);
  175. return;
  176. }
  177. v->mvm_handle = mvm_handle;
  178. }
  179. static u16 voice_get_cvs_handle(struct voice_data *v)
  180. {
  181. if (v == NULL) {
  182. pr_err("%s: v is NULL\n", __func__);
  183. return 0;
  184. }
  185. pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
  186. return v->cvs_handle;
  187. }
  188. static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
  189. {
  190. pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
  191. if (v == NULL) {
  192. pr_err("%s: v is NULL\n", __func__);
  193. return;
  194. }
  195. v->cvs_handle = cvs_handle;
  196. }
  197. static u16 voice_get_cvp_handle(struct voice_data *v)
  198. {
  199. if (v == NULL) {
  200. pr_err("%s: v is NULL\n", __func__);
  201. return 0;
  202. }
  203. pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
  204. return v->cvp_handle;
  205. }
  206. static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
  207. {
  208. pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
  209. if (v == NULL) {
  210. pr_err("%s: v is NULL\n", __func__);
  211. return;
  212. }
  213. v->cvp_handle = cvp_handle;
  214. }
  215. char *voc_get_session_name(u32 session_id)
  216. {
  217. char *session_name = NULL;
  218. if (session_id == common.voice[VOC_PATH_PASSIVE].session_id) {
  219. session_name = VOICE_SESSION_NAME;
  220. } else if (session_id ==
  221. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id) {
  222. session_name = VOLTE_SESSION_NAME;
  223. } else if (session_id ==
  224. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id) {
  225. session_name = QCHAT_SESSION_NAME;
  226. } else if (session_id ==
  227. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id) {
  228. session_name = VOWLAN_SESSION_NAME;
  229. } else if (session_id ==
  230. common.voice[VOC_PATH_VOICEMMODE1_PASSIVE].session_id) {
  231. session_name = VOICEMMODE1_NAME;
  232. } else if (session_id ==
  233. common.voice[VOC_PATH_VOICEMMODE2_PASSIVE].session_id) {
  234. session_name = VOICEMMODE2_NAME;
  235. } else if (session_id == common.voice[VOC_PATH_FULL].session_id) {
  236. session_name = VOIP_SESSION_NAME;
  237. }
  238. return session_name;
  239. }
  240. uint32_t voc_get_session_id(char *name)
  241. {
  242. u32 session_id = 0;
  243. if (name != NULL) {
  244. if (!strcmp(name, "Voice session"))
  245. session_id = common.voice[VOC_PATH_PASSIVE].session_id;
  246. else if (!strcmp(name, "Voice2 session"))
  247. session_id =
  248. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id;
  249. else if (!strcmp(name, "VoLTE session"))
  250. session_id =
  251. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id;
  252. else if (!strcmp(name, "QCHAT session"))
  253. session_id =
  254. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id;
  255. else if (!strcmp(name, "VoWLAN session"))
  256. session_id =
  257. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id;
  258. else if (!strcmp(name, "VoiceMMode1"))
  259. session_id =
  260. common.voice[VOC_PATH_VOICEMMODE1_PASSIVE].session_id;
  261. else if (!strcmp(name, "VoiceMMode2"))
  262. session_id =
  263. common.voice[VOC_PATH_VOICEMMODE2_PASSIVE].session_id;
  264. else
  265. session_id = common.voice[VOC_PATH_FULL].session_id;
  266. pr_debug("%s: %s has session id 0x%x\n", __func__, name,
  267. session_id);
  268. }
  269. return session_id;
  270. }
  271. static struct voice_data *voice_get_session(u32 session_id)
  272. {
  273. struct voice_data *v = NULL;
  274. switch (session_id) {
  275. case VOICE_SESSION_VSID:
  276. v = &common.voice[VOC_PATH_PASSIVE];
  277. break;
  278. case VOICE2_SESSION_VSID:
  279. v = &common.voice[VOC_PATH_VOICE2_PASSIVE];
  280. break;
  281. case VOLTE_SESSION_VSID:
  282. v = &common.voice[VOC_PATH_VOLTE_PASSIVE];
  283. break;
  284. case VOIP_SESSION_VSID:
  285. v = &common.voice[VOC_PATH_FULL];
  286. break;
  287. case QCHAT_SESSION_VSID:
  288. v = &common.voice[VOC_PATH_QCHAT_PASSIVE];
  289. break;
  290. case VOWLAN_SESSION_VSID:
  291. v = &common.voice[VOC_PATH_VOWLAN_PASSIVE];
  292. break;
  293. case VOICEMMODE1_VSID:
  294. v = &common.voice[VOC_PATH_VOICEMMODE1_PASSIVE];
  295. break;
  296. case VOICEMMODE2_VSID:
  297. v = &common.voice[VOC_PATH_VOICEMMODE2_PASSIVE];
  298. break;
  299. case ALL_SESSION_VSID:
  300. break;
  301. default:
  302. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  303. break;
  304. }
  305. pr_debug("%s:session_id 0x%x session handle %pK\n",
  306. __func__, session_id, v);
  307. return v;
  308. }
  309. int voice_get_idx_for_session(u32 session_id)
  310. {
  311. int idx = 0;
  312. switch (session_id) {
  313. case VOICE_SESSION_VSID:
  314. idx = VOC_PATH_PASSIVE;
  315. break;
  316. case VOICE2_SESSION_VSID:
  317. idx = VOC_PATH_VOICE2_PASSIVE;
  318. break;
  319. case VOLTE_SESSION_VSID:
  320. idx = VOC_PATH_VOLTE_PASSIVE;
  321. break;
  322. case VOIP_SESSION_VSID:
  323. idx = VOC_PATH_FULL;
  324. break;
  325. case QCHAT_SESSION_VSID:
  326. idx = VOC_PATH_QCHAT_PASSIVE;
  327. break;
  328. case VOWLAN_SESSION_VSID:
  329. idx = VOC_PATH_VOWLAN_PASSIVE;
  330. break;
  331. case VOICEMMODE1_VSID:
  332. idx = VOC_PATH_VOICEMMODE1_PASSIVE;
  333. break;
  334. case VOICEMMODE2_VSID:
  335. idx = VOC_PATH_VOICEMMODE2_PASSIVE;
  336. break;
  337. case ALL_SESSION_VSID:
  338. idx = MAX_VOC_SESSIONS - 1;
  339. break;
  340. default:
  341. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  342. break;
  343. }
  344. return idx;
  345. }
  346. static struct voice_data *voice_get_session_by_idx(int idx)
  347. {
  348. return ((idx < 0 || idx >= MAX_VOC_SESSIONS) ?
  349. NULL : &common.voice[idx]);
  350. }
  351. static bool is_voip_session(u32 session_id)
  352. {
  353. return (session_id == common.voice[VOC_PATH_FULL].session_id);
  354. }
  355. static bool is_volte_session(u32 session_id)
  356. {
  357. return (session_id == common.voice[VOC_PATH_VOLTE_PASSIVE].session_id);
  358. }
  359. static bool is_voice2_session(u32 session_id)
  360. {
  361. return (session_id == common.voice[VOC_PATH_VOICE2_PASSIVE].session_id);
  362. }
  363. static bool is_qchat_session(u32 session_id)
  364. {
  365. return (session_id == common.voice[VOC_PATH_QCHAT_PASSIVE].session_id);
  366. }
  367. static bool is_vowlan_session(u32 session_id)
  368. {
  369. return (session_id == common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id);
  370. }
  371. static bool is_voicemmode1(u32 session_id)
  372. {
  373. return session_id ==
  374. common.voice[VOC_PATH_VOICEMMODE1_PASSIVE].session_id;
  375. }
  376. static bool is_voicemmode2(u32 session_id)
  377. {
  378. return session_id ==
  379. common.voice[VOC_PATH_VOICEMMODE2_PASSIVE].session_id;
  380. }
  381. static bool is_voc_state_active(int voc_state)
  382. {
  383. if ((voc_state == VOC_RUN) ||
  384. (voc_state == VOC_CHANGE) ||
  385. (voc_state == VOC_STANDBY))
  386. return true;
  387. return false;
  388. }
  389. static void voc_set_error_state(uint16_t reset_proc)
  390. {
  391. struct voice_data *v = NULL;
  392. int i;
  393. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  394. v = &common.voice[i];
  395. if (v != NULL) {
  396. v->voc_state = VOC_ERROR;
  397. v->rec_info.recording = 0;
  398. }
  399. }
  400. }
  401. static bool is_other_session_active(u32 session_id)
  402. {
  403. int i;
  404. bool ret = false;
  405. /* Check if there is other active session except the input one */
  406. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  407. if (common.voice[i].session_id == session_id)
  408. continue;
  409. if (is_voc_state_active(common.voice[i].voc_state)) {
  410. ret = true;
  411. break;
  412. }
  413. }
  414. pr_debug("%s: ret %d\n", __func__, ret);
  415. return ret;
  416. }
  417. static bool is_sub1_vsid(u32 session_id)
  418. {
  419. bool ret;
  420. switch (session_id) {
  421. case VOICE_SESSION_VSID:
  422. case VOLTE_SESSION_VSID:
  423. case VOWLAN_SESSION_VSID:
  424. case VOICEMMODE1_VSID:
  425. ret = true;
  426. break;
  427. default:
  428. ret = false;
  429. }
  430. return ret;
  431. }
  432. static bool is_sub2_vsid(u32 session_id)
  433. {
  434. bool ret;
  435. switch (session_id) {
  436. case VOICE2_SESSION_VSID:
  437. case VOICEMMODE2_VSID:
  438. ret = true;
  439. break;
  440. default:
  441. ret = false;
  442. }
  443. return ret;
  444. }
  445. static bool is_voice_app_id(u32 session_id)
  446. {
  447. return is_sub1_vsid(session_id) || is_sub2_vsid(session_id);
  448. }
  449. static void init_session_id(void)
  450. {
  451. common.voice[VOC_PATH_PASSIVE].session_id = VOICE_SESSION_VSID;
  452. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id = VOLTE_SESSION_VSID;
  453. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id = VOICE2_SESSION_VSID;
  454. common.voice[VOC_PATH_FULL].session_id = VOIP_SESSION_VSID;
  455. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id = QCHAT_SESSION_VSID;
  456. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id = VOWLAN_SESSION_VSID;
  457. common.voice[VOC_PATH_VOICEMMODE1_PASSIVE].session_id =
  458. VOICEMMODE1_VSID;
  459. common.voice[VOC_PATH_VOICEMMODE2_PASSIVE].session_id =
  460. VOICEMMODE2_VSID;
  461. }
  462. static bool is_cvd_version_queried(void)
  463. {
  464. bool ret = 0;
  465. if (!strcmp(common.cvd_version, CVD_VERSION_DEFAULT))
  466. ret = false;
  467. else
  468. ret = true;
  469. return ret;
  470. }
  471. static int voice_get_cvd_int_version(char *cvd_ver_string)
  472. {
  473. unsigned int idx;
  474. int cvd_int_ver = CVD_INT_VERSION_DEFAULT;
  475. for (idx = 0; idx < CVD_INT_VERSION_MAX; idx++) {
  476. if (strcmp((char *)cvd_ver_string,
  477. cvd_version_table_mapping[idx].cvd_ver) == 0) {
  478. cvd_int_ver =
  479. cvd_version_table_mapping[idx].cvd_ver_int;
  480. break;
  481. }
  482. }
  483. return cvd_int_ver;
  484. }
  485. static int voice_apr_register(uint32_t session_id)
  486. {
  487. pr_debug("%s\n", __func__);
  488. mutex_lock(&common.common_lock);
  489. /* register callback to APR */
  490. if (common.apr_q6_mvm == NULL) {
  491. pr_debug("%s: Start to register MVM callback\n", __func__);
  492. common.apr_q6_mvm = apr_register("ADSP", "MVM",
  493. qdsp_mvm_callback,
  494. 0xFFFFFFFF, &common);
  495. if (common.apr_q6_mvm == NULL) {
  496. pr_err("%s: Unable to register MVM\n", __func__);
  497. goto err;
  498. }
  499. }
  500. if (common.apr_q6_cvs == NULL) {
  501. pr_debug("%s: Start to register CVS callback\n", __func__);
  502. common.apr_q6_cvs = apr_register("ADSP", "CVS",
  503. qdsp_cvs_callback,
  504. 0xFFFFFFFF, &common);
  505. if (common.apr_q6_cvs == NULL) {
  506. pr_err("%s: Unable to register CVS\n", __func__);
  507. goto err;
  508. }
  509. rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
  510. }
  511. if (common.apr_q6_cvp == NULL) {
  512. pr_debug("%s: Start to register CVP callback\n", __func__);
  513. common.apr_q6_cvp = apr_register("ADSP", "CVP",
  514. qdsp_cvp_callback,
  515. 0xFFFFFFFF, &common);
  516. if (common.apr_q6_cvp == NULL) {
  517. pr_err("%s: Unable to register CVP\n", __func__);
  518. goto err;
  519. }
  520. rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
  521. }
  522. mutex_unlock(&common.common_lock);
  523. return 0;
  524. err:
  525. if (common.apr_q6_cvs != NULL) {
  526. apr_deregister(common.apr_q6_cvs);
  527. common.apr_q6_cvs = NULL;
  528. rtac_set_voice_handle(RTAC_CVS, NULL);
  529. }
  530. if (common.apr_q6_mvm != NULL) {
  531. apr_deregister(common.apr_q6_mvm);
  532. common.apr_q6_mvm = NULL;
  533. }
  534. mutex_unlock(&common.common_lock);
  535. return -ENODEV;
  536. }
  537. static int voice_send_mvm_cvd_version_cmd(struct voice_data *v)
  538. {
  539. int ret;
  540. struct apr_hdr cvd_version_get_cmd;
  541. void *apr_mvm;
  542. if (v == NULL) {
  543. pr_err("%s: v is NULL\n", __func__);
  544. ret = -EINVAL;
  545. goto done;
  546. }
  547. apr_mvm = common.apr_q6_mvm;
  548. if (!apr_mvm) {
  549. pr_err("%s: apr_mvm is NULL.\n", __func__);
  550. ret = -EINVAL;
  551. goto done;
  552. }
  553. /* Send command to CVD to retrieve Version */
  554. cvd_version_get_cmd.hdr_field = APR_HDR_FIELD(
  555. APR_MSG_TYPE_SEQ_CMD,
  556. APR_HDR_LEN(APR_HDR_SIZE),
  557. APR_PKT_VER);
  558. cvd_version_get_cmd.pkt_size = APR_PKT_SIZE(
  559. APR_HDR_SIZE,
  560. sizeof(cvd_version_get_cmd) -
  561. APR_HDR_SIZE);
  562. cvd_version_get_cmd.src_port =
  563. voice_get_idx_for_session(v->session_id);
  564. cvd_version_get_cmd.dest_port = 0;
  565. cvd_version_get_cmd.token = 0;
  566. cvd_version_get_cmd.opcode = VSS_IVERSION_CMD_GET;
  567. pr_debug("%s: send CVD version get cmd, pkt size = %d\n",
  568. __func__, cvd_version_get_cmd.pkt_size);
  569. v->mvm_state = CMD_STATUS_FAIL;
  570. v->async_err = 0;
  571. ret = apr_send_pkt(apr_mvm,
  572. (uint32_t *) &cvd_version_get_cmd);
  573. if (ret < 0) {
  574. pr_err("%s: Error sending command\n", __func__);
  575. ret = -EINVAL;
  576. goto done;
  577. }
  578. ret = wait_event_timeout(v->mvm_wait,
  579. (v->mvm_state == CMD_STATUS_SUCCESS),
  580. msecs_to_jiffies(TIMEOUT_MS));
  581. if (!ret) {
  582. pr_err("%s: wait_event timeout, fall back to default\n",
  583. __func__);
  584. ret = -EINVAL;
  585. goto done;
  586. }
  587. if (v->async_err > 0) {
  588. pr_err("%s: DSP returned error[%s]\n",
  589. __func__, adsp_err_get_err_str(
  590. v->async_err));
  591. ret = adsp_err_get_lnx_err_code(
  592. v->async_err);
  593. goto done;
  594. }
  595. ret = 0;
  596. done:
  597. if (ret) {
  598. strlcpy(common.cvd_version, CVD_VERSION_0_0,
  599. sizeof(common.cvd_version));
  600. }
  601. pr_debug("%s: CVD Version retrieved=%s\n",
  602. __func__, common.cvd_version);
  603. return ret;
  604. }
  605. static int voice_send_dual_control_cmd(struct voice_data *v)
  606. {
  607. int ret = 0;
  608. struct mvm_modem_dual_control_session_cmd mvm_voice_ctl_cmd;
  609. void *apr_mvm;
  610. u16 mvm_handle;
  611. if (v == NULL) {
  612. pr_err("%s: v is NULL\n", __func__);
  613. return -EINVAL;
  614. }
  615. apr_mvm = common.apr_q6_mvm;
  616. if (!apr_mvm) {
  617. pr_err("%s: apr_mvm is NULL.\n", __func__);
  618. return -EINVAL;
  619. }
  620. pr_debug("%s: Send Dual Control command to MVM\n", __func__);
  621. if (!is_voip_session(v->session_id)) {
  622. mvm_handle = voice_get_mvm_handle(v);
  623. mvm_voice_ctl_cmd.hdr.hdr_field = APR_HDR_FIELD(
  624. APR_MSG_TYPE_SEQ_CMD,
  625. APR_HDR_LEN(APR_HDR_SIZE),
  626. APR_PKT_VER);
  627. mvm_voice_ctl_cmd.hdr.pkt_size = APR_PKT_SIZE(
  628. APR_HDR_SIZE,
  629. sizeof(mvm_voice_ctl_cmd) -
  630. APR_HDR_SIZE);
  631. pr_debug("%s: send mvm Voice Ctl pkt size = %d\n",
  632. __func__, mvm_voice_ctl_cmd.hdr.pkt_size);
  633. mvm_voice_ctl_cmd.hdr.src_port =
  634. voice_get_idx_for_session(v->session_id);
  635. mvm_voice_ctl_cmd.hdr.dest_port = mvm_handle;
  636. mvm_voice_ctl_cmd.hdr.token = 0;
  637. mvm_voice_ctl_cmd.hdr.opcode =
  638. VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL;
  639. mvm_voice_ctl_cmd.voice_ctl.enable_flag = true;
  640. v->mvm_state = CMD_STATUS_FAIL;
  641. v->async_err = 0;
  642. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_voice_ctl_cmd);
  643. if (ret < 0) {
  644. pr_err("%s: Error sending MVM Voice CTL CMD\n",
  645. __func__);
  646. ret = -EINVAL;
  647. goto fail;
  648. }
  649. ret = wait_event_timeout(v->mvm_wait,
  650. (v->mvm_state == CMD_STATUS_SUCCESS),
  651. msecs_to_jiffies(TIMEOUT_MS));
  652. if (!ret) {
  653. pr_err("%s: wait_event timeout\n", __func__);
  654. ret = -EINVAL;
  655. goto fail;
  656. }
  657. if (v->async_err > 0) {
  658. pr_err("%s: DSP returned error[%s]\n",
  659. __func__, adsp_err_get_err_str(
  660. v->async_err));
  661. ret = adsp_err_get_lnx_err_code(
  662. v->async_err);
  663. goto fail;
  664. }
  665. }
  666. ret = 0;
  667. fail:
  668. return ret;
  669. }
  670. static int voice_create_mvm_cvs_session(struct voice_data *v)
  671. {
  672. int ret = 0;
  673. struct mvm_create_ctl_session_cmd mvm_session_cmd;
  674. struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
  675. struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
  676. struct mvm_attach_stream_cmd attach_stream_cmd;
  677. void *apr_mvm, *apr_cvs, *apr_cvp;
  678. u16 mvm_handle, cvs_handle, cvp_handle;
  679. if (v == NULL) {
  680. pr_err("%s: v is NULL\n", __func__);
  681. return -EINVAL;
  682. }
  683. apr_mvm = common.apr_q6_mvm;
  684. apr_cvs = common.apr_q6_cvs;
  685. apr_cvp = common.apr_q6_cvp;
  686. if (!apr_mvm || !apr_cvs || !apr_cvp) {
  687. pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
  688. return -EINVAL;
  689. }
  690. mvm_handle = voice_get_mvm_handle(v);
  691. cvs_handle = voice_get_cvs_handle(v);
  692. cvp_handle = voice_get_cvp_handle(v);
  693. pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
  694. mvm_handle, cvs_handle);
  695. /* send cmd to create mvm session and wait for response */
  696. if (!mvm_handle) {
  697. memset(mvm_session_cmd.mvm_session.name, 0,
  698. sizeof(mvm_session_cmd.mvm_session.name));
  699. if (!is_voip_session(v->session_id)) {
  700. mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  701. APR_MSG_TYPE_SEQ_CMD,
  702. APR_HDR_LEN(APR_HDR_SIZE),
  703. APR_PKT_VER);
  704. mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
  705. APR_HDR_SIZE,
  706. sizeof(mvm_session_cmd) -
  707. APR_HDR_SIZE);
  708. pr_debug("%s: send mvm create session pkt size = %d\n",
  709. __func__, mvm_session_cmd.hdr.pkt_size);
  710. mvm_session_cmd.hdr.src_port =
  711. voice_get_idx_for_session(v->session_id);
  712. mvm_session_cmd.hdr.dest_port = 0;
  713. mvm_session_cmd.hdr.token = 0;
  714. mvm_session_cmd.hdr.opcode =
  715. VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  716. if (is_volte_session(v->session_id)) {
  717. strlcpy(mvm_session_cmd.mvm_session.name,
  718. "default volte voice",
  719. strlen("default volte voice")+1);
  720. } else if (is_voice2_session(v->session_id)) {
  721. strlcpy(mvm_session_cmd.mvm_session.name,
  722. VOICE2_SESSION_VSID_STR,
  723. strlen(VOICE2_SESSION_VSID_STR)+1);
  724. } else if (is_qchat_session(v->session_id)) {
  725. strlcpy(mvm_session_cmd.mvm_session.name,
  726. QCHAT_SESSION_VSID_STR,
  727. strlen(QCHAT_SESSION_VSID_STR)+1);
  728. } else if (is_vowlan_session(v->session_id)) {
  729. strlcpy(mvm_session_cmd.mvm_session.name,
  730. VOWLAN_SESSION_VSID_STR,
  731. strlen(VOWLAN_SESSION_VSID_STR)+1);
  732. } else if (is_voicemmode1(v->session_id)) {
  733. strlcpy(mvm_session_cmd.mvm_session.name,
  734. VOICEMMODE1_VSID_STR,
  735. strlen(VOICEMMODE1_VSID_STR) + 1);
  736. } else if (is_voicemmode2(v->session_id)) {
  737. strlcpy(mvm_session_cmd.mvm_session.name,
  738. VOICEMMODE2_VSID_STR,
  739. strlen(VOICEMMODE2_VSID_STR) + 1);
  740. } else {
  741. strlcpy(mvm_session_cmd.mvm_session.name,
  742. "default modem voice",
  743. strlen("default modem voice")+1);
  744. }
  745. v->mvm_state = CMD_STATUS_FAIL;
  746. v->async_err = 0;
  747. ret = apr_send_pkt(apr_mvm,
  748. (uint32_t *) &mvm_session_cmd);
  749. if (ret < 0) {
  750. pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
  751. __func__);
  752. goto fail;
  753. }
  754. ret = wait_event_timeout(v->mvm_wait,
  755. (v->mvm_state == CMD_STATUS_SUCCESS),
  756. msecs_to_jiffies(TIMEOUT_MS));
  757. if (!ret) {
  758. pr_err("%s: wait_event timeout\n", __func__);
  759. goto fail;
  760. }
  761. if (v->async_err > 0) {
  762. pr_err("%s: DSP returned error[%s]\n",
  763. __func__, adsp_err_get_err_str(
  764. v->async_err));
  765. ret = adsp_err_get_lnx_err_code(
  766. v->async_err);
  767. goto fail;
  768. }
  769. } else {
  770. pr_debug("%s: creating MVM full ctrl\n", __func__);
  771. mvm_session_cmd.hdr.hdr_field =
  772. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  773. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  774. mvm_session_cmd.hdr.pkt_size =
  775. APR_PKT_SIZE(APR_HDR_SIZE,
  776. sizeof(mvm_session_cmd) -
  777. APR_HDR_SIZE);
  778. mvm_session_cmd.hdr.src_port =
  779. voice_get_idx_for_session(v->session_id);
  780. mvm_session_cmd.hdr.dest_port = 0;
  781. mvm_session_cmd.hdr.token = 0;
  782. mvm_session_cmd.hdr.opcode =
  783. VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
  784. strlcpy(mvm_session_cmd.mvm_session.name,
  785. "default voip",
  786. strlen("default voip")+1);
  787. v->mvm_state = CMD_STATUS_FAIL;
  788. v->async_err = 0;
  789. ret = apr_send_pkt(apr_mvm,
  790. (uint32_t *) &mvm_session_cmd);
  791. if (ret < 0) {
  792. pr_err("Fail in sending MVM_CONTROL_SESSION\n");
  793. goto fail;
  794. }
  795. ret = wait_event_timeout(v->mvm_wait,
  796. (v->mvm_state == CMD_STATUS_SUCCESS),
  797. msecs_to_jiffies(TIMEOUT_MS));
  798. if (!ret) {
  799. pr_err("%s: wait_event timeout\n", __func__);
  800. goto fail;
  801. }
  802. if (v->async_err > 0) {
  803. pr_err("%s: DSP returned error[%s]\n",
  804. __func__, adsp_err_get_err_str(
  805. v->async_err));
  806. ret = adsp_err_get_lnx_err_code(
  807. v->async_err);
  808. goto fail;
  809. }
  810. }
  811. /* Get the created MVM handle. */
  812. mvm_handle = voice_get_mvm_handle(v);
  813. }
  814. /* send cmd to create cvs session */
  815. if (!cvs_handle) {
  816. memset(cvs_session_cmd.cvs_session.name, 0,
  817. sizeof(cvs_session_cmd.cvs_session.name));
  818. if (!is_voip_session(v->session_id)) {
  819. pr_debug("%s: creating CVS passive session\n",
  820. __func__);
  821. cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  822. APR_MSG_TYPE_SEQ_CMD,
  823. APR_HDR_LEN(APR_HDR_SIZE),
  824. APR_PKT_VER);
  825. cvs_session_cmd.hdr.pkt_size =
  826. APR_PKT_SIZE(APR_HDR_SIZE,
  827. sizeof(cvs_session_cmd) -
  828. APR_HDR_SIZE);
  829. cvs_session_cmd.hdr.src_port =
  830. voice_get_idx_for_session(v->session_id);
  831. cvs_session_cmd.hdr.dest_port = 0;
  832. cvs_session_cmd.hdr.token = 0;
  833. cvs_session_cmd.hdr.opcode =
  834. VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  835. if (is_volte_session(v->session_id)) {
  836. strlcpy(cvs_session_cmd.cvs_session.name,
  837. "default volte voice",
  838. strlen("default volte voice")+1);
  839. } else if (is_voice2_session(v->session_id)) {
  840. strlcpy(cvs_session_cmd.cvs_session.name,
  841. VOICE2_SESSION_VSID_STR,
  842. strlen(VOICE2_SESSION_VSID_STR)+1);
  843. } else if (is_qchat_session(v->session_id)) {
  844. strlcpy(cvs_session_cmd.cvs_session.name,
  845. QCHAT_SESSION_VSID_STR,
  846. strlen(QCHAT_SESSION_VSID_STR)+1);
  847. } else if (is_vowlan_session(v->session_id)) {
  848. strlcpy(cvs_session_cmd.cvs_session.name,
  849. VOWLAN_SESSION_VSID_STR,
  850. strlen(VOWLAN_SESSION_VSID_STR)+1);
  851. } else if (is_voicemmode1(v->session_id)) {
  852. strlcpy(cvs_session_cmd.cvs_session.name,
  853. VOICEMMODE1_VSID_STR,
  854. strlen(VOICEMMODE1_VSID_STR) + 1);
  855. } else if (is_voicemmode2(v->session_id)) {
  856. strlcpy(cvs_session_cmd.cvs_session.name,
  857. VOICEMMODE2_VSID_STR,
  858. strlen(VOICEMMODE2_VSID_STR) + 1);
  859. } else {
  860. strlcpy(cvs_session_cmd.cvs_session.name,
  861. "default modem voice",
  862. strlen("default modem voice")+1);
  863. }
  864. v->cvs_state = CMD_STATUS_FAIL;
  865. v->async_err = 0;
  866. ret = apr_send_pkt(apr_cvs,
  867. (uint32_t *) &cvs_session_cmd);
  868. if (ret < 0) {
  869. pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
  870. goto fail;
  871. }
  872. ret = wait_event_timeout(v->cvs_wait,
  873. (v->cvs_state == CMD_STATUS_SUCCESS),
  874. msecs_to_jiffies(TIMEOUT_MS));
  875. if (!ret) {
  876. pr_err("%s: wait_event timeout\n", __func__);
  877. goto fail;
  878. }
  879. if (v->async_err > 0) {
  880. pr_err("%s: DSP returned error[%s]\n",
  881. __func__, adsp_err_get_err_str(
  882. v->async_err));
  883. ret = adsp_err_get_lnx_err_code(
  884. v->async_err);
  885. goto fail;
  886. }
  887. /* Get the created CVS handle. */
  888. cvs_handle = voice_get_cvs_handle(v);
  889. } else {
  890. pr_debug("%s: creating CVS full session\n", __func__);
  891. cvs_full_ctl_cmd.hdr.hdr_field =
  892. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  893. APR_HDR_LEN(APR_HDR_SIZE),
  894. APR_PKT_VER);
  895. cvs_full_ctl_cmd.hdr.pkt_size =
  896. APR_PKT_SIZE(APR_HDR_SIZE,
  897. sizeof(cvs_full_ctl_cmd) -
  898. APR_HDR_SIZE);
  899. cvs_full_ctl_cmd.hdr.src_port =
  900. voice_get_idx_for_session(v->session_id);
  901. cvs_full_ctl_cmd.hdr.dest_port = 0;
  902. cvs_full_ctl_cmd.hdr.token = 0;
  903. cvs_full_ctl_cmd.hdr.opcode =
  904. VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
  905. cvs_full_ctl_cmd.cvs_session.direction = 2;
  906. cvs_full_ctl_cmd.cvs_session.enc_media_type =
  907. common.mvs_info.media_type;
  908. cvs_full_ctl_cmd.cvs_session.dec_media_type =
  909. common.mvs_info.media_type;
  910. cvs_full_ctl_cmd.cvs_session.network_id =
  911. common.mvs_info.network_type;
  912. strlcpy(cvs_full_ctl_cmd.cvs_session.name,
  913. "default q6 voice",
  914. strlen("default q6 voice")+1);
  915. v->cvs_state = CMD_STATUS_FAIL;
  916. v->async_err = 0;
  917. ret = apr_send_pkt(apr_cvs,
  918. (uint32_t *) &cvs_full_ctl_cmd);
  919. if (ret < 0) {
  920. pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
  921. __func__, ret);
  922. goto fail;
  923. }
  924. ret = wait_event_timeout(v->cvs_wait,
  925. (v->cvs_state == CMD_STATUS_SUCCESS),
  926. msecs_to_jiffies(TIMEOUT_MS));
  927. if (!ret) {
  928. pr_err("%s: wait_event timeout\n", __func__);
  929. goto fail;
  930. }
  931. if (v->async_err > 0) {
  932. pr_err("%s: DSP returned error[%s]\n",
  933. __func__, adsp_err_get_err_str(
  934. v->async_err));
  935. ret = adsp_err_get_lnx_err_code(
  936. v->async_err);
  937. goto fail;
  938. }
  939. /* Get the created CVS handle. */
  940. cvs_handle = voice_get_cvs_handle(v);
  941. /* Attach MVM to CVS. */
  942. pr_debug("%s: Attach MVM to stream\n", __func__);
  943. attach_stream_cmd.hdr.hdr_field =
  944. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  945. APR_HDR_LEN(APR_HDR_SIZE),
  946. APR_PKT_VER);
  947. attach_stream_cmd.hdr.pkt_size =
  948. APR_PKT_SIZE(APR_HDR_SIZE,
  949. sizeof(attach_stream_cmd) -
  950. APR_HDR_SIZE);
  951. attach_stream_cmd.hdr.src_port =
  952. voice_get_idx_for_session(v->session_id);
  953. attach_stream_cmd.hdr.dest_port = mvm_handle;
  954. attach_stream_cmd.hdr.token = 0;
  955. attach_stream_cmd.hdr.opcode =
  956. VSS_IMVM_CMD_ATTACH_STREAM;
  957. attach_stream_cmd.attach_stream.handle = cvs_handle;
  958. v->mvm_state = CMD_STATUS_FAIL;
  959. v->async_err = 0;
  960. ret = apr_send_pkt(apr_mvm,
  961. (uint32_t *) &attach_stream_cmd);
  962. if (ret < 0) {
  963. pr_err("%s: Error %d sending ATTACH_STREAM\n",
  964. __func__, ret);
  965. goto fail;
  966. }
  967. ret = wait_event_timeout(v->mvm_wait,
  968. (v->mvm_state == CMD_STATUS_SUCCESS),
  969. msecs_to_jiffies(TIMEOUT_MS));
  970. if (!ret) {
  971. pr_err("%s: wait_event timeout\n", __func__);
  972. goto fail;
  973. }
  974. if (v->async_err > 0) {
  975. pr_err("%s: DSP returned error[%s]\n",
  976. __func__, adsp_err_get_err_str(
  977. v->async_err));
  978. ret = adsp_err_get_lnx_err_code(
  979. v->async_err);
  980. goto fail;
  981. }
  982. }
  983. }
  984. return 0;
  985. fail:
  986. return ret;
  987. }
  988. static int voice_unmap_cal_block(struct voice_data *v, int cal_index)
  989. {
  990. int result = 0;
  991. struct cal_block_data *cal_block;
  992. if (common.cal_data[cal_index] == NULL) {
  993. pr_err("%s: Cal type is NULL, index %d!\n",
  994. __func__, cal_index);
  995. goto done;
  996. }
  997. mutex_lock(&common.cal_data[cal_index]->lock);
  998. cal_block = cal_utils_get_only_cal_block(
  999. common.cal_data[cal_index]);
  1000. if (cal_block == NULL) {
  1001. pr_err("%s: Cal block is NULL, index %d!\n",
  1002. __func__, cal_index);
  1003. result = -EINVAL;
  1004. goto unlock;
  1005. }
  1006. if (cal_block->map_data.q6map_handle == 0) {
  1007. pr_debug("%s: Q6 handle is not set!\n", __func__);
  1008. result = -EINVAL;
  1009. goto unlock;
  1010. }
  1011. mutex_lock(&common.common_lock);
  1012. result = voice_send_mvm_unmap_memory_physical_cmd(
  1013. v, cal_block->map_data.q6map_handle);
  1014. if (result)
  1015. pr_err("%s: Voice_send_mvm_unmap_memory_physical_cmd failed for session 0x%x, err %d!\n",
  1016. __func__, v->session_id, result);
  1017. cal_block->map_data.q6map_handle = 0;
  1018. mutex_unlock(&common.common_lock);
  1019. unlock:
  1020. mutex_unlock(&common.cal_data[cal_index]->lock);
  1021. done:
  1022. return result;
  1023. }
  1024. static int voice_destroy_mvm_cvs_session(struct voice_data *v)
  1025. {
  1026. int ret = 0;
  1027. struct mvm_detach_stream_cmd detach_stream;
  1028. struct apr_hdr mvm_destroy;
  1029. struct apr_hdr cvs_destroy;
  1030. void *apr_mvm, *apr_cvs;
  1031. u16 mvm_handle, cvs_handle;
  1032. if (v == NULL) {
  1033. pr_err("%s: v is NULL\n", __func__);
  1034. return -EINVAL;
  1035. }
  1036. apr_mvm = common.apr_q6_mvm;
  1037. apr_cvs = common.apr_q6_cvs;
  1038. if (!apr_mvm || !apr_cvs) {
  1039. pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
  1040. return -EINVAL;
  1041. }
  1042. mvm_handle = voice_get_mvm_handle(v);
  1043. cvs_handle = voice_get_cvs_handle(v);
  1044. /* MVM, CVS sessions are destroyed only for Full control sessions. */
  1045. if (is_voip_session(v->session_id)) {
  1046. pr_debug("%s: MVM detach stream, VOC_STATE: %d\n", __func__,
  1047. v->voc_state);
  1048. /* Detach voice stream. */
  1049. detach_stream.hdr.hdr_field =
  1050. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1051. APR_HDR_LEN(APR_HDR_SIZE),
  1052. APR_PKT_VER);
  1053. detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1054. sizeof(detach_stream) - APR_HDR_SIZE);
  1055. detach_stream.hdr.src_port =
  1056. voice_get_idx_for_session(v->session_id);
  1057. detach_stream.hdr.dest_port = mvm_handle;
  1058. detach_stream.hdr.token = 0;
  1059. detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
  1060. detach_stream.detach_stream.handle = cvs_handle;
  1061. v->mvm_state = CMD_STATUS_FAIL;
  1062. v->async_err = 0;
  1063. ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
  1064. if (ret < 0) {
  1065. pr_err("%s: Error %d sending DETACH_STREAM\n",
  1066. __func__, ret);
  1067. goto fail;
  1068. }
  1069. ret = wait_event_timeout(v->mvm_wait,
  1070. (v->mvm_state == CMD_STATUS_SUCCESS),
  1071. msecs_to_jiffies(TIMEOUT_MS));
  1072. if (!ret) {
  1073. pr_err("%s: wait event timeout\n", __func__);
  1074. goto fail;
  1075. }
  1076. if (v->async_err > 0) {
  1077. pr_err("%s: DSP returned error[%s]\n",
  1078. __func__, adsp_err_get_err_str(
  1079. v->async_err));
  1080. ret = adsp_err_get_lnx_err_code(
  1081. v->async_err);
  1082. goto fail;
  1083. }
  1084. /* Unmap memory */
  1085. if (v->shmem_info.mem_handle != 0) {
  1086. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  1087. v->shmem_info.mem_handle);
  1088. if (ret < 0) {
  1089. pr_err("%s Memory_unmap for voip failed %d\n",
  1090. __func__, ret);
  1091. goto fail;
  1092. }
  1093. v->shmem_info.mem_handle = 0;
  1094. }
  1095. }
  1096. /* Unmap Source Tracking shared memory if mapped earlier */
  1097. voice_unmap_and_free_source_tracking_shared_memory(v);
  1098. if (is_voip_session(v->session_id) ||
  1099. is_qchat_session(v->session_id) ||
  1100. is_volte_session(v->session_id) ||
  1101. is_vowlan_session(v->session_id) ||
  1102. v->voc_state == VOC_ERROR || common.is_destroy_cvd) {
  1103. /* Destroy CVS. */
  1104. pr_debug("%s: CVS destroy session\n", __func__);
  1105. cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1106. APR_HDR_LEN(APR_HDR_SIZE),
  1107. APR_PKT_VER);
  1108. cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1109. sizeof(cvs_destroy) - APR_HDR_SIZE);
  1110. cvs_destroy.src_port =
  1111. voice_get_idx_for_session(v->session_id);
  1112. cvs_destroy.dest_port = cvs_handle;
  1113. cvs_destroy.token = 0;
  1114. cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  1115. v->cvs_state = CMD_STATUS_FAIL;
  1116. v->async_err = 0;
  1117. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
  1118. if (ret < 0) {
  1119. pr_err("%s: Error %d sending CVS DESTROY\n",
  1120. __func__, ret);
  1121. goto fail;
  1122. }
  1123. ret = wait_event_timeout(v->cvs_wait,
  1124. (v->cvs_state == CMD_STATUS_SUCCESS),
  1125. msecs_to_jiffies(TIMEOUT_MS));
  1126. if (!ret) {
  1127. pr_err("%s: wait event timeout\n", __func__);
  1128. goto fail;
  1129. }
  1130. if (v->async_err > 0) {
  1131. pr_err("%s: DSP returned error[%s]\n",
  1132. __func__, adsp_err_get_err_str(
  1133. v->async_err));
  1134. ret = adsp_err_get_lnx_err_code(
  1135. v->async_err);
  1136. goto fail;
  1137. }
  1138. cvs_handle = 0;
  1139. voice_set_cvs_handle(v, cvs_handle);
  1140. /* Unmap physical memory for all calibration buffers */
  1141. if (!is_other_session_active(v->session_id)) {
  1142. if (voice_unmap_cal_block(v, CVP_VOCPROC_CAL))
  1143. pr_err("%s: Unmap VOCPROC cal failed\n",
  1144. __func__);
  1145. if (voice_unmap_cal_block(v, CVP_VOCVOL_CAL))
  1146. pr_err("%s: Unmap VOCVOL cal failed\n",
  1147. __func__);
  1148. if (voice_unmap_cal_block(v, CVP_VOCDEV_CFG_CAL))
  1149. pr_err("%s: Unmap VOCDEV_CFG cal failed\n",
  1150. __func__);
  1151. if (voice_unmap_cal_block(v, CVS_VOCSTRM_CAL))
  1152. pr_err("%s: Unmap VOCSTRM cal failed\n",
  1153. __func__);
  1154. }
  1155. /* Destroy MVM. */
  1156. pr_debug("%s: MVM destroy session\n", __func__);
  1157. mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1158. APR_HDR_LEN(APR_HDR_SIZE),
  1159. APR_PKT_VER);
  1160. mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1161. sizeof(mvm_destroy) - APR_HDR_SIZE);
  1162. mvm_destroy.src_port =
  1163. voice_get_idx_for_session(v->session_id);
  1164. mvm_destroy.dest_port = mvm_handle;
  1165. mvm_destroy.token = 0;
  1166. mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  1167. v->mvm_state = CMD_STATUS_FAIL;
  1168. v->async_err = 0;
  1169. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
  1170. if (ret < 0) {
  1171. pr_err("%s: Error %d sending MVM DESTROY\n",
  1172. __func__, ret);
  1173. goto fail;
  1174. }
  1175. ret = wait_event_timeout(v->mvm_wait,
  1176. (v->mvm_state == CMD_STATUS_SUCCESS),
  1177. msecs_to_jiffies(TIMEOUT_MS));
  1178. if (!ret) {
  1179. pr_err("%s: wait event timeout\n", __func__);
  1180. goto fail;
  1181. }
  1182. if (v->async_err > 0) {
  1183. pr_err("%s: DSP returned error[%s]\n",
  1184. __func__, adsp_err_get_err_str(
  1185. v->async_err));
  1186. ret = adsp_err_get_lnx_err_code(
  1187. v->async_err);
  1188. goto fail;
  1189. }
  1190. mvm_handle = 0;
  1191. voice_set_mvm_handle(v, mvm_handle);
  1192. }
  1193. return 0;
  1194. fail:
  1195. return ret;
  1196. }
  1197. static int voice_send_tty_mode_cmd(struct voice_data *v)
  1198. {
  1199. int ret = 0;
  1200. struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
  1201. void *apr_mvm;
  1202. u16 mvm_handle;
  1203. if (v == NULL) {
  1204. pr_err("%s: v is NULL\n", __func__);
  1205. return -EINVAL;
  1206. }
  1207. apr_mvm = common.apr_q6_mvm;
  1208. if (!apr_mvm) {
  1209. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1210. return -EINVAL;
  1211. }
  1212. mvm_handle = voice_get_mvm_handle(v);
  1213. /* send tty mode cmd to mvm */
  1214. mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
  1215. APR_MSG_TYPE_SEQ_CMD,
  1216. APR_HDR_LEN(APR_HDR_SIZE),
  1217. APR_PKT_VER);
  1218. mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1219. sizeof(mvm_tty_mode_cmd) -
  1220. APR_HDR_SIZE);
  1221. pr_debug("%s: pkt size = %d\n",
  1222. __func__, mvm_tty_mode_cmd.hdr.pkt_size);
  1223. mvm_tty_mode_cmd.hdr.src_port =
  1224. voice_get_idx_for_session(v->session_id);
  1225. mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
  1226. mvm_tty_mode_cmd.hdr.token = 0;
  1227. mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
  1228. mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
  1229. pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
  1230. v->mvm_state = CMD_STATUS_FAIL;
  1231. v->async_err = 0;
  1232. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
  1233. if (ret < 0) {
  1234. pr_err("%s: Error %d sending SET_TTY_MODE\n",
  1235. __func__, ret);
  1236. goto fail;
  1237. }
  1238. ret = wait_event_timeout(v->mvm_wait,
  1239. (v->mvm_state == CMD_STATUS_SUCCESS),
  1240. msecs_to_jiffies(TIMEOUT_MS));
  1241. if (!ret) {
  1242. pr_err("%s: wait_event timeout\n", __func__);
  1243. goto fail;
  1244. }
  1245. if (v->async_err > 0) {
  1246. pr_err("%s: DSP returned error[%s]\n",
  1247. __func__, adsp_err_get_err_str(
  1248. v->async_err));
  1249. ret = adsp_err_get_lnx_err_code(
  1250. v->async_err);
  1251. goto fail;
  1252. }
  1253. return 0;
  1254. fail:
  1255. return ret;
  1256. }
  1257. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  1258. uint32_t module_id, int enable)
  1259. {
  1260. struct cvs_set_pp_enable_cmd cvs_set_pp_cmd;
  1261. int ret = 0;
  1262. void *apr_cvs;
  1263. u16 cvs_handle;
  1264. if (v == NULL) {
  1265. pr_err("%s: v is NULL\n", __func__);
  1266. return -EINVAL;
  1267. }
  1268. apr_cvs = common.apr_q6_cvs;
  1269. if (!apr_cvs) {
  1270. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1271. return -EINVAL;
  1272. }
  1273. cvs_handle = voice_get_cvs_handle(v);
  1274. cvs_set_pp_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1275. APR_HDR_LEN(APR_HDR_SIZE),
  1276. APR_PKT_VER);
  1277. cvs_set_pp_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1278. sizeof(cvs_set_pp_cmd) -
  1279. APR_HDR_SIZE);
  1280. cvs_set_pp_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  1281. cvs_set_pp_cmd.hdr.dest_port = cvs_handle;
  1282. cvs_set_pp_cmd.hdr.token = 0;
  1283. cvs_set_pp_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  1284. cvs_set_pp_cmd.vss_set_pp.module_id = module_id;
  1285. cvs_set_pp_cmd.vss_set_pp.param_id = VOICE_PARAM_MOD_ENABLE;
  1286. cvs_set_pp_cmd.vss_set_pp.param_size = MOD_ENABLE_PARAM_LEN;
  1287. cvs_set_pp_cmd.vss_set_pp.reserved = 0;
  1288. cvs_set_pp_cmd.vss_set_pp.enable = enable;
  1289. cvs_set_pp_cmd.vss_set_pp.reserved_field = 0;
  1290. pr_debug("voice_send_set_pp_enable_cmd, module_id=%d, enable=%d\n",
  1291. module_id, enable);
  1292. v->cvs_state = CMD_STATUS_FAIL;
  1293. v->async_err = 0;
  1294. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_pp_cmd);
  1295. if (ret < 0) {
  1296. pr_err("Fail: sending cvs set pp enable,\n");
  1297. goto fail;
  1298. }
  1299. ret = wait_event_timeout(v->cvs_wait,
  1300. (v->cvs_state == CMD_STATUS_SUCCESS),
  1301. msecs_to_jiffies(TIMEOUT_MS));
  1302. if (!ret) {
  1303. pr_err("%s: wait_event timeout\n", __func__);
  1304. goto fail;
  1305. }
  1306. if (v->async_err > 0) {
  1307. pr_err("%s: DSP returned error[%s]\n",
  1308. __func__, adsp_err_get_err_str(
  1309. v->async_err));
  1310. ret = adsp_err_get_lnx_err_code(
  1311. v->async_err);
  1312. goto fail;
  1313. }
  1314. return 0;
  1315. fail:
  1316. return ret;
  1317. }
  1318. static int voice_send_hd_cmd(struct voice_data *v, int enable)
  1319. {
  1320. struct mvm_set_hd_enable_cmd mvm_set_hd_cmd;
  1321. int ret = 0;
  1322. void *apr_mvm;
  1323. u16 mvm_handle;
  1324. if (v == NULL) {
  1325. pr_err("%s: v is NULL\n", __func__);
  1326. ret = -EINVAL;
  1327. goto done;
  1328. }
  1329. apr_mvm = common.apr_q6_mvm;
  1330. if (!apr_mvm) {
  1331. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1332. ret = -EINVAL;
  1333. goto done;
  1334. }
  1335. mvm_handle = voice_get_mvm_handle(v);
  1336. if (!mvm_handle) {
  1337. pr_err("%s: mvm_handle is NULL\n", __func__);
  1338. ret = -EINVAL;
  1339. goto done;
  1340. }
  1341. mvm_set_hd_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1342. APR_HDR_LEN(APR_HDR_SIZE),
  1343. APR_PKT_VER);
  1344. mvm_set_hd_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1345. sizeof(mvm_set_hd_cmd) -
  1346. APR_HDR_SIZE);
  1347. mvm_set_hd_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  1348. mvm_set_hd_cmd.hdr.dest_port = mvm_handle;
  1349. mvm_set_hd_cmd.hdr.token = 0;
  1350. if (enable)
  1351. mvm_set_hd_cmd.hdr.opcode = VSS_IHDVOICE_CMD_ENABLE;
  1352. else
  1353. mvm_set_hd_cmd.hdr.opcode = VSS_IHDVOICE_CMD_DISABLE;
  1354. pr_debug("%s: enable=%d\n", __func__, enable);
  1355. v->mvm_state = CMD_STATUS_FAIL;
  1356. v->async_err = 0;
  1357. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_hd_cmd);
  1358. if (ret < 0) {
  1359. pr_err("%s: Failed to sending mvm set HD Voice enable %d\n",
  1360. __func__, ret);
  1361. ret = -EINVAL;
  1362. goto done;
  1363. }
  1364. ret = wait_event_timeout(v->mvm_wait,
  1365. (v->mvm_state == CMD_STATUS_SUCCESS),
  1366. msecs_to_jiffies(TIMEOUT_MS));
  1367. if (!ret) {
  1368. pr_err("%s: wait_event timeout\n", __func__);
  1369. ret = -EINVAL;
  1370. goto done;
  1371. }
  1372. if (v->async_err > 0) {
  1373. pr_err("%s: DSP returned error[%s]\n",
  1374. __func__, adsp_err_get_err_str(
  1375. v->async_err));
  1376. ret = adsp_err_get_lnx_err_code(
  1377. v->async_err);
  1378. goto done;
  1379. }
  1380. done:
  1381. return ret;
  1382. }
  1383. static int voice_set_dtx(struct voice_data *v)
  1384. {
  1385. int ret = 0;
  1386. void *apr_cvs;
  1387. u16 cvs_handle;
  1388. struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
  1389. if (v == NULL) {
  1390. pr_err("%s: v is NULL\n", __func__);
  1391. return -EINVAL;
  1392. }
  1393. apr_cvs = common.apr_q6_cvs;
  1394. if (!apr_cvs) {
  1395. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1396. return -EINVAL;
  1397. }
  1398. cvs_handle = voice_get_cvs_handle(v);
  1399. /* Set DTX */
  1400. cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1401. APR_HDR_LEN(APR_HDR_SIZE),
  1402. APR_PKT_VER);
  1403. cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1404. sizeof(cvs_set_dtx) - APR_HDR_SIZE);
  1405. cvs_set_dtx.hdr.src_port =
  1406. voice_get_idx_for_session(v->session_id);
  1407. cvs_set_dtx.hdr.dest_port = cvs_handle;
  1408. cvs_set_dtx.hdr.token = 0;
  1409. cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
  1410. cvs_set_dtx.dtx_mode.enable = common.mvs_info.dtx_mode;
  1411. pr_debug("%s: Setting DTX %d\n", __func__, common.mvs_info.dtx_mode);
  1412. v->cvs_state = CMD_STATUS_FAIL;
  1413. v->async_err = 0;
  1414. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
  1415. if (ret < 0) {
  1416. pr_err("%s: Error %d sending SET_DTX\n", __func__, ret);
  1417. return -EINVAL;
  1418. }
  1419. ret = wait_event_timeout(v->cvs_wait,
  1420. (v->cvs_state == CMD_STATUS_SUCCESS),
  1421. msecs_to_jiffies(TIMEOUT_MS));
  1422. if (!ret) {
  1423. pr_err("%s: wait_event timeout\n", __func__);
  1424. return -EINVAL;
  1425. }
  1426. if (v->async_err > 0) {
  1427. pr_err("%s: DSP returned error[%s]\n",
  1428. __func__, adsp_err_get_err_str(
  1429. v->async_err));
  1430. ret = adsp_err_get_lnx_err_code(
  1431. v->async_err);
  1432. return ret;
  1433. }
  1434. return 0;
  1435. }
  1436. static int voice_send_mvm_media_type_cmd(struct voice_data *v)
  1437. {
  1438. struct vss_imvm_cmd_set_cal_media_type_t mvm_set_cal_media_type;
  1439. int ret = 0;
  1440. void *apr_mvm;
  1441. u16 mvm_handle;
  1442. if (v == NULL) {
  1443. pr_err("%s: v is NULL\n", __func__);
  1444. return -EINVAL;
  1445. }
  1446. apr_mvm = common.apr_q6_mvm;
  1447. if (!apr_mvm) {
  1448. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1449. return -EINVAL;
  1450. }
  1451. mvm_handle = voice_get_mvm_handle(v);
  1452. mvm_set_cal_media_type.hdr.hdr_field =
  1453. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1454. APR_HDR_LEN(APR_HDR_SIZE),
  1455. APR_PKT_VER);
  1456. mvm_set_cal_media_type.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1457. sizeof(mvm_set_cal_media_type) -
  1458. APR_HDR_SIZE);
  1459. mvm_set_cal_media_type.hdr.src_port =
  1460. voice_get_idx_for_session(v->session_id);
  1461. mvm_set_cal_media_type.hdr.dest_port = mvm_handle;
  1462. mvm_set_cal_media_type.hdr.token = 0;
  1463. mvm_set_cal_media_type.hdr.opcode = VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE;
  1464. mvm_set_cal_media_type.media_id = common.mvs_info.media_type;
  1465. pr_debug("%s: setting media_id as %x\n",
  1466. __func__, mvm_set_cal_media_type.media_id);
  1467. v->mvm_state = CMD_STATUS_FAIL;
  1468. v->async_err = 0;
  1469. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_media_type);
  1470. if (ret < 0) {
  1471. pr_err("%s: Error %d sending media type\n", __func__, ret);
  1472. goto fail;
  1473. }
  1474. ret = wait_event_timeout(v->mvm_wait,
  1475. (v->mvm_state == CMD_STATUS_SUCCESS),
  1476. msecs_to_jiffies(TIMEOUT_MS));
  1477. if (!ret) {
  1478. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  1479. goto fail;
  1480. }
  1481. if (v->async_err > 0) {
  1482. pr_err("%s: DSP returned error[%s]\n",
  1483. __func__, adsp_err_get_err_str(
  1484. v->async_err));
  1485. ret = adsp_err_get_lnx_err_code(
  1486. v->async_err);
  1487. goto fail;
  1488. }
  1489. return 0;
  1490. fail:
  1491. return ret;
  1492. }
  1493. static int voice_send_dtmf_rx_detection_cmd(struct voice_data *v,
  1494. uint32_t enable)
  1495. {
  1496. int ret = 0;
  1497. void *apr_cvs;
  1498. u16 cvs_handle;
  1499. struct cvs_set_rx_dtmf_detection_cmd cvs_dtmf_rx_detection;
  1500. if (v == NULL) {
  1501. pr_err("%s: v is NULL\n", __func__);
  1502. return -EINVAL;
  1503. }
  1504. apr_cvs = common.apr_q6_cvs;
  1505. if (!apr_cvs) {
  1506. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1507. return -EINVAL;
  1508. }
  1509. cvs_handle = voice_get_cvs_handle(v);
  1510. /* Set SET_DTMF_RX_DETECTION */
  1511. cvs_dtmf_rx_detection.hdr.hdr_field =
  1512. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1513. APR_HDR_LEN(APR_HDR_SIZE),
  1514. APR_PKT_VER);
  1515. cvs_dtmf_rx_detection.hdr.pkt_size =
  1516. APR_PKT_SIZE(APR_HDR_SIZE,
  1517. sizeof(cvs_dtmf_rx_detection) - APR_HDR_SIZE);
  1518. cvs_dtmf_rx_detection.hdr.src_port =
  1519. voice_get_idx_for_session(v->session_id);
  1520. cvs_dtmf_rx_detection.hdr.dest_port = cvs_handle;
  1521. cvs_dtmf_rx_detection.hdr.token = 0;
  1522. cvs_dtmf_rx_detection.hdr.opcode =
  1523. VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION;
  1524. cvs_dtmf_rx_detection.cvs_dtmf_det.enable = enable;
  1525. v->cvs_state = CMD_STATUS_FAIL;
  1526. v->async_err = 0;
  1527. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dtmf_rx_detection);
  1528. if (ret < 0) {
  1529. pr_err("%s: Error %d sending SET_DTMF_RX_DETECTION\n",
  1530. __func__,
  1531. ret);
  1532. return -EINVAL;
  1533. }
  1534. ret = wait_event_timeout(v->cvs_wait,
  1535. (v->cvs_state == CMD_STATUS_SUCCESS),
  1536. msecs_to_jiffies(TIMEOUT_MS));
  1537. if (!ret) {
  1538. pr_err("%s: wait_event timeout\n", __func__);
  1539. return -EINVAL;
  1540. }
  1541. if (v->async_err > 0) {
  1542. pr_err("%s: DSP returned error[%s]\n",
  1543. __func__, adsp_err_get_err_str(
  1544. v->async_err));
  1545. ret = adsp_err_get_lnx_err_code(
  1546. v->async_err);
  1547. return ret;
  1548. }
  1549. return ret;
  1550. }
  1551. void voc_disable_dtmf_det_on_active_sessions(void)
  1552. {
  1553. struct voice_data *v = NULL;
  1554. int i;
  1555. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  1556. v = &common.voice[i];
  1557. if ((v->dtmf_rx_detect_en) &&
  1558. is_voc_state_active(v->voc_state)) {
  1559. pr_debug("disable dtmf det on ses_id=%d\n",
  1560. v->session_id);
  1561. voice_send_dtmf_rx_detection_cmd(v, 0);
  1562. }
  1563. }
  1564. }
  1565. int voc_enable_dtmf_rx_detection(uint32_t session_id, uint32_t enable)
  1566. {
  1567. struct voice_data *v = voice_get_session(session_id);
  1568. int ret = 0;
  1569. if (v == NULL) {
  1570. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  1571. return -EINVAL;
  1572. }
  1573. mutex_lock(&v->lock);
  1574. v->dtmf_rx_detect_en = enable;
  1575. if (is_voc_state_active(v->voc_state))
  1576. ret = voice_send_dtmf_rx_detection_cmd(v,
  1577. v->dtmf_rx_detect_en);
  1578. mutex_unlock(&v->lock);
  1579. return ret;
  1580. }
  1581. void voc_set_destroy_cvd_flag(bool is_destroy_cvd)
  1582. {
  1583. pr_debug("%s: %d\n", __func__, is_destroy_cvd);
  1584. common.is_destroy_cvd = is_destroy_cvd;
  1585. }
  1586. int voc_alloc_cal_shared_memory(void)
  1587. {
  1588. int rc = 0;
  1589. mutex_lock(&common.common_lock);
  1590. if (is_cal_memory_allocated()) {
  1591. pr_debug("%s: Calibration shared buffer already allocated",
  1592. __func__);
  1593. } else {
  1594. /* Allocate memory for calibration memory map table. */
  1595. rc = voice_alloc_cal_mem_map_table();
  1596. if ((rc < 0) && (rc != -EPROBE_DEFER)) {
  1597. pr_err("%s: Failed to allocate cal memory, err=%d",
  1598. __func__, rc);
  1599. }
  1600. }
  1601. mutex_unlock(&common.common_lock);
  1602. return rc;
  1603. }
  1604. int voc_alloc_voip_shared_memory(void)
  1605. {
  1606. int rc = 0;
  1607. /* Allocate shared memory for OOB Voip */
  1608. rc = voice_alloc_oob_shared_mem();
  1609. if (rc < 0) {
  1610. pr_err("%s: Failed to alloc shared memory for OOB rc:%d\n",
  1611. __func__, rc);
  1612. } else {
  1613. /* Allocate mem map table for OOB */
  1614. rc = voice_alloc_oob_mem_table();
  1615. if (rc < 0) {
  1616. pr_err("%s: Failed to alloc mem map talbe rc:%d\n",
  1617. __func__, rc);
  1618. voice_free_oob_shared_mem();
  1619. }
  1620. }
  1621. return rc;
  1622. }
  1623. static int is_cal_memory_allocated(void)
  1624. {
  1625. bool ret;
  1626. if (common.cal_mem_map_table.client != NULL &&
  1627. common.cal_mem_map_table.handle != NULL)
  1628. ret = true;
  1629. else
  1630. ret = false;
  1631. return ret;
  1632. }
  1633. static int free_cal_map_table(void)
  1634. {
  1635. int ret = 0;
  1636. if ((common.cal_mem_map_table.client == NULL) ||
  1637. (common.cal_mem_map_table.handle == NULL))
  1638. goto done;
  1639. ret = msm_audio_ion_free(common.cal_mem_map_table.client,
  1640. common.cal_mem_map_table.handle);
  1641. if (ret < 0)
  1642. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1643. done:
  1644. common.cal_mem_map_table.client = NULL;
  1645. common.cal_mem_map_table.handle = NULL;
  1646. return ret;
  1647. }
  1648. static int is_rtac_memory_allocated(void)
  1649. {
  1650. bool ret;
  1651. if (common.rtac_mem_map_table.client != NULL &&
  1652. common.rtac_mem_map_table.handle != NULL)
  1653. ret = true;
  1654. else
  1655. ret = false;
  1656. return ret;
  1657. }
  1658. static int free_rtac_map_table(void)
  1659. {
  1660. int ret = 0;
  1661. if ((common.rtac_mem_map_table.client == NULL) ||
  1662. (common.rtac_mem_map_table.handle == NULL))
  1663. goto done;
  1664. ret = msm_audio_ion_free(common.rtac_mem_map_table.client,
  1665. common.rtac_mem_map_table.handle);
  1666. if (ret < 0)
  1667. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1668. done:
  1669. common.rtac_mem_map_table.client = NULL;
  1670. common.rtac_mem_map_table.handle = NULL;
  1671. return ret;
  1672. }
  1673. static int is_voip_memory_allocated(void)
  1674. {
  1675. bool ret;
  1676. struct voice_data *v = voice_get_session(
  1677. common.voice[VOC_PATH_FULL].session_id);
  1678. if (v == NULL) {
  1679. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1680. common.voice[VOC_PATH_FULL].session_id);
  1681. ret = false;
  1682. goto done;
  1683. }
  1684. mutex_lock(&common.common_lock);
  1685. if (v->shmem_info.sh_buf.client != NULL &&
  1686. v->shmem_info.sh_buf.handle != NULL)
  1687. ret = true;
  1688. else
  1689. ret = false;
  1690. mutex_unlock(&common.common_lock);
  1691. done:
  1692. return ret;
  1693. }
  1694. static int voice_config_cvs_vocoder_amr_rate(struct voice_data *v)
  1695. {
  1696. int ret = 0;
  1697. void *apr_cvs;
  1698. u16 cvs_handle;
  1699. struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
  1700. if (v == NULL) {
  1701. pr_err("%s: v is NULL\n", __func__);
  1702. ret = -EINVAL;
  1703. goto done;
  1704. }
  1705. apr_cvs = common.apr_q6_cvs;
  1706. if (!apr_cvs) {
  1707. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1708. ret = -EINVAL;
  1709. goto done;
  1710. }
  1711. cvs_handle = voice_get_cvs_handle(v);
  1712. pr_debug("%s: Setting AMR rate. Media Type: %d\n", __func__,
  1713. common.mvs_info.media_type);
  1714. cvs_set_amr_rate.hdr.hdr_field =
  1715. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1716. APR_HDR_LEN(APR_HDR_SIZE),
  1717. APR_PKT_VER);
  1718. cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1719. sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
  1720. cvs_set_amr_rate.hdr.src_port =
  1721. voice_get_idx_for_session(v->session_id);
  1722. cvs_set_amr_rate.hdr.dest_port = cvs_handle;
  1723. cvs_set_amr_rate.hdr.token = 0;
  1724. if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_NB_MODEM)
  1725. cvs_set_amr_rate.hdr.opcode =
  1726. VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
  1727. else if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_WB_MODEM)
  1728. cvs_set_amr_rate.hdr.opcode =
  1729. VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
  1730. cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
  1731. v->cvs_state = CMD_STATUS_FAIL;
  1732. v->async_err = 0;
  1733. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
  1734. if (ret < 0) {
  1735. pr_err("%s: Error %d sending SET_AMR_RATE\n",
  1736. __func__, ret);
  1737. goto done;
  1738. }
  1739. ret = wait_event_timeout(v->cvs_wait,
  1740. (v->cvs_state == CMD_STATUS_SUCCESS),
  1741. msecs_to_jiffies(TIMEOUT_MS));
  1742. if (!ret) {
  1743. pr_err("%s: wait_event timeout\n", __func__);
  1744. ret = -EINVAL;
  1745. goto done;
  1746. }
  1747. if (v->async_err > 0) {
  1748. pr_err("%s: DSP returned error[%s]\n",
  1749. __func__, adsp_err_get_err_str(
  1750. v->async_err));
  1751. ret = adsp_err_get_lnx_err_code(
  1752. v->async_err);
  1753. goto done;
  1754. }
  1755. return 0;
  1756. done:
  1757. return ret;
  1758. }
  1759. static int voice_config_cvs_vocoder(struct voice_data *v)
  1760. {
  1761. int ret = 0;
  1762. void *apr_cvs;
  1763. u16 cvs_handle;
  1764. /* Set media type. */
  1765. struct cvs_set_media_type_cmd cvs_set_media_cmd;
  1766. if (v == NULL) {
  1767. pr_err("%s: v is NULL\n", __func__);
  1768. return -EINVAL;
  1769. }
  1770. apr_cvs = common.apr_q6_cvs;
  1771. if (!apr_cvs) {
  1772. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1773. return -EINVAL;
  1774. }
  1775. cvs_handle = voice_get_cvs_handle(v);
  1776. cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1777. APR_HDR_LEN(APR_HDR_SIZE),
  1778. APR_PKT_VER);
  1779. cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1780. sizeof(cvs_set_media_cmd) -
  1781. APR_HDR_SIZE);
  1782. cvs_set_media_cmd.hdr.src_port =
  1783. voice_get_idx_for_session(v->session_id);
  1784. cvs_set_media_cmd.hdr.dest_port = cvs_handle;
  1785. cvs_set_media_cmd.hdr.token = 0;
  1786. cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
  1787. cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
  1788. cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
  1789. v->cvs_state = CMD_STATUS_FAIL;
  1790. v->async_err = 0;
  1791. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
  1792. if (ret < 0) {
  1793. pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
  1794. __func__, ret);
  1795. goto fail;
  1796. }
  1797. ret = wait_event_timeout(v->cvs_wait,
  1798. (v->cvs_state == CMD_STATUS_SUCCESS),
  1799. msecs_to_jiffies(TIMEOUT_MS));
  1800. if (!ret) {
  1801. pr_err("%s: wait_event timeout\n", __func__);
  1802. goto fail;
  1803. }
  1804. if (v->async_err > 0) {
  1805. pr_err("%s: DSP returned error[%s]\n",
  1806. __func__, adsp_err_get_err_str(
  1807. v->async_err));
  1808. ret = adsp_err_get_lnx_err_code(
  1809. v->async_err);
  1810. goto fail;
  1811. }
  1812. /* Set encoder properties. */
  1813. switch (common.mvs_info.media_type) {
  1814. case VSS_MEDIA_ID_EVRC_MODEM:
  1815. case VSS_MEDIA_ID_4GV_NB_MODEM:
  1816. case VSS_MEDIA_ID_4GV_WB_MODEM:
  1817. case VSS_MEDIA_ID_4GV_NW_MODEM: {
  1818. struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
  1819. pr_debug("Setting EVRC min-max rate\n");
  1820. cvs_set_cdma_rate.hdr.hdr_field =
  1821. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1822. APR_HDR_LEN(APR_HDR_SIZE),
  1823. APR_PKT_VER);
  1824. cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1825. sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
  1826. cvs_set_cdma_rate.hdr.src_port =
  1827. voice_get_idx_for_session(v->session_id);
  1828. cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
  1829. cvs_set_cdma_rate.hdr.token = 0;
  1830. cvs_set_cdma_rate.hdr.opcode =
  1831. VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
  1832. cvs_set_cdma_rate.cdma_rate.min_rate =
  1833. common.mvs_info.evrc_min_rate;
  1834. cvs_set_cdma_rate.cdma_rate.max_rate =
  1835. common.mvs_info.evrc_max_rate;
  1836. v->cvs_state = CMD_STATUS_FAIL;
  1837. v->async_err = 0;
  1838. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
  1839. if (ret < 0) {
  1840. pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
  1841. __func__, ret);
  1842. goto fail;
  1843. }
  1844. ret = wait_event_timeout(v->cvs_wait,
  1845. (v->cvs_state == CMD_STATUS_SUCCESS),
  1846. msecs_to_jiffies(TIMEOUT_MS));
  1847. if (!ret) {
  1848. pr_err("%s: wait_event timeout\n", __func__);
  1849. goto fail;
  1850. }
  1851. if (v->async_err > 0) {
  1852. pr_err("%s: DSP returned error[%s]\n",
  1853. __func__, adsp_err_get_err_str(
  1854. v->async_err));
  1855. ret = adsp_err_get_lnx_err_code(
  1856. v->async_err);
  1857. goto fail;
  1858. }
  1859. if (common.mvs_info.media_type != VSS_MEDIA_ID_EVRC_MODEM) {
  1860. ret = voice_set_dtx(v);
  1861. if (ret < 0)
  1862. goto fail;
  1863. }
  1864. break;
  1865. }
  1866. case VSS_MEDIA_ID_AMR_NB_MODEM:
  1867. case VSS_MEDIA_ID_AMR_WB_MODEM: {
  1868. ret = voice_config_cvs_vocoder_amr_rate(v);
  1869. if (ret) {
  1870. pr_err("%s: Failed to update vocoder rate. %d\n",
  1871. __func__, ret);
  1872. goto fail;
  1873. }
  1874. ret = voice_set_dtx(v);
  1875. if (ret < 0)
  1876. goto fail;
  1877. break;
  1878. }
  1879. case VSS_MEDIA_ID_G729:
  1880. case VSS_MEDIA_ID_G711_ALAW:
  1881. case VSS_MEDIA_ID_G711_MULAW: {
  1882. ret = voice_set_dtx(v);
  1883. break;
  1884. }
  1885. default:
  1886. /* Do nothing. */
  1887. break;
  1888. }
  1889. return 0;
  1890. fail:
  1891. return ret;
  1892. }
  1893. int voc_update_amr_vocoder_rate(uint32_t session_id)
  1894. {
  1895. int ret = 0;
  1896. struct voice_data *v;
  1897. pr_debug("%s: session_id:%d", __func__, session_id);
  1898. v = voice_get_session(session_id);
  1899. if (v == NULL) {
  1900. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1901. session_id);
  1902. ret = -EINVAL;
  1903. goto done;
  1904. }
  1905. mutex_lock(&v->lock);
  1906. ret = voice_config_cvs_vocoder_amr_rate(v);
  1907. mutex_unlock(&v->lock);
  1908. done:
  1909. return ret;
  1910. }
  1911. static int voice_send_start_voice_cmd(struct voice_data *v)
  1912. {
  1913. struct apr_hdr mvm_start_voice_cmd;
  1914. int ret = 0;
  1915. void *apr_mvm;
  1916. u16 mvm_handle;
  1917. if (v == NULL) {
  1918. pr_err("%s: v is NULL\n", __func__);
  1919. return -EINVAL;
  1920. }
  1921. apr_mvm = common.apr_q6_mvm;
  1922. if (!apr_mvm) {
  1923. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1924. return -EINVAL;
  1925. }
  1926. mvm_handle = voice_get_mvm_handle(v);
  1927. mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1928. APR_HDR_LEN(APR_HDR_SIZE),
  1929. APR_PKT_VER);
  1930. mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1931. sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
  1932. pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
  1933. mvm_start_voice_cmd.pkt_size);
  1934. mvm_start_voice_cmd.src_port =
  1935. voice_get_idx_for_session(v->session_id);
  1936. mvm_start_voice_cmd.dest_port = mvm_handle;
  1937. mvm_start_voice_cmd.token = 0;
  1938. mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
  1939. v->mvm_state = CMD_STATUS_FAIL;
  1940. v->async_err = 0;
  1941. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
  1942. if (ret < 0) {
  1943. pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
  1944. goto fail;
  1945. }
  1946. ret = wait_event_timeout(v->mvm_wait,
  1947. (v->mvm_state == CMD_STATUS_SUCCESS),
  1948. msecs_to_jiffies(TIMEOUT_MS));
  1949. if (!ret) {
  1950. pr_err("%s: wait_event timeout\n", __func__);
  1951. goto fail;
  1952. }
  1953. if (v->async_err > 0) {
  1954. pr_err("%s: DSP returned error[%s]\n",
  1955. __func__, adsp_err_get_err_str(
  1956. v->async_err));
  1957. ret = adsp_err_get_lnx_err_code(
  1958. v->async_err);
  1959. goto fail;
  1960. }
  1961. return 0;
  1962. fail:
  1963. return ret;
  1964. }
  1965. static void voc_get_tx_rx_topology(struct voice_data *v,
  1966. uint32_t *tx_topology_id,
  1967. uint32_t *rx_topology_id)
  1968. {
  1969. uint32_t tx_id = 0;
  1970. uint32_t rx_id = 0;
  1971. if (v->lch_mode == VOICE_LCH_START || v->disable_topology) {
  1972. pr_debug("%s: Setting TX and RX topology to NONE for LCH\n",
  1973. __func__);
  1974. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1975. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1976. } else {
  1977. tx_id = voice_get_topology(CVP_VOC_TX_TOPOLOGY_CAL);
  1978. rx_id = voice_get_topology(CVP_VOC_RX_TOPOLOGY_CAL);
  1979. }
  1980. *tx_topology_id = tx_id;
  1981. *rx_topology_id = rx_id;
  1982. }
  1983. static int voice_send_set_device_cmd(struct voice_data *v)
  1984. {
  1985. struct cvp_set_device_cmd cvp_setdev_cmd;
  1986. int ret = 0;
  1987. void *apr_cvp;
  1988. u16 cvp_handle;
  1989. if (v == NULL) {
  1990. pr_err("%s: v is NULL\n", __func__);
  1991. return -EINVAL;
  1992. }
  1993. apr_cvp = common.apr_q6_cvp;
  1994. if (!apr_cvp) {
  1995. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1996. return -EINVAL;
  1997. }
  1998. cvp_handle = voice_get_cvp_handle(v);
  1999. /* set device and wait for response */
  2000. cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2001. APR_HDR_LEN(APR_HDR_SIZE),
  2002. APR_PKT_VER);
  2003. cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2004. sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
  2005. pr_debug(" send create cvp setdev, pkt size = %d\n",
  2006. cvp_setdev_cmd.hdr.pkt_size);
  2007. cvp_setdev_cmd.hdr.src_port =
  2008. voice_get_idx_for_session(v->session_id);
  2009. cvp_setdev_cmd.hdr.dest_port = cvp_handle;
  2010. cvp_setdev_cmd.hdr.token = 0;
  2011. if (voice_get_cvd_int_version(common.cvd_version) >=
  2012. CVD_INT_VERSION_2_2)
  2013. cvp_setdev_cmd.hdr.opcode =
  2014. VSS_IVOCPROC_CMD_SET_DEVICE_V3;
  2015. else
  2016. cvp_setdev_cmd.hdr.opcode =
  2017. VSS_IVOCPROC_CMD_SET_DEVICE_V2;
  2018. voc_get_tx_rx_topology(v,
  2019. &cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  2020. &cvp_setdev_cmd.cvp_set_device_v2.rx_topology_id);
  2021. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id = v->dev_tx.port_id;
  2022. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id = v->dev_rx.port_id;
  2023. if (common.ec_ref_ext) {
  2024. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  2025. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2026. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  2027. common.ec_media_fmt_info.port_id;
  2028. } else {
  2029. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  2030. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2031. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  2032. VSS_IVOCPROC_PORT_ID_NONE;
  2033. }
  2034. pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
  2035. cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  2036. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id,
  2037. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id);
  2038. v->cvp_state = CMD_STATUS_FAIL;
  2039. v->async_err = 0;
  2040. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
  2041. if (ret < 0) {
  2042. pr_err("Fail in sending VSS_IVOCPROC_CMD_SET_DEVICE\n");
  2043. goto fail;
  2044. }
  2045. ret = wait_event_timeout(v->cvp_wait,
  2046. (v->cvp_state == CMD_STATUS_SUCCESS),
  2047. msecs_to_jiffies(TIMEOUT_MS));
  2048. if (!ret) {
  2049. pr_err("%s: wait_event timeout\n", __func__);
  2050. goto fail;
  2051. }
  2052. if (v->async_err > 0) {
  2053. pr_err("%s: DSP returned error[%s]\n",
  2054. __func__, adsp_err_get_err_str(
  2055. v->async_err));
  2056. ret = adsp_err_get_lnx_err_code(
  2057. v->async_err);
  2058. goto fail;
  2059. }
  2060. return 0;
  2061. fail:
  2062. return ret;
  2063. }
  2064. static int voice_send_stop_voice_cmd(struct voice_data *v)
  2065. {
  2066. struct apr_hdr mvm_stop_voice_cmd;
  2067. int ret = 0;
  2068. void *apr_mvm;
  2069. u16 mvm_handle;
  2070. if (v == NULL) {
  2071. pr_err("%s: v is NULL\n", __func__);
  2072. return -EINVAL;
  2073. }
  2074. apr_mvm = common.apr_q6_mvm;
  2075. if (!apr_mvm) {
  2076. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2077. return -EINVAL;
  2078. }
  2079. mvm_handle = voice_get_mvm_handle(v);
  2080. mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2081. APR_HDR_LEN(APR_HDR_SIZE),
  2082. APR_PKT_VER);
  2083. mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2084. sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
  2085. pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
  2086. mvm_stop_voice_cmd.pkt_size);
  2087. mvm_stop_voice_cmd.src_port =
  2088. voice_get_idx_for_session(v->session_id);
  2089. mvm_stop_voice_cmd.dest_port = mvm_handle;
  2090. mvm_stop_voice_cmd.token = 0;
  2091. mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
  2092. v->mvm_state = CMD_STATUS_FAIL;
  2093. v->async_err = 0;
  2094. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
  2095. if (ret < 0) {
  2096. pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
  2097. goto fail;
  2098. }
  2099. ret = wait_event_timeout(v->mvm_wait,
  2100. (v->mvm_state == CMD_STATUS_SUCCESS),
  2101. msecs_to_jiffies(TIMEOUT_MS));
  2102. if (!ret) {
  2103. pr_err("%s: wait_event timeout\n", __func__);
  2104. goto fail;
  2105. }
  2106. if (v->async_err > 0) {
  2107. pr_err("%s: DSP returned error[%s]\n",
  2108. __func__, adsp_err_get_err_str(
  2109. v->async_err));
  2110. ret = adsp_err_get_lnx_err_code(
  2111. v->async_err);
  2112. goto fail;
  2113. }
  2114. return 0;
  2115. fail:
  2116. return ret;
  2117. }
  2118. static int voice_get_cal(struct cal_block_data **cal_block,
  2119. int cal_block_idx,
  2120. struct cal_block_data **col_data,
  2121. int col_data_idx, int session_id)
  2122. {
  2123. int ret = 0;
  2124. *cal_block = cal_utils_get_only_cal_block(
  2125. common.cal_data[cal_block_idx]);
  2126. if (*cal_block == NULL) {
  2127. pr_err("%s: No cal data for cal %d!\n",
  2128. __func__, cal_block_idx);
  2129. ret = -ENODEV;
  2130. goto done;
  2131. }
  2132. ret = remap_cal_data(*cal_block, session_id);
  2133. if (ret < 0) {
  2134. pr_err("%s: Remap_cal_data failed for cal %d!\n",
  2135. __func__, cal_block_idx);
  2136. ret = -ENODEV;
  2137. goto done;
  2138. }
  2139. if (col_data == NULL)
  2140. goto done;
  2141. *col_data = cal_utils_get_only_cal_block(
  2142. common.cal_data[col_data_idx]);
  2143. if (*col_data == NULL) {
  2144. pr_err("%s: No cal data for cal %d!\n",
  2145. __func__, col_data_idx);
  2146. ret = -ENODEV;
  2147. goto done;
  2148. }
  2149. done:
  2150. return ret;
  2151. }
  2152. static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
  2153. {
  2154. struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
  2155. struct cal_block_data *cal_block = NULL;
  2156. struct cal_block_data *col_data = NULL;
  2157. int ret = 0;
  2158. memset(&cvs_reg_cal_cmd, 0, sizeof(cvs_reg_cal_cmd));
  2159. if (v == NULL) {
  2160. pr_err("%s: v is NULL\n", __func__);
  2161. ret = -EINVAL;
  2162. goto done;
  2163. }
  2164. if (!common.apr_q6_cvs) {
  2165. pr_err("%s: apr_cvs is NULL\n", __func__);
  2166. ret = -EINVAL;
  2167. goto done;
  2168. }
  2169. mutex_lock(&common.cal_data[CVS_VOCSTRM_CAL]->lock);
  2170. mutex_lock(&common.cal_data[CVS_VOCSTRM_COL_CAL]->lock);
  2171. ret = voice_get_cal(&cal_block, CVS_VOCSTRM_CAL, &col_data,
  2172. CVS_VOCSTRM_COL_CAL, v->session_id);
  2173. if (ret < 0) {
  2174. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2175. __func__, CVS_VOCSTRM_CAL);
  2176. goto unlock;
  2177. }
  2178. memcpy(&cvs_reg_cal_cmd.cvs_cal_data.column_info[0],
  2179. (void *) &((struct audio_cal_info_voc_col *)
  2180. col_data->cal_info)->data,
  2181. col_data->cal_data.size);
  2182. cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2183. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2184. cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2185. sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
  2186. cvs_reg_cal_cmd.hdr.src_port =
  2187. voice_get_idx_for_session(v->session_id);
  2188. cvs_reg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  2189. cvs_reg_cal_cmd.hdr.token = 0;
  2190. if (common.is_per_vocoder_cal_enabled)
  2191. cvs_reg_cal_cmd.hdr.opcode =
  2192. VSS_ISTREAM_CMD_REGISTER_STATIC_CALIBRATION_DATA;
  2193. else
  2194. cvs_reg_cal_cmd.hdr.opcode =
  2195. VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2;
  2196. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_handle =
  2197. cal_block->map_data.q6map_handle;
  2198. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address_lsw =
  2199. lower_32_bits(cal_block->cal_data.paddr);
  2200. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address_msw =
  2201. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2202. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_size =
  2203. cal_block->cal_data.size;
  2204. v->cvs_state = CMD_STATUS_FAIL;
  2205. v->async_err = 0;
  2206. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_reg_cal_cmd);
  2207. if (ret < 0) {
  2208. pr_err("%s: Error %d registering CVS cal\n", __func__, ret);
  2209. ret = -EINVAL;
  2210. goto unlock;
  2211. }
  2212. ret = wait_event_timeout(v->cvs_wait,
  2213. (v->cvs_state == CMD_STATUS_SUCCESS),
  2214. msecs_to_jiffies(TIMEOUT_MS));
  2215. if (!ret) {
  2216. pr_err("%s: Command timeout\n", __func__);
  2217. ret = -EINVAL;
  2218. goto unlock;
  2219. }
  2220. if (v->async_err > 0) {
  2221. pr_err("%s: DSP returned error[%s]\n",
  2222. __func__, adsp_err_get_err_str(
  2223. v->async_err));
  2224. ret = adsp_err_get_lnx_err_code(
  2225. v->async_err);
  2226. goto unlock;
  2227. }
  2228. unlock:
  2229. mutex_unlock(&common.cal_data[CVS_VOCSTRM_COL_CAL]->lock);
  2230. mutex_unlock(&common.cal_data[CVS_VOCSTRM_CAL]->lock);
  2231. done:
  2232. return ret;
  2233. }
  2234. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
  2235. {
  2236. struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
  2237. int ret = 0;
  2238. memset(&cvs_dereg_cal_cmd, 0, sizeof(cvs_dereg_cal_cmd));
  2239. if (v == NULL) {
  2240. pr_err("%s: v is NULL\n", __func__);
  2241. ret = -EINVAL;
  2242. goto done;
  2243. }
  2244. if (!common.apr_q6_cvs) {
  2245. pr_err("%s: apr_cvs is NULL\n", __func__);
  2246. ret = -EPERM;
  2247. goto done;
  2248. }
  2249. cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2250. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2251. cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2252. sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
  2253. cvs_dereg_cal_cmd.hdr.src_port =
  2254. voice_get_idx_for_session(v->session_id);
  2255. cvs_dereg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  2256. cvs_dereg_cal_cmd.hdr.token = 0;
  2257. if (common.is_per_vocoder_cal_enabled)
  2258. cvs_dereg_cal_cmd.hdr.opcode =
  2259. VSS_ISTREAM_CMD_DEREGISTER_STATIC_CALIBRATION_DATA;
  2260. else
  2261. cvs_dereg_cal_cmd.hdr.opcode =
  2262. VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
  2263. v->cvs_state = CMD_STATUS_FAIL;
  2264. v->async_err = 0;
  2265. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
  2266. if (ret < 0) {
  2267. pr_err("%s: Error %d de-registering CVS cal\n", __func__, ret);
  2268. goto done;
  2269. }
  2270. ret = wait_event_timeout(v->cvs_wait,
  2271. (v->cvs_state == CMD_STATUS_SUCCESS),
  2272. msecs_to_jiffies(TIMEOUT_MS));
  2273. if (!ret) {
  2274. pr_err("%s: Command timeout\n", __func__);
  2275. goto done;
  2276. }
  2277. if (v->async_err > 0) {
  2278. pr_err("%s: DSP returned error[%s]\n",
  2279. __func__, adsp_err_get_err_str(
  2280. v->async_err));
  2281. ret = adsp_err_get_lnx_err_code(
  2282. v->async_err);
  2283. goto done;
  2284. }
  2285. done:
  2286. return ret;
  2287. }
  2288. static int voice_send_cvp_create_cmd(struct voice_data *v)
  2289. {
  2290. struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
  2291. void *apr_cvp;
  2292. int ret = 0;
  2293. if (v == NULL) {
  2294. pr_err("%s: v is NULL\n", __func__);
  2295. ret = -EINVAL;
  2296. goto done;
  2297. }
  2298. apr_cvp = common.apr_q6_cvp;
  2299. if (!apr_cvp) {
  2300. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2301. ret = -EINVAL;
  2302. goto done;
  2303. }
  2304. /* create cvp session and wait for response */
  2305. cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2306. APR_HDR_LEN(APR_HDR_SIZE),
  2307. APR_PKT_VER);
  2308. cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2309. sizeof(cvp_session_cmd) - APR_HDR_SIZE);
  2310. pr_debug("%s: send create cvp session, pkt size = %d\n",
  2311. __func__, cvp_session_cmd.hdr.pkt_size);
  2312. cvp_session_cmd.hdr.src_port =
  2313. voice_get_idx_for_session(v->session_id);
  2314. cvp_session_cmd.hdr.dest_port = 0;
  2315. cvp_session_cmd.hdr.token = 0;
  2316. if (voice_get_cvd_int_version(common.cvd_version) >=
  2317. CVD_INT_VERSION_2_2)
  2318. cvp_session_cmd.hdr.opcode =
  2319. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V3;
  2320. else
  2321. cvp_session_cmd.hdr.opcode =
  2322. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2;
  2323. voc_get_tx_rx_topology(v,
  2324. &cvp_session_cmd.cvp_session.tx_topology_id,
  2325. &cvp_session_cmd.cvp_session.rx_topology_id);
  2326. cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
  2327. cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
  2328. cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
  2329. cvp_session_cmd.cvp_session.profile_id =
  2330. VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2331. if (common.ec_ref_ext) {
  2332. cvp_session_cmd.cvp_session.vocproc_mode =
  2333. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2334. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2335. common.ec_media_fmt_info.port_id;
  2336. } else {
  2337. cvp_session_cmd.cvp_session.vocproc_mode =
  2338. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2339. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2340. VSS_IVOCPROC_PORT_ID_NONE;
  2341. }
  2342. pr_debug("tx_topology: %d tx_port_id=%d, rx_port_id=%d, mode: 0x%x\n",
  2343. cvp_session_cmd.cvp_session.tx_topology_id,
  2344. cvp_session_cmd.cvp_session.tx_port_id,
  2345. cvp_session_cmd.cvp_session.rx_port_id,
  2346. cvp_session_cmd.cvp_session.vocproc_mode);
  2347. pr_debug("rx_topology: %d, profile_id: 0x%x, pkt_size: %d\n",
  2348. cvp_session_cmd.cvp_session.rx_topology_id,
  2349. cvp_session_cmd.cvp_session.profile_id,
  2350. cvp_session_cmd.hdr.pkt_size);
  2351. v->cvp_state = CMD_STATUS_FAIL;
  2352. v->async_err = 0;
  2353. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
  2354. if (ret < 0) {
  2355. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  2356. ret = -EINVAL;
  2357. goto done;
  2358. }
  2359. ret = wait_event_timeout(v->cvp_wait,
  2360. (v->cvp_state == CMD_STATUS_SUCCESS),
  2361. msecs_to_jiffies(TIMEOUT_MS));
  2362. if (!ret) {
  2363. pr_err("%s: wait_event timeout\n", __func__);
  2364. ret = -EINVAL;
  2365. goto done;
  2366. }
  2367. if (v->async_err > 0) {
  2368. pr_err("%s: DSP returned error[%s]\n",
  2369. __func__, adsp_err_get_err_str(
  2370. v->async_err));
  2371. ret = adsp_err_get_lnx_err_code(
  2372. v->async_err);
  2373. goto done;
  2374. }
  2375. done:
  2376. return ret;
  2377. }
  2378. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v)
  2379. {
  2380. struct cvp_register_dev_cfg_cmd cvp_reg_dev_cfg_cmd;
  2381. struct cal_block_data *cal_block = NULL;
  2382. int ret = 0;
  2383. memset(&cvp_reg_dev_cfg_cmd, 0, sizeof(cvp_reg_dev_cfg_cmd));
  2384. if (v == NULL) {
  2385. pr_err("%s: v is NULL\n", __func__);
  2386. ret = -EINVAL;
  2387. goto done;
  2388. }
  2389. if (!common.apr_q6_cvp) {
  2390. pr_err("%s: apr_cvp is NULL\n", __func__);
  2391. ret = -EPERM;
  2392. goto done;
  2393. }
  2394. mutex_lock(&common.cal_data[CVP_VOCDEV_CFG_CAL]->lock);
  2395. ret = voice_get_cal(&cal_block, CVP_VOCDEV_CFG_CAL, NULL,
  2396. 0, v->session_id);
  2397. if (ret < 0) {
  2398. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2399. __func__, CVP_VOCDEV_CFG_CAL);
  2400. goto unlock;
  2401. }
  2402. cvp_reg_dev_cfg_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2403. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2404. cvp_reg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2405. sizeof(cvp_reg_dev_cfg_cmd) - APR_HDR_SIZE);
  2406. cvp_reg_dev_cfg_cmd.hdr.src_port =
  2407. voice_get_idx_for_session(v->session_id);
  2408. cvp_reg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2409. cvp_reg_dev_cfg_cmd.hdr.token = 0;
  2410. cvp_reg_dev_cfg_cmd.hdr.opcode =
  2411. VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG;
  2412. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_handle =
  2413. cal_block->map_data.q6map_handle;
  2414. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address_lsw =
  2415. lower_32_bits(cal_block->cal_data.paddr);
  2416. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address_msw =
  2417. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2418. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_size =
  2419. cal_block->cal_data.size;
  2420. v->cvp_state = CMD_STATUS_FAIL;
  2421. v->async_err = 0;
  2422. ret = apr_send_pkt(common.apr_q6_cvp,
  2423. (uint32_t *) &cvp_reg_dev_cfg_cmd);
  2424. if (ret < 0) {
  2425. pr_err("%s: Error %d registering CVP dev cfg cal\n",
  2426. __func__, ret);
  2427. ret = -EINVAL;
  2428. goto unlock;
  2429. }
  2430. ret = wait_event_timeout(v->cvp_wait,
  2431. (v->cvp_state == CMD_STATUS_SUCCESS),
  2432. msecs_to_jiffies(TIMEOUT_MS));
  2433. if (!ret) {
  2434. pr_err("%s: Command timeout\n", __func__);
  2435. ret = -EINVAL;
  2436. goto unlock;
  2437. }
  2438. if (v->async_err > 0) {
  2439. pr_err("%s: DSP returned error[%s]\n",
  2440. __func__, adsp_err_get_err_str(
  2441. v->async_err));
  2442. ret = adsp_err_get_lnx_err_code(
  2443. v->async_err);
  2444. goto unlock;
  2445. }
  2446. unlock:
  2447. mutex_unlock(&common.cal_data[CVP_VOCDEV_CFG_CAL]->lock);
  2448. done:
  2449. return ret;
  2450. }
  2451. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v)
  2452. {
  2453. struct cvp_deregister_dev_cfg_cmd cvp_dereg_dev_cfg_cmd;
  2454. int ret = 0;
  2455. memset(&cvp_dereg_dev_cfg_cmd, 0, sizeof(cvp_dereg_dev_cfg_cmd));
  2456. if (v == NULL) {
  2457. pr_err("%s: v is NULL\n", __func__);
  2458. ret = -EINVAL;
  2459. goto done;
  2460. }
  2461. if (!common.apr_q6_cvp) {
  2462. pr_err("%s: apr_cvp is NULL\n", __func__);
  2463. ret = -EPERM;
  2464. goto done;
  2465. }
  2466. cvp_dereg_dev_cfg_cmd.hdr.hdr_field =
  2467. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2468. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2469. cvp_dereg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2470. sizeof(cvp_dereg_dev_cfg_cmd) - APR_HDR_SIZE);
  2471. cvp_dereg_dev_cfg_cmd.hdr.src_port =
  2472. voice_get_idx_for_session(v->session_id);
  2473. cvp_dereg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2474. cvp_dereg_dev_cfg_cmd.hdr.token = 0;
  2475. cvp_dereg_dev_cfg_cmd.hdr.opcode =
  2476. VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG;
  2477. v->cvp_state = CMD_STATUS_FAIL;
  2478. v->async_err = 0;
  2479. ret = apr_send_pkt(common.apr_q6_cvp,
  2480. (uint32_t *) &cvp_dereg_dev_cfg_cmd);
  2481. if (ret < 0) {
  2482. pr_err("%s: Error %d de-registering CVP dev cfg cal\n",
  2483. __func__, ret);
  2484. goto done;
  2485. }
  2486. ret = wait_event_timeout(v->cvp_wait,
  2487. (v->cvp_state == CMD_STATUS_SUCCESS),
  2488. msecs_to_jiffies(TIMEOUT_MS));
  2489. if (!ret) {
  2490. pr_err("%s: Command timeout\n", __func__);
  2491. goto done;
  2492. }
  2493. if (v->async_err > 0) {
  2494. pr_err("%s: DSP returned error[%s]\n",
  2495. __func__, adsp_err_get_err_str(
  2496. v->async_err));
  2497. ret = adsp_err_get_lnx_err_code(
  2498. v->async_err);
  2499. goto done;
  2500. }
  2501. done:
  2502. return ret;
  2503. }
  2504. static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
  2505. {
  2506. struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
  2507. struct cal_block_data *cal_block = NULL;
  2508. struct cal_block_data *col_data = NULL;
  2509. int ret = 0;
  2510. memset(&cvp_reg_cal_cmd, 0, sizeof(cvp_reg_cal_cmd));
  2511. if (v == NULL) {
  2512. pr_err("%s: v is NULL\n", __func__);
  2513. ret = -EINVAL;
  2514. goto done;
  2515. }
  2516. if (!common.apr_q6_cvp) {
  2517. pr_err("%s: apr_cvp is NULL\n", __func__);
  2518. ret = -EINVAL;
  2519. goto done;
  2520. }
  2521. mutex_lock(&common.cal_data[CVP_VOCPROC_CAL]->lock);
  2522. mutex_lock(&common.cal_data[CVP_VOCPROC_COL_CAL]->lock);
  2523. ret = voice_get_cal(&cal_block, CVP_VOCPROC_CAL, &col_data,
  2524. CVP_VOCPROC_COL_CAL, v->session_id);
  2525. if (ret < 0) {
  2526. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2527. __func__, CVP_VOCPROC_CAL);
  2528. goto unlock;
  2529. }
  2530. v->dev_tx.dev_id = ((struct audio_cal_info_vocproc *)
  2531. cal_block->cal_info)->tx_acdb_id;
  2532. v->dev_rx.dev_id = ((struct audio_cal_info_vocproc *)
  2533. cal_block->cal_info)->rx_acdb_id;
  2534. pr_debug("%s: %s: Tx acdb id = %d and Rx acdb id = %d", __func__,
  2535. voc_get_session_name(v->session_id), v->dev_tx.dev_id,
  2536. v->dev_rx.dev_id);
  2537. memcpy(&cvp_reg_cal_cmd.cvp_cal_data.column_info[0],
  2538. (void *) &((struct audio_cal_info_voc_col *)
  2539. col_data->cal_info)->data,
  2540. col_data->cal_data.size);
  2541. cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2542. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2543. cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2544. sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
  2545. cvp_reg_cal_cmd.hdr.src_port =
  2546. voice_get_idx_for_session(v->session_id);
  2547. cvp_reg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2548. cvp_reg_cal_cmd.hdr.token = 0;
  2549. if (common.is_per_vocoder_cal_enabled)
  2550. cvp_reg_cal_cmd.hdr.opcode =
  2551. VSS_IVOCPROC_CMD_REGISTER_STATIC_CALIBRATION_DATA;
  2552. else
  2553. cvp_reg_cal_cmd.hdr.opcode =
  2554. VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2;
  2555. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_handle =
  2556. cal_block->map_data.q6map_handle;
  2557. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address_lsw =
  2558. lower_32_bits(cal_block->cal_data.paddr);
  2559. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address_msw =
  2560. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2561. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_size =
  2562. cal_block->cal_data.size;
  2563. v->cvp_state = CMD_STATUS_FAIL;
  2564. v->async_err = 0;
  2565. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_reg_cal_cmd);
  2566. if (ret < 0) {
  2567. pr_err("%s: Error %d registering CVP cal\n", __func__, ret);
  2568. ret = -EINVAL;
  2569. goto unlock;
  2570. }
  2571. ret = wait_event_timeout(v->cvp_wait,
  2572. (v->cvp_state == CMD_STATUS_SUCCESS),
  2573. msecs_to_jiffies(TIMEOUT_MS));
  2574. if (!ret) {
  2575. pr_err("%s: Command timeout\n", __func__);
  2576. ret = -EINVAL;
  2577. goto unlock;
  2578. }
  2579. if (v->async_err > 0) {
  2580. pr_err("%s: DSP returned error[%s]\n",
  2581. __func__, adsp_err_get_err_str(
  2582. v->async_err));
  2583. ret = adsp_err_get_lnx_err_code(
  2584. v->async_err);
  2585. goto unlock;
  2586. }
  2587. unlock:
  2588. mutex_unlock(&common.cal_data[CVP_VOCPROC_COL_CAL]->lock);
  2589. mutex_unlock(&common.cal_data[CVP_VOCPROC_CAL]->lock);
  2590. done:
  2591. return ret;
  2592. }
  2593. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
  2594. {
  2595. struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
  2596. int ret = 0;
  2597. memset(&cvp_dereg_cal_cmd, 0, sizeof(cvp_dereg_cal_cmd));
  2598. if (v == NULL) {
  2599. pr_err("%s: v is NULL\n", __func__);
  2600. ret = -EINVAL;
  2601. goto done;
  2602. }
  2603. if (!common.apr_q6_cvp) {
  2604. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2605. ret = -EPERM;
  2606. goto done;
  2607. }
  2608. cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2609. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2610. cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2611. sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
  2612. cvp_dereg_cal_cmd.hdr.src_port =
  2613. voice_get_idx_for_session(v->session_id);
  2614. cvp_dereg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2615. cvp_dereg_cal_cmd.hdr.token = 0;
  2616. if (common.is_per_vocoder_cal_enabled)
  2617. cvp_dereg_cal_cmd.hdr.opcode =
  2618. VSS_IVOCPROC_CMD_DEREGISTER_STATIC_CALIBRATION_DATA;
  2619. else
  2620. cvp_dereg_cal_cmd.hdr.opcode =
  2621. VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
  2622. v->cvp_state = CMD_STATUS_FAIL;
  2623. v->async_err = 0;
  2624. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
  2625. if (ret < 0) {
  2626. pr_err("%s: Error %d de-registering CVP cal\n", __func__, ret);
  2627. goto done;
  2628. }
  2629. ret = wait_event_timeout(v->cvp_wait,
  2630. (v->cvp_state == CMD_STATUS_SUCCESS),
  2631. msecs_to_jiffies(TIMEOUT_MS));
  2632. if (!ret) {
  2633. pr_err("%s: Command timeout\n", __func__);
  2634. goto done;
  2635. }
  2636. if (v->async_err > 0) {
  2637. pr_err("%s: DSP returned error[%s]\n",
  2638. __func__, adsp_err_get_err_str(
  2639. v->async_err));
  2640. ret = adsp_err_get_lnx_err_code(
  2641. v->async_err);
  2642. goto done;
  2643. }
  2644. done:
  2645. return ret;
  2646. }
  2647. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v)
  2648. {
  2649. struct cvp_register_vol_cal_data_cmd cvp_reg_vol_cal_cmd;
  2650. struct cal_block_data *cal_block = NULL;
  2651. struct cal_block_data *col_data = NULL;
  2652. int ret = 0;
  2653. memset(&cvp_reg_vol_cal_cmd, 0, sizeof(cvp_reg_vol_cal_cmd));
  2654. if (v == NULL) {
  2655. pr_err("%s: v is NULL\n", __func__);
  2656. ret = -EINVAL;
  2657. goto done;
  2658. }
  2659. if (!common.apr_q6_cvp) {
  2660. pr_err("%s: apr_cvp is NULL\n", __func__);
  2661. ret = -EINVAL;
  2662. goto done;
  2663. }
  2664. mutex_lock(&common.cal_data[CVP_VOCVOL_CAL]->lock);
  2665. mutex_lock(&common.cal_data[CVP_VOCVOL_COL_CAL]->lock);
  2666. ret = voice_get_cal(&cal_block, CVP_VOCVOL_CAL, &col_data,
  2667. CVP_VOCVOL_COL_CAL, v->session_id);
  2668. if (ret < 0) {
  2669. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2670. __func__, CVP_VOCVOL_CAL);
  2671. goto unlock;
  2672. }
  2673. memcpy(&cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info[0],
  2674. (void *) &((struct audio_cal_info_voc_col *)
  2675. col_data->cal_info)->data,
  2676. col_data->cal_data.size);
  2677. cvp_reg_vol_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2678. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2679. cvp_reg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2680. sizeof(cvp_reg_vol_cal_cmd) - APR_HDR_SIZE);
  2681. cvp_reg_vol_cal_cmd.hdr.src_port =
  2682. voice_get_idx_for_session(v->session_id);
  2683. cvp_reg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2684. cvp_reg_vol_cal_cmd.hdr.token = 0;
  2685. if (common.is_per_vocoder_cal_enabled)
  2686. cvp_reg_vol_cal_cmd.hdr.opcode =
  2687. VSS_IVOCPROC_CMD_REGISTER_DYNAMIC_CALIBRATION_DATA;
  2688. else
  2689. cvp_reg_vol_cal_cmd.hdr.opcode =
  2690. VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA;
  2691. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_handle =
  2692. cal_block->map_data.q6map_handle;
  2693. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address_lsw =
  2694. lower_32_bits(cal_block->cal_data.paddr);
  2695. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address_msw =
  2696. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2697. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_size =
  2698. cal_block->cal_data.size;
  2699. v->cvp_state = CMD_STATUS_FAIL;
  2700. v->async_err = 0;
  2701. ret = apr_send_pkt(common.apr_q6_cvp,
  2702. (uint32_t *) &cvp_reg_vol_cal_cmd);
  2703. if (ret < 0) {
  2704. pr_err("%s: Error %d registering CVP vol cal\n", __func__, ret);
  2705. ret = -EINVAL;
  2706. goto unlock;
  2707. }
  2708. ret = wait_event_timeout(v->cvp_wait,
  2709. (v->cvp_state == CMD_STATUS_SUCCESS),
  2710. msecs_to_jiffies(TIMEOUT_MS));
  2711. if (!ret) {
  2712. pr_err("%s: Command timeout\n", __func__);
  2713. ret = -EINVAL;
  2714. goto unlock;
  2715. }
  2716. if (v->async_err > 0) {
  2717. pr_err("%s: DSP returned error[%s]\n",
  2718. __func__, adsp_err_get_err_str(
  2719. v->async_err));
  2720. ret = adsp_err_get_lnx_err_code(
  2721. v->async_err);
  2722. goto unlock;
  2723. }
  2724. unlock:
  2725. mutex_unlock(&common.cal_data[CVP_VOCVOL_COL_CAL]->lock);
  2726. mutex_unlock(&common.cal_data[CVP_VOCVOL_CAL]->lock);
  2727. done:
  2728. return ret;
  2729. }
  2730. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v)
  2731. {
  2732. struct cvp_deregister_vol_cal_data_cmd cvp_dereg_vol_cal_cmd;
  2733. int ret = 0;
  2734. memset(&cvp_dereg_vol_cal_cmd, 0, sizeof(cvp_dereg_vol_cal_cmd));
  2735. if (v == NULL) {
  2736. pr_err("%s: v is NULL\n", __func__);
  2737. ret = -EINVAL;
  2738. goto done;
  2739. }
  2740. if (!common.apr_q6_cvp) {
  2741. pr_err("%s: apr_cvp is NULL\n", __func__);
  2742. ret = -EPERM;
  2743. goto done;
  2744. }
  2745. cvp_dereg_vol_cal_cmd.hdr.hdr_field =
  2746. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2747. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2748. cvp_dereg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2749. sizeof(cvp_dereg_vol_cal_cmd) - APR_HDR_SIZE);
  2750. cvp_dereg_vol_cal_cmd.hdr.src_port =
  2751. voice_get_idx_for_session(v->session_id);
  2752. cvp_dereg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2753. cvp_dereg_vol_cal_cmd.hdr.token = 0;
  2754. if (common.is_per_vocoder_cal_enabled)
  2755. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2756. VSS_IVOCPROC_CMD_DEREGISTER_DYNAMIC_CALIBRATION_DATA;
  2757. else
  2758. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2759. VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA;
  2760. v->cvp_state = CMD_STATUS_FAIL;
  2761. v->async_err = 0;
  2762. ret = apr_send_pkt(common.apr_q6_cvp,
  2763. (uint32_t *) &cvp_dereg_vol_cal_cmd);
  2764. if (ret < 0) {
  2765. pr_err("%s: Error %d de-registering CVP vol cal\n",
  2766. __func__, ret);
  2767. goto done;
  2768. }
  2769. ret = wait_event_timeout(v->cvp_wait,
  2770. (v->cvp_state == CMD_STATUS_SUCCESS),
  2771. msecs_to_jiffies(TIMEOUT_MS));
  2772. if (!ret) {
  2773. pr_err("%s: Command timeout\n", __func__);
  2774. goto done;
  2775. }
  2776. if (v->async_err > 0) {
  2777. pr_err("%s: DSP returned error[%s]\n",
  2778. __func__, adsp_err_get_err_str(
  2779. v->async_err));
  2780. ret = adsp_err_get_lnx_err_code(
  2781. v->async_err);
  2782. goto done;
  2783. }
  2784. done:
  2785. return ret;
  2786. }
  2787. static int voice_map_memory_physical_cmd(struct voice_data *v,
  2788. struct mem_map_table *table_info,
  2789. dma_addr_t phys,
  2790. uint32_t size,
  2791. uint32_t token)
  2792. {
  2793. struct vss_imemory_cmd_map_physical_t mvm_map_phys_cmd;
  2794. uint32_t *memtable;
  2795. int ret = 0;
  2796. if (v == NULL) {
  2797. pr_err("%s: v is NULL\n", __func__);
  2798. ret = -EINVAL;
  2799. goto fail;
  2800. }
  2801. if (!common.apr_q6_mvm) {
  2802. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2803. ret = -EINVAL;
  2804. goto fail;
  2805. }
  2806. if (!table_info->data) {
  2807. pr_err("%s: memory table is NULL.\n", __func__);
  2808. ret = -EINVAL;
  2809. goto fail;
  2810. }
  2811. memtable = (uint32_t *) table_info->data;
  2812. /*
  2813. * Store next table descriptor's address(64 bit) as NULL as there
  2814. * is only one memory block
  2815. */
  2816. memtable[0] = 0;
  2817. memtable[1] = 0;
  2818. /* Store next table descriptor's size */
  2819. memtable[2] = 0;
  2820. /* Store shared mem adddress (64 bit) */
  2821. memtable[3] = lower_32_bits(phys);
  2822. memtable[4] = msm_audio_populate_upper_32_bits(phys);
  2823. /* Store shared memory size */
  2824. memtable[5] = size;
  2825. mvm_map_phys_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2826. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2827. mvm_map_phys_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2828. sizeof(mvm_map_phys_cmd) - APR_HDR_SIZE);
  2829. mvm_map_phys_cmd.hdr.src_port =
  2830. voice_get_idx_for_session(v->session_id);
  2831. mvm_map_phys_cmd.hdr.dest_port = voice_get_mvm_handle(v);
  2832. mvm_map_phys_cmd.hdr.token = token;
  2833. mvm_map_phys_cmd.hdr.opcode = VSS_IMEMORY_CMD_MAP_PHYSICAL;
  2834. mvm_map_phys_cmd.table_descriptor.mem_address_lsw =
  2835. lower_32_bits(table_info->phys);
  2836. mvm_map_phys_cmd.table_descriptor.mem_address_msw =
  2837. msm_audio_populate_upper_32_bits(table_info->phys);
  2838. mvm_map_phys_cmd.table_descriptor.mem_size =
  2839. sizeof(struct vss_imemory_block_t) +
  2840. sizeof(struct vss_imemory_table_descriptor_t);
  2841. mvm_map_phys_cmd.is_cached = true;
  2842. mvm_map_phys_cmd.cache_line_size = 128;
  2843. mvm_map_phys_cmd.access_mask = 3;
  2844. mvm_map_phys_cmd.page_align = 4096;
  2845. mvm_map_phys_cmd.min_data_width = 8;
  2846. mvm_map_phys_cmd.max_data_width = 64;
  2847. pr_debug("%s: next table desc: add: %lld, size: %d\n",
  2848. __func__, *((uint64_t *) memtable),
  2849. *(((uint32_t *) memtable) + 2));
  2850. pr_debug("%s: phy add of of mem being mapped LSW:0x%x, MSW:0x%x size: %d\n",
  2851. __func__, *(((uint32_t *) memtable) + 3),
  2852. *(((uint32_t *) memtable) + 4), *(((uint32_t *) memtable) + 5));
  2853. v->mvm_state = CMD_STATUS_FAIL;
  2854. v->async_err = 0;
  2855. ret = apr_send_pkt(common.apr_q6_mvm, (uint32_t *) &mvm_map_phys_cmd);
  2856. if (ret < 0) {
  2857. pr_err("%s: Error %d sending mvm map phy cmd\n", __func__, ret);
  2858. goto fail;
  2859. }
  2860. ret = wait_event_timeout(v->mvm_wait,
  2861. (v->mvm_state == CMD_STATUS_SUCCESS),
  2862. msecs_to_jiffies(TIMEOUT_MS));
  2863. if (!ret) {
  2864. pr_err("%s: Command timeout\n", __func__);
  2865. goto fail;
  2866. }
  2867. if (v->async_err > 0) {
  2868. pr_err("%s: DSP returned error[%s]\n",
  2869. __func__, adsp_err_get_err_str(
  2870. v->async_err));
  2871. ret = adsp_err_get_lnx_err_code(
  2872. v->async_err);
  2873. goto fail;
  2874. }
  2875. return 0;
  2876. fail:
  2877. return ret;
  2878. }
  2879. static int voice_pause_voice_call(struct voice_data *v)
  2880. {
  2881. struct apr_hdr mvm_pause_voice_cmd;
  2882. void *apr_mvm;
  2883. int ret = 0;
  2884. pr_debug("%s\n", __func__);
  2885. if (v == NULL) {
  2886. pr_err("%s: Voice data is NULL\n", __func__);
  2887. ret = -EINVAL;
  2888. goto done;
  2889. }
  2890. apr_mvm = common.apr_q6_mvm;
  2891. if (!apr_mvm) {
  2892. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2893. ret = -EINVAL;
  2894. goto done;
  2895. }
  2896. mvm_pause_voice_cmd.hdr_field =
  2897. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2898. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2899. mvm_pause_voice_cmd.pkt_size =
  2900. APR_PKT_SIZE(APR_HDR_SIZE,
  2901. sizeof(mvm_pause_voice_cmd) - APR_HDR_SIZE);
  2902. mvm_pause_voice_cmd.src_port =
  2903. voice_get_idx_for_session(v->session_id);
  2904. mvm_pause_voice_cmd.dest_port = voice_get_mvm_handle(v);
  2905. mvm_pause_voice_cmd.token = 0;
  2906. mvm_pause_voice_cmd.opcode = VSS_IMVM_CMD_PAUSE_VOICE;
  2907. v->mvm_state = CMD_STATUS_FAIL;
  2908. v->async_err = 0;
  2909. pr_debug("%s: send mvm_pause_voice_cmd pkt size = %d\n",
  2910. __func__, mvm_pause_voice_cmd.pkt_size);
  2911. ret = apr_send_pkt(apr_mvm,
  2912. (uint32_t *)&mvm_pause_voice_cmd);
  2913. if (ret < 0) {
  2914. pr_err("Fail in sending VSS_IMVM_CMD_PAUSE_VOICE\n");
  2915. ret = -EINVAL;
  2916. goto done;
  2917. }
  2918. ret = wait_event_timeout(v->mvm_wait,
  2919. (v->mvm_state == CMD_STATUS_SUCCESS),
  2920. msecs_to_jiffies(TIMEOUT_MS));
  2921. if (!ret) {
  2922. pr_err("%s: Command timeout\n", __func__);
  2923. ret = -EINVAL;
  2924. goto done;
  2925. }
  2926. if (v->async_err > 0) {
  2927. pr_err("%s: DSP returned error[%s]\n",
  2928. __func__, adsp_err_get_err_str(
  2929. v->async_err));
  2930. ret = adsp_err_get_lnx_err_code(
  2931. v->async_err);
  2932. goto done;
  2933. }
  2934. done:
  2935. return ret;
  2936. }
  2937. static int voice_map_cal_memory(struct cal_block_data *cal_block,
  2938. uint32_t session_id)
  2939. {
  2940. int result = 0;
  2941. int voc_index;
  2942. struct voice_data *v = NULL;
  2943. pr_debug("%s\n", __func__);
  2944. if (cal_block == NULL) {
  2945. pr_err("%s: Cal block is NULL!\n", __func__);
  2946. result = -EINVAL;
  2947. goto done;
  2948. }
  2949. if (cal_block->cal_data.paddr == 0) {
  2950. pr_debug("%s: No address to map!\n", __func__);
  2951. result = -EINVAL;
  2952. goto done;
  2953. }
  2954. if (cal_block->map_data.map_size == 0) {
  2955. pr_debug("%s: Map size is 0!\n", __func__);
  2956. result = -EINVAL;
  2957. goto done;
  2958. }
  2959. voc_index = voice_get_idx_for_session(session_id);
  2960. if (voc_index < 0) {
  2961. pr_err("%s: Invalid session ID %d\n", __func__, session_id);
  2962. goto done;
  2963. }
  2964. mutex_lock(&common.common_lock);
  2965. v = &common.voice[voc_index];
  2966. result = voice_map_memory_physical_cmd(v,
  2967. &common.cal_mem_map_table,
  2968. (dma_addr_t)cal_block->cal_data.paddr,
  2969. cal_block->map_data.map_size,
  2970. VOC_CAL_MEM_MAP_TOKEN);
  2971. if (result < 0) {
  2972. pr_err("%s: Mmap did not work! addr = 0x%pK, size = %zd\n",
  2973. __func__,
  2974. &cal_block->cal_data.paddr,
  2975. cal_block->map_data.map_size);
  2976. goto done_unlock;
  2977. }
  2978. cal_block->map_data.q6map_handle = common.cal_mem_handle;
  2979. done_unlock:
  2980. mutex_unlock(&common.common_lock);
  2981. done:
  2982. return result;
  2983. }
  2984. static int remap_cal_data(struct cal_block_data *cal_block,
  2985. uint32_t session_id)
  2986. {
  2987. int ret = 0;
  2988. pr_debug("%s\n", __func__);
  2989. if (cal_block->map_data.ion_client == NULL) {
  2990. pr_err("%s: No ION allocation for session_id %d!\n",
  2991. __func__, session_id);
  2992. ret = -EINVAL;
  2993. goto done;
  2994. }
  2995. if ((cal_block->map_data.map_size > 0) &&
  2996. (cal_block->map_data.q6map_handle == 0)) {
  2997. /* cal type not used */
  2998. ret = voice_map_cal_memory(cal_block, session_id);
  2999. if (ret < 0) {
  3000. pr_err("%s: Mmap did not work! size = %zd\n",
  3001. __func__, cal_block->map_data.map_size);
  3002. goto done;
  3003. }
  3004. } else {
  3005. pr_debug("%s: Cal block 0x%pK, size %zd already mapped. Q6 map handle = %d\n",
  3006. __func__, &cal_block->cal_data.paddr,
  3007. cal_block->map_data.map_size,
  3008. cal_block->map_data.q6map_handle);
  3009. }
  3010. done:
  3011. return ret;
  3012. }
  3013. static int voice_unmap_cal_memory(int32_t cal_type,
  3014. struct cal_block_data *cal_block)
  3015. {
  3016. int result = 0;
  3017. int result2 = 0;
  3018. int i;
  3019. struct voice_data *v = NULL;
  3020. pr_debug("%s\n", __func__);
  3021. if (cal_block == NULL) {
  3022. pr_err("%s: Cal block is NULL!\n", __func__);
  3023. result = -EINVAL;
  3024. goto done;
  3025. }
  3026. if (cal_block->map_data.q6map_handle == 0) {
  3027. pr_debug("%s: Q6 handle is not set!\n", __func__);
  3028. result = -EINVAL;
  3029. goto done;
  3030. }
  3031. mutex_lock(&common.common_lock);
  3032. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3033. v = &common.voice[i];
  3034. mutex_lock(&v->lock);
  3035. if (is_voc_state_active(v->voc_state)) {
  3036. result2 = voice_pause_voice_call(v);
  3037. if (result2 < 0) {
  3038. pr_err("%s: Voice_pause_voice_call failed for session 0x%x, err %d!\n",
  3039. __func__, v->session_id, result2);
  3040. result = result2;
  3041. }
  3042. if (cal_type == CVP_VOCPROC_DYNAMIC_CAL_TYPE)
  3043. voice_send_cvp_deregister_vol_cal_cmd(v);
  3044. else if (cal_type == CVP_VOCPROC_STATIC_CAL_TYPE)
  3045. voice_send_cvp_deregister_cal_cmd(v);
  3046. else if (cal_type == CVP_VOCDEV_CFG_CAL_TYPE)
  3047. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3048. else if (cal_type == CVS_VOCSTRM_STATIC_CAL_TYPE)
  3049. voice_send_cvs_deregister_cal_cmd(v);
  3050. else
  3051. pr_err("%s: Invalid cal type %d!\n",
  3052. __func__, cal_type);
  3053. result2 = voice_send_start_voice_cmd(v);
  3054. if (result2) {
  3055. pr_err("%s: Voice_send_start_voice_cmd failed for session 0x%x, err %d!\n",
  3056. __func__, v->session_id, result2);
  3057. result = result2;
  3058. }
  3059. }
  3060. if ((cal_block->map_data.q6map_handle != 0) &&
  3061. (!is_other_session_active(v->session_id))) {
  3062. result2 = voice_send_mvm_unmap_memory_physical_cmd(
  3063. v, cal_block->map_data.q6map_handle);
  3064. if (result2) {
  3065. pr_err("%s: Voice_send_mvm_unmap_memory_physical_cmd failed for session 0x%x, err %d!\n",
  3066. __func__, v->session_id, result2);
  3067. result = result2;
  3068. }
  3069. cal_block->map_data.q6map_handle = 0;
  3070. }
  3071. mutex_unlock(&v->lock);
  3072. }
  3073. mutex_unlock(&common.common_lock);
  3074. done:
  3075. return result;
  3076. }
  3077. int voc_register_vocproc_vol_table(void)
  3078. {
  3079. int result = 0;
  3080. int result2 = 0;
  3081. int i;
  3082. struct voice_data *v = NULL;
  3083. pr_debug("%s\n", __func__);
  3084. mutex_lock(&common.common_lock);
  3085. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3086. v = &common.voice[i];
  3087. mutex_lock(&v->lock);
  3088. if (is_voc_state_active(v->voc_state)) {
  3089. result2 = voice_send_cvp_register_vol_cal_cmd(v);
  3090. if (result2 < 0) {
  3091. pr_err("%s: Failed to register vocvol table for session 0x%x!\n",
  3092. __func__, v->session_id);
  3093. result = result2;
  3094. /* Still try to register other sessions */
  3095. }
  3096. }
  3097. mutex_unlock(&v->lock);
  3098. }
  3099. mutex_unlock(&common.common_lock);
  3100. return result;
  3101. }
  3102. int voc_deregister_vocproc_vol_table(void)
  3103. {
  3104. int result = 0;
  3105. int success = 0;
  3106. int i;
  3107. struct voice_data *v = NULL;
  3108. pr_debug("%s\n", __func__);
  3109. mutex_lock(&common.common_lock);
  3110. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3111. v = &common.voice[i];
  3112. mutex_lock(&v->lock);
  3113. if (is_voc_state_active(v->voc_state)) {
  3114. result = voice_send_cvp_deregister_vol_cal_cmd(v);
  3115. if (result < 0) {
  3116. pr_err("%s: Failed to deregister vocvol table for session 0x%x!\n",
  3117. __func__, v->session_id);
  3118. mutex_unlock(&v->lock);
  3119. mutex_unlock(&common.common_lock);
  3120. if (success) {
  3121. pr_err("%s: Try to re-register all deregistered sessions!\n",
  3122. __func__);
  3123. voc_register_vocproc_vol_table();
  3124. }
  3125. goto done;
  3126. } else {
  3127. success = 1;
  3128. }
  3129. }
  3130. mutex_unlock(&v->lock);
  3131. }
  3132. mutex_unlock(&common.common_lock);
  3133. done:
  3134. return result;
  3135. }
  3136. int voc_map_rtac_block(struct rtac_cal_block_data *cal_block)
  3137. {
  3138. int result = 0;
  3139. struct voice_data *v = NULL;
  3140. pr_debug("%s\n", __func__);
  3141. if (cal_block == NULL) {
  3142. pr_err("%s: cal_block is NULL!\n",
  3143. __func__);
  3144. result = -EINVAL;
  3145. goto done;
  3146. }
  3147. if (cal_block->cal_data.paddr == 0) {
  3148. pr_debug("%s: No address to map!\n",
  3149. __func__);
  3150. result = -EINVAL;
  3151. goto done;
  3152. }
  3153. if (cal_block->map_data.map_size == 0) {
  3154. pr_debug("%s: map size is 0!\n",
  3155. __func__);
  3156. result = -EINVAL;
  3157. goto done;
  3158. }
  3159. mutex_lock(&common.common_lock);
  3160. /* use first session */
  3161. v = &common.voice[0];
  3162. mutex_lock(&v->lock);
  3163. if (!is_rtac_memory_allocated()) {
  3164. result = voice_alloc_rtac_mem_map_table();
  3165. if (result < 0) {
  3166. pr_err("%s: RTAC alloc mem map table did not work! addr = 0x%pK, size = %d\n",
  3167. __func__,
  3168. &cal_block->cal_data.paddr,
  3169. cal_block->map_data.map_size);
  3170. goto done_unlock;
  3171. }
  3172. }
  3173. result = voice_map_memory_physical_cmd(v,
  3174. &common.rtac_mem_map_table,
  3175. (dma_addr_t)cal_block->cal_data.paddr,
  3176. cal_block->map_data.map_size,
  3177. VOC_RTAC_MEM_MAP_TOKEN);
  3178. if (result < 0) {
  3179. pr_err("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
  3180. __func__,
  3181. &cal_block->cal_data.paddr,
  3182. cal_block->map_data.map_size);
  3183. free_rtac_map_table();
  3184. goto done_unlock;
  3185. }
  3186. cal_block->map_data.map_handle = common.rtac_mem_handle;
  3187. done_unlock:
  3188. mutex_unlock(&v->lock);
  3189. mutex_unlock(&common.common_lock);
  3190. done:
  3191. return result;
  3192. }
  3193. int voc_unmap_rtac_block(uint32_t *mem_map_handle)
  3194. {
  3195. int result = 0;
  3196. struct voice_data *v = NULL;
  3197. pr_debug("%s\n", __func__);
  3198. if (mem_map_handle == NULL) {
  3199. pr_debug("%s: Map handle is NULL, nothing to unmap\n",
  3200. __func__);
  3201. goto done;
  3202. }
  3203. if (*mem_map_handle == 0) {
  3204. pr_debug("%s: Map handle is 0, nothing to unmap\n",
  3205. __func__);
  3206. goto done;
  3207. }
  3208. mutex_lock(&common.common_lock);
  3209. /* Use first session */
  3210. /* Only used for apr wait lock */
  3211. v = &common.voice[0];
  3212. mutex_lock(&v->lock);
  3213. result = voice_send_mvm_unmap_memory_physical_cmd(
  3214. v, *mem_map_handle);
  3215. if (result) {
  3216. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd Failed for session 0x%x!\n",
  3217. __func__, v->session_id);
  3218. } else {
  3219. *mem_map_handle = 0;
  3220. common.rtac_mem_handle = 0;
  3221. free_rtac_map_table();
  3222. }
  3223. mutex_unlock(&v->lock);
  3224. mutex_unlock(&common.common_lock);
  3225. done:
  3226. return result;
  3227. }
  3228. static int voice_setup_vocproc(struct voice_data *v)
  3229. {
  3230. int ret = 0;
  3231. ret = voice_send_cvp_create_cmd(v);
  3232. if (ret < 0) {
  3233. pr_err("%s: CVP create failed err:%d\n", __func__, ret);
  3234. goto fail;
  3235. }
  3236. ret = voice_send_cvp_media_fmt_info_cmd(v);
  3237. if (ret < 0) {
  3238. pr_err("%s: Set media format info failed err:%d\n", __func__,
  3239. ret);
  3240. goto fail;
  3241. }
  3242. ret = voice_send_cvp_topology_commit_cmd(v);
  3243. if (ret < 0) {
  3244. pr_err("%s: Set topology commit failed err:%d\n",
  3245. __func__, ret);
  3246. goto fail;
  3247. }
  3248. voice_send_cvs_register_cal_cmd(v);
  3249. voice_send_cvp_register_dev_cfg_cmd(v);
  3250. voice_send_cvp_register_cal_cmd(v);
  3251. voice_send_cvp_register_vol_cal_cmd(v);
  3252. /* enable vocproc */
  3253. ret = voice_send_enable_vocproc_cmd(v);
  3254. if (ret < 0)
  3255. goto fail;
  3256. /* attach vocproc */
  3257. ret = voice_send_attach_vocproc_cmd(v);
  3258. if (ret < 0)
  3259. goto fail;
  3260. /* send tty mode if tty device is used */
  3261. voice_send_tty_mode_cmd(v);
  3262. if (is_voip_session(v->session_id)) {
  3263. ret = voice_send_mvm_cal_network_cmd(v);
  3264. if (ret < 0)
  3265. pr_err("%s: voice_send_mvm_cal_network_cmd: %d\n",
  3266. __func__, ret);
  3267. ret = voice_send_mvm_media_type_cmd(v);
  3268. if (ret < 0)
  3269. pr_err("%s: voice_send_mvm_media_type_cmd: %d\n",
  3270. __func__, ret);
  3271. voice_send_netid_timing_cmd(v);
  3272. }
  3273. if (v->st_enable && !v->tty_mode)
  3274. voice_send_set_pp_enable_cmd(v,
  3275. MODULE_ID_VOICE_MODULE_ST,
  3276. v->st_enable);
  3277. /* Start in-call music delivery if this feature is enabled */
  3278. if (v->music_info.play_enable)
  3279. voice_cvs_start_playback(v);
  3280. /* Start in-call recording if this feature is enabled */
  3281. if (v->rec_info.rec_enable)
  3282. voice_cvs_start_record(v, v->rec_info.rec_mode);
  3283. if (v->dtmf_rx_detect_en)
  3284. voice_send_dtmf_rx_detection_cmd(v, v->dtmf_rx_detect_en);
  3285. if (v->hd_enable)
  3286. voice_send_hd_cmd(v, v->hd_enable);
  3287. rtac_add_voice(voice_get_cvs_handle(v),
  3288. voice_get_cvp_handle(v),
  3289. v->dev_rx.port_id, v->dev_tx.port_id,
  3290. v->dev_rx.dev_id, v->dev_tx.dev_id,
  3291. v->session_id);
  3292. return 0;
  3293. fail:
  3294. return ret;
  3295. }
  3296. static int voice_send_cvp_device_channels_cmd(struct voice_data *v)
  3297. {
  3298. int ret = 0;
  3299. struct cvp_set_dev_channels_cmd cvp_set_dev_channels_cmd;
  3300. void *apr_cvp;
  3301. u16 cvp_handle;
  3302. if (!(voice_get_cvd_int_version(common.cvd_version) >=
  3303. CVD_INT_VERSION_2_2)) {
  3304. pr_debug("%s CVD ver %s doesn't support send_device_channels cmd\n",
  3305. __func__, common.cvd_version);
  3306. goto done;
  3307. }
  3308. if (v == NULL) {
  3309. pr_err("%s: v is NULL\n", __func__);
  3310. ret = -EINVAL;
  3311. goto done;
  3312. }
  3313. apr_cvp = common.apr_q6_cvp;
  3314. if (!apr_cvp) {
  3315. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3316. ret = -EINVAL;
  3317. goto done;
  3318. }
  3319. cvp_handle = voice_get_cvp_handle(v);
  3320. cvp_set_dev_channels_cmd.hdr.hdr_field =
  3321. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3322. APR_HDR_LEN(APR_HDR_SIZE),
  3323. APR_PKT_VER);
  3324. cvp_set_dev_channels_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3325. sizeof(cvp_set_dev_channels_cmd) - APR_HDR_SIZE);
  3326. cvp_set_dev_channels_cmd.hdr.src_port =
  3327. voice_get_idx_for_session(v->session_id);
  3328. cvp_set_dev_channels_cmd.hdr.dest_port = cvp_handle;
  3329. cvp_set_dev_channels_cmd.hdr.token = 0;
  3330. cvp_set_dev_channels_cmd.hdr.opcode =
  3331. VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS;
  3332. cvp_set_dev_channels_cmd.cvp_set_channels.rx_num_channels =
  3333. VSS_NUM_DEV_CHANNELS_1;
  3334. cvp_set_dev_channels_cmd.cvp_set_channels.tx_num_channels =
  3335. v->dev_tx.no_of_channels;
  3336. v->cvp_state = CMD_STATUS_FAIL;
  3337. v->async_err = 0;
  3338. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_set_dev_channels_cmd);
  3339. if (ret < 0) {
  3340. pr_err("%s: Fail in sending VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS\n",
  3341. __func__);
  3342. ret = -EINVAL;
  3343. goto done;
  3344. }
  3345. ret = wait_event_timeout(v->cvp_wait,
  3346. (v->cvp_state == CMD_STATUS_SUCCESS),
  3347. msecs_to_jiffies(TIMEOUT_MS));
  3348. if (!ret) {
  3349. pr_err("%s: wait_event timeout\n", __func__);
  3350. ret = -EINVAL;
  3351. goto done;
  3352. }
  3353. if (v->async_err > 0) {
  3354. pr_err("%s: DSP returned error[%s]\n",
  3355. __func__, adsp_err_get_err_str(
  3356. v->async_err));
  3357. ret = adsp_err_get_lnx_err_code(
  3358. v->async_err);
  3359. goto done;
  3360. }
  3361. done:
  3362. return ret;
  3363. }
  3364. static int voice_send_cvp_media_fmt_info_cmd(struct voice_data *v)
  3365. {
  3366. int ret;
  3367. ret = voice_send_cvp_device_channels_cmd(v);
  3368. if (ret < 0)
  3369. goto done;
  3370. if (voice_get_cvd_int_version(common.cvd_version) >=
  3371. CVD_INT_VERSION_2_3) {
  3372. ret = voice_send_cvp_media_format_cmd(v, RX_PATH);
  3373. if (ret < 0)
  3374. goto done;
  3375. ret = voice_send_cvp_media_format_cmd(v, TX_PATH);
  3376. if (ret < 0)
  3377. goto done;
  3378. if (common.ec_ref_ext)
  3379. ret = voice_send_cvp_media_format_cmd(v, EC_REF_PATH);
  3380. }
  3381. done:
  3382. return ret;
  3383. }
  3384. static int voice_send_cvp_media_format_cmd(struct voice_data *v,
  3385. uint32_t param_type)
  3386. {
  3387. int ret = 0;
  3388. struct cvp_set_media_format_cmd cvp_set_media_format_cmd;
  3389. void *apr_cvp;
  3390. u16 cvp_handle;
  3391. struct vss_icommon_param_data_t *media_fmt_param_data =
  3392. &cvp_set_media_format_cmd.cvp_set_param_v2.param_data;
  3393. struct vss_param_endpoint_media_format_info_t *media_fmt_info =
  3394. &media_fmt_param_data->media_format_info;
  3395. if (v == NULL) {
  3396. pr_err("%s: v is NULL\n", __func__);
  3397. ret = -EINVAL;
  3398. goto done;
  3399. }
  3400. apr_cvp = common.apr_q6_cvp;
  3401. if (!apr_cvp) {
  3402. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3403. ret = -EINVAL;
  3404. goto done;
  3405. }
  3406. cvp_handle = voice_get_cvp_handle(v);
  3407. memset(&cvp_set_media_format_cmd, 0, sizeof(cvp_set_media_format_cmd));
  3408. /* Fill header data */
  3409. cvp_set_media_format_cmd.hdr.hdr_field =
  3410. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  3411. APR_PKT_VER);
  3412. cvp_set_media_format_cmd.hdr.pkt_size =
  3413. APR_PKT_SIZE(APR_HDR_SIZE,
  3414. sizeof(cvp_set_media_format_cmd) - APR_HDR_SIZE);
  3415. cvp_set_media_format_cmd.hdr.src_svc = 0;
  3416. cvp_set_media_format_cmd.hdr.src_domain = APR_DOMAIN_APPS;
  3417. cvp_set_media_format_cmd.hdr.src_port =
  3418. voice_get_idx_for_session(v->session_id);
  3419. cvp_set_media_format_cmd.hdr.dest_svc = 0;
  3420. cvp_set_media_format_cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  3421. cvp_set_media_format_cmd.hdr.dest_port = cvp_handle;
  3422. cvp_set_media_format_cmd.hdr.token = VOC_SET_MEDIA_FORMAT_PARAM_TOKEN;
  3423. cvp_set_media_format_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_PARAM_V2;
  3424. /* Fill param data */
  3425. cvp_set_media_format_cmd.cvp_set_param_v2.mem_size =
  3426. sizeof(struct vss_icommon_param_data_t);
  3427. media_fmt_param_data->module_id = VSS_MODULE_CVD_GENERIC;
  3428. media_fmt_param_data->param_size =
  3429. sizeof(struct vss_param_endpoint_media_format_info_t);
  3430. /* Fill device specific data */
  3431. switch (param_type) {
  3432. case RX_PATH:
  3433. media_fmt_param_data->param_id =
  3434. VSS_PARAM_RX_PORT_ENDPOINT_MEDIA_INFO;
  3435. media_fmt_info->port_id = v->dev_rx.port_id;
  3436. media_fmt_info->num_channels = v->dev_rx.no_of_channels;
  3437. media_fmt_info->bits_per_sample = v->dev_rx.bits_per_sample;
  3438. media_fmt_info->sample_rate = v->dev_rx.sample_rate;
  3439. memcpy(&media_fmt_info->channel_mapping,
  3440. &v->dev_rx.channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  3441. break;
  3442. case TX_PATH:
  3443. media_fmt_param_data->param_id =
  3444. VSS_PARAM_TX_PORT_ENDPOINT_MEDIA_INFO;
  3445. media_fmt_info->port_id = v->dev_tx.port_id;
  3446. media_fmt_info->num_channels = v->dev_tx.no_of_channels;
  3447. media_fmt_info->bits_per_sample = v->dev_tx.bits_per_sample;
  3448. media_fmt_info->sample_rate = v->dev_tx.sample_rate;
  3449. memcpy(&media_fmt_info->channel_mapping,
  3450. &v->dev_tx.channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  3451. break;
  3452. case EC_REF_PATH:
  3453. media_fmt_param_data->param_id =
  3454. VSS_PARAM_EC_REF_PORT_ENDPOINT_MEDIA_INFO;
  3455. media_fmt_info->port_id = common.ec_media_fmt_info.port_id;
  3456. media_fmt_info->num_channels =
  3457. common.ec_media_fmt_info.num_channels;
  3458. media_fmt_info->bits_per_sample =
  3459. common.ec_media_fmt_info.bits_per_sample;
  3460. media_fmt_info->sample_rate =
  3461. common.ec_media_fmt_info.sample_rate;
  3462. memcpy(&media_fmt_info->channel_mapping,
  3463. &common.ec_media_fmt_info.channel_mapping,
  3464. VSS_CHANNEL_MAPPING_SIZE);
  3465. break;
  3466. default:
  3467. pr_err("%s: Invalid param type %d\n", __func__, param_type);
  3468. ret = -EINVAL;
  3469. goto done;
  3470. }
  3471. /* Send command */
  3472. v->cvp_state = CMD_STATUS_FAIL;
  3473. v->async_err = 0;
  3474. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_set_media_format_cmd);
  3475. if (ret < 0) {
  3476. pr_err("%s: Fail in sending VSS_ICOMMON_CMD_SET_PARAM_V2\n",
  3477. __func__);
  3478. ret = -EINVAL;
  3479. goto done;
  3480. }
  3481. ret = wait_event_timeout(v->cvp_wait,
  3482. (v->cvp_state == CMD_STATUS_SUCCESS),
  3483. msecs_to_jiffies(TIMEOUT_MS));
  3484. if (!ret) {
  3485. pr_err("%s: wait_event timeout\n", __func__);
  3486. ret = -EINVAL;
  3487. goto done;
  3488. }
  3489. if (v->async_err > 0) {
  3490. pr_err("%s: DSP returned error[%s] handle = %d\n", __func__,
  3491. adsp_err_get_err_str(v->async_err), cvp_handle);
  3492. ret = adsp_err_get_lnx_err_code(v->async_err);
  3493. goto done;
  3494. }
  3495. done:
  3496. return ret;
  3497. }
  3498. static int voice_send_cvp_topology_commit_cmd(struct voice_data *v)
  3499. {
  3500. int ret = 0;
  3501. struct apr_hdr cvp_topology_commit_cmd;
  3502. void *apr_cvp;
  3503. u16 cvp_handle;
  3504. if (!(voice_get_cvd_int_version(common.cvd_version) >=
  3505. CVD_INT_VERSION_2_2)) {
  3506. pr_debug("%s CVD version string %s doesn't support this command\n",
  3507. __func__, common.cvd_version);
  3508. goto done;
  3509. }
  3510. if (v == NULL) {
  3511. pr_err("%s: v is NULL\n", __func__);
  3512. ret = -EINVAL;
  3513. goto done;
  3514. }
  3515. apr_cvp = common.apr_q6_cvp;
  3516. if (!apr_cvp) {
  3517. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3518. ret = -EINVAL;
  3519. goto done;
  3520. }
  3521. cvp_handle = voice_get_cvp_handle(v);
  3522. cvp_topology_commit_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3523. APR_HDR_LEN(APR_HDR_SIZE),
  3524. APR_PKT_VER);
  3525. cvp_topology_commit_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3526. sizeof(cvp_topology_commit_cmd) - APR_HDR_SIZE);
  3527. cvp_topology_commit_cmd.src_port =
  3528. voice_get_idx_for_session(v->session_id);
  3529. cvp_topology_commit_cmd.dest_port = cvp_handle;
  3530. cvp_topology_commit_cmd.token = 0;
  3531. cvp_topology_commit_cmd.opcode = VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT;
  3532. v->cvp_state = CMD_STATUS_FAIL;
  3533. v->async_err = 0;
  3534. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_topology_commit_cmd);
  3535. if (ret < 0) {
  3536. pr_err("%s: Fail in sending VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT\n",
  3537. __func__);
  3538. ret = -EINVAL;
  3539. goto done;
  3540. }
  3541. ret = wait_event_timeout(v->cvp_wait,
  3542. (v->cvp_state == CMD_STATUS_SUCCESS),
  3543. msecs_to_jiffies(TIMEOUT_MS));
  3544. if (!ret) {
  3545. pr_err("%s: wait_event timeout\n", __func__);
  3546. ret = -EINVAL;
  3547. goto done;
  3548. }
  3549. if (v->async_err > 0) {
  3550. pr_err("%s: DSP returned error[%s]\n",
  3551. __func__, adsp_err_get_err_str(
  3552. v->async_err));
  3553. ret = adsp_err_get_lnx_err_code(
  3554. v->async_err);
  3555. goto done;
  3556. }
  3557. done:
  3558. return ret;
  3559. }
  3560. static int voice_send_enable_vocproc_cmd(struct voice_data *v)
  3561. {
  3562. int ret = 0;
  3563. struct apr_hdr cvp_enable_cmd;
  3564. void *apr_cvp;
  3565. u16 cvp_handle;
  3566. if (v == NULL) {
  3567. pr_err("%s: v is NULL\n", __func__);
  3568. return -EINVAL;
  3569. }
  3570. apr_cvp = common.apr_q6_cvp;
  3571. if (!apr_cvp) {
  3572. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3573. return -EINVAL;
  3574. }
  3575. cvp_handle = voice_get_cvp_handle(v);
  3576. /* enable vocproc and wait for respose */
  3577. cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3578. APR_HDR_LEN(APR_HDR_SIZE),
  3579. APR_PKT_VER);
  3580. cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3581. sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
  3582. pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
  3583. cvp_enable_cmd.pkt_size, cvp_handle);
  3584. cvp_enable_cmd.src_port =
  3585. voice_get_idx_for_session(v->session_id);
  3586. cvp_enable_cmd.dest_port = cvp_handle;
  3587. cvp_enable_cmd.token = 0;
  3588. cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
  3589. v->cvp_state = CMD_STATUS_FAIL;
  3590. v->async_err = 0;
  3591. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
  3592. if (ret < 0) {
  3593. pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
  3594. goto fail;
  3595. }
  3596. ret = wait_event_timeout(v->cvp_wait,
  3597. (v->cvp_state == CMD_STATUS_SUCCESS),
  3598. msecs_to_jiffies(TIMEOUT_MS));
  3599. if (!ret) {
  3600. pr_err("%s: wait_event timeout\n", __func__);
  3601. goto fail;
  3602. }
  3603. if (v->async_err > 0) {
  3604. pr_err("%s: DSP returned error[%s]\n",
  3605. __func__, adsp_err_get_err_str(
  3606. v->async_err));
  3607. ret = adsp_err_get_lnx_err_code(
  3608. v->async_err);
  3609. goto fail;
  3610. }
  3611. return 0;
  3612. fail:
  3613. return ret;
  3614. }
  3615. static int voice_send_mvm_cal_network_cmd(struct voice_data *v)
  3616. {
  3617. struct vss_imvm_cmd_set_cal_network_t mvm_set_cal_network;
  3618. int ret = 0;
  3619. void *apr_mvm;
  3620. u16 mvm_handle;
  3621. if (v == NULL) {
  3622. pr_err("%s: v is NULL\n", __func__);
  3623. return -EINVAL;
  3624. }
  3625. apr_mvm = common.apr_q6_mvm;
  3626. if (!apr_mvm) {
  3627. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3628. return -EINVAL;
  3629. }
  3630. mvm_handle = voice_get_mvm_handle(v);
  3631. mvm_set_cal_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3632. APR_HDR_LEN(APR_HDR_SIZE),
  3633. APR_PKT_VER);
  3634. mvm_set_cal_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3635. sizeof(mvm_set_cal_network) - APR_HDR_SIZE);
  3636. mvm_set_cal_network.hdr.src_port =
  3637. voice_get_idx_for_session(v->session_id);
  3638. mvm_set_cal_network.hdr.dest_port = mvm_handle;
  3639. mvm_set_cal_network.hdr.token = 0;
  3640. mvm_set_cal_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  3641. mvm_set_cal_network.network_id = VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  3642. v->mvm_state = CMD_STATUS_FAIL;
  3643. v->async_err = 0;
  3644. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_network);
  3645. if (ret < 0) {
  3646. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  3647. goto fail;
  3648. }
  3649. ret = wait_event_timeout(v->mvm_wait,
  3650. (v->mvm_state == CMD_STATUS_SUCCESS),
  3651. msecs_to_jiffies(TIMEOUT_MS));
  3652. if (!ret) {
  3653. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3654. goto fail;
  3655. }
  3656. if (v->async_err > 0) {
  3657. pr_err("%s: DSP returned error[%s]\n",
  3658. __func__, adsp_err_get_err_str(
  3659. v->async_err));
  3660. ret = adsp_err_get_lnx_err_code(
  3661. v->async_err);
  3662. goto fail;
  3663. }
  3664. return 0;
  3665. fail:
  3666. return ret;
  3667. }
  3668. static int voice_send_netid_timing_cmd(struct voice_data *v)
  3669. {
  3670. int ret = 0;
  3671. void *apr_mvm;
  3672. u16 mvm_handle;
  3673. struct mvm_set_network_cmd mvm_set_network;
  3674. struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
  3675. if (v == NULL) {
  3676. pr_err("%s: v is NULL\n", __func__);
  3677. return -EINVAL;
  3678. }
  3679. apr_mvm = common.apr_q6_mvm;
  3680. if (!apr_mvm) {
  3681. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3682. return -EINVAL;
  3683. }
  3684. mvm_handle = voice_get_mvm_handle(v);
  3685. ret = voice_config_cvs_vocoder(v);
  3686. if (ret < 0) {
  3687. pr_err("%s: Error %d configuring CVS voc",
  3688. __func__, ret);
  3689. goto fail;
  3690. }
  3691. /* Set network ID. */
  3692. pr_debug("Setting network ID %x\n", common.mvs_info.network_type);
  3693. mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3694. APR_HDR_LEN(APR_HDR_SIZE),
  3695. APR_PKT_VER);
  3696. mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3697. sizeof(mvm_set_network) - APR_HDR_SIZE);
  3698. mvm_set_network.hdr.src_port =
  3699. voice_get_idx_for_session(v->session_id);
  3700. mvm_set_network.hdr.dest_port = mvm_handle;
  3701. mvm_set_network.hdr.token = 0;
  3702. mvm_set_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  3703. mvm_set_network.network.network_id = common.mvs_info.network_type;
  3704. v->mvm_state = CMD_STATUS_FAIL;
  3705. v->async_err = 0;
  3706. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
  3707. if (ret < 0) {
  3708. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  3709. goto fail;
  3710. }
  3711. ret = wait_event_timeout(v->mvm_wait,
  3712. (v->mvm_state == CMD_STATUS_SUCCESS),
  3713. msecs_to_jiffies(TIMEOUT_MS));
  3714. if (!ret) {
  3715. pr_err("%s: wait_event timeout\n", __func__);
  3716. goto fail;
  3717. }
  3718. if (v->async_err > 0) {
  3719. pr_err("%s: DSP returned error[%s]\n",
  3720. __func__, adsp_err_get_err_str(
  3721. v->async_err));
  3722. ret = adsp_err_get_lnx_err_code(
  3723. v->async_err);
  3724. goto fail;
  3725. }
  3726. /* Set voice timing. */
  3727. pr_debug("Setting voice timing\n");
  3728. mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3729. APR_HDR_LEN(APR_HDR_SIZE),
  3730. APR_PKT_VER);
  3731. mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3732. sizeof(mvm_set_voice_timing) -
  3733. APR_HDR_SIZE);
  3734. mvm_set_voice_timing.hdr.src_port =
  3735. voice_get_idx_for_session(v->session_id);
  3736. mvm_set_voice_timing.hdr.dest_port = mvm_handle;
  3737. mvm_set_voice_timing.hdr.token = 0;
  3738. mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
  3739. mvm_set_voice_timing.timing.mode = 0;
  3740. mvm_set_voice_timing.timing.enc_offset = 8000;
  3741. mvm_set_voice_timing.timing.dec_req_offset = 3300;
  3742. mvm_set_voice_timing.timing.dec_offset = 8300;
  3743. v->mvm_state = CMD_STATUS_FAIL;
  3744. v->async_err = 0;
  3745. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
  3746. if (ret < 0) {
  3747. pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
  3748. goto fail;
  3749. }
  3750. ret = wait_event_timeout(v->mvm_wait,
  3751. (v->mvm_state == CMD_STATUS_SUCCESS),
  3752. msecs_to_jiffies(TIMEOUT_MS));
  3753. if (!ret) {
  3754. pr_err("%s: wait_event timeout\n", __func__);
  3755. goto fail;
  3756. }
  3757. if (v->async_err > 0) {
  3758. pr_err("%s: DSP returned error[%s]\n",
  3759. __func__, adsp_err_get_err_str(
  3760. v->async_err));
  3761. ret = adsp_err_get_lnx_err_code(
  3762. v->async_err);
  3763. goto fail;
  3764. }
  3765. return 0;
  3766. fail:
  3767. return ret;
  3768. }
  3769. static int voice_send_attach_vocproc_cmd(struct voice_data *v)
  3770. {
  3771. int ret = 0;
  3772. struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
  3773. void *apr_mvm;
  3774. u16 mvm_handle, cvp_handle;
  3775. if (v == NULL) {
  3776. pr_err("%s: v is NULL\n", __func__);
  3777. return -EINVAL;
  3778. }
  3779. apr_mvm = common.apr_q6_mvm;
  3780. if (!apr_mvm) {
  3781. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3782. return -EINVAL;
  3783. }
  3784. mvm_handle = voice_get_mvm_handle(v);
  3785. cvp_handle = voice_get_cvp_handle(v);
  3786. /* attach vocproc and wait for response */
  3787. mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3788. APR_HDR_LEN(APR_HDR_SIZE),
  3789. APR_PKT_VER);
  3790. mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3791. sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
  3792. pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
  3793. mvm_a_vocproc_cmd.hdr.pkt_size);
  3794. mvm_a_vocproc_cmd.hdr.src_port =
  3795. voice_get_idx_for_session(v->session_id);
  3796. mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
  3797. mvm_a_vocproc_cmd.hdr.token = 0;
  3798. mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
  3799. mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
  3800. v->mvm_state = CMD_STATUS_FAIL;
  3801. v->async_err = 0;
  3802. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
  3803. if (ret < 0) {
  3804. pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
  3805. goto fail;
  3806. }
  3807. ret = wait_event_timeout(v->mvm_wait,
  3808. (v->mvm_state == CMD_STATUS_SUCCESS),
  3809. msecs_to_jiffies(TIMEOUT_MS));
  3810. if (!ret) {
  3811. pr_err("%s: wait_event timeout\n", __func__);
  3812. goto fail;
  3813. }
  3814. if (v->async_err > 0) {
  3815. pr_err("%s: DSP returned error[%s]\n",
  3816. __func__, adsp_err_get_err_str(
  3817. v->async_err));
  3818. ret = adsp_err_get_lnx_err_code(
  3819. v->async_err);
  3820. goto fail;
  3821. }
  3822. return 0;
  3823. fail:
  3824. return ret;
  3825. }
  3826. static void voc_update_session_params(struct voice_data *v)
  3827. {
  3828. /* reset LCH mode */
  3829. v->lch_mode = 0;
  3830. /* clear disable topology setting */
  3831. v->disable_topology = false;
  3832. /* clear mute setting */
  3833. v->dev_rx.dev_mute = common.default_mute_val;
  3834. v->dev_tx.dev_mute = common.default_mute_val;
  3835. v->stream_rx.stream_mute = common.default_mute_val;
  3836. v->stream_tx.stream_mute = common.default_mute_val;
  3837. }
  3838. static int voice_destroy_vocproc(struct voice_data *v)
  3839. {
  3840. struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
  3841. struct apr_hdr cvp_destroy_session_cmd;
  3842. int ret = 0;
  3843. void *apr_mvm, *apr_cvp;
  3844. u16 mvm_handle, cvp_handle;
  3845. if (v == NULL) {
  3846. pr_err("%s: v is NULL\n", __func__);
  3847. return -EINVAL;
  3848. }
  3849. apr_mvm = common.apr_q6_mvm;
  3850. apr_cvp = common.apr_q6_cvp;
  3851. if (!apr_mvm || !apr_cvp) {
  3852. pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
  3853. return -EINVAL;
  3854. }
  3855. mvm_handle = voice_get_mvm_handle(v);
  3856. cvp_handle = voice_get_cvp_handle(v);
  3857. /* disable slowtalk if st_enable is set */
  3858. if (v->st_enable)
  3859. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_ST, 0);
  3860. /* Disable HD Voice if hd_enable is set */
  3861. if (v->hd_enable)
  3862. voice_send_hd_cmd(v, 0);
  3863. /* stop playback or recording */
  3864. v->music_info.force = 1;
  3865. voice_cvs_stop_playback(v);
  3866. voice_cvs_stop_record(v);
  3867. /* If voice call is active during VoLTE, SRVCC happens.
  3868. * Start recording on voice session if recording started during VoLTE.
  3869. */
  3870. if (is_volte_session(v->session_id) &&
  3871. ((common.voice[VOC_PATH_PASSIVE].voc_state == VOC_RUN) ||
  3872. (common.voice[VOC_PATH_PASSIVE].voc_state == VOC_CHANGE))) {
  3873. if (v->rec_info.rec_enable) {
  3874. voice_cvs_start_record(
  3875. &common.voice[VOC_PATH_PASSIVE],
  3876. v->rec_info.rec_mode);
  3877. common.srvcc_rec_flag = true;
  3878. pr_debug("%s: switch recording, srvcc_rec_flag %d\n",
  3879. __func__, common.srvcc_rec_flag);
  3880. }
  3881. }
  3882. /* send stop voice cmd */
  3883. voice_send_stop_voice_cmd(v);
  3884. /* send stop dtmf detecton cmd */
  3885. if (v->dtmf_rx_detect_en)
  3886. voice_send_dtmf_rx_detection_cmd(v, 0);
  3887. /* detach VOCPROC and wait for response from mvm */
  3888. mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3889. APR_HDR_LEN(APR_HDR_SIZE),
  3890. APR_PKT_VER);
  3891. mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3892. sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
  3893. pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
  3894. mvm_d_vocproc_cmd.hdr.pkt_size);
  3895. mvm_d_vocproc_cmd.hdr.src_port =
  3896. voice_get_idx_for_session(v->session_id);
  3897. mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
  3898. mvm_d_vocproc_cmd.hdr.token = 0;
  3899. mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
  3900. mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
  3901. v->mvm_state = CMD_STATUS_FAIL;
  3902. v->async_err = 0;
  3903. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
  3904. if (ret < 0) {
  3905. pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
  3906. goto fail;
  3907. }
  3908. ret = wait_event_timeout(v->mvm_wait,
  3909. (v->mvm_state == CMD_STATUS_SUCCESS),
  3910. msecs_to_jiffies(TIMEOUT_MS));
  3911. if (!ret) {
  3912. pr_err("%s: wait_event timeout\n", __func__);
  3913. goto fail;
  3914. }
  3915. if (v->async_err > 0) {
  3916. pr_err("%s: DSP returned error[%s]\n",
  3917. __func__, adsp_err_get_err_str(
  3918. v->async_err));
  3919. ret = adsp_err_get_lnx_err_code(
  3920. v->async_err);
  3921. goto fail;
  3922. }
  3923. voice_send_cvp_deregister_vol_cal_cmd(v);
  3924. voice_send_cvp_deregister_cal_cmd(v);
  3925. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3926. voice_send_cvs_deregister_cal_cmd(v);
  3927. /* destrop cvp session */
  3928. cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3929. APR_HDR_LEN(APR_HDR_SIZE),
  3930. APR_PKT_VER);
  3931. cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3932. sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
  3933. pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
  3934. cvp_destroy_session_cmd.pkt_size);
  3935. cvp_destroy_session_cmd.src_port =
  3936. voice_get_idx_for_session(v->session_id);
  3937. cvp_destroy_session_cmd.dest_port = cvp_handle;
  3938. cvp_destroy_session_cmd.token = 0;
  3939. cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  3940. v->cvp_state = CMD_STATUS_FAIL;
  3941. v->async_err = 0;
  3942. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
  3943. if (ret < 0) {
  3944. pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
  3945. goto fail;
  3946. }
  3947. ret = wait_event_timeout(v->cvp_wait,
  3948. (v->cvp_state == CMD_STATUS_SUCCESS),
  3949. msecs_to_jiffies(TIMEOUT_MS));
  3950. if (!ret) {
  3951. pr_err("%s: wait_event timeout\n", __func__);
  3952. goto fail;
  3953. }
  3954. if (v->async_err > 0) {
  3955. pr_err("%s: DSP returned error[%s]\n",
  3956. __func__, adsp_err_get_err_str(
  3957. v->async_err));
  3958. ret = adsp_err_get_lnx_err_code(
  3959. v->async_err);
  3960. goto fail;
  3961. }
  3962. rtac_remove_voice(voice_get_cvs_handle(v));
  3963. cvp_handle = 0;
  3964. voice_set_cvp_handle(v, cvp_handle);
  3965. return 0;
  3966. fail:
  3967. return ret;
  3968. }
  3969. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  3970. uint32_t mem_handle)
  3971. {
  3972. struct vss_imemory_cmd_unmap_t mem_unmap;
  3973. int ret = 0;
  3974. void *apr_mvm;
  3975. u16 mvm_handle;
  3976. if (v == NULL) {
  3977. pr_err("%s: v is NULL\n", __func__);
  3978. return -EINVAL;
  3979. }
  3980. apr_mvm = common.apr_q6_mvm;
  3981. if (!apr_mvm) {
  3982. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3983. return -EINVAL;
  3984. }
  3985. mvm_handle = voice_get_mvm_handle(v);
  3986. mem_unmap.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3987. APR_HDR_LEN(APR_HDR_SIZE),
  3988. APR_PKT_VER);
  3989. mem_unmap.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3990. sizeof(mem_unmap) - APR_HDR_SIZE);
  3991. mem_unmap.hdr.src_port =
  3992. voice_get_idx_for_session(v->session_id);
  3993. mem_unmap.hdr.dest_port = mvm_handle;
  3994. mem_unmap.hdr.token = 0;
  3995. mem_unmap.hdr.opcode = VSS_IMEMORY_CMD_UNMAP;
  3996. mem_unmap.mem_handle = mem_handle;
  3997. pr_debug("%s: mem_handle: 0x%x\n", __func__, mem_unmap.mem_handle);
  3998. v->mvm_state = CMD_STATUS_FAIL;
  3999. v->async_err = 0;
  4000. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mem_unmap);
  4001. if (ret < 0) {
  4002. pr_err("mem_unmap op[0x%x]ret[%d]\n",
  4003. mem_unmap.hdr.opcode, ret);
  4004. goto fail;
  4005. }
  4006. ret = wait_event_timeout(v->mvm_wait,
  4007. (v->mvm_state == CMD_STATUS_SUCCESS),
  4008. msecs_to_jiffies(TIMEOUT_MS));
  4009. if (!ret) {
  4010. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4011. goto fail;
  4012. }
  4013. if (v->async_err > 0) {
  4014. pr_err("%s: DSP returned error[%s]\n",
  4015. __func__, adsp_err_get_err_str(
  4016. v->async_err));
  4017. ret = adsp_err_get_lnx_err_code(
  4018. v->async_err);
  4019. goto fail;
  4020. }
  4021. return 0;
  4022. fail:
  4023. return ret;
  4024. }
  4025. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v)
  4026. {
  4027. struct vss_istream_cmd_set_oob_packet_exchange_config_t
  4028. packet_exchange_config_pkt;
  4029. int ret = 0;
  4030. void *apr_cvs;
  4031. u16 cvs_handle;
  4032. if (v == NULL) {
  4033. pr_err("%s: v is NULL\n", __func__);
  4034. return -EINVAL;
  4035. }
  4036. apr_cvs = common.apr_q6_cvs;
  4037. if (!apr_cvs) {
  4038. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4039. return -EINVAL;
  4040. }
  4041. cvs_handle = voice_get_cvs_handle(v);
  4042. packet_exchange_config_pkt.hdr.hdr_field = APR_HDR_FIELD(
  4043. APR_MSG_TYPE_SEQ_CMD,
  4044. APR_HDR_LEN(APR_HDR_SIZE),
  4045. APR_PKT_VER);
  4046. packet_exchange_config_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4047. sizeof(packet_exchange_config_pkt) -
  4048. APR_HDR_SIZE);
  4049. packet_exchange_config_pkt.hdr.src_port =
  4050. voice_get_idx_for_session(v->session_id);
  4051. packet_exchange_config_pkt.hdr.dest_port = cvs_handle;
  4052. packet_exchange_config_pkt.hdr.token = 0;
  4053. packet_exchange_config_pkt.hdr.opcode =
  4054. VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG;
  4055. packet_exchange_config_pkt.mem_handle = v->shmem_info.mem_handle;
  4056. /* dec buffer address */
  4057. packet_exchange_config_pkt.dec_buf_addr_lsw =
  4058. lower_32_bits(v->shmem_info.sh_buf.buf[0].phys);
  4059. packet_exchange_config_pkt.dec_buf_addr_msw =
  4060. msm_audio_populate_upper_32_bits(
  4061. v->shmem_info.sh_buf.buf[0].phys);
  4062. packet_exchange_config_pkt.dec_buf_size = 4096;
  4063. /* enc buffer address */
  4064. packet_exchange_config_pkt.enc_buf_addr_lsw =
  4065. lower_32_bits(v->shmem_info.sh_buf.buf[1].phys);
  4066. packet_exchange_config_pkt.enc_buf_addr_msw =
  4067. msm_audio_populate_upper_32_bits(
  4068. v->shmem_info.sh_buf.buf[1].phys);
  4069. packet_exchange_config_pkt.enc_buf_size = 4096;
  4070. pr_debug("%s: dec buf add: lsw %0x msw %0x, size %d, enc buf add: lsw %0x msw %0x, size %d\n",
  4071. __func__,
  4072. packet_exchange_config_pkt.dec_buf_addr_lsw,
  4073. packet_exchange_config_pkt.dec_buf_addr_msw,
  4074. packet_exchange_config_pkt.dec_buf_size,
  4075. packet_exchange_config_pkt.enc_buf_addr_lsw,
  4076. packet_exchange_config_pkt.enc_buf_addr_msw,
  4077. packet_exchange_config_pkt.enc_buf_size);
  4078. v->cvs_state = CMD_STATUS_FAIL;
  4079. v->async_err = 0;
  4080. ret = apr_send_pkt(apr_cvs, (uint32_t *) &packet_exchange_config_pkt);
  4081. if (ret < 0) {
  4082. pr_err("Failed to send packet exchange config cmd %d\n", ret);
  4083. goto fail;
  4084. }
  4085. ret = wait_event_timeout(v->cvs_wait,
  4086. (v->cvs_state == CMD_STATUS_SUCCESS),
  4087. msecs_to_jiffies(TIMEOUT_MS));
  4088. if (!ret)
  4089. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4090. if (v->async_err > 0) {
  4091. pr_err("%s: DSP returned error[%s]\n",
  4092. __func__, adsp_err_get_err_str(
  4093. v->async_err));
  4094. ret = adsp_err_get_lnx_err_code(
  4095. v->async_err);
  4096. goto fail;
  4097. }
  4098. return 0;
  4099. fail:
  4100. return ret;
  4101. }
  4102. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v)
  4103. {
  4104. struct vss_istream_cmd_set_packet_exchange_mode_t data_exchange_pkt;
  4105. int ret = 0;
  4106. void *apr_cvs;
  4107. u16 cvs_handle;
  4108. if (v == NULL) {
  4109. pr_err("%s: v is NULL\n", __func__);
  4110. return -EINVAL;
  4111. }
  4112. apr_cvs = common.apr_q6_cvs;
  4113. if (!apr_cvs) {
  4114. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4115. return -EINVAL;
  4116. }
  4117. cvs_handle = voice_get_cvs_handle(v);
  4118. data_exchange_pkt.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4119. APR_HDR_LEN(APR_HDR_SIZE),
  4120. APR_PKT_VER);
  4121. data_exchange_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4122. sizeof(data_exchange_pkt) - APR_HDR_SIZE);
  4123. data_exchange_pkt.hdr.src_port =
  4124. voice_get_idx_for_session(v->session_id);
  4125. data_exchange_pkt.hdr.dest_port = cvs_handle;
  4126. data_exchange_pkt.hdr.token = 0;
  4127. data_exchange_pkt.hdr.opcode = VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE;
  4128. data_exchange_pkt.mode = VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND;
  4129. v->cvs_state = CMD_STATUS_FAIL;
  4130. v->async_err = 0;
  4131. ret = apr_send_pkt(apr_cvs, (uint32_t *) &data_exchange_pkt);
  4132. if (ret < 0) {
  4133. pr_err("Failed to send data exchange mode %d\n", ret);
  4134. goto fail;
  4135. }
  4136. ret = wait_event_timeout(v->cvs_wait,
  4137. (v->cvs_state == CMD_STATUS_SUCCESS),
  4138. msecs_to_jiffies(TIMEOUT_MS));
  4139. if (!ret)
  4140. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4141. if (v->async_err > 0) {
  4142. pr_err("%s: DSP returned error[%s]\n",
  4143. __func__, adsp_err_get_err_str(
  4144. v->async_err));
  4145. ret = adsp_err_get_lnx_err_code(
  4146. v->async_err);
  4147. goto fail;
  4148. }
  4149. return 0;
  4150. fail:
  4151. return ret;
  4152. }
  4153. static int voice_send_stream_mute_cmd(struct voice_data *v, uint16_t direction,
  4154. uint16_t mute_flag, uint32_t ramp_duration)
  4155. {
  4156. struct cvs_set_mute_cmd cvs_mute_cmd;
  4157. int ret = 0;
  4158. if (v == NULL) {
  4159. pr_err("%s: v is NULL\n", __func__);
  4160. ret = -EINVAL;
  4161. goto fail;
  4162. }
  4163. if (!common.apr_q6_cvs) {
  4164. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4165. ret = -EINVAL;
  4166. goto fail;
  4167. }
  4168. /* send mute/unmute to cvs */
  4169. cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4170. APR_HDR_LEN(APR_HDR_SIZE),
  4171. APR_PKT_VER);
  4172. cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4173. sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
  4174. cvs_mute_cmd.hdr.src_port =
  4175. voice_get_idx_for_session(v->session_id);
  4176. cvs_mute_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  4177. cvs_mute_cmd.hdr.token = 0;
  4178. cvs_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  4179. cvs_mute_cmd.cvs_set_mute.direction = direction;
  4180. cvs_mute_cmd.cvs_set_mute.mute_flag = mute_flag;
  4181. cvs_mute_cmd.cvs_set_mute.ramp_duration_ms = ramp_duration;
  4182. v->cvs_state = CMD_STATUS_FAIL;
  4183. v->async_err = 0;
  4184. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_mute_cmd);
  4185. if (ret < 0) {
  4186. pr_err("%s: Error %d sending stream mute\n", __func__, ret);
  4187. goto fail;
  4188. }
  4189. ret = wait_event_timeout(v->cvs_wait,
  4190. (v->cvs_state == CMD_STATUS_SUCCESS),
  4191. msecs_to_jiffies(TIMEOUT_MS));
  4192. if (!ret) {
  4193. pr_err("%s: Command timeout\n", __func__);
  4194. goto fail;
  4195. }
  4196. if (v->async_err > 0) {
  4197. pr_err("%s: DSP returned error[%s]\n",
  4198. __func__, adsp_err_get_err_str(
  4199. v->async_err));
  4200. ret = adsp_err_get_lnx_err_code(
  4201. v->async_err);
  4202. goto fail;
  4203. }
  4204. return 0;
  4205. fail:
  4206. return ret;
  4207. }
  4208. static int voice_send_device_mute_cmd(struct voice_data *v, uint16_t direction,
  4209. uint16_t mute_flag, uint32_t ramp_duration)
  4210. {
  4211. struct cvp_set_mute_cmd cvp_mute_cmd;
  4212. int ret = 0;
  4213. if (v == NULL) {
  4214. pr_err("%s: v is NULL\n", __func__);
  4215. ret = -EINVAL;
  4216. goto fail;
  4217. }
  4218. if (!common.apr_q6_cvp) {
  4219. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4220. ret = -EINVAL;
  4221. goto fail;
  4222. }
  4223. cvp_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4224. APR_HDR_LEN(APR_HDR_SIZE),
  4225. APR_PKT_VER);
  4226. cvp_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4227. sizeof(cvp_mute_cmd) - APR_HDR_SIZE);
  4228. cvp_mute_cmd.hdr.src_port =
  4229. voice_get_idx_for_session(v->session_id);
  4230. cvp_mute_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  4231. cvp_mute_cmd.hdr.token = 0;
  4232. cvp_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  4233. cvp_mute_cmd.cvp_set_mute.direction = direction;
  4234. cvp_mute_cmd.cvp_set_mute.mute_flag = mute_flag;
  4235. cvp_mute_cmd.cvp_set_mute.ramp_duration_ms = ramp_duration;
  4236. v->cvp_state = CMD_STATUS_FAIL;
  4237. v->async_err = 0;
  4238. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_mute_cmd);
  4239. if (ret < 0) {
  4240. pr_err("%s: Error %d sending rx device cmd\n", __func__, ret);
  4241. goto fail;
  4242. }
  4243. ret = wait_event_timeout(v->cvp_wait,
  4244. (v->cvp_state == CMD_STATUS_SUCCESS),
  4245. msecs_to_jiffies(TIMEOUT_MS));
  4246. if (!ret) {
  4247. pr_err("%s: Command timeout\n", __func__);
  4248. goto fail;
  4249. }
  4250. if (v->async_err > 0) {
  4251. pr_err("%s: DSP returned error[%s]\n",
  4252. __func__, adsp_err_get_err_str(
  4253. v->async_err));
  4254. ret = adsp_err_get_lnx_err_code(
  4255. v->async_err);
  4256. goto fail;
  4257. }
  4258. return 0;
  4259. fail:
  4260. return ret;
  4261. }
  4262. static int voice_send_vol_step_cmd(struct voice_data *v)
  4263. {
  4264. struct cvp_set_rx_volume_step_cmd cvp_vol_step_cmd;
  4265. int ret = 0;
  4266. void *apr_cvp;
  4267. u16 cvp_handle;
  4268. if (v == NULL) {
  4269. pr_err("%s: v is NULL\n", __func__);
  4270. return -EINVAL;
  4271. }
  4272. apr_cvp = common.apr_q6_cvp;
  4273. if (!apr_cvp) {
  4274. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4275. return -EINVAL;
  4276. }
  4277. cvp_handle = voice_get_cvp_handle(v);
  4278. /* send volume index to cvp */
  4279. cvp_vol_step_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4280. APR_HDR_LEN(APR_HDR_SIZE),
  4281. APR_PKT_VER);
  4282. cvp_vol_step_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4283. sizeof(cvp_vol_step_cmd) - APR_HDR_SIZE);
  4284. cvp_vol_step_cmd.hdr.src_port =
  4285. voice_get_idx_for_session(v->session_id);
  4286. cvp_vol_step_cmd.hdr.dest_port = cvp_handle;
  4287. cvp_vol_step_cmd.hdr.token = 0;
  4288. cvp_vol_step_cmd.hdr.opcode = VSS_IVOLUME_CMD_SET_STEP;
  4289. cvp_vol_step_cmd.cvp_set_vol_step.direction = VSS_IVOLUME_DIRECTION_RX;
  4290. cvp_vol_step_cmd.cvp_set_vol_step.value = v->dev_rx.volume_step_value;
  4291. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms =
  4292. v->dev_rx.volume_ramp_duration_ms;
  4293. pr_debug("%s step_value:%d, ramp_duration_ms:%d",
  4294. __func__,
  4295. cvp_vol_step_cmd.cvp_set_vol_step.value,
  4296. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms);
  4297. v->cvp_state = CMD_STATUS_FAIL;
  4298. v->async_err = 0;
  4299. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_step_cmd);
  4300. if (ret < 0) {
  4301. pr_err("Fail in sending RX VOL step\n");
  4302. return -EINVAL;
  4303. }
  4304. ret = wait_event_timeout(v->cvp_wait,
  4305. (v->cvp_state == CMD_STATUS_SUCCESS),
  4306. msecs_to_jiffies(TIMEOUT_MS));
  4307. if (!ret) {
  4308. pr_err("%s: wait_event timeout\n", __func__);
  4309. return -EINVAL;
  4310. }
  4311. if (v->async_err > 0) {
  4312. pr_err("%s: DSP returned error[%s]\n",
  4313. __func__, adsp_err_get_err_str(
  4314. v->async_err));
  4315. ret = adsp_err_get_lnx_err_code(
  4316. v->async_err);
  4317. return ret;
  4318. }
  4319. return 0;
  4320. }
  4321. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode)
  4322. {
  4323. int ret = 0;
  4324. void *apr_cvs;
  4325. u16 cvs_handle;
  4326. struct cvs_start_record_cmd cvs_start_record;
  4327. if (v == NULL) {
  4328. pr_err("%s: v is NULL\n", __func__);
  4329. return -EINVAL;
  4330. }
  4331. apr_cvs = common.apr_q6_cvs;
  4332. if (!apr_cvs) {
  4333. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4334. return -EINVAL;
  4335. }
  4336. cvs_handle = voice_get_cvs_handle(v);
  4337. if (!v->rec_info.recording) {
  4338. cvs_start_record.hdr.hdr_field = APR_HDR_FIELD(
  4339. APR_MSG_TYPE_SEQ_CMD,
  4340. APR_HDR_LEN(APR_HDR_SIZE),
  4341. APR_PKT_VER);
  4342. cvs_start_record.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4343. sizeof(cvs_start_record) - APR_HDR_SIZE);
  4344. cvs_start_record.hdr.src_port =
  4345. voice_get_idx_for_session(v->session_id);
  4346. cvs_start_record.hdr.dest_port = cvs_handle;
  4347. cvs_start_record.hdr.token = 0;
  4348. cvs_start_record.hdr.opcode = VSS_IRECORD_CMD_START;
  4349. cvs_start_record.rec_mode.port_id =
  4350. VSS_IRECORD_PORT_ID_DEFAULT;
  4351. if (rec_mode == VOC_REC_UPLINK) {
  4352. cvs_start_record.rec_mode.rx_tap_point =
  4353. VSS_IRECORD_TAP_POINT_NONE;
  4354. cvs_start_record.rec_mode.tx_tap_point =
  4355. VSS_IRECORD_TAP_POINT_STREAM_END;
  4356. } else if (rec_mode == VOC_REC_DOWNLINK) {
  4357. cvs_start_record.rec_mode.rx_tap_point =
  4358. VSS_IRECORD_TAP_POINT_STREAM_END;
  4359. cvs_start_record.rec_mode.tx_tap_point =
  4360. VSS_IRECORD_TAP_POINT_NONE;
  4361. } else if (rec_mode == VOC_REC_BOTH) {
  4362. cvs_start_record.rec_mode.rx_tap_point =
  4363. VSS_IRECORD_TAP_POINT_STREAM_END;
  4364. cvs_start_record.rec_mode.tx_tap_point =
  4365. VSS_IRECORD_TAP_POINT_STREAM_END;
  4366. } else {
  4367. pr_err("%s: Invalid in-call rec_mode %d\n", __func__,
  4368. rec_mode);
  4369. ret = -EINVAL;
  4370. goto fail;
  4371. }
  4372. v->cvs_state = CMD_STATUS_FAIL;
  4373. v->async_err = 0;
  4374. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_record);
  4375. if (ret < 0) {
  4376. pr_err("%s: Error %d sending START_RECORD\n", __func__,
  4377. ret);
  4378. goto fail;
  4379. }
  4380. ret = wait_event_timeout(v->cvs_wait,
  4381. (v->cvs_state == CMD_STATUS_SUCCESS),
  4382. msecs_to_jiffies(TIMEOUT_MS));
  4383. if (!ret) {
  4384. pr_err("%s: wait_event timeout\n", __func__);
  4385. goto fail;
  4386. }
  4387. if (v->async_err > 0) {
  4388. pr_err("%s: DSP returned error[%s]\n",
  4389. __func__, adsp_err_get_err_str(
  4390. v->async_err));
  4391. ret = adsp_err_get_lnx_err_code(
  4392. v->async_err);
  4393. goto fail;
  4394. }
  4395. v->rec_info.recording = 1;
  4396. } else {
  4397. pr_debug("%s: Start record already sent\n", __func__);
  4398. }
  4399. return 0;
  4400. fail:
  4401. return ret;
  4402. }
  4403. static int voice_cvs_stop_record(struct voice_data *v)
  4404. {
  4405. int ret = 0;
  4406. void *apr_cvs;
  4407. u16 cvs_handle;
  4408. struct apr_hdr cvs_stop_record;
  4409. if (v == NULL) {
  4410. pr_err("%s: v is NULL\n", __func__);
  4411. return -EINVAL;
  4412. }
  4413. apr_cvs = common.apr_q6_cvs;
  4414. if (!apr_cvs) {
  4415. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4416. return -EINVAL;
  4417. }
  4418. cvs_handle = voice_get_cvs_handle(v);
  4419. if (v->rec_info.recording) {
  4420. cvs_stop_record.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4421. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4422. cvs_stop_record.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4423. sizeof(cvs_stop_record) - APR_HDR_SIZE);
  4424. cvs_stop_record.src_port =
  4425. voice_get_idx_for_session(v->session_id);
  4426. cvs_stop_record.dest_port = cvs_handle;
  4427. cvs_stop_record.token = 0;
  4428. cvs_stop_record.opcode = VSS_IRECORD_CMD_STOP;
  4429. v->cvs_state = CMD_STATUS_FAIL;
  4430. v->async_err = 0;
  4431. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_record);
  4432. if (ret < 0) {
  4433. pr_err("%s: Error %d sending STOP_RECORD\n",
  4434. __func__, ret);
  4435. goto fail;
  4436. }
  4437. ret = wait_event_timeout(v->cvs_wait,
  4438. (v->cvs_state == CMD_STATUS_SUCCESS),
  4439. msecs_to_jiffies(TIMEOUT_MS));
  4440. if (!ret) {
  4441. pr_err("%s: wait_event timeout\n", __func__);
  4442. goto fail;
  4443. }
  4444. if (v->async_err > 0) {
  4445. pr_err("%s: DSP returned error[%s]\n",
  4446. __func__, adsp_err_get_err_str(
  4447. v->async_err));
  4448. ret = adsp_err_get_lnx_err_code(
  4449. v->async_err);
  4450. goto fail;
  4451. }
  4452. v->rec_info.recording = 0;
  4453. } else {
  4454. pr_debug("%s: Stop record already sent\n", __func__);
  4455. }
  4456. return 0;
  4457. fail:
  4458. return ret;
  4459. }
  4460. int voc_start_record(uint32_t port_id, uint32_t set, uint32_t session_id)
  4461. {
  4462. int ret = 0;
  4463. int rec_mode = 0;
  4464. u16 cvs_handle;
  4465. int rec_set = 0;
  4466. struct voice_session_itr itr;
  4467. struct voice_data *v = NULL;
  4468. /* check if session_id is valid */
  4469. if (!voice_is_valid_session_id(session_id)) {
  4470. pr_err("%s: Invalid session id:%u\n", __func__,
  4471. session_id);
  4472. return -EINVAL;
  4473. }
  4474. voice_itr_init(&itr, session_id);
  4475. pr_debug("%s: session_id:%u\n", __func__, session_id);
  4476. while (voice_itr_get_next_session(&itr, &v)) {
  4477. if (v == NULL) {
  4478. pr_err("%s: v is NULL, sessionid:%u\n", __func__,
  4479. session_id);
  4480. break;
  4481. }
  4482. pr_debug("%s: port_id: %d, set: %d, v: %pK\n",
  4483. __func__, port_id, set, v);
  4484. mutex_lock(&v->lock);
  4485. rec_mode = v->rec_info.rec_mode;
  4486. rec_set = set;
  4487. if (set) {
  4488. if ((v->rec_route_state.ul_flag != 0) &&
  4489. (v->rec_route_state.dl_flag != 0)) {
  4490. pr_debug("%s: rec mode already set.\n",
  4491. __func__);
  4492. mutex_unlock(&v->lock);
  4493. continue;
  4494. }
  4495. if (port_id == VOICE_RECORD_TX) {
  4496. if ((v->rec_route_state.ul_flag == 0)
  4497. && (v->rec_route_state.dl_flag == 0)) {
  4498. rec_mode = VOC_REC_UPLINK;
  4499. v->rec_route_state.ul_flag = 1;
  4500. } else if ((v->rec_route_state.ul_flag == 0)
  4501. && (v->rec_route_state.dl_flag != 0)) {
  4502. voice_cvs_stop_record(v);
  4503. rec_mode = VOC_REC_BOTH;
  4504. v->rec_route_state.ul_flag = 1;
  4505. }
  4506. } else if (port_id == VOICE_RECORD_RX) {
  4507. if ((v->rec_route_state.ul_flag == 0)
  4508. && (v->rec_route_state.dl_flag == 0)) {
  4509. rec_mode = VOC_REC_DOWNLINK;
  4510. v->rec_route_state.dl_flag = 1;
  4511. } else if ((v->rec_route_state.ul_flag != 0)
  4512. && (v->rec_route_state.dl_flag == 0)) {
  4513. voice_cvs_stop_record(v);
  4514. rec_mode = VOC_REC_BOTH;
  4515. v->rec_route_state.dl_flag = 1;
  4516. }
  4517. }
  4518. rec_set = 1;
  4519. } else {
  4520. if ((v->rec_route_state.ul_flag == 0) &&
  4521. (v->rec_route_state.dl_flag == 0)) {
  4522. pr_debug("%s: rec already stops.\n",
  4523. __func__);
  4524. mutex_unlock(&v->lock);
  4525. continue;
  4526. }
  4527. if (port_id == VOICE_RECORD_TX) {
  4528. if ((v->rec_route_state.ul_flag != 0)
  4529. && (v->rec_route_state.dl_flag == 0)) {
  4530. v->rec_route_state.ul_flag = 0;
  4531. rec_set = 0;
  4532. } else if ((v->rec_route_state.ul_flag != 0)
  4533. && (v->rec_route_state.dl_flag != 0)) {
  4534. voice_cvs_stop_record(v);
  4535. v->rec_route_state.ul_flag = 0;
  4536. rec_mode = VOC_REC_DOWNLINK;
  4537. rec_set = 1;
  4538. }
  4539. } else if (port_id == VOICE_RECORD_RX) {
  4540. if ((v->rec_route_state.ul_flag == 0)
  4541. && (v->rec_route_state.dl_flag != 0)) {
  4542. v->rec_route_state.dl_flag = 0;
  4543. rec_set = 0;
  4544. } else if ((v->rec_route_state.ul_flag != 0)
  4545. && (v->rec_route_state.dl_flag != 0)) {
  4546. voice_cvs_stop_record(v);
  4547. v->rec_route_state.dl_flag = 0;
  4548. rec_mode = VOC_REC_UPLINK;
  4549. rec_set = 1;
  4550. }
  4551. }
  4552. }
  4553. pr_debug("%s: mode =%d, set =%d\n", __func__,
  4554. rec_mode, rec_set);
  4555. cvs_handle = voice_get_cvs_handle(v);
  4556. if (cvs_handle != 0) {
  4557. if (rec_set)
  4558. ret = voice_cvs_start_record(v, rec_mode);
  4559. else
  4560. ret = voice_cvs_stop_record(v);
  4561. }
  4562. /* During SRVCC, recording will switch from VoLTE session to
  4563. * voice session.
  4564. * Then stop recording, need to stop recording on voice session.
  4565. */
  4566. if ((!rec_set) && common.srvcc_rec_flag) {
  4567. pr_debug("%s, srvcc_rec_flag:%d\n", __func__,
  4568. common.srvcc_rec_flag);
  4569. voice_cvs_stop_record(&common.voice[VOC_PATH_PASSIVE]);
  4570. common.srvcc_rec_flag = false;
  4571. }
  4572. /* Cache the value */
  4573. v->rec_info.rec_enable = rec_set;
  4574. v->rec_info.rec_mode = rec_mode;
  4575. mutex_unlock(&v->lock);
  4576. }
  4577. return ret;
  4578. }
  4579. static int voice_cvs_start_playback(struct voice_data *v)
  4580. {
  4581. int ret = 0;
  4582. struct cvs_start_playback_cmd cvs_start_playback;
  4583. void *apr_cvs;
  4584. u16 cvs_handle;
  4585. if (v == NULL) {
  4586. pr_err("%s: v is NULL\n", __func__);
  4587. return -EINVAL;
  4588. }
  4589. apr_cvs = common.apr_q6_cvs;
  4590. if (!apr_cvs) {
  4591. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4592. return -EINVAL;
  4593. }
  4594. cvs_handle = voice_get_cvs_handle(v);
  4595. if (!v->music_info.playing && v->music_info.count) {
  4596. cvs_start_playback.hdr.hdr_field = APR_HDR_FIELD(
  4597. APR_MSG_TYPE_SEQ_CMD,
  4598. APR_HDR_LEN(APR_HDR_SIZE),
  4599. APR_PKT_VER);
  4600. cvs_start_playback.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4601. sizeof(cvs_start_playback) - APR_HDR_SIZE);
  4602. cvs_start_playback.hdr.src_port =
  4603. voice_get_idx_for_session(v->session_id);
  4604. cvs_start_playback.hdr.dest_port = cvs_handle;
  4605. cvs_start_playback.hdr.token = 0;
  4606. cvs_start_playback.hdr.opcode = VSS_IPLAYBACK_CMD_START;
  4607. cvs_start_playback.playback_mode.port_id =
  4608. v->music_info.port_id;
  4609. v->cvs_state = CMD_STATUS_FAIL;
  4610. v->async_err = 0;
  4611. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
  4612. if (ret < 0) {
  4613. pr_err("%s: Error %d sending START_PLAYBACK\n",
  4614. __func__, ret);
  4615. goto fail;
  4616. }
  4617. ret = wait_event_timeout(v->cvs_wait,
  4618. (v->cvs_state == CMD_STATUS_SUCCESS),
  4619. msecs_to_jiffies(TIMEOUT_MS));
  4620. if (!ret) {
  4621. pr_err("%s: wait_event timeout\n", __func__);
  4622. goto fail;
  4623. }
  4624. if (v->async_err > 0) {
  4625. pr_err("%s: DSP returned error[%s]\n",
  4626. __func__, adsp_err_get_err_str(
  4627. v->async_err));
  4628. ret = adsp_err_get_lnx_err_code(
  4629. v->async_err);
  4630. goto fail;
  4631. }
  4632. v->music_info.playing = 1;
  4633. } else {
  4634. pr_debug("%s: Start playback already sent\n", __func__);
  4635. }
  4636. return 0;
  4637. fail:
  4638. return ret;
  4639. }
  4640. static int voice_cvs_stop_playback(struct voice_data *v)
  4641. {
  4642. int ret = 0;
  4643. struct apr_hdr cvs_stop_playback;
  4644. void *apr_cvs;
  4645. u16 cvs_handle;
  4646. if (v == NULL) {
  4647. pr_err("%s: v is NULL\n", __func__);
  4648. return -EINVAL;
  4649. }
  4650. apr_cvs = common.apr_q6_cvs;
  4651. if (!apr_cvs) {
  4652. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4653. return -EINVAL;
  4654. }
  4655. cvs_handle = voice_get_cvs_handle(v);
  4656. if (v->music_info.playing && ((!v->music_info.count) ||
  4657. (v->music_info.force))) {
  4658. cvs_stop_playback.hdr_field =
  4659. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4660. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4661. cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4662. sizeof(cvs_stop_playback) - APR_HDR_SIZE);
  4663. cvs_stop_playback.src_port =
  4664. voice_get_idx_for_session(v->session_id);
  4665. cvs_stop_playback.dest_port = cvs_handle;
  4666. cvs_stop_playback.token = 0;
  4667. cvs_stop_playback.opcode = VSS_IPLAYBACK_CMD_STOP;
  4668. v->cvs_state = CMD_STATUS_FAIL;
  4669. v->async_err = 0;
  4670. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
  4671. if (ret < 0) {
  4672. pr_err("%s: Error %d sending STOP_PLAYBACK\n",
  4673. __func__, ret);
  4674. goto fail;
  4675. }
  4676. ret = wait_event_timeout(v->cvs_wait,
  4677. (v->cvs_state == CMD_STATUS_SUCCESS),
  4678. msecs_to_jiffies(TIMEOUT_MS));
  4679. if (!ret) {
  4680. pr_err("%s: wait_event timeout\n", __func__);
  4681. goto fail;
  4682. }
  4683. if (v->async_err > 0) {
  4684. pr_err("%s: DSP returned error[%s]\n",
  4685. __func__, adsp_err_get_err_str(
  4686. v->async_err));
  4687. ret = adsp_err_get_lnx_err_code(
  4688. v->async_err);
  4689. goto fail;
  4690. }
  4691. v->music_info.playing = 0;
  4692. v->music_info.force = 0;
  4693. } else {
  4694. pr_debug("%s: Stop playback already sent\n", __func__);
  4695. }
  4696. return 0;
  4697. fail:
  4698. return ret;
  4699. }
  4700. static int voc_lch_ops(struct voice_data *v, enum voice_lch_mode lch_mode)
  4701. {
  4702. int ret = 0;
  4703. if (v == NULL) {
  4704. pr_err("%s: v is NULL\n", __func__);
  4705. ret = -EINVAL;
  4706. goto done;
  4707. }
  4708. switch (lch_mode) {
  4709. case VOICE_LCH_START:
  4710. ret = voc_end_voice_call(v->session_id);
  4711. if (ret < 0)
  4712. pr_err("%s: voice call end failed %d\n",
  4713. __func__, ret);
  4714. break;
  4715. case VOICE_LCH_STOP:
  4716. ret = voc_start_voice_call(v->session_id);
  4717. if (ret < 0) {
  4718. pr_err("%s: voice call start failed %d\n",
  4719. __func__, ret);
  4720. goto done;
  4721. }
  4722. break;
  4723. default:
  4724. pr_err("%s: Invalid LCH mode: %d\n",
  4725. __func__, v->lch_mode);
  4726. break;
  4727. }
  4728. done:
  4729. return ret;
  4730. }
  4731. int voc_start_playback(uint32_t set, uint16_t port_id)
  4732. {
  4733. struct voice_data *v = NULL;
  4734. int ret = 0;
  4735. struct voice_session_itr itr;
  4736. u16 cvs_handle;
  4737. pr_debug("%s port_id = %#x set = %d", __func__, port_id, set);
  4738. voice_itr_init(&itr, ALL_SESSION_VSID);
  4739. while (voice_itr_get_next_session(&itr, &v)) {
  4740. if ((v != NULL) &&
  4741. (((port_id == VOICE_PLAYBACK_TX) &&
  4742. is_sub1_vsid(v->session_id)) ||
  4743. ((port_id == VOICE2_PLAYBACK_TX) &&
  4744. is_sub2_vsid(v->session_id)))) {
  4745. mutex_lock(&v->lock);
  4746. v->music_info.port_id = port_id;
  4747. v->music_info.play_enable = set;
  4748. if (set)
  4749. v->music_info.count++;
  4750. else
  4751. v->music_info.count--;
  4752. pr_debug("%s: music_info count=%d\n", __func__,
  4753. v->music_info.count);
  4754. cvs_handle = voice_get_cvs_handle(v);
  4755. if (cvs_handle != 0) {
  4756. if (set)
  4757. ret = voice_cvs_start_playback(v);
  4758. else
  4759. ret = voice_cvs_stop_playback(v);
  4760. }
  4761. mutex_unlock(&v->lock);
  4762. } else {
  4763. pr_err("%s: Invalid session\n", __func__);
  4764. }
  4765. }
  4766. return ret;
  4767. }
  4768. int voc_disable_topology(uint32_t session_id, uint32_t disable)
  4769. {
  4770. struct voice_data *v = voice_get_session(session_id);
  4771. int ret = 0;
  4772. if (v == NULL) {
  4773. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4774. return -EINVAL;
  4775. }
  4776. mutex_lock(&v->lock);
  4777. v->disable_topology = disable;
  4778. mutex_unlock(&v->lock);
  4779. return ret;
  4780. }
  4781. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  4782. uint32_t mode)
  4783. {
  4784. struct voice_data *v = voice_get_session(session_id);
  4785. int ret = 0;
  4786. if (v == NULL) {
  4787. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4788. return -EINVAL;
  4789. }
  4790. if (v->voc_state != VOC_RUN)
  4791. ret = voice_send_cvs_data_exchange_mode_cmd(v);
  4792. if (ret) {
  4793. pr_err("%s: Error voice_send_data_exchange_mode_cmd %d\n",
  4794. __func__, ret);
  4795. goto fail;
  4796. }
  4797. ret = voice_send_cvs_packet_exchange_config_cmd(v);
  4798. if (ret) {
  4799. pr_err("%s: Error: voice_send_packet_exchange_config_cmd %d\n",
  4800. __func__, ret);
  4801. goto fail;
  4802. }
  4803. return ret;
  4804. fail:
  4805. return -EINVAL;
  4806. }
  4807. int voc_set_tx_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  4808. uint32_t ramp_duration)
  4809. {
  4810. struct voice_data *v = NULL;
  4811. int ret = 0;
  4812. struct voice_session_itr itr;
  4813. voice_itr_init(&itr, session_id);
  4814. while (voice_itr_get_next_session(&itr, &v)) {
  4815. if (v != NULL) {
  4816. mutex_lock(&v->lock);
  4817. v->stream_tx.stream_mute = mute;
  4818. v->stream_tx.stream_mute_ramp_duration_ms =
  4819. ramp_duration;
  4820. if (is_voc_state_active(v->voc_state) &&
  4821. (v->lch_mode == 0))
  4822. ret = voice_send_stream_mute_cmd(v,
  4823. VSS_IVOLUME_DIRECTION_TX,
  4824. v->stream_tx.stream_mute,
  4825. v->stream_tx.stream_mute_ramp_duration_ms);
  4826. mutex_unlock(&v->lock);
  4827. } else {
  4828. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4829. session_id);
  4830. ret = -EINVAL;
  4831. break;
  4832. }
  4833. }
  4834. return ret;
  4835. }
  4836. int voc_set_device_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  4837. uint32_t ramp_duration)
  4838. {
  4839. struct voice_data *v = NULL;
  4840. int ret = 0;
  4841. struct voice_session_itr itr;
  4842. voice_itr_init(&itr, session_id);
  4843. while (voice_itr_get_next_session(&itr, &v)) {
  4844. if (v != NULL) {
  4845. mutex_lock(&v->lock);
  4846. if (dir == VSS_IVOLUME_DIRECTION_TX) {
  4847. v->dev_tx.dev_mute = mute;
  4848. v->dev_tx.dev_mute_ramp_duration_ms =
  4849. ramp_duration;
  4850. } else {
  4851. v->dev_rx.dev_mute = mute;
  4852. v->dev_rx.dev_mute_ramp_duration_ms =
  4853. ramp_duration;
  4854. }
  4855. if (((v->voc_state == VOC_RUN) ||
  4856. (v->voc_state == VOC_STANDBY)) &&
  4857. (v->lch_mode == 0))
  4858. ret = voice_send_device_mute_cmd(v,
  4859. dir,
  4860. mute,
  4861. ramp_duration);
  4862. mutex_unlock(&v->lock);
  4863. } else {
  4864. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4865. session_id);
  4866. ret = -EINVAL;
  4867. break;
  4868. }
  4869. }
  4870. return ret;
  4871. }
  4872. int voc_get_rx_device_mute(uint32_t session_id)
  4873. {
  4874. struct voice_data *v = voice_get_session(session_id);
  4875. int ret = 0;
  4876. if (v == NULL) {
  4877. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4878. return -EINVAL;
  4879. }
  4880. mutex_lock(&v->lock);
  4881. ret = v->dev_rx.dev_mute;
  4882. mutex_unlock(&v->lock);
  4883. return ret;
  4884. }
  4885. int voc_set_tty_mode(uint32_t session_id, uint8_t tty_mode)
  4886. {
  4887. struct voice_data *v = voice_get_session(session_id);
  4888. int ret = 0;
  4889. if (v == NULL) {
  4890. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4891. return -EINVAL;
  4892. }
  4893. mutex_lock(&v->lock);
  4894. v->tty_mode = tty_mode;
  4895. mutex_unlock(&v->lock);
  4896. return ret;
  4897. }
  4898. uint8_t voc_get_tty_mode(uint32_t session_id)
  4899. {
  4900. struct voice_data *v = voice_get_session(session_id);
  4901. int ret = 0;
  4902. if (v == NULL) {
  4903. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4904. return -EINVAL;
  4905. }
  4906. mutex_lock(&v->lock);
  4907. ret = v->tty_mode;
  4908. mutex_unlock(&v->lock);
  4909. return ret;
  4910. }
  4911. int voc_set_pp_enable(uint32_t session_id, uint32_t module_id, uint32_t enable)
  4912. {
  4913. struct voice_data *v = NULL;
  4914. int ret = 0;
  4915. struct voice_session_itr itr;
  4916. voice_itr_init(&itr, session_id);
  4917. while (voice_itr_get_next_session(&itr, &v)) {
  4918. if (v != NULL) {
  4919. if (!(is_voice_app_id(v->session_id)))
  4920. continue;
  4921. mutex_lock(&v->lock);
  4922. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  4923. v->st_enable = enable;
  4924. if (v->voc_state == VOC_RUN) {
  4925. if ((module_id == MODULE_ID_VOICE_MODULE_ST) &&
  4926. (!v->tty_mode))
  4927. ret = voice_send_set_pp_enable_cmd(v,
  4928. MODULE_ID_VOICE_MODULE_ST,
  4929. enable);
  4930. }
  4931. mutex_unlock(&v->lock);
  4932. } else {
  4933. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4934. session_id);
  4935. ret = -EINVAL;
  4936. break;
  4937. }
  4938. }
  4939. return ret;
  4940. }
  4941. int voc_set_hd_enable(uint32_t session_id, uint32_t enable)
  4942. {
  4943. struct voice_data *v = NULL;
  4944. int ret = 0;
  4945. struct voice_session_itr itr;
  4946. voice_itr_init(&itr, session_id);
  4947. while (voice_itr_get_next_session(&itr, &v)) {
  4948. if (v != NULL) {
  4949. mutex_lock(&v->lock);
  4950. v->hd_enable = enable;
  4951. if (v->voc_state == VOC_RUN)
  4952. ret = voice_send_hd_cmd(v, enable);
  4953. mutex_unlock(&v->lock);
  4954. } else {
  4955. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4956. session_id);
  4957. ret = -EINVAL;
  4958. break;
  4959. }
  4960. }
  4961. return ret;
  4962. }
  4963. int voc_set_afe_sidetone(uint32_t session_id, bool sidetone_enable)
  4964. {
  4965. struct voice_data *v = NULL;
  4966. int ret = -EINVAL;
  4967. struct voice_session_itr itr;
  4968. u16 rx_port, tx_port;
  4969. common.sidetone_enable = sidetone_enable;
  4970. voice_itr_init(&itr, session_id);
  4971. while (voice_itr_get_next_session(&itr, &v)) {
  4972. if (v == NULL) {
  4973. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4974. session_id);
  4975. ret = -EINVAL;
  4976. break;
  4977. }
  4978. mutex_lock(&v->lock);
  4979. if (v->voc_state != VOC_RUN) {
  4980. mutex_unlock(&v->lock);
  4981. continue;
  4982. }
  4983. rx_port = v->dev_rx.port_id;
  4984. tx_port = v->dev_tx.port_id;
  4985. ret = afe_sidetone_enable(tx_port, rx_port,
  4986. sidetone_enable);
  4987. if (!ret) {
  4988. mutex_unlock(&v->lock);
  4989. break;
  4990. }
  4991. mutex_unlock(&v->lock);
  4992. }
  4993. return ret;
  4994. }
  4995. bool voc_get_afe_sidetone(void)
  4996. {
  4997. bool ret;
  4998. ret = common.sidetone_enable;
  4999. return ret;
  5000. }
  5001. int voc_get_pp_enable(uint32_t session_id, uint32_t module_id)
  5002. {
  5003. struct voice_data *v = voice_get_session(session_id);
  5004. int ret = 0;
  5005. if (v == NULL) {
  5006. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5007. return -EINVAL;
  5008. }
  5009. mutex_lock(&v->lock);
  5010. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  5011. ret = v->st_enable;
  5012. mutex_unlock(&v->lock);
  5013. return ret;
  5014. }
  5015. int voc_set_rx_vol_step(uint32_t session_id, uint32_t dir, uint32_t vol_step,
  5016. uint32_t ramp_duration)
  5017. {
  5018. struct voice_data *v = NULL;
  5019. int ret = 0;
  5020. struct voice_session_itr itr;
  5021. pr_debug("%s session id = %#x vol = %u", __func__, session_id,
  5022. vol_step);
  5023. voice_itr_init(&itr, session_id);
  5024. while (voice_itr_get_next_session(&itr, &v)) {
  5025. if (v != NULL) {
  5026. mutex_lock(&v->lock);
  5027. v->dev_rx.volume_step_value = vol_step;
  5028. v->dev_rx.volume_ramp_duration_ms = ramp_duration;
  5029. if (is_voc_state_active(v->voc_state))
  5030. ret = voice_send_vol_step_cmd(v);
  5031. mutex_unlock(&v->lock);
  5032. } else {
  5033. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5034. session_id);
  5035. ret = -EINVAL;
  5036. break;
  5037. }
  5038. }
  5039. return ret;
  5040. }
  5041. int voc_set_device_config(uint32_t session_id, uint8_t path_dir,
  5042. struct media_format_info *finfo)
  5043. {
  5044. struct voice_data *v = voice_get_session(session_id);
  5045. if (v == NULL) {
  5046. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  5047. return -EINVAL;
  5048. }
  5049. pr_debug("%s: path_dir=%d port_id=%x, channels=%d, sample_rate=%d, bits_per_sample=%d\n",
  5050. __func__, path_dir, finfo->port_id, finfo->num_channels,
  5051. finfo->sample_rate, finfo->bits_per_sample);
  5052. mutex_lock(&v->lock);
  5053. switch (path_dir) {
  5054. case RX_PATH:
  5055. v->dev_rx.port_id = q6audio_get_port_id(finfo->port_id);
  5056. v->dev_rx.no_of_channels = finfo->num_channels;
  5057. v->dev_rx.sample_rate = finfo->sample_rate;
  5058. v->dev_rx.bits_per_sample = finfo->bits_per_sample;
  5059. memcpy(&v->dev_rx.channel_mapping, &finfo->channel_mapping,
  5060. VSS_CHANNEL_MAPPING_SIZE);
  5061. break;
  5062. case TX_PATH:
  5063. v->dev_tx.port_id = q6audio_get_port_id(finfo->port_id);
  5064. v->dev_tx.no_of_channels = finfo->num_channels;
  5065. v->dev_tx.sample_rate = finfo->sample_rate;
  5066. v->dev_tx.bits_per_sample = finfo->bits_per_sample;
  5067. memcpy(&v->dev_tx.channel_mapping, &finfo->channel_mapping,
  5068. VSS_CHANNEL_MAPPING_SIZE);
  5069. break;
  5070. default:
  5071. pr_err("%s: Invalid path_dir %d\n", __func__, path_dir);
  5072. return -EINVAL;
  5073. }
  5074. mutex_unlock(&v->lock);
  5075. return 0;
  5076. }
  5077. int voc_set_ext_ec_ref_media_fmt_info(struct media_format_info *finfo)
  5078. {
  5079. mutex_lock(&common.common_lock);
  5080. if (common.ec_ref_ext) {
  5081. common.ec_media_fmt_info.num_channels = finfo->num_channels;
  5082. common.ec_media_fmt_info.bits_per_sample =
  5083. finfo->bits_per_sample;
  5084. common.ec_media_fmt_info.sample_rate = finfo->sample_rate;
  5085. memcpy(&common.ec_media_fmt_info.channel_mapping,
  5086. &finfo->channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  5087. } else {
  5088. pr_debug("%s: Ext Ec Ref not active, returning", __func__);
  5089. }
  5090. mutex_unlock(&common.common_lock);
  5091. return 0;
  5092. }
  5093. int voc_set_route_flag(uint32_t session_id, uint8_t path_dir, uint8_t set)
  5094. {
  5095. struct voice_data *v = voice_get_session(session_id);
  5096. if (v == NULL) {
  5097. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5098. return -EINVAL;
  5099. }
  5100. pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
  5101. mutex_lock(&v->lock);
  5102. if (path_dir == RX_PATH)
  5103. v->voc_route_state.rx_route_flag = set;
  5104. else
  5105. v->voc_route_state.tx_route_flag = set;
  5106. mutex_unlock(&v->lock);
  5107. return 0;
  5108. }
  5109. uint8_t voc_get_route_flag(uint32_t session_id, uint8_t path_dir)
  5110. {
  5111. struct voice_data *v = voice_get_session(session_id);
  5112. int ret = 0;
  5113. if (v == NULL) {
  5114. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5115. return 0;
  5116. }
  5117. mutex_lock(&v->lock);
  5118. if (path_dir == RX_PATH)
  5119. ret = v->voc_route_state.rx_route_flag;
  5120. else
  5121. ret = v->voc_route_state.tx_route_flag;
  5122. mutex_unlock(&v->lock);
  5123. return ret;
  5124. }
  5125. int voc_end_voice_call(uint32_t session_id)
  5126. {
  5127. struct voice_data *v = voice_get_session(session_id);
  5128. int ret = 0;
  5129. if (v == NULL) {
  5130. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5131. return -EINVAL;
  5132. }
  5133. mutex_lock(&v->lock);
  5134. if (v->voc_state == VOC_RUN || v->voc_state == VOC_ERROR ||
  5135. v->voc_state == VOC_CHANGE || v->voc_state == VOC_STANDBY) {
  5136. pr_debug("%s: VOC_STATE: %d\n", __func__, v->voc_state);
  5137. ret = voice_destroy_vocproc(v);
  5138. if (ret < 0)
  5139. pr_err("%s: destroy voice failed\n", __func__);
  5140. voc_update_session_params(v);
  5141. voice_destroy_mvm_cvs_session(v);
  5142. v->voc_state = VOC_RELEASE;
  5143. } else {
  5144. pr_err("%s: Error: End voice called in state %d\n",
  5145. __func__, v->voc_state);
  5146. ret = -EINVAL;
  5147. }
  5148. mutex_unlock(&v->lock);
  5149. return ret;
  5150. }
  5151. int voc_standby_voice_call(uint32_t session_id)
  5152. {
  5153. struct voice_data *v = voice_get_session(session_id);
  5154. struct apr_hdr mvm_standby_voice_cmd;
  5155. void *apr_mvm;
  5156. u16 mvm_handle;
  5157. int ret = 0;
  5158. if (v == NULL) {
  5159. pr_err("%s: v is NULL\n", __func__);
  5160. return -EINVAL;
  5161. }
  5162. pr_debug("%s: voc state=%d", __func__, v->voc_state);
  5163. if (v->voc_state == VOC_RUN) {
  5164. apr_mvm = common.apr_q6_mvm;
  5165. if (!apr_mvm) {
  5166. pr_err("%s: apr_mvm is NULL.\n", __func__);
  5167. ret = -EINVAL;
  5168. goto fail;
  5169. }
  5170. mvm_handle = voice_get_mvm_handle(v);
  5171. mvm_standby_voice_cmd.hdr_field =
  5172. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  5173. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  5174. mvm_standby_voice_cmd.pkt_size =
  5175. APR_PKT_SIZE(APR_HDR_SIZE,
  5176. sizeof(mvm_standby_voice_cmd) - APR_HDR_SIZE);
  5177. pr_debug("send mvm_standby_voice_cmd pkt size = %d\n",
  5178. mvm_standby_voice_cmd.pkt_size);
  5179. mvm_standby_voice_cmd.src_port =
  5180. voice_get_idx_for_session(v->session_id);
  5181. mvm_standby_voice_cmd.dest_port = mvm_handle;
  5182. mvm_standby_voice_cmd.token = 0;
  5183. mvm_standby_voice_cmd.opcode = VSS_IMVM_CMD_STANDBY_VOICE;
  5184. v->mvm_state = CMD_STATUS_FAIL;
  5185. ret = apr_send_pkt(apr_mvm,
  5186. (uint32_t *)&mvm_standby_voice_cmd);
  5187. if (ret < 0) {
  5188. pr_err("Fail in sending VSS_IMVM_CMD_STANDBY_VOICE\n");
  5189. ret = -EINVAL;
  5190. goto fail;
  5191. }
  5192. v->voc_state = VOC_STANDBY;
  5193. }
  5194. fail:
  5195. return ret;
  5196. }
  5197. int voc_disable_device(uint32_t session_id)
  5198. {
  5199. struct voice_data *v = voice_get_session(session_id);
  5200. int ret = 0;
  5201. if (v == NULL) {
  5202. pr_err("%s: v is NULL\n", __func__);
  5203. return -EINVAL;
  5204. }
  5205. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  5206. mutex_lock(&v->lock);
  5207. if (v->voc_state == VOC_RUN) {
  5208. ret = voice_pause_voice_call(v);
  5209. if (ret < 0) {
  5210. pr_err("%s: Pause Voice Call failed for session 0x%x, err %d!\n",
  5211. __func__, v->session_id, ret);
  5212. goto done;
  5213. }
  5214. rtac_remove_voice(voice_get_cvs_handle(v));
  5215. voice_send_cvp_deregister_vol_cal_cmd(v);
  5216. voice_send_cvp_deregister_cal_cmd(v);
  5217. voice_send_cvp_deregister_dev_cfg_cmd(v);
  5218. v->voc_state = VOC_CHANGE;
  5219. } else {
  5220. pr_debug("%s: called in voc state=%d, No_OP\n",
  5221. __func__, v->voc_state);
  5222. }
  5223. done:
  5224. mutex_unlock(&v->lock);
  5225. return ret;
  5226. }
  5227. int voc_enable_device(uint32_t session_id)
  5228. {
  5229. struct voice_data *v = voice_get_session(session_id);
  5230. int ret = 0;
  5231. if (v == NULL) {
  5232. pr_err("%s: v is NULL\n", __func__);
  5233. return -EINVAL;
  5234. }
  5235. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  5236. mutex_lock(&v->lock);
  5237. if (v->voc_state == VOC_CHANGE) {
  5238. ret = voice_send_tty_mode_cmd(v);
  5239. if (ret < 0) {
  5240. pr_err("%s: Sending TTY mode failed, ret=%d\n",
  5241. __func__, ret);
  5242. /* Not a critical error, allow voice call to continue */
  5243. }
  5244. if (v->tty_mode) {
  5245. /* disable slowtalk */
  5246. voice_send_set_pp_enable_cmd(v,
  5247. MODULE_ID_VOICE_MODULE_ST,
  5248. 0);
  5249. } else {
  5250. /* restore slowtalk */
  5251. voice_send_set_pp_enable_cmd(v,
  5252. MODULE_ID_VOICE_MODULE_ST,
  5253. v->st_enable);
  5254. }
  5255. ret = voice_send_set_device_cmd(v);
  5256. if (ret < 0) {
  5257. pr_err("%s: Set device failed, ret=%d\n",
  5258. __func__, ret);
  5259. goto done;
  5260. }
  5261. ret = voice_send_cvp_media_fmt_info_cmd(v);
  5262. if (ret < 0) {
  5263. pr_err("%s: Set format failed err:%d\n", __func__, ret);
  5264. goto done;
  5265. }
  5266. ret = voice_send_cvp_topology_commit_cmd(v);
  5267. if (ret < 0) {
  5268. pr_err("%s: Set topology commit failed\n", __func__);
  5269. goto done;
  5270. }
  5271. voice_send_cvp_register_dev_cfg_cmd(v);
  5272. voice_send_cvp_register_cal_cmd(v);
  5273. voice_send_cvp_register_vol_cal_cmd(v);
  5274. rtac_add_voice(voice_get_cvs_handle(v),
  5275. voice_get_cvp_handle(v),
  5276. v->dev_rx.port_id, v->dev_tx.port_id,
  5277. v->dev_rx.dev_id, v->dev_tx.dev_id,
  5278. v->session_id);
  5279. ret = voice_send_start_voice_cmd(v);
  5280. if (ret < 0) {
  5281. pr_err("%s: Fail in sending START_VOICE, ret=%d\n",
  5282. __func__, ret);
  5283. goto done;
  5284. }
  5285. v->voc_state = VOC_RUN;
  5286. } else {
  5287. pr_debug("%s: called in voc state=%d, No_OP\n",
  5288. __func__, v->voc_state);
  5289. }
  5290. done:
  5291. mutex_unlock(&v->lock);
  5292. return ret;
  5293. }
  5294. int voc_set_lch(uint32_t session_id, enum voice_lch_mode lch_mode)
  5295. {
  5296. struct voice_data *v = voice_get_session(session_id);
  5297. int ret = 0;
  5298. if (v == NULL) {
  5299. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  5300. ret = -EINVAL;
  5301. goto done;
  5302. }
  5303. mutex_lock(&v->lock);
  5304. if (v->lch_mode == lch_mode) {
  5305. pr_debug("%s: Session %d already in LCH mode %d\n",
  5306. __func__, session_id, lch_mode);
  5307. mutex_unlock(&v->lock);
  5308. goto done;
  5309. }
  5310. v->lch_mode = lch_mode;
  5311. mutex_unlock(&v->lock);
  5312. ret = voc_lch_ops(v, v->lch_mode);
  5313. if (ret < 0) {
  5314. pr_err("%s: lch ops failed %d\n", __func__, ret);
  5315. goto done;
  5316. }
  5317. done:
  5318. return ret;
  5319. }
  5320. int voc_resume_voice_call(uint32_t session_id)
  5321. {
  5322. struct voice_data *v = voice_get_session(session_id);
  5323. int ret = 0;
  5324. ret = voice_send_start_voice_cmd(v);
  5325. if (ret < 0) {
  5326. pr_err("Fail in sending START_VOICE\n");
  5327. goto fail;
  5328. }
  5329. v->voc_state = VOC_RUN;
  5330. return 0;
  5331. fail:
  5332. return -EINVAL;
  5333. }
  5334. int voc_start_voice_call(uint32_t session_id)
  5335. {
  5336. struct voice_data *v = voice_get_session(session_id);
  5337. int ret = 0;
  5338. if (v == NULL) {
  5339. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5340. return -EINVAL;
  5341. }
  5342. mutex_lock(&v->lock);
  5343. if (v->voc_state == VOC_ERROR) {
  5344. pr_debug("%s: VOC in ERR state\n", __func__);
  5345. voice_destroy_mvm_cvs_session(v);
  5346. v->voc_state = VOC_INIT;
  5347. }
  5348. if ((v->voc_state == VOC_INIT) ||
  5349. (v->voc_state == VOC_RELEASE)) {
  5350. ret = voice_apr_register(session_id);
  5351. if (ret < 0) {
  5352. pr_err("%s: apr register failed\n", __func__);
  5353. goto fail;
  5354. }
  5355. if (is_cvd_version_queried()) {
  5356. pr_debug("%s: Returning the cached value %s\n",
  5357. __func__, common.cvd_version);
  5358. } else {
  5359. ret = voice_send_mvm_cvd_version_cmd(v);
  5360. if (ret < 0)
  5361. pr_debug("%s: Error retrieving CVD version %d\n",
  5362. __func__, ret);
  5363. }
  5364. ret = voice_create_mvm_cvs_session(v);
  5365. if (ret < 0) {
  5366. pr_err("create mvm and cvs failed\n");
  5367. goto fail;
  5368. }
  5369. if (is_voip_session(session_id)) {
  5370. /* Allocate oob mem if not already allocated and
  5371. * memory map the oob memory block.
  5372. */
  5373. ret = voice_alloc_and_map_oob_mem(v);
  5374. if (ret < 0) {
  5375. pr_err("%s: voice_alloc_and_map_oob_mem() failed, ret:%d\n",
  5376. __func__, ret);
  5377. goto fail;
  5378. }
  5379. ret = voice_set_packet_exchange_mode_and_config(
  5380. session_id,
  5381. VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND);
  5382. if (ret) {
  5383. pr_err("%s: Err: exchange_mode_and_config %d\n",
  5384. __func__, ret);
  5385. goto fail;
  5386. }
  5387. }
  5388. ret = voice_send_dual_control_cmd(v);
  5389. if (ret < 0) {
  5390. pr_err("Err Dual command failed\n");
  5391. goto fail;
  5392. }
  5393. ret = voice_setup_vocproc(v);
  5394. if (ret < 0) {
  5395. pr_err("setup voice failed\n");
  5396. goto fail;
  5397. }
  5398. ret = voice_send_vol_step_cmd(v);
  5399. if (ret < 0)
  5400. pr_err("voice volume failed\n");
  5401. ret = voice_send_stream_mute_cmd(v,
  5402. VSS_IVOLUME_DIRECTION_TX,
  5403. v->stream_tx.stream_mute,
  5404. v->stream_tx.stream_mute_ramp_duration_ms);
  5405. if (ret < 0)
  5406. pr_err("voice mute failed\n");
  5407. ret = voice_send_start_voice_cmd(v);
  5408. if (ret < 0) {
  5409. pr_err("start voice failed\n");
  5410. goto fail;
  5411. }
  5412. v->voc_state = VOC_RUN;
  5413. } else {
  5414. pr_err("%s: Error: Start voice called in state %d\n",
  5415. __func__, v->voc_state);
  5416. ret = -EINVAL;
  5417. goto fail;
  5418. }
  5419. fail:
  5420. mutex_unlock(&v->lock);
  5421. return ret;
  5422. }
  5423. int voc_set_ext_ec_ref_port_id(uint16_t port_id, bool state)
  5424. {
  5425. int ret = 0;
  5426. mutex_lock(&common.common_lock);
  5427. if (state == true) {
  5428. if (port_id == AFE_PORT_INVALID) {
  5429. pr_err("%s: Invalid port id", __func__);
  5430. ret = -EINVAL;
  5431. goto exit;
  5432. }
  5433. common.ec_ref_ext = true;
  5434. } else {
  5435. common.ec_ref_ext = false;
  5436. }
  5437. /* Cache EC Fromat Info in common */
  5438. common.ec_media_fmt_info.port_id = port_id;
  5439. exit:
  5440. mutex_unlock(&common.common_lock);
  5441. return ret;
  5442. }
  5443. int voc_get_ext_ec_ref_port_id(void)
  5444. {
  5445. if (common.ec_ref_ext)
  5446. return common.ec_media_fmt_info.port_id;
  5447. else
  5448. return AFE_PORT_INVALID;
  5449. }
  5450. void voc_register_mvs_cb(ul_cb_fn ul_cb,
  5451. dl_cb_fn dl_cb,
  5452. voip_ssr_cb ssr_cb,
  5453. void *private_data)
  5454. {
  5455. common.mvs_info.ul_cb = ul_cb;
  5456. common.mvs_info.dl_cb = dl_cb;
  5457. common.mvs_info.ssr_cb = ssr_cb;
  5458. common.mvs_info.private_data = private_data;
  5459. }
  5460. void voc_register_dtmf_rx_detection_cb(dtmf_rx_det_cb_fn dtmf_rx_ul_cb,
  5461. void *private_data)
  5462. {
  5463. common.dtmf_info.dtmf_rx_ul_cb = dtmf_rx_ul_cb;
  5464. common.dtmf_info.private_data = private_data;
  5465. }
  5466. void voc_config_vocoder(uint32_t media_type,
  5467. uint32_t rate,
  5468. uint32_t network_type,
  5469. uint32_t dtx_mode,
  5470. uint32_t evrc_min_rate,
  5471. uint32_t evrc_max_rate)
  5472. {
  5473. common.mvs_info.media_type = media_type;
  5474. common.mvs_info.rate = rate;
  5475. common.mvs_info.network_type = network_type;
  5476. common.mvs_info.dtx_mode = dtx_mode;
  5477. common.mvs_info.evrc_min_rate = evrc_min_rate;
  5478. common.mvs_info.evrc_max_rate = evrc_max_rate;
  5479. }
  5480. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
  5481. {
  5482. uint32_t *ptr = NULL;
  5483. struct common_data *c = NULL;
  5484. struct voice_data *v = NULL;
  5485. int i = 0;
  5486. struct vss_iversion_rsp_get_t *version_rsp = NULL;
  5487. if ((data == NULL) || (priv == NULL)) {
  5488. pr_err("%s: data or priv is NULL\n", __func__);
  5489. return -EINVAL;
  5490. }
  5491. c = priv;
  5492. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  5493. data->payload_size, data->opcode);
  5494. if (data->opcode == RESET_EVENTS) {
  5495. pr_debug("%s: Reset event received in Voice service\n",
  5496. __func__);
  5497. if (common.mvs_info.ssr_cb) {
  5498. pr_debug("%s: Informing reset event to VoIP\n",
  5499. __func__);
  5500. common.mvs_info.ssr_cb(data->opcode,
  5501. common.mvs_info.private_data);
  5502. }
  5503. apr_reset(c->apr_q6_mvm);
  5504. c->apr_q6_mvm = NULL;
  5505. /* clean up memory handle */
  5506. c->cal_mem_handle = 0;
  5507. c->rtac_mem_handle = 0;
  5508. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  5509. common.cal_data);
  5510. rtac_clear_mapping(VOICE_RTAC_CAL);
  5511. /* Sub-system restart is applicable to all sessions. */
  5512. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  5513. c->voice[i].mvm_handle = 0;
  5514. c->voice[i].shmem_info.mem_handle = 0;
  5515. }
  5516. /* Free the ION memory and clear handles for Source Tracking */
  5517. if (is_source_tracking_shared_memomry_allocated()) {
  5518. msm_audio_ion_free(
  5519. common.source_tracking_sh_mem.sh_mem_block.client,
  5520. common.source_tracking_sh_mem.sh_mem_block.handle);
  5521. common.source_tracking_sh_mem.mem_handle = 0;
  5522. common.source_tracking_sh_mem.sh_mem_block.client =
  5523. NULL;
  5524. common.source_tracking_sh_mem.sh_mem_block.handle =
  5525. NULL;
  5526. }
  5527. /* clean up srvcc rec flag */
  5528. c->srvcc_rec_flag = false;
  5529. voc_set_error_state(data->reset_proc);
  5530. return 0;
  5531. }
  5532. pr_debug("%s: session_idx 0x%x\n", __func__, data->dest_port);
  5533. v = voice_get_session_by_idx(data->dest_port);
  5534. if (v == NULL) {
  5535. pr_err("%s: v is NULL\n", __func__);
  5536. return -EINVAL;
  5537. }
  5538. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5539. if (data->payload_size) {
  5540. ptr = data->payload;
  5541. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5542. /* ping mvm service ACK */
  5543. switch (ptr[0]) {
  5544. case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  5545. case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
  5546. /* Passive session is used for CS call
  5547. * Full session is used for VoIP call.
  5548. */
  5549. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5550. if (!ptr[1]) {
  5551. pr_debug("%s: MVM handle is %d\n",
  5552. __func__, data->src_port);
  5553. voice_set_mvm_handle(v, data->src_port);
  5554. } else
  5555. pr_err("got NACK for sending MVM create session\n");
  5556. v->mvm_state = CMD_STATUS_SUCCESS;
  5557. v->async_err = ptr[1];
  5558. wake_up(&v->mvm_wait);
  5559. break;
  5560. case VSS_IMVM_CMD_START_VOICE:
  5561. case VSS_IMVM_CMD_ATTACH_VOCPROC:
  5562. case VSS_IMVM_CMD_STOP_VOICE:
  5563. case VSS_IMVM_CMD_DETACH_VOCPROC:
  5564. case VSS_ISTREAM_CMD_SET_TTY_MODE:
  5565. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5566. case VSS_IMVM_CMD_ATTACH_STREAM:
  5567. case VSS_IMVM_CMD_DETACH_STREAM:
  5568. case VSS_ICOMMON_CMD_SET_NETWORK:
  5569. case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
  5570. case VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL:
  5571. case VSS_IMVM_CMD_SET_CAL_NETWORK:
  5572. case VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE:
  5573. case VSS_IMEMORY_CMD_MAP_PHYSICAL:
  5574. case VSS_IMEMORY_CMD_UNMAP:
  5575. case VSS_IMVM_CMD_PAUSE_VOICE:
  5576. case VSS_IMVM_CMD_STANDBY_VOICE:
  5577. case VSS_IHDVOICE_CMD_ENABLE:
  5578. case VSS_IHDVOICE_CMD_DISABLE:
  5579. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5580. v->mvm_state = CMD_STATUS_SUCCESS;
  5581. v->async_err = ptr[1];
  5582. wake_up(&v->mvm_wait);
  5583. break;
  5584. case VSS_IVERSION_CMD_GET:
  5585. pr_debug("%s: Error retrieving CVD Version, error:%d\n",
  5586. __func__, ptr[1]);
  5587. strlcpy(common.cvd_version, CVD_VERSION_0_0,
  5588. sizeof(common.cvd_version));
  5589. pr_debug("%s: Fall back to default value, CVD Version = %s\n",
  5590. __func__, common.cvd_version);
  5591. v->mvm_state = CMD_STATUS_SUCCESS;
  5592. v->async_err = ptr[1];
  5593. wake_up(&v->mvm_wait);
  5594. break;
  5595. default:
  5596. pr_debug("%s: not match cmd = 0x%x\n",
  5597. __func__, ptr[0]);
  5598. break;
  5599. }
  5600. }
  5601. } else if (data->opcode == VSS_IMEMORY_RSP_MAP) {
  5602. pr_debug("%s, Revd VSS_IMEMORY_RSP_MAP response\n", __func__);
  5603. if (data->payload_size && data->token == VOIP_MEM_MAP_TOKEN) {
  5604. ptr = data->payload;
  5605. if (ptr[0]) {
  5606. v->shmem_info.mem_handle = ptr[0];
  5607. pr_debug("%s: shared mem_handle: 0x[%x]\n",
  5608. __func__, v->shmem_info.mem_handle);
  5609. v->mvm_state = CMD_STATUS_SUCCESS;
  5610. wake_up(&v->mvm_wait);
  5611. }
  5612. } else if (data->payload_size &&
  5613. data->token == VOC_CAL_MEM_MAP_TOKEN) {
  5614. ptr = data->payload;
  5615. if (ptr[0]) {
  5616. c->cal_mem_handle = ptr[0];
  5617. pr_debug("%s: cal mem handle 0x%x\n",
  5618. __func__, c->cal_mem_handle);
  5619. v->mvm_state = CMD_STATUS_SUCCESS;
  5620. wake_up(&v->mvm_wait);
  5621. }
  5622. } else if (data->payload_size &&
  5623. data->token == VOC_VOICE_HOST_PCM_MAP_TOKEN) {
  5624. ptr = data->payload;
  5625. if (ptr[0]) {
  5626. common.voice_host_pcm_mem_handle = ptr[0];
  5627. pr_debug("%s: vhpcm mem handle 0x%x\n",
  5628. __func__,
  5629. common.voice_host_pcm_mem_handle);
  5630. v->mvm_state = CMD_STATUS_SUCCESS;
  5631. wake_up(&v->mvm_wait);
  5632. }
  5633. } else if (data->payload_size &&
  5634. data->token == VOC_RTAC_MEM_MAP_TOKEN) {
  5635. ptr = data->payload;
  5636. if (ptr[0]) {
  5637. c->rtac_mem_handle = ptr[0];
  5638. pr_debug("%s: cal mem handle 0x%x\n",
  5639. __func__, c->rtac_mem_handle);
  5640. v->mvm_state = CMD_STATUS_SUCCESS;
  5641. wake_up(&v->mvm_wait);
  5642. }
  5643. } else if (data->payload_size &&
  5644. data->token == VOC_SOURCE_TRACKING_MEM_MAP_TOKEN) {
  5645. ptr = data->payload;
  5646. if (ptr[0]) {
  5647. common.source_tracking_sh_mem.mem_handle =
  5648. ptr[0];
  5649. pr_debug("%s: Source Tracking shared mem handle 0x%x\n",
  5650. __func__,
  5651. common.source_tracking_sh_mem.mem_handle);
  5652. v->mvm_state = CMD_STATUS_SUCCESS;
  5653. wake_up(&v->mvm_wait);
  5654. }
  5655. } else {
  5656. pr_err("%s: Unknown mem map token %d\n",
  5657. __func__, data->token);
  5658. }
  5659. } else if (data->opcode == VSS_IVERSION_RSP_GET) {
  5660. pr_debug("%s: Received VSS_IVERSION_RSP_GET\n", __func__);
  5661. if (data->payload_size) {
  5662. version_rsp =
  5663. (struct vss_iversion_rsp_get_t *)data->payload;
  5664. memcpy(common.cvd_version, version_rsp->version,
  5665. CVD_VERSION_STRING_MAX_SIZE);
  5666. pr_debug("%s: CVD Version = %s\n",
  5667. __func__, common.cvd_version);
  5668. v->mvm_state = CMD_STATUS_SUCCESS;
  5669. wake_up(&v->mvm_wait);
  5670. }
  5671. }
  5672. return 0;
  5673. }
  5674. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
  5675. {
  5676. uint32_t *ptr = NULL;
  5677. struct common_data *c = NULL;
  5678. struct voice_data *v = NULL;
  5679. int i = 0;
  5680. if ((data == NULL) || (priv == NULL)) {
  5681. pr_err("%s: data or priv is NULL\n", __func__);
  5682. return -EINVAL;
  5683. }
  5684. c = priv;
  5685. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  5686. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  5687. data->payload_size, data->opcode);
  5688. if (data->opcode == RESET_EVENTS) {
  5689. pr_debug("%s: Reset event received in Voice service\n",
  5690. __func__);
  5691. apr_reset(c->apr_q6_cvs);
  5692. c->apr_q6_cvs = NULL;
  5693. /* Sub-system restart is applicable to all sessions. */
  5694. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  5695. c->voice[i].cvs_handle = 0;
  5696. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  5697. common.cal_data);
  5698. /* Free the ION memory and clear handles for Source Tracking */
  5699. if (is_source_tracking_shared_memomry_allocated()) {
  5700. msm_audio_ion_free(
  5701. common.source_tracking_sh_mem.sh_mem_block.client,
  5702. common.source_tracking_sh_mem.sh_mem_block.handle);
  5703. common.source_tracking_sh_mem.mem_handle = 0;
  5704. common.source_tracking_sh_mem.sh_mem_block.client =
  5705. NULL;
  5706. common.source_tracking_sh_mem.sh_mem_block.handle =
  5707. NULL;
  5708. }
  5709. voc_set_error_state(data->reset_proc);
  5710. return 0;
  5711. }
  5712. v = voice_get_session_by_idx(data->dest_port);
  5713. if (v == NULL) {
  5714. pr_err("%s: v is NULL\n", __func__);
  5715. return -EINVAL;
  5716. }
  5717. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5718. if (data->payload_size) {
  5719. ptr = data->payload;
  5720. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5721. if (ptr[1] != 0) {
  5722. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  5723. __func__, ptr[0], ptr[1]);
  5724. }
  5725. /*response from CVS */
  5726. switch (ptr[0]) {
  5727. case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  5728. case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
  5729. if (!ptr[1]) {
  5730. pr_debug("%s: CVS handle is %d\n",
  5731. __func__, data->src_port);
  5732. voice_set_cvs_handle(v, data->src_port);
  5733. } else
  5734. pr_err("got NACK for sending CVS create session\n");
  5735. v->cvs_state = CMD_STATUS_SUCCESS;
  5736. v->async_err = ptr[1];
  5737. wake_up(&v->cvs_wait);
  5738. break;
  5739. case VSS_IVOLUME_CMD_MUTE_V2:
  5740. case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
  5741. case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
  5742. case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
  5743. case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
  5744. case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
  5745. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5746. case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2:
  5747. case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
  5748. case VSS_ISTREAM_CMD_REGISTER_STATIC_CALIBRATION_DATA:
  5749. case VSS_ISTREAM_CMD_DEREGISTER_STATIC_CALIBRATION_DATA:
  5750. case VSS_ICOMMON_CMD_MAP_MEMORY:
  5751. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  5752. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  5753. case VSS_IPLAYBACK_CMD_START:
  5754. case VSS_IPLAYBACK_CMD_STOP:
  5755. case VSS_IRECORD_CMD_START:
  5756. case VSS_IRECORD_CMD_STOP:
  5757. case VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE:
  5758. case VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG:
  5759. case VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION:
  5760. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5761. v->cvs_state = CMD_STATUS_SUCCESS;
  5762. v->async_err = ptr[1];
  5763. wake_up(&v->cvs_wait);
  5764. break;
  5765. case VSS_ICOMMON_CMD_SET_PARAM_V2:
  5766. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2\n",
  5767. __func__);
  5768. rtac_make_voice_callback(RTAC_CVS, ptr,
  5769. data->payload_size);
  5770. break;
  5771. case VSS_ICOMMON_CMD_GET_PARAM_V2:
  5772. pr_debug("%s: VSS_ICOMMON_CMD_GET_PARAM_V2\n",
  5773. __func__);
  5774. /* Should only come here if there is an APR */
  5775. /* error or malformed APR packet. Otherwise */
  5776. /* response will be returned as */
  5777. /* VSS_ICOMMON_RSP_GET_PARAM */
  5778. if (ptr[1] != 0) {
  5779. pr_err("%s: CVP get param error = %d, resuming\n",
  5780. __func__, ptr[1]);
  5781. rtac_make_voice_callback(RTAC_CVP,
  5782. data->payload,
  5783. data->payload_size);
  5784. }
  5785. break;
  5786. default:
  5787. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5788. break;
  5789. }
  5790. }
  5791. } else if (data->opcode ==
  5792. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_READY) {
  5793. int ret = 0;
  5794. u16 cvs_handle;
  5795. uint32_t *cvs_voc_pkt;
  5796. struct cvs_enc_buffer_consumed_cmd send_enc_buf_consumed_cmd;
  5797. void *apr_cvs;
  5798. pr_debug("Encoder buffer is ready\n");
  5799. apr_cvs = common.apr_q6_cvs;
  5800. if (!apr_cvs) {
  5801. pr_err("%s: apr_cvs is NULL\n", __func__);
  5802. return -EINVAL;
  5803. }
  5804. cvs_handle = voice_get_cvs_handle(v);
  5805. send_enc_buf_consumed_cmd.hdr.hdr_field =
  5806. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  5807. APR_HDR_LEN(APR_HDR_SIZE),
  5808. APR_PKT_VER);
  5809. send_enc_buf_consumed_cmd.hdr.pkt_size =
  5810. APR_PKT_SIZE(APR_HDR_SIZE,
  5811. sizeof(send_enc_buf_consumed_cmd) - APR_HDR_SIZE);
  5812. send_enc_buf_consumed_cmd.hdr.src_port =
  5813. voice_get_idx_for_session(v->session_id);
  5814. send_enc_buf_consumed_cmd.hdr.dest_port = cvs_handle;
  5815. send_enc_buf_consumed_cmd.hdr.token = 0;
  5816. send_enc_buf_consumed_cmd.hdr.opcode =
  5817. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_CONSUMED;
  5818. cvs_voc_pkt = v->shmem_info.sh_buf.buf[1].data;
  5819. if (cvs_voc_pkt != NULL && common.mvs_info.ul_cb != NULL) {
  5820. /* cvs_voc_pkt[0] contains tx timestamp */
  5821. common.mvs_info.ul_cb((uint8_t *)&cvs_voc_pkt[3],
  5822. cvs_voc_pkt[2],
  5823. cvs_voc_pkt[0],
  5824. common.mvs_info.private_data);
  5825. } else
  5826. pr_err("%s: cvs_voc_pkt or ul_cb is NULL\n", __func__);
  5827. ret = apr_send_pkt(apr_cvs,
  5828. (uint32_t *) &send_enc_buf_consumed_cmd);
  5829. if (ret < 0) {
  5830. pr_err("%s: Err send ENC_BUF_CONSUMED_NOTIFY %d\n",
  5831. __func__, ret);
  5832. goto fail;
  5833. }
  5834. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
  5835. pr_debug("Recd VSS_ISTREAM_EVT_SEND_ENC_BUFFER\n");
  5836. } else if (data->opcode ==
  5837. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_REQUEST) {
  5838. int ret = 0;
  5839. u16 cvs_handle;
  5840. uint32_t *cvs_voc_pkt;
  5841. struct cvs_dec_buffer_ready_cmd send_dec_buf;
  5842. void *apr_cvs;
  5843. apr_cvs = common.apr_q6_cvs;
  5844. if (!apr_cvs) {
  5845. pr_err("%s: apr_cvs is NULL\n", __func__);
  5846. return -EINVAL;
  5847. }
  5848. cvs_handle = voice_get_cvs_handle(v);
  5849. send_dec_buf.hdr.hdr_field =
  5850. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  5851. APR_HDR_LEN(APR_HDR_SIZE),
  5852. APR_PKT_VER);
  5853. send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  5854. sizeof(send_dec_buf) - APR_HDR_SIZE);
  5855. send_dec_buf.hdr.src_port =
  5856. voice_get_idx_for_session(v->session_id);
  5857. send_dec_buf.hdr.dest_port = cvs_handle;
  5858. send_dec_buf.hdr.token = 0;
  5859. send_dec_buf.hdr.opcode =
  5860. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_READY;
  5861. cvs_voc_pkt = (uint32_t *)(v->shmem_info.sh_buf.buf[0].data);
  5862. if (cvs_voc_pkt != NULL && common.mvs_info.dl_cb != NULL) {
  5863. /* Set timestamp to 0 and advance the pointer */
  5864. cvs_voc_pkt[0] = 0;
  5865. /* Set media_type and advance the pointer */
  5866. cvs_voc_pkt[1] = common.mvs_info.media_type;
  5867. common.mvs_info.dl_cb(
  5868. (uint8_t *)&cvs_voc_pkt[2],
  5869. common.mvs_info.private_data);
  5870. ret = apr_send_pkt(apr_cvs, (uint32_t *) &send_dec_buf);
  5871. if (ret < 0) {
  5872. pr_err("%s: Err send DEC_BUF_READY_NOTIFI %d\n",
  5873. __func__, ret);
  5874. goto fail;
  5875. }
  5876. } else {
  5877. pr_debug("%s: voc_pkt or dl_cb is NULL\n", __func__);
  5878. goto fail;
  5879. }
  5880. } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
  5881. pr_debug("Recd VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER\n");
  5882. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
  5883. pr_debug("Send dec buf resp\n");
  5884. } else if (data->opcode == APR_RSP_ACCEPTED) {
  5885. ptr = data->payload;
  5886. if (ptr[0])
  5887. pr_debug("%s: APR_RSP_ACCEPTED for 0x%x:\n",
  5888. __func__, ptr[0]);
  5889. } else if (data->opcode == VSS_ISTREAM_EVT_NOT_READY) {
  5890. pr_debug("Recd VSS_ISTREAM_EVT_NOT_READY\n");
  5891. } else if (data->opcode == VSS_ISTREAM_EVT_READY) {
  5892. pr_debug("Recd VSS_ISTREAM_EVT_READY\n");
  5893. } else if (data->opcode == VSS_ICOMMON_RSP_GET_PARAM) {
  5894. pr_debug("%s: VSS_ICOMMON_RSP_GET_PARAM\n", __func__);
  5895. ptr = data->payload;
  5896. if (ptr[0] != 0) {
  5897. pr_err("%s: VSS_ICOMMON_RSP_GET_PARAM returned error = 0x%x\n",
  5898. __func__, ptr[0]);
  5899. }
  5900. rtac_make_voice_callback(RTAC_CVS, data->payload,
  5901. data->payload_size);
  5902. } else if (data->opcode == VSS_ISTREAM_EVT_RX_DTMF_DETECTED) {
  5903. struct vss_istream_evt_rx_dtmf_detected *dtmf_rx_detected;
  5904. uint32_t *voc_pkt = data->payload;
  5905. uint32_t pkt_len = data->payload_size;
  5906. if ((voc_pkt != NULL) &&
  5907. (pkt_len ==
  5908. sizeof(struct vss_istream_evt_rx_dtmf_detected))) {
  5909. dtmf_rx_detected =
  5910. (struct vss_istream_evt_rx_dtmf_detected *) voc_pkt;
  5911. pr_debug("RX_DTMF_DETECTED low_freq=%d high_freq=%d\n",
  5912. dtmf_rx_detected->low_freq,
  5913. dtmf_rx_detected->high_freq);
  5914. if (c->dtmf_info.dtmf_rx_ul_cb)
  5915. c->dtmf_info.dtmf_rx_ul_cb((uint8_t *)voc_pkt,
  5916. voc_get_session_name(v->session_id),
  5917. c->dtmf_info.private_data);
  5918. } else {
  5919. pr_err("Invalid packet\n");
  5920. }
  5921. } else
  5922. pr_debug("Unknown opcode 0x%x\n", data->opcode);
  5923. fail:
  5924. return 0;
  5925. }
  5926. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
  5927. {
  5928. uint32_t *ptr = NULL;
  5929. struct common_data *c = NULL;
  5930. struct voice_data *v = NULL;
  5931. int i = 0;
  5932. if ((data == NULL) || (priv == NULL)) {
  5933. pr_err("%s: data or priv is NULL\n", __func__);
  5934. return -EINVAL;
  5935. }
  5936. c = priv;
  5937. if (data->opcode == RESET_EVENTS) {
  5938. pr_debug("%s: Reset event received in Voice service\n",
  5939. __func__);
  5940. apr_reset(c->apr_q6_cvp);
  5941. c->apr_q6_cvp = NULL;
  5942. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  5943. common.cal_data);
  5944. /* Sub-system restart is applicable to all sessions. */
  5945. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  5946. c->voice[i].cvp_handle = 0;
  5947. /*
  5948. * Free the ION memory and clear handles for
  5949. * Source Tracking
  5950. */
  5951. if (is_source_tracking_shared_memomry_allocated()) {
  5952. msm_audio_ion_free(
  5953. common.source_tracking_sh_mem.sh_mem_block.client,
  5954. common.source_tracking_sh_mem.sh_mem_block.handle);
  5955. common.source_tracking_sh_mem.mem_handle = 0;
  5956. common.source_tracking_sh_mem.sh_mem_block.client =
  5957. NULL;
  5958. common.source_tracking_sh_mem.sh_mem_block.handle =
  5959. NULL;
  5960. }
  5961. voc_set_error_state(data->reset_proc);
  5962. return 0;
  5963. }
  5964. v = voice_get_session_by_idx(data->dest_port);
  5965. if (v == NULL) {
  5966. pr_err("%s: v is NULL\n", __func__);
  5967. return -EINVAL;
  5968. }
  5969. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5970. if (data->payload_size) {
  5971. ptr = data->payload;
  5972. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5973. if (ptr[1] != 0) {
  5974. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  5975. __func__, ptr[0], ptr[1]);
  5976. }
  5977. switch (ptr[0]) {
  5978. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2:
  5979. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V3:
  5980. /*response from CVP */
  5981. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5982. if (!ptr[1]) {
  5983. voice_set_cvp_handle(v, data->src_port);
  5984. pr_debug("status: %d, cvphdl=%d\n",
  5985. ptr[1], data->src_port);
  5986. } else
  5987. pr_err("got NACK from CVP create session response\n");
  5988. v->cvp_state = CMD_STATUS_SUCCESS;
  5989. v->async_err = ptr[1];
  5990. wake_up(&v->cvp_wait);
  5991. break;
  5992. case VSS_IVOCPROC_CMD_SET_DEVICE_V2:
  5993. case VSS_IVOCPROC_CMD_SET_DEVICE_V3:
  5994. case VSS_IVOLUME_CMD_SET_STEP:
  5995. case VSS_IVOCPROC_CMD_ENABLE:
  5996. case VSS_IVOCPROC_CMD_DISABLE:
  5997. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5998. case VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA:
  5999. case VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA:
  6000. case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2:
  6001. case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
  6002. case VSS_IVOCPROC_CMD_REGISTER_DYNAMIC_CALIBRATION_DATA:
  6003. case VSS_IVOCPROC_CMD_DEREGISTER_DYNAMIC_CALIBRATION_DATA:
  6004. case VSS_IVOCPROC_CMD_REGISTER_STATIC_CALIBRATION_DATA:
  6005. case VSS_IVOCPROC_CMD_DEREGISTER_STATIC_CALIBRATION_DATA:
  6006. case VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG:
  6007. case VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG:
  6008. case VSS_ICOMMON_CMD_MAP_MEMORY:
  6009. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  6010. case VSS_IVOLUME_CMD_MUTE_V2:
  6011. case VSS_IVPCM_CMD_START_V2:
  6012. case VSS_IVPCM_CMD_STOP:
  6013. case VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS:
  6014. case VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT:
  6015. v->cvp_state = CMD_STATUS_SUCCESS;
  6016. v->async_err = ptr[1];
  6017. wake_up(&v->cvp_wait);
  6018. break;
  6019. case VSS_IVPCM_EVT_PUSH_BUFFER_V2:
  6020. break;
  6021. case VSS_ICOMMON_CMD_SET_PARAM_V2:
  6022. switch (data->token) {
  6023. case VOC_SET_MEDIA_FORMAT_PARAM_TOKEN:
  6024. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2 called by voice_send_cvp_media_format_cmd\n",
  6025. __func__);
  6026. v->cvp_state = CMD_STATUS_SUCCESS;
  6027. v->async_err = ptr[1];
  6028. wake_up(&v->cvp_wait);
  6029. break;
  6030. case VOC_RTAC_SET_PARAM_TOKEN:
  6031. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2 called by rtac\n",
  6032. __func__);
  6033. rtac_make_voice_callback(
  6034. RTAC_CVP, ptr,
  6035. data->payload_size);
  6036. break;
  6037. default:
  6038. pr_debug("%s: invalid token for command VSS_ICOMMON_CMD_SET_PARAM_V2: %d\n",
  6039. __func__, data->token);
  6040. break;
  6041. }
  6042. break;
  6043. case VSS_ICOMMON_CMD_GET_PARAM_V2:
  6044. pr_debug("%s: VSS_ICOMMON_CMD_GET_PARAM_V2\n",
  6045. __func__);
  6046. /* Should only come here if there is an APR */
  6047. /* error or malformed APR packet. Otherwise */
  6048. /* response will be returned as */
  6049. /* VSS_ICOMMON_RSP_GET_PARAM */
  6050. if (ptr[1] != 0) {
  6051. pr_err("%s: CVP get param error = %d, resuming\n",
  6052. __func__, ptr[1]);
  6053. rtac_make_voice_callback(RTAC_CVP,
  6054. data->payload,
  6055. data->payload_size);
  6056. }
  6057. break;
  6058. case VSS_ISOUNDFOCUS_CMD_SET_SECTORS:
  6059. if (!ptr[1])
  6060. common.is_sound_focus_resp_success =
  6061. true;
  6062. else
  6063. common.is_sound_focus_resp_success =
  6064. false;
  6065. v->cvp_state = CMD_STATUS_SUCCESS;
  6066. v->async_err = ptr[1];
  6067. wake_up(&v->cvp_wait);
  6068. break;
  6069. case VSS_ISOUNDFOCUS_CMD_GET_SECTORS:
  6070. /*
  6071. * Should only come here if there is an error
  6072. * response received from ADSP. Otherwise
  6073. * response will be returned as
  6074. * VSS_ISOUNDFOCUS_RSP_GET_SECTORS
  6075. */
  6076. pr_err("%s: VSS_ISOUNDFOCUS_CMD_GET_SECTORS failed\n",
  6077. __func__);
  6078. common.is_sound_focus_resp_success = false;
  6079. v->cvp_state = CMD_STATUS_SUCCESS;
  6080. v->async_err = ptr[1];
  6081. wake_up(&v->cvp_wait);
  6082. break;
  6083. case VSS_ISOURCETRACK_CMD_GET_ACTIVITY:
  6084. if (!ptr[1]) {
  6085. /* Read data from shared memory */
  6086. memcpy(&common.sourceTrackingResponse,
  6087. common.source_tracking_sh_mem.
  6088. sh_mem_block.data,
  6089. sizeof(struct
  6090. vss_isourcetrack_activity_data_t));
  6091. common.is_source_tracking_resp_success =
  6092. true;
  6093. } else {
  6094. common.is_source_tracking_resp_success =
  6095. false;
  6096. pr_err("%s: Error received for source tracking params\n",
  6097. __func__);
  6098. }
  6099. v->cvp_state = CMD_STATUS_SUCCESS;
  6100. v->async_err = ptr[1];
  6101. wake_up(&v->cvp_wait);
  6102. break;
  6103. default:
  6104. pr_debug("%s: not match cmd = 0x%x\n",
  6105. __func__, ptr[0]);
  6106. break;
  6107. }
  6108. }
  6109. } else if (data->opcode == VSS_ICOMMON_RSP_GET_PARAM) {
  6110. pr_debug("%s: VSS_ICOMMON_RSP_GET_PARAM\n", __func__);
  6111. ptr = data->payload;
  6112. if (ptr[0] != 0) {
  6113. pr_err("%s: VSS_ICOMMON_RSP_GET_PARAM returned error = 0x%x\n",
  6114. __func__, ptr[0]);
  6115. }
  6116. rtac_make_voice_callback(RTAC_CVP, data->payload,
  6117. data->payload_size);
  6118. } else if (data->opcode == VSS_IVPCM_EVT_NOTIFY_V2) {
  6119. if ((data->payload != NULL) && data->payload_size ==
  6120. sizeof(struct vss_ivpcm_evt_notify_v2_t) &&
  6121. common.hostpcm_info.hostpcm_evt_cb != NULL) {
  6122. common.hostpcm_info.hostpcm_evt_cb(data->payload,
  6123. voc_get_session_name(v->session_id),
  6124. common.hostpcm_info.private_data);
  6125. }
  6126. } else if (data->opcode == VSS_ISOUNDFOCUS_RSP_GET_SECTORS) {
  6127. if (data->payload && (data->payload_size ==
  6128. sizeof(struct vss_isoundfocus_rsp_get_sectors_t))) {
  6129. common.is_sound_focus_resp_success = true;
  6130. memcpy(&common.soundFocusResponse,
  6131. (struct vss_isoundfocus_rsp_get_sectors_t *)
  6132. data->payload,
  6133. sizeof(struct
  6134. vss_isoundfocus_rsp_get_sectors_t));
  6135. } else {
  6136. common.is_sound_focus_resp_success = false;
  6137. pr_debug("%s: Invalid payload received from CVD\n",
  6138. __func__);
  6139. }
  6140. v->cvp_state = CMD_STATUS_SUCCESS;
  6141. wake_up(&v->cvp_wait);
  6142. }
  6143. return 0;
  6144. }
  6145. static int voice_free_oob_shared_mem(void)
  6146. {
  6147. int rc = 0;
  6148. int cnt = 0;
  6149. int bufcnt = NUM_OF_BUFFERS;
  6150. struct voice_data *v = voice_get_session(
  6151. common.voice[VOC_PATH_FULL].session_id);
  6152. mutex_lock(&common.common_lock);
  6153. if (v == NULL) {
  6154. pr_err("%s: v is NULL\n", __func__);
  6155. rc = -EINVAL;
  6156. goto done;
  6157. }
  6158. rc = msm_audio_ion_free(v->shmem_info.sh_buf.client,
  6159. v->shmem_info.sh_buf.handle);
  6160. v->shmem_info.sh_buf.client = NULL;
  6161. v->shmem_info.sh_buf.handle = NULL;
  6162. if (rc < 0) {
  6163. pr_err("%s: Error:%d freeing memory\n", __func__, rc);
  6164. goto done;
  6165. }
  6166. while (cnt < bufcnt) {
  6167. v->shmem_info.sh_buf.buf[cnt].data = NULL;
  6168. v->shmem_info.sh_buf.buf[cnt].phys = 0;
  6169. cnt++;
  6170. }
  6171. v->shmem_info.sh_buf.client = NULL;
  6172. v->shmem_info.sh_buf.handle = NULL;
  6173. done:
  6174. mutex_unlock(&common.common_lock);
  6175. return rc;
  6176. }
  6177. static int voice_alloc_oob_shared_mem(void)
  6178. {
  6179. int cnt = 0;
  6180. int rc = 0;
  6181. size_t len;
  6182. void *mem_addr;
  6183. dma_addr_t phys;
  6184. int bufsz = BUFFER_BLOCK_SIZE;
  6185. int bufcnt = NUM_OF_BUFFERS;
  6186. struct voice_data *v = voice_get_session(
  6187. common.voice[VOC_PATH_FULL].session_id);
  6188. mutex_lock(&common.common_lock);
  6189. if (v == NULL) {
  6190. pr_err("%s: v is NULL\n", __func__);
  6191. rc = -EINVAL;
  6192. goto done;
  6193. }
  6194. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.sh_buf.client),
  6195. &(v->shmem_info.sh_buf.handle),
  6196. bufsz*bufcnt,
  6197. &phys, &len,
  6198. &mem_addr);
  6199. if (rc < 0) {
  6200. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6201. __func__, rc);
  6202. goto done;
  6203. }
  6204. while (cnt < bufcnt) {
  6205. v->shmem_info.sh_buf.buf[cnt].data = mem_addr + (cnt * bufsz);
  6206. v->shmem_info.sh_buf.buf[cnt].phys = phys + (cnt * bufsz);
  6207. v->shmem_info.sh_buf.buf[cnt].size = bufsz;
  6208. cnt++;
  6209. }
  6210. pr_debug("%s buf[0].data:[%pK], buf[0].phys:[%pK], &buf[0].phys:[%pK],\n",
  6211. __func__,
  6212. (void *)v->shmem_info.sh_buf.buf[0].data,
  6213. &v->shmem_info.sh_buf.buf[0].phys,
  6214. (void *)&v->shmem_info.sh_buf.buf[0].phys);
  6215. pr_debug("%s: buf[1].data:[%pK], buf[1].phys[%pK], &buf[1].phys[%pK]\n",
  6216. __func__,
  6217. (void *)v->shmem_info.sh_buf.buf[1].data,
  6218. &v->shmem_info.sh_buf.buf[1].phys,
  6219. (void *)&v->shmem_info.sh_buf.buf[1].phys);
  6220. memset((void *)v->shmem_info.sh_buf.buf[0].data, 0, (bufsz * bufcnt));
  6221. done:
  6222. mutex_unlock(&common.common_lock);
  6223. return rc;
  6224. }
  6225. static int voice_alloc_oob_mem_table(void)
  6226. {
  6227. int rc = 0;
  6228. size_t len;
  6229. struct voice_data *v = voice_get_session(
  6230. common.voice[VOC_PATH_FULL].session_id);
  6231. mutex_lock(&common.common_lock);
  6232. if (v == NULL) {
  6233. pr_err("%s: v is NULL\n", __func__);
  6234. rc = -EINVAL;
  6235. goto done;
  6236. }
  6237. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.memtbl.client),
  6238. &(v->shmem_info.memtbl.handle),
  6239. sizeof(struct vss_imemory_table_t),
  6240. &v->shmem_info.memtbl.phys,
  6241. &len,
  6242. &(v->shmem_info.memtbl.data));
  6243. if (rc < 0) {
  6244. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6245. __func__, rc);
  6246. goto done;
  6247. }
  6248. v->shmem_info.memtbl.size = sizeof(struct vss_imemory_table_t);
  6249. pr_debug("%s data[%pK]phys[%pK][%pK]\n", __func__,
  6250. (void *)v->shmem_info.memtbl.data,
  6251. &v->shmem_info.memtbl.phys,
  6252. (void *)&v->shmem_info.memtbl.phys);
  6253. done:
  6254. mutex_unlock(&common.common_lock);
  6255. return rc;
  6256. }
  6257. int voc_send_cvp_start_vocpcm(uint32_t session_id,
  6258. struct vss_ivpcm_tap_point *vpcm_tp,
  6259. uint32_t no_of_tp)
  6260. {
  6261. struct cvp_start_cmd cvp_start_cmd;
  6262. int ret = 0;
  6263. void *apr_cvp;
  6264. u16 cvp_handle;
  6265. struct voice_data *v = voice_get_session(session_id);
  6266. int i = 0;
  6267. if (v == NULL) {
  6268. pr_err("%s: v is NULL\n", __func__);
  6269. ret = -EINVAL;
  6270. goto done;
  6271. }
  6272. apr_cvp = common.apr_q6_cvp;
  6273. if (!apr_cvp) {
  6274. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6275. ret = -EINVAL;
  6276. goto done;
  6277. }
  6278. cvp_handle = voice_get_cvp_handle(v);
  6279. /* Fill the header */
  6280. cvp_start_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6281. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6282. cvp_start_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6283. sizeof(struct vss_ivpcm_tap_point) * no_of_tp) +
  6284. sizeof(cvp_start_cmd.vpcm_start_cmd.num_tap_points) +
  6285. sizeof(cvp_start_cmd.vpcm_start_cmd.mem_handle);
  6286. cvp_start_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  6287. cvp_start_cmd.hdr.dest_port = cvp_handle;
  6288. cvp_start_cmd.hdr.token = 0;
  6289. cvp_start_cmd.hdr.opcode = VSS_IVPCM_CMD_START_V2;
  6290. for (i = 0; i < no_of_tp; i++) {
  6291. cvp_start_cmd.vpcm_start_cmd.tap_points[i].tap_point =
  6292. vpcm_tp[i].tap_point;
  6293. cvp_start_cmd.vpcm_start_cmd.tap_points[i].direction =
  6294. vpcm_tp[i].direction;
  6295. cvp_start_cmd.vpcm_start_cmd.tap_points[i].sampling_rate =
  6296. vpcm_tp[i].sampling_rate;
  6297. cvp_start_cmd.vpcm_start_cmd.tap_points[i].duration = 0;
  6298. }
  6299. cvp_start_cmd.vpcm_start_cmd.mem_handle =
  6300. common.voice_host_pcm_mem_handle;
  6301. cvp_start_cmd.vpcm_start_cmd.num_tap_points = no_of_tp;
  6302. v->cvp_state = CMD_STATUS_FAIL;
  6303. v->async_err = 0;
  6304. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_start_cmd);
  6305. if (ret < 0) {
  6306. pr_err("%s: Fail: sending vocpcm map memory,\n", __func__);
  6307. goto done;
  6308. }
  6309. ret = wait_event_timeout(v->cvp_wait,
  6310. (v->cvp_state == CMD_STATUS_SUCCESS),
  6311. msecs_to_jiffies(TIMEOUT_MS));
  6312. if (!ret) {
  6313. pr_err("%s: wait_event timeout\n", __func__);
  6314. goto done;
  6315. }
  6316. if (v->async_err > 0) {
  6317. pr_err("%s: DSP returned error[%s]\n",
  6318. __func__, adsp_err_get_err_str(
  6319. v->async_err));
  6320. ret = adsp_err_get_lnx_err_code(
  6321. v->async_err);
  6322. goto done;
  6323. }
  6324. done:
  6325. return ret;
  6326. }
  6327. int voc_send_cvp_stop_vocpcm(uint32_t session_id)
  6328. {
  6329. struct cvp_command vpcm_stop_cmd;
  6330. int ret = 0;
  6331. void *apr_cvp;
  6332. u16 cvp_handle;
  6333. struct voice_data *v = voice_get_session(session_id);
  6334. if (v == NULL) {
  6335. pr_err("%s: v is NULL\n", __func__);
  6336. ret = -EINVAL;
  6337. goto done;
  6338. }
  6339. apr_cvp = common.apr_q6_cvp;
  6340. if (!apr_cvp) {
  6341. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6342. ret = -EINVAL;
  6343. goto done;
  6344. }
  6345. cvp_handle = voice_get_cvp_handle(v);
  6346. /* fill in the header */
  6347. vpcm_stop_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6348. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6349. vpcm_stop_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6350. sizeof(vpcm_stop_cmd) - APR_HDR_SIZE);
  6351. vpcm_stop_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  6352. vpcm_stop_cmd.hdr.dest_port = cvp_handle;
  6353. vpcm_stop_cmd.hdr.token = 0;
  6354. vpcm_stop_cmd.hdr.opcode = VSS_IVPCM_CMD_STOP;
  6355. v->cvp_state = CMD_STATUS_FAIL;
  6356. v->async_err = 0;
  6357. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_stop_cmd);
  6358. if (ret < 0) {
  6359. pr_err("Fail: sending vocpcm stop,\n");
  6360. goto done;
  6361. }
  6362. ret = wait_event_timeout(v->cvp_wait,
  6363. (v->cvp_state == CMD_STATUS_SUCCESS),
  6364. msecs_to_jiffies(TIMEOUT_MS));
  6365. if (!ret) {
  6366. pr_err("%s: wait_event timeout\n", __func__);
  6367. goto done;
  6368. }
  6369. if (v->async_err > 0) {
  6370. pr_err("%s: DSP returned error[%s]\n",
  6371. __func__, adsp_err_get_err_str(
  6372. v->async_err));
  6373. ret = adsp_err_get_lnx_err_code(
  6374. v->async_err);
  6375. goto done;
  6376. }
  6377. done:
  6378. return ret;
  6379. }
  6380. int voc_send_cvp_map_vocpcm_memory(uint32_t session_id,
  6381. struct mem_map_table *tp_mem_table,
  6382. phys_addr_t paddr, uint32_t bufsize)
  6383. {
  6384. return voice_map_memory_physical_cmd(voice_get_session(session_id),
  6385. tp_mem_table,
  6386. (dma_addr_t) paddr, bufsize,
  6387. VOC_VOICE_HOST_PCM_MAP_TOKEN);
  6388. }
  6389. int voc_send_cvp_unmap_vocpcm_memory(uint32_t session_id)
  6390. {
  6391. int ret = 0;
  6392. ret = voice_send_mvm_unmap_memory_physical_cmd(
  6393. voice_get_session(session_id),
  6394. common.voice_host_pcm_mem_handle);
  6395. if (ret == 0)
  6396. common.voice_host_pcm_mem_handle = 0;
  6397. return ret;
  6398. }
  6399. int voc_send_cvp_vocpcm_push_buf_evt(uint32_t session_id,
  6400. struct vss_ivpcm_evt_push_buffer_v2_t *push_buff_evt)
  6401. {
  6402. struct cvp_push_buf_cmd vpcm_push_buf_cmd;
  6403. int ret = 0;
  6404. void *apr_cvp;
  6405. u16 cvp_handle;
  6406. struct voice_data *v = voice_get_session(session_id);
  6407. if (v == NULL) {
  6408. pr_err("%s: v is NULL\n", __func__);
  6409. ret = -EINVAL;
  6410. goto done;
  6411. }
  6412. apr_cvp = common.apr_q6_cvp;
  6413. if (!apr_cvp) {
  6414. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6415. ret = -EINVAL;
  6416. goto done;
  6417. }
  6418. memset(&vpcm_push_buf_cmd, 0, sizeof(vpcm_push_buf_cmd));
  6419. cvp_handle = voice_get_cvp_handle(v);
  6420. /* fill in the header */
  6421. vpcm_push_buf_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6422. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6423. vpcm_push_buf_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6424. sizeof(vpcm_push_buf_cmd) - APR_HDR_SIZE);
  6425. vpcm_push_buf_cmd.hdr.src_port =
  6426. voice_get_idx_for_session(v->session_id);
  6427. vpcm_push_buf_cmd.hdr.dest_port = cvp_handle;
  6428. vpcm_push_buf_cmd.hdr.token = 0;
  6429. vpcm_push_buf_cmd.hdr.opcode = VSS_IVPCM_EVT_PUSH_BUFFER_V2;
  6430. vpcm_push_buf_cmd.vpcm_evt_push_buffer.tap_point =
  6431. push_buff_evt->tap_point;
  6432. vpcm_push_buf_cmd.vpcm_evt_push_buffer.push_buf_mask =
  6433. push_buff_evt->push_buf_mask;
  6434. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_mem_address =
  6435. push_buff_evt->out_buf_mem_address;
  6436. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_mem_address =
  6437. push_buff_evt->in_buf_mem_address;
  6438. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_mem_size =
  6439. push_buff_evt->out_buf_mem_size;
  6440. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_mem_size =
  6441. push_buff_evt->in_buf_mem_size;
  6442. vpcm_push_buf_cmd.vpcm_evt_push_buffer.sampling_rate =
  6443. push_buff_evt->sampling_rate;
  6444. vpcm_push_buf_cmd.vpcm_evt_push_buffer.num_in_channels =
  6445. push_buff_evt->num_in_channels;
  6446. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_push_buf_cmd);
  6447. if (ret < 0) {
  6448. pr_err("Fail: sending vocpcm map memory,\n");
  6449. goto done;
  6450. }
  6451. done:
  6452. return ret;
  6453. }
  6454. void voc_register_hpcm_evt_cb(hostpcm_cb_fn hostpcm_cb,
  6455. void *private_data)
  6456. {
  6457. common.hostpcm_info.hostpcm_evt_cb = hostpcm_cb;
  6458. common.hostpcm_info.private_data = private_data;
  6459. }
  6460. void voc_deregister_hpcm_evt_cb(void)
  6461. {
  6462. common.hostpcm_info.hostpcm_evt_cb = NULL;
  6463. common.hostpcm_info.private_data = NULL;
  6464. }
  6465. int voc_get_cvd_version(char *cvd_version)
  6466. {
  6467. int ret = 0;
  6468. struct voice_data *v = voice_get_session(VOICE_SESSION_VSID);
  6469. if (v == NULL) {
  6470. pr_err("%s: invalid session_id 0x%x\n",
  6471. __func__, VOICE_SESSION_VSID);
  6472. ret = -EINVAL;
  6473. goto done;
  6474. }
  6475. if (is_cvd_version_queried()) {
  6476. pr_debug("%s: Returning the cached value %s\n",
  6477. __func__, common.cvd_version);
  6478. goto done;
  6479. }
  6480. /* Register callback to APR */
  6481. ret = voice_apr_register(VOICE_SESSION_VSID);
  6482. if (ret < 0) {
  6483. pr_err("%s: apr register failed\n", __func__);
  6484. goto done;
  6485. }
  6486. mutex_lock(&common.common_lock);
  6487. mutex_lock(&v->lock);
  6488. ret = voice_send_mvm_cvd_version_cmd(v);
  6489. if (ret < 0) {
  6490. pr_err("%s: voice_send_mvm_cvd_version_cmd failed\n", __func__);
  6491. goto unlock;
  6492. }
  6493. ret = 0;
  6494. unlock:
  6495. mutex_unlock(&v->lock);
  6496. mutex_unlock(&common.common_lock);
  6497. done:
  6498. if (cvd_version)
  6499. memcpy(cvd_version, common.cvd_version,
  6500. CVD_VERSION_STRING_MAX_SIZE);
  6501. return ret;
  6502. }
  6503. static int voice_alloc_cal_mem_map_table(void)
  6504. {
  6505. int ret = 0;
  6506. size_t len;
  6507. ret = msm_audio_ion_alloc("voc_cal",
  6508. &(common.cal_mem_map_table.client),
  6509. &(common.cal_mem_map_table.handle),
  6510. sizeof(struct vss_imemory_table_t),
  6511. &common.cal_mem_map_table.phys,
  6512. &len,
  6513. &(common.cal_mem_map_table.data));
  6514. if ((ret < 0) && (ret != -EPROBE_DEFER)) {
  6515. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6516. __func__, ret);
  6517. goto done;
  6518. }
  6519. common.cal_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  6520. pr_debug("%s: data %pK phys %pK\n", __func__,
  6521. common.cal_mem_map_table.data,
  6522. &common.cal_mem_map_table.phys);
  6523. done:
  6524. return ret;
  6525. }
  6526. static int voice_alloc_rtac_mem_map_table(void)
  6527. {
  6528. int ret = 0;
  6529. size_t len;
  6530. ret = msm_audio_ion_alloc("voc_rtac_cal",
  6531. &(common.rtac_mem_map_table.client),
  6532. &(common.rtac_mem_map_table.handle),
  6533. sizeof(struct vss_imemory_table_t),
  6534. &common.rtac_mem_map_table.phys,
  6535. &len,
  6536. &(common.rtac_mem_map_table.data));
  6537. if (ret < 0) {
  6538. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6539. __func__, ret);
  6540. goto done;
  6541. }
  6542. common.rtac_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  6543. pr_debug("%s: data %pK phys %pK\n", __func__,
  6544. common.rtac_mem_map_table.data,
  6545. &common.rtac_mem_map_table.phys);
  6546. done:
  6547. return ret;
  6548. }
  6549. static int voice_alloc_and_map_oob_mem(struct voice_data *v)
  6550. {
  6551. int ret = 0;
  6552. if (v == NULL) {
  6553. pr_err("%s: v is NULL\n", __func__);
  6554. return -EINVAL;
  6555. }
  6556. if (!is_voip_memory_allocated()) {
  6557. ret = voc_alloc_voip_shared_memory();
  6558. if (ret < 0) {
  6559. pr_err("%s: Failed to create voip oob memory %d\n",
  6560. __func__, ret);
  6561. goto done;
  6562. }
  6563. }
  6564. ret = voice_map_memory_physical_cmd(v,
  6565. &v->shmem_info.memtbl,
  6566. v->shmem_info.sh_buf.buf[0].phys,
  6567. v->shmem_info.sh_buf.buf[0].size * NUM_OF_BUFFERS,
  6568. VOIP_MEM_MAP_TOKEN);
  6569. if (ret) {
  6570. pr_err("%s: mvm_map_memory_phy failed %d\n",
  6571. __func__, ret);
  6572. goto done;
  6573. }
  6574. done:
  6575. return ret;
  6576. }
  6577. uint32_t voice_get_topology(uint32_t topology_idx)
  6578. {
  6579. uint32_t topology = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  6580. struct cal_block_data *cal_block = NULL;
  6581. /* initialize as default topology */
  6582. if (topology_idx == CVP_VOC_RX_TOPOLOGY_CAL) {
  6583. topology = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  6584. } else if (topology_idx == CVP_VOC_TX_TOPOLOGY_CAL) {
  6585. topology = VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
  6586. } else {
  6587. pr_err("%s: cal index %x is invalid!\n",
  6588. __func__, topology_idx);
  6589. goto done;
  6590. }
  6591. if (common.cal_data[topology_idx] == NULL) {
  6592. pr_err("%s: cal type is NULL for cal index %x\n",
  6593. __func__, topology_idx);
  6594. goto done;
  6595. }
  6596. mutex_lock(&common.cal_data[topology_idx]->lock);
  6597. cal_block = cal_utils_get_only_cal_block(
  6598. common.cal_data[topology_idx]);
  6599. if (cal_block == NULL) {
  6600. pr_debug("%s: cal_block not found for cal index %x\n",
  6601. __func__, topology_idx);
  6602. goto unlock;
  6603. }
  6604. topology = ((struct audio_cal_info_voc_top *)
  6605. cal_block->cal_info)->topology;
  6606. unlock:
  6607. mutex_unlock(&common.cal_data[topology_idx]->lock);
  6608. done:
  6609. pr_debug("%s: Using topology %d\n", __func__, topology);
  6610. return topology;
  6611. }
  6612. static int get_cal_type_index(int32_t cal_type)
  6613. {
  6614. int ret = -EINVAL;
  6615. switch (cal_type) {
  6616. case CVP_VOC_RX_TOPOLOGY_CAL_TYPE:
  6617. ret = CVP_VOC_RX_TOPOLOGY_CAL;
  6618. break;
  6619. case CVP_VOC_TX_TOPOLOGY_CAL_TYPE:
  6620. ret = CVP_VOC_TX_TOPOLOGY_CAL;
  6621. break;
  6622. case CVP_VOCPROC_STATIC_CAL_TYPE:
  6623. ret = CVP_VOCPROC_CAL;
  6624. break;
  6625. case CVP_VOCPROC_DYNAMIC_CAL_TYPE:
  6626. ret = CVP_VOCVOL_CAL;
  6627. break;
  6628. case CVS_VOCSTRM_STATIC_CAL_TYPE:
  6629. ret = CVS_VOCSTRM_CAL;
  6630. break;
  6631. case CVP_VOCDEV_CFG_CAL_TYPE:
  6632. ret = CVP_VOCDEV_CFG_CAL;
  6633. break;
  6634. case CVP_VOCPROC_STATIC_COL_CAL_TYPE:
  6635. ret = CVP_VOCPROC_COL_CAL;
  6636. break;
  6637. case CVP_VOCPROC_DYNAMIC_COL_CAL_TYPE:
  6638. ret = CVP_VOCVOL_COL_CAL;
  6639. break;
  6640. case CVS_VOCSTRM_STATIC_COL_CAL_TYPE:
  6641. ret = CVS_VOCSTRM_COL_CAL;
  6642. break;
  6643. case VOICE_RTAC_INFO_CAL_TYPE:
  6644. ret = VOICE_RTAC_INFO_CAL;
  6645. break;
  6646. case VOICE_RTAC_APR_CAL_TYPE:
  6647. ret = VOICE_RTAC_APR_CAL;
  6648. break;
  6649. default:
  6650. pr_err("%s: Invalid cal type %d!\n", __func__, cal_type);
  6651. }
  6652. return ret;
  6653. }
  6654. static int voice_prepare_volume_boost(int32_t cal_type,
  6655. size_t data_size, void *data)
  6656. {
  6657. return voc_deregister_vocproc_vol_table();
  6658. }
  6659. static int voice_enable_volume_boost(int32_t cal_type,
  6660. size_t data_size, void *data)
  6661. {
  6662. return voc_register_vocproc_vol_table();
  6663. }
  6664. static int voice_alloc_cal(int32_t cal_type,
  6665. size_t data_size, void *data)
  6666. {
  6667. int ret = 0;
  6668. int cal_index;
  6669. int cal_version;
  6670. pr_debug("%s\n", __func__);
  6671. cal_version = cal_utils_get_cal_type_version(data);
  6672. common.is_per_vocoder_cal_enabled =
  6673. !!(cal_version & PER_VOCODER_CAL_BIT_MASK);
  6674. cal_index = get_cal_type_index(cal_type);
  6675. if (cal_index < 0) {
  6676. pr_err("%s: Could not get cal index %d!\n",
  6677. __func__, cal_index);
  6678. ret = -EINVAL;
  6679. goto done;
  6680. }
  6681. ret = cal_utils_alloc_cal(data_size, data,
  6682. common.cal_data[cal_index], 0, NULL);
  6683. if (ret < 0) {
  6684. pr_err("%s: Cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
  6685. __func__, ret, cal_type);
  6686. ret = -EINVAL;
  6687. goto done;
  6688. }
  6689. done:
  6690. return ret;
  6691. }
  6692. static int voice_dealloc_cal(int32_t cal_type,
  6693. size_t data_size, void *data)
  6694. {
  6695. int ret = 0;
  6696. int cal_index;
  6697. pr_debug("%s\n", __func__);
  6698. cal_index = get_cal_type_index(cal_type);
  6699. if (cal_index < 0) {
  6700. pr_err("%s: Could not get cal index %d!\n",
  6701. __func__, cal_index);
  6702. ret = -EINVAL;
  6703. goto done;
  6704. }
  6705. ret = cal_utils_dealloc_cal(data_size, data,
  6706. common.cal_data[cal_index]);
  6707. if (ret < 0) {
  6708. pr_err("%s: Cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
  6709. __func__, ret, cal_type);
  6710. ret = -EINVAL;
  6711. goto done;
  6712. }
  6713. done:
  6714. return ret;
  6715. }
  6716. static int voice_set_cal(int32_t cal_type,
  6717. size_t data_size, void *data)
  6718. {
  6719. int ret = 0;
  6720. int cal_index;
  6721. pr_debug("%s\n", __func__);
  6722. cal_index = get_cal_type_index(cal_type);
  6723. if (cal_index < 0) {
  6724. pr_err("%s: Could not get cal index %d!\n",
  6725. __func__, cal_index);
  6726. ret = -EINVAL;
  6727. goto done;
  6728. }
  6729. ret = cal_utils_set_cal(data_size, data,
  6730. common.cal_data[cal_index], 0, NULL);
  6731. if (ret < 0) {
  6732. pr_err("%s: Cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
  6733. __func__, ret, cal_type);
  6734. ret = -EINVAL;
  6735. goto done;
  6736. }
  6737. done:
  6738. return ret;
  6739. }
  6740. static void voice_delete_cal_data(void)
  6741. {
  6742. pr_debug("%s\n", __func__);
  6743. cal_utils_destroy_cal_types(MAX_VOICE_CAL_TYPES, common.cal_data);
  6744. }
  6745. static int voice_init_cal_data(void)
  6746. {
  6747. int ret = 0;
  6748. struct cal_type_info cal_type_info[] = {
  6749. {{CVP_VOC_RX_TOPOLOGY_CAL_TYPE,
  6750. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  6751. {NULL, NULL, cal_utils_match_buf_num} },
  6752. {{CVP_VOC_TX_TOPOLOGY_CAL_TYPE,
  6753. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  6754. {NULL, NULL, cal_utils_match_buf_num} },
  6755. {{CVP_VOCPROC_STATIC_CAL_TYPE,
  6756. {voice_alloc_cal, voice_dealloc_cal, NULL,
  6757. voice_set_cal, NULL, NULL} },
  6758. {NULL, voice_unmap_cal_memory,
  6759. cal_utils_match_buf_num} },
  6760. {{CVP_VOCPROC_DYNAMIC_CAL_TYPE,
  6761. {voice_alloc_cal, voice_dealloc_cal,
  6762. voice_prepare_volume_boost,
  6763. voice_set_cal, NULL,
  6764. voice_enable_volume_boost} },
  6765. {NULL, voice_unmap_cal_memory,
  6766. cal_utils_match_buf_num} },
  6767. {{CVP_VOCDEV_CFG_CAL_TYPE,
  6768. {voice_alloc_cal, voice_dealloc_cal, NULL,
  6769. voice_set_cal, NULL, NULL} },
  6770. {NULL, voice_unmap_cal_memory,
  6771. cal_utils_match_buf_num} },
  6772. {{CVP_VOCPROC_STATIC_COL_CAL_TYPE,
  6773. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  6774. {NULL, NULL, cal_utils_match_buf_num} },
  6775. {{CVP_VOCPROC_DYNAMIC_COL_CAL_TYPE,
  6776. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  6777. {NULL, NULL, cal_utils_match_buf_num} },
  6778. {{CVS_VOCSTRM_STATIC_CAL_TYPE,
  6779. {voice_alloc_cal, voice_dealloc_cal, NULL,
  6780. voice_set_cal, NULL, NULL} },
  6781. {NULL, voice_unmap_cal_memory,
  6782. cal_utils_match_buf_num} },
  6783. {{CVS_VOCSTRM_STATIC_COL_CAL_TYPE,
  6784. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  6785. {NULL, NULL, cal_utils_match_buf_num} },
  6786. {{VOICE_RTAC_INFO_CAL_TYPE,
  6787. {NULL, NULL, NULL, NULL, NULL, NULL} },
  6788. {NULL, NULL, cal_utils_match_buf_num} },
  6789. {{VOICE_RTAC_APR_CAL_TYPE,
  6790. {NULL, NULL, NULL, NULL, NULL, NULL} },
  6791. {NULL, NULL, cal_utils_match_buf_num} },
  6792. };
  6793. ret = cal_utils_create_cal_types(MAX_VOICE_CAL_TYPES, common.cal_data,
  6794. cal_type_info);
  6795. if (ret < 0) {
  6796. pr_err("%s: Could not create cal type!\n",
  6797. __func__);
  6798. ret = -EINVAL;
  6799. goto err;
  6800. }
  6801. return ret;
  6802. err:
  6803. voice_delete_cal_data();
  6804. memset(&common, 0, sizeof(struct common_data));
  6805. return ret;
  6806. }
  6807. static int voice_send_set_sound_focus_cmd(struct voice_data *v,
  6808. struct sound_focus_param soundFocusData)
  6809. {
  6810. struct cvp_set_sound_focus_param_cmd_t cvp_set_sound_focus_param_cmd;
  6811. int ret = 0;
  6812. void *apr_cvp;
  6813. u16 cvp_handle;
  6814. int i;
  6815. pr_debug("%s: Enter\n", __func__);
  6816. if (v == NULL) {
  6817. pr_err("%s: v is NULL\n", __func__);
  6818. ret = -EINVAL;
  6819. goto done;
  6820. }
  6821. apr_cvp = common.apr_q6_cvp;
  6822. if (!apr_cvp) {
  6823. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6824. ret = -EINVAL;
  6825. goto done;
  6826. }
  6827. cvp_handle = voice_get_cvp_handle(v);
  6828. /* send Sound Focus Params to cvp */
  6829. cvp_set_sound_focus_param_cmd.hdr.hdr_field =
  6830. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6831. APR_HDR_LEN(APR_HDR_SIZE),
  6832. APR_PKT_VER);
  6833. cvp_set_sound_focus_param_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6834. sizeof(cvp_set_sound_focus_param_cmd) - APR_HDR_SIZE);
  6835. cvp_set_sound_focus_param_cmd.hdr.src_port =
  6836. voice_get_idx_for_session(v->session_id);
  6837. cvp_set_sound_focus_param_cmd.hdr.dest_port = cvp_handle;
  6838. cvp_set_sound_focus_param_cmd.hdr.token = 0;
  6839. cvp_set_sound_focus_param_cmd.hdr.opcode =
  6840. VSS_ISOUNDFOCUS_CMD_SET_SECTORS;
  6841. memset(&(cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param), 0xFF,
  6842. sizeof(struct vss_isoundfocus_cmd_set_sectors_t));
  6843. for (i = 0; i < MAX_SECTORS; i++) {
  6844. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.
  6845. start_angles[i] = soundFocusData.start_angle[i];
  6846. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.
  6847. enables[i] = soundFocusData.enable[i];
  6848. pr_debug("%s: start_angle[%d] = %d\n",
  6849. __func__, i, soundFocusData.start_angle[i]);
  6850. pr_debug("%s: enable[%d] = %d\n",
  6851. __func__, i, soundFocusData.enable[i]);
  6852. }
  6853. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.gain_step =
  6854. soundFocusData.gain_step;
  6855. pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
  6856. v->cvp_state = CMD_STATUS_FAIL;
  6857. v->async_err = 0;
  6858. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_set_sound_focus_param_cmd);
  6859. if (ret < 0) {
  6860. pr_err("%s: Error in sending APR command\n", __func__);
  6861. ret = -EINVAL;
  6862. goto done;
  6863. }
  6864. ret = wait_event_timeout(v->cvp_wait,
  6865. (v->cvp_state == CMD_STATUS_SUCCESS),
  6866. msecs_to_jiffies(TIMEOUT_MS));
  6867. if (!ret) {
  6868. pr_err("%s: wait_event timeout\n", __func__);
  6869. ret = -EINVAL;
  6870. goto done;
  6871. }
  6872. if (v->async_err > 0) {
  6873. pr_err("%s: DSP returned error[%s]\n",
  6874. __func__, adsp_err_get_err_str(
  6875. v->async_err));
  6876. ret = adsp_err_get_lnx_err_code(
  6877. v->async_err);
  6878. goto done;
  6879. }
  6880. if (common.is_sound_focus_resp_success) {
  6881. ret = 0;
  6882. } else {
  6883. pr_err("%s: Error in setting sound focus params\n", __func__);
  6884. ret = -EINVAL;
  6885. }
  6886. done:
  6887. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  6888. return ret;
  6889. }
  6890. int voc_set_sound_focus(struct sound_focus_param soundFocusData)
  6891. {
  6892. struct voice_data *v = NULL;
  6893. int ret = -EINVAL;
  6894. struct voice_session_itr itr;
  6895. pr_debug("%s: Enter\n", __func__);
  6896. mutex_lock(&common.common_lock);
  6897. voice_itr_init(&itr, ALL_SESSION_VSID);
  6898. while (voice_itr_get_next_session(&itr, &v)) {
  6899. if (v != NULL) {
  6900. mutex_lock(&v->lock);
  6901. if (is_voc_state_active(v->voc_state) &&
  6902. (v->lch_mode != VOICE_LCH_START) &&
  6903. !v->disable_topology)
  6904. ret = voice_send_set_sound_focus_cmd(v,
  6905. soundFocusData);
  6906. mutex_unlock(&v->lock);
  6907. } else {
  6908. pr_err("%s: invalid session\n", __func__);
  6909. ret = -EINVAL;
  6910. break;
  6911. }
  6912. }
  6913. mutex_unlock(&common.common_lock);
  6914. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  6915. return ret;
  6916. }
  6917. static int voice_send_get_sound_focus_cmd(struct voice_data *v,
  6918. struct sound_focus_param *soundFocusData)
  6919. {
  6920. struct apr_hdr cvp_get_sound_focus_param_cmd;
  6921. int ret = 0;
  6922. void *apr_cvp;
  6923. u16 cvp_handle;
  6924. int i;
  6925. pr_debug("%s: Enter\n", __func__);
  6926. if (!v) {
  6927. pr_err("%s: v is NULL\n", __func__);
  6928. ret = -EINVAL;
  6929. goto done;
  6930. }
  6931. apr_cvp = common.apr_q6_cvp;
  6932. if (!apr_cvp) {
  6933. pr_err("%s: apr_cvp is NULL\n", __func__);
  6934. ret = -EINVAL;
  6935. goto done;
  6936. }
  6937. cvp_handle = voice_get_cvp_handle(v);
  6938. /* send APR command to retrieve Sound Focus Params */
  6939. cvp_get_sound_focus_param_cmd.hdr_field =
  6940. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6941. APR_HDR_LEN(APR_HDR_SIZE),
  6942. APR_PKT_VER);
  6943. cvp_get_sound_focus_param_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6944. sizeof(cvp_get_sound_focus_param_cmd) - APR_HDR_SIZE);
  6945. cvp_get_sound_focus_param_cmd.src_port =
  6946. voice_get_idx_for_session(v->session_id);
  6947. cvp_get_sound_focus_param_cmd.dest_port = cvp_handle;
  6948. cvp_get_sound_focus_param_cmd.token = 0;
  6949. cvp_get_sound_focus_param_cmd.opcode = VSS_ISOUNDFOCUS_CMD_GET_SECTORS;
  6950. v->cvp_state = CMD_STATUS_FAIL;
  6951. v->async_err = 0;
  6952. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_get_sound_focus_param_cmd);
  6953. if (ret < 0) {
  6954. pr_err("%s: Error in sending APR command\n", __func__);
  6955. ret = -EINVAL;
  6956. goto done;
  6957. }
  6958. ret = wait_event_timeout(v->cvp_wait,
  6959. (v->cvp_state == CMD_STATUS_SUCCESS),
  6960. msecs_to_jiffies(TIMEOUT_MS));
  6961. if (!ret) {
  6962. pr_err("%s: wait_event timeout\n", __func__);
  6963. ret = -EINVAL;
  6964. goto done;
  6965. }
  6966. if (v->async_err > 0) {
  6967. pr_err("%s: DSP returned error[%s]\n",
  6968. __func__, adsp_err_get_err_str(
  6969. v->async_err));
  6970. ret = adsp_err_get_lnx_err_code(
  6971. v->async_err);
  6972. goto done;
  6973. }
  6974. if (common.is_sound_focus_resp_success) {
  6975. for (i = 0; i < MAX_SECTORS; i++) {
  6976. soundFocusData->start_angle[i] =
  6977. common.soundFocusResponse.start_angles[i];
  6978. soundFocusData->enable[i] =
  6979. common.soundFocusResponse.enables[i];
  6980. pr_debug("%s: start_angle[%d] = %d\n",
  6981. __func__, i, soundFocusData->start_angle[i]);
  6982. pr_debug("%s: enable[%d] = %d\n",
  6983. __func__, i, soundFocusData->enable[i]);
  6984. }
  6985. soundFocusData->gain_step = common.soundFocusResponse.gain_step;
  6986. pr_debug("%s: gain_step = %d\n", __func__,
  6987. soundFocusData->gain_step);
  6988. common.is_sound_focus_resp_success = false;
  6989. ret = 0;
  6990. } else {
  6991. pr_err("%s: Invalid payload received from CVD\n", __func__);
  6992. ret = -EINVAL;
  6993. }
  6994. done:
  6995. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  6996. return ret;
  6997. }
  6998. int voc_get_sound_focus(struct sound_focus_param *soundFocusData)
  6999. {
  7000. struct voice_data *v = NULL;
  7001. int ret = -EINVAL;
  7002. struct voice_session_itr itr;
  7003. pr_debug("%s: Enter\n", __func__);
  7004. mutex_lock(&common.common_lock);
  7005. voice_itr_init(&itr, ALL_SESSION_VSID);
  7006. while (voice_itr_get_next_session(&itr, &v)) {
  7007. if (v) {
  7008. mutex_lock(&v->lock);
  7009. if (is_voc_state_active(v->voc_state) &&
  7010. (v->lch_mode != VOICE_LCH_START) &&
  7011. !v->disable_topology)
  7012. ret = voice_send_get_sound_focus_cmd(v,
  7013. soundFocusData);
  7014. mutex_unlock(&v->lock);
  7015. } else {
  7016. pr_err("%s: invalid session\n", __func__);
  7017. ret = -EINVAL;
  7018. break;
  7019. }
  7020. }
  7021. mutex_unlock(&common.common_lock);
  7022. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7023. return ret;
  7024. }
  7025. static int is_source_tracking_shared_memomry_allocated(void)
  7026. {
  7027. bool ret;
  7028. pr_debug("%s: Enter\n", __func__);
  7029. if (common.source_tracking_sh_mem.sh_mem_block.client != NULL &&
  7030. common.source_tracking_sh_mem.sh_mem_block.handle != NULL)
  7031. ret = true;
  7032. else
  7033. ret = false;
  7034. pr_debug("%s: Exit\n", __func__);
  7035. return ret;
  7036. }
  7037. static int voice_alloc_source_tracking_shared_memory(void)
  7038. {
  7039. int ret = 0;
  7040. pr_debug("%s: Enter\n", __func__);
  7041. ret = msm_audio_ion_alloc("source_tracking_sh_mem_block",
  7042. &(common.source_tracking_sh_mem.sh_mem_block.client),
  7043. &(common.source_tracking_sh_mem.sh_mem_block.handle),
  7044. BUFFER_BLOCK_SIZE,
  7045. &(common.source_tracking_sh_mem.sh_mem_block.phys),
  7046. (size_t *)&(common.source_tracking_sh_mem.sh_mem_block.size),
  7047. &(common.source_tracking_sh_mem.sh_mem_block.data));
  7048. if (ret < 0) {
  7049. pr_err("%s: audio ION alloc failed for sh_mem block, ret = %d\n",
  7050. __func__, ret);
  7051. ret = -EINVAL;
  7052. goto done;
  7053. }
  7054. memset((void *)(common.source_tracking_sh_mem.sh_mem_block.data), 0,
  7055. common.source_tracking_sh_mem.sh_mem_block.size);
  7056. pr_debug("%s: sh_mem_block: phys:[%pK], data:[0x%pK], size:[%zd]\n",
  7057. __func__,
  7058. &(common.source_tracking_sh_mem.sh_mem_block.phys),
  7059. (void *)(common.source_tracking_sh_mem.sh_mem_block.data),
  7060. (size_t)(common.source_tracking_sh_mem.sh_mem_block.size));
  7061. ret = msm_audio_ion_alloc("source_tracking_sh_mem_table",
  7062. &(common.source_tracking_sh_mem.sh_mem_table.client),
  7063. &(common.source_tracking_sh_mem.sh_mem_table.handle),
  7064. sizeof(struct vss_imemory_table_t),
  7065. &(common.source_tracking_sh_mem.sh_mem_table.phys),
  7066. (size_t *)&(common.source_tracking_sh_mem.sh_mem_table.size),
  7067. &(common.source_tracking_sh_mem.sh_mem_table.data));
  7068. if (ret < 0) {
  7069. pr_err("%s: audio ION alloc failed for sh_mem table, ret = %d\n",
  7070. __func__, ret);
  7071. ret = msm_audio_ion_free(
  7072. common.source_tracking_sh_mem.sh_mem_block.client,
  7073. common.source_tracking_sh_mem.sh_mem_block.handle);
  7074. common.source_tracking_sh_mem.sh_mem_block.client = NULL;
  7075. common.source_tracking_sh_mem.sh_mem_block.handle = NULL;
  7076. if (ret < 0)
  7077. pr_err("%s: Error:%d freeing memory\n", __func__, ret);
  7078. ret = -EINVAL;
  7079. goto done;
  7080. }
  7081. memset((void *)(common.source_tracking_sh_mem.sh_mem_table.data), 0,
  7082. common.source_tracking_sh_mem.sh_mem_table.size);
  7083. pr_debug("%s sh_mem_table: phys:[%pK], data:[0x%pK], size:[%zd],\n",
  7084. __func__,
  7085. &(common.source_tracking_sh_mem.sh_mem_table.phys),
  7086. (void *)(common.source_tracking_sh_mem.sh_mem_table.data),
  7087. (size_t)(common.source_tracking_sh_mem.sh_mem_table.size));
  7088. done:
  7089. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7090. return ret;
  7091. }
  7092. static int voice_alloc_and_map_source_tracking_shared_memory(
  7093. struct voice_data *v)
  7094. {
  7095. int ret = 0;
  7096. pr_debug("%s: Enter\n", __func__);
  7097. ret = voice_alloc_source_tracking_shared_memory();
  7098. if (ret) {
  7099. pr_err("%s: Failed to allocate shared memory %d\n",
  7100. __func__, ret);
  7101. ret = -EINVAL;
  7102. goto done;
  7103. }
  7104. ret = voice_map_memory_physical_cmd(v,
  7105. &(common.source_tracking_sh_mem.sh_mem_table),
  7106. common.source_tracking_sh_mem.sh_mem_block.phys,
  7107. common.source_tracking_sh_mem.sh_mem_block.size,
  7108. VOC_SOURCE_TRACKING_MEM_MAP_TOKEN);
  7109. if (ret) {
  7110. pr_err("%s: memory mapping failed %d\n",
  7111. __func__, ret);
  7112. ret = -EINVAL;
  7113. goto done;
  7114. }
  7115. done:
  7116. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7117. return ret;
  7118. }
  7119. static int voice_unmap_and_free_source_tracking_shared_memory(
  7120. struct voice_data *v)
  7121. {
  7122. int ret = 0;
  7123. pr_debug("%s: Enter\n", __func__);
  7124. if (common.source_tracking_sh_mem.mem_handle != 0) {
  7125. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  7126. common.source_tracking_sh_mem.mem_handle);
  7127. if (ret < 0) {
  7128. pr_err("%s: Memory_unmap failed err %d\n",
  7129. __func__, ret);
  7130. ret = -EINVAL;
  7131. goto done;
  7132. }
  7133. }
  7134. if ((common.source_tracking_sh_mem.sh_mem_block.client == NULL) ||
  7135. (common.source_tracking_sh_mem.sh_mem_block.handle == NULL))
  7136. goto done;
  7137. ret = msm_audio_ion_free(
  7138. common.source_tracking_sh_mem.sh_mem_block.client,
  7139. common.source_tracking_sh_mem.sh_mem_block.handle);
  7140. if (ret < 0) {
  7141. pr_err("%s: Error:%d freeing memory\n", __func__, ret);
  7142. ret = -EINVAL;
  7143. goto done;
  7144. }
  7145. done:
  7146. common.source_tracking_sh_mem.mem_handle = 0;
  7147. common.source_tracking_sh_mem.sh_mem_block.client = NULL;
  7148. common.source_tracking_sh_mem.sh_mem_block.handle = NULL;
  7149. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7150. return ret;
  7151. }
  7152. static int voice_send_get_source_tracking_cmd(struct voice_data *v,
  7153. struct source_tracking_param *sourceTrackingData)
  7154. {
  7155. struct cvp_get_source_tracking_param_cmd_t st_cmd;
  7156. int ret = 0;
  7157. void *apr_cvp;
  7158. u16 cvp_handle;
  7159. int i;
  7160. pr_debug("%s: Enter\n", __func__);
  7161. if (!v) {
  7162. pr_err("%s: v is NULL\n", __func__);
  7163. return -EINVAL;
  7164. }
  7165. apr_cvp = common.apr_q6_cvp;
  7166. if (!apr_cvp) {
  7167. pr_err("%s: apr_cvp is NULL.\n", __func__);
  7168. return -EINVAL;
  7169. }
  7170. cvp_handle = voice_get_cvp_handle(v);
  7171. if (!is_source_tracking_shared_memomry_allocated()) {
  7172. ret = voice_alloc_and_map_source_tracking_shared_memory(v);
  7173. if (ret) {
  7174. pr_err("%s: Fail in allocating/mapping shared memory\n",
  7175. __func__);
  7176. ret = -EINVAL;
  7177. goto done;
  7178. }
  7179. }
  7180. st_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  7181. APR_HDR_LEN(APR_HDR_SIZE),
  7182. APR_PKT_VER);
  7183. st_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  7184. sizeof(st_cmd) - APR_HDR_SIZE);
  7185. st_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  7186. st_cmd.hdr.dest_port = cvp_handle;
  7187. st_cmd.hdr.token = 0;
  7188. st_cmd.hdr.opcode = VSS_ISOURCETRACK_CMD_GET_ACTIVITY;
  7189. st_cmd.cvp_get_source_tracking_param.mem_handle =
  7190. common.source_tracking_sh_mem.mem_handle;
  7191. st_cmd.cvp_get_source_tracking_param.mem_address_lsw =
  7192. lower_32_bits(common.source_tracking_sh_mem.sh_mem_block.phys);
  7193. st_cmd.cvp_get_source_tracking_param.mem_address_msw =
  7194. msm_audio_populate_upper_32_bits(common.source_tracking_sh_mem.
  7195. sh_mem_block.phys);
  7196. st_cmd.cvp_get_source_tracking_param.mem_size =
  7197. (uint32_t)common.source_tracking_sh_mem.sh_mem_block.size;
  7198. pr_debug("%s: mem_handle=0x%x, mem_address_lsw=0x%x, msw=0x%x, mem_size=%d\n",
  7199. __func__,
  7200. st_cmd.cvp_get_source_tracking_param.mem_handle,
  7201. st_cmd.cvp_get_source_tracking_param.mem_address_lsw,
  7202. st_cmd.cvp_get_source_tracking_param.mem_address_msw,
  7203. (uint32_t)st_cmd.cvp_get_source_tracking_param.mem_size);
  7204. v->cvp_state = CMD_STATUS_FAIL;
  7205. v->async_err = 0;
  7206. ret = apr_send_pkt(apr_cvp,
  7207. (uint32_t *) &st_cmd);
  7208. if (ret < 0) {
  7209. pr_err("%s: Error in sending APR command\n", __func__);
  7210. ret = -EINVAL;
  7211. goto done;
  7212. }
  7213. ret = wait_event_timeout(v->cvp_wait,
  7214. (v->cvp_state == CMD_STATUS_SUCCESS),
  7215. msecs_to_jiffies(TIMEOUT_MS));
  7216. if (!ret) {
  7217. pr_err("%s: wait_event timeout\n", __func__);
  7218. ret = -EINVAL;
  7219. goto done;
  7220. }
  7221. if (v->async_err > 0) {
  7222. pr_err("%s: DSP returned error[%s]\n",
  7223. __func__, adsp_err_get_err_str(
  7224. v->async_err));
  7225. ret = adsp_err_get_lnx_err_code(
  7226. v->async_err);
  7227. goto done;
  7228. }
  7229. if (common.is_source_tracking_resp_success) {
  7230. for (i = 0; i < MAX_SECTORS; i++) {
  7231. sourceTrackingData->vad[i] =
  7232. common.sourceTrackingResponse.voice_active[i];
  7233. pr_debug("%s: vad[%d] = %d\n",
  7234. __func__, i, sourceTrackingData->vad[i]);
  7235. }
  7236. sourceTrackingData->doa_speech =
  7237. common.sourceTrackingResponse.talker_doa;
  7238. pr_debug("%s: doa_speech = %d\n",
  7239. __func__, sourceTrackingData->doa_speech);
  7240. for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
  7241. sourceTrackingData->doa_noise[i] =
  7242. common.sourceTrackingResponse.interferer_doa[i];
  7243. pr_debug("%s: doa_noise[%d] = %d\n",
  7244. __func__, i, sourceTrackingData->doa_noise[i]);
  7245. }
  7246. for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
  7247. sourceTrackingData->polar_activity[i] =
  7248. common.sourceTrackingResponse.sound_strength[i];
  7249. pr_debug("%s: polar_activity[%d] = %d\n",
  7250. __func__, i, sourceTrackingData->polar_activity[i]);
  7251. }
  7252. common.is_source_tracking_resp_success = false;
  7253. ret = 0;
  7254. } else {
  7255. pr_err("%s: Error response received from CVD\n", __func__);
  7256. ret = -EINVAL;
  7257. }
  7258. done:
  7259. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7260. return ret;
  7261. }
  7262. int voc_get_source_tracking(struct source_tracking_param *sourceTrackingData)
  7263. {
  7264. struct voice_data *v = NULL;
  7265. int ret = -EINVAL;
  7266. struct voice_session_itr itr;
  7267. pr_debug("%s: Enter\n", __func__);
  7268. mutex_lock(&common.common_lock);
  7269. voice_itr_init(&itr, ALL_SESSION_VSID);
  7270. while (voice_itr_get_next_session(&itr, &v)) {
  7271. if (v != NULL) {
  7272. mutex_lock(&v->lock);
  7273. if (is_voc_state_active(v->voc_state) &&
  7274. (v->lch_mode != VOICE_LCH_START) &&
  7275. !v->disable_topology)
  7276. ret = voice_send_get_source_tracking_cmd(v,
  7277. sourceTrackingData);
  7278. mutex_unlock(&v->lock);
  7279. } else {
  7280. pr_err("%s: invalid session\n", __func__);
  7281. break;
  7282. }
  7283. }
  7284. mutex_unlock(&common.common_lock);
  7285. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7286. return ret;
  7287. }
  7288. int is_voc_initialized(void)
  7289. {
  7290. return module_initialized;
  7291. }
  7292. static int __init voice_init(void)
  7293. {
  7294. int rc = 0, i = 0;
  7295. memset(&common, 0, sizeof(struct common_data));
  7296. /* set default value */
  7297. common.default_mute_val = 0; /* default is un-mute */
  7298. common.default_sample_val = 8000;
  7299. common.default_vol_step_val = 0;
  7300. common.default_vol_ramp_duration_ms = DEFAULT_VOLUME_RAMP_DURATION;
  7301. common.default_mute_ramp_duration_ms = DEFAULT_MUTE_RAMP_DURATION;
  7302. /* Initialize EC Ref media format info */
  7303. common.ec_ref_ext = false;
  7304. common.ec_media_fmt_info.port_id = AFE_PORT_INVALID;
  7305. common.ec_media_fmt_info.num_channels = 0;
  7306. common.ec_media_fmt_info.bits_per_sample = 16;
  7307. common.ec_media_fmt_info.sample_rate = 8000;
  7308. memset(&common.ec_media_fmt_info.channel_mapping, 0,
  7309. VSS_CHANNEL_MAPPING_SIZE);
  7310. /* Initialize AFE Sidetone Enable */
  7311. common.sidetone_enable = false;
  7312. /* Initialize MVS info. */
  7313. common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
  7314. /* Initialize is low memory flag */
  7315. common.is_destroy_cvd = false;
  7316. /* Initialize CVD version */
  7317. strlcpy(common.cvd_version, CVD_VERSION_DEFAULT,
  7318. sizeof(common.cvd_version));
  7319. /* Initialize Per-Vocoder Calibration flag */
  7320. common.is_per_vocoder_cal_enabled = false;
  7321. mutex_init(&common.common_lock);
  7322. /* Initialize session id with vsid */
  7323. init_session_id();
  7324. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  7325. /* initialize dev_rx and dev_tx */
  7326. common.voice[i].dev_rx.dev_mute = common.default_mute_val;
  7327. common.voice[i].dev_tx.dev_mute = common.default_mute_val;
  7328. common.voice[i].dev_rx.volume_step_value =
  7329. common.default_vol_step_val;
  7330. common.voice[i].dev_rx.volume_ramp_duration_ms =
  7331. common.default_vol_ramp_duration_ms;
  7332. common.voice[i].dev_rx.dev_mute_ramp_duration_ms =
  7333. common.default_mute_ramp_duration_ms;
  7334. common.voice[i].dev_tx.dev_mute_ramp_duration_ms =
  7335. common.default_mute_ramp_duration_ms;
  7336. common.voice[i].stream_rx.stream_mute = common.default_mute_val;
  7337. common.voice[i].stream_tx.stream_mute = common.default_mute_val;
  7338. common.voice[i].dev_tx.port_id = 0x100B;
  7339. common.voice[i].dev_rx.port_id = 0x100A;
  7340. common.voice[i].dev_tx.dev_id = 0;
  7341. common.voice[i].dev_rx.dev_id = 0;
  7342. common.voice[i].dev_tx.no_of_channels = 0;
  7343. common.voice[i].dev_rx.no_of_channels = 0;
  7344. common.voice[i].dev_tx.sample_rate = 8000;
  7345. common.voice[i].dev_rx.sample_rate = 8000;
  7346. common.voice[i].dev_tx.bits_per_sample = 16;
  7347. common.voice[i].dev_rx.bits_per_sample = 16;
  7348. memset(&common.voice[i].dev_tx.channel_mapping, 0,
  7349. VSS_CHANNEL_MAPPING_SIZE);
  7350. memset(&common.voice[i].dev_rx.channel_mapping, 0,
  7351. VSS_CHANNEL_MAPPING_SIZE);
  7352. common.voice[i].sidetone_gain = 0x512;
  7353. common.voice[i].dtmf_rx_detect_en = 0;
  7354. common.voice[i].lch_mode = 0;
  7355. common.voice[i].disable_topology = false;
  7356. common.voice[i].voc_state = VOC_INIT;
  7357. init_waitqueue_head(&common.voice[i].mvm_wait);
  7358. init_waitqueue_head(&common.voice[i].cvs_wait);
  7359. init_waitqueue_head(&common.voice[i].cvp_wait);
  7360. mutex_init(&common.voice[i].lock);
  7361. }
  7362. if (voice_init_cal_data())
  7363. pr_err("%s: Could not init cal data!\n", __func__);
  7364. if (rc == 0)
  7365. module_initialized = true;
  7366. pr_debug("%s: rc=%d\n", __func__, rc);
  7367. return rc;
  7368. }
  7369. device_initcall(voice_init);
  7370. static void __exit voice_exit(void)
  7371. {
  7372. voice_delete_cal_data();
  7373. free_cal_map_table();
  7374. }
  7375. __exitcall(voice_exit);