q6voice.c 247 KB

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