q6voice.c 244 KB

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