q6voice.c 254 KB

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