q6voice.c 248 KB

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