q6voice.c 232 KB

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