q6voice.c 259 KB

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