q6voice.c 247 KB

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