q6voice.c 253 KB

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