q6voice.c 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429
  1. /* Copyright (c) 2012-2014, 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 <linux/msm_audio_ion.h>
  20. #include <asm/mach-types.h>
  21. #include <mach/socinfo.h>
  22. #include <mach/qdsp6v2/apr_tal.h>
  23. #include "sound/apr_audio-v2.h"
  24. #include "sound/q6afe-v2.h"
  25. #include "audio_acdb.h"
  26. #include "q6voice.h"
  27. #define TIMEOUT_MS 500
  28. #define CMD_STATUS_SUCCESS 0
  29. #define CMD_STATUS_FAIL 1
  30. /* CVP CAL Size: 245760 = 240 * 1024 */
  31. #define CVP_CAL_SIZE 245760
  32. /* CVS CAL Size: 49152 = 48 * 1024 */
  33. #define CVS_CAL_SIZE 49152
  34. enum {
  35. VOC_TOKEN_NONE,
  36. VOIP_MEM_MAP_TOKEN,
  37. VOC_CAL_MEM_MAP_TOKEN,
  38. VOC_RTAC_MEM_MAP_TOKEN
  39. };
  40. static struct common_data common;
  41. static bool module_initialized;
  42. static int loopback_mode = 0;
  43. static int loopback_prev_mode = 0;
  44. static int dha_state = 0;
  45. static int In_roaming = 0;
  46. int voc_get_loopback_enable(void)
  47. {
  48. return loopback_mode;
  49. }
  50. void voc_set_loopback_enable(int mode)
  51. {
  52. loopback_prev_mode = loopback_mode;
  53. loopback_mode = mode;
  54. pr_info("%s : prev_mode = %d, mode = %d\n",
  55. __func__, loopback_prev_mode, mode);
  56. }
  57. int voc_get_roaming_enable(void)
  58. {
  59. return In_roaming;
  60. }
  61. void voc_set_roaming_enable(int mode)
  62. {
  63. In_roaming = mode;
  64. pr_info("%s : In_roaming = %d, mode = %d\n",
  65. __func__, In_roaming, mode);
  66. }
  67. static int voice_send_enable_vocproc_cmd(struct voice_data *v);
  68. static int voice_send_netid_timing_cmd(struct voice_data *v);
  69. static int voice_send_attach_vocproc_cmd(struct voice_data *v);
  70. static int voice_send_set_device_cmd(struct voice_data *v);
  71. static int voice_send_disable_vocproc_cmd(struct voice_data *v);
  72. static int voice_send_vol_step_cmd(struct voice_data *v);
  73. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  74. uint32_t mem_handle);
  75. static int voice_send_mvm_cal_network_cmd(struct voice_data *v);
  76. static int voice_send_mvm_media_type_cmd(struct voice_data *v);
  77. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v);
  78. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v);
  79. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  80. uint32_t mode);
  81. static int voice_send_cvs_register_cal_cmd(struct voice_data *v);
  82. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v);
  83. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v);
  84. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v);
  85. static int voice_send_cvp_register_cal_cmd(struct voice_data *v);
  86. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v);
  87. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v);
  88. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v);
  89. static int voice_cvs_stop_playback(struct voice_data *v);
  90. static int voice_cvs_start_playback(struct voice_data *v);
  91. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode);
  92. static int voice_cvs_stop_record(struct voice_data *v);
  93. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
  94. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
  95. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
  96. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  97. uint32_t module_id, int enable);
  98. static int send_packet_loopback_cmd(struct voice_data *v, bool mode);
  99. static int is_cal_memory_allocated(void);
  100. static int is_voip_memory_allocated(void);
  101. static int voice_alloc_cal_mem_map_table(void);
  102. static int voice_alloc_rtac_mem_map_table(void);
  103. static int voice_alloc_oob_shared_mem(void);
  104. static int voice_free_oob_shared_mem(void);
  105. static int voice_alloc_oob_mem_table(void);
  106. static int voice_alloc_and_map_cal_mem(struct voice_data *v);
  107. static int voice_alloc_and_map_oob_mem(struct voice_data *v);
  108. static int voc_disable_cvp(uint32_t session_id);
  109. static int voc_enable_cvp(uint32_t session_id);
  110. static struct voice_data *voice_get_session_by_idx(int idx);
  111. static void voice_itr_init(struct voice_session_itr *itr,
  112. u32 session_id)
  113. {
  114. if (itr == NULL)
  115. return;
  116. itr->session_idx = voice_get_idx_for_session(session_id);
  117. if (session_id == ALL_SESSION_VSID)
  118. itr->cur_idx = 0;
  119. else
  120. itr->cur_idx = itr->session_idx;
  121. }
  122. static bool voice_itr_get_next_session(struct voice_session_itr *itr,
  123. struct voice_data **voice)
  124. {
  125. bool ret = false;
  126. if (itr == NULL)
  127. return false;
  128. pr_debug("%s : cur idx = %d session idx = %d",
  129. __func__, itr->cur_idx, itr->session_idx);
  130. if (itr->cur_idx <= itr->session_idx) {
  131. ret = true;
  132. *voice = voice_get_session_by_idx(itr->cur_idx);
  133. itr->cur_idx++;
  134. } else {
  135. *voice = NULL;
  136. }
  137. return ret;
  138. }
  139. static bool voice_is_valid_session_id(uint32_t session_id)
  140. {
  141. bool ret = false;
  142. switch (session_id) {
  143. case VOICE_SESSION_VSID:
  144. case VOICE2_SESSION_VSID:
  145. case VOLTE_SESSION_VSID:
  146. case VOIP_SESSION_VSID:
  147. case QCHAT_SESSION_VSID:
  148. case VOWLAN_SESSION_VSID:
  149. case ALL_SESSION_VSID:
  150. ret = true;
  151. break;
  152. default:
  153. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  154. break;
  155. }
  156. return ret;
  157. }
  158. static u16 voice_get_mvm_handle(struct voice_data *v)
  159. {
  160. if (v == NULL) {
  161. pr_err("%s: v is NULL\n", __func__);
  162. return 0;
  163. }
  164. pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
  165. return v->mvm_handle;
  166. }
  167. static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
  168. {
  169. pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
  170. if (v == NULL) {
  171. pr_err("%s: v is NULL\n", __func__);
  172. return;
  173. }
  174. v->mvm_handle = mvm_handle;
  175. }
  176. static u16 voice_get_cvs_handle(struct voice_data *v)
  177. {
  178. if (v == NULL) {
  179. pr_err("%s: v is NULL\n", __func__);
  180. return 0;
  181. }
  182. pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
  183. return v->cvs_handle;
  184. }
  185. static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
  186. {
  187. pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
  188. if (v == NULL) {
  189. pr_err("%s: v is NULL\n", __func__);
  190. return;
  191. }
  192. v->cvs_handle = cvs_handle;
  193. }
  194. static u16 voice_get_cvp_handle(struct voice_data *v)
  195. {
  196. if (v == NULL) {
  197. pr_err("%s: v is NULL\n", __func__);
  198. return 0;
  199. }
  200. pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
  201. return v->cvp_handle;
  202. }
  203. static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
  204. {
  205. pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
  206. if (v == NULL) {
  207. pr_err("%s: v is NULL\n", __func__);
  208. return;
  209. }
  210. v->cvp_handle = cvp_handle;
  211. }
  212. char *voc_get_session_name(u32 session_id)
  213. {
  214. char *session_name = NULL;
  215. if (session_id == common.voice[VOC_PATH_PASSIVE].session_id) {
  216. session_name = VOICE_SESSION_NAME;
  217. } else if (session_id ==
  218. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id) {
  219. session_name = VOLTE_SESSION_NAME;
  220. } else if (session_id ==
  221. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id) {
  222. session_name = QCHAT_SESSION_NAME;
  223. } else if (session_id ==
  224. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id) {
  225. session_name = VOWLAN_SESSION_NAME;
  226. } else if (session_id == common.voice[VOC_PATH_FULL].session_id) {
  227. session_name = VOIP_SESSION_NAME;
  228. }
  229. return session_name;
  230. }
  231. uint32_t voc_get_session_id(char *name)
  232. {
  233. u32 session_id = 0;
  234. if (name != NULL) {
  235. if (!strncmp(name, "Voice session", 13))
  236. session_id = common.voice[VOC_PATH_PASSIVE].session_id;
  237. else if (!strncmp(name, "Voice2 session", 14))
  238. session_id =
  239. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id;
  240. else if (!strncmp(name, "VoLTE session", 13))
  241. session_id =
  242. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id;
  243. else if (!strncmp(name, "QCHAT session", 13))
  244. session_id =
  245. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id;
  246. else if (!strncmp(name, "VoWLAN session", 14))
  247. session_id =
  248. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id;
  249. else
  250. session_id = common.voice[VOC_PATH_FULL].session_id;
  251. pr_debug("%s: %s has session id 0x%x\n", __func__, name,
  252. session_id);
  253. }
  254. return session_id;
  255. }
  256. static struct voice_data *voice_get_session(u32 session_id)
  257. {
  258. struct voice_data *v = NULL;
  259. switch (session_id) {
  260. case VOICE_SESSION_VSID:
  261. v = &common.voice[VOC_PATH_PASSIVE];
  262. break;
  263. case VOICE2_SESSION_VSID:
  264. v = &common.voice[VOC_PATH_VOICE2_PASSIVE];
  265. break;
  266. case VOLTE_SESSION_VSID:
  267. v = &common.voice[VOC_PATH_VOLTE_PASSIVE];
  268. break;
  269. case VOIP_SESSION_VSID:
  270. v = &common.voice[VOC_PATH_FULL];
  271. break;
  272. case QCHAT_SESSION_VSID:
  273. v = &common.voice[VOC_PATH_QCHAT_PASSIVE];
  274. break;
  275. case VOWLAN_SESSION_VSID:
  276. v = &common.voice[VOC_PATH_VOWLAN_PASSIVE];
  277. break;
  278. case ALL_SESSION_VSID:
  279. break;
  280. default:
  281. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  282. break;
  283. }
  284. pr_debug("%s:session_id 0x%x session handle 0x%x\n",
  285. __func__, session_id, (unsigned int)v);
  286. return v;
  287. }
  288. int voice_get_idx_for_session(u32 session_id)
  289. {
  290. int idx = 0;
  291. switch (session_id) {
  292. case VOICE_SESSION_VSID:
  293. idx = VOC_PATH_PASSIVE;
  294. break;
  295. case VOICE2_SESSION_VSID:
  296. idx = VOC_PATH_VOICE2_PASSIVE;
  297. break;
  298. case VOLTE_SESSION_VSID:
  299. idx = VOC_PATH_VOLTE_PASSIVE;
  300. break;
  301. case VOIP_SESSION_VSID:
  302. idx = VOC_PATH_FULL;
  303. break;
  304. case QCHAT_SESSION_VSID:
  305. idx = VOC_PATH_QCHAT_PASSIVE;
  306. break;
  307. case VOWLAN_SESSION_VSID:
  308. idx = VOC_PATH_VOWLAN_PASSIVE;
  309. break;
  310. case ALL_SESSION_VSID:
  311. idx = MAX_VOC_SESSIONS - 1;
  312. break;
  313. default:
  314. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  315. break;
  316. }
  317. return idx;
  318. }
  319. static struct voice_data *voice_get_session_by_idx(int idx)
  320. {
  321. return ((idx < 0 || idx >= MAX_VOC_SESSIONS) ?
  322. NULL : &common.voice[idx]);
  323. }
  324. static bool is_voice_session(u32 session_id)
  325. {
  326. return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
  327. }
  328. static bool is_voip_session(u32 session_id)
  329. {
  330. return (session_id == common.voice[VOC_PATH_FULL].session_id);
  331. }
  332. static bool is_volte_session(u32 session_id)
  333. {
  334. return (session_id == common.voice[VOC_PATH_VOLTE_PASSIVE].session_id);
  335. }
  336. static bool is_voice2_session(u32 session_id)
  337. {
  338. return (session_id == common.voice[VOC_PATH_VOICE2_PASSIVE].session_id);
  339. }
  340. static bool is_qchat_session(u32 session_id)
  341. {
  342. return (session_id == common.voice[VOC_PATH_QCHAT_PASSIVE].session_id);
  343. }
  344. static bool is_vowlan_session(u32 session_id)
  345. {
  346. return (session_id == common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id);
  347. }
  348. static bool is_voc_state_active(int voc_state)
  349. {
  350. if ((voc_state == VOC_RUN) ||
  351. (voc_state == VOC_CHANGE) ||
  352. (voc_state == VOC_STANDBY))
  353. return true;
  354. return false;
  355. }
  356. static void voc_set_error_state(uint16_t reset_proc)
  357. {
  358. struct voice_data *v = NULL;
  359. int i;
  360. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  361. if (reset_proc == APR_DEST_MODEM && i == VOC_PATH_FULL)
  362. continue;
  363. v = &common.voice[i];
  364. if (v != NULL)
  365. v->voc_state = VOC_ERROR;
  366. }
  367. }
  368. static bool is_other_session_active(u32 session_id)
  369. {
  370. int i;
  371. bool ret = false;
  372. /* Check if there is other active session except the input one */
  373. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  374. if (common.voice[i].session_id == session_id)
  375. continue;
  376. if (is_voc_state_active(common.voice[i].voc_state)) {
  377. ret = true;
  378. break;
  379. }
  380. }
  381. pr_debug("%s: ret %d\n", __func__, ret);
  382. return ret;
  383. }
  384. static bool is_voice_app_id(u32 session_id)
  385. {
  386. return (((session_id & APP_ID_MASK) >> APP_ID_SHIFT) ==
  387. VSID_APP_CS_VOICE);
  388. }
  389. static void init_session_id(void)
  390. {
  391. common.voice[VOC_PATH_PASSIVE].session_id = VOICE_SESSION_VSID;
  392. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id = VOLTE_SESSION_VSID;
  393. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id = VOICE2_SESSION_VSID;
  394. common.voice[VOC_PATH_FULL].session_id = VOIP_SESSION_VSID;
  395. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id = QCHAT_SESSION_VSID;
  396. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id = VOWLAN_SESSION_VSID;
  397. }
  398. static int voice_apr_register(void)
  399. {
  400. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  401. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  402. void *modem_mvm, *modem_cvs, *modem_cvp;
  403. #endif
  404. pr_debug("%s\n", __func__);
  405. mutex_lock(&common.common_lock);
  406. /* register callback to APR */
  407. if (common.apr_q6_mvm == NULL) {
  408. pr_debug("%s: Start to register MVM callback\n", __func__);
  409. common.apr_q6_mvm = apr_register("ADSP", "MVM",
  410. qdsp_mvm_callback,
  411. 0xFFFFFFFF, &common);
  412. if (common.apr_q6_mvm == NULL) {
  413. pr_err("%s: Unable to register MVM\n", __func__);
  414. goto err;
  415. }
  416. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  417. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  418. /*
  419. * Register with modem for SSR callback. The APR handle
  420. * is not stored since it is used only to receive notifications
  421. * and not for communication
  422. */
  423. modem_mvm = apr_register("MODEM", "MVM",
  424. qdsp_mvm_callback,
  425. 0xFFFFFFFF, &common);
  426. if (modem_mvm == NULL)
  427. pr_err("%s: Unable to register MVM for MODEM\n",
  428. __func__);
  429. #endif
  430. }
  431. if (common.apr_q6_cvs == NULL) {
  432. pr_debug("%s: Start to register CVS callback\n", __func__);
  433. common.apr_q6_cvs = apr_register("ADSP", "CVS",
  434. qdsp_cvs_callback,
  435. 0xFFFFFFFF, &common);
  436. if (common.apr_q6_cvs == NULL) {
  437. pr_err("%s: Unable to register CVS\n", __func__);
  438. goto err;
  439. }
  440. rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
  441. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  442. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  443. /*
  444. * Register with modem for SSR callback. The APR handle
  445. * is not stored since it is used only to receive notifications
  446. * and not for communication
  447. */
  448. modem_cvs = apr_register("MODEM", "CVS",
  449. qdsp_cvs_callback,
  450. 0xFFFFFFFF, &common);
  451. if (modem_cvs == NULL)
  452. pr_err("%s: Unable to register CVS for MODEM\n",
  453. __func__);
  454. #endif
  455. }
  456. if (common.apr_q6_cvp == NULL) {
  457. pr_debug("%s: Start to register CVP callback\n", __func__);
  458. common.apr_q6_cvp = apr_register("ADSP", "CVP",
  459. qdsp_cvp_callback,
  460. 0xFFFFFFFF, &common);
  461. if (common.apr_q6_cvp == NULL) {
  462. pr_err("%s: Unable to register CVP\n", __func__);
  463. goto err;
  464. }
  465. rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
  466. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  467. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  468. /*
  469. * Register with modem for SSR callback. The APR handle
  470. * is not stored since it is used only to receive notifications
  471. * and not for communication
  472. */
  473. modem_cvp = apr_register("MODEM", "CVP",
  474. qdsp_cvp_callback,
  475. 0xFFFFFFFF, &common);
  476. if (modem_cvp == NULL)
  477. pr_err("%s: Unable to register CVP for MODEM\n",
  478. __func__);
  479. #endif
  480. }
  481. mutex_unlock(&common.common_lock);
  482. return 0;
  483. err:
  484. if (common.apr_q6_cvs != NULL) {
  485. apr_deregister(common.apr_q6_cvs);
  486. common.apr_q6_cvs = NULL;
  487. rtac_set_voice_handle(RTAC_CVS, NULL);
  488. }
  489. if (common.apr_q6_mvm != NULL) {
  490. apr_deregister(common.apr_q6_mvm);
  491. common.apr_q6_mvm = NULL;
  492. }
  493. mutex_unlock(&common.common_lock);
  494. return -ENODEV;
  495. }
  496. static int voice_send_dual_control_cmd(struct voice_data *v)
  497. {
  498. int ret = 0;
  499. struct mvm_modem_dual_control_session_cmd mvm_voice_ctl_cmd;
  500. void *apr_mvm;
  501. u16 mvm_handle;
  502. if (v == NULL) {
  503. pr_err("%s: v is NULL\n", __func__);
  504. return -EINVAL;
  505. }
  506. apr_mvm = common.apr_q6_mvm;
  507. if (!apr_mvm) {
  508. pr_err("%s: apr_mvm is NULL.\n", __func__);
  509. return -EINVAL;
  510. }
  511. pr_debug("%s: Send Dual Control command to MVM\n", __func__);
  512. if (!is_voip_session(v->session_id)) {
  513. mvm_handle = voice_get_mvm_handle(v);
  514. mvm_voice_ctl_cmd.hdr.hdr_field = APR_HDR_FIELD(
  515. APR_MSG_TYPE_SEQ_CMD,
  516. APR_HDR_LEN(APR_HDR_SIZE),
  517. APR_PKT_VER);
  518. mvm_voice_ctl_cmd.hdr.pkt_size = APR_PKT_SIZE(
  519. APR_HDR_SIZE,
  520. sizeof(mvm_voice_ctl_cmd) -
  521. APR_HDR_SIZE);
  522. pr_debug("%s: send mvm Voice Ctl pkt size = %d\n",
  523. __func__, mvm_voice_ctl_cmd.hdr.pkt_size);
  524. mvm_voice_ctl_cmd.hdr.src_port =
  525. voice_get_idx_for_session(v->session_id);
  526. mvm_voice_ctl_cmd.hdr.dest_port = mvm_handle;
  527. mvm_voice_ctl_cmd.hdr.token = 0;
  528. mvm_voice_ctl_cmd.hdr.opcode =
  529. VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL;
  530. mvm_voice_ctl_cmd.voice_ctl.enable_flag = true;
  531. v->mvm_state = CMD_STATUS_FAIL;
  532. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_voice_ctl_cmd);
  533. if (ret < 0) {
  534. pr_err("%s: Error sending MVM Voice CTL CMD\n",
  535. __func__);
  536. ret = -EINVAL;
  537. goto fail;
  538. }
  539. ret = wait_event_timeout(v->mvm_wait,
  540. (v->mvm_state == CMD_STATUS_SUCCESS),
  541. msecs_to_jiffies(TIMEOUT_MS));
  542. if (!ret) {
  543. pr_err("%s: wait_event timeout\n", __func__);
  544. ret = -EINVAL;
  545. goto fail;
  546. }
  547. }
  548. ret = 0;
  549. fail:
  550. return ret;
  551. }
  552. static int voice_create_mvm_cvs_session(struct voice_data *v)
  553. {
  554. int ret = 0;
  555. struct mvm_create_ctl_session_cmd mvm_session_cmd;
  556. struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
  557. struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
  558. struct mvm_attach_stream_cmd attach_stream_cmd;
  559. void *apr_mvm, *apr_cvs, *apr_cvp;
  560. u16 mvm_handle, cvs_handle, cvp_handle;
  561. if (v == NULL) {
  562. pr_err("%s: v is NULL\n", __func__);
  563. return -EINVAL;
  564. }
  565. apr_mvm = common.apr_q6_mvm;
  566. apr_cvs = common.apr_q6_cvs;
  567. apr_cvp = common.apr_q6_cvp;
  568. if (!apr_mvm || !apr_cvs || !apr_cvp) {
  569. pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
  570. return -EINVAL;
  571. }
  572. mvm_handle = voice_get_mvm_handle(v);
  573. cvs_handle = voice_get_cvs_handle(v);
  574. cvp_handle = voice_get_cvp_handle(v);
  575. pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
  576. mvm_handle, cvs_handle);
  577. /* send cmd to create mvm session and wait for response */
  578. if (!mvm_handle) {
  579. memset(mvm_session_cmd.mvm_session.name, 0,
  580. sizeof(mvm_session_cmd.mvm_session.name));
  581. if (!is_voip_session(v->session_id)) {
  582. mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  583. APR_MSG_TYPE_SEQ_CMD,
  584. APR_HDR_LEN(APR_HDR_SIZE),
  585. APR_PKT_VER);
  586. mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
  587. APR_HDR_SIZE,
  588. sizeof(mvm_session_cmd) -
  589. APR_HDR_SIZE);
  590. pr_debug("%s: send mvm create session pkt size = %d\n",
  591. __func__, mvm_session_cmd.hdr.pkt_size);
  592. mvm_session_cmd.hdr.src_port =
  593. voice_get_idx_for_session(v->session_id);
  594. mvm_session_cmd.hdr.dest_port = 0;
  595. mvm_session_cmd.hdr.token = 0;
  596. mvm_session_cmd.hdr.opcode =
  597. VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  598. if (is_volte_session(v->session_id)) {
  599. strlcpy(mvm_session_cmd.mvm_session.name,
  600. "default volte voice",
  601. strlen("default volte voice")+1);
  602. } else if (is_voice2_session(v->session_id)) {
  603. if(In_roaming == true) { //MSM 2nd call
  604. strlcpy(mvm_session_cmd.mvm_session.name,
  605. VOICE2_SESSION_VSID_STR,
  606. sizeof(mvm_session_cmd.mvm_session.name));
  607. }
  608. else { //QSC call
  609. strlcpy(mvm_session_cmd.mvm_session.name,
  610. #ifdef CONFIG_DSDA_VIA_UART
  611. "default modem voice2",
  612. #else
  613. VOICE2_SESSION_VSID_STR,
  614. #endif /* CONFIG_DSDA_VIA_UART */
  615. strlen(VOICE2_SESSION_VSID_STR)+1);
  616. }
  617. } else if (is_qchat_session(v->session_id)) {
  618. strlcpy(mvm_session_cmd.mvm_session.name,
  619. QCHAT_SESSION_VSID_STR,
  620. strlen(QCHAT_SESSION_VSID_STR)+1);
  621. } else if (is_vowlan_session(v->session_id)) {
  622. strlcpy(mvm_session_cmd.mvm_session.name,
  623. VOWLAN_SESSION_VSID_STR,
  624. strlen(VOWLAN_SESSION_VSID_STR)+1);
  625. } else {
  626. strlcpy(mvm_session_cmd.mvm_session.name,
  627. "default modem voice",
  628. strlen("default modem voice")+1);
  629. }
  630. v->mvm_state = CMD_STATUS_FAIL;
  631. ret = apr_send_pkt(apr_mvm,
  632. (uint32_t *) &mvm_session_cmd);
  633. if (ret < 0) {
  634. pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
  635. __func__);
  636. goto fail;
  637. }
  638. ret = wait_event_timeout(v->mvm_wait,
  639. (v->mvm_state == CMD_STATUS_SUCCESS),
  640. msecs_to_jiffies(TIMEOUT_MS));
  641. if (!ret) {
  642. pr_err("%s: wait_event timeout\n", __func__);
  643. goto fail;
  644. }
  645. } else {
  646. pr_debug("%s: creating MVM full ctrl\n", __func__);
  647. mvm_session_cmd.hdr.hdr_field =
  648. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  649. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  650. mvm_session_cmd.hdr.pkt_size =
  651. APR_PKT_SIZE(APR_HDR_SIZE,
  652. sizeof(mvm_session_cmd) -
  653. APR_HDR_SIZE);
  654. mvm_session_cmd.hdr.src_port =
  655. voice_get_idx_for_session(v->session_id);
  656. mvm_session_cmd.hdr.dest_port = 0;
  657. mvm_session_cmd.hdr.token = 0;
  658. mvm_session_cmd.hdr.opcode =
  659. VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
  660. strlcpy(mvm_session_cmd.mvm_session.name,
  661. "default voip",
  662. strlen("default voip")+1);
  663. v->mvm_state = CMD_STATUS_FAIL;
  664. ret = apr_send_pkt(apr_mvm,
  665. (uint32_t *) &mvm_session_cmd);
  666. if (ret < 0) {
  667. pr_err("Fail in sending MVM_CONTROL_SESSION\n");
  668. goto fail;
  669. }
  670. ret = wait_event_timeout(v->mvm_wait,
  671. (v->mvm_state == CMD_STATUS_SUCCESS),
  672. msecs_to_jiffies(TIMEOUT_MS));
  673. if (!ret) {
  674. pr_err("%s: wait_event timeout\n", __func__);
  675. goto fail;
  676. }
  677. }
  678. /* Get the created MVM handle. */
  679. mvm_handle = voice_get_mvm_handle(v);
  680. }
  681. /* send cmd to create cvs session */
  682. if (!cvs_handle) {
  683. memset(cvs_session_cmd.cvs_session.name, 0,
  684. sizeof(cvs_session_cmd.cvs_session.name));
  685. if (!is_voip_session(v->session_id)) {
  686. pr_debug("%s: creating CVS passive session\n",
  687. __func__);
  688. cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  689. APR_MSG_TYPE_SEQ_CMD,
  690. APR_HDR_LEN(APR_HDR_SIZE),
  691. APR_PKT_VER);
  692. cvs_session_cmd.hdr.pkt_size =
  693. APR_PKT_SIZE(APR_HDR_SIZE,
  694. sizeof(cvs_session_cmd) -
  695. APR_HDR_SIZE);
  696. cvs_session_cmd.hdr.src_port =
  697. voice_get_idx_for_session(v->session_id);
  698. cvs_session_cmd.hdr.dest_port = 0;
  699. cvs_session_cmd.hdr.token = 0;
  700. cvs_session_cmd.hdr.opcode =
  701. VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  702. if (is_volte_session(v->session_id)) {
  703. strlcpy(cvs_session_cmd.cvs_session.name,
  704. "default volte voice",
  705. strlen("default volte voice")+1);
  706. } else if (is_voice2_session(v->session_id)) {
  707. if(In_roaming == true) { //MSM 2nd call
  708. strlcpy(cvs_session_cmd.cvs_session.name,
  709. VOICE2_SESSION_VSID_STR,
  710. sizeof(cvs_session_cmd.cvs_session.name));
  711. }
  712. else { //QSC call
  713. strlcpy(cvs_session_cmd.cvs_session.name,
  714. #ifdef CONFIG_DSDA_VIA_UART
  715. "default modem voice2",
  716. #else
  717. VOICE2_SESSION_VSID_STR,
  718. #endif /* CONFIG_DSDA_VIA_UART */
  719. strlen(VOICE2_SESSION_VSID_STR)+1);
  720. }
  721. } else if (is_qchat_session(v->session_id)) {
  722. strlcpy(cvs_session_cmd.cvs_session.name,
  723. QCHAT_SESSION_VSID_STR,
  724. strlen(QCHAT_SESSION_VSID_STR)+1);
  725. } else if (is_vowlan_session(v->session_id)) {
  726. strlcpy(cvs_session_cmd.cvs_session.name,
  727. VOWLAN_SESSION_VSID_STR,
  728. strlen(VOWLAN_SESSION_VSID_STR)+1);
  729. } else {
  730. strlcpy(cvs_session_cmd.cvs_session.name,
  731. "default modem voice",
  732. strlen("default modem voice")+1);
  733. }
  734. v->cvs_state = CMD_STATUS_FAIL;
  735. ret = apr_send_pkt(apr_cvs,
  736. (uint32_t *) &cvs_session_cmd);
  737. if (ret < 0) {
  738. pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
  739. goto fail;
  740. }
  741. ret = wait_event_timeout(v->cvs_wait,
  742. (v->cvs_state == CMD_STATUS_SUCCESS),
  743. msecs_to_jiffies(TIMEOUT_MS));
  744. if (!ret) {
  745. pr_err("%s: wait_event timeout\n", __func__);
  746. goto fail;
  747. }
  748. /* Get the created CVS handle. */
  749. cvs_handle = voice_get_cvs_handle(v);
  750. } else {
  751. pr_debug("%s: creating CVS full session\n", __func__);
  752. cvs_full_ctl_cmd.hdr.hdr_field =
  753. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  754. APR_HDR_LEN(APR_HDR_SIZE),
  755. APR_PKT_VER);
  756. cvs_full_ctl_cmd.hdr.pkt_size =
  757. APR_PKT_SIZE(APR_HDR_SIZE,
  758. sizeof(cvs_full_ctl_cmd) -
  759. APR_HDR_SIZE);
  760. cvs_full_ctl_cmd.hdr.src_port =
  761. voice_get_idx_for_session(v->session_id);
  762. cvs_full_ctl_cmd.hdr.dest_port = 0;
  763. cvs_full_ctl_cmd.hdr.token = 0;
  764. cvs_full_ctl_cmd.hdr.opcode =
  765. VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
  766. cvs_full_ctl_cmd.cvs_session.direction = 2;
  767. cvs_full_ctl_cmd.cvs_session.enc_media_type =
  768. common.mvs_info.media_type;
  769. cvs_full_ctl_cmd.cvs_session.dec_media_type =
  770. common.mvs_info.media_type;
  771. cvs_full_ctl_cmd.cvs_session.network_id =
  772. common.mvs_info.network_type;
  773. strlcpy(cvs_full_ctl_cmd.cvs_session.name,
  774. "default q6 voice",
  775. strlen("default q6 voice")+1);
  776. v->cvs_state = CMD_STATUS_FAIL;
  777. ret = apr_send_pkt(apr_cvs,
  778. (uint32_t *) &cvs_full_ctl_cmd);
  779. if (ret < 0) {
  780. pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
  781. __func__, ret);
  782. goto fail;
  783. }
  784. ret = wait_event_timeout(v->cvs_wait,
  785. (v->cvs_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. /* Get the created CVS handle. */
  792. cvs_handle = voice_get_cvs_handle(v);
  793. /* Attach MVM to CVS. */
  794. pr_debug("%s: Attach MVM to stream\n", __func__);
  795. attach_stream_cmd.hdr.hdr_field =
  796. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  797. APR_HDR_LEN(APR_HDR_SIZE),
  798. APR_PKT_VER);
  799. attach_stream_cmd.hdr.pkt_size =
  800. APR_PKT_SIZE(APR_HDR_SIZE,
  801. sizeof(attach_stream_cmd) -
  802. APR_HDR_SIZE);
  803. attach_stream_cmd.hdr.src_port =
  804. voice_get_idx_for_session(v->session_id);
  805. attach_stream_cmd.hdr.dest_port = mvm_handle;
  806. attach_stream_cmd.hdr.token = 0;
  807. attach_stream_cmd.hdr.opcode =
  808. VSS_IMVM_CMD_ATTACH_STREAM;
  809. attach_stream_cmd.attach_stream.handle = cvs_handle;
  810. v->mvm_state = CMD_STATUS_FAIL;
  811. ret = apr_send_pkt(apr_mvm,
  812. (uint32_t *) &attach_stream_cmd);
  813. if (ret < 0) {
  814. pr_err("%s: Error %d sending ATTACH_STREAM\n",
  815. __func__, ret);
  816. goto fail;
  817. }
  818. ret = wait_event_timeout(v->mvm_wait,
  819. (v->mvm_state == CMD_STATUS_SUCCESS),
  820. msecs_to_jiffies(TIMEOUT_MS));
  821. if (!ret) {
  822. pr_err("%s: wait_event timeout\n", __func__);
  823. goto fail;
  824. }
  825. }
  826. }
  827. return 0;
  828. fail:
  829. return -EINVAL;
  830. }
  831. static int voice_destroy_mvm_cvs_session(struct voice_data *v)
  832. {
  833. int ret = 0;
  834. struct mvm_detach_stream_cmd detach_stream;
  835. struct apr_hdr mvm_destroy;
  836. struct apr_hdr cvs_destroy;
  837. void *apr_mvm, *apr_cvs;
  838. u16 mvm_handle, cvs_handle;
  839. if (v == NULL) {
  840. pr_err("%s: v is NULL\n", __func__);
  841. return -EINVAL;
  842. }
  843. apr_mvm = common.apr_q6_mvm;
  844. apr_cvs = common.apr_q6_cvs;
  845. if (!apr_mvm || !apr_cvs) {
  846. pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
  847. return -EINVAL;
  848. }
  849. mvm_handle = voice_get_mvm_handle(v);
  850. cvs_handle = voice_get_cvs_handle(v);
  851. /* MVM, CVS sessions are destroyed only for Full control sessions. */
  852. if (is_voip_session(v->session_id)) {
  853. pr_debug("%s: MVM detach stream, VOC_STATE: %d\n", __func__,
  854. v->voc_state);
  855. /* Detach voice stream. */
  856. detach_stream.hdr.hdr_field =
  857. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  858. APR_HDR_LEN(APR_HDR_SIZE),
  859. APR_PKT_VER);
  860. detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  861. sizeof(detach_stream) - APR_HDR_SIZE);
  862. detach_stream.hdr.src_port =
  863. voice_get_idx_for_session(v->session_id);
  864. detach_stream.hdr.dest_port = mvm_handle;
  865. detach_stream.hdr.token = 0;
  866. detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
  867. detach_stream.detach_stream.handle = cvs_handle;
  868. v->mvm_state = CMD_STATUS_FAIL;
  869. ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
  870. if (ret < 0) {
  871. pr_err("%s: Error %d sending DETACH_STREAM\n",
  872. __func__, ret);
  873. goto fail;
  874. }
  875. ret = wait_event_timeout(v->mvm_wait,
  876. (v->mvm_state == CMD_STATUS_SUCCESS),
  877. msecs_to_jiffies(TIMEOUT_MS));
  878. if (!ret) {
  879. pr_err("%s: wait event timeout\n", __func__);
  880. goto fail;
  881. }
  882. /* Unmap memory */
  883. if (v->shmem_info.mem_handle != 0) {
  884. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  885. v->shmem_info.mem_handle);
  886. if (ret < 0) {
  887. pr_err("%s Memory_unmap for voip failed %d\n",
  888. __func__, ret);
  889. goto fail;
  890. }
  891. v->shmem_info.mem_handle = 0;
  892. }
  893. }
  894. if (is_voip_session(v->session_id) ||
  895. is_qchat_session(v->session_id) ||
  896. is_volte_session(v->session_id) ||
  897. v->voc_state == VOC_ERROR) {
  898. /* Destroy CVS. */
  899. pr_debug("%s: CVS destroy session\n", __func__);
  900. cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  901. APR_HDR_LEN(APR_HDR_SIZE),
  902. APR_PKT_VER);
  903. cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  904. sizeof(cvs_destroy) - APR_HDR_SIZE);
  905. cvs_destroy.src_port =
  906. voice_get_idx_for_session(v->session_id);
  907. cvs_destroy.dest_port = cvs_handle;
  908. cvs_destroy.token = 0;
  909. cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  910. v->cvs_state = CMD_STATUS_FAIL;
  911. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
  912. if (ret < 0) {
  913. pr_err("%s: Error %d sending CVS DESTROY\n",
  914. __func__, ret);
  915. goto fail;
  916. }
  917. ret = wait_event_timeout(v->cvs_wait,
  918. (v->cvs_state == CMD_STATUS_SUCCESS),
  919. msecs_to_jiffies(TIMEOUT_MS));
  920. if (!ret) {
  921. pr_err("%s: wait event timeout\n", __func__);
  922. goto fail;
  923. }
  924. cvs_handle = 0;
  925. voice_set_cvs_handle(v, cvs_handle);
  926. /* Unmap physical memory for calibration */
  927. pr_debug("%s: cal_mem_handle %d\n", __func__,
  928. common.cal_mem_handle);
  929. if (!is_other_session_active(v->session_id) &&
  930. (common.cal_mem_handle != 0)) {
  931. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  932. common.cal_mem_handle);
  933. if (ret < 0) {
  934. pr_err("%s Fail at cal mem unmap %d\n",
  935. __func__, ret);
  936. goto fail;
  937. }
  938. common.cal_mem_handle = 0;
  939. }
  940. /* Destroy MVM. */
  941. pr_debug("MVM destroy session\n");
  942. mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  943. APR_HDR_LEN(APR_HDR_SIZE),
  944. APR_PKT_VER);
  945. mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  946. sizeof(mvm_destroy) - APR_HDR_SIZE);
  947. mvm_destroy.src_port =
  948. voice_get_idx_for_session(v->session_id);
  949. mvm_destroy.dest_port = mvm_handle;
  950. mvm_destroy.token = 0;
  951. mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  952. v->mvm_state = CMD_STATUS_FAIL;
  953. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
  954. if (ret < 0) {
  955. pr_err("%s: Error %d sending MVM DESTROY\n",
  956. __func__, ret);
  957. goto fail;
  958. }
  959. ret = wait_event_timeout(v->mvm_wait,
  960. (v->mvm_state == CMD_STATUS_SUCCESS),
  961. msecs_to_jiffies(TIMEOUT_MS));
  962. if (!ret) {
  963. pr_err("%s: wait event timeout\n", __func__);
  964. goto fail;
  965. }
  966. mvm_handle = 0;
  967. voice_set_mvm_handle(v, mvm_handle);
  968. }
  969. return 0;
  970. fail:
  971. return -EINVAL;
  972. }
  973. static int voice_send_tty_mode_cmd(struct voice_data *v)
  974. {
  975. int ret = 0;
  976. struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
  977. void *apr_mvm;
  978. u16 mvm_handle;
  979. if (v == NULL) {
  980. pr_err("%s: v is NULL\n", __func__);
  981. return -EINVAL;
  982. }
  983. apr_mvm = common.apr_q6_mvm;
  984. if (!apr_mvm) {
  985. pr_err("%s: apr_mvm is NULL.\n", __func__);
  986. return -EINVAL;
  987. }
  988. mvm_handle = voice_get_mvm_handle(v);
  989. /* send tty mode cmd to mvm */
  990. mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
  991. APR_MSG_TYPE_SEQ_CMD,
  992. APR_HDR_LEN(APR_HDR_SIZE),
  993. APR_PKT_VER);
  994. mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  995. sizeof(mvm_tty_mode_cmd) -
  996. APR_HDR_SIZE);
  997. pr_debug("%s: pkt size = %d\n",
  998. __func__, mvm_tty_mode_cmd.hdr.pkt_size);
  999. mvm_tty_mode_cmd.hdr.src_port =
  1000. voice_get_idx_for_session(v->session_id);
  1001. mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
  1002. mvm_tty_mode_cmd.hdr.token = 0;
  1003. mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
  1004. mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
  1005. pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
  1006. v->mvm_state = CMD_STATUS_FAIL;
  1007. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
  1008. if (ret < 0) {
  1009. pr_err("%s: Error %d sending SET_TTY_MODE\n",
  1010. __func__, ret);
  1011. goto fail;
  1012. }
  1013. ret = wait_event_timeout(v->mvm_wait,
  1014. (v->mvm_state == CMD_STATUS_SUCCESS),
  1015. msecs_to_jiffies(TIMEOUT_MS));
  1016. if (!ret) {
  1017. pr_err("%s: wait_event timeout\n", __func__);
  1018. goto fail;
  1019. }
  1020. return 0;
  1021. fail:
  1022. return -EINVAL;
  1023. }
  1024. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  1025. uint32_t module_id, int enable)
  1026. {
  1027. struct cvs_set_pp_enable_cmd cvs_set_pp_cmd;
  1028. int ret = 0;
  1029. void *apr_cvs;
  1030. u16 cvs_handle;
  1031. if (v == NULL) {
  1032. pr_err("%s: v is NULL\n", __func__);
  1033. return -EINVAL;
  1034. }
  1035. apr_cvs = common.apr_q6_cvs;
  1036. if (!apr_cvs) {
  1037. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1038. return -EINVAL;
  1039. }
  1040. cvs_handle = voice_get_cvs_handle(v);
  1041. cvs_set_pp_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1042. APR_HDR_LEN(APR_HDR_SIZE),
  1043. APR_PKT_VER);
  1044. cvs_set_pp_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1045. sizeof(cvs_set_pp_cmd) -
  1046. APR_HDR_SIZE);
  1047. cvs_set_pp_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  1048. cvs_set_pp_cmd.hdr.dest_port = cvs_handle;
  1049. cvs_set_pp_cmd.hdr.token = 0;
  1050. cvs_set_pp_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  1051. cvs_set_pp_cmd.vss_set_pp.module_id = module_id;
  1052. cvs_set_pp_cmd.vss_set_pp.param_id = VOICE_PARAM_MOD_ENABLE;
  1053. cvs_set_pp_cmd.vss_set_pp.param_size = MOD_ENABLE_PARAM_LEN;
  1054. cvs_set_pp_cmd.vss_set_pp.reserved = 0;
  1055. cvs_set_pp_cmd.vss_set_pp.enable = enable;
  1056. cvs_set_pp_cmd.vss_set_pp.reserved_field = 0;
  1057. pr_debug("voice_send_set_pp_enable_cmd, module_id=%d, enable=%d\n",
  1058. module_id, enable);
  1059. v->cvs_state = CMD_STATUS_FAIL;
  1060. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_pp_cmd);
  1061. if (ret < 0) {
  1062. pr_err("Fail: sending cvs set pp enable,\n");
  1063. goto fail;
  1064. }
  1065. ret = wait_event_timeout(v->cvs_wait,
  1066. (v->cvs_state == CMD_STATUS_SUCCESS),
  1067. msecs_to_jiffies(TIMEOUT_MS));
  1068. if (!ret) {
  1069. pr_err("%s: wait_event timeout\n", __func__);
  1070. goto fail;
  1071. }
  1072. return 0;
  1073. fail:
  1074. return -EINVAL;
  1075. }
  1076. static int voice_set_dtx(struct voice_data *v)
  1077. {
  1078. int ret = 0;
  1079. void *apr_cvs;
  1080. u16 cvs_handle;
  1081. struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
  1082. if (v == NULL) {
  1083. pr_err("%s: v is NULL\n", __func__);
  1084. return -EINVAL;
  1085. }
  1086. apr_cvs = common.apr_q6_cvs;
  1087. if (!apr_cvs) {
  1088. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1089. return -EINVAL;
  1090. }
  1091. cvs_handle = voice_get_cvs_handle(v);
  1092. /* Set DTX */
  1093. cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1094. APR_HDR_LEN(APR_HDR_SIZE),
  1095. APR_PKT_VER);
  1096. cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1097. sizeof(cvs_set_dtx) - APR_HDR_SIZE);
  1098. cvs_set_dtx.hdr.src_port =
  1099. voice_get_idx_for_session(v->session_id);
  1100. cvs_set_dtx.hdr.dest_port = cvs_handle;
  1101. cvs_set_dtx.hdr.token = 0;
  1102. cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
  1103. cvs_set_dtx.dtx_mode.enable = common.mvs_info.dtx_mode;
  1104. pr_debug("%s: Setting DTX %d\n", __func__, common.mvs_info.dtx_mode);
  1105. v->cvs_state = CMD_STATUS_FAIL;
  1106. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
  1107. if (ret < 0) {
  1108. pr_err("%s: Error %d sending SET_DTX\n", __func__, ret);
  1109. return -EINVAL;
  1110. }
  1111. ret = wait_event_timeout(v->cvs_wait,
  1112. (v->cvs_state == CMD_STATUS_SUCCESS),
  1113. msecs_to_jiffies(TIMEOUT_MS));
  1114. if (!ret) {
  1115. pr_err("%s: wait_event timeout\n", __func__);
  1116. return -EINVAL;
  1117. }
  1118. return 0;
  1119. }
  1120. static int voice_send_mvm_media_type_cmd(struct voice_data *v)
  1121. {
  1122. struct vss_imvm_cmd_set_cal_media_type_t mvm_set_cal_media_type;
  1123. int ret = 0;
  1124. void *apr_mvm;
  1125. u16 mvm_handle;
  1126. if (v == NULL) {
  1127. pr_err("%s: v is NULL\n", __func__);
  1128. return -EINVAL;
  1129. }
  1130. apr_mvm = common.apr_q6_mvm;
  1131. if (!apr_mvm) {
  1132. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1133. return -EINVAL;
  1134. }
  1135. mvm_handle = voice_get_mvm_handle(v);
  1136. mvm_set_cal_media_type.hdr.hdr_field =
  1137. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1138. APR_HDR_LEN(APR_HDR_SIZE),
  1139. APR_PKT_VER);
  1140. mvm_set_cal_media_type.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1141. sizeof(mvm_set_cal_media_type) -
  1142. APR_HDR_SIZE);
  1143. mvm_set_cal_media_type.hdr.src_port =
  1144. voice_get_idx_for_session(v->session_id);
  1145. mvm_set_cal_media_type.hdr.dest_port = mvm_handle;
  1146. mvm_set_cal_media_type.hdr.token = 0;
  1147. mvm_set_cal_media_type.hdr.opcode = VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE;
  1148. mvm_set_cal_media_type.media_id = common.mvs_info.media_type;
  1149. pr_debug("%s: setting media_id as %x\n",
  1150. __func__ , mvm_set_cal_media_type.media_id);
  1151. v->mvm_state = CMD_STATUS_FAIL;
  1152. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_media_type);
  1153. if (ret < 0) {
  1154. pr_err("%s: Error %d sending media type\n", __func__, ret);
  1155. goto fail;
  1156. }
  1157. ret = wait_event_timeout(v->mvm_wait,
  1158. (v->mvm_state == CMD_STATUS_SUCCESS),
  1159. msecs_to_jiffies(TIMEOUT_MS));
  1160. if (!ret) {
  1161. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  1162. goto fail;
  1163. }
  1164. return 0;
  1165. fail:
  1166. return -EINVAL;
  1167. }
  1168. static int voice_send_dtmf_rx_detection_cmd(struct voice_data *v,
  1169. uint32_t enable)
  1170. {
  1171. int ret = 0;
  1172. void *apr_cvs;
  1173. u16 cvs_handle;
  1174. struct cvs_set_rx_dtmf_detection_cmd cvs_dtmf_rx_detection;
  1175. if (v == NULL) {
  1176. pr_err("%s: v is NULL\n", __func__);
  1177. return -EINVAL;
  1178. }
  1179. apr_cvs = common.apr_q6_cvs;
  1180. if (!apr_cvs) {
  1181. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1182. return -EINVAL;
  1183. }
  1184. cvs_handle = voice_get_cvs_handle(v);
  1185. /* Set SET_DTMF_RX_DETECTION */
  1186. cvs_dtmf_rx_detection.hdr.hdr_field =
  1187. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1188. APR_HDR_LEN(APR_HDR_SIZE),
  1189. APR_PKT_VER);
  1190. cvs_dtmf_rx_detection.hdr.pkt_size =
  1191. APR_PKT_SIZE(APR_HDR_SIZE,
  1192. sizeof(cvs_dtmf_rx_detection) - APR_HDR_SIZE);
  1193. cvs_dtmf_rx_detection.hdr.src_port =
  1194. voice_get_idx_for_session(v->session_id);
  1195. cvs_dtmf_rx_detection.hdr.dest_port = cvs_handle;
  1196. cvs_dtmf_rx_detection.hdr.token = 0;
  1197. cvs_dtmf_rx_detection.hdr.opcode =
  1198. VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION;
  1199. cvs_dtmf_rx_detection.cvs_dtmf_det.enable = enable;
  1200. v->cvs_state = CMD_STATUS_FAIL;
  1201. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dtmf_rx_detection);
  1202. if (ret < 0) {
  1203. pr_err("%s: Error %d sending SET_DTMF_RX_DETECTION\n",
  1204. __func__,
  1205. ret);
  1206. return -EINVAL;
  1207. }
  1208. ret = wait_event_timeout(v->cvs_wait,
  1209. (v->cvs_state == CMD_STATUS_SUCCESS),
  1210. msecs_to_jiffies(TIMEOUT_MS));
  1211. if (!ret) {
  1212. pr_err("%s: wait_event timeout\n", __func__);
  1213. return -EINVAL;
  1214. }
  1215. return ret;
  1216. }
  1217. void voc_disable_dtmf_det_on_active_sessions(void)
  1218. {
  1219. struct voice_data *v = NULL;
  1220. int i;
  1221. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  1222. v = &common.voice[i];
  1223. if ((v->dtmf_rx_detect_en) &&
  1224. is_voc_state_active(v->voc_state)) {
  1225. pr_debug("disable dtmf det on ses_id=%d\n",
  1226. v->session_id);
  1227. voice_send_dtmf_rx_detection_cmd(v, 0);
  1228. }
  1229. }
  1230. }
  1231. int voc_enable_dtmf_rx_detection(uint32_t session_id, uint32_t enable)
  1232. {
  1233. struct voice_data *v = voice_get_session(session_id);
  1234. int ret = 0;
  1235. if (v == NULL) {
  1236. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  1237. return -EINVAL;
  1238. }
  1239. mutex_lock(&v->lock);
  1240. v->dtmf_rx_detect_en = enable;
  1241. if (is_voc_state_active(v->voc_state))
  1242. ret = voice_send_dtmf_rx_detection_cmd(v,
  1243. v->dtmf_rx_detect_en);
  1244. mutex_unlock(&v->lock);
  1245. return ret;
  1246. }
  1247. int voc_alloc_cal_shared_memory(void)
  1248. {
  1249. int rc = 0;
  1250. mutex_lock(&common.common_lock);
  1251. if (is_cal_memory_allocated()) {
  1252. pr_debug("%s: Calibration shared buffer already allocated",
  1253. __func__);
  1254. } else {
  1255. /* Allocate memory for calibration memory map table. */
  1256. rc = voice_alloc_cal_mem_map_table();
  1257. if (rc < 0) {
  1258. pr_err("%s: Failed to allocate cal memory, err=%d",
  1259. __func__, rc);
  1260. }
  1261. }
  1262. mutex_unlock(&common.common_lock);
  1263. return rc;
  1264. }
  1265. int voc_alloc_voip_shared_memory(void)
  1266. {
  1267. int rc = 0;
  1268. /* Allocate shared memory for OOB Voip */
  1269. rc = voice_alloc_oob_shared_mem();
  1270. if (rc < 0) {
  1271. pr_err("%s: Failed to alloc shared memory for OOB rc:%d\n",
  1272. __func__, rc);
  1273. } else {
  1274. /* Allocate mem map table for OOB */
  1275. rc = voice_alloc_oob_mem_table();
  1276. if (rc < 0) {
  1277. pr_err("%s: Failed to alloc mem map talbe rc:%d\n",
  1278. __func__, rc);
  1279. voice_free_oob_shared_mem();
  1280. }
  1281. }
  1282. return rc;
  1283. }
  1284. static int is_cal_memory_allocated(void)
  1285. {
  1286. bool ret;
  1287. if (common.cal_mem_map_table.client != NULL &&
  1288. common.cal_mem_map_table.handle != NULL)
  1289. ret = true;
  1290. else
  1291. ret = false;
  1292. return ret;
  1293. }
  1294. static int free_cal_map_table(void)
  1295. {
  1296. int ret = 0;
  1297. if ((common.cal_mem_map_table.client == NULL) ||
  1298. (common.cal_mem_map_table.handle == NULL))
  1299. goto done;
  1300. ret = msm_audio_ion_free(common.cal_mem_map_table.client,
  1301. common.cal_mem_map_table.handle);
  1302. if (ret < 0) {
  1303. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1304. ret = -EPERM;
  1305. }
  1306. done:
  1307. common.cal_mem_map_table.client = NULL;
  1308. common.cal_mem_map_table.handle = NULL;
  1309. return ret;
  1310. }
  1311. static int is_rtac_memory_allocated(void)
  1312. {
  1313. bool ret;
  1314. if (common.rtac_mem_map_table.client != NULL &&
  1315. common.rtac_mem_map_table.handle != NULL)
  1316. ret = true;
  1317. else
  1318. ret = false;
  1319. return ret;
  1320. }
  1321. static int free_rtac_map_table(void)
  1322. {
  1323. int ret = 0;
  1324. if ((common.rtac_mem_map_table.client == NULL) ||
  1325. (common.rtac_mem_map_table.handle == NULL))
  1326. goto done;
  1327. ret = msm_audio_ion_free(common.rtac_mem_map_table.client,
  1328. common.rtac_mem_map_table.handle);
  1329. if (ret < 0) {
  1330. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1331. ret = -EPERM;
  1332. }
  1333. done:
  1334. common.rtac_mem_map_table.client = NULL;
  1335. common.rtac_mem_map_table.handle = NULL;
  1336. return ret;
  1337. }
  1338. static int is_voip_memory_allocated(void)
  1339. {
  1340. bool ret;
  1341. struct voice_data *v = voice_get_session(
  1342. common.voice[VOC_PATH_FULL].session_id);
  1343. if (v == NULL) {
  1344. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1345. common.voice[VOC_PATH_FULL].session_id);
  1346. ret = false;
  1347. goto done;
  1348. }
  1349. mutex_lock(&common.common_lock);
  1350. if (v->shmem_info.sh_buf.client != NULL &&
  1351. v->shmem_info.sh_buf.handle != NULL)
  1352. ret = true;
  1353. else
  1354. ret = false;
  1355. mutex_unlock(&common.common_lock);
  1356. done:
  1357. return ret;
  1358. }
  1359. static int voice_config_cvs_vocoder_amr_rate(struct voice_data *v)
  1360. {
  1361. int ret = 0;
  1362. void *apr_cvs;
  1363. u16 cvs_handle;
  1364. struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
  1365. if (v == NULL) {
  1366. pr_err("%s: v is NULL\n", __func__);
  1367. ret = -EINVAL;
  1368. goto done;
  1369. }
  1370. apr_cvs = common.apr_q6_cvs;
  1371. if (!apr_cvs) {
  1372. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1373. ret = -EINVAL;
  1374. goto done;
  1375. }
  1376. cvs_handle = voice_get_cvs_handle(v);
  1377. pr_debug("%s: Setting AMR rate. Media Type: %d\n", __func__,
  1378. common.mvs_info.media_type);
  1379. cvs_set_amr_rate.hdr.hdr_field =
  1380. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1381. APR_HDR_LEN(APR_HDR_SIZE),
  1382. APR_PKT_VER);
  1383. cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1384. sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
  1385. cvs_set_amr_rate.hdr.src_port =
  1386. voice_get_idx_for_session(v->session_id);
  1387. cvs_set_amr_rate.hdr.dest_port = cvs_handle;
  1388. cvs_set_amr_rate.hdr.token = 0;
  1389. if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_NB_MODEM)
  1390. cvs_set_amr_rate.hdr.opcode =
  1391. VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
  1392. else if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_WB_MODEM)
  1393. cvs_set_amr_rate.hdr.opcode =
  1394. VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
  1395. cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
  1396. v->cvs_state = CMD_STATUS_FAIL;
  1397. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
  1398. if (ret < 0) {
  1399. pr_err("%s: Error %d sending SET_AMR_RATE\n",
  1400. __func__, ret);
  1401. goto done;
  1402. }
  1403. ret = wait_event_timeout(v->cvs_wait,
  1404. (v->cvs_state == CMD_STATUS_SUCCESS),
  1405. msecs_to_jiffies(TIMEOUT_MS));
  1406. if (!ret) {
  1407. pr_err("%s: wait_event timeout\n", __func__);
  1408. ret = -EINVAL;
  1409. goto done;
  1410. }
  1411. return 0;
  1412. done:
  1413. return ret;
  1414. }
  1415. static int voice_config_cvs_vocoder(struct voice_data *v)
  1416. {
  1417. int ret = 0;
  1418. void *apr_cvs;
  1419. u16 cvs_handle;
  1420. /* Set media type. */
  1421. struct cvs_set_media_type_cmd cvs_set_media_cmd;
  1422. if (v == NULL) {
  1423. pr_err("%s: v is NULL\n", __func__);
  1424. return -EINVAL;
  1425. }
  1426. apr_cvs = common.apr_q6_cvs;
  1427. if (!apr_cvs) {
  1428. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1429. return -EINVAL;
  1430. }
  1431. cvs_handle = voice_get_cvs_handle(v);
  1432. cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1433. APR_HDR_LEN(APR_HDR_SIZE),
  1434. APR_PKT_VER);
  1435. cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1436. sizeof(cvs_set_media_cmd) -
  1437. APR_HDR_SIZE);
  1438. cvs_set_media_cmd.hdr.src_port =
  1439. voice_get_idx_for_session(v->session_id);
  1440. cvs_set_media_cmd.hdr.dest_port = cvs_handle;
  1441. cvs_set_media_cmd.hdr.token = 0;
  1442. cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
  1443. cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
  1444. cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
  1445. v->cvs_state = CMD_STATUS_FAIL;
  1446. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
  1447. if (ret < 0) {
  1448. pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
  1449. __func__, ret);
  1450. goto fail;
  1451. }
  1452. ret = wait_event_timeout(v->cvs_wait,
  1453. (v->cvs_state == CMD_STATUS_SUCCESS),
  1454. msecs_to_jiffies(TIMEOUT_MS));
  1455. if (!ret) {
  1456. pr_err("%s: wait_event timeout\n", __func__);
  1457. goto fail;
  1458. }
  1459. /* Set encoder properties. */
  1460. switch (common.mvs_info.media_type) {
  1461. case VSS_MEDIA_ID_EVRC_MODEM:
  1462. case VSS_MEDIA_ID_4GV_NB_MODEM:
  1463. case VSS_MEDIA_ID_4GV_WB_MODEM:
  1464. case VSS_MEDIA_ID_4GV_NW_MODEM: {
  1465. struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
  1466. pr_debug("Setting EVRC min-max rate\n");
  1467. cvs_set_cdma_rate.hdr.hdr_field =
  1468. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1469. APR_HDR_LEN(APR_HDR_SIZE),
  1470. APR_PKT_VER);
  1471. cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1472. sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
  1473. cvs_set_cdma_rate.hdr.src_port =
  1474. voice_get_idx_for_session(v->session_id);
  1475. cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
  1476. cvs_set_cdma_rate.hdr.token = 0;
  1477. cvs_set_cdma_rate.hdr.opcode =
  1478. VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
  1479. cvs_set_cdma_rate.cdma_rate.min_rate =
  1480. common.mvs_info.evrc_min_rate;
  1481. cvs_set_cdma_rate.cdma_rate.max_rate =
  1482. common.mvs_info.evrc_max_rate;
  1483. v->cvs_state = CMD_STATUS_FAIL;
  1484. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
  1485. if (ret < 0) {
  1486. pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
  1487. __func__, ret);
  1488. goto fail;
  1489. }
  1490. ret = wait_event_timeout(v->cvs_wait,
  1491. (v->cvs_state == CMD_STATUS_SUCCESS),
  1492. msecs_to_jiffies(TIMEOUT_MS));
  1493. if (!ret) {
  1494. pr_err("%s: wait_event timeout\n", __func__);
  1495. goto fail;
  1496. }
  1497. if (common.mvs_info.media_type != VSS_MEDIA_ID_EVRC_MODEM) {
  1498. ret = voice_set_dtx(v);
  1499. if (ret < 0)
  1500. goto fail;
  1501. }
  1502. break;
  1503. }
  1504. case VSS_MEDIA_ID_AMR_NB_MODEM:
  1505. case VSS_MEDIA_ID_AMR_WB_MODEM: {
  1506. ret = voice_config_cvs_vocoder_amr_rate(v);
  1507. if (ret) {
  1508. pr_err("%s: Failed to update vocoder rate. %d\n",
  1509. __func__, ret);
  1510. goto fail;
  1511. }
  1512. ret = voice_set_dtx(v);
  1513. if (ret < 0)
  1514. goto fail;
  1515. break;
  1516. }
  1517. case VSS_MEDIA_ID_G729:
  1518. case VSS_MEDIA_ID_G711_ALAW:
  1519. case VSS_MEDIA_ID_G711_MULAW: {
  1520. ret = voice_set_dtx(v);
  1521. break;
  1522. }
  1523. default:
  1524. /* Do nothing. */
  1525. break;
  1526. }
  1527. return 0;
  1528. fail:
  1529. return -EINVAL;
  1530. }
  1531. int voc_update_amr_vocoder_rate(uint32_t session_id)
  1532. {
  1533. int ret = 0;
  1534. struct voice_data *v;
  1535. pr_debug("%s: session_id:%d", __func__, session_id);
  1536. v = voice_get_session(session_id);
  1537. if (v == NULL) {
  1538. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1539. session_id);
  1540. ret = -EINVAL;
  1541. goto done;
  1542. }
  1543. mutex_lock(&v->lock);
  1544. ret = voice_config_cvs_vocoder_amr_rate(v);
  1545. mutex_unlock(&v->lock);
  1546. done:
  1547. return ret;
  1548. }
  1549. static int voice_send_start_voice_cmd(struct voice_data *v)
  1550. {
  1551. struct apr_hdr mvm_start_voice_cmd;
  1552. int ret = 0;
  1553. void *apr_mvm;
  1554. u16 mvm_handle;
  1555. if (v == NULL) {
  1556. pr_err("%s: v is NULL\n", __func__);
  1557. return -EINVAL;
  1558. }
  1559. apr_mvm = common.apr_q6_mvm;
  1560. if (!apr_mvm) {
  1561. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1562. return -EINVAL;
  1563. }
  1564. mvm_handle = voice_get_mvm_handle(v);
  1565. mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1566. APR_HDR_LEN(APR_HDR_SIZE),
  1567. APR_PKT_VER);
  1568. mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1569. sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
  1570. pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
  1571. mvm_start_voice_cmd.pkt_size);
  1572. mvm_start_voice_cmd.src_port =
  1573. voice_get_idx_for_session(v->session_id);
  1574. mvm_start_voice_cmd.dest_port = mvm_handle;
  1575. mvm_start_voice_cmd.token = 0;
  1576. mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
  1577. v->mvm_state = CMD_STATUS_FAIL;
  1578. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
  1579. if (ret < 0) {
  1580. pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
  1581. goto fail;
  1582. }
  1583. ret = wait_event_timeout(v->mvm_wait,
  1584. (v->mvm_state == CMD_STATUS_SUCCESS),
  1585. msecs_to_jiffies(TIMEOUT_MS));
  1586. if (!ret) {
  1587. pr_err("%s: wait_event timeout\n", __func__);
  1588. goto fail;
  1589. }
  1590. return 0;
  1591. fail:
  1592. return -EINVAL;
  1593. }
  1594. static int voice_send_disable_vocproc_cmd(struct voice_data *v)
  1595. {
  1596. struct apr_hdr cvp_disable_cmd;
  1597. int ret = 0;
  1598. void *apr_cvp;
  1599. u16 cvp_handle;
  1600. if (v == NULL) {
  1601. pr_err("%s: v is NULL\n", __func__);
  1602. return -EINVAL;
  1603. }
  1604. apr_cvp = common.apr_q6_cvp;
  1605. if (!apr_cvp) {
  1606. pr_err("%s: apr regist failed\n", __func__);
  1607. return -EINVAL;
  1608. }
  1609. cvp_handle = voice_get_cvp_handle(v);
  1610. /* disable vocproc and wait for respose */
  1611. cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1612. APR_HDR_LEN(APR_HDR_SIZE),
  1613. APR_PKT_VER);
  1614. cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1615. sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
  1616. pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
  1617. cvp_disable_cmd.pkt_size, cvp_handle);
  1618. cvp_disable_cmd.src_port =
  1619. voice_get_idx_for_session(v->session_id);
  1620. cvp_disable_cmd.dest_port = cvp_handle;
  1621. cvp_disable_cmd.token = 0;
  1622. cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
  1623. v->cvp_state = CMD_STATUS_FAIL;
  1624. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
  1625. if (ret < 0) {
  1626. pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
  1627. goto fail;
  1628. }
  1629. ret = wait_event_timeout(v->cvp_wait,
  1630. (v->cvp_state == CMD_STATUS_SUCCESS),
  1631. msecs_to_jiffies(TIMEOUT_MS));
  1632. if (!ret) {
  1633. pr_err("%s: wait_event timeout\n", __func__);
  1634. goto fail;
  1635. }
  1636. return 0;
  1637. fail:
  1638. return -EINVAL;
  1639. }
  1640. static void voc_get_tx_rx_topology(struct voice_data *v,
  1641. uint32_t *tx_topology_id,
  1642. uint32_t *rx_topology_id)
  1643. {
  1644. uint32_t tx_id = 0;
  1645. uint32_t rx_id = 0;
  1646. if (v->lch_mode == VOICE_LCH_START) {
  1647. pr_debug("%s: Setting TX and RX topology to NONE for LCH\n",
  1648. __func__);
  1649. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1650. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1651. } else {
  1652. /* Use default topology if invalid value in ACDB */
  1653. tx_id = get_voice_tx_topology();
  1654. if (tx_id == 0)
  1655. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
  1656. rx_id = get_voice_rx_topology();
  1657. if (rx_id == 0)
  1658. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  1659. }
  1660. *tx_topology_id = tx_id;
  1661. *rx_topology_id = rx_id;
  1662. }
  1663. static int voice_send_set_device_cmd(struct voice_data *v)
  1664. {
  1665. struct cvp_set_device_cmd cvp_setdev_cmd;
  1666. int ret = 0;
  1667. void *apr_cvp;
  1668. u16 cvp_handle;
  1669. if (v == NULL) {
  1670. pr_err("%s: v is NULL\n", __func__);
  1671. return -EINVAL;
  1672. }
  1673. apr_cvp = common.apr_q6_cvp;
  1674. if (!apr_cvp) {
  1675. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1676. return -EINVAL;
  1677. }
  1678. cvp_handle = voice_get_cvp_handle(v);
  1679. /* set device and wait for response */
  1680. cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1681. APR_HDR_LEN(APR_HDR_SIZE),
  1682. APR_PKT_VER);
  1683. cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1684. sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
  1685. pr_debug(" send create cvp setdev, pkt size = %d\n",
  1686. cvp_setdev_cmd.hdr.pkt_size);
  1687. cvp_setdev_cmd.hdr.src_port =
  1688. voice_get_idx_for_session(v->session_id);
  1689. cvp_setdev_cmd.hdr.dest_port = cvp_handle;
  1690. cvp_setdev_cmd.hdr.token = 0;
  1691. cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE_V2;
  1692. voc_get_tx_rx_topology(v,
  1693. &cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  1694. &cvp_setdev_cmd.cvp_set_device_v2.rx_topology_id);
  1695. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id = v->dev_tx.port_id;
  1696. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id = v->dev_rx.port_id;
  1697. if (common.ec_ref_ext) {
  1698. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  1699. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  1700. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  1701. common.ec_port_id;
  1702. } else {
  1703. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  1704. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  1705. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  1706. VSS_IVOCPROC_PORT_ID_NONE;
  1707. }
  1708. pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
  1709. cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  1710. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id,
  1711. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id);
  1712. v->cvp_state = CMD_STATUS_FAIL;
  1713. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
  1714. if (ret < 0) {
  1715. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  1716. goto fail;
  1717. }
  1718. pr_debug("wait for cvp create session event\n");
  1719. ret = wait_event_timeout(v->cvp_wait,
  1720. (v->cvp_state == CMD_STATUS_SUCCESS),
  1721. msecs_to_jiffies(TIMEOUT_MS));
  1722. if (!ret) {
  1723. pr_err("%s: wait_event timeout\n", __func__);
  1724. goto fail;
  1725. }
  1726. return 0;
  1727. fail:
  1728. return -EINVAL;
  1729. }
  1730. static int voice_send_stop_voice_cmd(struct voice_data *v)
  1731. {
  1732. struct apr_hdr mvm_stop_voice_cmd;
  1733. int ret = 0;
  1734. void *apr_mvm;
  1735. u16 mvm_handle;
  1736. if (v == NULL) {
  1737. pr_err("%s: v is NULL\n", __func__);
  1738. return -EINVAL;
  1739. }
  1740. apr_mvm = common.apr_q6_mvm;
  1741. if (!apr_mvm) {
  1742. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1743. return -EINVAL;
  1744. }
  1745. mvm_handle = voice_get_mvm_handle(v);
  1746. mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1747. APR_HDR_LEN(APR_HDR_SIZE),
  1748. APR_PKT_VER);
  1749. mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1750. sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
  1751. pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
  1752. mvm_stop_voice_cmd.pkt_size);
  1753. mvm_stop_voice_cmd.src_port =
  1754. voice_get_idx_for_session(v->session_id);
  1755. mvm_stop_voice_cmd.dest_port = mvm_handle;
  1756. mvm_stop_voice_cmd.token = 0;
  1757. mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
  1758. v->mvm_state = CMD_STATUS_FAIL;
  1759. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
  1760. if (ret < 0) {
  1761. pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
  1762. goto fail;
  1763. }
  1764. ret = wait_event_timeout(v->mvm_wait,
  1765. (v->mvm_state == CMD_STATUS_SUCCESS),
  1766. msecs_to_jiffies(TIMEOUT_MS));
  1767. if (!ret) {
  1768. pr_err("%s: wait_event timeout\n", __func__);
  1769. goto fail;
  1770. }
  1771. return 0;
  1772. fail:
  1773. return -EINVAL;
  1774. }
  1775. static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
  1776. {
  1777. struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
  1778. struct acdb_cal_block cal_block;
  1779. int ret = 0;
  1780. memset(&cvs_reg_cal_cmd, 0, sizeof(cvs_reg_cal_cmd));
  1781. if (v == NULL) {
  1782. pr_err("%s: v is NULL\n", __func__);
  1783. ret = -EINVAL;
  1784. goto done;
  1785. }
  1786. if (!common.apr_q6_cvs) {
  1787. pr_err("%s: apr_cvs is NULL\n", __func__);
  1788. ret = -EINVAL;
  1789. goto done;
  1790. }
  1791. if (!common.cal_mem_handle) {
  1792. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1793. ret = -EINVAL;
  1794. goto done;
  1795. }
  1796. get_vocstrm_cal(&cal_block);
  1797. if (cal_block.cal_size == 0) {
  1798. pr_err("%s: CVS cal size is 0\n", __func__);
  1799. ret = -EINVAL;
  1800. goto done;
  1801. }
  1802. cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1803. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1804. cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1805. sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
  1806. cvs_reg_cal_cmd.hdr.src_port =
  1807. voice_get_idx_for_session(v->session_id);
  1808. cvs_reg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  1809. cvs_reg_cal_cmd.hdr.token = 0;
  1810. cvs_reg_cal_cmd.hdr.opcode =
  1811. VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2;
  1812. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_handle = common.cal_mem_handle;
  1813. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address = cal_block.cal_paddr;
  1814. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_size = cal_block.cal_size;
  1815. /* Get the column info corresponding to CVS cal from ACDB. */
  1816. get_voice_col_data(VOCSTRM_CAL, &cal_block);
  1817. if (cal_block.cal_size == 0 ||
  1818. cal_block.cal_size >
  1819. sizeof(cvs_reg_cal_cmd.cvs_cal_data.column_info)) {
  1820. pr_err("%s: Invalid VOCSTRM_CAL size %d\n",
  1821. __func__, cal_block.cal_size);
  1822. ret = -EINVAL;
  1823. goto done;
  1824. }
  1825. memcpy(&cvs_reg_cal_cmd.cvs_cal_data.column_info[0],
  1826. (void *) cal_block.cal_kvaddr,
  1827. cal_block.cal_size);
  1828. v->cvs_state = CMD_STATUS_FAIL;
  1829. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_reg_cal_cmd);
  1830. if (ret < 0) {
  1831. pr_err("%s: Error %d registering CVS cal\n", __func__, ret);
  1832. ret = -EINVAL;
  1833. goto done;
  1834. }
  1835. ret = wait_event_timeout(v->cvs_wait,
  1836. (v->cvs_state == CMD_STATUS_SUCCESS),
  1837. msecs_to_jiffies(TIMEOUT_MS));
  1838. if (!ret) {
  1839. pr_err("%s: Command timeout\n", __func__);
  1840. ret = -EINVAL;
  1841. goto done;
  1842. }
  1843. done:
  1844. return ret;
  1845. }
  1846. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
  1847. {
  1848. struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
  1849. struct acdb_cal_block cal_block;
  1850. int ret = 0;
  1851. memset(&cvs_dereg_cal_cmd, 0, sizeof(cvs_dereg_cal_cmd));
  1852. if (v == NULL) {
  1853. pr_err("%s: v is NULL\n", __func__);
  1854. ret = -EINVAL;
  1855. goto done;
  1856. }
  1857. if (!common.apr_q6_cvs) {
  1858. pr_err("%s: apr_cvs is NULL\n", __func__);
  1859. ret = -EPERM;
  1860. goto done;
  1861. }
  1862. if (!common.cal_mem_handle) {
  1863. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1864. ret = -EPERM;
  1865. goto done;
  1866. }
  1867. get_vocstrm_cal(&cal_block);
  1868. if (cal_block.cal_size == 0) {
  1869. pr_err("%s: CVS cal size is 0\n", __func__);
  1870. ret = -EPERM;
  1871. goto done;
  1872. }
  1873. cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1874. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1875. cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1876. sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
  1877. cvs_dereg_cal_cmd.hdr.src_port =
  1878. voice_get_idx_for_session(v->session_id);
  1879. cvs_dereg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  1880. cvs_dereg_cal_cmd.hdr.token = 0;
  1881. cvs_dereg_cal_cmd.hdr.opcode =
  1882. VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
  1883. v->cvs_state = CMD_STATUS_FAIL;
  1884. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
  1885. if (ret < 0) {
  1886. pr_err("%s: Error %d de-registering CVS cal\n", __func__, ret);
  1887. ret = -EINVAL;
  1888. goto done;
  1889. }
  1890. ret = wait_event_timeout(v->cvs_wait,
  1891. (v->cvs_state == CMD_STATUS_SUCCESS),
  1892. msecs_to_jiffies(TIMEOUT_MS));
  1893. if (!ret) {
  1894. pr_err("%s: Command timeout\n", __func__);
  1895. ret = -EINVAL;
  1896. goto done;
  1897. }
  1898. done:
  1899. return ret;
  1900. }
  1901. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v)
  1902. {
  1903. struct cvp_register_dev_cfg_cmd cvp_reg_dev_cfg_cmd;
  1904. struct acdb_cal_block cal_block;
  1905. int ret = 0;
  1906. memset(&cvp_reg_dev_cfg_cmd, 0, sizeof(cvp_reg_dev_cfg_cmd));
  1907. if (v == NULL) {
  1908. pr_err("%s: v is NULL\n", __func__);
  1909. ret = -EINVAL;
  1910. goto done;
  1911. }
  1912. if (!common.apr_q6_cvp) {
  1913. pr_err("%s: apr_cvp is NULL\n", __func__);
  1914. ret = -EPERM;
  1915. goto done;
  1916. }
  1917. if (!common.cal_mem_handle) {
  1918. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1919. ret = -EPERM;
  1920. goto done;
  1921. }
  1922. get_vocproc_dev_cfg_cal(&cal_block);
  1923. if (cal_block.cal_size == 0) {
  1924. pr_err("%s: CVP cal size is 0\n", __func__);
  1925. ret = -EPERM;
  1926. goto done;
  1927. }
  1928. cvp_reg_dev_cfg_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1929. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1930. cvp_reg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1931. sizeof(cvp_reg_dev_cfg_cmd) - APR_HDR_SIZE);
  1932. cvp_reg_dev_cfg_cmd.hdr.src_port =
  1933. voice_get_idx_for_session(v->session_id);
  1934. cvp_reg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  1935. cvp_reg_dev_cfg_cmd.hdr.token = 0;
  1936. cvp_reg_dev_cfg_cmd.hdr.opcode =
  1937. VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG;
  1938. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_handle = common.cal_mem_handle;
  1939. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address = cal_block.cal_paddr;
  1940. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_size = cal_block.cal_size;
  1941. v->cvp_state = CMD_STATUS_FAIL;
  1942. ret = apr_send_pkt(common.apr_q6_cvp,
  1943. (uint32_t *) &cvp_reg_dev_cfg_cmd);
  1944. if (ret < 0) {
  1945. pr_err("%s: Error %d registering CVP dev cfg cal\n",
  1946. __func__, ret);
  1947. ret = -EINVAL;
  1948. goto done;
  1949. }
  1950. ret = wait_event_timeout(v->cvp_wait,
  1951. (v->cvp_state == CMD_STATUS_SUCCESS),
  1952. msecs_to_jiffies(TIMEOUT_MS));
  1953. if (!ret) {
  1954. pr_err("%s: Command timeout\n", __func__);
  1955. ret = -EINVAL;
  1956. goto done;
  1957. }
  1958. done:
  1959. return ret;
  1960. }
  1961. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v)
  1962. {
  1963. struct cvp_deregister_dev_cfg_cmd cvp_dereg_dev_cfg_cmd;
  1964. struct acdb_cal_block cal_block;
  1965. int ret = 0;
  1966. memset(&cvp_dereg_dev_cfg_cmd, 0, sizeof(cvp_dereg_dev_cfg_cmd));
  1967. if (v == NULL) {
  1968. pr_err("%s: v is NULL\n", __func__);
  1969. ret = -EINVAL;
  1970. goto done;
  1971. }
  1972. if (!common.apr_q6_cvp) {
  1973. pr_err("%s: apr_cvp is NULL\n", __func__);
  1974. ret = -EPERM;
  1975. goto done;
  1976. }
  1977. if (!common.cal_mem_handle) {
  1978. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1979. ret = -EPERM;
  1980. goto done;
  1981. }
  1982. get_vocproc_dev_cfg_cal(&cal_block);
  1983. if (cal_block.cal_size == 0) {
  1984. pr_err("%s: CVP cal size is 0\n", __func__);
  1985. ret = -EPERM;
  1986. goto done;
  1987. }
  1988. cvp_dereg_dev_cfg_cmd.hdr.hdr_field =
  1989. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1990. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1991. cvp_dereg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1992. sizeof(cvp_dereg_dev_cfg_cmd) - APR_HDR_SIZE);
  1993. cvp_dereg_dev_cfg_cmd.hdr.src_port =
  1994. voice_get_idx_for_session(v->session_id);
  1995. cvp_dereg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  1996. cvp_dereg_dev_cfg_cmd.hdr.token = 0;
  1997. cvp_dereg_dev_cfg_cmd.hdr.opcode =
  1998. VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG;
  1999. v->cvp_state = CMD_STATUS_FAIL;
  2000. ret = apr_send_pkt(common.apr_q6_cvp,
  2001. (uint32_t *) &cvp_dereg_dev_cfg_cmd);
  2002. if (ret < 0) {
  2003. pr_err("%s: Error %d de-registering CVP dev cfg cal\n",
  2004. __func__, ret);
  2005. ret = -EINVAL;
  2006. goto done;
  2007. }
  2008. ret = wait_event_timeout(v->cvp_wait,
  2009. (v->cvp_state == CMD_STATUS_SUCCESS),
  2010. msecs_to_jiffies(TIMEOUT_MS));
  2011. if (!ret) {
  2012. pr_err("%s: Command timeout\n", __func__);
  2013. ret = -EINVAL;
  2014. goto done;
  2015. }
  2016. done:
  2017. return ret;
  2018. }
  2019. static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
  2020. {
  2021. struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
  2022. struct acdb_cal_block cal_block;
  2023. int ret = 0;
  2024. memset(&cvp_reg_cal_cmd, 0, sizeof(cvp_reg_cal_cmd));
  2025. if (v == NULL) {
  2026. pr_err("%s: v is NULL\n", __func__);
  2027. ret = -EINVAL;
  2028. goto done;
  2029. }
  2030. if (!common.apr_q6_cvp) {
  2031. pr_err("%s: apr_cvp is NULL\n", __func__);
  2032. ret = -EINVAL;
  2033. goto done;
  2034. }
  2035. if (!common.cal_mem_handle) {
  2036. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2037. ret = -EINVAL;
  2038. goto done;
  2039. }
  2040. get_vocproc_cal(&cal_block);
  2041. if (cal_block.cal_size == 0) {
  2042. pr_err("%s: CVP cal size is 0\n", __func__);
  2043. ret = -EINVAL;
  2044. goto done;
  2045. }
  2046. cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2047. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2048. cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2049. sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
  2050. cvp_reg_cal_cmd.hdr.src_port =
  2051. voice_get_idx_for_session(v->session_id);
  2052. cvp_reg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2053. cvp_reg_cal_cmd.hdr.token = 0;
  2054. cvp_reg_cal_cmd.hdr.opcode =
  2055. VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2;
  2056. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_handle = common.cal_mem_handle;
  2057. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address = cal_block.cal_paddr;
  2058. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_size = cal_block.cal_size;
  2059. /* Get the column info corresponding to CVP cal from ACDB. */
  2060. get_voice_col_data(VOCPROC_CAL, &cal_block);
  2061. if (cal_block.cal_size == 0 ||
  2062. cal_block.cal_size >
  2063. sizeof(cvp_reg_cal_cmd.cvp_cal_data.column_info)) {
  2064. pr_err("%s: Invalid VOCPROC_CAL size %d\n",
  2065. __func__, cal_block.cal_size);
  2066. ret = -EINVAL;
  2067. goto done;
  2068. }
  2069. memcpy(&cvp_reg_cal_cmd.cvp_cal_data.column_info[0],
  2070. (void *) cal_block.cal_kvaddr,
  2071. cal_block.cal_size);
  2072. v->cvp_state = CMD_STATUS_FAIL;
  2073. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_reg_cal_cmd);
  2074. if (ret < 0) {
  2075. pr_err("%s: Error %d registering CVP cal\n", __func__, ret);
  2076. ret = -EINVAL;
  2077. goto done;
  2078. }
  2079. ret = wait_event_timeout(v->cvp_wait,
  2080. (v->cvp_state == CMD_STATUS_SUCCESS),
  2081. msecs_to_jiffies(TIMEOUT_MS));
  2082. if (!ret) {
  2083. pr_err("%s: Command timeout\n", __func__);
  2084. ret = -EINVAL;
  2085. goto done;
  2086. }
  2087. done:
  2088. return ret;
  2089. }
  2090. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
  2091. {
  2092. struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
  2093. struct acdb_cal_block cal_block;
  2094. int ret = 0;
  2095. memset(&cvp_dereg_cal_cmd, 0, sizeof(cvp_dereg_cal_cmd));
  2096. if (v == NULL) {
  2097. pr_err("%s: v is NULL\n", __func__);
  2098. ret = -EINVAL;
  2099. goto done;
  2100. }
  2101. if (!common.apr_q6_cvp) {
  2102. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2103. ret = -EPERM;
  2104. goto done;
  2105. }
  2106. if (!common.cal_mem_handle) {
  2107. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2108. ret = -EPERM;
  2109. goto done;
  2110. }
  2111. get_vocproc_cal(&cal_block);
  2112. if (cal_block.cal_size == 0) {
  2113. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2114. ret = -EPERM;
  2115. goto done;
  2116. }
  2117. cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2118. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2119. cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2120. sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
  2121. cvp_dereg_cal_cmd.hdr.src_port =
  2122. voice_get_idx_for_session(v->session_id);
  2123. cvp_dereg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2124. cvp_dereg_cal_cmd.hdr.token = 0;
  2125. cvp_dereg_cal_cmd.hdr.opcode =
  2126. VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
  2127. v->cvp_state = CMD_STATUS_FAIL;
  2128. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
  2129. if (ret < 0) {
  2130. pr_err("%s: Error %d de-registering CVP cal\n", __func__, ret);
  2131. ret = -EINVAL;
  2132. goto done;
  2133. }
  2134. ret = wait_event_timeout(v->cvp_wait,
  2135. (v->cvp_state == CMD_STATUS_SUCCESS),
  2136. msecs_to_jiffies(TIMEOUT_MS));
  2137. if (!ret) {
  2138. pr_err("%s: Command timeout\n", __func__);
  2139. ret = -EINVAL;
  2140. goto done;
  2141. }
  2142. done:
  2143. return -EINVAL;
  2144. }
  2145. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v)
  2146. {
  2147. struct cvp_register_vol_cal_data_cmd cvp_reg_vol_cal_cmd;
  2148. struct acdb_cal_block cal_block;
  2149. int ret = 0;
  2150. memset(&cvp_reg_vol_cal_cmd, 0, sizeof(cvp_reg_vol_cal_cmd));
  2151. if (v == NULL) {
  2152. pr_err("%s: v is NULL\n", __func__);
  2153. ret = -EINVAL;
  2154. goto done;
  2155. }
  2156. if (!common.apr_q6_cvp) {
  2157. pr_err("%s: apr_cvp is NULL\n", __func__);
  2158. ret = -EINVAL;
  2159. goto done;
  2160. }
  2161. if (!common.cal_mem_handle) {
  2162. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2163. ret = -EINVAL;
  2164. goto done;
  2165. }
  2166. get_vocvol_cal(&cal_block);
  2167. if (cal_block.cal_size == 0) {
  2168. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2169. ret = -EINVAL;
  2170. goto done;
  2171. }
  2172. cvp_reg_vol_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2173. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2174. cvp_reg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2175. sizeof(cvp_reg_vol_cal_cmd) - APR_HDR_SIZE);
  2176. cvp_reg_vol_cal_cmd.hdr.src_port =
  2177. voice_get_idx_for_session(v->session_id);
  2178. cvp_reg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2179. cvp_reg_vol_cal_cmd.hdr.token = 0;
  2180. cvp_reg_vol_cal_cmd.hdr.opcode =
  2181. VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA;
  2182. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_handle =
  2183. common.cal_mem_handle;
  2184. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address =
  2185. cal_block.cal_paddr;
  2186. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_size = cal_block.cal_size;
  2187. /* Get the column info corresponding to CVP volume cal from ACDB. */
  2188. get_voice_col_data(VOCVOL_CAL, &cal_block);
  2189. if (cal_block.cal_size == 0 ||
  2190. cal_block.cal_size >
  2191. sizeof(cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info)) {
  2192. pr_err("%s: Invalid VOCVOL_CAL size %d\n",
  2193. __func__, cal_block.cal_size);
  2194. ret = -EINVAL;
  2195. goto done;
  2196. }
  2197. memcpy(&cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info[0],
  2198. (void *) cal_block.cal_kvaddr,
  2199. cal_block.cal_size);
  2200. v->cvp_state = CMD_STATUS_FAIL;
  2201. ret = apr_send_pkt(common.apr_q6_cvp,
  2202. (uint32_t *) &cvp_reg_vol_cal_cmd);
  2203. if (ret < 0) {
  2204. pr_err("%s: Error %d registering CVP vol cal\n", __func__, ret);
  2205. ret = -EINVAL;
  2206. goto done;
  2207. }
  2208. ret = wait_event_timeout(v->cvp_wait,
  2209. (v->cvp_state == CMD_STATUS_SUCCESS),
  2210. msecs_to_jiffies(TIMEOUT_MS));
  2211. if (!ret) {
  2212. pr_err("%s: Command timeout\n", __func__);
  2213. ret = -EINVAL;
  2214. goto done;
  2215. }
  2216. done:
  2217. return ret;
  2218. }
  2219. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v)
  2220. {
  2221. struct cvp_deregister_vol_cal_data_cmd cvp_dereg_vol_cal_cmd;
  2222. struct acdb_cal_block cal_block;
  2223. int ret = 0;
  2224. memset(&cvp_dereg_vol_cal_cmd, 0, sizeof(cvp_dereg_vol_cal_cmd));
  2225. if (v == NULL) {
  2226. pr_err("%s: v is NULL\n", __func__);
  2227. ret = -EINVAL;
  2228. goto done;
  2229. }
  2230. if (!common.apr_q6_cvp) {
  2231. pr_err("%s: apr_cvp is NULL\n", __func__);
  2232. ret = -EPERM;
  2233. goto done;
  2234. }
  2235. if (!common.cal_mem_handle) {
  2236. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2237. ret = -EPERM;
  2238. goto done;
  2239. }
  2240. get_vocvol_cal(&cal_block);
  2241. if (cal_block.cal_size == 0) {
  2242. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2243. ret = -EPERM;
  2244. goto done;
  2245. }
  2246. cvp_dereg_vol_cal_cmd.hdr.hdr_field =
  2247. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2248. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2249. cvp_dereg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2250. sizeof(cvp_dereg_vol_cal_cmd) - APR_HDR_SIZE);
  2251. cvp_dereg_vol_cal_cmd.hdr.src_port =
  2252. voice_get_idx_for_session(v->session_id);
  2253. cvp_dereg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2254. cvp_dereg_vol_cal_cmd.hdr.token = 0;
  2255. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2256. VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA;
  2257. v->cvp_state = CMD_STATUS_FAIL;
  2258. ret = apr_send_pkt(common.apr_q6_cvp,
  2259. (uint32_t *) &cvp_dereg_vol_cal_cmd);
  2260. if (ret < 0) {
  2261. pr_err("%s: Error %d de-registering CVP vol cal\n",
  2262. __func__, ret);
  2263. ret = -EINVAL;
  2264. goto done;
  2265. }
  2266. ret = wait_event_timeout(v->cvp_wait,
  2267. (v->cvp_state == CMD_STATUS_SUCCESS),
  2268. msecs_to_jiffies(TIMEOUT_MS));
  2269. if (!ret) {
  2270. pr_err("%s: Command timeout\n", __func__);
  2271. ret = -EINVAL;
  2272. goto done;
  2273. }
  2274. done:
  2275. return ret;
  2276. }
  2277. static int voice_map_memory_physical_cmd(struct voice_data *v,
  2278. struct mem_map_table *table_info,
  2279. dma_addr_t phys,
  2280. uint32_t size,
  2281. uint32_t token)
  2282. {
  2283. struct vss_imemory_cmd_map_physical_t mvm_map_phys_cmd;
  2284. uint32_t *memtable;
  2285. int ret = 0;
  2286. if (v == NULL) {
  2287. pr_err("%s: v is NULL\n", __func__);
  2288. goto fail;
  2289. }
  2290. if (!common.apr_q6_mvm) {
  2291. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2292. goto fail;
  2293. }
  2294. if (!table_info->data) {
  2295. pr_err("%s: memory table is NULL.\n", __func__);
  2296. goto fail;
  2297. }
  2298. memtable = (uint32_t *) table_info->data;
  2299. /*
  2300. * Store next table descriptor's address(64 bit) as NULL as there
  2301. * is only one memory block
  2302. */
  2303. memtable[0] = (uint32_t)NULL;
  2304. memtable[1] = (uint32_t)NULL;
  2305. /* Store next table descriptor's size */
  2306. memtable[2] = 0;
  2307. /* Store shared mem add */
  2308. memtable[3] = phys;
  2309. memtable[4] = 0;
  2310. /* Store shared memory size */
  2311. memtable[5] = size;
  2312. mvm_map_phys_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2313. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2314. mvm_map_phys_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2315. sizeof(mvm_map_phys_cmd) - APR_HDR_SIZE);
  2316. mvm_map_phys_cmd.hdr.src_port =
  2317. voice_get_idx_for_session(v->session_id);
  2318. mvm_map_phys_cmd.hdr.dest_port = voice_get_mvm_handle(v);
  2319. mvm_map_phys_cmd.hdr.token = token;
  2320. mvm_map_phys_cmd.hdr.opcode = VSS_IMEMORY_CMD_MAP_PHYSICAL;
  2321. mvm_map_phys_cmd.table_descriptor.mem_address = table_info->phys;
  2322. mvm_map_phys_cmd.table_descriptor.mem_size =
  2323. sizeof(struct vss_imemory_block_t) +
  2324. sizeof(struct vss_imemory_table_descriptor_t);
  2325. mvm_map_phys_cmd.is_cached = true;
  2326. mvm_map_phys_cmd.cache_line_size = 128;
  2327. mvm_map_phys_cmd.access_mask = 3;
  2328. mvm_map_phys_cmd.page_align = 4096;
  2329. mvm_map_phys_cmd.min_data_width = 8;
  2330. mvm_map_phys_cmd.max_data_width = 64;
  2331. pr_debug("%s: next table desc: add: %lld, size: %d\n",
  2332. __func__, *((uint64_t *) memtable),
  2333. *(((uint32_t *) memtable) + 2));
  2334. pr_debug("%s: phy add of of mem being mapped 0x%x, size: %d\n",
  2335. __func__, *(((uint32_t *) memtable) + 3),
  2336. *(((uint32_t *) memtable) + 5));
  2337. v->mvm_state = CMD_STATUS_FAIL;
  2338. ret = apr_send_pkt(common.apr_q6_mvm, (uint32_t *) &mvm_map_phys_cmd);
  2339. if (ret < 0) {
  2340. pr_err("%s: Error %d sending mvm map phy cmd\n", __func__, ret);
  2341. goto fail;
  2342. }
  2343. ret = wait_event_timeout(v->mvm_wait,
  2344. (v->mvm_state == CMD_STATUS_SUCCESS),
  2345. msecs_to_jiffies(TIMEOUT_MS));
  2346. if (!ret) {
  2347. pr_err("%s: Command timeout\n", __func__);
  2348. goto fail;
  2349. }
  2350. return 0;
  2351. fail:
  2352. return -EINVAL;
  2353. }
  2354. static int send_packet_loopback_cmd(struct voice_data *v, bool mode)
  2355. {
  2356. struct cvs_set_loopback_enable_cmd cvs_set_loopback_cmd;
  2357. int ret = 0;
  2358. void *apr_cvs;
  2359. u16 cvs_handle;
  2360. if (v == NULL) {
  2361. pr_err("%s: v is NULL\n", __func__);
  2362. return -EINVAL;
  2363. }
  2364. apr_cvs = common.apr_q6_cvs;
  2365. if (!apr_cvs) {
  2366. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2367. return -EINVAL;
  2368. }
  2369. cvs_handle = voice_get_cvs_handle(v);
  2370. /* fill in the header */
  2371. cvs_set_loopback_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2372. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2373. cvs_set_loopback_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2374. sizeof(cvs_set_loopback_cmd) - APR_HDR_SIZE);
  2375. cvs_set_loopback_cmd.hdr.src_port =
  2376. voice_get_idx_for_session(v->session_id);
  2377. cvs_set_loopback_cmd.hdr.dest_port = cvs_handle;
  2378. cvs_set_loopback_cmd.hdr.token = 0;
  2379. cvs_set_loopback_cmd.hdr.opcode = VOICE_CMD_SET_PARAM;
  2380. cvs_set_loopback_cmd.mem_handle = 0;
  2381. cvs_set_loopback_cmd.mem_address = 0;
  2382. cvs_set_loopback_cmd.mem_size = 0x10;
  2383. cvs_set_loopback_cmd.vss_set_loopback.module_id = VOICEPROC_MODULE_VENC;
  2384. cvs_set_loopback_cmd.vss_set_loopback.param_id = VOICE_PARAM_LOOPBACK_ENABLE;
  2385. cvs_set_loopback_cmd.vss_set_loopback.param_size = MOD_ENABLE_PARAM_LEN;
  2386. cvs_set_loopback_cmd.vss_set_loopback.reserved = 0;
  2387. cvs_set_loopback_cmd.vss_set_loopback.loopback_enable = (mode)? 1: 0;
  2388. cvs_set_loopback_cmd.vss_set_loopback.reserved_field = 0;
  2389. v->cvs_state = CMD_STATUS_FAIL;
  2390. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_loopback_cmd);
  2391. if (ret < 0) {
  2392. pr_err("Fail: sending cvs set loopback enable,\n");
  2393. goto fail;
  2394. }
  2395. ret = wait_event_timeout(v->cvs_wait,
  2396. (v->cvs_state == CMD_STATUS_SUCCESS),
  2397. msecs_to_jiffies(TIMEOUT_MS));
  2398. if (!ret) {
  2399. pr_err("%s: wait_event timeout\n", __func__);
  2400. goto fail;
  2401. }
  2402. return 0;
  2403. fail:
  2404. return -EINVAL;
  2405. }
  2406. static int voice_mem_map_cal_block(struct voice_data *v)
  2407. {
  2408. int ret = 0;
  2409. struct acdb_cal_block cal_block;
  2410. if (v == NULL) {
  2411. pr_err("%s: v is NULL\n", __func__);
  2412. return -EINVAL;
  2413. }
  2414. mutex_lock(&common.common_lock);
  2415. if (common.cal_mem_handle != 0) {
  2416. pr_debug("%s: Cal block already mem mapped\n", __func__);
  2417. goto done;
  2418. }
  2419. /* Get the physical address of calibration memory block from ACDB. */
  2420. get_voice_cal_allocation(&cal_block);
  2421. if (!cal_block.cal_paddr) {
  2422. pr_err("%s: Cal block not allocated\n", __func__);
  2423. ret = -EINVAL;
  2424. goto done;
  2425. }
  2426. ret = voice_map_memory_physical_cmd(v,
  2427. &common.cal_mem_map_table,
  2428. cal_block.cal_paddr,
  2429. cal_block.cal_size,
  2430. VOC_CAL_MEM_MAP_TOKEN);
  2431. done:
  2432. mutex_unlock(&common.common_lock);
  2433. return ret;
  2434. }
  2435. static int voice_pause_voice_call(struct voice_data *v)
  2436. {
  2437. struct apr_hdr mvm_pause_voice_cmd;
  2438. void *apr_mvm;
  2439. int ret = 0;
  2440. pr_debug("%s\n", __func__);
  2441. if (v == NULL) {
  2442. pr_err("%s: Voice data is NULL\n", __func__);
  2443. ret = -EINVAL;
  2444. goto done;
  2445. }
  2446. apr_mvm = common.apr_q6_mvm;
  2447. if (!apr_mvm) {
  2448. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2449. ret = -EINVAL;
  2450. goto done;
  2451. }
  2452. mvm_pause_voice_cmd.hdr_field =
  2453. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2454. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2455. mvm_pause_voice_cmd.pkt_size =
  2456. APR_PKT_SIZE(APR_HDR_SIZE,
  2457. sizeof(mvm_pause_voice_cmd) - APR_HDR_SIZE);
  2458. mvm_pause_voice_cmd.src_port =
  2459. voice_get_idx_for_session(v->session_id);
  2460. mvm_pause_voice_cmd.dest_port = voice_get_mvm_handle(v);
  2461. mvm_pause_voice_cmd.token = 0;
  2462. mvm_pause_voice_cmd.opcode = VSS_IMVM_CMD_PAUSE_VOICE;
  2463. v->mvm_state = CMD_STATUS_FAIL;
  2464. pr_debug("%s: send mvm_pause_voice_cmd pkt size = %d\n",
  2465. __func__, mvm_pause_voice_cmd.pkt_size);
  2466. ret = apr_send_pkt(apr_mvm,
  2467. (uint32_t *)&mvm_pause_voice_cmd);
  2468. if (ret < 0) {
  2469. pr_err("Fail in sending VSS_IMVM_CMD_PAUSE_VOICE\n");
  2470. ret = -EINVAL;
  2471. goto done;
  2472. }
  2473. ret = wait_event_timeout(v->mvm_wait,
  2474. (v->mvm_state == CMD_STATUS_SUCCESS),
  2475. msecs_to_jiffies(TIMEOUT_MS));
  2476. if (!ret) {
  2477. pr_err("%s: Command timeout\n", __func__);
  2478. ret = -EINVAL;
  2479. goto done;
  2480. }
  2481. done:
  2482. return ret;
  2483. }
  2484. int voc_register_vocproc_vol_table(void)
  2485. {
  2486. int result = 0;
  2487. int result2 = 0;
  2488. int i;
  2489. struct voice_data *v = NULL;
  2490. pr_debug("%s\n", __func__);
  2491. mutex_lock(&common.common_lock);
  2492. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2493. v = &common.voice[i];
  2494. mutex_lock(&v->lock);
  2495. if (is_voc_state_active(v->voc_state)) {
  2496. result2 = voice_send_cvp_register_vol_cal_cmd(v);
  2497. if (result2 < 0) {
  2498. pr_err("%s: Failed to register vocvol table for session 0x%x!\n",
  2499. __func__, v->session_id);
  2500. result = result2;
  2501. /* Still try to register other sessions */
  2502. }
  2503. }
  2504. mutex_unlock(&v->lock);
  2505. }
  2506. mutex_unlock(&common.common_lock);
  2507. return result;
  2508. }
  2509. int voc_deregister_vocproc_vol_table(void)
  2510. {
  2511. int result = 0;
  2512. int success = 0;
  2513. int i;
  2514. struct voice_data *v = NULL;
  2515. pr_debug("%s\n", __func__);
  2516. mutex_lock(&common.common_lock);
  2517. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2518. v = &common.voice[i];
  2519. mutex_lock(&v->lock);
  2520. if (is_voc_state_active(v->voc_state)) {
  2521. result = voice_send_cvp_deregister_vol_cal_cmd(v);
  2522. if (result < 0) {
  2523. pr_err("%s: Failed to deregister vocvol table for session 0x%x!\n",
  2524. __func__, v->session_id);
  2525. mutex_unlock(&v->lock);
  2526. mutex_unlock(&common.common_lock);
  2527. if (success) {
  2528. pr_err("%s: Try to re-register all deregistered sessions!\n",
  2529. __func__);
  2530. voc_register_vocproc_vol_table();
  2531. }
  2532. goto done;
  2533. } else {
  2534. success = 1;
  2535. }
  2536. }
  2537. mutex_unlock(&v->lock);
  2538. }
  2539. mutex_unlock(&common.common_lock);
  2540. done:
  2541. return result;
  2542. }
  2543. int voc_map_rtac_block(struct rtac_cal_block_data *cal_block)
  2544. {
  2545. int result = 0;
  2546. struct voice_data *v = NULL;
  2547. pr_debug("%s\n", __func__);
  2548. if (cal_block == NULL) {
  2549. pr_err("%s: cal_block is NULL!\n",
  2550. __func__);
  2551. result = -EINVAL;
  2552. goto done;
  2553. }
  2554. if (cal_block->cal_data.paddr == 0) {
  2555. pr_debug("%s: No address to map!\n",
  2556. __func__);
  2557. result = -EINVAL;
  2558. goto done;
  2559. }
  2560. if (cal_block->map_data.map_size == 0) {
  2561. pr_debug("%s: map size is 0!\n",
  2562. __func__);
  2563. result = -EINVAL;
  2564. goto done;
  2565. }
  2566. mutex_lock(&common.common_lock);
  2567. /* use first session */
  2568. v = &common.voice[0];
  2569. mutex_lock(&v->lock);
  2570. if (!is_rtac_memory_allocated()) {
  2571. result = voice_alloc_rtac_mem_map_table();
  2572. if (result < 0) {
  2573. pr_err("%s: RTAC alloc mem map table did not work! addr = 0x%x, size = %d\n",
  2574. __func__, cal_block->cal_data.paddr,
  2575. cal_block->map_data.map_size);
  2576. goto err;
  2577. }
  2578. }
  2579. result = voice_map_memory_physical_cmd(v,
  2580. &common.rtac_mem_map_table,
  2581. (dma_addr_t)cal_block->cal_data.paddr,
  2582. cal_block->map_data.map_size,
  2583. VOC_RTAC_MEM_MAP_TOKEN);
  2584. if (result < 0) {
  2585. pr_err("%s: RTAC mmap did not work! addr = 0x%x, size = %d\n",
  2586. __func__, cal_block->cal_data.paddr,
  2587. cal_block->map_data.map_size);
  2588. free_rtac_map_table();
  2589. goto err;
  2590. }
  2591. cal_block->map_data.map_handle = common.rtac_mem_handle;
  2592. err:
  2593. mutex_unlock(&v->lock);
  2594. mutex_unlock(&common.common_lock);
  2595. done:
  2596. return result;
  2597. }
  2598. int voc_unmap_rtac_block(uint32_t *mem_map_handle)
  2599. {
  2600. int result = 0;
  2601. struct voice_data *v = NULL;
  2602. pr_debug("%s\n", __func__);
  2603. if (mem_map_handle == NULL) {
  2604. pr_debug("%s: Map handle is NULL, nothing to unmap\n",
  2605. __func__);
  2606. goto done;
  2607. }
  2608. if (*mem_map_handle == 0) {
  2609. pr_debug("%s: Map handle is 0, nothing to unmap\n",
  2610. __func__);
  2611. goto done;
  2612. }
  2613. mutex_lock(&common.common_lock);
  2614. /* use first session */
  2615. v = &common.voice[0];
  2616. mutex_lock(&v->lock);
  2617. result = voice_send_mvm_unmap_memory_physical_cmd(
  2618. v, *mem_map_handle);
  2619. if (result) {
  2620. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd Failed for session 0x%x!\n",
  2621. __func__, v->session_id);
  2622. } else {
  2623. *mem_map_handle = 0;
  2624. common.rtac_mem_handle = 0;
  2625. free_rtac_map_table();
  2626. }
  2627. mutex_unlock(&v->lock);
  2628. mutex_unlock(&common.common_lock);
  2629. done:
  2630. return result;
  2631. }
  2632. int voc_unmap_cal_blocks(void)
  2633. {
  2634. int result = 0;
  2635. int result2 = 0;
  2636. int i;
  2637. struct voice_data *v = NULL;
  2638. pr_debug("%s\n", __func__);
  2639. mutex_lock(&common.common_lock);
  2640. if (common.cal_mem_handle == 0)
  2641. goto done;
  2642. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2643. v = &common.voice[i];
  2644. mutex_lock(&v->lock);
  2645. if (is_voc_state_active(v->voc_state)) {
  2646. result2 = voice_pause_voice_call(v);
  2647. if (result2 < 0) {
  2648. pr_err("%s: voice_pause_voice_call failed for session 0x%x, err %d!\n",
  2649. __func__, v->session_id, result2);
  2650. result = result2;
  2651. }
  2652. voice_send_cvp_deregister_vol_cal_cmd(v);
  2653. voice_send_cvp_deregister_cal_cmd(v);
  2654. voice_send_cvp_deregister_dev_cfg_cmd(v);
  2655. voice_send_cvs_deregister_cal_cmd(v);
  2656. result2 = voice_send_start_voice_cmd(v);
  2657. if (result2) {
  2658. pr_err("%s: voice_send_start_voice_cmd failed for session 0x%x, err %d!\n",
  2659. __func__, v->session_id, result2);
  2660. result = result2;
  2661. }
  2662. }
  2663. if ((common.cal_mem_handle != 0) &&
  2664. (!is_other_session_active(v->session_id))) {
  2665. result2 = voice_send_mvm_unmap_memory_physical_cmd(
  2666. v, common.cal_mem_handle);
  2667. if (result2) {
  2668. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd failed for session 0x%x, err %d!\n",
  2669. __func__, v->session_id, result2);
  2670. result = result2;
  2671. } else {
  2672. common.cal_mem_handle = 0;
  2673. free_cal_map_table();
  2674. }
  2675. }
  2676. mutex_unlock(&v->lock);
  2677. }
  2678. done:
  2679. mutex_unlock(&common.common_lock);
  2680. return result;
  2681. }
  2682. static int voice_setup_vocproc(struct voice_data *v)
  2683. {
  2684. struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
  2685. int ret = 0;
  2686. void *apr_cvp;
  2687. if (v == NULL) {
  2688. pr_err("%s: v is NULL\n", __func__);
  2689. return -EINVAL;
  2690. }
  2691. apr_cvp = common.apr_q6_cvp;
  2692. if (!apr_cvp) {
  2693. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2694. return -EINVAL;
  2695. }
  2696. /* create cvp session and wait for response */
  2697. cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2698. APR_HDR_LEN(APR_HDR_SIZE),
  2699. APR_PKT_VER);
  2700. cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2701. sizeof(cvp_session_cmd) - APR_HDR_SIZE);
  2702. pr_debug(" send create cvp session, pkt size = %d\n",
  2703. cvp_session_cmd.hdr.pkt_size);
  2704. cvp_session_cmd.hdr.src_port =
  2705. voice_get_idx_for_session(v->session_id);
  2706. cvp_session_cmd.hdr.dest_port = 0;
  2707. cvp_session_cmd.hdr.token = 0;
  2708. cvp_session_cmd.hdr.opcode =
  2709. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2;
  2710. voc_get_tx_rx_topology(v,
  2711. &cvp_session_cmd.cvp_session.tx_topology_id,
  2712. &cvp_session_cmd.cvp_session.rx_topology_id);
  2713. cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
  2714. cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
  2715. cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
  2716. cvp_session_cmd.cvp_session.profile_id =
  2717. VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2718. if (common.ec_ref_ext) {
  2719. cvp_session_cmd.cvp_session.vocproc_mode =
  2720. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2721. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2722. common.ec_port_id;
  2723. } else {
  2724. cvp_session_cmd.cvp_session.vocproc_mode =
  2725. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2726. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2727. VSS_IVOCPROC_PORT_ID_NONE;
  2728. }
  2729. pr_debug("tx_topology: %d tx_port_id=%d, rx_port_id=%d, mode: 0x%x\n",
  2730. cvp_session_cmd.cvp_session.tx_topology_id,
  2731. cvp_session_cmd.cvp_session.tx_port_id,
  2732. cvp_session_cmd.cvp_session.rx_port_id,
  2733. cvp_session_cmd.cvp_session.vocproc_mode);
  2734. pr_debug("rx_topology: %d, profile_id: 0x%x, pkt_size: %d\n",
  2735. cvp_session_cmd.cvp_session.rx_topology_id,
  2736. cvp_session_cmd.cvp_session.profile_id,
  2737. cvp_session_cmd.hdr.pkt_size);
  2738. v->cvp_state = CMD_STATUS_FAIL;
  2739. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
  2740. if (ret < 0) {
  2741. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  2742. goto fail;
  2743. }
  2744. ret = wait_event_timeout(v->cvp_wait,
  2745. (v->cvp_state == CMD_STATUS_SUCCESS),
  2746. msecs_to_jiffies(TIMEOUT_MS));
  2747. if (!ret) {
  2748. pr_err("%s: wait_event timeout\n", __func__);
  2749. goto fail;
  2750. }
  2751. voice_send_cvs_register_cal_cmd(v);
  2752. voice_send_cvp_register_dev_cfg_cmd(v);
  2753. voice_send_cvp_register_cal_cmd(v);
  2754. voice_send_cvp_register_vol_cal_cmd(v);
  2755. /* enable vocproc */
  2756. ret = voice_send_enable_vocproc_cmd(v);
  2757. if (ret < 0)
  2758. goto fail;
  2759. /* attach vocproc */
  2760. ret = voice_send_attach_vocproc_cmd(v);
  2761. if (ret < 0)
  2762. goto fail;
  2763. /* send tty mode if tty device is used */
  2764. voice_send_tty_mode_cmd(v);
  2765. if (is_voip_session(v->session_id)) {
  2766. ret = voice_send_mvm_cal_network_cmd(v);
  2767. if (ret < 0)
  2768. pr_err("%s: voice_send_mvm_cal_network_cmd: %d\n",
  2769. __func__, ret);
  2770. ret = voice_send_mvm_media_type_cmd(v);
  2771. if (ret < 0)
  2772. pr_err("%s: voice_send_mvm_media_type_cmd: %d\n",
  2773. __func__, ret);
  2774. voice_send_netid_timing_cmd(v);
  2775. }
  2776. if (v->st_enable && !v->tty_mode)
  2777. voice_send_set_pp_enable_cmd(v,
  2778. MODULE_ID_VOICE_MODULE_ST,
  2779. v->st_enable);
  2780. /* Start in-call music delivery if this feature is enabled */
  2781. if (v->music_info.play_enable)
  2782. voice_cvs_start_playback(v);
  2783. /* Start in-call recording if this feature is enabled */
  2784. if (v->rec_info.rec_enable)
  2785. voice_cvs_start_record(v, v->rec_info.rec_mode);
  2786. if (v->dtmf_rx_detect_en)
  2787. voice_send_dtmf_rx_detection_cmd(v, v->dtmf_rx_detect_en);
  2788. rtac_add_voice(voice_get_cvs_handle(v),
  2789. voice_get_cvp_handle(v),
  2790. v->dev_rx.port_id, v->dev_tx.port_id,
  2791. v->session_id);
  2792. return 0;
  2793. fail:
  2794. return -EINVAL;
  2795. }
  2796. static int voice_send_enable_vocproc_cmd(struct voice_data *v)
  2797. {
  2798. int ret = 0;
  2799. struct apr_hdr cvp_enable_cmd;
  2800. void *apr_cvp;
  2801. u16 cvp_handle;
  2802. if (v == NULL) {
  2803. pr_err("%s: v is NULL\n", __func__);
  2804. return -EINVAL;
  2805. }
  2806. apr_cvp = common.apr_q6_cvp;
  2807. if (!apr_cvp) {
  2808. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2809. return -EINVAL;
  2810. }
  2811. cvp_handle = voice_get_cvp_handle(v);
  2812. /* enable vocproc and wait for respose */
  2813. cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2814. APR_HDR_LEN(APR_HDR_SIZE),
  2815. APR_PKT_VER);
  2816. cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2817. sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
  2818. pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
  2819. cvp_enable_cmd.pkt_size, cvp_handle);
  2820. cvp_enable_cmd.src_port =
  2821. voice_get_idx_for_session(v->session_id);
  2822. cvp_enable_cmd.dest_port = cvp_handle;
  2823. cvp_enable_cmd.token = 0;
  2824. cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
  2825. v->cvp_state = CMD_STATUS_FAIL;
  2826. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
  2827. if (ret < 0) {
  2828. pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
  2829. goto fail;
  2830. }
  2831. ret = wait_event_timeout(v->cvp_wait,
  2832. (v->cvp_state == CMD_STATUS_SUCCESS),
  2833. msecs_to_jiffies(TIMEOUT_MS));
  2834. if (!ret) {
  2835. pr_err("%s: wait_event timeout\n", __func__);
  2836. goto fail;
  2837. }
  2838. return 0;
  2839. fail:
  2840. return -EINVAL;
  2841. }
  2842. static int voice_send_mvm_cal_network_cmd(struct voice_data *v)
  2843. {
  2844. struct vss_imvm_cmd_set_cal_network_t mvm_set_cal_network;
  2845. int ret = 0;
  2846. void *apr_mvm;
  2847. u16 mvm_handle;
  2848. if (v == NULL) {
  2849. pr_err("%s: v is NULL\n", __func__);
  2850. return -EINVAL;
  2851. }
  2852. apr_mvm = common.apr_q6_mvm;
  2853. if (!apr_mvm) {
  2854. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2855. return -EINVAL;
  2856. }
  2857. mvm_handle = voice_get_mvm_handle(v);
  2858. mvm_set_cal_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2859. APR_HDR_LEN(APR_HDR_SIZE),
  2860. APR_PKT_VER);
  2861. mvm_set_cal_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2862. sizeof(mvm_set_cal_network) - APR_HDR_SIZE);
  2863. mvm_set_cal_network.hdr.src_port =
  2864. voice_get_idx_for_session(v->session_id);
  2865. mvm_set_cal_network.hdr.dest_port = mvm_handle;
  2866. mvm_set_cal_network.hdr.token = 0;
  2867. mvm_set_cal_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  2868. mvm_set_cal_network.network_id = VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2869. v->mvm_state = CMD_STATUS_FAIL;
  2870. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_network);
  2871. if (ret < 0) {
  2872. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  2873. goto fail;
  2874. }
  2875. ret = wait_event_timeout(v->mvm_wait,
  2876. (v->mvm_state == CMD_STATUS_SUCCESS),
  2877. msecs_to_jiffies(TIMEOUT_MS));
  2878. if (!ret) {
  2879. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  2880. goto fail;
  2881. }
  2882. return 0;
  2883. fail:
  2884. return -EINVAL;
  2885. }
  2886. static int voice_send_netid_timing_cmd(struct voice_data *v)
  2887. {
  2888. int ret = 0;
  2889. void *apr_mvm;
  2890. u16 mvm_handle;
  2891. struct mvm_set_network_cmd mvm_set_network;
  2892. struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
  2893. if (v == NULL) {
  2894. pr_err("%s: v is NULL\n", __func__);
  2895. return -EINVAL;
  2896. }
  2897. apr_mvm = common.apr_q6_mvm;
  2898. if (!apr_mvm) {
  2899. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2900. return -EINVAL;
  2901. }
  2902. mvm_handle = voice_get_mvm_handle(v);
  2903. ret = voice_config_cvs_vocoder(v);
  2904. if (ret < 0) {
  2905. pr_err("%s: Error %d configuring CVS voc",
  2906. __func__, ret);
  2907. goto fail;
  2908. }
  2909. /* Set network ID. */
  2910. pr_debug("Setting network ID\n");
  2911. mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2912. APR_HDR_LEN(APR_HDR_SIZE),
  2913. APR_PKT_VER);
  2914. mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2915. sizeof(mvm_set_network) - APR_HDR_SIZE);
  2916. mvm_set_network.hdr.src_port =
  2917. voice_get_idx_for_session(v->session_id);
  2918. mvm_set_network.hdr.dest_port = mvm_handle;
  2919. mvm_set_network.hdr.token = 0;
  2920. mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
  2921. mvm_set_network.network.network_id = common.mvs_info.network_type;
  2922. v->mvm_state = CMD_STATUS_FAIL;
  2923. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
  2924. if (ret < 0) {
  2925. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  2926. goto fail;
  2927. }
  2928. ret = wait_event_timeout(v->mvm_wait,
  2929. (v->mvm_state == CMD_STATUS_SUCCESS),
  2930. msecs_to_jiffies(TIMEOUT_MS));
  2931. if (!ret) {
  2932. pr_err("%s: wait_event timeout\n", __func__);
  2933. goto fail;
  2934. }
  2935. /* Set voice timing. */
  2936. pr_debug("Setting voice timing\n");
  2937. mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2938. APR_HDR_LEN(APR_HDR_SIZE),
  2939. APR_PKT_VER);
  2940. mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2941. sizeof(mvm_set_voice_timing) -
  2942. APR_HDR_SIZE);
  2943. mvm_set_voice_timing.hdr.src_port =
  2944. voice_get_idx_for_session(v->session_id);
  2945. mvm_set_voice_timing.hdr.dest_port = mvm_handle;
  2946. mvm_set_voice_timing.hdr.token = 0;
  2947. mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
  2948. mvm_set_voice_timing.timing.mode = 0;
  2949. mvm_set_voice_timing.timing.enc_offset = 8000;
  2950. mvm_set_voice_timing.timing.dec_req_offset = 3300;
  2951. mvm_set_voice_timing.timing.dec_offset = 8300;
  2952. v->mvm_state = CMD_STATUS_FAIL;
  2953. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
  2954. if (ret < 0) {
  2955. pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
  2956. goto fail;
  2957. }
  2958. ret = wait_event_timeout(v->mvm_wait,
  2959. (v->mvm_state == CMD_STATUS_SUCCESS),
  2960. msecs_to_jiffies(TIMEOUT_MS));
  2961. if (!ret) {
  2962. pr_err("%s: wait_event timeout\n", __func__);
  2963. goto fail;
  2964. }
  2965. return 0;
  2966. fail:
  2967. return -EINVAL;
  2968. }
  2969. static int voice_send_attach_vocproc_cmd(struct voice_data *v)
  2970. {
  2971. int ret = 0;
  2972. struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
  2973. void *apr_mvm;
  2974. u16 mvm_handle, cvp_handle;
  2975. if (v == NULL) {
  2976. pr_err("%s: v is NULL\n", __func__);
  2977. return -EINVAL;
  2978. }
  2979. apr_mvm = common.apr_q6_mvm;
  2980. if (!apr_mvm) {
  2981. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2982. return -EINVAL;
  2983. }
  2984. mvm_handle = voice_get_mvm_handle(v);
  2985. cvp_handle = voice_get_cvp_handle(v);
  2986. /* attach vocproc and wait for response */
  2987. mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2988. APR_HDR_LEN(APR_HDR_SIZE),
  2989. APR_PKT_VER);
  2990. mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2991. sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
  2992. pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
  2993. mvm_a_vocproc_cmd.hdr.pkt_size);
  2994. mvm_a_vocproc_cmd.hdr.src_port =
  2995. voice_get_idx_for_session(v->session_id);
  2996. mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
  2997. mvm_a_vocproc_cmd.hdr.token = 0;
  2998. mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
  2999. mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
  3000. v->mvm_state = CMD_STATUS_FAIL;
  3001. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
  3002. if (ret < 0) {
  3003. pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
  3004. goto fail;
  3005. }
  3006. ret = wait_event_timeout(v->mvm_wait,
  3007. (v->mvm_state == CMD_STATUS_SUCCESS),
  3008. msecs_to_jiffies(TIMEOUT_MS));
  3009. if (!ret) {
  3010. pr_err("%s: wait_event timeout\n", __func__);
  3011. goto fail;
  3012. }
  3013. return 0;
  3014. fail:
  3015. return -EINVAL;
  3016. }
  3017. static int voice_destroy_vocproc(struct voice_data *v)
  3018. {
  3019. struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
  3020. struct apr_hdr cvp_destroy_session_cmd;
  3021. int ret = 0;
  3022. void *apr_mvm, *apr_cvp;
  3023. u16 mvm_handle, cvp_handle;
  3024. if (v == NULL) {
  3025. pr_err("%s: v is NULL\n", __func__);
  3026. return -EINVAL;
  3027. }
  3028. apr_mvm = common.apr_q6_mvm;
  3029. apr_cvp = common.apr_q6_cvp;
  3030. if (!apr_mvm || !apr_cvp) {
  3031. pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
  3032. return -EINVAL;
  3033. }
  3034. mvm_handle = voice_get_mvm_handle(v);
  3035. cvp_handle = voice_get_cvp_handle(v);
  3036. /* disable slowtalk if st_enable is set */
  3037. if (v->st_enable)
  3038. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_ST, 0);
  3039. /* stop playback or recording */
  3040. v->music_info.force = 1;
  3041. voice_cvs_stop_playback(v);
  3042. voice_cvs_stop_record(v);
  3043. /* If voice call is active during VoLTE, SRVCC happens.
  3044. Start recording on voice session if recording started during VoLTE.
  3045. */
  3046. if (is_volte_session(v->session_id) &&
  3047. ((common.voice[VOC_PATH_PASSIVE].voc_state == VOC_RUN) ||
  3048. (common.voice[VOC_PATH_PASSIVE].voc_state == VOC_CHANGE))) {
  3049. if (v->rec_info.rec_enable) {
  3050. voice_cvs_start_record(
  3051. &common.voice[VOC_PATH_PASSIVE],
  3052. v->rec_info.rec_mode);
  3053. common.srvcc_rec_flag = true;
  3054. pr_debug("%s: switch recording, srvcc_rec_flag %d\n",
  3055. __func__, common.srvcc_rec_flag);
  3056. }
  3057. }
  3058. /* send stop voice cmd */
  3059. voice_send_stop_voice_cmd(v);
  3060. /* send stop dtmf detecton cmd */
  3061. if (v->dtmf_rx_detect_en)
  3062. voice_send_dtmf_rx_detection_cmd(v, 0);
  3063. /* reset LCH mode */
  3064. v->lch_mode = 0;
  3065. /* clear mute setting */
  3066. v->dev_rx.dev_mute = common.default_mute_val;
  3067. v->dev_tx.dev_mute = common.default_mute_val;
  3068. v->stream_rx.stream_mute = common.default_mute_val;
  3069. v->stream_tx.stream_mute = common.default_mute_val;
  3070. /* detach VOCPROC and wait for response from mvm */
  3071. mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3072. APR_HDR_LEN(APR_HDR_SIZE),
  3073. APR_PKT_VER);
  3074. mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3075. sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
  3076. pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
  3077. mvm_d_vocproc_cmd.hdr.pkt_size);
  3078. mvm_d_vocproc_cmd.hdr.src_port =
  3079. voice_get_idx_for_session(v->session_id);
  3080. mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
  3081. mvm_d_vocproc_cmd.hdr.token = 0;
  3082. mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
  3083. mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
  3084. v->mvm_state = CMD_STATUS_FAIL;
  3085. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
  3086. if (ret < 0) {
  3087. pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
  3088. goto fail;
  3089. }
  3090. ret = wait_event_timeout(v->mvm_wait,
  3091. (v->mvm_state == CMD_STATUS_SUCCESS),
  3092. msecs_to_jiffies(TIMEOUT_MS));
  3093. if (!ret) {
  3094. pr_err("%s: wait_event timeout\n", __func__);
  3095. goto fail;
  3096. }
  3097. voice_send_cvp_deregister_vol_cal_cmd(v);
  3098. voice_send_cvp_deregister_cal_cmd(v);
  3099. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3100. voice_send_cvs_deregister_cal_cmd(v);
  3101. /* destrop cvp session */
  3102. cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3103. APR_HDR_LEN(APR_HDR_SIZE),
  3104. APR_PKT_VER);
  3105. cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3106. sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
  3107. pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
  3108. cvp_destroy_session_cmd.pkt_size);
  3109. cvp_destroy_session_cmd.src_port =
  3110. voice_get_idx_for_session(v->session_id);
  3111. cvp_destroy_session_cmd.dest_port = cvp_handle;
  3112. cvp_destroy_session_cmd.token = 0;
  3113. cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  3114. v->cvp_state = CMD_STATUS_FAIL;
  3115. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
  3116. if (ret < 0) {
  3117. pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
  3118. goto fail;
  3119. }
  3120. ret = wait_event_timeout(v->cvp_wait,
  3121. (v->cvp_state == CMD_STATUS_SUCCESS),
  3122. msecs_to_jiffies(TIMEOUT_MS));
  3123. if (!ret) {
  3124. pr_err("%s: wait_event timeout\n", __func__);
  3125. goto fail;
  3126. }
  3127. rtac_remove_voice(voice_get_cvs_handle(v));
  3128. cvp_handle = 0;
  3129. voice_set_cvp_handle(v, cvp_handle);
  3130. return 0;
  3131. fail:
  3132. return -EINVAL;
  3133. }
  3134. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  3135. uint32_t mem_handle)
  3136. {
  3137. struct vss_imemory_cmd_unmap_t mem_unmap;
  3138. int ret = 0;
  3139. void *apr_mvm;
  3140. u16 mvm_handle;
  3141. if (v == NULL) {
  3142. pr_err("%s: v is NULL\n", __func__);
  3143. return -EINVAL;
  3144. }
  3145. apr_mvm = common.apr_q6_mvm;
  3146. if (!apr_mvm) {
  3147. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3148. return -EINVAL;
  3149. }
  3150. mvm_handle = voice_get_mvm_handle(v);
  3151. mem_unmap.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3152. APR_HDR_LEN(APR_HDR_SIZE),
  3153. APR_PKT_VER);
  3154. mem_unmap.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3155. sizeof(mem_unmap) - APR_HDR_SIZE);
  3156. mem_unmap.hdr.src_port =
  3157. voice_get_idx_for_session(v->session_id);
  3158. mem_unmap.hdr.dest_port = mvm_handle;
  3159. mem_unmap.hdr.token = 0;
  3160. mem_unmap.hdr.opcode = VSS_IMEMORY_CMD_UNMAP;
  3161. mem_unmap.mem_handle = mem_handle;
  3162. pr_debug("%s: mem_handle: ox%x\n", __func__, mem_unmap.mem_handle);
  3163. v->mvm_state = CMD_STATUS_FAIL;
  3164. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mem_unmap);
  3165. if (ret < 0) {
  3166. pr_err("mem_unmap op[0x%x]ret[%d]\n",
  3167. mem_unmap.hdr.opcode, ret);
  3168. goto fail;
  3169. }
  3170. ret = wait_event_timeout(v->mvm_wait,
  3171. (v->mvm_state == CMD_STATUS_SUCCESS),
  3172. msecs_to_jiffies(TIMEOUT_MS));
  3173. if (!ret) {
  3174. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3175. goto fail;
  3176. }
  3177. return 0;
  3178. fail:
  3179. return ret;
  3180. }
  3181. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v)
  3182. {
  3183. struct vss_istream_cmd_set_oob_packet_exchange_config_t
  3184. packet_exchange_config_pkt;
  3185. int ret = 0;
  3186. uint64_t *dec_buf;
  3187. uint64_t *enc_buf;
  3188. void *apr_cvs;
  3189. u16 cvs_handle;
  3190. if (v == NULL) {
  3191. pr_err("%s: v is NULL\n", __func__);
  3192. return -EINVAL;
  3193. }
  3194. dec_buf = (uint64_t *)v->shmem_info.sh_buf.buf[0].phys;
  3195. enc_buf = (uint64_t *)v->shmem_info.sh_buf.buf[1].phys;
  3196. apr_cvs = common.apr_q6_cvs;
  3197. if (!apr_cvs) {
  3198. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3199. return -EINVAL;
  3200. }
  3201. cvs_handle = voice_get_cvs_handle(v);
  3202. packet_exchange_config_pkt.hdr.hdr_field = APR_HDR_FIELD(
  3203. APR_MSG_TYPE_SEQ_CMD,
  3204. APR_HDR_LEN(APR_HDR_SIZE),
  3205. APR_PKT_VER);
  3206. packet_exchange_config_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3207. sizeof(packet_exchange_config_pkt) -
  3208. APR_HDR_SIZE);
  3209. packet_exchange_config_pkt.hdr.src_port =
  3210. voice_get_idx_for_session(v->session_id);
  3211. packet_exchange_config_pkt.hdr.dest_port = cvs_handle;
  3212. packet_exchange_config_pkt.hdr.token = 0;
  3213. packet_exchange_config_pkt.hdr.opcode =
  3214. VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG;
  3215. packet_exchange_config_pkt.mem_handle = v->shmem_info.mem_handle;
  3216. packet_exchange_config_pkt.dec_buf_addr = (uint32_t)dec_buf;
  3217. packet_exchange_config_pkt.dec_buf_size = 4096;
  3218. packet_exchange_config_pkt.enc_buf_addr = (uint32_t)enc_buf;
  3219. packet_exchange_config_pkt.enc_buf_size = 4096;
  3220. pr_debug("%s: dec buf: add %p, size %d, enc buf: add %p, size %d\n",
  3221. __func__,
  3222. dec_buf,
  3223. packet_exchange_config_pkt.dec_buf_size,
  3224. enc_buf,
  3225. packet_exchange_config_pkt.enc_buf_size);
  3226. v->cvs_state = CMD_STATUS_FAIL;
  3227. ret = apr_send_pkt(apr_cvs, (uint32_t *) &packet_exchange_config_pkt);
  3228. if (ret < 0) {
  3229. pr_err("Failed to send packet exchange config cmd %d\n", ret);
  3230. goto fail;
  3231. }
  3232. ret = wait_event_timeout(v->cvs_wait,
  3233. (v->cvs_state == CMD_STATUS_SUCCESS),
  3234. msecs_to_jiffies(TIMEOUT_MS));
  3235. if (!ret)
  3236. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3237. return 0;
  3238. fail:
  3239. return -EINVAL;
  3240. }
  3241. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v)
  3242. {
  3243. struct vss_istream_cmd_set_packet_exchange_mode_t data_exchange_pkt;
  3244. int ret = 0;
  3245. void *apr_cvs;
  3246. u16 cvs_handle;
  3247. if (v == NULL) {
  3248. pr_err("%s: v is NULL\n", __func__);
  3249. return -EINVAL;
  3250. }
  3251. apr_cvs = common.apr_q6_cvs;
  3252. if (!apr_cvs) {
  3253. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3254. return -EINVAL;
  3255. }
  3256. cvs_handle = voice_get_cvs_handle(v);
  3257. data_exchange_pkt.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3258. APR_HDR_LEN(APR_HDR_SIZE),
  3259. APR_PKT_VER);
  3260. data_exchange_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3261. sizeof(data_exchange_pkt) - APR_HDR_SIZE);
  3262. data_exchange_pkt.hdr.src_port =
  3263. voice_get_idx_for_session(v->session_id);
  3264. data_exchange_pkt.hdr.dest_port = cvs_handle;
  3265. data_exchange_pkt.hdr.token = 0;
  3266. data_exchange_pkt.hdr.opcode = VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE;
  3267. data_exchange_pkt.mode = VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND;
  3268. v->cvs_state = CMD_STATUS_FAIL;
  3269. ret = apr_send_pkt(apr_cvs, (uint32_t *) &data_exchange_pkt);
  3270. if (ret < 0) {
  3271. pr_err("Failed to send data exchange mode %d\n", ret);
  3272. goto fail;
  3273. }
  3274. ret = wait_event_timeout(v->cvs_wait,
  3275. (v->cvs_state == CMD_STATUS_SUCCESS),
  3276. msecs_to_jiffies(TIMEOUT_MS));
  3277. if (!ret)
  3278. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3279. return 0;
  3280. fail:
  3281. return -EINVAL;
  3282. }
  3283. static int voice_send_stream_mute_cmd(struct voice_data *v, uint16_t direction,
  3284. uint16_t mute_flag, uint32_t ramp_duration)
  3285. {
  3286. struct cvs_set_mute_cmd cvs_mute_cmd;
  3287. int ret = 0;
  3288. if (v == NULL) {
  3289. pr_err("%s: v is NULL\n", __func__);
  3290. goto fail;
  3291. }
  3292. if (!common.apr_q6_cvs) {
  3293. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3294. goto fail;
  3295. }
  3296. /* send mute/unmute to cvs */
  3297. cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3298. APR_HDR_LEN(APR_HDR_SIZE),
  3299. APR_PKT_VER);
  3300. cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3301. sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
  3302. cvs_mute_cmd.hdr.src_port =
  3303. voice_get_idx_for_session(v->session_id);
  3304. cvs_mute_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  3305. cvs_mute_cmd.hdr.token = 0;
  3306. cvs_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  3307. cvs_mute_cmd.cvs_set_mute.direction = direction;
  3308. cvs_mute_cmd.cvs_set_mute.mute_flag = mute_flag;
  3309. cvs_mute_cmd.cvs_set_mute.ramp_duration_ms = ramp_duration;
  3310. v->cvs_state = CMD_STATUS_FAIL;
  3311. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_mute_cmd);
  3312. if (ret < 0) {
  3313. pr_err("%s: Error %d sending stream mute\n", __func__, ret);
  3314. goto fail;
  3315. }
  3316. ret = wait_event_timeout(v->cvs_wait,
  3317. (v->cvs_state == CMD_STATUS_SUCCESS),
  3318. msecs_to_jiffies(TIMEOUT_MS));
  3319. if (!ret) {
  3320. pr_err("%s: Command timeout\n", __func__);
  3321. goto fail;
  3322. }
  3323. return 0;
  3324. fail:
  3325. return -EINVAL;
  3326. }
  3327. static int voice_send_device_mute_cmd(struct voice_data *v, uint16_t direction,
  3328. uint16_t mute_flag, uint32_t ramp_duration)
  3329. {
  3330. struct cvp_set_mute_cmd cvp_mute_cmd;
  3331. int ret = 0;
  3332. if (v == NULL) {
  3333. pr_err("%s: v is NULL\n", __func__);
  3334. goto fail;
  3335. }
  3336. if (!common.apr_q6_cvp) {
  3337. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3338. goto fail;
  3339. }
  3340. cvp_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3341. APR_HDR_LEN(APR_HDR_SIZE),
  3342. APR_PKT_VER);
  3343. cvp_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3344. sizeof(cvp_mute_cmd) - APR_HDR_SIZE);
  3345. cvp_mute_cmd.hdr.src_port =
  3346. voice_get_idx_for_session(v->session_id);
  3347. cvp_mute_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  3348. cvp_mute_cmd.hdr.token = 0;
  3349. cvp_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  3350. cvp_mute_cmd.cvp_set_mute.direction = direction;
  3351. cvp_mute_cmd.cvp_set_mute.mute_flag = mute_flag;
  3352. cvp_mute_cmd.cvp_set_mute.ramp_duration_ms = ramp_duration;
  3353. v->cvp_state = CMD_STATUS_FAIL;
  3354. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_mute_cmd);
  3355. if (ret < 0) {
  3356. pr_err("%s: Error %d sending rx device cmd\n", __func__, ret);
  3357. goto fail;
  3358. }
  3359. ret = wait_event_timeout(v->cvp_wait,
  3360. (v->cvp_state == CMD_STATUS_SUCCESS),
  3361. msecs_to_jiffies(TIMEOUT_MS));
  3362. if (!ret) {
  3363. pr_err("%s: Command timeout\n", __func__);
  3364. goto fail;
  3365. }
  3366. return 0;
  3367. fail:
  3368. return -EINVAL;
  3369. }
  3370. static int voice_send_vol_step_cmd(struct voice_data *v)
  3371. {
  3372. struct cvp_set_rx_volume_step_cmd cvp_vol_step_cmd;
  3373. int ret = 0;
  3374. void *apr_cvp;
  3375. u16 cvp_handle;
  3376. if (v == NULL) {
  3377. pr_err("%s: v is NULL\n", __func__);
  3378. return -EINVAL;
  3379. }
  3380. apr_cvp = common.apr_q6_cvp;
  3381. if (!apr_cvp) {
  3382. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3383. return -EINVAL;
  3384. }
  3385. cvp_handle = voice_get_cvp_handle(v);
  3386. /* send volume index to cvp */
  3387. cvp_vol_step_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3388. APR_HDR_LEN(APR_HDR_SIZE),
  3389. APR_PKT_VER);
  3390. cvp_vol_step_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3391. sizeof(cvp_vol_step_cmd) - APR_HDR_SIZE);
  3392. cvp_vol_step_cmd.hdr.src_port =
  3393. voice_get_idx_for_session(v->session_id);
  3394. cvp_vol_step_cmd.hdr.dest_port = cvp_handle;
  3395. cvp_vol_step_cmd.hdr.token = 0;
  3396. cvp_vol_step_cmd.hdr.opcode = VSS_IVOLUME_CMD_SET_STEP;
  3397. cvp_vol_step_cmd.cvp_set_vol_step.direction = VSS_IVOLUME_DIRECTION_RX;
  3398. cvp_vol_step_cmd.cvp_set_vol_step.value = v->dev_rx.volume_step_value;
  3399. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms =
  3400. v->dev_rx.volume_ramp_duration_ms;
  3401. pr_debug("%s step_value:%d, ramp_duration_ms:%d",
  3402. __func__,
  3403. cvp_vol_step_cmd.cvp_set_vol_step.value,
  3404. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms);
  3405. v->cvp_state = CMD_STATUS_FAIL;
  3406. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_step_cmd);
  3407. if (ret < 0) {
  3408. pr_err("Fail in sending RX VOL step\n");
  3409. return -EINVAL;
  3410. }
  3411. ret = wait_event_timeout(v->cvp_wait,
  3412. (v->cvp_state == CMD_STATUS_SUCCESS),
  3413. msecs_to_jiffies(TIMEOUT_MS));
  3414. if (!ret) {
  3415. pr_err("%s: wait_event timeout\n", __func__);
  3416. return -EINVAL;
  3417. }
  3418. return 0;
  3419. }
  3420. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode)
  3421. {
  3422. int ret = 0;
  3423. void *apr_cvs;
  3424. u16 cvs_handle;
  3425. struct cvs_start_record_cmd cvs_start_record;
  3426. if (v == NULL) {
  3427. pr_err("%s: v is NULL\n", __func__);
  3428. return -EINVAL;
  3429. }
  3430. apr_cvs = common.apr_q6_cvs;
  3431. if (!apr_cvs) {
  3432. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3433. return -EINVAL;
  3434. }
  3435. cvs_handle = voice_get_cvs_handle(v);
  3436. if (!v->rec_info.recording) {
  3437. cvs_start_record.hdr.hdr_field = APR_HDR_FIELD(
  3438. APR_MSG_TYPE_SEQ_CMD,
  3439. APR_HDR_LEN(APR_HDR_SIZE),
  3440. APR_PKT_VER);
  3441. cvs_start_record.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3442. sizeof(cvs_start_record) - APR_HDR_SIZE);
  3443. cvs_start_record.hdr.src_port =
  3444. voice_get_idx_for_session(v->session_id);
  3445. cvs_start_record.hdr.dest_port = cvs_handle;
  3446. cvs_start_record.hdr.token = 0;
  3447. cvs_start_record.hdr.opcode = VSS_IRECORD_CMD_START;
  3448. /* In order to enable stereo recording,
  3449. * i.e. TX on the left and RX on the right
  3450. * the respective ports need to be explicitly specified:
  3451. * INCALL_RECORD_TX => 0x8003
  3452. * INCALL_RECORD_RX => 0x8004 */
  3453. cvs_start_record.rec_mode.port_id =
  3454. VSS_IRECORD_PORT_ID_TX_RX;
  3455. if (rec_mode == VOC_REC_UPLINK) {
  3456. cvs_start_record.rec_mode.rx_tap_point =
  3457. VSS_IRECORD_TAP_POINT_NONE;
  3458. cvs_start_record.rec_mode.tx_tap_point =
  3459. VSS_IRECORD_TAP_POINT_STREAM_END;
  3460. } else if (rec_mode == VOC_REC_DOWNLINK) {
  3461. cvs_start_record.rec_mode.rx_tap_point =
  3462. VSS_IRECORD_TAP_POINT_STREAM_END;
  3463. cvs_start_record.rec_mode.tx_tap_point =
  3464. VSS_IRECORD_TAP_POINT_NONE;
  3465. } else if (rec_mode == VOC_REC_BOTH) {
  3466. cvs_start_record.rec_mode.rx_tap_point =
  3467. VSS_IRECORD_TAP_POINT_STREAM_END;
  3468. cvs_start_record.rec_mode.tx_tap_point =
  3469. VSS_IRECORD_TAP_POINT_STREAM_END;
  3470. } else {
  3471. pr_err("%s: Invalid in-call rec_mode %d\n", __func__,
  3472. rec_mode);
  3473. ret = -EINVAL;
  3474. goto fail;
  3475. }
  3476. /* Request stereo recording */
  3477. cvs_start_record.rec_mode.mode = VSS_IRECORD_MODE_TX_RX_STEREO;
  3478. v->cvs_state = CMD_STATUS_FAIL;
  3479. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_record);
  3480. if (ret < 0) {
  3481. pr_err("%s: Error %d sending START_RECORD\n", __func__,
  3482. ret);
  3483. goto fail;
  3484. }
  3485. ret = wait_event_timeout(v->cvs_wait,
  3486. (v->cvs_state == CMD_STATUS_SUCCESS),
  3487. msecs_to_jiffies(TIMEOUT_MS));
  3488. if (!ret) {
  3489. pr_err("%s: wait_event timeout\n", __func__);
  3490. goto fail;
  3491. }
  3492. v->rec_info.recording = 1;
  3493. } else {
  3494. pr_debug("%s: Start record already sent\n", __func__);
  3495. }
  3496. return 0;
  3497. fail:
  3498. return ret;
  3499. }
  3500. static int voice_cvs_stop_record(struct voice_data *v)
  3501. {
  3502. int ret = 0;
  3503. void *apr_cvs;
  3504. u16 cvs_handle;
  3505. struct apr_hdr cvs_stop_record;
  3506. if (v == NULL) {
  3507. pr_err("%s: v is NULL\n", __func__);
  3508. return -EINVAL;
  3509. }
  3510. apr_cvs = common.apr_q6_cvs;
  3511. if (!apr_cvs) {
  3512. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3513. return -EINVAL;
  3514. }
  3515. cvs_handle = voice_get_cvs_handle(v);
  3516. if (v->rec_info.recording) {
  3517. cvs_stop_record.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3518. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3519. cvs_stop_record.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3520. sizeof(cvs_stop_record) - APR_HDR_SIZE);
  3521. cvs_stop_record.src_port =
  3522. voice_get_idx_for_session(v->session_id);
  3523. cvs_stop_record.dest_port = cvs_handle;
  3524. cvs_stop_record.token = 0;
  3525. cvs_stop_record.opcode = VSS_IRECORD_CMD_STOP;
  3526. v->cvs_state = CMD_STATUS_FAIL;
  3527. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_record);
  3528. if (ret < 0) {
  3529. pr_err("%s: Error %d sending STOP_RECORD\n",
  3530. __func__, ret);
  3531. goto fail;
  3532. }
  3533. ret = wait_event_timeout(v->cvs_wait,
  3534. (v->cvs_state == CMD_STATUS_SUCCESS),
  3535. msecs_to_jiffies(TIMEOUT_MS));
  3536. if (!ret) {
  3537. pr_err("%s: wait_event timeout\n", __func__);
  3538. goto fail;
  3539. }
  3540. v->rec_info.recording = 0;
  3541. } else {
  3542. pr_debug("%s: Stop record already sent\n", __func__);
  3543. }
  3544. return 0;
  3545. fail:
  3546. return ret;
  3547. }
  3548. int voc_start_record(uint32_t port_id, uint32_t set, uint32_t session_id)
  3549. {
  3550. int ret = 0;
  3551. int rec_mode = 0;
  3552. u16 cvs_handle;
  3553. int rec_set = 0;
  3554. struct voice_session_itr itr;
  3555. struct voice_data *v = NULL;
  3556. /* check if session_id is valid */
  3557. if (!voice_is_valid_session_id(session_id)) {
  3558. pr_err("%s: Invalid session id:%u\n", __func__,
  3559. session_id);
  3560. return -EINVAL;
  3561. }
  3562. voice_itr_init(&itr, session_id);
  3563. pr_debug("%s: session_id:%u\n", __func__, session_id);
  3564. while (voice_itr_get_next_session(&itr, &v)) {
  3565. if (v == NULL) {
  3566. pr_err("%s: v is NULL, sessionid:%u\n", __func__,
  3567. session_id);
  3568. break;
  3569. }
  3570. pr_debug("%s: port_id: %d, set: %d, v: %p\n",
  3571. __func__, port_id, set, v);
  3572. mutex_lock(&v->lock);
  3573. rec_mode = v->rec_info.rec_mode;
  3574. rec_set = set;
  3575. if (set) {
  3576. if ((v->rec_route_state.ul_flag != 0) &&
  3577. (v->rec_route_state.dl_flag != 0)) {
  3578. pr_debug("%s: rec mode already set.\n",
  3579. __func__);
  3580. mutex_unlock(&v->lock);
  3581. continue;
  3582. }
  3583. if (port_id == VOICE_RECORD_TX) {
  3584. if ((v->rec_route_state.ul_flag == 0)
  3585. && (v->rec_route_state.dl_flag == 0)) {
  3586. rec_mode = VOC_REC_UPLINK;
  3587. v->rec_route_state.ul_flag = 1;
  3588. } else if ((v->rec_route_state.ul_flag == 0)
  3589. && (v->rec_route_state.dl_flag != 0)) {
  3590. voice_cvs_stop_record(v);
  3591. rec_mode = VOC_REC_BOTH;
  3592. v->rec_route_state.ul_flag = 1;
  3593. }
  3594. } else if (port_id == VOICE_RECORD_RX) {
  3595. if ((v->rec_route_state.ul_flag == 0)
  3596. && (v->rec_route_state.dl_flag == 0)) {
  3597. rec_mode = VOC_REC_DOWNLINK;
  3598. v->rec_route_state.dl_flag = 1;
  3599. } else if ((v->rec_route_state.ul_flag != 0)
  3600. && (v->rec_route_state.dl_flag == 0)) {
  3601. voice_cvs_stop_record(v);
  3602. rec_mode = VOC_REC_BOTH;
  3603. v->rec_route_state.dl_flag = 1;
  3604. }
  3605. }
  3606. rec_set = 1;
  3607. } else {
  3608. if ((v->rec_route_state.ul_flag == 0) &&
  3609. (v->rec_route_state.dl_flag == 0)) {
  3610. pr_debug("%s: rec already stops.\n",
  3611. __func__);
  3612. mutex_unlock(&v->lock);
  3613. continue;
  3614. }
  3615. if (port_id == VOICE_RECORD_TX) {
  3616. if ((v->rec_route_state.ul_flag != 0)
  3617. && (v->rec_route_state.dl_flag == 0)) {
  3618. v->rec_route_state.ul_flag = 0;
  3619. rec_set = 0;
  3620. } else if ((v->rec_route_state.ul_flag != 0)
  3621. && (v->rec_route_state.dl_flag != 0)) {
  3622. voice_cvs_stop_record(v);
  3623. v->rec_route_state.ul_flag = 0;
  3624. rec_mode = VOC_REC_DOWNLINK;
  3625. rec_set = 1;
  3626. }
  3627. } else if (port_id == VOICE_RECORD_RX) {
  3628. if ((v->rec_route_state.ul_flag == 0)
  3629. && (v->rec_route_state.dl_flag != 0)) {
  3630. v->rec_route_state.dl_flag = 0;
  3631. rec_set = 0;
  3632. } else if ((v->rec_route_state.ul_flag != 0)
  3633. && (v->rec_route_state.dl_flag != 0)) {
  3634. voice_cvs_stop_record(v);
  3635. v->rec_route_state.dl_flag = 0;
  3636. rec_mode = VOC_REC_UPLINK;
  3637. rec_set = 1;
  3638. }
  3639. }
  3640. }
  3641. pr_debug("%s: mode =%d, set =%d\n", __func__,
  3642. rec_mode, rec_set);
  3643. cvs_handle = voice_get_cvs_handle(v);
  3644. if (cvs_handle != 0) {
  3645. if (rec_set)
  3646. ret = voice_cvs_start_record(v, rec_mode);
  3647. else
  3648. ret = voice_cvs_stop_record(v);
  3649. }
  3650. /* During SRVCC, recording will switch from VoLTE session to
  3651. voice session.
  3652. Then stop recording, need to stop recording on voice session.
  3653. */
  3654. if ((!rec_set) && common.srvcc_rec_flag) {
  3655. pr_debug("%s, srvcc_rec_flag:%d\n", __func__,
  3656. common.srvcc_rec_flag);
  3657. voice_cvs_stop_record(&common.voice[VOC_PATH_PASSIVE]);
  3658. common.srvcc_rec_flag = false;
  3659. }
  3660. /* Cache the value */
  3661. v->rec_info.rec_enable = rec_set;
  3662. v->rec_info.rec_mode = rec_mode;
  3663. mutex_unlock(&v->lock);
  3664. }
  3665. return ret;
  3666. }
  3667. static int voice_cvs_start_playback(struct voice_data *v)
  3668. {
  3669. int ret = 0;
  3670. struct cvs_start_playback_cmd cvs_start_playback;
  3671. void *apr_cvs;
  3672. u16 cvs_handle;
  3673. if (v == NULL) {
  3674. pr_err("%s: v is NULL\n", __func__);
  3675. return -EINVAL;
  3676. }
  3677. apr_cvs = common.apr_q6_cvs;
  3678. if (!apr_cvs) {
  3679. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3680. return -EINVAL;
  3681. }
  3682. cvs_handle = voice_get_cvs_handle(v);
  3683. if (!v->music_info.playing && v->music_info.count) {
  3684. cvs_start_playback.hdr.hdr_field = APR_HDR_FIELD(
  3685. APR_MSG_TYPE_SEQ_CMD,
  3686. APR_HDR_LEN(APR_HDR_SIZE),
  3687. APR_PKT_VER);
  3688. cvs_start_playback.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3689. sizeof(cvs_start_playback) - APR_HDR_SIZE);
  3690. cvs_start_playback.hdr.src_port =
  3691. voice_get_idx_for_session(v->session_id);
  3692. cvs_start_playback.hdr.dest_port = cvs_handle;
  3693. cvs_start_playback.hdr.token = 0;
  3694. cvs_start_playback.hdr.opcode = VSS_IPLAYBACK_CMD_START;
  3695. cvs_start_playback.playback_mode.port_id =
  3696. v->music_info.port_id;
  3697. v->cvs_state = CMD_STATUS_FAIL;
  3698. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
  3699. if (ret < 0) {
  3700. pr_err("%s: Error %d sending START_PLAYBACK\n",
  3701. __func__, ret);
  3702. goto fail;
  3703. }
  3704. ret = wait_event_timeout(v->cvs_wait,
  3705. (v->cvs_state == CMD_STATUS_SUCCESS),
  3706. msecs_to_jiffies(TIMEOUT_MS));
  3707. if (!ret) {
  3708. pr_err("%s: wait_event timeout\n", __func__);
  3709. goto fail;
  3710. }
  3711. v->music_info.playing = 1;
  3712. } else {
  3713. pr_debug("%s: Start playback already sent\n", __func__);
  3714. }
  3715. return 0;
  3716. fail:
  3717. return ret;
  3718. }
  3719. static int voice_cvs_stop_playback(struct voice_data *v)
  3720. {
  3721. int ret = 0;
  3722. struct apr_hdr cvs_stop_playback;
  3723. void *apr_cvs;
  3724. u16 cvs_handle;
  3725. if (v == NULL) {
  3726. pr_err("%s: v is NULL\n", __func__);
  3727. return -EINVAL;
  3728. }
  3729. apr_cvs = common.apr_q6_cvs;
  3730. if (!apr_cvs) {
  3731. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3732. return -EINVAL;
  3733. }
  3734. cvs_handle = voice_get_cvs_handle(v);
  3735. if (v->music_info.playing && ((!v->music_info.count) ||
  3736. (v->music_info.force))) {
  3737. cvs_stop_playback.hdr_field =
  3738. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3739. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3740. cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3741. sizeof(cvs_stop_playback) - APR_HDR_SIZE);
  3742. cvs_stop_playback.src_port =
  3743. voice_get_idx_for_session(v->session_id);
  3744. cvs_stop_playback.dest_port = cvs_handle;
  3745. cvs_stop_playback.token = 0;
  3746. cvs_stop_playback.opcode = VSS_IPLAYBACK_CMD_STOP;
  3747. v->cvs_state = CMD_STATUS_FAIL;
  3748. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
  3749. if (ret < 0) {
  3750. pr_err("%s: Error %d sending STOP_PLAYBACK\n",
  3751. __func__, ret);
  3752. goto fail;
  3753. }
  3754. ret = wait_event_timeout(v->cvs_wait,
  3755. (v->cvs_state == CMD_STATUS_SUCCESS),
  3756. msecs_to_jiffies(TIMEOUT_MS));
  3757. if (!ret) {
  3758. pr_err("%s: wait_event timeout\n", __func__);
  3759. goto fail;
  3760. }
  3761. v->music_info.playing = 0;
  3762. v->music_info.force = 0;
  3763. } else {
  3764. pr_debug("%s: Stop playback already sent\n", __func__);
  3765. }
  3766. return 0;
  3767. fail:
  3768. return ret;
  3769. }
  3770. int voc_start_playback(uint32_t set, uint16_t port_id)
  3771. {
  3772. int ret = 0;
  3773. u16 cvs_handle;
  3774. struct voice_data *v = NULL;
  3775. if (port_id == VOICE_PLAYBACK_TX)
  3776. v = voice_get_session(voc_get_session_id(VOICE_SESSION_NAME));
  3777. else if (port_id == VOICE2_PLAYBACK_TX)
  3778. v = voice_get_session(voc_get_session_id(VOICE2_SESSION_NAME));
  3779. else
  3780. pr_err("%s: Invalid port_id 0x%x", __func__, port_id);
  3781. while (v != NULL) {
  3782. mutex_lock(&v->lock);
  3783. v->music_info.port_id = port_id;
  3784. v->music_info.play_enable = set;
  3785. if (set)
  3786. v->music_info.count++;
  3787. else
  3788. v->music_info.count--;
  3789. pr_debug("%s: music_info count =%d\n", __func__,
  3790. v->music_info.count);
  3791. cvs_handle = voice_get_cvs_handle(v);
  3792. if (cvs_handle != 0) {
  3793. if (set)
  3794. ret = voice_cvs_start_playback(v);
  3795. else
  3796. ret = voice_cvs_stop_playback(v);
  3797. }
  3798. mutex_unlock(&v->lock);
  3799. /* Voice and VoLTE call use the same pseudo port and hence
  3800. * use the same mixer control. So enable incall delivery
  3801. * for VoLTE as well with Voice.
  3802. */
  3803. if (is_voice_session(v->session_id)) {
  3804. v = voice_get_session(voc_get_session_id(
  3805. VOLTE_SESSION_NAME));
  3806. } else {
  3807. break;
  3808. }
  3809. }
  3810. return ret;
  3811. }
  3812. static int voc_disable_cvp(uint32_t session_id)
  3813. {
  3814. struct voice_data *v = voice_get_session(session_id);
  3815. int ret = 0;
  3816. if (v == NULL) {
  3817. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3818. return -EINVAL;
  3819. }
  3820. mutex_lock(&v->lock);
  3821. if (v->voc_state == VOC_RUN) {
  3822. rtac_remove_voice(voice_get_cvs_handle(v));
  3823. /* send cmd to dsp to disable vocproc */
  3824. ret = voice_send_disable_vocproc_cmd(v);
  3825. if (ret < 0) {
  3826. pr_err("%s: disable vocproc failed\n", __func__);
  3827. goto fail;
  3828. }
  3829. voice_send_cvp_deregister_vol_cal_cmd(v);
  3830. voice_send_cvp_deregister_cal_cmd(v);
  3831. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3832. v->voc_state = VOC_CHANGE;
  3833. }
  3834. if (common.ec_ref_ext)
  3835. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  3836. fail: mutex_unlock(&v->lock);
  3837. return ret;
  3838. }
  3839. static int voc_enable_cvp(uint32_t session_id)
  3840. {
  3841. struct voice_data *v = voice_get_session(session_id);
  3842. int ret = 0;
  3843. if (v == NULL) {
  3844. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  3845. return -EINVAL;
  3846. }
  3847. mutex_lock(&v->lock);
  3848. if (v->voc_state == VOC_CHANGE) {
  3849. ret = voice_send_set_device_cmd(v);
  3850. if (ret < 0) {
  3851. pr_err("%s: Set device failed\n", __func__);
  3852. goto fail;
  3853. }
  3854. voice_send_cvp_register_dev_cfg_cmd(v);
  3855. voice_send_cvp_register_cal_cmd(v);
  3856. voice_send_cvp_register_vol_cal_cmd(v);
  3857. if (v->lch_mode == VOICE_LCH_START) {
  3858. pr_debug("%s: TX and RX mute ON\n", __func__);
  3859. voice_send_device_mute_cmd(v,
  3860. VSS_IVOLUME_DIRECTION_TX,
  3861. VSS_IVOLUME_MUTE_ON,
  3862. DEFAULT_MUTE_RAMP_DURATION);
  3863. voice_send_device_mute_cmd(v,
  3864. VSS_IVOLUME_DIRECTION_RX,
  3865. VSS_IVOLUME_MUTE_ON,
  3866. DEFAULT_MUTE_RAMP_DURATION);
  3867. /* Send unmute cmd as the TX stream
  3868. * might be muted previously
  3869. */
  3870. voice_send_stream_mute_cmd(v,
  3871. VSS_IVOLUME_DIRECTION_TX,
  3872. VSS_IVOLUME_MUTE_OFF,
  3873. DEFAULT_MUTE_RAMP_DURATION);
  3874. } else if (v->lch_mode == VOICE_LCH_STOP) {
  3875. pr_debug("%s: TX and RX mute OFF\n", __func__);
  3876. voice_send_device_mute_cmd(v,
  3877. VSS_IVOLUME_DIRECTION_TX,
  3878. VSS_IVOLUME_MUTE_OFF,
  3879. DEFAULT_MUTE_RAMP_DURATION);
  3880. voice_send_device_mute_cmd(v,
  3881. VSS_IVOLUME_DIRECTION_RX,
  3882. VSS_IVOLUME_MUTE_OFF,
  3883. DEFAULT_MUTE_RAMP_DURATION);
  3884. /* Reset lch mode when VOICE_LCH_STOP is recieved */
  3885. v->lch_mode = 0;
  3886. /* Apply cached mute setting */
  3887. voice_send_stream_mute_cmd(v,
  3888. VSS_IVOLUME_DIRECTION_TX,
  3889. v->stream_tx.stream_mute,
  3890. v->stream_tx.stream_mute_ramp_duration_ms);
  3891. } else {
  3892. pr_debug("%s: Mute commands not sent for lch_mode=%d\n",
  3893. __func__, v->lch_mode);
  3894. }
  3895. ret = voice_send_enable_vocproc_cmd(v);
  3896. if (ret < 0) {
  3897. pr_err("%s: Enable vocproc failed %d\n", __func__, ret);
  3898. goto fail;
  3899. }
  3900. voice_send_tty_mode_cmd(v);
  3901. if (v->st_enable && !v->tty_mode)
  3902. voice_send_set_pp_enable_cmd(v,
  3903. MODULE_ID_VOICE_MODULE_ST,
  3904. v->st_enable);
  3905. rtac_add_voice(voice_get_cvs_handle(v),
  3906. voice_get_cvp_handle(v),
  3907. v->dev_rx.port_id, v->dev_tx.port_id,
  3908. v->session_id);
  3909. v->voc_state = VOC_RUN;
  3910. }
  3911. fail:
  3912. mutex_unlock(&v->lock);
  3913. return ret;
  3914. }
  3915. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  3916. uint32_t mode)
  3917. {
  3918. struct voice_data *v = voice_get_session(session_id);
  3919. int ret = 0;
  3920. if (v == NULL) {
  3921. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3922. return -EINVAL;
  3923. }
  3924. if (v->voc_state != VOC_RUN)
  3925. ret = voice_send_cvs_data_exchange_mode_cmd(v);
  3926. if (ret) {
  3927. pr_err("%s: Error voice_send_data_exchange_mode_cmd %d\n",
  3928. __func__, ret);
  3929. goto fail;
  3930. }
  3931. ret = voice_send_cvs_packet_exchange_config_cmd(v);
  3932. if (ret) {
  3933. pr_err("%s: Error: voice_send_packet_exchange_config_cmd %d\n",
  3934. __func__, ret);
  3935. goto fail;
  3936. }
  3937. return ret;
  3938. fail:
  3939. return -EINVAL;
  3940. }
  3941. int voc_set_tx_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  3942. uint32_t ramp_duration)
  3943. {
  3944. struct voice_data *v = NULL;
  3945. int ret = 0;
  3946. struct voice_session_itr itr;
  3947. voice_itr_init(&itr, session_id);
  3948. while (voice_itr_get_next_session(&itr, &v)) {
  3949. if (v != NULL) {
  3950. mutex_lock(&v->lock);
  3951. v->stream_tx.stream_mute = mute;
  3952. v->stream_tx.stream_mute_ramp_duration_ms =
  3953. ramp_duration;
  3954. if (is_voc_state_active(v->voc_state) &&
  3955. (v->lch_mode == 0))
  3956. ret = voice_send_stream_mute_cmd(v,
  3957. VSS_IVOLUME_DIRECTION_TX,
  3958. v->stream_tx.stream_mute,
  3959. v->stream_tx.stream_mute_ramp_duration_ms);
  3960. mutex_unlock(&v->lock);
  3961. } else {
  3962. pr_err("%s: invalid session_id 0x%x\n", __func__,
  3963. session_id);
  3964. ret = -EINVAL;
  3965. break;
  3966. }
  3967. }
  3968. return ret;
  3969. }
  3970. int voc_set_device_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  3971. uint32_t ramp_duration)
  3972. {
  3973. struct voice_data *v = NULL;
  3974. int ret = 0;
  3975. struct voice_session_itr itr;
  3976. voice_itr_init(&itr, session_id);
  3977. while (voice_itr_get_next_session(&itr, &v)) {
  3978. if (v != NULL) {
  3979. mutex_lock(&v->lock);
  3980. if (dir == VSS_IVOLUME_DIRECTION_TX) {
  3981. v->dev_tx.dev_mute = mute;
  3982. v->dev_tx.dev_mute_ramp_duration_ms =
  3983. ramp_duration;
  3984. } else {
  3985. v->dev_rx.dev_mute = mute;
  3986. v->dev_rx.dev_mute_ramp_duration_ms =
  3987. ramp_duration;
  3988. }
  3989. if (((v->voc_state == VOC_RUN) ||
  3990. (v->voc_state == VOC_STANDBY)) &&
  3991. (v->lch_mode == 0))
  3992. ret = voice_send_device_mute_cmd(v,
  3993. dir,
  3994. mute,
  3995. ramp_duration);
  3996. mutex_unlock(&v->lock);
  3997. } else {
  3998. pr_err("%s: invalid session_id 0x%x\n", __func__,
  3999. session_id);
  4000. ret = -EINVAL;
  4001. break;
  4002. }
  4003. }
  4004. return ret;
  4005. }
  4006. int voc_get_rx_device_mute(uint32_t session_id)
  4007. {
  4008. struct voice_data *v = voice_get_session(session_id);
  4009. int ret = 0;
  4010. if (v == NULL) {
  4011. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4012. return -EINVAL;
  4013. }
  4014. mutex_lock(&v->lock);
  4015. ret = v->dev_rx.dev_mute;
  4016. mutex_unlock(&v->lock);
  4017. return ret;
  4018. }
  4019. int voc_set_tty_mode(uint32_t session_id, uint8_t tty_mode)
  4020. {
  4021. struct voice_data *v = voice_get_session(session_id);
  4022. int ret = 0;
  4023. if (v == NULL) {
  4024. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4025. return -EINVAL;
  4026. }
  4027. mutex_lock(&v->lock);
  4028. v->tty_mode = tty_mode;
  4029. mutex_unlock(&v->lock);
  4030. return ret;
  4031. }
  4032. uint8_t voc_get_tty_mode(uint32_t session_id)
  4033. {
  4034. struct voice_data *v = voice_get_session(session_id);
  4035. int ret = 0;
  4036. if (v == NULL) {
  4037. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4038. return -EINVAL;
  4039. }
  4040. mutex_lock(&v->lock);
  4041. ret = v->tty_mode;
  4042. mutex_unlock(&v->lock);
  4043. return ret;
  4044. }
  4045. int voc_set_pp_enable(uint32_t session_id, uint32_t module_id, uint32_t enable)
  4046. {
  4047. struct voice_data *v = NULL;
  4048. int ret = 0;
  4049. struct voice_session_itr itr;
  4050. voice_itr_init(&itr, session_id);
  4051. while (voice_itr_get_next_session(&itr, &v)) {
  4052. if (v != NULL) {
  4053. if (!(is_voice_app_id(v->session_id) ||
  4054. is_volte_session(v->session_id)))
  4055. continue;
  4056. mutex_lock(&v->lock);
  4057. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  4058. v->st_enable = enable;
  4059. if (v->voc_state == VOC_RUN) {
  4060. if ((module_id == MODULE_ID_VOICE_MODULE_ST) &&
  4061. (!v->tty_mode))
  4062. ret = voice_send_set_pp_enable_cmd(v,
  4063. MODULE_ID_VOICE_MODULE_ST,
  4064. enable);
  4065. }
  4066. mutex_unlock(&v->lock);
  4067. } else {
  4068. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4069. session_id);
  4070. ret = -EINVAL;
  4071. break;
  4072. }
  4073. }
  4074. return ret;
  4075. }
  4076. int voc_get_pp_enable(uint32_t session_id, uint32_t module_id)
  4077. {
  4078. struct voice_data *v = voice_get_session(session_id);
  4079. int ret = 0;
  4080. if (v == NULL) {
  4081. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4082. return -EINVAL;
  4083. }
  4084. mutex_lock(&v->lock);
  4085. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  4086. ret = v->st_enable;
  4087. mutex_unlock(&v->lock);
  4088. return ret;
  4089. }
  4090. int voc_set_rx_vol_step(uint32_t session_id, uint32_t dir, uint32_t vol_step,
  4091. uint32_t ramp_duration)
  4092. {
  4093. struct voice_data *v = NULL;
  4094. int ret = 0;
  4095. struct voice_session_itr itr;
  4096. pr_debug("%s session id = %#x vol = %u", __func__, session_id,
  4097. vol_step);
  4098. voice_itr_init(&itr, session_id);
  4099. while (voice_itr_get_next_session(&itr, &v)) {
  4100. if (v != NULL) {
  4101. mutex_lock(&v->lock);
  4102. v->dev_rx.volume_step_value = vol_step;
  4103. v->dev_rx.volume_ramp_duration_ms = ramp_duration;
  4104. if (is_voc_state_active(v->voc_state))
  4105. ret = voice_send_vol_step_cmd(v);
  4106. mutex_unlock(&v->lock);
  4107. } else {
  4108. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4109. session_id);
  4110. ret = -EINVAL;
  4111. break;
  4112. }
  4113. }
  4114. return ret;
  4115. }
  4116. int voc_set_rxtx_port(uint32_t session_id, uint32_t port_id, uint32_t dev_type)
  4117. {
  4118. struct voice_data *v = voice_get_session(session_id);
  4119. if (v == NULL) {
  4120. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4121. return -EINVAL;
  4122. }
  4123. pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
  4124. mutex_lock(&v->lock);
  4125. if (dev_type == DEV_RX)
  4126. v->dev_rx.port_id = q6audio_get_port_id(port_id);
  4127. else
  4128. v->dev_tx.port_id = q6audio_get_port_id(port_id);
  4129. mutex_unlock(&v->lock);
  4130. return 0;
  4131. }
  4132. int voc_set_route_flag(uint32_t session_id, uint8_t path_dir, uint8_t set)
  4133. {
  4134. struct voice_data *v = voice_get_session(session_id);
  4135. if (v == NULL) {
  4136. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4137. return -EINVAL;
  4138. }
  4139. pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
  4140. mutex_lock(&v->lock);
  4141. if (path_dir == RX_PATH)
  4142. v->voc_route_state.rx_route_flag = set;
  4143. else
  4144. v->voc_route_state.tx_route_flag = set;
  4145. mutex_unlock(&v->lock);
  4146. return 0;
  4147. }
  4148. uint8_t voc_get_route_flag(uint32_t session_id, uint8_t path_dir)
  4149. {
  4150. struct voice_data *v = voice_get_session(session_id);
  4151. int ret = 0;
  4152. if (v == NULL) {
  4153. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4154. return 0;
  4155. }
  4156. mutex_lock(&v->lock);
  4157. if (path_dir == RX_PATH)
  4158. ret = v->voc_route_state.rx_route_flag;
  4159. else
  4160. ret = v->voc_route_state.tx_route_flag;
  4161. mutex_unlock(&v->lock);
  4162. return ret;
  4163. }
  4164. int voc_end_voice_call(uint32_t session_id)
  4165. {
  4166. struct voice_data *v = voice_get_session(session_id);
  4167. int ret = 0;
  4168. if (v == NULL) {
  4169. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4170. return -EINVAL;
  4171. }
  4172. mutex_lock(&v->lock);
  4173. if (v->voc_state == VOC_RUN || v->voc_state == VOC_ERROR ||
  4174. v->voc_state == VOC_CHANGE || v->voc_state == VOC_STANDBY) {
  4175. if ((loopback_mode == 0) && (loopback_prev_mode == 1)) {
  4176. ret = send_packet_loopback_cmd(v, false);
  4177. if (ret < 0) {
  4178. pr_err("send packet loopback disable cmd failed\n");
  4179. } else {
  4180. pr_info("send packet loopback disable cmd success\n");
  4181. }
  4182. loopback_prev_mode = 0;
  4183. }
  4184. pr_debug("%s: VOC_STATE: %d\n", __func__, v->voc_state);
  4185. ret = voice_destroy_vocproc(v);
  4186. if (ret < 0)
  4187. pr_err("%s: destroy voice failed\n", __func__);
  4188. voice_destroy_mvm_cvs_session(v);
  4189. v->voc_state = VOC_RELEASE;
  4190. } else {
  4191. pr_err("%s: Error: End voice called in state %d\n",
  4192. __func__, v->voc_state);
  4193. ret = -EINVAL;
  4194. }
  4195. if (common.ec_ref_ext)
  4196. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  4197. mutex_unlock(&v->lock);
  4198. return ret;
  4199. }
  4200. int voc_standby_voice_call(uint32_t session_id)
  4201. {
  4202. struct voice_data *v = voice_get_session(session_id);
  4203. struct apr_hdr mvm_standby_voice_cmd;
  4204. void *apr_mvm;
  4205. u16 mvm_handle;
  4206. int ret = 0;
  4207. if (v == NULL) {
  4208. pr_err("%s: v is NULL\n", __func__);
  4209. return -EINVAL;
  4210. }
  4211. pr_debug("%s: voc state=%d", __func__, v->voc_state);
  4212. if (v->voc_state == VOC_RUN) {
  4213. apr_mvm = common.apr_q6_mvm;
  4214. if (!apr_mvm) {
  4215. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4216. ret = -EINVAL;
  4217. goto fail;
  4218. }
  4219. mvm_handle = voice_get_mvm_handle(v);
  4220. mvm_standby_voice_cmd.hdr_field =
  4221. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4222. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4223. mvm_standby_voice_cmd.pkt_size =
  4224. APR_PKT_SIZE(APR_HDR_SIZE,
  4225. sizeof(mvm_standby_voice_cmd) - APR_HDR_SIZE);
  4226. pr_debug("send mvm_standby_voice_cmd pkt size = %d\n",
  4227. mvm_standby_voice_cmd.pkt_size);
  4228. mvm_standby_voice_cmd.src_port =
  4229. voice_get_idx_for_session(v->session_id);
  4230. mvm_standby_voice_cmd.dest_port = mvm_handle;
  4231. mvm_standby_voice_cmd.token = 0;
  4232. mvm_standby_voice_cmd.opcode = VSS_IMVM_CMD_STANDBY_VOICE;
  4233. v->mvm_state = CMD_STATUS_FAIL;
  4234. ret = apr_send_pkt(apr_mvm,
  4235. (uint32_t *)&mvm_standby_voice_cmd);
  4236. if (ret < 0) {
  4237. pr_err("Fail in sending VSS_IMVM_CMD_STANDBY_VOICE\n");
  4238. ret = -EINVAL;
  4239. goto fail;
  4240. }
  4241. v->voc_state = VOC_STANDBY;
  4242. }
  4243. fail:
  4244. return ret;
  4245. }
  4246. int voc_disable_device(uint32_t session_id)
  4247. {
  4248. struct voice_data *v = voice_get_session(session_id);
  4249. int ret = 0;
  4250. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  4251. if (v == NULL) {
  4252. pr_err("%s: v is NULL\n", __func__);
  4253. return -EINVAL;
  4254. }
  4255. mutex_lock(&v->lock);
  4256. if (v->voc_state == VOC_RUN) {
  4257. ret = voice_pause_voice_call(v);
  4258. if (ret < 0) {
  4259. pr_err("%s: Pause Voice Call failed for session 0x%x, err %d!\n",
  4260. __func__, v->session_id, ret);
  4261. goto done;
  4262. }
  4263. rtac_remove_voice(voice_get_cvs_handle(v));
  4264. voice_send_cvp_deregister_vol_cal_cmd(v);
  4265. voice_send_cvp_deregister_cal_cmd(v);
  4266. voice_send_cvp_deregister_dev_cfg_cmd(v);
  4267. v->voc_state = VOC_CHANGE;
  4268. } else {
  4269. pr_debug("%s: called in voc state=%d, No_OP\n",
  4270. __func__, v->voc_state);
  4271. }
  4272. if (common.ec_ref_ext)
  4273. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  4274. done:
  4275. mutex_unlock(&v->lock);
  4276. return ret;
  4277. }
  4278. int voc_enable_device(uint32_t session_id)
  4279. {
  4280. struct voice_data *v = voice_get_session(session_id);
  4281. int ret = 0;
  4282. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  4283. if (v == NULL) {
  4284. pr_err("%s: v is NULL\n", __func__);
  4285. return -EINVAL;
  4286. }
  4287. mutex_lock(&v->lock);
  4288. if (v->voc_state == VOC_CHANGE) {
  4289. ret = voice_send_tty_mode_cmd(v);
  4290. if (ret < 0) {
  4291. pr_err("%s: Sending TTY mode failed, ret=%d\n",
  4292. __func__, ret);
  4293. /* Not a critical error, allow voice call to continue */
  4294. }
  4295. if (v->tty_mode) {
  4296. /* disable slowtalk */
  4297. voice_send_set_pp_enable_cmd(v,
  4298. MODULE_ID_VOICE_MODULE_ST,
  4299. 0);
  4300. } else {
  4301. /* restore slowtalk */
  4302. voice_send_set_pp_enable_cmd(v,
  4303. MODULE_ID_VOICE_MODULE_ST,
  4304. v->st_enable);
  4305. }
  4306. ret = voice_send_set_device_cmd(v);
  4307. if (ret < 0) {
  4308. pr_err("%s: Set device failed, ret=%d\n",
  4309. __func__, ret);
  4310. goto done;
  4311. }
  4312. voice_send_cvp_register_dev_cfg_cmd(v);
  4313. voice_send_cvp_register_cal_cmd(v);
  4314. voice_send_cvp_register_vol_cal_cmd(v);
  4315. rtac_add_voice(voice_get_cvs_handle(v),
  4316. voice_get_cvp_handle(v),
  4317. v->dev_rx.port_id, v->dev_tx.port_id,
  4318. v->session_id);
  4319. ret = voice_send_start_voice_cmd(v);
  4320. if (ret < 0) {
  4321. pr_err("%s: Fail in sending START_VOICE, ret=%d\n",
  4322. __func__, ret);
  4323. goto done;
  4324. }
  4325. v->voc_state = VOC_RUN;
  4326. } else {
  4327. pr_debug("%s: called in voc state=%d, No_OP\n",
  4328. __func__, v->voc_state);
  4329. }
  4330. done:
  4331. mutex_unlock(&v->lock);
  4332. return ret;
  4333. }
  4334. int voc_set_lch(uint32_t session_id, enum voice_lch_mode lch_mode)
  4335. {
  4336. struct voice_data *v = voice_get_session(session_id);
  4337. int ret = 0;
  4338. if (v == NULL) {
  4339. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  4340. ret = -EINVAL;
  4341. goto done;
  4342. }
  4343. mutex_lock(&v->lock);
  4344. if (v->lch_mode == lch_mode) {
  4345. pr_debug("%s: Session %d already in LCH mode %d\n",
  4346. __func__, session_id, lch_mode);
  4347. mutex_unlock(&v->lock);
  4348. goto done;
  4349. }
  4350. v->lch_mode = lch_mode;
  4351. mutex_unlock(&v->lock);
  4352. ret = voc_disable_cvp(session_id);
  4353. if (ret < 0) {
  4354. pr_err("%s: voc_disable_cvp failed ret=%d\n", __func__, ret);
  4355. goto done;
  4356. }
  4357. /* Mute and topology_none will be set as part of voc_enable_cvp() */
  4358. ret = voc_enable_cvp(session_id);
  4359. if (ret < 0) {
  4360. pr_err("%s: voc_enable_cvp failed ret=%d\n", __func__, ret);
  4361. goto done;
  4362. }
  4363. done:
  4364. return ret;
  4365. }
  4366. int voc_resume_voice_call(uint32_t session_id)
  4367. {
  4368. struct voice_data *v = voice_get_session(session_id);
  4369. int ret = 0;
  4370. ret = voice_send_start_voice_cmd(v);
  4371. if (ret < 0) {
  4372. pr_err("Fail in sending START_VOICE\n");
  4373. goto fail;
  4374. }
  4375. v->voc_state = VOC_RUN;
  4376. return 0;
  4377. fail:
  4378. return -EINVAL;
  4379. }
  4380. int voc_start_voice_call(uint32_t session_id)
  4381. {
  4382. struct voice_data *v = voice_get_session(session_id);
  4383. int ret = 0;
  4384. if (v == NULL) {
  4385. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4386. return -EINVAL;
  4387. }
  4388. mutex_lock(&v->lock);
  4389. if (v->voc_state == VOC_ERROR) {
  4390. pr_debug("%s: VOC in ERR state\n", __func__);
  4391. voice_destroy_mvm_cvs_session(v);
  4392. v->voc_state = VOC_INIT;
  4393. }
  4394. if ((v->voc_state == VOC_INIT) ||
  4395. (v->voc_state == VOC_RELEASE)) {
  4396. ret = voice_apr_register();
  4397. if (ret < 0) {
  4398. pr_err("%s: apr register failed\n", __func__);
  4399. goto fail;
  4400. }
  4401. ret = voice_create_mvm_cvs_session(v);
  4402. if (ret < 0) {
  4403. pr_err("create mvm and cvs failed\n");
  4404. goto fail;
  4405. }
  4406. /* Allocate cal mem if not already allocated and memory map
  4407. * the calibration memory block.
  4408. */
  4409. ret = voice_alloc_and_map_cal_mem(v);
  4410. if (ret < 0) {
  4411. pr_debug("%s: Continue without calibration %d\n",
  4412. __func__, ret);
  4413. }
  4414. if (is_voip_session(session_id)) {
  4415. /* Allocate oob mem if not already allocated and
  4416. * memory map the oob memory block.
  4417. */
  4418. ret = voice_alloc_and_map_oob_mem(v);
  4419. if (ret < 0) {
  4420. pr_err("%s: voice_alloc_and_map_oob_mem() failed, ret:%d\n",
  4421. __func__, ret);
  4422. goto fail;
  4423. }
  4424. ret = voice_set_packet_exchange_mode_and_config(
  4425. session_id,
  4426. VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND);
  4427. if (ret) {
  4428. pr_err("%s: Err: exchange_mode_and_config %d\n",
  4429. __func__, ret);
  4430. goto fail;
  4431. }
  4432. }
  4433. ret = voice_send_dual_control_cmd(v);
  4434. if (ret < 0) {
  4435. pr_err("Err Dual command failed\n");
  4436. goto fail;
  4437. }
  4438. ret = voice_setup_vocproc(v);
  4439. if (ret < 0) {
  4440. pr_err("setup voice failed\n");
  4441. goto fail;
  4442. }
  4443. ret = voice_send_vol_step_cmd(v);
  4444. if (ret < 0)
  4445. pr_err("voice volume failed\n");
  4446. ret = voice_send_stream_mute_cmd(v,
  4447. VSS_IVOLUME_DIRECTION_TX,
  4448. v->stream_tx.stream_mute,
  4449. v->stream_tx.stream_mute_ramp_duration_ms);
  4450. if (ret < 0)
  4451. pr_err("voice mute failed\n");
  4452. ret = voice_send_start_voice_cmd(v);
  4453. if (ret < 0) {
  4454. pr_err("start voice failed\n");
  4455. goto fail;
  4456. }
  4457. if (loopback_mode == 1) {
  4458. ret = send_packet_loopback_cmd(v, true);
  4459. if (ret < 0) {
  4460. pr_err("send packet loopback cmd failed\n");
  4461. goto fail;
  4462. } else {
  4463. pr_info("%s : send packet loopback enable cmd success\n", __func__);
  4464. }
  4465. }
  4466. v->voc_state = VOC_RUN;
  4467. } else {
  4468. pr_err("%s: Error: Start voice called in state %d\n",
  4469. __func__, v->voc_state);
  4470. ret = -EINVAL;
  4471. goto fail;
  4472. }
  4473. fail:
  4474. mutex_unlock(&v->lock);
  4475. return ret;
  4476. }
  4477. int voc_set_ext_ec_ref(uint16_t port_id, bool state)
  4478. {
  4479. int ret = 0;
  4480. mutex_lock(&common.common_lock);
  4481. if (state == true) {
  4482. if (port_id == AFE_PORT_INVALID) {
  4483. pr_err("%s: Invalid port id", __func__);
  4484. ret = -EINVAL;
  4485. goto exit;
  4486. }
  4487. common.ec_port_id = port_id;
  4488. common.ec_ref_ext = true;
  4489. } else {
  4490. common.ec_ref_ext = false;
  4491. common.ec_port_id = port_id;
  4492. }
  4493. exit:
  4494. mutex_unlock(&common.common_lock);
  4495. return ret;
  4496. }
  4497. void voc_register_mvs_cb(ul_cb_fn ul_cb,
  4498. dl_cb_fn dl_cb,
  4499. voip_ssr_cb ssr_cb,
  4500. void *private_data)
  4501. {
  4502. common.mvs_info.ul_cb = ul_cb;
  4503. common.mvs_info.dl_cb = dl_cb;
  4504. common.mvs_info.ssr_cb = ssr_cb;
  4505. common.mvs_info.private_data = private_data;
  4506. }
  4507. void voc_register_dtmf_rx_detection_cb(dtmf_rx_det_cb_fn dtmf_rx_ul_cb,
  4508. void *private_data)
  4509. {
  4510. common.dtmf_info.dtmf_rx_ul_cb = dtmf_rx_ul_cb;
  4511. common.dtmf_info.private_data = private_data;
  4512. }
  4513. void voc_config_vocoder(uint32_t media_type,
  4514. uint32_t rate,
  4515. uint32_t network_type,
  4516. uint32_t dtx_mode,
  4517. uint32_t evrc_min_rate,
  4518. uint32_t evrc_max_rate)
  4519. {
  4520. common.mvs_info.media_type = media_type;
  4521. common.mvs_info.rate = rate;
  4522. common.mvs_info.network_type = network_type;
  4523. common.mvs_info.dtx_mode = dtx_mode;
  4524. common.mvs_info.evrc_min_rate = evrc_min_rate;
  4525. common.mvs_info.evrc_max_rate = evrc_max_rate;
  4526. }
  4527. #ifdef CONFIG_SEC_DHA_SOL_MAL
  4528. static int voice_send_dha_data(struct voice_data *v)
  4529. {
  4530. struct oem_dha_parm_send_cmd vpcm_dha_param_send_cmd;
  4531. int ret = 0, mode = 0;
  4532. void *apr_cvp;
  4533. u16 cvp_handle;
  4534. if (v == NULL) {
  4535. pr_err("%s: v is NULL\n", __func__);
  4536. return -EINVAL;
  4537. }
  4538. apr_cvp = common.apr_q6_cvp;
  4539. if (!apr_cvp) {
  4540. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4541. return -EINVAL;
  4542. }
  4543. cvp_handle = voice_get_cvp_handle(v);
  4544. /* BEGIN: DHA */
  4545. /* Send start vpcm and wait for response. */
  4546. pr_debug("%s: Success DHA\n", __func__);
  4547. /* fill in the header */
  4548. vpcm_dha_param_send_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4549. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4550. vpcm_dha_param_send_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4551. sizeof(vpcm_dha_param_send_cmd) - APR_HDR_SIZE);
  4552. vpcm_dha_param_send_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  4553. vpcm_dha_param_send_cmd.hdr.dest_port = cvp_handle;
  4554. vpcm_dha_param_send_cmd.hdr.token = 0;
  4555. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  4556. vpcm_dha_param_send_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  4557. #else
  4558. vpcm_dha_param_send_cmd.hdr.opcode = VOICE_CMD_SET_PARAM;
  4559. #endif
  4560. #if !defined(CONFIG_MACH_S3VE3G_EUR) && !defined(CONFIG_MACH_MS01_EUR_3G) && !defined(CONFIG_MACH_MS01_EUR_LTE) && !defined(CONFIG_MACH_MS01_KOR_LTE) && !defined(CONFIG_DSDA_VIA_UART)
  4561. vpcm_dha_param_send_cmd.mem_handle = 0;
  4562. vpcm_dha_param_send_cmd.mem_address = 0;
  4563. vpcm_dha_param_send_cmd.mem_size = 40;
  4564. #endif
  4565. vpcm_dha_param_send_cmd.dha_send.module_id = VOICE_MODULE_DHA;
  4566. vpcm_dha_param_send_cmd.dha_send.param_id = VOICE_PARAM_DHA_DYNAMIC;
  4567. vpcm_dha_param_send_cmd.dha_send.param_size = 28;
  4568. vpcm_dha_param_send_cmd.dha_send.reserved = 0;
  4569. mode = v->sec_dha_data.dha_mode;
  4570. vpcm_dha_param_send_cmd.dha_send.eq_mode = mode;
  4571. vpcm_dha_param_send_cmd.dha_send.select =
  4572. (uint16_t)v->sec_dha_data.dha_select;
  4573. memcpy(vpcm_dha_param_send_cmd.dha_send.param,
  4574. v->sec_dha_data.dha_params, 24);
  4575. pr_info(" send vpcm_dha_param_send_cmd, mode = %d, select=%d\n",
  4576. mode, vpcm_dha_param_send_cmd.dha_send.select);
  4577. v->cvp_state = CMD_STATUS_FAIL;
  4578. dha_state = 1;
  4579. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_dha_param_send_cmd);
  4580. if (ret < 0) {
  4581. pr_err("%s: Failed to send vpcm_dha_param_send_cmd\n",
  4582. __func__);
  4583. dha_state = 0;
  4584. goto fail;
  4585. }
  4586. pr_debug("wait for vpcm_dha_param_send_cmd\n");
  4587. ret = wait_event_timeout(v->cvp_wait,
  4588. (v->cvp_state == CMD_STATUS_SUCCESS),
  4589. msecs_to_jiffies(TIMEOUT_MS));
  4590. dha_state = 0;
  4591. if (!ret) {
  4592. pr_err("%s: wait_event timeout\n", __func__);
  4593. goto fail;
  4594. }
  4595. return 0;
  4596. fail:
  4597. return -EINVAL;
  4598. }
  4599. int voice_sec_set_dha_data(uint32_t session_id, short mode,
  4600. short select, short *parameters)
  4601. {
  4602. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  4603. struct voice_data *v = NULL;
  4604. int ret = 0;
  4605. int i = 0;
  4606. struct voice_session_itr itr;
  4607. voice_itr_init(&itr, session_id);
  4608. while (voice_itr_get_next_session(&itr, &v)) {
  4609. if (v != NULL) {
  4610. mutex_lock(&v->lock);
  4611. v->sec_dha_data.dha_mode = mode;
  4612. v->sec_dha_data.dha_select = select;
  4613. for (i = 0; i < 12; i++)
  4614. v->sec_dha_data.dha_params[i] = (short)parameters[i];
  4615. if (is_voc_state_active(v->voc_state) &&
  4616. (v->lch_mode == 0))
  4617. ret = voice_send_dha_data(v);
  4618. mutex_unlock(&v->lock);
  4619. } else {
  4620. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4621. session_id);
  4622. ret = -EINVAL;
  4623. break;
  4624. }
  4625. }
  4626. #else
  4627. struct voice_data *v = voice_get_session(session_id);
  4628. int ret = 0;
  4629. int i;
  4630. if (v == NULL) {
  4631. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4632. return -EINVAL;
  4633. }
  4634. mutex_lock(&v->lock);
  4635. v->sec_dha_data.dha_mode = mode;
  4636. v->sec_dha_data.dha_select = select;
  4637. for (i = 0; i < 12; i++)
  4638. v->sec_dha_data.dha_params[i] = (short)parameters[i];
  4639. if (v->voc_state == VOC_RUN)
  4640. ret = voice_send_dha_data(v);
  4641. mutex_unlock(&v->lock);
  4642. #endif
  4643. return ret;
  4644. }
  4645. EXPORT_SYMBOL(voice_sec_set_dha_data);
  4646. #endif /* CONFIG_SEC_DHA_SOL_MAL*/
  4647. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
  4648. {
  4649. uint32_t *ptr = NULL;
  4650. struct common_data *c = NULL;
  4651. struct voice_data *v = NULL;
  4652. int i = 0;
  4653. if ((data == NULL) || (priv == NULL)) {
  4654. pr_err("%s: data or priv is NULL\n", __func__);
  4655. return -EINVAL;
  4656. }
  4657. c = priv;
  4658. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  4659. data->payload_size, data->opcode);
  4660. if (data->opcode == RESET_EVENTS) {
  4661. if (data->reset_proc == APR_DEST_MODEM) {
  4662. pr_debug("%s: Received MODEM reset event\n", __func__);
  4663. } else {
  4664. pr_debug("%s: Reset event received in Voice service\n",
  4665. __func__);
  4666. if (common.mvs_info.ssr_cb) {
  4667. pr_debug("%s: Informing reset event to VoIP\n",
  4668. __func__);
  4669. common.mvs_info.ssr_cb(data->opcode,
  4670. common.mvs_info.private_data);
  4671. }
  4672. apr_reset(c->apr_q6_mvm);
  4673. c->apr_q6_mvm = NULL;
  4674. /* clean up memory handle */
  4675. c->cal_mem_handle = 0;
  4676. c->rtac_mem_handle = 0;
  4677. rtac_clear_mapping(VOICE_RTAC_CAL);
  4678. /* Sub-system restart is applicable to all sessions. */
  4679. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  4680. c->voice[i].mvm_handle = 0;
  4681. c->voice[i].shmem_info.mem_handle = 0;
  4682. }
  4683. }
  4684. /* clean up srvcc rec flag */
  4685. c->srvcc_rec_flag = false;
  4686. voc_set_error_state(data->reset_proc);
  4687. return 0;
  4688. }
  4689. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  4690. v = voice_get_session_by_idx(data->dest_port);
  4691. if (v == NULL) {
  4692. pr_err("%s: v is NULL\n", __func__);
  4693. return -EINVAL;
  4694. }
  4695. if (data->opcode == APR_BASIC_RSP_RESULT) {
  4696. if (data->payload_size) {
  4697. ptr = data->payload;
  4698. pr_debug("%x %x\n", ptr[0], ptr[1]);
  4699. /* ping mvm service ACK */
  4700. switch (ptr[0]) {
  4701. case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  4702. case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
  4703. /* Passive session is used for CS call
  4704. * Full session is used for VoIP call. */
  4705. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4706. if (!ptr[1]) {
  4707. pr_debug("%s: MVM handle is %d\n",
  4708. __func__, data->src_port);
  4709. voice_set_mvm_handle(v, data->src_port);
  4710. } else
  4711. pr_err("got NACK for sending MVM create session\n");
  4712. v->mvm_state = CMD_STATUS_SUCCESS;
  4713. wake_up(&v->mvm_wait);
  4714. break;
  4715. case VSS_IMVM_CMD_START_VOICE:
  4716. case VSS_IMVM_CMD_ATTACH_VOCPROC:
  4717. case VSS_IMVM_CMD_STOP_VOICE:
  4718. case VSS_IMVM_CMD_DETACH_VOCPROC:
  4719. case VSS_ISTREAM_CMD_SET_TTY_MODE:
  4720. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  4721. case VSS_IMVM_CMD_ATTACH_STREAM:
  4722. case VSS_IMVM_CMD_DETACH_STREAM:
  4723. case VSS_ICOMMON_CMD_SET_NETWORK:
  4724. case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
  4725. case VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL:
  4726. case VSS_IMVM_CMD_SET_CAL_NETWORK:
  4727. case VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE:
  4728. case VSS_IMEMORY_CMD_MAP_PHYSICAL:
  4729. case VSS_IMEMORY_CMD_UNMAP:
  4730. case VSS_IMVM_CMD_PAUSE_VOICE:
  4731. case VSS_IMVM_CMD_STANDBY_VOICE:
  4732. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4733. v->mvm_state = CMD_STATUS_SUCCESS;
  4734. wake_up(&v->mvm_wait);
  4735. break;
  4736. default:
  4737. pr_debug("%s: not match cmd = 0x%x\n",
  4738. __func__, ptr[0]);
  4739. break;
  4740. }
  4741. }
  4742. } else if (data->opcode == VSS_IMEMORY_RSP_MAP) {
  4743. pr_debug("%s, Revd VSS_IMEMORY_RSP_MAP response\n", __func__);
  4744. if (data->payload_size && data->token == VOIP_MEM_MAP_TOKEN) {
  4745. ptr = data->payload;
  4746. if (ptr[0]) {
  4747. v->shmem_info.mem_handle = ptr[0];
  4748. pr_debug("%s: shared mem_handle: 0x[%x]\n",
  4749. __func__, v->shmem_info.mem_handle);
  4750. v->mvm_state = CMD_STATUS_SUCCESS;
  4751. wake_up(&v->mvm_wait);
  4752. }
  4753. } else if (data->payload_size &&
  4754. data->token == VOC_CAL_MEM_MAP_TOKEN) {
  4755. ptr = data->payload;
  4756. if (ptr[0]) {
  4757. c->cal_mem_handle = ptr[0];
  4758. pr_debug("%s: cal mem handle 0x%x\n",
  4759. __func__, c->cal_mem_handle);
  4760. v->mvm_state = CMD_STATUS_SUCCESS;
  4761. wake_up(&v->mvm_wait);
  4762. }
  4763. } else if (data->payload_size &&
  4764. data->token == VOC_RTAC_MEM_MAP_TOKEN) {
  4765. ptr = data->payload;
  4766. if (ptr[0]) {
  4767. c->rtac_mem_handle = ptr[0];
  4768. pr_debug("%s: cal mem handle 0x%x\n",
  4769. __func__, c->rtac_mem_handle);
  4770. v->mvm_state = CMD_STATUS_SUCCESS;
  4771. wake_up(&v->mvm_wait);
  4772. }
  4773. } else {
  4774. pr_err("%s: Unknown mem map token %d\n",
  4775. __func__, data->token);
  4776. }
  4777. }
  4778. return 0;
  4779. }
  4780. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
  4781. {
  4782. uint32_t *ptr = NULL;
  4783. struct common_data *c = NULL;
  4784. struct voice_data *v = NULL;
  4785. int i = 0;
  4786. if ((data == NULL) || (priv == NULL)) {
  4787. pr_err("%s: data or priv is NULL\n", __func__);
  4788. return -EINVAL;
  4789. }
  4790. c = priv;
  4791. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  4792. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  4793. data->payload_size, data->opcode);
  4794. if (data->opcode == RESET_EVENTS) {
  4795. if (data->reset_proc == APR_DEST_MODEM) {
  4796. pr_debug("%s: Received Modem reset event\n", __func__);
  4797. } else {
  4798. pr_debug("%s: Reset event received in Voice service\n",
  4799. __func__);
  4800. apr_reset(c->apr_q6_cvs);
  4801. c->apr_q6_cvs = NULL;
  4802. /* Sub-system restart is applicable to all sessions. */
  4803. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  4804. c->voice[i].cvs_handle = 0;
  4805. }
  4806. voc_set_error_state(data->reset_proc);
  4807. return 0;
  4808. }
  4809. v = voice_get_session_by_idx(data->dest_port);
  4810. if (v == NULL) {
  4811. pr_err("%s: v is NULL\n", __func__);
  4812. return -EINVAL;
  4813. }
  4814. if (data->opcode == APR_BASIC_RSP_RESULT) {
  4815. if (data->payload_size) {
  4816. ptr = data->payload;
  4817. pr_debug("%x %x\n", ptr[0], ptr[1]);
  4818. if (ptr[1] != 0) {
  4819. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  4820. __func__, ptr[0], ptr[1]);
  4821. }
  4822. /*response from CVS */
  4823. switch (ptr[0]) {
  4824. case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  4825. case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
  4826. if (!ptr[1]) {
  4827. pr_debug("%s: CVS handle is %d\n",
  4828. __func__, data->src_port);
  4829. voice_set_cvs_handle(v, data->src_port);
  4830. } else
  4831. pr_err("got NACK for sending CVS create session\n");
  4832. v->cvs_state = CMD_STATUS_SUCCESS;
  4833. wake_up(&v->cvs_wait);
  4834. break;
  4835. case VSS_IVOLUME_CMD_MUTE_V2:
  4836. case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
  4837. case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
  4838. case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
  4839. case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
  4840. case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
  4841. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  4842. case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2:
  4843. case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
  4844. case VSS_ICOMMON_CMD_MAP_MEMORY:
  4845. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  4846. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  4847. case VSS_IPLAYBACK_CMD_START:
  4848. case VSS_IPLAYBACK_CMD_STOP:
  4849. case VSS_IRECORD_CMD_START:
  4850. case VSS_IRECORD_CMD_STOP:
  4851. case VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE:
  4852. case VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG:
  4853. case VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION:
  4854. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4855. v->cvs_state = CMD_STATUS_SUCCESS;
  4856. wake_up(&v->cvs_wait);
  4857. break;
  4858. case VOICE_CMD_SET_PARAM:
  4859. pr_debug("%s: VOICE_CMD_SET_PARAM\n", __func__);
  4860. rtac_make_voice_callback(RTAC_CVS, ptr,
  4861. data->payload_size);
  4862. if ((loopback_mode == 1) ||
  4863. ((loopback_mode == 0) && (loopback_prev_mode == 1))) {
  4864. v->cvs_state = CMD_STATUS_SUCCESS;
  4865. wake_up(&v->cvs_wait);
  4866. }
  4867. break;
  4868. case VOICE_CMD_GET_PARAM:
  4869. pr_debug("%s: VOICE_CMD_GET_PARAM\n",
  4870. __func__);
  4871. /* Should only come here if there is an APR */
  4872. /* error or malformed APR packet. Otherwise */
  4873. /* response will be returned as */
  4874. /* VOICE_EVT_GET_PARAM_ACK */
  4875. if (ptr[1] != 0) {
  4876. pr_err("%s: CVP get param error = %d, resuming\n",
  4877. __func__, ptr[1]);
  4878. rtac_make_voice_callback(RTAC_CVP,
  4879. data->payload,
  4880. data->payload_size);
  4881. }
  4882. break;
  4883. default:
  4884. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4885. break;
  4886. }
  4887. }
  4888. } else if (data->opcode ==
  4889. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_READY) {
  4890. int ret = 0;
  4891. u16 cvs_handle;
  4892. uint32_t *cvs_voc_pkt;
  4893. struct cvs_enc_buffer_consumed_cmd send_enc_buf_consumed_cmd;
  4894. void *apr_cvs;
  4895. pr_debug("Encoder buffer is ready\n");
  4896. apr_cvs = common.apr_q6_cvs;
  4897. if (!apr_cvs) {
  4898. pr_err("%s: apr_cvs is NULL\n", __func__);
  4899. return -EINVAL;
  4900. }
  4901. cvs_handle = voice_get_cvs_handle(v);
  4902. send_enc_buf_consumed_cmd.hdr.hdr_field =
  4903. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4904. APR_HDR_LEN(APR_HDR_SIZE),
  4905. APR_PKT_VER);
  4906. send_enc_buf_consumed_cmd.hdr.pkt_size =
  4907. APR_PKT_SIZE(APR_HDR_SIZE,
  4908. sizeof(send_enc_buf_consumed_cmd) - APR_HDR_SIZE);
  4909. send_enc_buf_consumed_cmd.hdr.src_port =
  4910. voice_get_idx_for_session(v->session_id);
  4911. send_enc_buf_consumed_cmd.hdr.dest_port = cvs_handle;
  4912. send_enc_buf_consumed_cmd.hdr.token = 0;
  4913. send_enc_buf_consumed_cmd.hdr.opcode =
  4914. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_CONSUMED;
  4915. cvs_voc_pkt = v->shmem_info.sh_buf.buf[1].data;
  4916. if (cvs_voc_pkt != NULL && common.mvs_info.ul_cb != NULL) {
  4917. if (v->shmem_info.sh_buf.buf[1].size <
  4918. ((3 * sizeof(uint32_t)) + cvs_voc_pkt[2])) {
  4919. pr_err("%s: invalid voc pkt size\n", __func__);
  4920. return -EINVAL;
  4921. }
  4922. /* cvs_voc_pkt[0] contains tx timestamp */
  4923. common.mvs_info.ul_cb((uint8_t *)&cvs_voc_pkt[3],
  4924. cvs_voc_pkt[2],
  4925. cvs_voc_pkt[0],
  4926. common.mvs_info.private_data);
  4927. } else
  4928. pr_err("%s: cvs_voc_pkt or ul_cb is NULL\n", __func__);
  4929. ret = apr_send_pkt(apr_cvs,
  4930. (uint32_t *) &send_enc_buf_consumed_cmd);
  4931. if (ret < 0) {
  4932. pr_err("%s: Err send ENC_BUF_CONSUMED_NOTIFY %d\n",
  4933. __func__, ret);
  4934. goto fail;
  4935. }
  4936. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
  4937. pr_debug("Recd VSS_ISTREAM_EVT_SEND_ENC_BUFFER\n");
  4938. } else if (data->opcode ==
  4939. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_REQUEST) {
  4940. int ret = 0;
  4941. u16 cvs_handle;
  4942. uint32_t *cvs_voc_pkt;
  4943. struct cvs_dec_buffer_ready_cmd send_dec_buf;
  4944. void *apr_cvs;
  4945. apr_cvs = common.apr_q6_cvs;
  4946. if (!apr_cvs) {
  4947. pr_err("%s: apr_cvs is NULL\n", __func__);
  4948. return -EINVAL;
  4949. }
  4950. cvs_handle = voice_get_cvs_handle(v);
  4951. send_dec_buf.hdr.hdr_field =
  4952. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4953. APR_HDR_LEN(APR_HDR_SIZE),
  4954. APR_PKT_VER);
  4955. send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4956. sizeof(send_dec_buf) - APR_HDR_SIZE);
  4957. send_dec_buf.hdr.src_port =
  4958. voice_get_idx_for_session(v->session_id);
  4959. send_dec_buf.hdr.dest_port = cvs_handle;
  4960. send_dec_buf.hdr.token = 0;
  4961. send_dec_buf.hdr.opcode =
  4962. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_READY;
  4963. cvs_voc_pkt = (uint32_t *)(v->shmem_info.sh_buf.buf[0].data);
  4964. if (cvs_voc_pkt != NULL && common.mvs_info.dl_cb != NULL) {
  4965. /* Set timestamp to 0 and advance the pointer */
  4966. cvs_voc_pkt[0] = 0;
  4967. /* Set media_type and advance the pointer */
  4968. cvs_voc_pkt[1] = common.mvs_info.media_type;
  4969. common.mvs_info.dl_cb(
  4970. (uint8_t *)&cvs_voc_pkt[2],
  4971. common.mvs_info.private_data);
  4972. ret = apr_send_pkt(apr_cvs, (uint32_t *) &send_dec_buf);
  4973. if (ret < 0) {
  4974. pr_err("%s: Err send DEC_BUF_READY_NOTIFI %d\n",
  4975. __func__, ret);
  4976. goto fail;
  4977. }
  4978. } else {
  4979. pr_debug("%s: voc_pkt or dl_cb is NULL\n", __func__);
  4980. goto fail;
  4981. }
  4982. } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
  4983. pr_debug("Recd VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER\n");
  4984. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
  4985. pr_debug("Send dec buf resp\n");
  4986. } else if (data->opcode == APR_RSP_ACCEPTED) {
  4987. ptr = data->payload;
  4988. if (ptr[0])
  4989. pr_debug("%s: APR_RSP_ACCEPTED for 0x%x:\n",
  4990. __func__, ptr[0]);
  4991. } else if (data->opcode == VSS_ISTREAM_EVT_NOT_READY) {
  4992. pr_debug("Recd VSS_ISTREAM_EVT_NOT_READY\n");
  4993. } else if (data->opcode == VSS_ISTREAM_EVT_READY) {
  4994. pr_debug("Recd VSS_ISTREAM_EVT_READY\n");
  4995. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  4996. pr_debug("%s: VOICE_EVT_GET_PARAM_ACK\n", __func__);
  4997. ptr = data->payload;
  4998. if (ptr[0] != 0) {
  4999. pr_err("%s: VOICE_EVT_GET_PARAM_ACK returned error = 0x%x\n",
  5000. __func__, ptr[0]);
  5001. }
  5002. rtac_make_voice_callback(RTAC_CVS, data->payload,
  5003. data->payload_size);
  5004. } else if (data->opcode == VSS_ISTREAM_EVT_RX_DTMF_DETECTED) {
  5005. struct vss_istream_evt_rx_dtmf_detected *dtmf_rx_detected;
  5006. uint32_t *voc_pkt = data->payload;
  5007. uint32_t pkt_len = data->payload_size;
  5008. if ((voc_pkt != NULL) &&
  5009. (pkt_len ==
  5010. sizeof(struct vss_istream_evt_rx_dtmf_detected))) {
  5011. dtmf_rx_detected =
  5012. (struct vss_istream_evt_rx_dtmf_detected *) voc_pkt;
  5013. pr_debug("RX_DTMF_DETECTED low_freq=%d high_freq=%d\n",
  5014. dtmf_rx_detected->low_freq,
  5015. dtmf_rx_detected->high_freq);
  5016. if (c->dtmf_info.dtmf_rx_ul_cb)
  5017. c->dtmf_info.dtmf_rx_ul_cb((uint8_t *)voc_pkt,
  5018. voc_get_session_name(v->session_id),
  5019. c->dtmf_info.private_data);
  5020. } else {
  5021. pr_err("Invalid packet\n");
  5022. }
  5023. } else
  5024. pr_debug("Unknown opcode 0x%x\n", data->opcode);
  5025. fail:
  5026. return 0;
  5027. }
  5028. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
  5029. {
  5030. uint32_t *ptr = NULL;
  5031. struct common_data *c = NULL;
  5032. struct voice_data *v = NULL;
  5033. int i = 0;
  5034. if ((data == NULL) || (priv == NULL)) {
  5035. pr_err("%s: data or priv is NULL\n", __func__);
  5036. return -EINVAL;
  5037. }
  5038. c = priv;
  5039. if (data->opcode == RESET_EVENTS) {
  5040. if (data->reset_proc == APR_DEST_MODEM) {
  5041. pr_debug("%s: Received Modem reset event\n", __func__);
  5042. } else {
  5043. pr_debug("%s: Reset event received in Voice service\n",
  5044. __func__);
  5045. apr_reset(c->apr_q6_cvp);
  5046. c->apr_q6_cvp = NULL;
  5047. /* Sub-system restart is applicable to all sessions. */
  5048. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  5049. c->voice[i].cvp_handle = 0;
  5050. }
  5051. voc_set_error_state(data->reset_proc);
  5052. return 0;
  5053. }
  5054. v = voice_get_session_by_idx(data->dest_port);
  5055. if (v == NULL) {
  5056. pr_err("%s: v is NULL\n", __func__);
  5057. return -EINVAL;
  5058. }
  5059. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5060. if (data->payload_size >= (2 * sizeof(uint32_t))) {
  5061. ptr = data->payload;
  5062. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5063. if (ptr[1] != 0) {
  5064. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  5065. __func__, ptr[0], ptr[1]);
  5066. }
  5067. switch (ptr[0]) {
  5068. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2:
  5069. /*response from CVP */
  5070. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5071. if (!ptr[1]) {
  5072. voice_set_cvp_handle(v, data->src_port);
  5073. pr_debug("status: %d, cvphdl=%d\n",
  5074. ptr[1], data->src_port);
  5075. } else
  5076. pr_err("got NACK from CVP create session response\n");
  5077. v->cvp_state = CMD_STATUS_SUCCESS;
  5078. wake_up(&v->cvp_wait);
  5079. break;
  5080. case VSS_IVOCPROC_CMD_SET_DEVICE_V2:
  5081. case VSS_IVOLUME_CMD_SET_STEP:
  5082. case VSS_IVOCPROC_CMD_ENABLE:
  5083. case VSS_IVOCPROC_CMD_DISABLE:
  5084. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5085. case VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA:
  5086. case VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA:
  5087. case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2:
  5088. case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
  5089. case VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG:
  5090. case VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG:
  5091. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  5092. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  5093. #endif
  5094. case VSS_ICOMMON_CMD_MAP_MEMORY:
  5095. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  5096. case VSS_IVOLUME_CMD_MUTE_V2:
  5097. v->cvp_state = CMD_STATUS_SUCCESS;
  5098. wake_up(&v->cvp_wait);
  5099. break;
  5100. case VOICE_CMD_SET_PARAM:
  5101. pr_debug("%s: VOICE_CMD_SET_PARAM\n", __func__);
  5102. rtac_make_voice_callback(RTAC_CVP, ptr,
  5103. data->payload_size);
  5104. if (dha_state) {
  5105. v->cvp_state = CMD_STATUS_SUCCESS;
  5106. wake_up(&v->cvp_wait);
  5107. }
  5108. break;
  5109. case VOICE_CMD_GET_PARAM:
  5110. pr_debug("%s: VOICE_CMD_GET_PARAM\n",
  5111. __func__);
  5112. /* Should only come here if there is an APR */
  5113. /* error or malformed APR packet. Otherwise */
  5114. /* response will be returned as */
  5115. /* VOICE_EVT_GET_PARAM_ACK */
  5116. if (ptr[1] != 0) {
  5117. pr_err("%s: CVP get param error = %d, resuming\n",
  5118. __func__, ptr[1]);
  5119. rtac_make_voice_callback(RTAC_CVP,
  5120. data->payload,
  5121. data->payload_size);
  5122. }
  5123. break;
  5124. #ifdef CONFIG_SEC_DHA_SOL_MAL
  5125. case VSS_ICOMMON_CMD_DHA_SET:
  5126. pr_err("Got ACK from CVP DHA set\n");
  5127. v->cvp_state = CMD_STATUS_SUCCESS;
  5128. wake_up(&v->cvp_wait);
  5129. break;
  5130. #endif /* CONFIG_SEC_DHA_SOL_MAL*/
  5131. default:
  5132. pr_debug("%s: not match cmd = 0x%x\n",
  5133. __func__, ptr[0]);
  5134. break;
  5135. }
  5136. }
  5137. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  5138. pr_debug("%s: VOICE_EVT_GET_PARAM_ACK\n", __func__);
  5139. ptr = data->payload;
  5140. if (ptr[0] != 0) {
  5141. pr_err("%s: VOICE_EVT_GET_PARAM_ACK returned error = 0x%x\n",
  5142. __func__, ptr[0]);
  5143. }
  5144. rtac_make_voice_callback(RTAC_CVP, data->payload,
  5145. data->payload_size);
  5146. }
  5147. return 0;
  5148. }
  5149. static int voice_free_oob_shared_mem(void)
  5150. {
  5151. int rc = 0;
  5152. int cnt = 0;
  5153. int bufcnt = NUM_OF_BUFFERS;
  5154. struct voice_data *v = voice_get_session(
  5155. common.voice[VOC_PATH_FULL].session_id);
  5156. mutex_lock(&common.common_lock);
  5157. if (v == NULL) {
  5158. pr_err("%s: v is NULL\n", __func__);
  5159. rc = -EINVAL;
  5160. goto done;
  5161. }
  5162. rc = msm_audio_ion_free(v->shmem_info.sh_buf.client,
  5163. v->shmem_info.sh_buf.handle);
  5164. v->shmem_info.sh_buf.client = NULL;
  5165. v->shmem_info.sh_buf.handle = NULL;
  5166. if (rc < 0) {
  5167. pr_err("%s: Error:%d freeing memory\n", __func__, rc);
  5168. goto done;
  5169. }
  5170. while (cnt < bufcnt) {
  5171. v->shmem_info.sh_buf.buf[cnt].data = NULL;
  5172. v->shmem_info.sh_buf.buf[cnt].phys = 0;
  5173. cnt++;
  5174. }
  5175. v->shmem_info.sh_buf.client = NULL;
  5176. v->shmem_info.sh_buf.handle = NULL;
  5177. done:
  5178. mutex_unlock(&common.common_lock);
  5179. return rc;
  5180. }
  5181. static int voice_alloc_oob_shared_mem(void)
  5182. {
  5183. int cnt = 0;
  5184. int rc = 0;
  5185. int len;
  5186. void *mem_addr;
  5187. dma_addr_t phys;
  5188. int bufsz = BUFFER_BLOCK_SIZE;
  5189. int bufcnt = NUM_OF_BUFFERS;
  5190. struct voice_data *v = voice_get_session(
  5191. common.voice[VOC_PATH_FULL].session_id);
  5192. mutex_lock(&common.common_lock);
  5193. if (v == NULL) {
  5194. pr_err("%s: v is NULL\n", __func__);
  5195. rc = -EINVAL;
  5196. goto done;
  5197. }
  5198. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.sh_buf.client),
  5199. &(v->shmem_info.sh_buf.handle),
  5200. bufsz*bufcnt,
  5201. (ion_phys_addr_t *)&phys, (size_t *)&len,
  5202. &mem_addr);
  5203. if (rc < 0) {
  5204. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5205. __func__, rc);
  5206. goto done;
  5207. }
  5208. while (cnt < bufcnt) {
  5209. v->shmem_info.sh_buf.buf[cnt].data = mem_addr + (cnt * bufsz);
  5210. v->shmem_info.sh_buf.buf[cnt].phys = phys + (cnt * bufsz);
  5211. v->shmem_info.sh_buf.buf[cnt].size = bufsz;
  5212. cnt++;
  5213. }
  5214. pr_debug("%s buf[0].data:[%p], buf[0].phys:[%p], &buf[0].phys:[%p],\n",
  5215. __func__,
  5216. (void *)v->shmem_info.sh_buf.buf[0].data,
  5217. (void *)v->shmem_info.sh_buf.buf[0].phys,
  5218. (void *)&v->shmem_info.sh_buf.buf[0].phys);
  5219. pr_debug("%s: buf[1].data:[%p], buf[1].phys[%p], &buf[1].phys[%p]\n",
  5220. __func__,
  5221. (void *)v->shmem_info.sh_buf.buf[1].data,
  5222. (void *)v->shmem_info.sh_buf.buf[1].phys,
  5223. (void *)&v->shmem_info.sh_buf.buf[1].phys);
  5224. memset((void *)v->shmem_info.sh_buf.buf[0].data, 0, (bufsz * bufcnt));
  5225. done:
  5226. mutex_unlock(&common.common_lock);
  5227. return rc;
  5228. }
  5229. static int voice_alloc_oob_mem_table(void)
  5230. {
  5231. int rc = 0;
  5232. int len;
  5233. struct voice_data *v = voice_get_session(
  5234. common.voice[VOC_PATH_FULL].session_id);
  5235. mutex_lock(&common.common_lock);
  5236. if (v == NULL) {
  5237. pr_err("%s: v is NULL\n", __func__);
  5238. rc = -EINVAL;
  5239. goto done;
  5240. }
  5241. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.memtbl.client),
  5242. &(v->shmem_info.memtbl.handle),
  5243. sizeof(struct vss_imemory_table_t),
  5244. (ion_phys_addr_t *)&v->shmem_info.memtbl.phys,
  5245. (size_t *)&len,
  5246. &(v->shmem_info.memtbl.data));
  5247. if (rc < 0) {
  5248. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5249. __func__, rc);
  5250. goto done;
  5251. }
  5252. v->shmem_info.memtbl.size = sizeof(struct vss_imemory_table_t);
  5253. pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
  5254. (void *)v->shmem_info.memtbl.data,
  5255. (void *)v->shmem_info.memtbl.phys,
  5256. (void *)&v->shmem_info.memtbl.phys);
  5257. done:
  5258. mutex_unlock(&common.common_lock);
  5259. return rc;
  5260. }
  5261. static int voice_alloc_cal_mem_map_table(void)
  5262. {
  5263. int ret = 0;
  5264. int len;
  5265. ret = msm_audio_ion_alloc("voc_cal",
  5266. &(common.cal_mem_map_table.client),
  5267. &(common.cal_mem_map_table.handle),
  5268. sizeof(struct vss_imemory_table_t),
  5269. (ion_phys_addr_t *)&common.cal_mem_map_table.phys,
  5270. (size_t *) &len,
  5271. &(common.cal_mem_map_table.data));
  5272. if (ret < 0) {
  5273. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5274. __func__, ret);
  5275. goto done;
  5276. }
  5277. common.cal_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  5278. pr_debug("%s: data 0x%x phys 0x%x\n", __func__,
  5279. (unsigned int) common.cal_mem_map_table.data,
  5280. common.cal_mem_map_table.phys);
  5281. done:
  5282. return ret;
  5283. }
  5284. static int voice_alloc_rtac_mem_map_table(void)
  5285. {
  5286. int ret = 0;
  5287. int len;
  5288. ret = msm_audio_ion_alloc("voc_rtac_cal",
  5289. &(common.rtac_mem_map_table.client),
  5290. &(common.rtac_mem_map_table.handle),
  5291. sizeof(struct vss_imemory_table_t),
  5292. (ion_phys_addr_t *)&common.rtac_mem_map_table.phys,
  5293. (size_t *) &len,
  5294. &(common.rtac_mem_map_table.data));
  5295. if (ret < 0) {
  5296. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5297. __func__, ret);
  5298. goto done;
  5299. }
  5300. common.rtac_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  5301. pr_debug("%s: data 0x%x phys 0x%x\n", __func__,
  5302. (unsigned int) common.rtac_mem_map_table.data,
  5303. common.rtac_mem_map_table.phys);
  5304. done:
  5305. return ret;
  5306. }
  5307. static int voice_alloc_and_map_cal_mem(struct voice_data *v)
  5308. {
  5309. int ret = 0;
  5310. if (v == NULL) {
  5311. pr_err("%s: v is NULL\n", __func__);
  5312. return -EINVAL;
  5313. }
  5314. ret = voc_alloc_cal_shared_memory();
  5315. if (ret < 0) {
  5316. pr_err("%s: Memory allocation of cal block failed %d\n",
  5317. __func__, ret);
  5318. goto done;
  5319. }
  5320. /* Memory map the calibration memory block. */
  5321. ret = voice_mem_map_cal_block(v);
  5322. if (ret < 0) {
  5323. pr_err("%s: Memory map of cal block failed %d\n",
  5324. __func__, ret);
  5325. }
  5326. done:
  5327. return ret;
  5328. }
  5329. static int voice_alloc_and_map_oob_mem(struct voice_data *v)
  5330. {
  5331. int ret = 0;
  5332. if (v == NULL) {
  5333. pr_err("%s: v is NULL\n", __func__);
  5334. return -EINVAL;
  5335. }
  5336. if (!is_voip_memory_allocated()) {
  5337. ret = voc_alloc_voip_shared_memory();
  5338. if (ret < 0) {
  5339. pr_err("%s: Failed to create voip oob memory %d\n",
  5340. __func__, ret);
  5341. goto done;
  5342. }
  5343. }
  5344. ret = voice_map_memory_physical_cmd(v,
  5345. &v->shmem_info.memtbl,
  5346. v->shmem_info.sh_buf.buf[0].phys,
  5347. v->shmem_info.sh_buf.buf[0].size * NUM_OF_BUFFERS,
  5348. VOIP_MEM_MAP_TOKEN);
  5349. if (ret) {
  5350. pr_err("%s: mvm_map_memory_phy failed %d\n",
  5351. __func__, ret);
  5352. goto done;
  5353. }
  5354. done:
  5355. return ret;
  5356. }
  5357. int is_voc_initialized(void)
  5358. {
  5359. return module_initialized;
  5360. }
  5361. static int __init voice_init(void)
  5362. {
  5363. int rc = 0, i = 0;
  5364. memset(&common, 0, sizeof(struct common_data));
  5365. /* set default value */
  5366. common.default_mute_val = 0; /* default is un-mute */
  5367. common.default_sample_val = 8000;
  5368. common.default_vol_step_val = 0;
  5369. common.default_vol_ramp_duration_ms = DEFAULT_VOLUME_RAMP_DURATION;
  5370. common.default_mute_ramp_duration_ms = DEFAULT_MUTE_RAMP_DURATION;
  5371. common.ec_ref_ext = false;
  5372. /* Initialize MVS info. */
  5373. common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
  5374. mutex_init(&common.common_lock);
  5375. /* Initialize session id with vsid */
  5376. init_session_id();
  5377. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  5378. /* initialize dev_rx and dev_tx */
  5379. common.voice[i].dev_rx.dev_mute = common.default_mute_val;
  5380. common.voice[i].dev_tx.dev_mute = common.default_mute_val;
  5381. common.voice[i].dev_rx.volume_step_value =
  5382. common.default_vol_step_val;
  5383. common.voice[i].dev_rx.volume_ramp_duration_ms =
  5384. common.default_vol_ramp_duration_ms;
  5385. common.voice[i].dev_rx.dev_mute_ramp_duration_ms =
  5386. common.default_mute_ramp_duration_ms;
  5387. common.voice[i].dev_tx.dev_mute_ramp_duration_ms =
  5388. common.default_mute_ramp_duration_ms;
  5389. common.voice[i].stream_rx.stream_mute = common.default_mute_val;
  5390. common.voice[i].stream_tx.stream_mute = common.default_mute_val;
  5391. common.voice[i].dev_tx.port_id = 0x100B;
  5392. common.voice[i].dev_rx.port_id = 0x100A;
  5393. common.voice[i].sidetone_gain = 0x512;
  5394. common.voice[i].dtmf_rx_detect_en = 0;
  5395. common.voice[i].lch_mode = 0;
  5396. common.voice[i].voc_state = VOC_INIT;
  5397. init_waitqueue_head(&common.voice[i].mvm_wait);
  5398. init_waitqueue_head(&common.voice[i].cvs_wait);
  5399. init_waitqueue_head(&common.voice[i].cvp_wait);
  5400. mutex_init(&common.voice[i].lock);
  5401. }
  5402. if (rc == 0)
  5403. module_initialized = true;
  5404. pr_debug("%s: rc=%d\n", __func__, rc);
  5405. return rc;
  5406. }
  5407. device_initcall(voice_init);