q6voice.c 265 KB

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