q6voice.c 232 KB

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