q6voice.c 259 KB

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