q6voice.c 228 KB

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