q6voice.c 255 KB

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