q6voice.c 255 KB

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