q6voice.c 235 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191
  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. voice_set_topology_specific_info(v, CVP_VOC_RX_TOPOLOGY_CAL);
  2032. voice_set_topology_specific_info(v, CVP_VOC_TX_TOPOLOGY_CAL);
  2033. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id = v->dev_tx.port_id;
  2034. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id = v->dev_rx.port_id;
  2035. if (common.ec_ref_ext) {
  2036. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  2037. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2038. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  2039. common.ec_media_fmt_info.port_id;
  2040. } else {
  2041. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  2042. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2043. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  2044. VSS_IVOCPROC_PORT_ID_NONE;
  2045. }
  2046. pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
  2047. cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  2048. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id,
  2049. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id);
  2050. v->cvp_state = CMD_STATUS_FAIL;
  2051. v->async_err = 0;
  2052. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
  2053. if (ret < 0) {
  2054. pr_err("Fail in sending VSS_IVOCPROC_CMD_SET_DEVICE\n");
  2055. goto fail;
  2056. }
  2057. ret = wait_event_timeout(v->cvp_wait,
  2058. (v->cvp_state == CMD_STATUS_SUCCESS),
  2059. msecs_to_jiffies(TIMEOUT_MS));
  2060. if (!ret) {
  2061. pr_err("%s: wait_event timeout\n", __func__);
  2062. goto fail;
  2063. }
  2064. if (v->async_err > 0) {
  2065. pr_err("%s: DSP returned error[%s]\n",
  2066. __func__, adsp_err_get_err_str(
  2067. v->async_err));
  2068. ret = adsp_err_get_lnx_err_code(
  2069. v->async_err);
  2070. goto fail;
  2071. }
  2072. return 0;
  2073. fail:
  2074. return ret;
  2075. }
  2076. static int voice_send_stop_voice_cmd(struct voice_data *v)
  2077. {
  2078. struct apr_hdr mvm_stop_voice_cmd;
  2079. int ret = 0;
  2080. void *apr_mvm;
  2081. u16 mvm_handle;
  2082. if (v == NULL) {
  2083. pr_err("%s: v is NULL\n", __func__);
  2084. return -EINVAL;
  2085. }
  2086. apr_mvm = common.apr_q6_mvm;
  2087. if (!apr_mvm) {
  2088. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2089. return -EINVAL;
  2090. }
  2091. mvm_handle = voice_get_mvm_handle(v);
  2092. mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2093. APR_HDR_LEN(APR_HDR_SIZE),
  2094. APR_PKT_VER);
  2095. mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2096. sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
  2097. pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
  2098. mvm_stop_voice_cmd.pkt_size);
  2099. mvm_stop_voice_cmd.src_port =
  2100. voice_get_idx_for_session(v->session_id);
  2101. mvm_stop_voice_cmd.dest_port = mvm_handle;
  2102. mvm_stop_voice_cmd.token = 0;
  2103. mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
  2104. v->mvm_state = CMD_STATUS_FAIL;
  2105. v->async_err = 0;
  2106. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
  2107. if (ret < 0) {
  2108. pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
  2109. goto fail;
  2110. }
  2111. ret = wait_event_timeout(v->mvm_wait,
  2112. (v->mvm_state == CMD_STATUS_SUCCESS),
  2113. msecs_to_jiffies(TIMEOUT_MS));
  2114. if (!ret) {
  2115. pr_err("%s: wait_event timeout\n", __func__);
  2116. goto fail;
  2117. }
  2118. if (v->async_err > 0) {
  2119. pr_err("%s: DSP returned error[%s]\n",
  2120. __func__, adsp_err_get_err_str(
  2121. v->async_err));
  2122. ret = adsp_err_get_lnx_err_code(
  2123. v->async_err);
  2124. goto fail;
  2125. }
  2126. return 0;
  2127. fail:
  2128. return ret;
  2129. }
  2130. static int voice_get_cal(struct cal_block_data **cal_block,
  2131. int cal_block_idx,
  2132. struct cal_block_data **col_data,
  2133. int col_data_idx, int session_id)
  2134. {
  2135. int ret = 0;
  2136. *cal_block = cal_utils_get_only_cal_block(
  2137. common.cal_data[cal_block_idx]);
  2138. if (*cal_block == NULL) {
  2139. pr_err("%s: No cal data for cal %d!\n",
  2140. __func__, cal_block_idx);
  2141. ret = -ENODEV;
  2142. goto done;
  2143. }
  2144. ret = remap_cal_data(*cal_block, session_id);
  2145. if (ret < 0) {
  2146. pr_err("%s: Remap_cal_data failed for cal %d!\n",
  2147. __func__, cal_block_idx);
  2148. ret = -ENODEV;
  2149. goto done;
  2150. }
  2151. if (col_data == NULL)
  2152. goto done;
  2153. *col_data = cal_utils_get_only_cal_block(
  2154. common.cal_data[col_data_idx]);
  2155. if (*col_data == NULL) {
  2156. pr_err("%s: No cal data for cal %d!\n",
  2157. __func__, col_data_idx);
  2158. ret = -ENODEV;
  2159. goto done;
  2160. }
  2161. done:
  2162. return ret;
  2163. }
  2164. static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
  2165. {
  2166. struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
  2167. struct cal_block_data *cal_block = NULL;
  2168. struct cal_block_data *col_data = NULL;
  2169. int ret = 0;
  2170. memset(&cvs_reg_cal_cmd, 0, sizeof(cvs_reg_cal_cmd));
  2171. if (v == NULL) {
  2172. pr_err("%s: v is NULL\n", __func__);
  2173. ret = -EINVAL;
  2174. goto done;
  2175. }
  2176. if (!common.apr_q6_cvs) {
  2177. pr_err("%s: apr_cvs is NULL\n", __func__);
  2178. ret = -EINVAL;
  2179. goto done;
  2180. }
  2181. mutex_lock(&common.cal_data[CVS_VOCSTRM_CAL]->lock);
  2182. mutex_lock(&common.cal_data[CVS_VOCSTRM_COL_CAL]->lock);
  2183. ret = voice_get_cal(&cal_block, CVS_VOCSTRM_CAL, &col_data,
  2184. CVS_VOCSTRM_COL_CAL, v->session_id);
  2185. if (ret < 0) {
  2186. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2187. __func__, CVS_VOCSTRM_CAL);
  2188. goto unlock;
  2189. }
  2190. memcpy(&cvs_reg_cal_cmd.cvs_cal_data.column_info[0],
  2191. (void *) &((struct audio_cal_info_voc_col *)
  2192. col_data->cal_info)->data,
  2193. col_data->cal_data.size);
  2194. cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2195. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2196. cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2197. sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
  2198. cvs_reg_cal_cmd.hdr.src_port =
  2199. voice_get_idx_for_session(v->session_id);
  2200. cvs_reg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  2201. cvs_reg_cal_cmd.hdr.token = 0;
  2202. if (common.is_per_vocoder_cal_enabled)
  2203. cvs_reg_cal_cmd.hdr.opcode =
  2204. VSS_ISTREAM_CMD_REGISTER_STATIC_CALIBRATION_DATA;
  2205. else
  2206. cvs_reg_cal_cmd.hdr.opcode =
  2207. VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2;
  2208. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_handle =
  2209. cal_block->map_data.q6map_handle;
  2210. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address_lsw =
  2211. lower_32_bits(cal_block->cal_data.paddr);
  2212. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address_msw =
  2213. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2214. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_size =
  2215. cal_block->cal_data.size;
  2216. v->cvs_state = CMD_STATUS_FAIL;
  2217. v->async_err = 0;
  2218. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_reg_cal_cmd);
  2219. if (ret < 0) {
  2220. pr_err("%s: Error %d registering CVS cal\n", __func__, ret);
  2221. ret = -EINVAL;
  2222. goto unlock;
  2223. }
  2224. ret = wait_event_timeout(v->cvs_wait,
  2225. (v->cvs_state == CMD_STATUS_SUCCESS),
  2226. msecs_to_jiffies(TIMEOUT_MS));
  2227. if (!ret) {
  2228. pr_err("%s: Command timeout\n", __func__);
  2229. ret = -EINVAL;
  2230. goto unlock;
  2231. }
  2232. if (v->async_err > 0) {
  2233. pr_err("%s: DSP returned error[%s]\n",
  2234. __func__, adsp_err_get_err_str(
  2235. v->async_err));
  2236. ret = adsp_err_get_lnx_err_code(
  2237. v->async_err);
  2238. goto unlock;
  2239. }
  2240. unlock:
  2241. mutex_unlock(&common.cal_data[CVS_VOCSTRM_COL_CAL]->lock);
  2242. mutex_unlock(&common.cal_data[CVS_VOCSTRM_CAL]->lock);
  2243. done:
  2244. return ret;
  2245. }
  2246. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
  2247. {
  2248. struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
  2249. int ret = 0;
  2250. memset(&cvs_dereg_cal_cmd, 0, sizeof(cvs_dereg_cal_cmd));
  2251. if (v == NULL) {
  2252. pr_err("%s: v is NULL\n", __func__);
  2253. ret = -EINVAL;
  2254. goto done;
  2255. }
  2256. if (!common.apr_q6_cvs) {
  2257. pr_err("%s: apr_cvs is NULL\n", __func__);
  2258. ret = -EPERM;
  2259. goto done;
  2260. }
  2261. cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2262. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2263. cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2264. sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
  2265. cvs_dereg_cal_cmd.hdr.src_port =
  2266. voice_get_idx_for_session(v->session_id);
  2267. cvs_dereg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  2268. cvs_dereg_cal_cmd.hdr.token = 0;
  2269. if (common.is_per_vocoder_cal_enabled)
  2270. cvs_dereg_cal_cmd.hdr.opcode =
  2271. VSS_ISTREAM_CMD_DEREGISTER_STATIC_CALIBRATION_DATA;
  2272. else
  2273. cvs_dereg_cal_cmd.hdr.opcode =
  2274. VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
  2275. v->cvs_state = CMD_STATUS_FAIL;
  2276. v->async_err = 0;
  2277. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
  2278. if (ret < 0) {
  2279. pr_err("%s: Error %d de-registering CVS cal\n", __func__, ret);
  2280. goto done;
  2281. }
  2282. ret = wait_event_timeout(v->cvs_wait,
  2283. (v->cvs_state == CMD_STATUS_SUCCESS),
  2284. msecs_to_jiffies(TIMEOUT_MS));
  2285. if (!ret) {
  2286. pr_err("%s: Command timeout\n", __func__);
  2287. goto done;
  2288. }
  2289. if (v->async_err > 0) {
  2290. pr_err("%s: DSP returned error[%s]\n",
  2291. __func__, adsp_err_get_err_str(
  2292. v->async_err));
  2293. ret = adsp_err_get_lnx_err_code(
  2294. v->async_err);
  2295. goto done;
  2296. }
  2297. done:
  2298. return ret;
  2299. }
  2300. static int voice_send_cvp_create_cmd(struct voice_data *v)
  2301. {
  2302. struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
  2303. void *apr_cvp;
  2304. int ret = 0;
  2305. if (v == NULL) {
  2306. pr_err("%s: v is NULL\n", __func__);
  2307. ret = -EINVAL;
  2308. goto done;
  2309. }
  2310. apr_cvp = common.apr_q6_cvp;
  2311. if (!apr_cvp) {
  2312. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2313. ret = -EINVAL;
  2314. goto done;
  2315. }
  2316. /* create cvp session and wait for response */
  2317. cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2318. APR_HDR_LEN(APR_HDR_SIZE),
  2319. APR_PKT_VER);
  2320. cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2321. sizeof(cvp_session_cmd) - APR_HDR_SIZE);
  2322. pr_debug("%s: send create cvp session, pkt size = %d\n",
  2323. __func__, cvp_session_cmd.hdr.pkt_size);
  2324. cvp_session_cmd.hdr.src_port =
  2325. voice_get_idx_for_session(v->session_id);
  2326. cvp_session_cmd.hdr.dest_port = 0;
  2327. cvp_session_cmd.hdr.token = 0;
  2328. if (voice_get_cvd_int_version(common.cvd_version) >=
  2329. CVD_INT_VERSION_2_2)
  2330. cvp_session_cmd.hdr.opcode =
  2331. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V3;
  2332. else
  2333. cvp_session_cmd.hdr.opcode =
  2334. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2;
  2335. voc_get_tx_rx_topology(v,
  2336. &cvp_session_cmd.cvp_session.tx_topology_id,
  2337. &cvp_session_cmd.cvp_session.rx_topology_id);
  2338. voice_set_topology_specific_info(v, CVP_VOC_RX_TOPOLOGY_CAL);
  2339. voice_set_topology_specific_info(v, CVP_VOC_TX_TOPOLOGY_CAL);
  2340. cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
  2341. cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
  2342. cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
  2343. cvp_session_cmd.cvp_session.profile_id =
  2344. VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2345. if (common.ec_ref_ext) {
  2346. cvp_session_cmd.cvp_session.vocproc_mode =
  2347. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2348. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2349. common.ec_media_fmt_info.port_id;
  2350. } else {
  2351. cvp_session_cmd.cvp_session.vocproc_mode =
  2352. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2353. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2354. VSS_IVOCPROC_PORT_ID_NONE;
  2355. }
  2356. pr_debug("tx_topology: %d tx_port_id=%d, rx_port_id=%d, mode: 0x%x\n",
  2357. cvp_session_cmd.cvp_session.tx_topology_id,
  2358. cvp_session_cmd.cvp_session.tx_port_id,
  2359. cvp_session_cmd.cvp_session.rx_port_id,
  2360. cvp_session_cmd.cvp_session.vocproc_mode);
  2361. pr_debug("rx_topology: %d, profile_id: 0x%x, pkt_size: %d\n",
  2362. cvp_session_cmd.cvp_session.rx_topology_id,
  2363. cvp_session_cmd.cvp_session.profile_id,
  2364. cvp_session_cmd.hdr.pkt_size);
  2365. v->cvp_state = CMD_STATUS_FAIL;
  2366. v->async_err = 0;
  2367. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
  2368. if (ret < 0) {
  2369. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  2370. ret = -EINVAL;
  2371. goto done;
  2372. }
  2373. ret = wait_event_timeout(v->cvp_wait,
  2374. (v->cvp_state == CMD_STATUS_SUCCESS),
  2375. msecs_to_jiffies(TIMEOUT_MS));
  2376. if (!ret) {
  2377. pr_err("%s: wait_event timeout\n", __func__);
  2378. ret = -EINVAL;
  2379. goto done;
  2380. }
  2381. if (v->async_err > 0) {
  2382. pr_err("%s: DSP returned error[%s]\n",
  2383. __func__, adsp_err_get_err_str(
  2384. v->async_err));
  2385. ret = adsp_err_get_lnx_err_code(
  2386. v->async_err);
  2387. goto done;
  2388. }
  2389. done:
  2390. return ret;
  2391. }
  2392. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v)
  2393. {
  2394. struct cvp_register_dev_cfg_cmd cvp_reg_dev_cfg_cmd;
  2395. struct cal_block_data *cal_block = NULL;
  2396. int ret = 0;
  2397. memset(&cvp_reg_dev_cfg_cmd, 0, sizeof(cvp_reg_dev_cfg_cmd));
  2398. if (v == NULL) {
  2399. pr_err("%s: v is NULL\n", __func__);
  2400. ret = -EINVAL;
  2401. goto done;
  2402. }
  2403. if (!common.apr_q6_cvp) {
  2404. pr_err("%s: apr_cvp is NULL\n", __func__);
  2405. ret = -EPERM;
  2406. goto done;
  2407. }
  2408. mutex_lock(&common.cal_data[CVP_VOCDEV_CFG_CAL]->lock);
  2409. ret = voice_get_cal(&cal_block, CVP_VOCDEV_CFG_CAL, NULL,
  2410. 0, v->session_id);
  2411. if (ret < 0) {
  2412. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2413. __func__, CVP_VOCDEV_CFG_CAL);
  2414. goto unlock;
  2415. }
  2416. cvp_reg_dev_cfg_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2417. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2418. cvp_reg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2419. sizeof(cvp_reg_dev_cfg_cmd) - APR_HDR_SIZE);
  2420. cvp_reg_dev_cfg_cmd.hdr.src_port =
  2421. voice_get_idx_for_session(v->session_id);
  2422. cvp_reg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2423. cvp_reg_dev_cfg_cmd.hdr.token = 0;
  2424. cvp_reg_dev_cfg_cmd.hdr.opcode =
  2425. VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG;
  2426. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_handle =
  2427. cal_block->map_data.q6map_handle;
  2428. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address_lsw =
  2429. lower_32_bits(cal_block->cal_data.paddr);
  2430. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address_msw =
  2431. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2432. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_size =
  2433. cal_block->cal_data.size;
  2434. v->cvp_state = CMD_STATUS_FAIL;
  2435. v->async_err = 0;
  2436. ret = apr_send_pkt(common.apr_q6_cvp,
  2437. (uint32_t *) &cvp_reg_dev_cfg_cmd);
  2438. if (ret < 0) {
  2439. pr_err("%s: Error %d registering CVP dev cfg cal\n",
  2440. __func__, ret);
  2441. ret = -EINVAL;
  2442. goto unlock;
  2443. }
  2444. ret = wait_event_timeout(v->cvp_wait,
  2445. (v->cvp_state == CMD_STATUS_SUCCESS),
  2446. msecs_to_jiffies(TIMEOUT_MS));
  2447. if (!ret) {
  2448. pr_err("%s: Command timeout\n", __func__);
  2449. ret = -EINVAL;
  2450. goto unlock;
  2451. }
  2452. if (v->async_err > 0) {
  2453. pr_err("%s: DSP returned error[%s]\n",
  2454. __func__, adsp_err_get_err_str(
  2455. v->async_err));
  2456. ret = adsp_err_get_lnx_err_code(
  2457. v->async_err);
  2458. goto unlock;
  2459. }
  2460. unlock:
  2461. mutex_unlock(&common.cal_data[CVP_VOCDEV_CFG_CAL]->lock);
  2462. done:
  2463. return ret;
  2464. }
  2465. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v)
  2466. {
  2467. struct cvp_deregister_dev_cfg_cmd cvp_dereg_dev_cfg_cmd;
  2468. int ret = 0;
  2469. memset(&cvp_dereg_dev_cfg_cmd, 0, sizeof(cvp_dereg_dev_cfg_cmd));
  2470. if (v == NULL) {
  2471. pr_err("%s: v is NULL\n", __func__);
  2472. ret = -EINVAL;
  2473. goto done;
  2474. }
  2475. if (!common.apr_q6_cvp) {
  2476. pr_err("%s: apr_cvp is NULL\n", __func__);
  2477. ret = -EPERM;
  2478. goto done;
  2479. }
  2480. cvp_dereg_dev_cfg_cmd.hdr.hdr_field =
  2481. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2482. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2483. cvp_dereg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2484. sizeof(cvp_dereg_dev_cfg_cmd) - APR_HDR_SIZE);
  2485. cvp_dereg_dev_cfg_cmd.hdr.src_port =
  2486. voice_get_idx_for_session(v->session_id);
  2487. cvp_dereg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2488. cvp_dereg_dev_cfg_cmd.hdr.token = 0;
  2489. cvp_dereg_dev_cfg_cmd.hdr.opcode =
  2490. VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG;
  2491. v->cvp_state = CMD_STATUS_FAIL;
  2492. v->async_err = 0;
  2493. ret = apr_send_pkt(common.apr_q6_cvp,
  2494. (uint32_t *) &cvp_dereg_dev_cfg_cmd);
  2495. if (ret < 0) {
  2496. pr_err("%s: Error %d de-registering CVP dev cfg cal\n",
  2497. __func__, ret);
  2498. goto done;
  2499. }
  2500. ret = wait_event_timeout(v->cvp_wait,
  2501. (v->cvp_state == CMD_STATUS_SUCCESS),
  2502. msecs_to_jiffies(TIMEOUT_MS));
  2503. if (!ret) {
  2504. pr_err("%s: Command timeout\n", __func__);
  2505. goto done;
  2506. }
  2507. if (v->async_err > 0) {
  2508. pr_err("%s: DSP returned error[%s]\n",
  2509. __func__, adsp_err_get_err_str(
  2510. v->async_err));
  2511. ret = adsp_err_get_lnx_err_code(
  2512. v->async_err);
  2513. goto done;
  2514. }
  2515. done:
  2516. return ret;
  2517. }
  2518. static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
  2519. {
  2520. struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
  2521. struct cal_block_data *cal_block = NULL;
  2522. struct cal_block_data *col_data = NULL;
  2523. int ret = 0;
  2524. memset(&cvp_reg_cal_cmd, 0, sizeof(cvp_reg_cal_cmd));
  2525. if (v == NULL) {
  2526. pr_err("%s: v is NULL\n", __func__);
  2527. ret = -EINVAL;
  2528. goto done;
  2529. }
  2530. if (!common.apr_q6_cvp) {
  2531. pr_err("%s: apr_cvp is NULL\n", __func__);
  2532. ret = -EINVAL;
  2533. goto done;
  2534. }
  2535. mutex_lock(&common.cal_data[CVP_VOCPROC_CAL]->lock);
  2536. mutex_lock(&common.cal_data[CVP_VOCPROC_COL_CAL]->lock);
  2537. ret = voice_get_cal(&cal_block, CVP_VOCPROC_CAL, &col_data,
  2538. CVP_VOCPROC_COL_CAL, v->session_id);
  2539. if (ret < 0) {
  2540. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2541. __func__, CVP_VOCPROC_CAL);
  2542. goto unlock;
  2543. }
  2544. v->dev_tx.dev_id = ((struct audio_cal_info_vocproc *)
  2545. cal_block->cal_info)->tx_acdb_id;
  2546. v->dev_rx.dev_id = ((struct audio_cal_info_vocproc *)
  2547. cal_block->cal_info)->rx_acdb_id;
  2548. pr_debug("%s: %s: Tx acdb id = %d and Rx acdb id = %d", __func__,
  2549. voc_get_session_name(v->session_id), v->dev_tx.dev_id,
  2550. v->dev_rx.dev_id);
  2551. memcpy(&cvp_reg_cal_cmd.cvp_cal_data.column_info[0],
  2552. (void *) &((struct audio_cal_info_voc_col *)
  2553. col_data->cal_info)->data,
  2554. col_data->cal_data.size);
  2555. cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2556. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2557. cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2558. sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
  2559. cvp_reg_cal_cmd.hdr.src_port =
  2560. voice_get_idx_for_session(v->session_id);
  2561. cvp_reg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2562. cvp_reg_cal_cmd.hdr.token = 0;
  2563. if (common.is_per_vocoder_cal_enabled)
  2564. cvp_reg_cal_cmd.hdr.opcode =
  2565. VSS_IVOCPROC_CMD_REGISTER_STATIC_CALIBRATION_DATA;
  2566. else
  2567. cvp_reg_cal_cmd.hdr.opcode =
  2568. VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2;
  2569. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_handle =
  2570. cal_block->map_data.q6map_handle;
  2571. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address_lsw =
  2572. lower_32_bits(cal_block->cal_data.paddr);
  2573. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address_msw =
  2574. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2575. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_size =
  2576. cal_block->cal_data.size;
  2577. v->cvp_state = CMD_STATUS_FAIL;
  2578. v->async_err = 0;
  2579. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_reg_cal_cmd);
  2580. if (ret < 0) {
  2581. pr_err("%s: Error %d registering CVP cal\n", __func__, ret);
  2582. ret = -EINVAL;
  2583. goto unlock;
  2584. }
  2585. ret = wait_event_timeout(v->cvp_wait,
  2586. (v->cvp_state == CMD_STATUS_SUCCESS),
  2587. msecs_to_jiffies(TIMEOUT_MS));
  2588. if (!ret) {
  2589. pr_err("%s: Command timeout\n", __func__);
  2590. ret = -EINVAL;
  2591. goto unlock;
  2592. }
  2593. if (v->async_err > 0) {
  2594. pr_err("%s: DSP returned error[%s]\n",
  2595. __func__, adsp_err_get_err_str(
  2596. v->async_err));
  2597. ret = adsp_err_get_lnx_err_code(
  2598. v->async_err);
  2599. goto unlock;
  2600. }
  2601. unlock:
  2602. mutex_unlock(&common.cal_data[CVP_VOCPROC_COL_CAL]->lock);
  2603. mutex_unlock(&common.cal_data[CVP_VOCPROC_CAL]->lock);
  2604. done:
  2605. return ret;
  2606. }
  2607. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
  2608. {
  2609. struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
  2610. int ret = 0;
  2611. memset(&cvp_dereg_cal_cmd, 0, sizeof(cvp_dereg_cal_cmd));
  2612. if (v == NULL) {
  2613. pr_err("%s: v is NULL\n", __func__);
  2614. ret = -EINVAL;
  2615. goto done;
  2616. }
  2617. if (!common.apr_q6_cvp) {
  2618. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2619. ret = -EPERM;
  2620. goto done;
  2621. }
  2622. cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2623. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2624. cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2625. sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
  2626. cvp_dereg_cal_cmd.hdr.src_port =
  2627. voice_get_idx_for_session(v->session_id);
  2628. cvp_dereg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2629. cvp_dereg_cal_cmd.hdr.token = 0;
  2630. if (common.is_per_vocoder_cal_enabled)
  2631. cvp_dereg_cal_cmd.hdr.opcode =
  2632. VSS_IVOCPROC_CMD_DEREGISTER_STATIC_CALIBRATION_DATA;
  2633. else
  2634. cvp_dereg_cal_cmd.hdr.opcode =
  2635. VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
  2636. v->cvp_state = CMD_STATUS_FAIL;
  2637. v->async_err = 0;
  2638. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
  2639. if (ret < 0) {
  2640. pr_err("%s: Error %d de-registering CVP cal\n", __func__, ret);
  2641. goto done;
  2642. }
  2643. ret = wait_event_timeout(v->cvp_wait,
  2644. (v->cvp_state == CMD_STATUS_SUCCESS),
  2645. msecs_to_jiffies(TIMEOUT_MS));
  2646. if (!ret) {
  2647. pr_err("%s: Command timeout\n", __func__);
  2648. goto done;
  2649. }
  2650. if (v->async_err > 0) {
  2651. pr_err("%s: DSP returned error[%s]\n",
  2652. __func__, adsp_err_get_err_str(
  2653. v->async_err));
  2654. ret = adsp_err_get_lnx_err_code(
  2655. v->async_err);
  2656. goto done;
  2657. }
  2658. done:
  2659. return ret;
  2660. }
  2661. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v)
  2662. {
  2663. struct cvp_register_vol_cal_data_cmd cvp_reg_vol_cal_cmd;
  2664. struct cal_block_data *cal_block = NULL;
  2665. struct cal_block_data *col_data = NULL;
  2666. int ret = 0;
  2667. memset(&cvp_reg_vol_cal_cmd, 0, sizeof(cvp_reg_vol_cal_cmd));
  2668. if (v == NULL) {
  2669. pr_err("%s: v is NULL\n", __func__);
  2670. ret = -EINVAL;
  2671. goto done;
  2672. }
  2673. if (!common.apr_q6_cvp) {
  2674. pr_err("%s: apr_cvp is NULL\n", __func__);
  2675. ret = -EINVAL;
  2676. goto done;
  2677. }
  2678. mutex_lock(&common.cal_data[CVP_VOCVOL_CAL]->lock);
  2679. mutex_lock(&common.cal_data[CVP_VOCVOL_COL_CAL]->lock);
  2680. ret = voice_get_cal(&cal_block, CVP_VOCVOL_CAL, &col_data,
  2681. CVP_VOCVOL_COL_CAL, v->session_id);
  2682. if (ret < 0) {
  2683. pr_err("%s: Voice_get_cal failed for cal %d!\n",
  2684. __func__, CVP_VOCVOL_CAL);
  2685. goto unlock;
  2686. }
  2687. memcpy(&cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info[0],
  2688. (void *) &((struct audio_cal_info_voc_col *)
  2689. col_data->cal_info)->data,
  2690. col_data->cal_data.size);
  2691. cvp_reg_vol_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2692. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2693. cvp_reg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2694. sizeof(cvp_reg_vol_cal_cmd) - APR_HDR_SIZE);
  2695. cvp_reg_vol_cal_cmd.hdr.src_port =
  2696. voice_get_idx_for_session(v->session_id);
  2697. cvp_reg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2698. cvp_reg_vol_cal_cmd.hdr.token = 0;
  2699. if (common.is_per_vocoder_cal_enabled)
  2700. cvp_reg_vol_cal_cmd.hdr.opcode =
  2701. VSS_IVOCPROC_CMD_REGISTER_DYNAMIC_CALIBRATION_DATA;
  2702. else
  2703. cvp_reg_vol_cal_cmd.hdr.opcode =
  2704. VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA;
  2705. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_handle =
  2706. cal_block->map_data.q6map_handle;
  2707. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address_lsw =
  2708. lower_32_bits(cal_block->cal_data.paddr);
  2709. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address_msw =
  2710. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  2711. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_size =
  2712. cal_block->cal_data.size;
  2713. v->cvp_state = CMD_STATUS_FAIL;
  2714. v->async_err = 0;
  2715. ret = apr_send_pkt(common.apr_q6_cvp,
  2716. (uint32_t *) &cvp_reg_vol_cal_cmd);
  2717. if (ret < 0) {
  2718. pr_err("%s: Error %d registering CVP vol cal\n", __func__, ret);
  2719. ret = -EINVAL;
  2720. goto unlock;
  2721. }
  2722. ret = wait_event_timeout(v->cvp_wait,
  2723. (v->cvp_state == CMD_STATUS_SUCCESS),
  2724. msecs_to_jiffies(TIMEOUT_MS));
  2725. if (!ret) {
  2726. pr_err("%s: Command timeout\n", __func__);
  2727. ret = -EINVAL;
  2728. goto unlock;
  2729. }
  2730. if (v->async_err > 0) {
  2731. pr_err("%s: DSP returned error[%s]\n",
  2732. __func__, adsp_err_get_err_str(
  2733. v->async_err));
  2734. ret = adsp_err_get_lnx_err_code(
  2735. v->async_err);
  2736. goto unlock;
  2737. }
  2738. unlock:
  2739. mutex_unlock(&common.cal_data[CVP_VOCVOL_COL_CAL]->lock);
  2740. mutex_unlock(&common.cal_data[CVP_VOCVOL_CAL]->lock);
  2741. done:
  2742. return ret;
  2743. }
  2744. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v)
  2745. {
  2746. struct cvp_deregister_vol_cal_data_cmd cvp_dereg_vol_cal_cmd;
  2747. int ret = 0;
  2748. memset(&cvp_dereg_vol_cal_cmd, 0, sizeof(cvp_dereg_vol_cal_cmd));
  2749. if (v == NULL) {
  2750. pr_err("%s: v is NULL\n", __func__);
  2751. ret = -EINVAL;
  2752. goto done;
  2753. }
  2754. if (!common.apr_q6_cvp) {
  2755. pr_err("%s: apr_cvp is NULL\n", __func__);
  2756. ret = -EPERM;
  2757. goto done;
  2758. }
  2759. cvp_dereg_vol_cal_cmd.hdr.hdr_field =
  2760. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2761. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2762. cvp_dereg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2763. sizeof(cvp_dereg_vol_cal_cmd) - APR_HDR_SIZE);
  2764. cvp_dereg_vol_cal_cmd.hdr.src_port =
  2765. voice_get_idx_for_session(v->session_id);
  2766. cvp_dereg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2767. cvp_dereg_vol_cal_cmd.hdr.token = 0;
  2768. if (common.is_per_vocoder_cal_enabled)
  2769. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2770. VSS_IVOCPROC_CMD_DEREGISTER_DYNAMIC_CALIBRATION_DATA;
  2771. else
  2772. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2773. VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA;
  2774. v->cvp_state = CMD_STATUS_FAIL;
  2775. v->async_err = 0;
  2776. ret = apr_send_pkt(common.apr_q6_cvp,
  2777. (uint32_t *) &cvp_dereg_vol_cal_cmd);
  2778. if (ret < 0) {
  2779. pr_err("%s: Error %d de-registering CVP vol cal\n",
  2780. __func__, ret);
  2781. goto done;
  2782. }
  2783. ret = wait_event_timeout(v->cvp_wait,
  2784. (v->cvp_state == CMD_STATUS_SUCCESS),
  2785. msecs_to_jiffies(TIMEOUT_MS));
  2786. if (!ret) {
  2787. pr_err("%s: Command timeout\n", __func__);
  2788. goto done;
  2789. }
  2790. if (v->async_err > 0) {
  2791. pr_err("%s: DSP returned error[%s]\n",
  2792. __func__, adsp_err_get_err_str(
  2793. v->async_err));
  2794. ret = adsp_err_get_lnx_err_code(
  2795. v->async_err);
  2796. goto done;
  2797. }
  2798. done:
  2799. return ret;
  2800. }
  2801. static int voice_map_memory_physical_cmd(struct voice_data *v,
  2802. struct mem_map_table *table_info,
  2803. dma_addr_t phys,
  2804. uint32_t size,
  2805. uint32_t token)
  2806. {
  2807. struct vss_imemory_cmd_map_physical_t mvm_map_phys_cmd;
  2808. uint32_t *memtable;
  2809. int ret = 0;
  2810. if (v == NULL) {
  2811. pr_err("%s: v is NULL\n", __func__);
  2812. ret = -EINVAL;
  2813. goto fail;
  2814. }
  2815. if (!common.apr_q6_mvm) {
  2816. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2817. ret = -EINVAL;
  2818. goto fail;
  2819. }
  2820. if (!table_info->data) {
  2821. pr_err("%s: memory table is NULL.\n", __func__);
  2822. ret = -EINVAL;
  2823. goto fail;
  2824. }
  2825. memtable = (uint32_t *) table_info->data;
  2826. /*
  2827. * Store next table descriptor's address(64 bit) as NULL as there
  2828. * is only one memory block
  2829. */
  2830. memtable[0] = 0;
  2831. memtable[1] = 0;
  2832. /* Store next table descriptor's size */
  2833. memtable[2] = 0;
  2834. /* Store shared mem adddress (64 bit) */
  2835. memtable[3] = lower_32_bits(phys);
  2836. memtable[4] = msm_audio_populate_upper_32_bits(phys);
  2837. /* Store shared memory size */
  2838. memtable[5] = size;
  2839. mvm_map_phys_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2840. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2841. mvm_map_phys_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2842. sizeof(mvm_map_phys_cmd) - APR_HDR_SIZE);
  2843. mvm_map_phys_cmd.hdr.src_port =
  2844. voice_get_idx_for_session(v->session_id);
  2845. mvm_map_phys_cmd.hdr.dest_port = voice_get_mvm_handle(v);
  2846. mvm_map_phys_cmd.hdr.token = token;
  2847. mvm_map_phys_cmd.hdr.opcode = VSS_IMEMORY_CMD_MAP_PHYSICAL;
  2848. mvm_map_phys_cmd.table_descriptor.mem_address_lsw =
  2849. lower_32_bits(table_info->phys);
  2850. mvm_map_phys_cmd.table_descriptor.mem_address_msw =
  2851. msm_audio_populate_upper_32_bits(table_info->phys);
  2852. mvm_map_phys_cmd.table_descriptor.mem_size =
  2853. sizeof(struct vss_imemory_block_t) +
  2854. sizeof(struct vss_imemory_table_descriptor_t);
  2855. mvm_map_phys_cmd.is_cached = true;
  2856. mvm_map_phys_cmd.cache_line_size = 128;
  2857. mvm_map_phys_cmd.access_mask = 3;
  2858. mvm_map_phys_cmd.page_align = 4096;
  2859. mvm_map_phys_cmd.min_data_width = 8;
  2860. mvm_map_phys_cmd.max_data_width = 64;
  2861. pr_debug("%s: next table desc: add: %lld, size: %d\n",
  2862. __func__, *((uint64_t *) memtable),
  2863. *(((uint32_t *) memtable) + 2));
  2864. pr_debug("%s: phy add of of mem being mapped LSW:0x%x, MSW:0x%x size: %d\n",
  2865. __func__, *(((uint32_t *) memtable) + 3),
  2866. *(((uint32_t *) memtable) + 4), *(((uint32_t *) memtable) + 5));
  2867. v->mvm_state = CMD_STATUS_FAIL;
  2868. v->async_err = 0;
  2869. ret = apr_send_pkt(common.apr_q6_mvm, (uint32_t *) &mvm_map_phys_cmd);
  2870. if (ret < 0) {
  2871. pr_err("%s: Error %d sending mvm map phy cmd\n", __func__, ret);
  2872. goto fail;
  2873. }
  2874. ret = wait_event_timeout(v->mvm_wait,
  2875. (v->mvm_state == CMD_STATUS_SUCCESS),
  2876. msecs_to_jiffies(TIMEOUT_MS));
  2877. if (!ret) {
  2878. pr_err("%s: Command timeout\n", __func__);
  2879. goto fail;
  2880. }
  2881. if (v->async_err > 0) {
  2882. pr_err("%s: DSP returned error[%s]\n",
  2883. __func__, adsp_err_get_err_str(
  2884. v->async_err));
  2885. ret = adsp_err_get_lnx_err_code(
  2886. v->async_err);
  2887. goto fail;
  2888. }
  2889. return 0;
  2890. fail:
  2891. return ret;
  2892. }
  2893. static int voice_pause_voice_call(struct voice_data *v)
  2894. {
  2895. struct apr_hdr mvm_pause_voice_cmd;
  2896. void *apr_mvm;
  2897. int ret = 0;
  2898. pr_debug("%s\n", __func__);
  2899. if (v == NULL) {
  2900. pr_err("%s: Voice data is NULL\n", __func__);
  2901. ret = -EINVAL;
  2902. goto done;
  2903. }
  2904. apr_mvm = common.apr_q6_mvm;
  2905. if (!apr_mvm) {
  2906. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2907. ret = -EINVAL;
  2908. goto done;
  2909. }
  2910. mvm_pause_voice_cmd.hdr_field =
  2911. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2912. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2913. mvm_pause_voice_cmd.pkt_size =
  2914. APR_PKT_SIZE(APR_HDR_SIZE,
  2915. sizeof(mvm_pause_voice_cmd) - APR_HDR_SIZE);
  2916. mvm_pause_voice_cmd.src_port =
  2917. voice_get_idx_for_session(v->session_id);
  2918. mvm_pause_voice_cmd.dest_port = voice_get_mvm_handle(v);
  2919. mvm_pause_voice_cmd.token = 0;
  2920. mvm_pause_voice_cmd.opcode = VSS_IMVM_CMD_PAUSE_VOICE;
  2921. v->mvm_state = CMD_STATUS_FAIL;
  2922. v->async_err = 0;
  2923. pr_debug("%s: send mvm_pause_voice_cmd pkt size = %d\n",
  2924. __func__, mvm_pause_voice_cmd.pkt_size);
  2925. ret = apr_send_pkt(apr_mvm,
  2926. (uint32_t *)&mvm_pause_voice_cmd);
  2927. if (ret < 0) {
  2928. pr_err("Fail in sending VSS_IMVM_CMD_PAUSE_VOICE\n");
  2929. ret = -EINVAL;
  2930. goto done;
  2931. }
  2932. ret = wait_event_timeout(v->mvm_wait,
  2933. (v->mvm_state == CMD_STATUS_SUCCESS),
  2934. msecs_to_jiffies(TIMEOUT_MS));
  2935. if (!ret) {
  2936. pr_err("%s: Command timeout\n", __func__);
  2937. ret = -EINVAL;
  2938. goto done;
  2939. }
  2940. if (v->async_err > 0) {
  2941. pr_err("%s: DSP returned error[%s]\n",
  2942. __func__, adsp_err_get_err_str(
  2943. v->async_err));
  2944. ret = adsp_err_get_lnx_err_code(
  2945. v->async_err);
  2946. goto done;
  2947. }
  2948. done:
  2949. return ret;
  2950. }
  2951. static int voice_map_cal_memory(struct cal_block_data *cal_block,
  2952. uint32_t session_id)
  2953. {
  2954. int result = 0;
  2955. int voc_index;
  2956. struct voice_data *v = NULL;
  2957. pr_debug("%s\n", __func__);
  2958. if (cal_block == NULL) {
  2959. pr_err("%s: Cal block is NULL!\n", __func__);
  2960. result = -EINVAL;
  2961. goto done;
  2962. }
  2963. if (cal_block->cal_data.paddr == 0) {
  2964. pr_debug("%s: No address to map!\n", __func__);
  2965. result = -EINVAL;
  2966. goto done;
  2967. }
  2968. if (cal_block->map_data.map_size == 0) {
  2969. pr_debug("%s: Map size is 0!\n", __func__);
  2970. result = -EINVAL;
  2971. goto done;
  2972. }
  2973. voc_index = voice_get_idx_for_session(session_id);
  2974. if (voc_index < 0) {
  2975. pr_err("%s: Invalid session ID %d\n", __func__, session_id);
  2976. goto done;
  2977. }
  2978. mutex_lock(&common.common_lock);
  2979. v = &common.voice[voc_index];
  2980. result = voice_map_memory_physical_cmd(v,
  2981. &common.cal_mem_map_table,
  2982. (dma_addr_t)cal_block->cal_data.paddr,
  2983. cal_block->map_data.map_size,
  2984. VOC_CAL_MEM_MAP_TOKEN);
  2985. if (result < 0) {
  2986. pr_err("%s: Mmap did not work! addr = 0x%pK, size = %zd\n",
  2987. __func__,
  2988. &cal_block->cal_data.paddr,
  2989. cal_block->map_data.map_size);
  2990. goto done_unlock;
  2991. }
  2992. cal_block->map_data.q6map_handle = common.cal_mem_handle;
  2993. done_unlock:
  2994. mutex_unlock(&common.common_lock);
  2995. done:
  2996. return result;
  2997. }
  2998. static int remap_cal_data(struct cal_block_data *cal_block,
  2999. uint32_t session_id)
  3000. {
  3001. int ret = 0;
  3002. pr_debug("%s\n", __func__);
  3003. if (cal_block->map_data.ion_client == NULL) {
  3004. pr_err("%s: No ION allocation for session_id %d!\n",
  3005. __func__, session_id);
  3006. ret = -EINVAL;
  3007. goto done;
  3008. }
  3009. if ((cal_block->map_data.map_size > 0) &&
  3010. (cal_block->map_data.q6map_handle == 0)) {
  3011. /* cal type not used */
  3012. ret = voice_map_cal_memory(cal_block, session_id);
  3013. if (ret < 0) {
  3014. pr_err("%s: Mmap did not work! size = %zd\n",
  3015. __func__, cal_block->map_data.map_size);
  3016. goto done;
  3017. }
  3018. } else {
  3019. pr_debug("%s: Cal block 0x%pK, size %zd already mapped. Q6 map handle = %d\n",
  3020. __func__, &cal_block->cal_data.paddr,
  3021. cal_block->map_data.map_size,
  3022. cal_block->map_data.q6map_handle);
  3023. }
  3024. done:
  3025. return ret;
  3026. }
  3027. static int voice_unmap_cal_memory(int32_t cal_type,
  3028. struct cal_block_data *cal_block)
  3029. {
  3030. int result = 0;
  3031. int result2 = 0;
  3032. int i;
  3033. struct voice_data *v = NULL;
  3034. pr_debug("%s\n", __func__);
  3035. if (cal_block == NULL) {
  3036. pr_err("%s: Cal block is NULL!\n", __func__);
  3037. result = -EINVAL;
  3038. goto done;
  3039. }
  3040. if (cal_block->map_data.q6map_handle == 0) {
  3041. pr_debug("%s: Q6 handle is not set!\n", __func__);
  3042. result = -EINVAL;
  3043. goto done;
  3044. }
  3045. mutex_lock(&common.common_lock);
  3046. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3047. v = &common.voice[i];
  3048. mutex_lock(&v->lock);
  3049. if (is_voc_state_active(v->voc_state)) {
  3050. result2 = voice_pause_voice_call(v);
  3051. if (result2 < 0) {
  3052. pr_err("%s: Voice_pause_voice_call failed for session 0x%x, err %d!\n",
  3053. __func__, v->session_id, result2);
  3054. result = result2;
  3055. }
  3056. if (cal_type == CVP_VOCPROC_DYNAMIC_CAL_TYPE)
  3057. voice_send_cvp_deregister_vol_cal_cmd(v);
  3058. else if (cal_type == CVP_VOCPROC_STATIC_CAL_TYPE)
  3059. voice_send_cvp_deregister_cal_cmd(v);
  3060. else if (cal_type == CVP_VOCDEV_CFG_CAL_TYPE)
  3061. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3062. else if (cal_type == CVS_VOCSTRM_STATIC_CAL_TYPE)
  3063. voice_send_cvs_deregister_cal_cmd(v);
  3064. else
  3065. pr_err("%s: Invalid cal type %d!\n",
  3066. __func__, cal_type);
  3067. result2 = voice_send_start_voice_cmd(v);
  3068. if (result2) {
  3069. pr_err("%s: Voice_send_start_voice_cmd failed for session 0x%x, err %d!\n",
  3070. __func__, v->session_id, result2);
  3071. result = result2;
  3072. }
  3073. }
  3074. if ((cal_block->map_data.q6map_handle != 0) &&
  3075. (!is_other_session_active(v->session_id))) {
  3076. result2 = voice_send_mvm_unmap_memory_physical_cmd(
  3077. v, cal_block->map_data.q6map_handle);
  3078. if (result2) {
  3079. pr_err("%s: Voice_send_mvm_unmap_memory_physical_cmd failed for session 0x%x, err %d!\n",
  3080. __func__, v->session_id, result2);
  3081. result = result2;
  3082. }
  3083. cal_block->map_data.q6map_handle = 0;
  3084. }
  3085. mutex_unlock(&v->lock);
  3086. }
  3087. mutex_unlock(&common.common_lock);
  3088. done:
  3089. return result;
  3090. }
  3091. int voc_register_vocproc_vol_table(void)
  3092. {
  3093. int result = 0;
  3094. int result2 = 0;
  3095. int i;
  3096. struct voice_data *v = NULL;
  3097. pr_debug("%s\n", __func__);
  3098. mutex_lock(&common.common_lock);
  3099. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3100. v = &common.voice[i];
  3101. mutex_lock(&v->lock);
  3102. if (is_voc_state_active(v->voc_state)) {
  3103. result2 = voice_send_cvp_register_vol_cal_cmd(v);
  3104. if (result2 < 0) {
  3105. pr_err("%s: Failed to register vocvol table for session 0x%x!\n",
  3106. __func__, v->session_id);
  3107. result = result2;
  3108. /* Still try to register other sessions */
  3109. }
  3110. }
  3111. mutex_unlock(&v->lock);
  3112. }
  3113. mutex_unlock(&common.common_lock);
  3114. return result;
  3115. }
  3116. int voc_deregister_vocproc_vol_table(void)
  3117. {
  3118. int result = 0;
  3119. int success = 0;
  3120. int i;
  3121. struct voice_data *v = NULL;
  3122. pr_debug("%s\n", __func__);
  3123. mutex_lock(&common.common_lock);
  3124. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3125. v = &common.voice[i];
  3126. mutex_lock(&v->lock);
  3127. if (is_voc_state_active(v->voc_state)) {
  3128. result = voice_send_cvp_deregister_vol_cal_cmd(v);
  3129. if (result < 0) {
  3130. pr_err("%s: Failed to deregister vocvol table for session 0x%x!\n",
  3131. __func__, v->session_id);
  3132. mutex_unlock(&v->lock);
  3133. mutex_unlock(&common.common_lock);
  3134. if (success) {
  3135. pr_err("%s: Try to re-register all deregistered sessions!\n",
  3136. __func__);
  3137. voc_register_vocproc_vol_table();
  3138. }
  3139. goto done;
  3140. } else {
  3141. success = 1;
  3142. }
  3143. }
  3144. mutex_unlock(&v->lock);
  3145. }
  3146. mutex_unlock(&common.common_lock);
  3147. done:
  3148. return result;
  3149. }
  3150. int voc_map_rtac_block(struct rtac_cal_block_data *cal_block)
  3151. {
  3152. int result = 0;
  3153. struct voice_data *v = NULL;
  3154. pr_debug("%s\n", __func__);
  3155. if (cal_block == NULL) {
  3156. pr_err("%s: cal_block is NULL!\n",
  3157. __func__);
  3158. result = -EINVAL;
  3159. goto done;
  3160. }
  3161. if (cal_block->cal_data.paddr == 0) {
  3162. pr_debug("%s: No address to map!\n",
  3163. __func__);
  3164. result = -EINVAL;
  3165. goto done;
  3166. }
  3167. if (cal_block->map_data.map_size == 0) {
  3168. pr_debug("%s: map size is 0!\n",
  3169. __func__);
  3170. result = -EINVAL;
  3171. goto done;
  3172. }
  3173. mutex_lock(&common.common_lock);
  3174. /* use first session */
  3175. v = &common.voice[0];
  3176. mutex_lock(&v->lock);
  3177. if (!is_rtac_memory_allocated()) {
  3178. result = voice_alloc_rtac_mem_map_table();
  3179. if (result < 0) {
  3180. pr_err("%s: RTAC alloc mem map table did not work! addr = 0x%pK, size = %d\n",
  3181. __func__,
  3182. &cal_block->cal_data.paddr,
  3183. cal_block->map_data.map_size);
  3184. goto done_unlock;
  3185. }
  3186. }
  3187. result = voice_map_memory_physical_cmd(v,
  3188. &common.rtac_mem_map_table,
  3189. (dma_addr_t)cal_block->cal_data.paddr,
  3190. cal_block->map_data.map_size,
  3191. VOC_RTAC_MEM_MAP_TOKEN);
  3192. if (result < 0) {
  3193. pr_err("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
  3194. __func__,
  3195. &cal_block->cal_data.paddr,
  3196. cal_block->map_data.map_size);
  3197. free_rtac_map_table();
  3198. goto done_unlock;
  3199. }
  3200. cal_block->map_data.map_handle = common.rtac_mem_handle;
  3201. done_unlock:
  3202. mutex_unlock(&v->lock);
  3203. mutex_unlock(&common.common_lock);
  3204. done:
  3205. return result;
  3206. }
  3207. int voc_unmap_rtac_block(uint32_t *mem_map_handle)
  3208. {
  3209. int result = 0;
  3210. struct voice_data *v = NULL;
  3211. pr_debug("%s\n", __func__);
  3212. if (mem_map_handle == NULL) {
  3213. pr_debug("%s: Map handle is NULL, nothing to unmap\n",
  3214. __func__);
  3215. goto done;
  3216. }
  3217. if (*mem_map_handle == 0) {
  3218. pr_debug("%s: Map handle is 0, nothing to unmap\n",
  3219. __func__);
  3220. goto done;
  3221. }
  3222. mutex_lock(&common.common_lock);
  3223. /* Use first session */
  3224. /* Only used for apr wait lock */
  3225. v = &common.voice[0];
  3226. mutex_lock(&v->lock);
  3227. result = voice_send_mvm_unmap_memory_physical_cmd(
  3228. v, *mem_map_handle);
  3229. if (result) {
  3230. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd Failed for session 0x%x!\n",
  3231. __func__, v->session_id);
  3232. } else {
  3233. *mem_map_handle = 0;
  3234. common.rtac_mem_handle = 0;
  3235. free_rtac_map_table();
  3236. }
  3237. mutex_unlock(&v->lock);
  3238. mutex_unlock(&common.common_lock);
  3239. done:
  3240. return result;
  3241. }
  3242. static int voice_send_cvp_channel_info_v2(struct voice_data *v,
  3243. uint32_t param_type)
  3244. {
  3245. int ret;
  3246. struct cvp_set_channel_info_cmd_v2 cvp_set_channel_info_cmd;
  3247. void *apr_cvp;
  3248. u16 cvp_handle;
  3249. struct vss_icommon_param_data_channel_info_v2_t
  3250. *channel_info_param_data =
  3251. &cvp_set_channel_info_cmd.
  3252. cvp_set_ch_info_param_v2.param_data;
  3253. struct vss_param_vocproc_dev_channel_info_t *channel_info =
  3254. &channel_info_param_data->channel_info;
  3255. if (v == NULL) {
  3256. pr_err("%s: v is NULL\n", __func__);
  3257. ret = -EINVAL;
  3258. goto done;
  3259. }
  3260. apr_cvp = common.apr_q6_cvp;
  3261. if (!apr_cvp) {
  3262. pr_err("%s: apr_cvp is NULL\n", __func__);
  3263. ret = -EINVAL;
  3264. goto done;
  3265. }
  3266. cvp_handle = voice_get_cvp_handle(v);
  3267. memset(&cvp_set_channel_info_cmd, 0, sizeof(cvp_set_channel_info_cmd));
  3268. cvp_set_channel_info_cmd.hdr.hdr_field =
  3269. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  3270. APR_PKT_VER);
  3271. cvp_set_channel_info_cmd.hdr.pkt_size =
  3272. APR_PKT_SIZE(APR_HDR_SIZE,
  3273. sizeof(cvp_set_channel_info_cmd) - APR_HDR_SIZE);
  3274. cvp_set_channel_info_cmd.hdr.src_svc = 0;
  3275. cvp_set_channel_info_cmd.hdr.src_domain = APR_DOMAIN_APPS;
  3276. cvp_set_channel_info_cmd.hdr.src_port =
  3277. voice_get_idx_for_session(v->session_id);
  3278. cvp_set_channel_info_cmd.hdr.dest_svc = 0;
  3279. cvp_set_channel_info_cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  3280. cvp_set_channel_info_cmd.hdr.dest_port = cvp_handle;
  3281. cvp_set_channel_info_cmd.hdr.token = 0;
  3282. cvp_set_channel_info_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_PARAM_V2;
  3283. cvp_set_channel_info_cmd.cvp_set_ch_info_param_v2.mem_size =
  3284. sizeof(struct vss_icommon_param_data_channel_info_v2_t);
  3285. channel_info_param_data->module_id = VSS_MODULE_CVD_GENERIC;
  3286. channel_info_param_data->param_size =
  3287. sizeof(struct vss_param_vocproc_dev_channel_info_t);
  3288. /* Device specific data */
  3289. switch (param_type) {
  3290. case RX_PATH:
  3291. channel_info_param_data->param_id =
  3292. VSS_PARAM_VOCPROC_RX_CHANNEL_INFO;
  3293. channel_info->num_channels = v->dev_rx.no_of_channels;
  3294. channel_info->bits_per_sample = v->dev_rx.bits_per_sample;
  3295. memcpy(&channel_info->channel_mapping,
  3296. v->dev_rx.channel_mapping,
  3297. VSS_NUM_CHANNELS_MAX * sizeof(uint8_t));
  3298. break;
  3299. case TX_PATH:
  3300. channel_info_param_data->param_id =
  3301. VSS_PARAM_VOCPROC_TX_CHANNEL_INFO;
  3302. channel_info->num_channels = v->dev_tx.no_of_channels;
  3303. channel_info->bits_per_sample = v->dev_tx.bits_per_sample;
  3304. memcpy(&channel_info->channel_mapping,
  3305. v->dev_tx.channel_mapping,
  3306. VSS_NUM_CHANNELS_MAX * sizeof(uint8_t));
  3307. break;
  3308. case EC_REF_PATH:
  3309. channel_info_param_data->param_id =
  3310. VSS_PARAM_VOCPROC_EC_REF_CHANNEL_INFO;
  3311. channel_info->num_channels = v->dev_rx.no_of_channels;
  3312. channel_info->bits_per_sample = v->dev_rx.bits_per_sample;
  3313. memcpy(&channel_info->channel_mapping,
  3314. v->dev_rx.channel_mapping,
  3315. VSS_NUM_CHANNELS_MAX * sizeof(uint8_t));
  3316. break;
  3317. default:
  3318. pr_err("%s: Invalid param type\n",
  3319. __func__);
  3320. ret = -EINVAL;
  3321. goto done;
  3322. }
  3323. v->cvp_state = CMD_STATUS_FAIL;
  3324. v->async_err = 0;
  3325. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_set_channel_info_cmd);
  3326. if (ret < 0) {
  3327. pr_err("%s: Failed to send VSS_ICOMMON_CMD_SET_PARAM_V2\n",
  3328. __func__);
  3329. goto done;
  3330. }
  3331. ret = wait_event_timeout(v->cvp_wait,
  3332. (v->cvp_state == CMD_STATUS_SUCCESS),
  3333. msecs_to_jiffies(TIMEOUT_MS));
  3334. if (!ret) {
  3335. pr_err("%s: wait_event timeout\n", __func__);
  3336. ret = -ETIMEDOUT;
  3337. goto done;
  3338. }
  3339. if (v->async_err > 0) {
  3340. pr_err("%s: DSP returned error[%s] handle = %d\n", __func__,
  3341. adsp_err_get_err_str(v->async_err), cvp_handle);
  3342. ret = adsp_err_get_lnx_err_code(v->async_err);
  3343. goto done;
  3344. }
  3345. ret = 0;
  3346. done:
  3347. return ret;
  3348. }
  3349. static int voice_send_cvp_channel_info_cmd(struct voice_data *v)
  3350. {
  3351. int ret = 0;
  3352. ret = voice_send_cvp_channel_info_v2(v, RX_PATH);
  3353. if (ret < 0) {
  3354. pr_err("%s: Error in sending cvp_channel_info RX: %d\n",
  3355. __func__, ret);
  3356. goto done;
  3357. }
  3358. ret = voice_send_cvp_channel_info_v2(v, TX_PATH);
  3359. if (ret < 0) {
  3360. pr_err("%s: Error in sending cvp_channel_info TX: %d\n",
  3361. __func__, ret);
  3362. goto done;
  3363. }
  3364. ret = voice_send_cvp_channel_info_v2(v, EC_REF_PATH);
  3365. if (ret < 0) {
  3366. pr_err("%s: Error in sending cvp_channel_info EC Ref: %d\n",
  3367. __func__, ret);
  3368. goto done;
  3369. }
  3370. done:
  3371. return ret;
  3372. }
  3373. static int voice_send_cvp_ch_mixer_info_v2(struct voice_data *v)
  3374. {
  3375. int ret;
  3376. struct cvp_set_channel_mixer_info_cmd_v2 cvp_set_ch_mixer_info_cmd;
  3377. void *apr_cvp;
  3378. u16 cvp_handle;
  3379. struct vss_icommon_param_data_ch_mixer_v2_t *cvp_config_param_data =
  3380. &cvp_set_ch_mixer_info_cmd.
  3381. cvp_set_ch_mixer_param_v2.param_data;
  3382. struct vss_param_channel_mixer_info_t *ch_mixer_info =
  3383. &cvp_config_param_data->ch_mixer_info;
  3384. if (v == NULL) {
  3385. pr_err("%s: v is NULL\n", __func__);
  3386. ret = -EINVAL;
  3387. goto done;
  3388. }
  3389. apr_cvp = common.apr_q6_cvp;
  3390. if (!apr_cvp) {
  3391. pr_err("%s: apr_cvp is NULL\n", __func__);
  3392. ret = -EINVAL;
  3393. goto done;
  3394. }
  3395. cvp_handle = voice_get_cvp_handle(v);
  3396. memset(&cvp_set_ch_mixer_info_cmd, 0,
  3397. sizeof(cvp_set_ch_mixer_info_cmd));
  3398. cvp_set_ch_mixer_info_cmd.hdr.hdr_field =
  3399. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3400. APR_HDR_LEN(APR_HDR_SIZE),
  3401. APR_PKT_VER);
  3402. cvp_set_ch_mixer_info_cmd.hdr.pkt_size =
  3403. APR_PKT_SIZE(APR_HDR_SIZE,
  3404. sizeof(cvp_set_ch_mixer_info_cmd) - APR_HDR_SIZE);
  3405. cvp_set_ch_mixer_info_cmd.hdr.src_svc = 0;
  3406. cvp_set_ch_mixer_info_cmd.hdr.src_domain = APR_DOMAIN_APPS;
  3407. cvp_set_ch_mixer_info_cmd.hdr.src_port =
  3408. voice_get_idx_for_session(v->session_id);
  3409. cvp_set_ch_mixer_info_cmd.hdr.dest_svc = 0;
  3410. cvp_set_ch_mixer_info_cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  3411. cvp_set_ch_mixer_info_cmd.hdr.dest_port = cvp_handle;
  3412. cvp_set_ch_mixer_info_cmd.hdr.token = VOC_GENERIC_SET_PARAM_TOKEN;
  3413. cvp_set_ch_mixer_info_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_PARAM_V2;
  3414. cvp_set_ch_mixer_info_cmd.cvp_set_ch_mixer_param_v2.mem_size =
  3415. sizeof(struct vss_icommon_param_data_ch_mixer_v2_t);
  3416. cvp_config_param_data->module_id = AUDPROC_MODULE_ID_MFC;
  3417. cvp_config_param_data->param_id =
  3418. AUDPROC_CHMIXER_PARAM_ID_COEFF;
  3419. cvp_config_param_data->param_size =
  3420. sizeof(struct vss_param_channel_mixer_info_t);
  3421. ch_mixer_info->index = 0;
  3422. ch_mixer_info->num_output_channels = v->dev_rx.no_of_channels;
  3423. /*
  3424. * Configure Rx input to be mono for channel mixer as the DSP
  3425. * configures vocproc input as mono.
  3426. */
  3427. ch_mixer_info->num_input_channels = NUM_CHANNELS_MONO;
  3428. ch_mixer_info->out_channel_map[0] = PCM_CHANNEL_L;
  3429. ch_mixer_info->out_channel_map[1] = PCM_CHANNEL_R;
  3430. ch_mixer_info->in_channel_map[0] = PCM_CHANNEL_L;
  3431. ch_mixer_info->channel_weight_coeff[0][0] = GAIN_Q14_FORMAT(1);
  3432. ch_mixer_info->channel_weight_coeff[1][0] = GAIN_Q14_FORMAT(1);
  3433. ch_mixer_info->reserved = 0;
  3434. v->cvp_state = CMD_STATUS_FAIL;
  3435. v->async_err = 0;
  3436. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_set_ch_mixer_info_cmd);
  3437. if (ret < 0) {
  3438. pr_err("%s: Failed to send VSS_ICOMMON_CMD_SET_PARAM_V2 %d\n",
  3439. __func__, ret);
  3440. goto done;
  3441. }
  3442. ret = wait_event_timeout(v->cvp_wait,
  3443. (v->cvp_state == CMD_STATUS_SUCCESS),
  3444. msecs_to_jiffies(TIMEOUT_MS));
  3445. if (!ret) {
  3446. pr_err("%s: wait_event timeout\n", __func__);
  3447. ret = -ETIMEDOUT;
  3448. goto done;
  3449. }
  3450. if (v->async_err > 0) {
  3451. pr_err("%s: DSP returned error[%s] handle = %d\n", __func__,
  3452. adsp_err_get_err_str(v->async_err), cvp_handle);
  3453. ret = adsp_err_get_lnx_err_code(v->async_err);
  3454. goto done;
  3455. }
  3456. ret = 0;
  3457. done:
  3458. return ret;
  3459. }
  3460. static int voice_send_cvp_mfc_config_v2(struct voice_data *v)
  3461. {
  3462. int ret;
  3463. struct cvp_set_mfc_config_cmd_v2 cvp_set_mfc_config_cmd;
  3464. void *apr_cvp;
  3465. u16 cvp_handle;
  3466. struct vss_icommon_param_data_mfc_config_v2_t *cvp_config_param_data =
  3467. &cvp_set_mfc_config_cmd.cvp_set_mfc_param_v2.param_data;
  3468. struct vss_param_mfc_config_info_t *mfc_config_info =
  3469. &cvp_config_param_data->mfc_config_info;
  3470. if (v == NULL) {
  3471. pr_err("%s: v is NULL\n", __func__);
  3472. ret = -EINVAL;
  3473. goto done;
  3474. }
  3475. apr_cvp = common.apr_q6_cvp;
  3476. if (!apr_cvp) {
  3477. pr_err("%s: apr_cvp is NULL\n", __func__);
  3478. ret = -EINVAL;
  3479. goto done;
  3480. }
  3481. cvp_handle = voice_get_cvp_handle(v);
  3482. memset(&cvp_set_mfc_config_cmd, 0, sizeof(cvp_set_mfc_config_cmd));
  3483. cvp_set_mfc_config_cmd.hdr.hdr_field =
  3484. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  3485. APR_PKT_VER);
  3486. cvp_set_mfc_config_cmd.hdr.pkt_size =
  3487. APR_PKT_SIZE(APR_HDR_SIZE,
  3488. sizeof(cvp_set_mfc_config_cmd) - APR_HDR_SIZE);
  3489. cvp_set_mfc_config_cmd.hdr.src_svc = 0;
  3490. cvp_set_mfc_config_cmd.hdr.src_domain = APR_DOMAIN_APPS;
  3491. cvp_set_mfc_config_cmd.hdr.src_port =
  3492. voice_get_idx_for_session(v->session_id);
  3493. cvp_set_mfc_config_cmd.hdr.dest_svc = 0;
  3494. cvp_set_mfc_config_cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  3495. cvp_set_mfc_config_cmd.hdr.dest_port = cvp_handle;
  3496. cvp_set_mfc_config_cmd.hdr.token = 0;
  3497. cvp_set_mfc_config_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_PARAM_V2;
  3498. cvp_set_mfc_config_cmd.cvp_set_mfc_param_v2.mem_size =
  3499. sizeof(struct vss_icommon_param_data_mfc_config_v2_t);
  3500. cvp_config_param_data->module_id = AUDPROC_MODULE_ID_MFC;
  3501. cvp_config_param_data->param_id =
  3502. AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
  3503. cvp_config_param_data->param_size =
  3504. sizeof(struct vss_param_mfc_config_info_t);
  3505. mfc_config_info->num_channels = v->dev_rx.no_of_channels;
  3506. mfc_config_info->bits_per_sample = 16;
  3507. mfc_config_info->sample_rate = v->dev_rx.sample_rate;
  3508. memcpy(&mfc_config_info->channel_type,
  3509. v->dev_rx.channel_mapping,
  3510. VSS_NUM_CHANNELS_MAX * sizeof(uint8_t));
  3511. v->cvp_state = CMD_STATUS_FAIL;
  3512. v->async_err = 0;
  3513. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_set_mfc_config_cmd);
  3514. if (ret < 0) {
  3515. pr_err("%s: Failed to send VSS_ICOMMON_CMD_SET_PARAM_V2 %d\n",
  3516. __func__, ret);
  3517. goto done;
  3518. }
  3519. ret = wait_event_timeout(v->cvp_wait,
  3520. (v->cvp_state == CMD_STATUS_SUCCESS),
  3521. msecs_to_jiffies(TIMEOUT_MS));
  3522. if (!ret) {
  3523. pr_err("%s: wait_event timeout\n", __func__);
  3524. ret = -ETIMEDOUT;
  3525. goto done;
  3526. }
  3527. if (v->async_err > 0) {
  3528. pr_err("%s: DSP returned error[%s] handle = %d\n", __func__,
  3529. adsp_err_get_err_str(v->async_err), cvp_handle);
  3530. ret = adsp_err_get_lnx_err_code(v->async_err);
  3531. goto done;
  3532. }
  3533. ret = 0;
  3534. done:
  3535. return ret;
  3536. }
  3537. static int voice_send_cvp_mfc_config_cmd(struct voice_data *v)
  3538. {
  3539. int ret = 0;
  3540. if (common.cvp_version >= CVP_VERSION_2) {
  3541. ret = voice_send_cvp_ch_mixer_info_v2(v);
  3542. if (ret < 0)
  3543. pr_warn("%s: Set channel mixer config failed err:%d",
  3544. __func__, ret);
  3545. ret = voice_send_cvp_mfc_config_v2(v);
  3546. if (ret < 0)
  3547. pr_warn("%s: Set MFC config failed err:%d",
  3548. __func__, ret);
  3549. } else {
  3550. pr_warn("%s: CVP Version not supported\n", __func__);
  3551. ret = -EINVAL;
  3552. }
  3553. return ret;
  3554. }
  3555. static int voice_get_avcs_version_per_service(uint32_t service_id)
  3556. {
  3557. int ret = 0;
  3558. size_t ver_size;
  3559. struct avcs_fwk_ver_info *ver_info = NULL;
  3560. if (service_id == AVCS_SERVICE_ID_ALL) {
  3561. pr_err("%s: Invalid service id: %d", __func__,
  3562. AVCS_SERVICE_ID_ALL);
  3563. return -EINVAL;
  3564. }
  3565. ver_size = sizeof(struct avcs_get_fwk_version) +
  3566. sizeof(struct avs_svc_api_info);
  3567. ver_info = kzalloc(ver_size, GFP_KERNEL);
  3568. if (ver_info == NULL)
  3569. return -ENOMEM;
  3570. ret = q6core_get_service_version(service_id, ver_info, ver_size);
  3571. if (ret < 0)
  3572. goto done;
  3573. ret = ver_info->services[0].api_version;
  3574. common.is_avcs_version_queried = true;
  3575. done:
  3576. kfree(ver_info);
  3577. return ret;
  3578. }
  3579. static int voice_setup_vocproc(struct voice_data *v)
  3580. {
  3581. int ret = 0;
  3582. ret = voice_send_cvp_create_cmd(v);
  3583. if (ret < 0) {
  3584. pr_err("%s: CVP create failed err:%d\n", __func__, ret);
  3585. goto fail;
  3586. }
  3587. if (common.is_avcs_version_queried == false)
  3588. common.cvp_version = voice_get_avcs_version_per_service(
  3589. APRV2_IDS_SERVICE_ID_ADSP_CVP_V);
  3590. if (common.cvp_version < 0) {
  3591. pr_err("%s: Invalid CVP version %d\n",
  3592. __func__, common.cvp_version);
  3593. ret = -EINVAL;
  3594. goto fail;
  3595. }
  3596. pr_debug("%s: CVP Version %d\n", __func__, common.cvp_version);
  3597. ret = voice_send_cvp_media_fmt_info_cmd(v);
  3598. if (ret < 0) {
  3599. pr_err("%s: Set media format info failed err:%d\n", __func__,
  3600. ret);
  3601. goto fail;
  3602. }
  3603. ret = voice_send_cvp_topology_commit_cmd(v);
  3604. if (ret < 0) {
  3605. pr_err("%s: Set topology commit failed err:%d\n",
  3606. __func__, ret);
  3607. goto fail;
  3608. }
  3609. /* Send MFC config only when the no of channels are more than 1 */
  3610. if (v->dev_rx.no_of_channels > NUM_CHANNELS_MONO) {
  3611. ret = voice_send_cvp_mfc_config_cmd(v);
  3612. if (ret < 0) {
  3613. pr_warn("%s: Set mfc config failed err:%d\n",
  3614. __func__, ret);
  3615. }
  3616. }
  3617. voice_send_cvs_register_cal_cmd(v);
  3618. voice_send_cvp_register_dev_cfg_cmd(v);
  3619. voice_send_cvp_register_cal_cmd(v);
  3620. voice_send_cvp_register_vol_cal_cmd(v);
  3621. /* enable vocproc */
  3622. ret = voice_send_enable_vocproc_cmd(v);
  3623. if (ret < 0)
  3624. goto fail;
  3625. /* attach vocproc */
  3626. ret = voice_send_attach_vocproc_cmd(v);
  3627. if (ret < 0)
  3628. goto fail;
  3629. /* send tty mode if tty device is used */
  3630. voice_send_tty_mode_cmd(v);
  3631. if (is_voip_session(v->session_id)) {
  3632. ret = voice_send_mvm_cal_network_cmd(v);
  3633. if (ret < 0)
  3634. pr_err("%s: voice_send_mvm_cal_network_cmd: %d\n",
  3635. __func__, ret);
  3636. ret = voice_send_mvm_media_type_cmd(v);
  3637. if (ret < 0)
  3638. pr_err("%s: voice_send_mvm_media_type_cmd: %d\n",
  3639. __func__, ret);
  3640. voice_send_netid_timing_cmd(v);
  3641. }
  3642. if (v->st_enable && !v->tty_mode)
  3643. voice_send_set_pp_enable_cmd(v,
  3644. MODULE_ID_VOICE_MODULE_ST,
  3645. v->st_enable);
  3646. /* Start in-call music delivery if this feature is enabled */
  3647. if (v->music_info.play_enable)
  3648. voice_cvs_start_playback(v);
  3649. /* Start in-call recording if this feature is enabled */
  3650. if (v->rec_info.rec_enable)
  3651. voice_cvs_start_record(v, v->rec_info.rec_mode);
  3652. if (v->dtmf_rx_detect_en)
  3653. voice_send_dtmf_rx_detection_cmd(v, v->dtmf_rx_detect_en);
  3654. if (v->hd_enable)
  3655. voice_send_hd_cmd(v, v->hd_enable);
  3656. rtac_add_voice(voice_get_cvs_handle(v),
  3657. voice_get_cvp_handle(v),
  3658. v->dev_rx.port_id, v->dev_tx.port_id,
  3659. v->dev_rx.dev_id, v->dev_tx.dev_id,
  3660. v->session_id);
  3661. return 0;
  3662. fail:
  3663. return ret;
  3664. }
  3665. static int voice_send_cvp_device_channels_cmd(struct voice_data *v)
  3666. {
  3667. int ret = 0;
  3668. struct cvp_set_dev_channels_cmd cvp_set_dev_channels_cmd;
  3669. void *apr_cvp;
  3670. u16 cvp_handle;
  3671. if (!(voice_get_cvd_int_version(common.cvd_version) >=
  3672. CVD_INT_VERSION_2_2)) {
  3673. pr_debug("%s CVD ver %s doesn't support send_device_channels cmd\n",
  3674. __func__, common.cvd_version);
  3675. goto done;
  3676. }
  3677. if (v == NULL) {
  3678. pr_err("%s: v is NULL\n", __func__);
  3679. ret = -EINVAL;
  3680. goto done;
  3681. }
  3682. apr_cvp = common.apr_q6_cvp;
  3683. if (!apr_cvp) {
  3684. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3685. ret = -EINVAL;
  3686. goto done;
  3687. }
  3688. cvp_handle = voice_get_cvp_handle(v);
  3689. cvp_set_dev_channels_cmd.hdr.hdr_field =
  3690. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3691. APR_HDR_LEN(APR_HDR_SIZE),
  3692. APR_PKT_VER);
  3693. cvp_set_dev_channels_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3694. sizeof(cvp_set_dev_channels_cmd) - APR_HDR_SIZE);
  3695. cvp_set_dev_channels_cmd.hdr.src_port =
  3696. voice_get_idx_for_session(v->session_id);
  3697. cvp_set_dev_channels_cmd.hdr.dest_port = cvp_handle;
  3698. cvp_set_dev_channels_cmd.hdr.token = 0;
  3699. cvp_set_dev_channels_cmd.hdr.opcode =
  3700. VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS;
  3701. cvp_set_dev_channels_cmd.cvp_set_channels.rx_num_channels =
  3702. VSS_NUM_DEV_CHANNELS_1;
  3703. cvp_set_dev_channels_cmd.cvp_set_channels.tx_num_channels =
  3704. v->dev_tx.no_of_channels;
  3705. v->cvp_state = CMD_STATUS_FAIL;
  3706. v->async_err = 0;
  3707. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_set_dev_channels_cmd);
  3708. if (ret < 0) {
  3709. pr_err("%s: Fail in sending VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS\n",
  3710. __func__);
  3711. ret = -EINVAL;
  3712. goto done;
  3713. }
  3714. ret = wait_event_timeout(v->cvp_wait,
  3715. (v->cvp_state == CMD_STATUS_SUCCESS),
  3716. msecs_to_jiffies(TIMEOUT_MS));
  3717. if (!ret) {
  3718. pr_err("%s: wait_event timeout\n", __func__);
  3719. ret = -EINVAL;
  3720. goto done;
  3721. }
  3722. if (v->async_err > 0) {
  3723. pr_err("%s: DSP returned error[%s]\n",
  3724. __func__, adsp_err_get_err_str(
  3725. v->async_err));
  3726. ret = adsp_err_get_lnx_err_code(
  3727. v->async_err);
  3728. goto done;
  3729. }
  3730. done:
  3731. return ret;
  3732. }
  3733. static int voice_send_cvp_media_fmt_info_cmd(struct voice_data *v)
  3734. {
  3735. int ret = 0;
  3736. if (common.cvp_version < CVP_VERSION_2)
  3737. ret = voice_send_cvp_device_channels_cmd(v);
  3738. else
  3739. ret = voice_send_cvp_channel_info_cmd(v);
  3740. if (ret < 0) {
  3741. pr_err("%s: Set channel info failed err: %d\n", __func__,
  3742. ret);
  3743. goto done;
  3744. }
  3745. if (voice_get_cvd_int_version(common.cvd_version) >=
  3746. CVD_INT_VERSION_2_3) {
  3747. ret = voice_send_cvp_media_format_cmd(v, RX_PATH);
  3748. if (ret < 0)
  3749. goto done;
  3750. ret = voice_send_cvp_media_format_cmd(v, TX_PATH);
  3751. if (ret < 0)
  3752. goto done;
  3753. if (common.ec_ref_ext)
  3754. ret = voice_send_cvp_media_format_cmd(v, EC_REF_PATH);
  3755. }
  3756. done:
  3757. return ret;
  3758. }
  3759. static int voice_send_cvp_media_format_cmd(struct voice_data *v,
  3760. uint32_t param_type)
  3761. {
  3762. int ret = 0;
  3763. struct cvp_set_media_format_cmd cvp_set_media_format_cmd;
  3764. void *apr_cvp;
  3765. u16 cvp_handle;
  3766. struct vss_icommon_param_data_t *media_fmt_param_data =
  3767. &cvp_set_media_format_cmd.cvp_set_media_param_v2.param_data;
  3768. struct vss_param_endpoint_media_format_info_t *media_fmt_info =
  3769. &media_fmt_param_data->media_format_info;
  3770. if (v == NULL) {
  3771. pr_err("%s: v is NULL\n", __func__);
  3772. ret = -EINVAL;
  3773. goto done;
  3774. }
  3775. apr_cvp = common.apr_q6_cvp;
  3776. if (!apr_cvp) {
  3777. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3778. ret = -EINVAL;
  3779. goto done;
  3780. }
  3781. cvp_handle = voice_get_cvp_handle(v);
  3782. memset(&cvp_set_media_format_cmd, 0, sizeof(cvp_set_media_format_cmd));
  3783. /* Fill header data */
  3784. cvp_set_media_format_cmd.hdr.hdr_field =
  3785. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  3786. APR_PKT_VER);
  3787. cvp_set_media_format_cmd.hdr.pkt_size =
  3788. APR_PKT_SIZE(APR_HDR_SIZE,
  3789. sizeof(cvp_set_media_format_cmd) - APR_HDR_SIZE);
  3790. cvp_set_media_format_cmd.hdr.src_svc = 0;
  3791. cvp_set_media_format_cmd.hdr.src_domain = APR_DOMAIN_APPS;
  3792. cvp_set_media_format_cmd.hdr.src_port =
  3793. voice_get_idx_for_session(v->session_id);
  3794. cvp_set_media_format_cmd.hdr.dest_svc = 0;
  3795. cvp_set_media_format_cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  3796. cvp_set_media_format_cmd.hdr.dest_port = cvp_handle;
  3797. cvp_set_media_format_cmd.hdr.token = VOC_SET_MEDIA_FORMAT_PARAM_TOKEN;
  3798. cvp_set_media_format_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_PARAM_V2;
  3799. /* Fill param data */
  3800. cvp_set_media_format_cmd.cvp_set_media_param_v2.mem_size =
  3801. sizeof(struct vss_icommon_param_data_t);
  3802. media_fmt_param_data->module_id = VSS_MODULE_CVD_GENERIC;
  3803. media_fmt_param_data->param_size =
  3804. sizeof(struct vss_param_endpoint_media_format_info_t);
  3805. /* Fill device specific data */
  3806. switch (param_type) {
  3807. case RX_PATH:
  3808. media_fmt_param_data->param_id =
  3809. VSS_PARAM_RX_PORT_ENDPOINT_MEDIA_INFO;
  3810. media_fmt_info->port_id = v->dev_rx.port_id;
  3811. media_fmt_info->num_channels = v->dev_rx.no_of_channels;
  3812. media_fmt_info->bits_per_sample = v->dev_rx.bits_per_sample;
  3813. media_fmt_info->sample_rate = v->dev_rx.sample_rate;
  3814. memcpy(&media_fmt_info->channel_mapping,
  3815. &v->dev_rx.channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  3816. break;
  3817. case TX_PATH:
  3818. media_fmt_param_data->param_id =
  3819. VSS_PARAM_TX_PORT_ENDPOINT_MEDIA_INFO;
  3820. media_fmt_info->port_id = v->dev_tx.port_id;
  3821. media_fmt_info->num_channels = v->dev_tx.no_of_channels;
  3822. media_fmt_info->bits_per_sample = v->dev_tx.bits_per_sample;
  3823. media_fmt_info->sample_rate = v->dev_tx.sample_rate;
  3824. memcpy(&media_fmt_info->channel_mapping,
  3825. &v->dev_tx.channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  3826. break;
  3827. case EC_REF_PATH:
  3828. media_fmt_param_data->param_id =
  3829. VSS_PARAM_EC_REF_PORT_ENDPOINT_MEDIA_INFO;
  3830. media_fmt_info->port_id = common.ec_media_fmt_info.port_id;
  3831. media_fmt_info->num_channels =
  3832. common.ec_media_fmt_info.num_channels;
  3833. media_fmt_info->bits_per_sample =
  3834. common.ec_media_fmt_info.bits_per_sample;
  3835. media_fmt_info->sample_rate =
  3836. common.ec_media_fmt_info.sample_rate;
  3837. memcpy(&media_fmt_info->channel_mapping,
  3838. &common.ec_media_fmt_info.channel_mapping,
  3839. VSS_CHANNEL_MAPPING_SIZE);
  3840. break;
  3841. default:
  3842. pr_err("%s: Invalid param type %d\n", __func__, param_type);
  3843. ret = -EINVAL;
  3844. goto done;
  3845. }
  3846. /* Send command */
  3847. v->cvp_state = CMD_STATUS_FAIL;
  3848. v->async_err = 0;
  3849. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_set_media_format_cmd);
  3850. if (ret < 0) {
  3851. pr_err("%s: Fail in sending VSS_ICOMMON_CMD_SET_PARAM_V2\n",
  3852. __func__);
  3853. ret = -EINVAL;
  3854. goto done;
  3855. }
  3856. ret = wait_event_timeout(v->cvp_wait,
  3857. (v->cvp_state == CMD_STATUS_SUCCESS),
  3858. msecs_to_jiffies(TIMEOUT_MS));
  3859. if (!ret) {
  3860. pr_err("%s: wait_event timeout\n", __func__);
  3861. ret = -EINVAL;
  3862. goto done;
  3863. }
  3864. if (v->async_err > 0) {
  3865. pr_err("%s: DSP returned error[%s] handle = %d\n", __func__,
  3866. adsp_err_get_err_str(v->async_err), cvp_handle);
  3867. ret = adsp_err_get_lnx_err_code(v->async_err);
  3868. goto done;
  3869. }
  3870. done:
  3871. return ret;
  3872. }
  3873. static int voice_send_cvp_topology_commit_cmd(struct voice_data *v)
  3874. {
  3875. int ret = 0;
  3876. struct apr_hdr cvp_topology_commit_cmd;
  3877. void *apr_cvp;
  3878. u16 cvp_handle;
  3879. if (!(voice_get_cvd_int_version(common.cvd_version) >=
  3880. CVD_INT_VERSION_2_2)) {
  3881. pr_debug("%s CVD version string %s doesn't support this command\n",
  3882. __func__, common.cvd_version);
  3883. goto done;
  3884. }
  3885. if (v == NULL) {
  3886. pr_err("%s: v is NULL\n", __func__);
  3887. ret = -EINVAL;
  3888. goto done;
  3889. }
  3890. apr_cvp = common.apr_q6_cvp;
  3891. if (!apr_cvp) {
  3892. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3893. ret = -EINVAL;
  3894. goto done;
  3895. }
  3896. cvp_handle = voice_get_cvp_handle(v);
  3897. cvp_topology_commit_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3898. APR_HDR_LEN(APR_HDR_SIZE),
  3899. APR_PKT_VER);
  3900. cvp_topology_commit_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3901. sizeof(cvp_topology_commit_cmd) - APR_HDR_SIZE);
  3902. cvp_topology_commit_cmd.src_port =
  3903. voice_get_idx_for_session(v->session_id);
  3904. cvp_topology_commit_cmd.dest_port = cvp_handle;
  3905. cvp_topology_commit_cmd.token = 0;
  3906. cvp_topology_commit_cmd.opcode = VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT;
  3907. v->cvp_state = CMD_STATUS_FAIL;
  3908. v->async_err = 0;
  3909. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_topology_commit_cmd);
  3910. if (ret < 0) {
  3911. pr_err("%s: Fail in sending VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT\n",
  3912. __func__);
  3913. ret = -EINVAL;
  3914. goto done;
  3915. }
  3916. ret = wait_event_timeout(v->cvp_wait,
  3917. (v->cvp_state == CMD_STATUS_SUCCESS),
  3918. msecs_to_jiffies(TIMEOUT_MS));
  3919. if (!ret) {
  3920. pr_err("%s: wait_event timeout\n", __func__);
  3921. ret = -EINVAL;
  3922. goto done;
  3923. }
  3924. if (v->async_err > 0) {
  3925. pr_err("%s: DSP returned error[%s]\n",
  3926. __func__, adsp_err_get_err_str(
  3927. v->async_err));
  3928. ret = adsp_err_get_lnx_err_code(
  3929. v->async_err);
  3930. goto done;
  3931. }
  3932. done:
  3933. return ret;
  3934. }
  3935. static int voice_send_enable_vocproc_cmd(struct voice_data *v)
  3936. {
  3937. int ret = 0;
  3938. struct apr_hdr cvp_enable_cmd;
  3939. void *apr_cvp;
  3940. u16 cvp_handle;
  3941. if (v == NULL) {
  3942. pr_err("%s: v is NULL\n", __func__);
  3943. return -EINVAL;
  3944. }
  3945. apr_cvp = common.apr_q6_cvp;
  3946. if (!apr_cvp) {
  3947. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3948. return -EINVAL;
  3949. }
  3950. cvp_handle = voice_get_cvp_handle(v);
  3951. /* enable vocproc and wait for respose */
  3952. cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3953. APR_HDR_LEN(APR_HDR_SIZE),
  3954. APR_PKT_VER);
  3955. cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3956. sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
  3957. pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
  3958. cvp_enable_cmd.pkt_size, cvp_handle);
  3959. cvp_enable_cmd.src_port =
  3960. voice_get_idx_for_session(v->session_id);
  3961. cvp_enable_cmd.dest_port = cvp_handle;
  3962. cvp_enable_cmd.token = 0;
  3963. cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
  3964. v->cvp_state = CMD_STATUS_FAIL;
  3965. v->async_err = 0;
  3966. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
  3967. if (ret < 0) {
  3968. pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
  3969. goto fail;
  3970. }
  3971. ret = wait_event_timeout(v->cvp_wait,
  3972. (v->cvp_state == CMD_STATUS_SUCCESS),
  3973. msecs_to_jiffies(TIMEOUT_MS));
  3974. if (!ret) {
  3975. pr_err("%s: wait_event timeout\n", __func__);
  3976. goto fail;
  3977. }
  3978. if (v->async_err > 0) {
  3979. pr_err("%s: DSP returned error[%s]\n",
  3980. __func__, adsp_err_get_err_str(
  3981. v->async_err));
  3982. ret = adsp_err_get_lnx_err_code(
  3983. v->async_err);
  3984. goto fail;
  3985. }
  3986. return 0;
  3987. fail:
  3988. return ret;
  3989. }
  3990. static int voice_send_mvm_cal_network_cmd(struct voice_data *v)
  3991. {
  3992. struct vss_imvm_cmd_set_cal_network_t mvm_set_cal_network;
  3993. int ret = 0;
  3994. void *apr_mvm;
  3995. u16 mvm_handle;
  3996. if (v == NULL) {
  3997. pr_err("%s: v is NULL\n", __func__);
  3998. return -EINVAL;
  3999. }
  4000. apr_mvm = common.apr_q6_mvm;
  4001. if (!apr_mvm) {
  4002. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4003. return -EINVAL;
  4004. }
  4005. mvm_handle = voice_get_mvm_handle(v);
  4006. mvm_set_cal_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4007. APR_HDR_LEN(APR_HDR_SIZE),
  4008. APR_PKT_VER);
  4009. mvm_set_cal_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4010. sizeof(mvm_set_cal_network) - APR_HDR_SIZE);
  4011. mvm_set_cal_network.hdr.src_port =
  4012. voice_get_idx_for_session(v->session_id);
  4013. mvm_set_cal_network.hdr.dest_port = mvm_handle;
  4014. mvm_set_cal_network.hdr.token = 0;
  4015. mvm_set_cal_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  4016. mvm_set_cal_network.network_id = VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  4017. v->mvm_state = CMD_STATUS_FAIL;
  4018. v->async_err = 0;
  4019. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_network);
  4020. if (ret < 0) {
  4021. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  4022. goto fail;
  4023. }
  4024. ret = wait_event_timeout(v->mvm_wait,
  4025. (v->mvm_state == CMD_STATUS_SUCCESS),
  4026. msecs_to_jiffies(TIMEOUT_MS));
  4027. if (!ret) {
  4028. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4029. goto fail;
  4030. }
  4031. if (v->async_err > 0) {
  4032. pr_err("%s: DSP returned error[%s]\n",
  4033. __func__, adsp_err_get_err_str(
  4034. v->async_err));
  4035. ret = adsp_err_get_lnx_err_code(
  4036. v->async_err);
  4037. goto fail;
  4038. }
  4039. return 0;
  4040. fail:
  4041. return ret;
  4042. }
  4043. static int voice_send_netid_timing_cmd(struct voice_data *v)
  4044. {
  4045. int ret = 0;
  4046. void *apr_mvm;
  4047. u16 mvm_handle;
  4048. struct mvm_set_network_cmd mvm_set_network;
  4049. struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
  4050. if (v == NULL) {
  4051. pr_err("%s: v is NULL\n", __func__);
  4052. return -EINVAL;
  4053. }
  4054. apr_mvm = common.apr_q6_mvm;
  4055. if (!apr_mvm) {
  4056. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4057. return -EINVAL;
  4058. }
  4059. mvm_handle = voice_get_mvm_handle(v);
  4060. ret = voice_config_cvs_vocoder(v);
  4061. if (ret < 0) {
  4062. pr_err("%s: Error %d configuring CVS voc",
  4063. __func__, ret);
  4064. goto fail;
  4065. }
  4066. /* Set network ID. */
  4067. pr_debug("Setting network ID %x\n", common.mvs_info.network_type);
  4068. mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4069. APR_HDR_LEN(APR_HDR_SIZE),
  4070. APR_PKT_VER);
  4071. mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4072. sizeof(mvm_set_network) - APR_HDR_SIZE);
  4073. mvm_set_network.hdr.src_port =
  4074. voice_get_idx_for_session(v->session_id);
  4075. mvm_set_network.hdr.dest_port = mvm_handle;
  4076. mvm_set_network.hdr.token = 0;
  4077. mvm_set_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  4078. mvm_set_network.network.network_id = common.mvs_info.network_type;
  4079. v->mvm_state = CMD_STATUS_FAIL;
  4080. v->async_err = 0;
  4081. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
  4082. if (ret < 0) {
  4083. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  4084. goto fail;
  4085. }
  4086. ret = wait_event_timeout(v->mvm_wait,
  4087. (v->mvm_state == CMD_STATUS_SUCCESS),
  4088. msecs_to_jiffies(TIMEOUT_MS));
  4089. if (!ret) {
  4090. pr_err("%s: wait_event timeout\n", __func__);
  4091. goto fail;
  4092. }
  4093. if (v->async_err > 0) {
  4094. pr_err("%s: DSP returned error[%s]\n",
  4095. __func__, adsp_err_get_err_str(
  4096. v->async_err));
  4097. ret = adsp_err_get_lnx_err_code(
  4098. v->async_err);
  4099. goto fail;
  4100. }
  4101. /* Set voice timing. */
  4102. pr_debug("Setting voice timing\n");
  4103. mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4104. APR_HDR_LEN(APR_HDR_SIZE),
  4105. APR_PKT_VER);
  4106. mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4107. sizeof(mvm_set_voice_timing) -
  4108. APR_HDR_SIZE);
  4109. mvm_set_voice_timing.hdr.src_port =
  4110. voice_get_idx_for_session(v->session_id);
  4111. mvm_set_voice_timing.hdr.dest_port = mvm_handle;
  4112. mvm_set_voice_timing.hdr.token = 0;
  4113. mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
  4114. mvm_set_voice_timing.timing.mode = 0;
  4115. mvm_set_voice_timing.timing.enc_offset = 8000;
  4116. mvm_set_voice_timing.timing.dec_req_offset = 3300;
  4117. mvm_set_voice_timing.timing.dec_offset = 8300;
  4118. v->mvm_state = CMD_STATUS_FAIL;
  4119. v->async_err = 0;
  4120. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
  4121. if (ret < 0) {
  4122. pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
  4123. goto fail;
  4124. }
  4125. ret = wait_event_timeout(v->mvm_wait,
  4126. (v->mvm_state == CMD_STATUS_SUCCESS),
  4127. msecs_to_jiffies(TIMEOUT_MS));
  4128. if (!ret) {
  4129. pr_err("%s: wait_event timeout\n", __func__);
  4130. goto fail;
  4131. }
  4132. if (v->async_err > 0) {
  4133. pr_err("%s: DSP returned error[%s]\n",
  4134. __func__, adsp_err_get_err_str(
  4135. v->async_err));
  4136. ret = adsp_err_get_lnx_err_code(
  4137. v->async_err);
  4138. goto fail;
  4139. }
  4140. return 0;
  4141. fail:
  4142. return ret;
  4143. }
  4144. static int voice_send_attach_vocproc_cmd(struct voice_data *v)
  4145. {
  4146. int ret = 0;
  4147. struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
  4148. void *apr_mvm;
  4149. u16 mvm_handle, cvp_handle;
  4150. if (v == NULL) {
  4151. pr_err("%s: v is NULL\n", __func__);
  4152. return -EINVAL;
  4153. }
  4154. apr_mvm = common.apr_q6_mvm;
  4155. if (!apr_mvm) {
  4156. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4157. return -EINVAL;
  4158. }
  4159. mvm_handle = voice_get_mvm_handle(v);
  4160. cvp_handle = voice_get_cvp_handle(v);
  4161. /* attach vocproc and wait for response */
  4162. mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4163. APR_HDR_LEN(APR_HDR_SIZE),
  4164. APR_PKT_VER);
  4165. mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4166. sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
  4167. pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
  4168. mvm_a_vocproc_cmd.hdr.pkt_size);
  4169. mvm_a_vocproc_cmd.hdr.src_port =
  4170. voice_get_idx_for_session(v->session_id);
  4171. mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
  4172. mvm_a_vocproc_cmd.hdr.token = 0;
  4173. mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
  4174. mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
  4175. v->mvm_state = CMD_STATUS_FAIL;
  4176. v->async_err = 0;
  4177. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
  4178. if (ret < 0) {
  4179. pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
  4180. goto fail;
  4181. }
  4182. ret = wait_event_timeout(v->mvm_wait,
  4183. (v->mvm_state == CMD_STATUS_SUCCESS),
  4184. msecs_to_jiffies(TIMEOUT_MS));
  4185. if (!ret) {
  4186. pr_err("%s: wait_event timeout\n", __func__);
  4187. goto fail;
  4188. }
  4189. if (v->async_err > 0) {
  4190. pr_err("%s: DSP returned error[%s]\n",
  4191. __func__, adsp_err_get_err_str(
  4192. v->async_err));
  4193. ret = adsp_err_get_lnx_err_code(
  4194. v->async_err);
  4195. goto fail;
  4196. }
  4197. return 0;
  4198. fail:
  4199. return ret;
  4200. }
  4201. static void voc_update_session_params(struct voice_data *v)
  4202. {
  4203. /* reset LCH mode */
  4204. v->lch_mode = 0;
  4205. /* clear disable topology setting */
  4206. v->disable_topology = false;
  4207. /* clear mute setting */
  4208. v->dev_rx.dev_mute = common.default_mute_val;
  4209. v->dev_tx.dev_mute = common.default_mute_val;
  4210. v->stream_rx.stream_mute = common.default_mute_val;
  4211. v->stream_tx.stream_mute = common.default_mute_val;
  4212. }
  4213. static int voice_destroy_vocproc(struct voice_data *v)
  4214. {
  4215. struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
  4216. struct apr_hdr cvp_destroy_session_cmd;
  4217. int ret = 0;
  4218. void *apr_mvm, *apr_cvp;
  4219. u16 mvm_handle, cvp_handle;
  4220. if (v == NULL) {
  4221. pr_err("%s: v is NULL\n", __func__);
  4222. return -EINVAL;
  4223. }
  4224. apr_mvm = common.apr_q6_mvm;
  4225. apr_cvp = common.apr_q6_cvp;
  4226. if (!apr_mvm || !apr_cvp) {
  4227. pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
  4228. return -EINVAL;
  4229. }
  4230. mvm_handle = voice_get_mvm_handle(v);
  4231. cvp_handle = voice_get_cvp_handle(v);
  4232. /* disable slowtalk if st_enable is set */
  4233. if (v->st_enable)
  4234. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_ST, 0);
  4235. /* Disable HD Voice if hd_enable is set */
  4236. if (v->hd_enable)
  4237. voice_send_hd_cmd(v, 0);
  4238. /* stop playback or recording */
  4239. v->music_info.force = 1;
  4240. voice_cvs_stop_playback(v);
  4241. voice_cvs_stop_record(v);
  4242. /* If voice call is active during VoLTE, SRVCC happens.
  4243. * Start recording on voice session if recording started during VoLTE.
  4244. */
  4245. if (is_volte_session(v->session_id) &&
  4246. ((common.voice[VOC_PATH_PASSIVE].voc_state == VOC_RUN) ||
  4247. (common.voice[VOC_PATH_PASSIVE].voc_state == VOC_CHANGE))) {
  4248. if (v->rec_info.rec_enable) {
  4249. voice_cvs_start_record(
  4250. &common.voice[VOC_PATH_PASSIVE],
  4251. v->rec_info.rec_mode);
  4252. common.srvcc_rec_flag = true;
  4253. pr_debug("%s: switch recording, srvcc_rec_flag %d\n",
  4254. __func__, common.srvcc_rec_flag);
  4255. }
  4256. }
  4257. /* send stop voice cmd */
  4258. voice_send_stop_voice_cmd(v);
  4259. /* send stop dtmf detecton cmd */
  4260. if (v->dtmf_rx_detect_en)
  4261. voice_send_dtmf_rx_detection_cmd(v, 0);
  4262. /* detach VOCPROC and wait for response from mvm */
  4263. mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4264. APR_HDR_LEN(APR_HDR_SIZE),
  4265. APR_PKT_VER);
  4266. mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4267. sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
  4268. pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
  4269. mvm_d_vocproc_cmd.hdr.pkt_size);
  4270. mvm_d_vocproc_cmd.hdr.src_port =
  4271. voice_get_idx_for_session(v->session_id);
  4272. mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
  4273. mvm_d_vocproc_cmd.hdr.token = 0;
  4274. mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
  4275. mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
  4276. v->mvm_state = CMD_STATUS_FAIL;
  4277. v->async_err = 0;
  4278. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
  4279. if (ret < 0) {
  4280. pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
  4281. goto fail;
  4282. }
  4283. ret = wait_event_timeout(v->mvm_wait,
  4284. (v->mvm_state == CMD_STATUS_SUCCESS),
  4285. msecs_to_jiffies(TIMEOUT_MS));
  4286. if (!ret) {
  4287. pr_err("%s: wait_event timeout\n", __func__);
  4288. goto fail;
  4289. }
  4290. if (v->async_err > 0) {
  4291. pr_err("%s: DSP returned error[%s]\n",
  4292. __func__, adsp_err_get_err_str(
  4293. v->async_err));
  4294. ret = adsp_err_get_lnx_err_code(
  4295. v->async_err);
  4296. goto fail;
  4297. }
  4298. voice_send_cvp_deregister_vol_cal_cmd(v);
  4299. voice_send_cvp_deregister_cal_cmd(v);
  4300. voice_send_cvp_deregister_dev_cfg_cmd(v);
  4301. voice_send_cvs_deregister_cal_cmd(v);
  4302. /* destrop cvp session */
  4303. cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4304. APR_HDR_LEN(APR_HDR_SIZE),
  4305. APR_PKT_VER);
  4306. cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4307. sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
  4308. pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
  4309. cvp_destroy_session_cmd.pkt_size);
  4310. cvp_destroy_session_cmd.src_port =
  4311. voice_get_idx_for_session(v->session_id);
  4312. cvp_destroy_session_cmd.dest_port = cvp_handle;
  4313. cvp_destroy_session_cmd.token = 0;
  4314. cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  4315. v->cvp_state = CMD_STATUS_FAIL;
  4316. v->async_err = 0;
  4317. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
  4318. if (ret < 0) {
  4319. pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
  4320. goto fail;
  4321. }
  4322. ret = wait_event_timeout(v->cvp_wait,
  4323. (v->cvp_state == CMD_STATUS_SUCCESS),
  4324. msecs_to_jiffies(TIMEOUT_MS));
  4325. if (!ret) {
  4326. pr_err("%s: wait_event timeout\n", __func__);
  4327. goto fail;
  4328. }
  4329. if (v->async_err > 0) {
  4330. pr_err("%s: DSP returned error[%s]\n",
  4331. __func__, adsp_err_get_err_str(
  4332. v->async_err));
  4333. ret = adsp_err_get_lnx_err_code(
  4334. v->async_err);
  4335. goto fail;
  4336. }
  4337. rtac_remove_voice(voice_get_cvs_handle(v));
  4338. cvp_handle = 0;
  4339. voice_set_cvp_handle(v, cvp_handle);
  4340. return 0;
  4341. fail:
  4342. return ret;
  4343. }
  4344. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  4345. uint32_t mem_handle)
  4346. {
  4347. struct vss_imemory_cmd_unmap_t mem_unmap;
  4348. int ret = 0;
  4349. void *apr_mvm;
  4350. u16 mvm_handle;
  4351. if (v == NULL) {
  4352. pr_err("%s: v is NULL\n", __func__);
  4353. return -EINVAL;
  4354. }
  4355. apr_mvm = common.apr_q6_mvm;
  4356. if (!apr_mvm) {
  4357. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4358. return -EINVAL;
  4359. }
  4360. mvm_handle = voice_get_mvm_handle(v);
  4361. mem_unmap.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4362. APR_HDR_LEN(APR_HDR_SIZE),
  4363. APR_PKT_VER);
  4364. mem_unmap.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4365. sizeof(mem_unmap) - APR_HDR_SIZE);
  4366. mem_unmap.hdr.src_port =
  4367. voice_get_idx_for_session(v->session_id);
  4368. mem_unmap.hdr.dest_port = mvm_handle;
  4369. mem_unmap.hdr.token = 0;
  4370. mem_unmap.hdr.opcode = VSS_IMEMORY_CMD_UNMAP;
  4371. mem_unmap.mem_handle = mem_handle;
  4372. pr_debug("%s: mem_handle: 0x%x\n", __func__, mem_unmap.mem_handle);
  4373. v->mvm_state = CMD_STATUS_FAIL;
  4374. v->async_err = 0;
  4375. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mem_unmap);
  4376. if (ret < 0) {
  4377. pr_err("mem_unmap op[0x%x]ret[%d]\n",
  4378. mem_unmap.hdr.opcode, ret);
  4379. goto fail;
  4380. }
  4381. ret = wait_event_timeout(v->mvm_wait,
  4382. (v->mvm_state == CMD_STATUS_SUCCESS),
  4383. msecs_to_jiffies(TIMEOUT_MS));
  4384. if (!ret) {
  4385. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4386. goto fail;
  4387. }
  4388. if (v->async_err > 0) {
  4389. pr_err("%s: DSP returned error[%s]\n",
  4390. __func__, adsp_err_get_err_str(
  4391. v->async_err));
  4392. ret = adsp_err_get_lnx_err_code(
  4393. v->async_err);
  4394. goto fail;
  4395. }
  4396. return 0;
  4397. fail:
  4398. return ret;
  4399. }
  4400. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v)
  4401. {
  4402. struct vss_istream_cmd_set_oob_packet_exchange_config_t
  4403. packet_exchange_config_pkt;
  4404. int ret = 0;
  4405. void *apr_cvs;
  4406. u16 cvs_handle;
  4407. if (v == NULL) {
  4408. pr_err("%s: v is NULL\n", __func__);
  4409. return -EINVAL;
  4410. }
  4411. apr_cvs = common.apr_q6_cvs;
  4412. if (!apr_cvs) {
  4413. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4414. return -EINVAL;
  4415. }
  4416. cvs_handle = voice_get_cvs_handle(v);
  4417. packet_exchange_config_pkt.hdr.hdr_field = APR_HDR_FIELD(
  4418. APR_MSG_TYPE_SEQ_CMD,
  4419. APR_HDR_LEN(APR_HDR_SIZE),
  4420. APR_PKT_VER);
  4421. packet_exchange_config_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4422. sizeof(packet_exchange_config_pkt) -
  4423. APR_HDR_SIZE);
  4424. packet_exchange_config_pkt.hdr.src_port =
  4425. voice_get_idx_for_session(v->session_id);
  4426. packet_exchange_config_pkt.hdr.dest_port = cvs_handle;
  4427. packet_exchange_config_pkt.hdr.token = 0;
  4428. packet_exchange_config_pkt.hdr.opcode =
  4429. VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG;
  4430. packet_exchange_config_pkt.mem_handle = v->shmem_info.mem_handle;
  4431. /* dec buffer address */
  4432. packet_exchange_config_pkt.dec_buf_addr_lsw =
  4433. lower_32_bits(v->shmem_info.sh_buf.buf[0].phys);
  4434. packet_exchange_config_pkt.dec_buf_addr_msw =
  4435. msm_audio_populate_upper_32_bits(
  4436. v->shmem_info.sh_buf.buf[0].phys);
  4437. packet_exchange_config_pkt.dec_buf_size = 4096;
  4438. /* enc buffer address */
  4439. packet_exchange_config_pkt.enc_buf_addr_lsw =
  4440. lower_32_bits(v->shmem_info.sh_buf.buf[1].phys);
  4441. packet_exchange_config_pkt.enc_buf_addr_msw =
  4442. msm_audio_populate_upper_32_bits(
  4443. v->shmem_info.sh_buf.buf[1].phys);
  4444. packet_exchange_config_pkt.enc_buf_size = 4096;
  4445. pr_debug("%s: dec buf add: lsw %0x msw %0x, size %d, enc buf add: lsw %0x msw %0x, size %d\n",
  4446. __func__,
  4447. packet_exchange_config_pkt.dec_buf_addr_lsw,
  4448. packet_exchange_config_pkt.dec_buf_addr_msw,
  4449. packet_exchange_config_pkt.dec_buf_size,
  4450. packet_exchange_config_pkt.enc_buf_addr_lsw,
  4451. packet_exchange_config_pkt.enc_buf_addr_msw,
  4452. packet_exchange_config_pkt.enc_buf_size);
  4453. v->cvs_state = CMD_STATUS_FAIL;
  4454. v->async_err = 0;
  4455. ret = apr_send_pkt(apr_cvs, (uint32_t *) &packet_exchange_config_pkt);
  4456. if (ret < 0) {
  4457. pr_err("Failed to send packet exchange config cmd %d\n", ret);
  4458. goto fail;
  4459. }
  4460. ret = wait_event_timeout(v->cvs_wait,
  4461. (v->cvs_state == CMD_STATUS_SUCCESS),
  4462. msecs_to_jiffies(TIMEOUT_MS));
  4463. if (!ret)
  4464. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4465. if (v->async_err > 0) {
  4466. pr_err("%s: DSP returned error[%s]\n",
  4467. __func__, adsp_err_get_err_str(
  4468. v->async_err));
  4469. ret = adsp_err_get_lnx_err_code(
  4470. v->async_err);
  4471. goto fail;
  4472. }
  4473. return 0;
  4474. fail:
  4475. return ret;
  4476. }
  4477. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v)
  4478. {
  4479. struct vss_istream_cmd_set_packet_exchange_mode_t data_exchange_pkt;
  4480. int ret = 0;
  4481. void *apr_cvs;
  4482. u16 cvs_handle;
  4483. if (v == NULL) {
  4484. pr_err("%s: v is NULL\n", __func__);
  4485. return -EINVAL;
  4486. }
  4487. apr_cvs = common.apr_q6_cvs;
  4488. if (!apr_cvs) {
  4489. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4490. return -EINVAL;
  4491. }
  4492. cvs_handle = voice_get_cvs_handle(v);
  4493. data_exchange_pkt.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4494. APR_HDR_LEN(APR_HDR_SIZE),
  4495. APR_PKT_VER);
  4496. data_exchange_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4497. sizeof(data_exchange_pkt) - APR_HDR_SIZE);
  4498. data_exchange_pkt.hdr.src_port =
  4499. voice_get_idx_for_session(v->session_id);
  4500. data_exchange_pkt.hdr.dest_port = cvs_handle;
  4501. data_exchange_pkt.hdr.token = 0;
  4502. data_exchange_pkt.hdr.opcode = VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE;
  4503. data_exchange_pkt.mode = VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND;
  4504. v->cvs_state = CMD_STATUS_FAIL;
  4505. v->async_err = 0;
  4506. ret = apr_send_pkt(apr_cvs, (uint32_t *) &data_exchange_pkt);
  4507. if (ret < 0) {
  4508. pr_err("Failed to send data exchange mode %d\n", ret);
  4509. goto fail;
  4510. }
  4511. ret = wait_event_timeout(v->cvs_wait,
  4512. (v->cvs_state == CMD_STATUS_SUCCESS),
  4513. msecs_to_jiffies(TIMEOUT_MS));
  4514. if (!ret)
  4515. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  4516. if (v->async_err > 0) {
  4517. pr_err("%s: DSP returned error[%s]\n",
  4518. __func__, adsp_err_get_err_str(
  4519. v->async_err));
  4520. ret = adsp_err_get_lnx_err_code(
  4521. v->async_err);
  4522. goto fail;
  4523. }
  4524. return 0;
  4525. fail:
  4526. return ret;
  4527. }
  4528. static int voice_send_stream_mute_cmd(struct voice_data *v, uint16_t direction,
  4529. uint16_t mute_flag, uint32_t ramp_duration)
  4530. {
  4531. struct cvs_set_mute_cmd cvs_mute_cmd;
  4532. int ret = 0;
  4533. if (v == NULL) {
  4534. pr_err("%s: v is NULL\n", __func__);
  4535. ret = -EINVAL;
  4536. goto fail;
  4537. }
  4538. if (!common.apr_q6_cvs) {
  4539. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4540. ret = -EINVAL;
  4541. goto fail;
  4542. }
  4543. /* send mute/unmute to cvs */
  4544. cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4545. APR_HDR_LEN(APR_HDR_SIZE),
  4546. APR_PKT_VER);
  4547. cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4548. sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
  4549. cvs_mute_cmd.hdr.src_port =
  4550. voice_get_idx_for_session(v->session_id);
  4551. cvs_mute_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  4552. cvs_mute_cmd.hdr.token = 0;
  4553. cvs_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  4554. cvs_mute_cmd.cvs_set_mute.direction = direction;
  4555. cvs_mute_cmd.cvs_set_mute.mute_flag = mute_flag;
  4556. cvs_mute_cmd.cvs_set_mute.ramp_duration_ms = ramp_duration;
  4557. v->cvs_state = CMD_STATUS_FAIL;
  4558. v->async_err = 0;
  4559. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_mute_cmd);
  4560. if (ret < 0) {
  4561. pr_err("%s: Error %d sending stream mute\n", __func__, ret);
  4562. goto fail;
  4563. }
  4564. ret = wait_event_timeout(v->cvs_wait,
  4565. (v->cvs_state == CMD_STATUS_SUCCESS),
  4566. msecs_to_jiffies(TIMEOUT_MS));
  4567. if (!ret) {
  4568. pr_err("%s: Command timeout\n", __func__);
  4569. goto fail;
  4570. }
  4571. if (v->async_err > 0) {
  4572. pr_err("%s: DSP returned error[%s]\n",
  4573. __func__, adsp_err_get_err_str(
  4574. v->async_err));
  4575. ret = adsp_err_get_lnx_err_code(
  4576. v->async_err);
  4577. goto fail;
  4578. }
  4579. return 0;
  4580. fail:
  4581. return ret;
  4582. }
  4583. static int voice_send_device_mute_cmd(struct voice_data *v, uint16_t direction,
  4584. uint16_t mute_flag, uint32_t ramp_duration)
  4585. {
  4586. struct cvp_set_mute_cmd cvp_mute_cmd;
  4587. int ret = 0;
  4588. if (v == NULL) {
  4589. pr_err("%s: v is NULL\n", __func__);
  4590. ret = -EINVAL;
  4591. goto fail;
  4592. }
  4593. if (!common.apr_q6_cvp) {
  4594. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4595. ret = -EINVAL;
  4596. goto fail;
  4597. }
  4598. cvp_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4599. APR_HDR_LEN(APR_HDR_SIZE),
  4600. APR_PKT_VER);
  4601. cvp_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4602. sizeof(cvp_mute_cmd) - APR_HDR_SIZE);
  4603. cvp_mute_cmd.hdr.src_port =
  4604. voice_get_idx_for_session(v->session_id);
  4605. cvp_mute_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  4606. cvp_mute_cmd.hdr.token = 0;
  4607. cvp_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  4608. cvp_mute_cmd.cvp_set_mute.direction = direction;
  4609. cvp_mute_cmd.cvp_set_mute.mute_flag = mute_flag;
  4610. cvp_mute_cmd.cvp_set_mute.ramp_duration_ms = ramp_duration;
  4611. v->cvp_state = CMD_STATUS_FAIL;
  4612. v->async_err = 0;
  4613. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_mute_cmd);
  4614. if (ret < 0) {
  4615. pr_err("%s: Error %d sending rx device cmd\n", __func__, ret);
  4616. goto fail;
  4617. }
  4618. ret = wait_event_timeout(v->cvp_wait,
  4619. (v->cvp_state == CMD_STATUS_SUCCESS),
  4620. msecs_to_jiffies(TIMEOUT_MS));
  4621. if (!ret) {
  4622. pr_err("%s: Command timeout\n", __func__);
  4623. goto fail;
  4624. }
  4625. if (v->async_err > 0) {
  4626. pr_err("%s: DSP returned error[%s]\n",
  4627. __func__, adsp_err_get_err_str(
  4628. v->async_err));
  4629. ret = adsp_err_get_lnx_err_code(
  4630. v->async_err);
  4631. goto fail;
  4632. }
  4633. return 0;
  4634. fail:
  4635. return ret;
  4636. }
  4637. static int voice_send_vol_step_cmd(struct voice_data *v)
  4638. {
  4639. struct cvp_set_rx_volume_step_cmd cvp_vol_step_cmd;
  4640. int ret = 0;
  4641. void *apr_cvp;
  4642. u16 cvp_handle;
  4643. if (v == NULL) {
  4644. pr_err("%s: v is NULL\n", __func__);
  4645. return -EINVAL;
  4646. }
  4647. apr_cvp = common.apr_q6_cvp;
  4648. if (!apr_cvp) {
  4649. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4650. return -EINVAL;
  4651. }
  4652. cvp_handle = voice_get_cvp_handle(v);
  4653. /* send volume index to cvp */
  4654. cvp_vol_step_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4655. APR_HDR_LEN(APR_HDR_SIZE),
  4656. APR_PKT_VER);
  4657. cvp_vol_step_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4658. sizeof(cvp_vol_step_cmd) - APR_HDR_SIZE);
  4659. cvp_vol_step_cmd.hdr.src_port =
  4660. voice_get_idx_for_session(v->session_id);
  4661. cvp_vol_step_cmd.hdr.dest_port = cvp_handle;
  4662. cvp_vol_step_cmd.hdr.token = 0;
  4663. cvp_vol_step_cmd.hdr.opcode = VSS_IVOLUME_CMD_SET_STEP;
  4664. cvp_vol_step_cmd.cvp_set_vol_step.direction = VSS_IVOLUME_DIRECTION_RX;
  4665. cvp_vol_step_cmd.cvp_set_vol_step.value = v->dev_rx.volume_step_value;
  4666. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms =
  4667. v->dev_rx.volume_ramp_duration_ms;
  4668. pr_debug("%s step_value:%d, ramp_duration_ms:%d",
  4669. __func__,
  4670. cvp_vol_step_cmd.cvp_set_vol_step.value,
  4671. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms);
  4672. v->cvp_state = CMD_STATUS_FAIL;
  4673. v->async_err = 0;
  4674. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_step_cmd);
  4675. if (ret < 0) {
  4676. pr_err("Fail in sending RX VOL step\n");
  4677. return -EINVAL;
  4678. }
  4679. ret = wait_event_timeout(v->cvp_wait,
  4680. (v->cvp_state == CMD_STATUS_SUCCESS),
  4681. msecs_to_jiffies(TIMEOUT_MS));
  4682. if (!ret) {
  4683. pr_err("%s: wait_event timeout\n", __func__);
  4684. return -EINVAL;
  4685. }
  4686. if (v->async_err > 0) {
  4687. pr_err("%s: DSP returned error[%s]\n",
  4688. __func__, adsp_err_get_err_str(
  4689. v->async_err));
  4690. ret = adsp_err_get_lnx_err_code(
  4691. v->async_err);
  4692. return ret;
  4693. }
  4694. return 0;
  4695. }
  4696. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode)
  4697. {
  4698. int ret = 0;
  4699. void *apr_cvs;
  4700. u16 cvs_handle;
  4701. struct cvs_start_record_cmd cvs_start_record;
  4702. if (v == NULL) {
  4703. pr_err("%s: v is NULL\n", __func__);
  4704. return -EINVAL;
  4705. }
  4706. apr_cvs = common.apr_q6_cvs;
  4707. if (!apr_cvs) {
  4708. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4709. return -EINVAL;
  4710. }
  4711. cvs_handle = voice_get_cvs_handle(v);
  4712. if (!v->rec_info.recording) {
  4713. cvs_start_record.hdr.hdr_field = APR_HDR_FIELD(
  4714. APR_MSG_TYPE_SEQ_CMD,
  4715. APR_HDR_LEN(APR_HDR_SIZE),
  4716. APR_PKT_VER);
  4717. cvs_start_record.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4718. sizeof(cvs_start_record) - APR_HDR_SIZE);
  4719. cvs_start_record.hdr.src_port =
  4720. voice_get_idx_for_session(v->session_id);
  4721. cvs_start_record.hdr.dest_port = cvs_handle;
  4722. cvs_start_record.hdr.token = 0;
  4723. cvs_start_record.hdr.opcode = VSS_IRECORD_CMD_START;
  4724. cvs_start_record.rec_mode.port_id =
  4725. VSS_IRECORD_PORT_ID_DEFAULT;
  4726. if (rec_mode == VOC_REC_UPLINK) {
  4727. cvs_start_record.rec_mode.rx_tap_point =
  4728. VSS_IRECORD_TAP_POINT_NONE;
  4729. cvs_start_record.rec_mode.tx_tap_point =
  4730. VSS_IRECORD_TAP_POINT_STREAM_END;
  4731. } else if (rec_mode == VOC_REC_DOWNLINK) {
  4732. cvs_start_record.rec_mode.rx_tap_point =
  4733. VSS_IRECORD_TAP_POINT_STREAM_END;
  4734. cvs_start_record.rec_mode.tx_tap_point =
  4735. VSS_IRECORD_TAP_POINT_NONE;
  4736. } else if (rec_mode == VOC_REC_BOTH) {
  4737. cvs_start_record.rec_mode.rx_tap_point =
  4738. VSS_IRECORD_TAP_POINT_STREAM_END;
  4739. cvs_start_record.rec_mode.tx_tap_point =
  4740. VSS_IRECORD_TAP_POINT_STREAM_END;
  4741. } else {
  4742. pr_err("%s: Invalid in-call rec_mode %d\n", __func__,
  4743. rec_mode);
  4744. ret = -EINVAL;
  4745. goto fail;
  4746. }
  4747. v->cvs_state = CMD_STATUS_FAIL;
  4748. v->async_err = 0;
  4749. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_record);
  4750. if (ret < 0) {
  4751. pr_err("%s: Error %d sending START_RECORD\n", __func__,
  4752. ret);
  4753. goto fail;
  4754. }
  4755. ret = wait_event_timeout(v->cvs_wait,
  4756. (v->cvs_state == CMD_STATUS_SUCCESS),
  4757. msecs_to_jiffies(TIMEOUT_MS));
  4758. if (!ret) {
  4759. pr_err("%s: wait_event timeout\n", __func__);
  4760. goto fail;
  4761. }
  4762. if (v->async_err > 0) {
  4763. pr_err("%s: DSP returned error[%s]\n",
  4764. __func__, adsp_err_get_err_str(
  4765. v->async_err));
  4766. ret = adsp_err_get_lnx_err_code(
  4767. v->async_err);
  4768. goto fail;
  4769. }
  4770. v->rec_info.recording = 1;
  4771. } else {
  4772. pr_debug("%s: Start record already sent\n", __func__);
  4773. }
  4774. return 0;
  4775. fail:
  4776. return ret;
  4777. }
  4778. static int voice_cvs_stop_record(struct voice_data *v)
  4779. {
  4780. int ret = 0;
  4781. void *apr_cvs;
  4782. u16 cvs_handle;
  4783. struct apr_hdr cvs_stop_record;
  4784. if (v == NULL) {
  4785. pr_err("%s: v is NULL\n", __func__);
  4786. return -EINVAL;
  4787. }
  4788. apr_cvs = common.apr_q6_cvs;
  4789. if (!apr_cvs) {
  4790. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4791. return -EINVAL;
  4792. }
  4793. cvs_handle = voice_get_cvs_handle(v);
  4794. if (v->rec_info.recording) {
  4795. cvs_stop_record.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4796. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4797. cvs_stop_record.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4798. sizeof(cvs_stop_record) - APR_HDR_SIZE);
  4799. cvs_stop_record.src_port =
  4800. voice_get_idx_for_session(v->session_id);
  4801. cvs_stop_record.dest_port = cvs_handle;
  4802. cvs_stop_record.token = 0;
  4803. cvs_stop_record.opcode = VSS_IRECORD_CMD_STOP;
  4804. v->cvs_state = CMD_STATUS_FAIL;
  4805. v->async_err = 0;
  4806. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_record);
  4807. if (ret < 0) {
  4808. pr_err("%s: Error %d sending STOP_RECORD\n",
  4809. __func__, ret);
  4810. goto fail;
  4811. }
  4812. ret = wait_event_timeout(v->cvs_wait,
  4813. (v->cvs_state == CMD_STATUS_SUCCESS),
  4814. msecs_to_jiffies(TIMEOUT_MS));
  4815. if (!ret) {
  4816. pr_err("%s: wait_event timeout\n", __func__);
  4817. goto fail;
  4818. }
  4819. if (v->async_err > 0) {
  4820. pr_err("%s: DSP returned error[%s]\n",
  4821. __func__, adsp_err_get_err_str(
  4822. v->async_err));
  4823. ret = adsp_err_get_lnx_err_code(
  4824. v->async_err);
  4825. goto fail;
  4826. }
  4827. v->rec_info.recording = 0;
  4828. } else {
  4829. pr_debug("%s: Stop record already sent\n", __func__);
  4830. }
  4831. return 0;
  4832. fail:
  4833. return ret;
  4834. }
  4835. int voc_start_record(uint32_t port_id, uint32_t set, uint32_t session_id)
  4836. {
  4837. int ret = 0;
  4838. int rec_mode = 0;
  4839. u16 cvs_handle;
  4840. int rec_set = 0;
  4841. struct voice_session_itr itr;
  4842. struct voice_data *v = NULL;
  4843. /* check if session_id is valid */
  4844. if (!voice_is_valid_session_id(session_id)) {
  4845. pr_err("%s: Invalid session id:%u\n", __func__,
  4846. session_id);
  4847. return -EINVAL;
  4848. }
  4849. voice_itr_init(&itr, session_id);
  4850. pr_debug("%s: session_id:%u\n", __func__, session_id);
  4851. while (voice_itr_get_next_session(&itr, &v)) {
  4852. if (v == NULL) {
  4853. pr_err("%s: v is NULL, sessionid:%u\n", __func__,
  4854. session_id);
  4855. break;
  4856. }
  4857. pr_debug("%s: port_id: %d, set: %d, v: %pK\n",
  4858. __func__, port_id, set, v);
  4859. mutex_lock(&v->lock);
  4860. rec_mode = v->rec_info.rec_mode;
  4861. rec_set = set;
  4862. if (set) {
  4863. if ((v->rec_route_state.ul_flag != 0) &&
  4864. (v->rec_route_state.dl_flag != 0)) {
  4865. pr_debug("%s: rec mode already set.\n",
  4866. __func__);
  4867. mutex_unlock(&v->lock);
  4868. continue;
  4869. }
  4870. if (port_id == VOICE_RECORD_TX) {
  4871. if ((v->rec_route_state.ul_flag == 0)
  4872. && (v->rec_route_state.dl_flag == 0)) {
  4873. rec_mode = VOC_REC_UPLINK;
  4874. v->rec_route_state.ul_flag = 1;
  4875. } else if ((v->rec_route_state.ul_flag == 0)
  4876. && (v->rec_route_state.dl_flag != 0)) {
  4877. voice_cvs_stop_record(v);
  4878. rec_mode = VOC_REC_BOTH;
  4879. v->rec_route_state.ul_flag = 1;
  4880. }
  4881. } else if (port_id == VOICE_RECORD_RX) {
  4882. if ((v->rec_route_state.ul_flag == 0)
  4883. && (v->rec_route_state.dl_flag == 0)) {
  4884. rec_mode = VOC_REC_DOWNLINK;
  4885. v->rec_route_state.dl_flag = 1;
  4886. } else if ((v->rec_route_state.ul_flag != 0)
  4887. && (v->rec_route_state.dl_flag == 0)) {
  4888. voice_cvs_stop_record(v);
  4889. rec_mode = VOC_REC_BOTH;
  4890. v->rec_route_state.dl_flag = 1;
  4891. }
  4892. }
  4893. rec_set = 1;
  4894. } else {
  4895. if ((v->rec_route_state.ul_flag == 0) &&
  4896. (v->rec_route_state.dl_flag == 0)) {
  4897. pr_debug("%s: rec already stops.\n",
  4898. __func__);
  4899. mutex_unlock(&v->lock);
  4900. continue;
  4901. }
  4902. if (port_id == VOICE_RECORD_TX) {
  4903. if ((v->rec_route_state.ul_flag != 0)
  4904. && (v->rec_route_state.dl_flag == 0)) {
  4905. v->rec_route_state.ul_flag = 0;
  4906. rec_set = 0;
  4907. } else if ((v->rec_route_state.ul_flag != 0)
  4908. && (v->rec_route_state.dl_flag != 0)) {
  4909. voice_cvs_stop_record(v);
  4910. v->rec_route_state.ul_flag = 0;
  4911. rec_mode = VOC_REC_DOWNLINK;
  4912. rec_set = 1;
  4913. }
  4914. } else if (port_id == VOICE_RECORD_RX) {
  4915. if ((v->rec_route_state.ul_flag == 0)
  4916. && (v->rec_route_state.dl_flag != 0)) {
  4917. v->rec_route_state.dl_flag = 0;
  4918. rec_set = 0;
  4919. } else if ((v->rec_route_state.ul_flag != 0)
  4920. && (v->rec_route_state.dl_flag != 0)) {
  4921. voice_cvs_stop_record(v);
  4922. v->rec_route_state.dl_flag = 0;
  4923. rec_mode = VOC_REC_UPLINK;
  4924. rec_set = 1;
  4925. }
  4926. }
  4927. }
  4928. pr_debug("%s: mode =%d, set =%d\n", __func__,
  4929. rec_mode, rec_set);
  4930. cvs_handle = voice_get_cvs_handle(v);
  4931. if (cvs_handle != 0) {
  4932. if (rec_set)
  4933. ret = voice_cvs_start_record(v, rec_mode);
  4934. else
  4935. ret = voice_cvs_stop_record(v);
  4936. }
  4937. /* During SRVCC, recording will switch from VoLTE session to
  4938. * voice session.
  4939. * Then stop recording, need to stop recording on voice session.
  4940. */
  4941. if ((!rec_set) && common.srvcc_rec_flag) {
  4942. pr_debug("%s, srvcc_rec_flag:%d\n", __func__,
  4943. common.srvcc_rec_flag);
  4944. voice_cvs_stop_record(&common.voice[VOC_PATH_PASSIVE]);
  4945. common.srvcc_rec_flag = false;
  4946. }
  4947. /* Cache the value */
  4948. v->rec_info.rec_enable = rec_set;
  4949. v->rec_info.rec_mode = rec_mode;
  4950. mutex_unlock(&v->lock);
  4951. }
  4952. return ret;
  4953. }
  4954. static int voice_cvs_start_playback(struct voice_data *v)
  4955. {
  4956. int ret = 0;
  4957. struct cvs_start_playback_cmd cvs_start_playback;
  4958. void *apr_cvs;
  4959. u16 cvs_handle;
  4960. if (v == NULL) {
  4961. pr_err("%s: v is NULL\n", __func__);
  4962. return -EINVAL;
  4963. }
  4964. apr_cvs = common.apr_q6_cvs;
  4965. if (!apr_cvs) {
  4966. pr_err("%s: apr_cvs is NULL.\n", __func__);
  4967. return -EINVAL;
  4968. }
  4969. cvs_handle = voice_get_cvs_handle(v);
  4970. if (!v->music_info.playing && v->music_info.count) {
  4971. cvs_start_playback.hdr.hdr_field = APR_HDR_FIELD(
  4972. APR_MSG_TYPE_SEQ_CMD,
  4973. APR_HDR_LEN(APR_HDR_SIZE),
  4974. APR_PKT_VER);
  4975. cvs_start_playback.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4976. sizeof(cvs_start_playback) - APR_HDR_SIZE);
  4977. cvs_start_playback.hdr.src_port =
  4978. voice_get_idx_for_session(v->session_id);
  4979. cvs_start_playback.hdr.dest_port = cvs_handle;
  4980. cvs_start_playback.hdr.token = 0;
  4981. cvs_start_playback.hdr.opcode = VSS_IPLAYBACK_CMD_START;
  4982. cvs_start_playback.playback_mode.port_id =
  4983. v->music_info.port_id;
  4984. v->cvs_state = CMD_STATUS_FAIL;
  4985. v->async_err = 0;
  4986. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
  4987. if (ret < 0) {
  4988. pr_err("%s: Error %d sending START_PLAYBACK\n",
  4989. __func__, ret);
  4990. goto fail;
  4991. }
  4992. ret = wait_event_timeout(v->cvs_wait,
  4993. (v->cvs_state == CMD_STATUS_SUCCESS),
  4994. msecs_to_jiffies(TIMEOUT_MS));
  4995. if (!ret) {
  4996. pr_err("%s: wait_event timeout\n", __func__);
  4997. goto fail;
  4998. }
  4999. if (v->async_err > 0) {
  5000. pr_err("%s: DSP returned error[%s]\n",
  5001. __func__, adsp_err_get_err_str(
  5002. v->async_err));
  5003. ret = adsp_err_get_lnx_err_code(
  5004. v->async_err);
  5005. goto fail;
  5006. }
  5007. v->music_info.playing = 1;
  5008. } else {
  5009. pr_debug("%s: Start playback already sent\n", __func__);
  5010. }
  5011. return 0;
  5012. fail:
  5013. return ret;
  5014. }
  5015. static int voice_cvs_stop_playback(struct voice_data *v)
  5016. {
  5017. int ret = 0;
  5018. struct apr_hdr cvs_stop_playback;
  5019. void *apr_cvs;
  5020. u16 cvs_handle;
  5021. if (v == NULL) {
  5022. pr_err("%s: v is NULL\n", __func__);
  5023. return -EINVAL;
  5024. }
  5025. apr_cvs = common.apr_q6_cvs;
  5026. if (!apr_cvs) {
  5027. pr_err("%s: apr_cvs is NULL.\n", __func__);
  5028. return -EINVAL;
  5029. }
  5030. cvs_handle = voice_get_cvs_handle(v);
  5031. if (v->music_info.playing && ((!v->music_info.count) ||
  5032. (v->music_info.force))) {
  5033. cvs_stop_playback.hdr_field =
  5034. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  5035. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  5036. cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  5037. sizeof(cvs_stop_playback) - APR_HDR_SIZE);
  5038. cvs_stop_playback.src_port =
  5039. voice_get_idx_for_session(v->session_id);
  5040. cvs_stop_playback.dest_port = cvs_handle;
  5041. cvs_stop_playback.token = 0;
  5042. cvs_stop_playback.opcode = VSS_IPLAYBACK_CMD_STOP;
  5043. v->cvs_state = CMD_STATUS_FAIL;
  5044. v->async_err = 0;
  5045. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
  5046. if (ret < 0) {
  5047. pr_err("%s: Error %d sending STOP_PLAYBACK\n",
  5048. __func__, ret);
  5049. goto fail;
  5050. }
  5051. ret = wait_event_timeout(v->cvs_wait,
  5052. (v->cvs_state == CMD_STATUS_SUCCESS),
  5053. msecs_to_jiffies(TIMEOUT_MS));
  5054. if (!ret) {
  5055. pr_err("%s: wait_event timeout\n", __func__);
  5056. goto fail;
  5057. }
  5058. if (v->async_err > 0) {
  5059. pr_err("%s: DSP returned error[%s]\n",
  5060. __func__, adsp_err_get_err_str(
  5061. v->async_err));
  5062. ret = adsp_err_get_lnx_err_code(
  5063. v->async_err);
  5064. goto fail;
  5065. }
  5066. v->music_info.playing = 0;
  5067. v->music_info.force = 0;
  5068. } else {
  5069. pr_debug("%s: Stop playback already sent\n", __func__);
  5070. }
  5071. return 0;
  5072. fail:
  5073. return ret;
  5074. }
  5075. static int voc_lch_ops(struct voice_data *v, enum voice_lch_mode lch_mode)
  5076. {
  5077. int ret = 0;
  5078. if (v == NULL) {
  5079. pr_err("%s: v is NULL\n", __func__);
  5080. ret = -EINVAL;
  5081. goto done;
  5082. }
  5083. switch (lch_mode) {
  5084. case VOICE_LCH_START:
  5085. ret = voc_end_voice_call(v->session_id);
  5086. if (ret < 0)
  5087. pr_err("%s: voice call end failed %d\n",
  5088. __func__, ret);
  5089. break;
  5090. case VOICE_LCH_STOP:
  5091. ret = voc_start_voice_call(v->session_id);
  5092. if (ret < 0) {
  5093. pr_err("%s: voice call start failed %d\n",
  5094. __func__, ret);
  5095. goto done;
  5096. }
  5097. break;
  5098. default:
  5099. pr_err("%s: Invalid LCH mode: %d\n",
  5100. __func__, v->lch_mode);
  5101. break;
  5102. }
  5103. done:
  5104. return ret;
  5105. }
  5106. int voc_start_playback(uint32_t set, uint16_t port_id)
  5107. {
  5108. struct voice_data *v = NULL;
  5109. int ret = 0;
  5110. struct voice_session_itr itr;
  5111. u16 cvs_handle;
  5112. pr_debug("%s port_id = %#x set = %d", __func__, port_id, set);
  5113. voice_itr_init(&itr, ALL_SESSION_VSID);
  5114. while (voice_itr_get_next_session(&itr, &v)) {
  5115. if ((v != NULL) &&
  5116. (((port_id == VOICE_PLAYBACK_TX) &&
  5117. is_sub1_vsid(v->session_id)) ||
  5118. ((port_id == VOICE2_PLAYBACK_TX) &&
  5119. is_sub2_vsid(v->session_id)))) {
  5120. mutex_lock(&v->lock);
  5121. v->music_info.port_id = port_id;
  5122. v->music_info.play_enable = set;
  5123. if (set)
  5124. v->music_info.count++;
  5125. else
  5126. v->music_info.count--;
  5127. pr_debug("%s: music_info count=%d\n", __func__,
  5128. v->music_info.count);
  5129. cvs_handle = voice_get_cvs_handle(v);
  5130. if (cvs_handle != 0) {
  5131. if (set)
  5132. ret = voice_cvs_start_playback(v);
  5133. else
  5134. ret = voice_cvs_stop_playback(v);
  5135. }
  5136. mutex_unlock(&v->lock);
  5137. } else {
  5138. pr_err("%s: Invalid session\n", __func__);
  5139. }
  5140. }
  5141. return ret;
  5142. }
  5143. int voc_disable_topology(uint32_t session_id, uint32_t disable)
  5144. {
  5145. struct voice_data *v = voice_get_session(session_id);
  5146. int ret = 0;
  5147. if (v == NULL) {
  5148. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5149. return -EINVAL;
  5150. }
  5151. mutex_lock(&v->lock);
  5152. v->disable_topology = disable;
  5153. mutex_unlock(&v->lock);
  5154. return ret;
  5155. }
  5156. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  5157. uint32_t mode)
  5158. {
  5159. struct voice_data *v = voice_get_session(session_id);
  5160. int ret = 0;
  5161. if (v == NULL) {
  5162. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5163. return -EINVAL;
  5164. }
  5165. if (v->voc_state != VOC_RUN)
  5166. ret = voice_send_cvs_data_exchange_mode_cmd(v);
  5167. if (ret) {
  5168. pr_err("%s: Error voice_send_data_exchange_mode_cmd %d\n",
  5169. __func__, ret);
  5170. goto fail;
  5171. }
  5172. ret = voice_send_cvs_packet_exchange_config_cmd(v);
  5173. if (ret) {
  5174. pr_err("%s: Error: voice_send_packet_exchange_config_cmd %d\n",
  5175. __func__, ret);
  5176. goto fail;
  5177. }
  5178. return ret;
  5179. fail:
  5180. return -EINVAL;
  5181. }
  5182. int voc_set_tx_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  5183. uint32_t ramp_duration)
  5184. {
  5185. struct voice_data *v = NULL;
  5186. int ret = 0;
  5187. struct voice_session_itr itr;
  5188. voice_itr_init(&itr, session_id);
  5189. while (voice_itr_get_next_session(&itr, &v)) {
  5190. if (v != NULL) {
  5191. mutex_lock(&v->lock);
  5192. v->stream_tx.stream_mute = mute;
  5193. v->stream_tx.stream_mute_ramp_duration_ms =
  5194. ramp_duration;
  5195. if (is_voc_state_active(v->voc_state) &&
  5196. (v->lch_mode == 0))
  5197. ret = voice_send_stream_mute_cmd(v,
  5198. VSS_IVOLUME_DIRECTION_TX,
  5199. v->stream_tx.stream_mute,
  5200. v->stream_tx.stream_mute_ramp_duration_ms);
  5201. mutex_unlock(&v->lock);
  5202. } else {
  5203. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5204. session_id);
  5205. ret = -EINVAL;
  5206. break;
  5207. }
  5208. }
  5209. return ret;
  5210. }
  5211. int voc_set_device_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  5212. uint32_t ramp_duration)
  5213. {
  5214. struct voice_data *v = NULL;
  5215. int ret = 0;
  5216. struct voice_session_itr itr;
  5217. voice_itr_init(&itr, session_id);
  5218. while (voice_itr_get_next_session(&itr, &v)) {
  5219. if (v != NULL) {
  5220. mutex_lock(&v->lock);
  5221. if (dir == VSS_IVOLUME_DIRECTION_TX) {
  5222. v->dev_tx.dev_mute = mute;
  5223. v->dev_tx.dev_mute_ramp_duration_ms =
  5224. ramp_duration;
  5225. } else {
  5226. v->dev_rx.dev_mute = mute;
  5227. v->dev_rx.dev_mute_ramp_duration_ms =
  5228. ramp_duration;
  5229. }
  5230. if (((v->voc_state == VOC_RUN) ||
  5231. (v->voc_state == VOC_STANDBY)) &&
  5232. (v->lch_mode == 0))
  5233. ret = voice_send_device_mute_cmd(v,
  5234. dir,
  5235. mute,
  5236. ramp_duration);
  5237. mutex_unlock(&v->lock);
  5238. } else {
  5239. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5240. session_id);
  5241. ret = -EINVAL;
  5242. break;
  5243. }
  5244. }
  5245. return ret;
  5246. }
  5247. int voc_get_rx_device_mute(uint32_t session_id)
  5248. {
  5249. struct voice_data *v = voice_get_session(session_id);
  5250. int ret = 0;
  5251. if (v == NULL) {
  5252. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5253. return -EINVAL;
  5254. }
  5255. mutex_lock(&v->lock);
  5256. ret = v->dev_rx.dev_mute;
  5257. mutex_unlock(&v->lock);
  5258. return ret;
  5259. }
  5260. int voc_set_tty_mode(uint32_t session_id, uint8_t tty_mode)
  5261. {
  5262. struct voice_data *v = voice_get_session(session_id);
  5263. int ret = 0;
  5264. if (v == NULL) {
  5265. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5266. return -EINVAL;
  5267. }
  5268. mutex_lock(&v->lock);
  5269. v->tty_mode = tty_mode;
  5270. mutex_unlock(&v->lock);
  5271. return ret;
  5272. }
  5273. uint8_t voc_get_tty_mode(uint32_t session_id)
  5274. {
  5275. struct voice_data *v = voice_get_session(session_id);
  5276. int ret = 0;
  5277. if (v == NULL) {
  5278. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5279. return -EINVAL;
  5280. }
  5281. mutex_lock(&v->lock);
  5282. ret = v->tty_mode;
  5283. mutex_unlock(&v->lock);
  5284. return ret;
  5285. }
  5286. int voc_set_pp_enable(uint32_t session_id, uint32_t module_id, uint32_t enable)
  5287. {
  5288. struct voice_data *v = NULL;
  5289. int ret = 0;
  5290. struct voice_session_itr itr;
  5291. voice_itr_init(&itr, session_id);
  5292. while (voice_itr_get_next_session(&itr, &v)) {
  5293. if (v != NULL) {
  5294. if (!(is_voice_app_id(v->session_id)))
  5295. continue;
  5296. mutex_lock(&v->lock);
  5297. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  5298. v->st_enable = enable;
  5299. if (v->voc_state == VOC_RUN) {
  5300. if ((module_id == MODULE_ID_VOICE_MODULE_ST) &&
  5301. (!v->tty_mode))
  5302. ret = voice_send_set_pp_enable_cmd(v,
  5303. MODULE_ID_VOICE_MODULE_ST,
  5304. enable);
  5305. }
  5306. mutex_unlock(&v->lock);
  5307. } else {
  5308. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5309. session_id);
  5310. ret = -EINVAL;
  5311. break;
  5312. }
  5313. }
  5314. return ret;
  5315. }
  5316. int voc_set_hd_enable(uint32_t session_id, uint32_t enable)
  5317. {
  5318. struct voice_data *v = NULL;
  5319. int ret = 0;
  5320. struct voice_session_itr itr;
  5321. voice_itr_init(&itr, session_id);
  5322. while (voice_itr_get_next_session(&itr, &v)) {
  5323. if (v != NULL) {
  5324. mutex_lock(&v->lock);
  5325. v->hd_enable = enable;
  5326. if (v->voc_state == VOC_RUN)
  5327. ret = voice_send_hd_cmd(v, enable);
  5328. mutex_unlock(&v->lock);
  5329. } else {
  5330. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5331. session_id);
  5332. ret = -EINVAL;
  5333. break;
  5334. }
  5335. }
  5336. return ret;
  5337. }
  5338. int voc_set_afe_sidetone(uint32_t session_id, bool sidetone_enable)
  5339. {
  5340. struct voice_data *v = NULL;
  5341. int ret = -EINVAL;
  5342. struct voice_session_itr itr;
  5343. u16 rx_port, tx_port;
  5344. common.sidetone_enable = sidetone_enable;
  5345. voice_itr_init(&itr, session_id);
  5346. while (voice_itr_get_next_session(&itr, &v)) {
  5347. if (v == NULL) {
  5348. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5349. session_id);
  5350. ret = -EINVAL;
  5351. break;
  5352. }
  5353. mutex_lock(&v->lock);
  5354. if (v->voc_state != VOC_RUN) {
  5355. mutex_unlock(&v->lock);
  5356. continue;
  5357. }
  5358. rx_port = v->dev_rx.port_id;
  5359. tx_port = v->dev_tx.port_id;
  5360. ret = afe_sidetone_enable(tx_port, rx_port,
  5361. sidetone_enable);
  5362. if (!ret) {
  5363. mutex_unlock(&v->lock);
  5364. break;
  5365. }
  5366. mutex_unlock(&v->lock);
  5367. }
  5368. return ret;
  5369. }
  5370. bool voc_get_afe_sidetone(void)
  5371. {
  5372. bool ret;
  5373. ret = common.sidetone_enable;
  5374. return ret;
  5375. }
  5376. int voc_get_pp_enable(uint32_t session_id, uint32_t module_id)
  5377. {
  5378. struct voice_data *v = voice_get_session(session_id);
  5379. int ret = 0;
  5380. if (v == NULL) {
  5381. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5382. return -EINVAL;
  5383. }
  5384. mutex_lock(&v->lock);
  5385. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  5386. ret = v->st_enable;
  5387. mutex_unlock(&v->lock);
  5388. return ret;
  5389. }
  5390. int voc_set_rx_vol_step(uint32_t session_id, uint32_t dir, uint32_t vol_step,
  5391. uint32_t ramp_duration)
  5392. {
  5393. struct voice_data *v = NULL;
  5394. int ret = 0;
  5395. struct voice_session_itr itr;
  5396. pr_debug("%s session id = %#x vol = %u", __func__, session_id,
  5397. vol_step);
  5398. voice_itr_init(&itr, session_id);
  5399. while (voice_itr_get_next_session(&itr, &v)) {
  5400. if (v != NULL) {
  5401. mutex_lock(&v->lock);
  5402. v->dev_rx.volume_step_value = vol_step;
  5403. v->dev_rx.volume_ramp_duration_ms = ramp_duration;
  5404. if (is_voc_state_active(v->voc_state))
  5405. ret = voice_send_vol_step_cmd(v);
  5406. mutex_unlock(&v->lock);
  5407. } else {
  5408. pr_err("%s: invalid session_id 0x%x\n", __func__,
  5409. session_id);
  5410. ret = -EINVAL;
  5411. break;
  5412. }
  5413. }
  5414. return ret;
  5415. }
  5416. int voc_set_device_config(uint32_t session_id, uint8_t path_dir,
  5417. struct media_format_info *finfo)
  5418. {
  5419. struct voice_data *v = voice_get_session(session_id);
  5420. if (v == NULL) {
  5421. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  5422. return -EINVAL;
  5423. }
  5424. pr_debug("%s: path_dir=%d port_id=%x, channels=%d, sample_rate=%d, bits_per_sample=%d\n",
  5425. __func__, path_dir, finfo->port_id, finfo->num_channels,
  5426. finfo->sample_rate, finfo->bits_per_sample);
  5427. mutex_lock(&v->lock);
  5428. switch (path_dir) {
  5429. case RX_PATH:
  5430. v->dev_rx.port_id = q6audio_get_port_id(finfo->port_id);
  5431. v->dev_rx.no_of_channels = finfo->num_channels;
  5432. v->dev_rx.sample_rate = finfo->sample_rate;
  5433. v->dev_rx.bits_per_sample = finfo->bits_per_sample;
  5434. memcpy(&v->dev_rx.channel_mapping, &finfo->channel_mapping,
  5435. VSS_CHANNEL_MAPPING_SIZE);
  5436. break;
  5437. case TX_PATH:
  5438. v->dev_tx.port_id = q6audio_get_port_id(finfo->port_id);
  5439. v->dev_tx.no_of_channels = finfo->num_channels;
  5440. v->dev_tx.sample_rate = finfo->sample_rate;
  5441. v->dev_tx.bits_per_sample = finfo->bits_per_sample;
  5442. memcpy(&v->dev_tx.channel_mapping, &finfo->channel_mapping,
  5443. VSS_CHANNEL_MAPPING_SIZE);
  5444. break;
  5445. default:
  5446. pr_err("%s: Invalid path_dir %d\n", __func__, path_dir);
  5447. return -EINVAL;
  5448. }
  5449. mutex_unlock(&v->lock);
  5450. return 0;
  5451. }
  5452. int voc_set_ext_ec_ref_media_fmt_info(struct media_format_info *finfo)
  5453. {
  5454. mutex_lock(&common.common_lock);
  5455. if (common.ec_ref_ext) {
  5456. common.ec_media_fmt_info.num_channels = finfo->num_channels;
  5457. common.ec_media_fmt_info.bits_per_sample =
  5458. finfo->bits_per_sample;
  5459. common.ec_media_fmt_info.sample_rate = finfo->sample_rate;
  5460. memcpy(&common.ec_media_fmt_info.channel_mapping,
  5461. &finfo->channel_mapping, VSS_CHANNEL_MAPPING_SIZE);
  5462. } else {
  5463. pr_debug("%s: Ext Ec Ref not active, returning", __func__);
  5464. }
  5465. mutex_unlock(&common.common_lock);
  5466. return 0;
  5467. }
  5468. int voc_set_route_flag(uint32_t session_id, uint8_t path_dir, uint8_t set)
  5469. {
  5470. struct voice_data *v = voice_get_session(session_id);
  5471. if (v == NULL) {
  5472. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5473. return -EINVAL;
  5474. }
  5475. pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
  5476. mutex_lock(&v->lock);
  5477. if (path_dir == RX_PATH)
  5478. v->voc_route_state.rx_route_flag = set;
  5479. else
  5480. v->voc_route_state.tx_route_flag = set;
  5481. mutex_unlock(&v->lock);
  5482. return 0;
  5483. }
  5484. uint8_t voc_get_route_flag(uint32_t session_id, uint8_t path_dir)
  5485. {
  5486. struct voice_data *v = voice_get_session(session_id);
  5487. int ret = 0;
  5488. if (v == NULL) {
  5489. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5490. return 0;
  5491. }
  5492. mutex_lock(&v->lock);
  5493. if (path_dir == RX_PATH)
  5494. ret = v->voc_route_state.rx_route_flag;
  5495. else
  5496. ret = v->voc_route_state.tx_route_flag;
  5497. mutex_unlock(&v->lock);
  5498. return ret;
  5499. }
  5500. int voc_end_voice_call(uint32_t session_id)
  5501. {
  5502. struct voice_data *v = voice_get_session(session_id);
  5503. int ret = 0;
  5504. if (v == NULL) {
  5505. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5506. return -EINVAL;
  5507. }
  5508. mutex_lock(&v->lock);
  5509. if (v->voc_state == VOC_RUN || v->voc_state == VOC_ERROR ||
  5510. v->voc_state == VOC_CHANGE || v->voc_state == VOC_STANDBY) {
  5511. pr_debug("%s: VOC_STATE: %d\n", __func__, v->voc_state);
  5512. ret = voice_destroy_vocproc(v);
  5513. if (ret < 0)
  5514. pr_err("%s: destroy voice failed\n", __func__);
  5515. voc_update_session_params(v);
  5516. voice_destroy_mvm_cvs_session(v);
  5517. v->voc_state = VOC_RELEASE;
  5518. } else {
  5519. pr_err("%s: Error: End voice called in state %d\n",
  5520. __func__, v->voc_state);
  5521. ret = -EINVAL;
  5522. }
  5523. mutex_unlock(&v->lock);
  5524. return ret;
  5525. }
  5526. int voc_standby_voice_call(uint32_t session_id)
  5527. {
  5528. struct voice_data *v = voice_get_session(session_id);
  5529. struct apr_hdr mvm_standby_voice_cmd;
  5530. void *apr_mvm;
  5531. u16 mvm_handle;
  5532. int ret = 0;
  5533. if (v == NULL) {
  5534. pr_err("%s: v is NULL\n", __func__);
  5535. return -EINVAL;
  5536. }
  5537. pr_debug("%s: voc state=%d", __func__, v->voc_state);
  5538. if (v->voc_state == VOC_RUN) {
  5539. apr_mvm = common.apr_q6_mvm;
  5540. if (!apr_mvm) {
  5541. pr_err("%s: apr_mvm is NULL.\n", __func__);
  5542. ret = -EINVAL;
  5543. goto fail;
  5544. }
  5545. mvm_handle = voice_get_mvm_handle(v);
  5546. mvm_standby_voice_cmd.hdr_field =
  5547. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  5548. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  5549. mvm_standby_voice_cmd.pkt_size =
  5550. APR_PKT_SIZE(APR_HDR_SIZE,
  5551. sizeof(mvm_standby_voice_cmd) - APR_HDR_SIZE);
  5552. pr_debug("send mvm_standby_voice_cmd pkt size = %d\n",
  5553. mvm_standby_voice_cmd.pkt_size);
  5554. mvm_standby_voice_cmd.src_port =
  5555. voice_get_idx_for_session(v->session_id);
  5556. mvm_standby_voice_cmd.dest_port = mvm_handle;
  5557. mvm_standby_voice_cmd.token = 0;
  5558. mvm_standby_voice_cmd.opcode = VSS_IMVM_CMD_STANDBY_VOICE;
  5559. v->mvm_state = CMD_STATUS_FAIL;
  5560. ret = apr_send_pkt(apr_mvm,
  5561. (uint32_t *)&mvm_standby_voice_cmd);
  5562. if (ret < 0) {
  5563. pr_err("Fail in sending VSS_IMVM_CMD_STANDBY_VOICE\n");
  5564. ret = -EINVAL;
  5565. goto fail;
  5566. }
  5567. v->voc_state = VOC_STANDBY;
  5568. }
  5569. fail:
  5570. return ret;
  5571. }
  5572. int voc_disable_device(uint32_t session_id)
  5573. {
  5574. struct voice_data *v = voice_get_session(session_id);
  5575. int ret = 0;
  5576. if (v == NULL) {
  5577. pr_err("%s: v is NULL\n", __func__);
  5578. return -EINVAL;
  5579. }
  5580. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  5581. mutex_lock(&v->lock);
  5582. if (v->voc_state == VOC_RUN) {
  5583. ret = voice_pause_voice_call(v);
  5584. if (ret < 0) {
  5585. pr_err("%s: Pause Voice Call failed for session 0x%x, err %d!\n",
  5586. __func__, v->session_id, ret);
  5587. goto done;
  5588. }
  5589. rtac_remove_voice(voice_get_cvs_handle(v));
  5590. voice_send_cvp_deregister_vol_cal_cmd(v);
  5591. voice_send_cvp_deregister_cal_cmd(v);
  5592. voice_send_cvp_deregister_dev_cfg_cmd(v);
  5593. v->voc_state = VOC_CHANGE;
  5594. } else {
  5595. pr_debug("%s: called in voc state=%d, No_OP\n",
  5596. __func__, v->voc_state);
  5597. }
  5598. done:
  5599. mutex_unlock(&v->lock);
  5600. return ret;
  5601. }
  5602. int voc_enable_device(uint32_t session_id)
  5603. {
  5604. struct voice_data *v = voice_get_session(session_id);
  5605. int ret = 0;
  5606. if (v == NULL) {
  5607. pr_err("%s: v is NULL\n", __func__);
  5608. return -EINVAL;
  5609. }
  5610. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  5611. mutex_lock(&v->lock);
  5612. if (v->voc_state == VOC_CHANGE) {
  5613. ret = voice_send_tty_mode_cmd(v);
  5614. if (ret < 0) {
  5615. pr_err("%s: Sending TTY mode failed, ret=%d\n",
  5616. __func__, ret);
  5617. /* Not a critical error, allow voice call to continue */
  5618. }
  5619. if (v->tty_mode) {
  5620. /* disable slowtalk */
  5621. voice_send_set_pp_enable_cmd(v,
  5622. MODULE_ID_VOICE_MODULE_ST,
  5623. 0);
  5624. } else {
  5625. /* restore slowtalk */
  5626. voice_send_set_pp_enable_cmd(v,
  5627. MODULE_ID_VOICE_MODULE_ST,
  5628. v->st_enable);
  5629. }
  5630. ret = voice_send_set_device_cmd(v);
  5631. if (ret < 0) {
  5632. pr_err("%s: Set device failed, ret=%d\n",
  5633. __func__, ret);
  5634. goto done;
  5635. }
  5636. ret = voice_send_cvp_media_fmt_info_cmd(v);
  5637. if (ret < 0) {
  5638. pr_err("%s: Set format failed err:%d\n", __func__, ret);
  5639. goto done;
  5640. }
  5641. ret = voice_send_cvp_topology_commit_cmd(v);
  5642. if (ret < 0) {
  5643. pr_err("%s: Set topology commit failed\n", __func__);
  5644. goto done;
  5645. }
  5646. /* Send MFC config only when the no of channels are > 1 */
  5647. if (v->dev_rx.no_of_channels > NUM_CHANNELS_MONO) {
  5648. ret = voice_send_cvp_mfc_config_cmd(v);
  5649. if (ret < 0) {
  5650. pr_warn("%s: Set mfc config failed err: %d\n",
  5651. __func__, ret);
  5652. }
  5653. }
  5654. voice_send_cvp_register_dev_cfg_cmd(v);
  5655. voice_send_cvp_register_cal_cmd(v);
  5656. voice_send_cvp_register_vol_cal_cmd(v);
  5657. rtac_add_voice(voice_get_cvs_handle(v),
  5658. voice_get_cvp_handle(v),
  5659. v->dev_rx.port_id, v->dev_tx.port_id,
  5660. v->dev_rx.dev_id, v->dev_tx.dev_id,
  5661. v->session_id);
  5662. ret = voice_send_start_voice_cmd(v);
  5663. if (ret < 0) {
  5664. pr_err("%s: Fail in sending START_VOICE, ret=%d\n",
  5665. __func__, ret);
  5666. goto done;
  5667. }
  5668. v->voc_state = VOC_RUN;
  5669. } else {
  5670. pr_debug("%s: called in voc state=%d, No_OP\n",
  5671. __func__, v->voc_state);
  5672. }
  5673. done:
  5674. mutex_unlock(&v->lock);
  5675. return ret;
  5676. }
  5677. int voc_set_lch(uint32_t session_id, enum voice_lch_mode lch_mode)
  5678. {
  5679. struct voice_data *v = voice_get_session(session_id);
  5680. int ret = 0;
  5681. if (v == NULL) {
  5682. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  5683. ret = -EINVAL;
  5684. goto done;
  5685. }
  5686. mutex_lock(&v->lock);
  5687. if (v->lch_mode == lch_mode) {
  5688. pr_debug("%s: Session %d already in LCH mode %d\n",
  5689. __func__, session_id, lch_mode);
  5690. mutex_unlock(&v->lock);
  5691. goto done;
  5692. }
  5693. v->lch_mode = lch_mode;
  5694. mutex_unlock(&v->lock);
  5695. ret = voc_lch_ops(v, v->lch_mode);
  5696. if (ret < 0) {
  5697. pr_err("%s: lch ops failed %d\n", __func__, ret);
  5698. goto done;
  5699. }
  5700. done:
  5701. return ret;
  5702. }
  5703. int voc_resume_voice_call(uint32_t session_id)
  5704. {
  5705. struct voice_data *v = voice_get_session(session_id);
  5706. int ret = 0;
  5707. ret = voice_send_start_voice_cmd(v);
  5708. if (ret < 0) {
  5709. pr_err("Fail in sending START_VOICE\n");
  5710. goto fail;
  5711. }
  5712. v->voc_state = VOC_RUN;
  5713. return 0;
  5714. fail:
  5715. return -EINVAL;
  5716. }
  5717. int voc_start_voice_call(uint32_t session_id)
  5718. {
  5719. struct voice_data *v = voice_get_session(session_id);
  5720. int ret = 0;
  5721. if (v == NULL) {
  5722. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  5723. return -EINVAL;
  5724. }
  5725. mutex_lock(&v->lock);
  5726. if (v->voc_state == VOC_ERROR) {
  5727. pr_debug("%s: VOC in ERR state\n", __func__);
  5728. voice_destroy_mvm_cvs_session(v);
  5729. v->voc_state = VOC_INIT;
  5730. }
  5731. if ((v->voc_state == VOC_INIT) ||
  5732. (v->voc_state == VOC_RELEASE)) {
  5733. ret = voice_apr_register(session_id);
  5734. if (ret < 0) {
  5735. pr_err("%s: apr register failed\n", __func__);
  5736. goto fail;
  5737. }
  5738. if (is_cvd_version_queried()) {
  5739. pr_debug("%s: Returning the cached value %s\n",
  5740. __func__, common.cvd_version);
  5741. } else {
  5742. ret = voice_send_mvm_cvd_version_cmd(v);
  5743. if (ret < 0)
  5744. pr_debug("%s: Error retrieving CVD version %d\n",
  5745. __func__, ret);
  5746. }
  5747. ret = voice_create_mvm_cvs_session(v);
  5748. if (ret < 0) {
  5749. pr_err("create mvm and cvs failed\n");
  5750. goto fail;
  5751. }
  5752. if (is_voip_session(session_id)) {
  5753. /* Allocate oob mem if not already allocated and
  5754. * memory map the oob memory block.
  5755. */
  5756. ret = voice_alloc_and_map_oob_mem(v);
  5757. if (ret < 0) {
  5758. pr_err("%s: voice_alloc_and_map_oob_mem() failed, ret:%d\n",
  5759. __func__, ret);
  5760. goto fail;
  5761. }
  5762. ret = voice_set_packet_exchange_mode_and_config(
  5763. session_id,
  5764. VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND);
  5765. if (ret) {
  5766. pr_err("%s: Err: exchange_mode_and_config %d\n",
  5767. __func__, ret);
  5768. goto fail;
  5769. }
  5770. }
  5771. ret = voice_send_dual_control_cmd(v);
  5772. if (ret < 0) {
  5773. pr_err("Err Dual command failed\n");
  5774. goto fail;
  5775. }
  5776. ret = voice_setup_vocproc(v);
  5777. if (ret < 0) {
  5778. pr_err("setup voice failed\n");
  5779. goto fail;
  5780. }
  5781. ret = voice_send_vol_step_cmd(v);
  5782. if (ret < 0)
  5783. pr_err("voice volume failed\n");
  5784. ret = voice_send_stream_mute_cmd(v,
  5785. VSS_IVOLUME_DIRECTION_TX,
  5786. v->stream_tx.stream_mute,
  5787. v->stream_tx.stream_mute_ramp_duration_ms);
  5788. if (ret < 0)
  5789. pr_err("voice mute failed\n");
  5790. ret = voice_send_start_voice_cmd(v);
  5791. if (ret < 0) {
  5792. pr_err("start voice failed\n");
  5793. goto fail;
  5794. }
  5795. v->voc_state = VOC_RUN;
  5796. } else {
  5797. pr_err("%s: Error: Start voice called in state %d\n",
  5798. __func__, v->voc_state);
  5799. ret = -EINVAL;
  5800. goto fail;
  5801. }
  5802. fail:
  5803. mutex_unlock(&v->lock);
  5804. return ret;
  5805. }
  5806. int voc_set_ext_ec_ref_port_id(uint16_t port_id, bool state)
  5807. {
  5808. int ret = 0;
  5809. mutex_lock(&common.common_lock);
  5810. if (state == true) {
  5811. if (port_id == AFE_PORT_INVALID) {
  5812. pr_err("%s: Invalid port id", __func__);
  5813. ret = -EINVAL;
  5814. goto exit;
  5815. }
  5816. common.ec_ref_ext = true;
  5817. } else {
  5818. common.ec_ref_ext = false;
  5819. }
  5820. /* Cache EC Fromat Info in common */
  5821. common.ec_media_fmt_info.port_id = port_id;
  5822. exit:
  5823. mutex_unlock(&common.common_lock);
  5824. return ret;
  5825. }
  5826. int voc_get_ext_ec_ref_port_id(void)
  5827. {
  5828. if (common.ec_ref_ext)
  5829. return common.ec_media_fmt_info.port_id;
  5830. else
  5831. return AFE_PORT_INVALID;
  5832. }
  5833. void voc_register_mvs_cb(ul_cb_fn ul_cb,
  5834. dl_cb_fn dl_cb,
  5835. voip_ssr_cb ssr_cb,
  5836. void *private_data)
  5837. {
  5838. common.mvs_info.ul_cb = ul_cb;
  5839. common.mvs_info.dl_cb = dl_cb;
  5840. common.mvs_info.ssr_cb = ssr_cb;
  5841. common.mvs_info.private_data = private_data;
  5842. }
  5843. void voc_register_dtmf_rx_detection_cb(dtmf_rx_det_cb_fn dtmf_rx_ul_cb,
  5844. void *private_data)
  5845. {
  5846. common.dtmf_info.dtmf_rx_ul_cb = dtmf_rx_ul_cb;
  5847. common.dtmf_info.private_data = private_data;
  5848. }
  5849. void voc_config_vocoder(uint32_t media_type,
  5850. uint32_t rate,
  5851. uint32_t network_type,
  5852. uint32_t dtx_mode,
  5853. uint32_t evrc_min_rate,
  5854. uint32_t evrc_max_rate)
  5855. {
  5856. common.mvs_info.media_type = media_type;
  5857. common.mvs_info.rate = rate;
  5858. common.mvs_info.network_type = network_type;
  5859. common.mvs_info.dtx_mode = dtx_mode;
  5860. common.mvs_info.evrc_min_rate = evrc_min_rate;
  5861. common.mvs_info.evrc_max_rate = evrc_max_rate;
  5862. }
  5863. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
  5864. {
  5865. uint32_t *ptr = NULL;
  5866. struct common_data *c = NULL;
  5867. struct voice_data *v = NULL;
  5868. int i = 0;
  5869. struct vss_iversion_rsp_get_t *version_rsp = NULL;
  5870. if ((data == NULL) || (priv == NULL)) {
  5871. pr_err("%s: data or priv is NULL\n", __func__);
  5872. return -EINVAL;
  5873. }
  5874. c = priv;
  5875. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  5876. data->payload_size, data->opcode);
  5877. if (data->opcode == RESET_EVENTS) {
  5878. pr_debug("%s: Reset event received in Voice service\n",
  5879. __func__);
  5880. if (common.mvs_info.ssr_cb) {
  5881. pr_debug("%s: Informing reset event to VoIP\n",
  5882. __func__);
  5883. common.mvs_info.ssr_cb(data->opcode,
  5884. common.mvs_info.private_data);
  5885. }
  5886. apr_reset(c->apr_q6_mvm);
  5887. c->apr_q6_mvm = NULL;
  5888. /* clean up memory handle */
  5889. c->cal_mem_handle = 0;
  5890. c->rtac_mem_handle = 0;
  5891. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  5892. common.cal_data);
  5893. rtac_clear_mapping(VOICE_RTAC_CAL);
  5894. /* Sub-system restart is applicable to all sessions. */
  5895. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  5896. c->voice[i].mvm_handle = 0;
  5897. c->voice[i].shmem_info.mem_handle = 0;
  5898. }
  5899. /* Free the ION memory and clear handles for Source Tracking */
  5900. if (is_source_tracking_shared_memomry_allocated()) {
  5901. msm_audio_ion_free(
  5902. common.source_tracking_sh_mem.sh_mem_block.client,
  5903. common.source_tracking_sh_mem.sh_mem_block.handle);
  5904. common.source_tracking_sh_mem.mem_handle = 0;
  5905. common.source_tracking_sh_mem.sh_mem_block.client =
  5906. NULL;
  5907. common.source_tracking_sh_mem.sh_mem_block.handle =
  5908. NULL;
  5909. }
  5910. /* clean up srvcc rec flag */
  5911. c->srvcc_rec_flag = false;
  5912. voc_set_error_state(data->reset_proc);
  5913. return 0;
  5914. }
  5915. pr_debug("%s: session_idx 0x%x\n", __func__, data->dest_port);
  5916. v = voice_get_session_by_idx(data->dest_port);
  5917. if (v == NULL) {
  5918. pr_err("%s: v is NULL\n", __func__);
  5919. return -EINVAL;
  5920. }
  5921. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5922. if (data->payload_size) {
  5923. ptr = data->payload;
  5924. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5925. /* ping mvm service ACK */
  5926. switch (ptr[0]) {
  5927. case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  5928. case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
  5929. /* Passive session is used for CS call
  5930. * Full session is used for VoIP call.
  5931. */
  5932. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5933. if (!ptr[1]) {
  5934. pr_debug("%s: MVM handle is %d\n",
  5935. __func__, data->src_port);
  5936. voice_set_mvm_handle(v, data->src_port);
  5937. } else
  5938. pr_err("got NACK for sending MVM create session\n");
  5939. v->mvm_state = CMD_STATUS_SUCCESS;
  5940. v->async_err = ptr[1];
  5941. wake_up(&v->mvm_wait);
  5942. break;
  5943. case VSS_IMVM_CMD_START_VOICE:
  5944. case VSS_IMVM_CMD_ATTACH_VOCPROC:
  5945. case VSS_IMVM_CMD_STOP_VOICE:
  5946. case VSS_IMVM_CMD_DETACH_VOCPROC:
  5947. case VSS_ISTREAM_CMD_SET_TTY_MODE:
  5948. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5949. case VSS_IMVM_CMD_ATTACH_STREAM:
  5950. case VSS_IMVM_CMD_DETACH_STREAM:
  5951. case VSS_ICOMMON_CMD_SET_NETWORK:
  5952. case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
  5953. case VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL:
  5954. case VSS_IMVM_CMD_SET_CAL_NETWORK:
  5955. case VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE:
  5956. case VSS_IMEMORY_CMD_MAP_PHYSICAL:
  5957. case VSS_IMEMORY_CMD_UNMAP:
  5958. case VSS_IMVM_CMD_PAUSE_VOICE:
  5959. case VSS_IMVM_CMD_STANDBY_VOICE:
  5960. case VSS_IHDVOICE_CMD_ENABLE:
  5961. case VSS_IHDVOICE_CMD_DISABLE:
  5962. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5963. v->mvm_state = CMD_STATUS_SUCCESS;
  5964. v->async_err = ptr[1];
  5965. wake_up(&v->mvm_wait);
  5966. break;
  5967. case VSS_IVERSION_CMD_GET:
  5968. pr_debug("%s: Error retrieving CVD Version, error:%d\n",
  5969. __func__, ptr[1]);
  5970. strlcpy(common.cvd_version, CVD_VERSION_0_0,
  5971. sizeof(common.cvd_version));
  5972. pr_debug("%s: Fall back to default value, CVD Version = %s\n",
  5973. __func__, common.cvd_version);
  5974. v->mvm_state = CMD_STATUS_SUCCESS;
  5975. v->async_err = ptr[1];
  5976. wake_up(&v->mvm_wait);
  5977. break;
  5978. default:
  5979. pr_debug("%s: not match cmd = 0x%x\n",
  5980. __func__, ptr[0]);
  5981. break;
  5982. }
  5983. }
  5984. } else if (data->opcode == VSS_IMEMORY_RSP_MAP) {
  5985. pr_debug("%s, Revd VSS_IMEMORY_RSP_MAP response\n", __func__);
  5986. if (data->payload_size && data->token == VOIP_MEM_MAP_TOKEN) {
  5987. ptr = data->payload;
  5988. if (ptr[0]) {
  5989. v->shmem_info.mem_handle = ptr[0];
  5990. pr_debug("%s: shared mem_handle: 0x[%x]\n",
  5991. __func__, v->shmem_info.mem_handle);
  5992. v->mvm_state = CMD_STATUS_SUCCESS;
  5993. wake_up(&v->mvm_wait);
  5994. }
  5995. } else if (data->payload_size &&
  5996. data->token == VOC_CAL_MEM_MAP_TOKEN) {
  5997. ptr = data->payload;
  5998. if (ptr[0]) {
  5999. c->cal_mem_handle = ptr[0];
  6000. pr_debug("%s: cal mem handle 0x%x\n",
  6001. __func__, c->cal_mem_handle);
  6002. v->mvm_state = CMD_STATUS_SUCCESS;
  6003. wake_up(&v->mvm_wait);
  6004. }
  6005. } else if (data->payload_size &&
  6006. data->token == VOC_VOICE_HOST_PCM_MAP_TOKEN) {
  6007. ptr = data->payload;
  6008. if (ptr[0]) {
  6009. common.voice_host_pcm_mem_handle = ptr[0];
  6010. pr_debug("%s: vhpcm mem handle 0x%x\n",
  6011. __func__,
  6012. common.voice_host_pcm_mem_handle);
  6013. v->mvm_state = CMD_STATUS_SUCCESS;
  6014. wake_up(&v->mvm_wait);
  6015. }
  6016. } else if (data->payload_size &&
  6017. data->token == VOC_RTAC_MEM_MAP_TOKEN) {
  6018. ptr = data->payload;
  6019. if (ptr[0]) {
  6020. c->rtac_mem_handle = ptr[0];
  6021. pr_debug("%s: cal mem handle 0x%x\n",
  6022. __func__, c->rtac_mem_handle);
  6023. v->mvm_state = CMD_STATUS_SUCCESS;
  6024. wake_up(&v->mvm_wait);
  6025. }
  6026. } else if (data->payload_size &&
  6027. data->token == VOC_SOURCE_TRACKING_MEM_MAP_TOKEN) {
  6028. ptr = data->payload;
  6029. if (ptr[0]) {
  6030. common.source_tracking_sh_mem.mem_handle =
  6031. ptr[0];
  6032. pr_debug("%s: Source Tracking shared mem handle 0x%x\n",
  6033. __func__,
  6034. common.source_tracking_sh_mem.mem_handle);
  6035. v->mvm_state = CMD_STATUS_SUCCESS;
  6036. wake_up(&v->mvm_wait);
  6037. }
  6038. } else {
  6039. pr_err("%s: Unknown mem map token %d\n",
  6040. __func__, data->token);
  6041. }
  6042. } else if (data->opcode == VSS_IVERSION_RSP_GET) {
  6043. pr_debug("%s: Received VSS_IVERSION_RSP_GET\n", __func__);
  6044. if (data->payload_size) {
  6045. version_rsp =
  6046. (struct vss_iversion_rsp_get_t *)data->payload;
  6047. memcpy(common.cvd_version, version_rsp->version,
  6048. CVD_VERSION_STRING_MAX_SIZE);
  6049. pr_debug("%s: CVD Version = %s\n",
  6050. __func__, common.cvd_version);
  6051. v->mvm_state = CMD_STATUS_SUCCESS;
  6052. wake_up(&v->mvm_wait);
  6053. }
  6054. }
  6055. return 0;
  6056. }
  6057. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
  6058. {
  6059. uint32_t *ptr = NULL;
  6060. struct common_data *c = NULL;
  6061. struct voice_data *v = NULL;
  6062. int i = 0;
  6063. if ((data == NULL) || (priv == NULL)) {
  6064. pr_err("%s: data or priv is NULL\n", __func__);
  6065. return -EINVAL;
  6066. }
  6067. c = priv;
  6068. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  6069. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  6070. data->payload_size, data->opcode);
  6071. if (data->opcode == RESET_EVENTS) {
  6072. pr_debug("%s: Reset event received in Voice service\n",
  6073. __func__);
  6074. apr_reset(c->apr_q6_cvs);
  6075. c->apr_q6_cvs = NULL;
  6076. /* Sub-system restart is applicable to all sessions. */
  6077. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  6078. c->voice[i].cvs_handle = 0;
  6079. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  6080. common.cal_data);
  6081. /* Free the ION memory and clear handles for Source Tracking */
  6082. if (is_source_tracking_shared_memomry_allocated()) {
  6083. msm_audio_ion_free(
  6084. common.source_tracking_sh_mem.sh_mem_block.client,
  6085. common.source_tracking_sh_mem.sh_mem_block.handle);
  6086. common.source_tracking_sh_mem.mem_handle = 0;
  6087. common.source_tracking_sh_mem.sh_mem_block.client =
  6088. NULL;
  6089. common.source_tracking_sh_mem.sh_mem_block.handle =
  6090. NULL;
  6091. }
  6092. voc_set_error_state(data->reset_proc);
  6093. return 0;
  6094. }
  6095. v = voice_get_session_by_idx(data->dest_port);
  6096. if (v == NULL) {
  6097. pr_err("%s: v is NULL\n", __func__);
  6098. return -EINVAL;
  6099. }
  6100. if (data->opcode == APR_BASIC_RSP_RESULT) {
  6101. if (data->payload_size) {
  6102. ptr = data->payload;
  6103. pr_debug("%x %x\n", ptr[0], ptr[1]);
  6104. if (ptr[1] != 0) {
  6105. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  6106. __func__, ptr[0], ptr[1]);
  6107. }
  6108. /*response from CVS */
  6109. switch (ptr[0]) {
  6110. case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  6111. case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
  6112. if (!ptr[1]) {
  6113. pr_debug("%s: CVS handle is %d\n",
  6114. __func__, data->src_port);
  6115. voice_set_cvs_handle(v, data->src_port);
  6116. } else
  6117. pr_err("got NACK for sending CVS create session\n");
  6118. v->cvs_state = CMD_STATUS_SUCCESS;
  6119. v->async_err = ptr[1];
  6120. wake_up(&v->cvs_wait);
  6121. break;
  6122. case VSS_IVOLUME_CMD_MUTE_V2:
  6123. case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
  6124. case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
  6125. case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
  6126. case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
  6127. case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
  6128. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  6129. case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2:
  6130. case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
  6131. case VSS_ISTREAM_CMD_REGISTER_STATIC_CALIBRATION_DATA:
  6132. case VSS_ISTREAM_CMD_DEREGISTER_STATIC_CALIBRATION_DATA:
  6133. case VSS_ICOMMON_CMD_MAP_MEMORY:
  6134. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  6135. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  6136. case VSS_IPLAYBACK_CMD_START:
  6137. case VSS_IPLAYBACK_CMD_STOP:
  6138. case VSS_IRECORD_CMD_START:
  6139. case VSS_IRECORD_CMD_STOP:
  6140. case VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE:
  6141. case VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG:
  6142. case VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION:
  6143. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  6144. v->cvs_state = CMD_STATUS_SUCCESS;
  6145. v->async_err = ptr[1];
  6146. wake_up(&v->cvs_wait);
  6147. break;
  6148. case VSS_ICOMMON_CMD_SET_PARAM_V2:
  6149. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2\n",
  6150. __func__);
  6151. rtac_make_voice_callback(RTAC_CVS, ptr,
  6152. data->payload_size);
  6153. break;
  6154. case VSS_ICOMMON_CMD_GET_PARAM_V2:
  6155. pr_debug("%s: VSS_ICOMMON_CMD_GET_PARAM_V2\n",
  6156. __func__);
  6157. /* Should only come here if there is an APR */
  6158. /* error or malformed APR packet. Otherwise */
  6159. /* response will be returned as */
  6160. /* VSS_ICOMMON_RSP_GET_PARAM */
  6161. if (ptr[1] != 0) {
  6162. pr_err("%s: CVP get param error = %d, resuming\n",
  6163. __func__, ptr[1]);
  6164. rtac_make_voice_callback(RTAC_CVP,
  6165. data->payload,
  6166. data->payload_size);
  6167. }
  6168. break;
  6169. default:
  6170. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  6171. break;
  6172. }
  6173. }
  6174. } else if (data->opcode ==
  6175. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_READY) {
  6176. int ret = 0;
  6177. u16 cvs_handle;
  6178. uint32_t *cvs_voc_pkt;
  6179. struct cvs_enc_buffer_consumed_cmd send_enc_buf_consumed_cmd;
  6180. void *apr_cvs;
  6181. pr_debug("Encoder buffer is ready\n");
  6182. apr_cvs = common.apr_q6_cvs;
  6183. if (!apr_cvs) {
  6184. pr_err("%s: apr_cvs is NULL\n", __func__);
  6185. return -EINVAL;
  6186. }
  6187. cvs_handle = voice_get_cvs_handle(v);
  6188. send_enc_buf_consumed_cmd.hdr.hdr_field =
  6189. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6190. APR_HDR_LEN(APR_HDR_SIZE),
  6191. APR_PKT_VER);
  6192. send_enc_buf_consumed_cmd.hdr.pkt_size =
  6193. APR_PKT_SIZE(APR_HDR_SIZE,
  6194. sizeof(send_enc_buf_consumed_cmd) - APR_HDR_SIZE);
  6195. send_enc_buf_consumed_cmd.hdr.src_port =
  6196. voice_get_idx_for_session(v->session_id);
  6197. send_enc_buf_consumed_cmd.hdr.dest_port = cvs_handle;
  6198. send_enc_buf_consumed_cmd.hdr.token = 0;
  6199. send_enc_buf_consumed_cmd.hdr.opcode =
  6200. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_CONSUMED;
  6201. cvs_voc_pkt = v->shmem_info.sh_buf.buf[1].data;
  6202. if (cvs_voc_pkt != NULL && common.mvs_info.ul_cb != NULL) {
  6203. /* cvs_voc_pkt[0] contains tx timestamp */
  6204. common.mvs_info.ul_cb((uint8_t *)&cvs_voc_pkt[3],
  6205. cvs_voc_pkt[2],
  6206. cvs_voc_pkt[0],
  6207. common.mvs_info.private_data);
  6208. } else
  6209. pr_err("%s: cvs_voc_pkt or ul_cb is NULL\n", __func__);
  6210. ret = apr_send_pkt(apr_cvs,
  6211. (uint32_t *) &send_enc_buf_consumed_cmd);
  6212. if (ret < 0) {
  6213. pr_err("%s: Err send ENC_BUF_CONSUMED_NOTIFY %d\n",
  6214. __func__, ret);
  6215. goto fail;
  6216. }
  6217. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
  6218. pr_debug("Recd VSS_ISTREAM_EVT_SEND_ENC_BUFFER\n");
  6219. } else if (data->opcode ==
  6220. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_REQUEST) {
  6221. int ret = 0;
  6222. u16 cvs_handle;
  6223. uint32_t *cvs_voc_pkt;
  6224. struct cvs_dec_buffer_ready_cmd send_dec_buf;
  6225. void *apr_cvs;
  6226. apr_cvs = common.apr_q6_cvs;
  6227. if (!apr_cvs) {
  6228. pr_err("%s: apr_cvs is NULL\n", __func__);
  6229. return -EINVAL;
  6230. }
  6231. cvs_handle = voice_get_cvs_handle(v);
  6232. send_dec_buf.hdr.hdr_field =
  6233. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6234. APR_HDR_LEN(APR_HDR_SIZE),
  6235. APR_PKT_VER);
  6236. send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6237. sizeof(send_dec_buf) - APR_HDR_SIZE);
  6238. send_dec_buf.hdr.src_port =
  6239. voice_get_idx_for_session(v->session_id);
  6240. send_dec_buf.hdr.dest_port = cvs_handle;
  6241. send_dec_buf.hdr.token = 0;
  6242. send_dec_buf.hdr.opcode =
  6243. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_READY;
  6244. cvs_voc_pkt = (uint32_t *)(v->shmem_info.sh_buf.buf[0].data);
  6245. if (cvs_voc_pkt != NULL && common.mvs_info.dl_cb != NULL) {
  6246. /* Set timestamp to 0 and advance the pointer */
  6247. cvs_voc_pkt[0] = 0;
  6248. /* Set media_type and advance the pointer */
  6249. cvs_voc_pkt[1] = common.mvs_info.media_type;
  6250. common.mvs_info.dl_cb(
  6251. (uint8_t *)&cvs_voc_pkt[2],
  6252. common.mvs_info.private_data);
  6253. ret = apr_send_pkt(apr_cvs, (uint32_t *) &send_dec_buf);
  6254. if (ret < 0) {
  6255. pr_err("%s: Err send DEC_BUF_READY_NOTIFI %d\n",
  6256. __func__, ret);
  6257. goto fail;
  6258. }
  6259. } else {
  6260. pr_debug("%s: voc_pkt or dl_cb is NULL\n", __func__);
  6261. goto fail;
  6262. }
  6263. } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
  6264. pr_debug("Recd VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER\n");
  6265. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
  6266. pr_debug("Send dec buf resp\n");
  6267. } else if (data->opcode == APR_RSP_ACCEPTED) {
  6268. ptr = data->payload;
  6269. if (ptr[0])
  6270. pr_debug("%s: APR_RSP_ACCEPTED for 0x%x:\n",
  6271. __func__, ptr[0]);
  6272. } else if (data->opcode == VSS_ISTREAM_EVT_NOT_READY) {
  6273. pr_debug("Recd VSS_ISTREAM_EVT_NOT_READY\n");
  6274. } else if (data->opcode == VSS_ISTREAM_EVT_READY) {
  6275. pr_debug("Recd VSS_ISTREAM_EVT_READY\n");
  6276. } else if (data->opcode == VSS_ICOMMON_RSP_GET_PARAM) {
  6277. pr_debug("%s: VSS_ICOMMON_RSP_GET_PARAM\n", __func__);
  6278. ptr = data->payload;
  6279. if (ptr[0] != 0) {
  6280. pr_err("%s: VSS_ICOMMON_RSP_GET_PARAM returned error = 0x%x\n",
  6281. __func__, ptr[0]);
  6282. }
  6283. rtac_make_voice_callback(RTAC_CVS, data->payload,
  6284. data->payload_size);
  6285. } else if (data->opcode == VSS_ISTREAM_EVT_RX_DTMF_DETECTED) {
  6286. struct vss_istream_evt_rx_dtmf_detected *dtmf_rx_detected;
  6287. uint32_t *voc_pkt = data->payload;
  6288. uint32_t pkt_len = data->payload_size;
  6289. if ((voc_pkt != NULL) &&
  6290. (pkt_len ==
  6291. sizeof(struct vss_istream_evt_rx_dtmf_detected))) {
  6292. dtmf_rx_detected =
  6293. (struct vss_istream_evt_rx_dtmf_detected *) voc_pkt;
  6294. pr_debug("RX_DTMF_DETECTED low_freq=%d high_freq=%d\n",
  6295. dtmf_rx_detected->low_freq,
  6296. dtmf_rx_detected->high_freq);
  6297. if (c->dtmf_info.dtmf_rx_ul_cb)
  6298. c->dtmf_info.dtmf_rx_ul_cb((uint8_t *)voc_pkt,
  6299. voc_get_session_name(v->session_id),
  6300. c->dtmf_info.private_data);
  6301. } else {
  6302. pr_err("Invalid packet\n");
  6303. }
  6304. } else
  6305. pr_debug("Unknown opcode 0x%x\n", data->opcode);
  6306. fail:
  6307. return 0;
  6308. }
  6309. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
  6310. {
  6311. uint32_t *ptr = NULL;
  6312. struct common_data *c = NULL;
  6313. struct voice_data *v = NULL;
  6314. int i = 0;
  6315. if ((data == NULL) || (priv == NULL)) {
  6316. pr_err("%s: data or priv is NULL\n", __func__);
  6317. return -EINVAL;
  6318. }
  6319. c = priv;
  6320. if (data->opcode == RESET_EVENTS) {
  6321. pr_debug("%s: Reset event received in Voice service\n",
  6322. __func__);
  6323. apr_reset(c->apr_q6_cvp);
  6324. c->apr_q6_cvp = NULL;
  6325. cal_utils_clear_cal_block_q6maps(MAX_VOICE_CAL_TYPES,
  6326. common.cal_data);
  6327. /* Sub-system restart is applicable to all sessions. */
  6328. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  6329. c->voice[i].cvp_handle = 0;
  6330. /*
  6331. * Free the ION memory and clear handles for
  6332. * Source Tracking
  6333. */
  6334. if (is_source_tracking_shared_memomry_allocated()) {
  6335. msm_audio_ion_free(
  6336. common.source_tracking_sh_mem.sh_mem_block.client,
  6337. common.source_tracking_sh_mem.sh_mem_block.handle);
  6338. common.source_tracking_sh_mem.mem_handle = 0;
  6339. common.source_tracking_sh_mem.sh_mem_block.client =
  6340. NULL;
  6341. common.source_tracking_sh_mem.sh_mem_block.handle =
  6342. NULL;
  6343. }
  6344. voc_set_error_state(data->reset_proc);
  6345. return 0;
  6346. }
  6347. v = voice_get_session_by_idx(data->dest_port);
  6348. if (v == NULL) {
  6349. pr_err("%s: v is NULL\n", __func__);
  6350. return -EINVAL;
  6351. }
  6352. if (data->opcode == APR_BASIC_RSP_RESULT) {
  6353. if (data->payload_size) {
  6354. ptr = data->payload;
  6355. pr_debug("%x %x\n", ptr[0], ptr[1]);
  6356. if (ptr[1] != 0) {
  6357. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  6358. __func__, ptr[0], ptr[1]);
  6359. }
  6360. switch (ptr[0]) {
  6361. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2:
  6362. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V3:
  6363. /*response from CVP */
  6364. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  6365. if (!ptr[1]) {
  6366. voice_set_cvp_handle(v, data->src_port);
  6367. pr_debug("status: %d, cvphdl=%d\n",
  6368. ptr[1], data->src_port);
  6369. } else
  6370. pr_err("got NACK from CVP create session response\n");
  6371. v->cvp_state = CMD_STATUS_SUCCESS;
  6372. v->async_err = ptr[1];
  6373. wake_up(&v->cvp_wait);
  6374. break;
  6375. case VSS_IVOCPROC_CMD_SET_DEVICE_V2:
  6376. case VSS_IVOCPROC_CMD_SET_DEVICE_V3:
  6377. case VSS_IVOLUME_CMD_SET_STEP:
  6378. case VSS_IVOCPROC_CMD_ENABLE:
  6379. case VSS_IVOCPROC_CMD_DISABLE:
  6380. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  6381. case VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA:
  6382. case VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA:
  6383. case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2:
  6384. case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
  6385. case VSS_IVOCPROC_CMD_REGISTER_DYNAMIC_CALIBRATION_DATA:
  6386. case VSS_IVOCPROC_CMD_DEREGISTER_DYNAMIC_CALIBRATION_DATA:
  6387. case VSS_IVOCPROC_CMD_REGISTER_STATIC_CALIBRATION_DATA:
  6388. case VSS_IVOCPROC_CMD_DEREGISTER_STATIC_CALIBRATION_DATA:
  6389. case VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG:
  6390. case VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG:
  6391. case VSS_ICOMMON_CMD_MAP_MEMORY:
  6392. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  6393. case VSS_IVOLUME_CMD_MUTE_V2:
  6394. case VSS_IVPCM_CMD_START_V2:
  6395. case VSS_IVPCM_CMD_STOP:
  6396. case VSS_IVOCPROC_CMD_TOPOLOGY_SET_DEV_CHANNELS:
  6397. case VSS_IVOCPROC_CMD_TOPOLOGY_COMMIT:
  6398. v->cvp_state = CMD_STATUS_SUCCESS;
  6399. v->async_err = ptr[1];
  6400. wake_up(&v->cvp_wait);
  6401. break;
  6402. case VSS_IVPCM_EVT_PUSH_BUFFER_V2:
  6403. break;
  6404. case VSS_ICOMMON_CMD_SET_PARAM_V2:
  6405. switch (data->token) {
  6406. case VOC_SET_MEDIA_FORMAT_PARAM_TOKEN:
  6407. case VOC_GENERIC_SET_PARAM_TOKEN:
  6408. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2 called\n",
  6409. __func__);
  6410. v->cvp_state = CMD_STATUS_SUCCESS;
  6411. v->async_err = ptr[1];
  6412. wake_up(&v->cvp_wait);
  6413. break;
  6414. case VOC_RTAC_SET_PARAM_TOKEN:
  6415. pr_debug("%s: VSS_ICOMMON_CMD_SET_PARAM_V2 called by rtac\n",
  6416. __func__);
  6417. rtac_make_voice_callback(
  6418. RTAC_CVP, ptr,
  6419. data->payload_size);
  6420. break;
  6421. default:
  6422. pr_debug("%s: invalid token for command VSS_ICOMMON_CMD_SET_PARAM_V2: %d\n",
  6423. __func__, data->token);
  6424. break;
  6425. }
  6426. break;
  6427. case VSS_ICOMMON_CMD_GET_PARAM_V2:
  6428. pr_debug("%s: VSS_ICOMMON_CMD_GET_PARAM_V2\n",
  6429. __func__);
  6430. /* Should only come here if there is an APR */
  6431. /* error or malformed APR packet. Otherwise */
  6432. /* response will be returned as */
  6433. /* VSS_ICOMMON_RSP_GET_PARAM */
  6434. if (ptr[1] != 0) {
  6435. pr_err("%s: CVP get param error = %d, resuming\n",
  6436. __func__, ptr[1]);
  6437. rtac_make_voice_callback(RTAC_CVP,
  6438. data->payload,
  6439. data->payload_size);
  6440. }
  6441. break;
  6442. case VSS_ISOUNDFOCUS_CMD_SET_SECTORS:
  6443. if (!ptr[1])
  6444. common.is_sound_focus_resp_success =
  6445. true;
  6446. else
  6447. common.is_sound_focus_resp_success =
  6448. false;
  6449. v->cvp_state = CMD_STATUS_SUCCESS;
  6450. v->async_err = ptr[1];
  6451. wake_up(&v->cvp_wait);
  6452. break;
  6453. case VSS_ISOUNDFOCUS_CMD_GET_SECTORS:
  6454. /*
  6455. * Should only come here if there is an error
  6456. * response received from ADSP. Otherwise
  6457. * response will be returned as
  6458. * VSS_ISOUNDFOCUS_RSP_GET_SECTORS
  6459. */
  6460. pr_err("%s: VSS_ISOUNDFOCUS_CMD_GET_SECTORS failed\n",
  6461. __func__);
  6462. common.is_sound_focus_resp_success = false;
  6463. v->cvp_state = CMD_STATUS_SUCCESS;
  6464. v->async_err = ptr[1];
  6465. wake_up(&v->cvp_wait);
  6466. break;
  6467. case VSS_ISOURCETRACK_CMD_GET_ACTIVITY:
  6468. if (!ptr[1]) {
  6469. /* Read data from shared memory */
  6470. memcpy(&common.sourceTrackingResponse,
  6471. common.source_tracking_sh_mem.
  6472. sh_mem_block.data,
  6473. sizeof(struct
  6474. vss_isourcetrack_activity_data_t));
  6475. common.is_source_tracking_resp_success =
  6476. true;
  6477. } else {
  6478. common.is_source_tracking_resp_success =
  6479. false;
  6480. pr_err("%s: Error received for source tracking params\n",
  6481. __func__);
  6482. }
  6483. v->cvp_state = CMD_STATUS_SUCCESS;
  6484. v->async_err = ptr[1];
  6485. wake_up(&v->cvp_wait);
  6486. break;
  6487. default:
  6488. pr_debug("%s: not match cmd = 0x%x\n",
  6489. __func__, ptr[0]);
  6490. break;
  6491. }
  6492. }
  6493. } else if (data->opcode == VSS_ICOMMON_RSP_GET_PARAM) {
  6494. pr_debug("%s: VSS_ICOMMON_RSP_GET_PARAM\n", __func__);
  6495. ptr = data->payload;
  6496. if (ptr[0] != 0) {
  6497. pr_err("%s: VSS_ICOMMON_RSP_GET_PARAM returned error = 0x%x\n",
  6498. __func__, ptr[0]);
  6499. }
  6500. rtac_make_voice_callback(RTAC_CVP, data->payload,
  6501. data->payload_size);
  6502. } else if (data->opcode == VSS_IVPCM_EVT_NOTIFY_V2) {
  6503. if ((data->payload != NULL) && data->payload_size ==
  6504. sizeof(struct vss_ivpcm_evt_notify_v2_t) &&
  6505. common.hostpcm_info.hostpcm_evt_cb != NULL) {
  6506. common.hostpcm_info.hostpcm_evt_cb(data->payload,
  6507. voc_get_session_name(v->session_id),
  6508. common.hostpcm_info.private_data);
  6509. }
  6510. } else if (data->opcode == VSS_ISOUNDFOCUS_RSP_GET_SECTORS) {
  6511. if (data->payload && (data->payload_size ==
  6512. sizeof(struct vss_isoundfocus_rsp_get_sectors_t))) {
  6513. common.is_sound_focus_resp_success = true;
  6514. memcpy(&common.soundFocusResponse,
  6515. (struct vss_isoundfocus_rsp_get_sectors_t *)
  6516. data->payload,
  6517. sizeof(struct
  6518. vss_isoundfocus_rsp_get_sectors_t));
  6519. } else {
  6520. common.is_sound_focus_resp_success = false;
  6521. pr_debug("%s: Invalid payload received from CVD\n",
  6522. __func__);
  6523. }
  6524. v->cvp_state = CMD_STATUS_SUCCESS;
  6525. wake_up(&v->cvp_wait);
  6526. }
  6527. return 0;
  6528. }
  6529. static int voice_free_oob_shared_mem(void)
  6530. {
  6531. int rc = 0;
  6532. int cnt = 0;
  6533. int bufcnt = NUM_OF_BUFFERS;
  6534. struct voice_data *v = voice_get_session(
  6535. common.voice[VOC_PATH_FULL].session_id);
  6536. mutex_lock(&common.common_lock);
  6537. if (v == NULL) {
  6538. pr_err("%s: v is NULL\n", __func__);
  6539. rc = -EINVAL;
  6540. goto done;
  6541. }
  6542. rc = msm_audio_ion_free(v->shmem_info.sh_buf.client,
  6543. v->shmem_info.sh_buf.handle);
  6544. v->shmem_info.sh_buf.client = NULL;
  6545. v->shmem_info.sh_buf.handle = NULL;
  6546. if (rc < 0) {
  6547. pr_err("%s: Error:%d freeing memory\n", __func__, rc);
  6548. goto done;
  6549. }
  6550. while (cnt < bufcnt) {
  6551. v->shmem_info.sh_buf.buf[cnt].data = NULL;
  6552. v->shmem_info.sh_buf.buf[cnt].phys = 0;
  6553. cnt++;
  6554. }
  6555. v->shmem_info.sh_buf.client = NULL;
  6556. v->shmem_info.sh_buf.handle = NULL;
  6557. done:
  6558. mutex_unlock(&common.common_lock);
  6559. return rc;
  6560. }
  6561. static int voice_alloc_oob_shared_mem(void)
  6562. {
  6563. int cnt = 0;
  6564. int rc = 0;
  6565. size_t len;
  6566. void *mem_addr;
  6567. dma_addr_t phys;
  6568. int bufsz = BUFFER_BLOCK_SIZE;
  6569. int bufcnt = NUM_OF_BUFFERS;
  6570. struct voice_data *v = voice_get_session(
  6571. common.voice[VOC_PATH_FULL].session_id);
  6572. mutex_lock(&common.common_lock);
  6573. if (v == NULL) {
  6574. pr_err("%s: v is NULL\n", __func__);
  6575. rc = -EINVAL;
  6576. goto done;
  6577. }
  6578. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.sh_buf.client),
  6579. &(v->shmem_info.sh_buf.handle),
  6580. bufsz*bufcnt,
  6581. &phys, &len,
  6582. &mem_addr);
  6583. if (rc < 0) {
  6584. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6585. __func__, rc);
  6586. goto done;
  6587. }
  6588. while (cnt < bufcnt) {
  6589. v->shmem_info.sh_buf.buf[cnt].data = mem_addr + (cnt * bufsz);
  6590. v->shmem_info.sh_buf.buf[cnt].phys = phys + (cnt * bufsz);
  6591. v->shmem_info.sh_buf.buf[cnt].size = bufsz;
  6592. cnt++;
  6593. }
  6594. pr_debug("%s buf[0].data:[%pK], buf[0].phys:[%pK], &buf[0].phys:[%pK],\n",
  6595. __func__,
  6596. (void *)v->shmem_info.sh_buf.buf[0].data,
  6597. &v->shmem_info.sh_buf.buf[0].phys,
  6598. (void *)&v->shmem_info.sh_buf.buf[0].phys);
  6599. pr_debug("%s: buf[1].data:[%pK], buf[1].phys[%pK], &buf[1].phys[%pK]\n",
  6600. __func__,
  6601. (void *)v->shmem_info.sh_buf.buf[1].data,
  6602. &v->shmem_info.sh_buf.buf[1].phys,
  6603. (void *)&v->shmem_info.sh_buf.buf[1].phys);
  6604. memset((void *)v->shmem_info.sh_buf.buf[0].data, 0, (bufsz * bufcnt));
  6605. done:
  6606. mutex_unlock(&common.common_lock);
  6607. return rc;
  6608. }
  6609. static int voice_alloc_oob_mem_table(void)
  6610. {
  6611. int rc = 0;
  6612. size_t len;
  6613. struct voice_data *v = voice_get_session(
  6614. common.voice[VOC_PATH_FULL].session_id);
  6615. mutex_lock(&common.common_lock);
  6616. if (v == NULL) {
  6617. pr_err("%s: v is NULL\n", __func__);
  6618. rc = -EINVAL;
  6619. goto done;
  6620. }
  6621. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.memtbl.client),
  6622. &(v->shmem_info.memtbl.handle),
  6623. sizeof(struct vss_imemory_table_t),
  6624. &v->shmem_info.memtbl.phys,
  6625. &len,
  6626. &(v->shmem_info.memtbl.data));
  6627. if (rc < 0) {
  6628. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6629. __func__, rc);
  6630. goto done;
  6631. }
  6632. v->shmem_info.memtbl.size = sizeof(struct vss_imemory_table_t);
  6633. pr_debug("%s data[%pK]phys[%pK][%pK]\n", __func__,
  6634. (void *)v->shmem_info.memtbl.data,
  6635. &v->shmem_info.memtbl.phys,
  6636. (void *)&v->shmem_info.memtbl.phys);
  6637. done:
  6638. mutex_unlock(&common.common_lock);
  6639. return rc;
  6640. }
  6641. int voc_send_cvp_start_vocpcm(uint32_t session_id,
  6642. struct vss_ivpcm_tap_point *vpcm_tp,
  6643. uint32_t no_of_tp)
  6644. {
  6645. struct cvp_start_cmd cvp_start_cmd;
  6646. int ret = 0;
  6647. void *apr_cvp;
  6648. u16 cvp_handle;
  6649. struct voice_data *v = voice_get_session(session_id);
  6650. int i = 0;
  6651. if (v == NULL) {
  6652. pr_err("%s: v is NULL\n", __func__);
  6653. ret = -EINVAL;
  6654. goto done;
  6655. }
  6656. apr_cvp = common.apr_q6_cvp;
  6657. if (!apr_cvp) {
  6658. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6659. ret = -EINVAL;
  6660. goto done;
  6661. }
  6662. cvp_handle = voice_get_cvp_handle(v);
  6663. /* Fill the header */
  6664. cvp_start_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6665. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6666. cvp_start_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6667. sizeof(struct vss_ivpcm_tap_point) * no_of_tp) +
  6668. sizeof(cvp_start_cmd.vpcm_start_cmd.num_tap_points) +
  6669. sizeof(cvp_start_cmd.vpcm_start_cmd.mem_handle);
  6670. cvp_start_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  6671. cvp_start_cmd.hdr.dest_port = cvp_handle;
  6672. cvp_start_cmd.hdr.token = 0;
  6673. cvp_start_cmd.hdr.opcode = VSS_IVPCM_CMD_START_V2;
  6674. for (i = 0; i < no_of_tp; i++) {
  6675. cvp_start_cmd.vpcm_start_cmd.tap_points[i].tap_point =
  6676. vpcm_tp[i].tap_point;
  6677. cvp_start_cmd.vpcm_start_cmd.tap_points[i].direction =
  6678. vpcm_tp[i].direction;
  6679. cvp_start_cmd.vpcm_start_cmd.tap_points[i].sampling_rate =
  6680. vpcm_tp[i].sampling_rate;
  6681. cvp_start_cmd.vpcm_start_cmd.tap_points[i].duration = 0;
  6682. }
  6683. cvp_start_cmd.vpcm_start_cmd.mem_handle =
  6684. common.voice_host_pcm_mem_handle;
  6685. cvp_start_cmd.vpcm_start_cmd.num_tap_points = no_of_tp;
  6686. v->cvp_state = CMD_STATUS_FAIL;
  6687. v->async_err = 0;
  6688. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_start_cmd);
  6689. if (ret < 0) {
  6690. pr_err("%s: Fail: sending vocpcm map memory,\n", __func__);
  6691. goto done;
  6692. }
  6693. ret = wait_event_timeout(v->cvp_wait,
  6694. (v->cvp_state == CMD_STATUS_SUCCESS),
  6695. msecs_to_jiffies(TIMEOUT_MS));
  6696. if (!ret) {
  6697. pr_err("%s: wait_event timeout\n", __func__);
  6698. goto done;
  6699. }
  6700. if (v->async_err > 0) {
  6701. pr_err("%s: DSP returned error[%s]\n",
  6702. __func__, adsp_err_get_err_str(
  6703. v->async_err));
  6704. ret = adsp_err_get_lnx_err_code(
  6705. v->async_err);
  6706. goto done;
  6707. }
  6708. done:
  6709. return ret;
  6710. }
  6711. int voc_send_cvp_stop_vocpcm(uint32_t session_id)
  6712. {
  6713. struct cvp_command vpcm_stop_cmd;
  6714. int ret = 0;
  6715. void *apr_cvp;
  6716. u16 cvp_handle;
  6717. struct voice_data *v = voice_get_session(session_id);
  6718. if (v == NULL) {
  6719. pr_err("%s: v is NULL\n", __func__);
  6720. ret = -EINVAL;
  6721. goto done;
  6722. }
  6723. apr_cvp = common.apr_q6_cvp;
  6724. if (!apr_cvp) {
  6725. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6726. ret = -EINVAL;
  6727. goto done;
  6728. }
  6729. cvp_handle = voice_get_cvp_handle(v);
  6730. /* fill in the header */
  6731. vpcm_stop_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6732. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6733. vpcm_stop_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6734. sizeof(vpcm_stop_cmd) - APR_HDR_SIZE);
  6735. vpcm_stop_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  6736. vpcm_stop_cmd.hdr.dest_port = cvp_handle;
  6737. vpcm_stop_cmd.hdr.token = 0;
  6738. vpcm_stop_cmd.hdr.opcode = VSS_IVPCM_CMD_STOP;
  6739. v->cvp_state = CMD_STATUS_FAIL;
  6740. v->async_err = 0;
  6741. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_stop_cmd);
  6742. if (ret < 0) {
  6743. pr_err("Fail: sending vocpcm stop,\n");
  6744. goto done;
  6745. }
  6746. ret = wait_event_timeout(v->cvp_wait,
  6747. (v->cvp_state == CMD_STATUS_SUCCESS),
  6748. msecs_to_jiffies(TIMEOUT_MS));
  6749. if (!ret) {
  6750. pr_err("%s: wait_event timeout\n", __func__);
  6751. goto done;
  6752. }
  6753. if (v->async_err > 0) {
  6754. pr_err("%s: DSP returned error[%s]\n",
  6755. __func__, adsp_err_get_err_str(
  6756. v->async_err));
  6757. ret = adsp_err_get_lnx_err_code(
  6758. v->async_err);
  6759. goto done;
  6760. }
  6761. done:
  6762. return ret;
  6763. }
  6764. int voc_send_cvp_map_vocpcm_memory(uint32_t session_id,
  6765. struct mem_map_table *tp_mem_table,
  6766. phys_addr_t paddr, uint32_t bufsize)
  6767. {
  6768. return voice_map_memory_physical_cmd(voice_get_session(session_id),
  6769. tp_mem_table,
  6770. (dma_addr_t) paddr, bufsize,
  6771. VOC_VOICE_HOST_PCM_MAP_TOKEN);
  6772. }
  6773. int voc_send_cvp_unmap_vocpcm_memory(uint32_t session_id)
  6774. {
  6775. int ret = 0;
  6776. ret = voice_send_mvm_unmap_memory_physical_cmd(
  6777. voice_get_session(session_id),
  6778. common.voice_host_pcm_mem_handle);
  6779. if (ret == 0)
  6780. common.voice_host_pcm_mem_handle = 0;
  6781. return ret;
  6782. }
  6783. int voc_send_cvp_vocpcm_push_buf_evt(uint32_t session_id,
  6784. struct vss_ivpcm_evt_push_buffer_v2_t *push_buff_evt)
  6785. {
  6786. struct cvp_push_buf_cmd vpcm_push_buf_cmd;
  6787. int ret = 0;
  6788. void *apr_cvp;
  6789. u16 cvp_handle;
  6790. struct voice_data *v = voice_get_session(session_id);
  6791. if (v == NULL) {
  6792. pr_err("%s: v is NULL\n", __func__);
  6793. ret = -EINVAL;
  6794. goto done;
  6795. }
  6796. apr_cvp = common.apr_q6_cvp;
  6797. if (!apr_cvp) {
  6798. pr_err("%s: apr_cvp is NULL.\n", __func__);
  6799. ret = -EINVAL;
  6800. goto done;
  6801. }
  6802. memset(&vpcm_push_buf_cmd, 0, sizeof(vpcm_push_buf_cmd));
  6803. cvp_handle = voice_get_cvp_handle(v);
  6804. /* fill in the header */
  6805. vpcm_push_buf_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  6806. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  6807. vpcm_push_buf_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  6808. sizeof(vpcm_push_buf_cmd) - APR_HDR_SIZE);
  6809. vpcm_push_buf_cmd.hdr.src_port =
  6810. voice_get_idx_for_session(v->session_id);
  6811. vpcm_push_buf_cmd.hdr.dest_port = cvp_handle;
  6812. vpcm_push_buf_cmd.hdr.token = 0;
  6813. vpcm_push_buf_cmd.hdr.opcode = VSS_IVPCM_EVT_PUSH_BUFFER_V2;
  6814. vpcm_push_buf_cmd.vpcm_evt_push_buffer.tap_point =
  6815. push_buff_evt->tap_point;
  6816. vpcm_push_buf_cmd.vpcm_evt_push_buffer.push_buf_mask =
  6817. push_buff_evt->push_buf_mask;
  6818. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_mem_address =
  6819. push_buff_evt->out_buf_mem_address;
  6820. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_mem_address =
  6821. push_buff_evt->in_buf_mem_address;
  6822. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_mem_size =
  6823. push_buff_evt->out_buf_mem_size;
  6824. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_mem_size =
  6825. push_buff_evt->in_buf_mem_size;
  6826. vpcm_push_buf_cmd.vpcm_evt_push_buffer.sampling_rate =
  6827. push_buff_evt->sampling_rate;
  6828. vpcm_push_buf_cmd.vpcm_evt_push_buffer.num_in_channels =
  6829. push_buff_evt->num_in_channels;
  6830. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_push_buf_cmd);
  6831. if (ret < 0) {
  6832. pr_err("Fail: sending vocpcm map memory,\n");
  6833. goto done;
  6834. }
  6835. done:
  6836. return ret;
  6837. }
  6838. void voc_register_hpcm_evt_cb(hostpcm_cb_fn hostpcm_cb,
  6839. void *private_data)
  6840. {
  6841. common.hostpcm_info.hostpcm_evt_cb = hostpcm_cb;
  6842. common.hostpcm_info.private_data = private_data;
  6843. }
  6844. void voc_deregister_hpcm_evt_cb(void)
  6845. {
  6846. common.hostpcm_info.hostpcm_evt_cb = NULL;
  6847. common.hostpcm_info.private_data = NULL;
  6848. }
  6849. int voc_get_cvd_version(char *cvd_version)
  6850. {
  6851. int ret = 0;
  6852. struct voice_data *v = voice_get_session(VOICE_SESSION_VSID);
  6853. if (v == NULL) {
  6854. pr_err("%s: invalid session_id 0x%x\n",
  6855. __func__, VOICE_SESSION_VSID);
  6856. ret = -EINVAL;
  6857. goto done;
  6858. }
  6859. if (is_cvd_version_queried()) {
  6860. pr_debug("%s: Returning the cached value %s\n",
  6861. __func__, common.cvd_version);
  6862. goto done;
  6863. }
  6864. /* Register callback to APR */
  6865. ret = voice_apr_register(VOICE_SESSION_VSID);
  6866. if (ret < 0) {
  6867. pr_err("%s: apr register failed\n", __func__);
  6868. goto done;
  6869. }
  6870. mutex_lock(&common.common_lock);
  6871. mutex_lock(&v->lock);
  6872. ret = voice_send_mvm_cvd_version_cmd(v);
  6873. if (ret < 0) {
  6874. pr_err("%s: voice_send_mvm_cvd_version_cmd failed\n", __func__);
  6875. goto unlock;
  6876. }
  6877. ret = 0;
  6878. unlock:
  6879. mutex_unlock(&v->lock);
  6880. mutex_unlock(&common.common_lock);
  6881. done:
  6882. if (cvd_version)
  6883. memcpy(cvd_version, common.cvd_version,
  6884. CVD_VERSION_STRING_MAX_SIZE);
  6885. return ret;
  6886. }
  6887. static int voice_alloc_cal_mem_map_table(void)
  6888. {
  6889. int ret = 0;
  6890. size_t len;
  6891. ret = msm_audio_ion_alloc("voc_cal",
  6892. &(common.cal_mem_map_table.client),
  6893. &(common.cal_mem_map_table.handle),
  6894. sizeof(struct vss_imemory_table_t),
  6895. &common.cal_mem_map_table.phys,
  6896. &len,
  6897. &(common.cal_mem_map_table.data));
  6898. if ((ret < 0) && (ret != -EPROBE_DEFER)) {
  6899. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6900. __func__, ret);
  6901. goto done;
  6902. }
  6903. common.cal_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  6904. pr_debug("%s: data %pK phys %pK\n", __func__,
  6905. common.cal_mem_map_table.data,
  6906. &common.cal_mem_map_table.phys);
  6907. done:
  6908. return ret;
  6909. }
  6910. static int voice_alloc_rtac_mem_map_table(void)
  6911. {
  6912. int ret = 0;
  6913. size_t len;
  6914. ret = msm_audio_ion_alloc("voc_rtac_cal",
  6915. &(common.rtac_mem_map_table.client),
  6916. &(common.rtac_mem_map_table.handle),
  6917. sizeof(struct vss_imemory_table_t),
  6918. &common.rtac_mem_map_table.phys,
  6919. &len,
  6920. &(common.rtac_mem_map_table.data));
  6921. if (ret < 0) {
  6922. pr_err("%s: audio ION alloc failed, rc = %d\n",
  6923. __func__, ret);
  6924. goto done;
  6925. }
  6926. common.rtac_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  6927. pr_debug("%s: data %pK phys %pK\n", __func__,
  6928. common.rtac_mem_map_table.data,
  6929. &common.rtac_mem_map_table.phys);
  6930. done:
  6931. return ret;
  6932. }
  6933. static int voice_alloc_and_map_oob_mem(struct voice_data *v)
  6934. {
  6935. int ret = 0;
  6936. if (v == NULL) {
  6937. pr_err("%s: v is NULL\n", __func__);
  6938. return -EINVAL;
  6939. }
  6940. if (!is_voip_memory_allocated()) {
  6941. ret = voc_alloc_voip_shared_memory();
  6942. if (ret < 0) {
  6943. pr_err("%s: Failed to create voip oob memory %d\n",
  6944. __func__, ret);
  6945. goto done;
  6946. }
  6947. }
  6948. ret = voice_map_memory_physical_cmd(v,
  6949. &v->shmem_info.memtbl,
  6950. v->shmem_info.sh_buf.buf[0].phys,
  6951. v->shmem_info.sh_buf.buf[0].size * NUM_OF_BUFFERS,
  6952. VOIP_MEM_MAP_TOKEN);
  6953. if (ret) {
  6954. pr_err("%s: mvm_map_memory_phy failed %d\n",
  6955. __func__, ret);
  6956. goto done;
  6957. }
  6958. done:
  6959. return ret;
  6960. }
  6961. uint32_t voice_get_topology(uint32_t topology_idx)
  6962. {
  6963. uint32_t topology = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  6964. struct cal_block_data *cal_block = NULL;
  6965. /* initialize as default topology */
  6966. if (topology_idx == CVP_VOC_RX_TOPOLOGY_CAL) {
  6967. topology = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  6968. } else if (topology_idx == CVP_VOC_TX_TOPOLOGY_CAL) {
  6969. topology = VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS_V2;
  6970. } else {
  6971. pr_err("%s: cal index %x is invalid!\n",
  6972. __func__, topology_idx);
  6973. goto done;
  6974. }
  6975. if (common.cal_data[topology_idx] == NULL) {
  6976. pr_err("%s: cal type is NULL for cal index %x\n",
  6977. __func__, topology_idx);
  6978. goto done;
  6979. }
  6980. mutex_lock(&common.cal_data[topology_idx]->lock);
  6981. cal_block = cal_utils_get_only_cal_block(
  6982. common.cal_data[topology_idx]);
  6983. if (cal_block == NULL) {
  6984. pr_debug("%s: cal_block not found for cal index %x\n",
  6985. __func__, topology_idx);
  6986. goto unlock;
  6987. }
  6988. topology = ((struct audio_cal_info_voc_top *)
  6989. cal_block->cal_info)->topology;
  6990. unlock:
  6991. mutex_unlock(&common.cal_data[topology_idx]->lock);
  6992. done:
  6993. pr_debug("%s: Using topology %d\n", __func__, topology);
  6994. return topology;
  6995. }
  6996. int voice_set_topology_specific_info(struct voice_data *v,
  6997. uint32_t topology_idx)
  6998. {
  6999. struct cal_block_data *cal_block = NULL;
  7000. int ret = 0;
  7001. uint32_t topo_channels;
  7002. if (common.cal_data[topology_idx] == NULL) {
  7003. pr_err("%s: cal type is NULL for cal index %x\n",
  7004. __func__, topology_idx);
  7005. ret = -EINVAL;
  7006. goto done;
  7007. }
  7008. mutex_lock(&common.cal_data[topology_idx]->lock);
  7009. cal_block = cal_utils_get_only_cal_block(
  7010. common.cal_data[topology_idx]);
  7011. if (cal_block == NULL) {
  7012. pr_debug("%s: cal_block not found for cal index %x\n",
  7013. __func__, topology_idx);
  7014. ret = -EINVAL;
  7015. goto unlock;
  7016. }
  7017. if (topology_idx == CVP_VOC_RX_TOPOLOGY_CAL) {
  7018. topo_channels = ((struct audio_cal_info_voc_top *)
  7019. cal_block->cal_info)->num_channels;
  7020. if (topo_channels > 0) {
  7021. v->dev_rx.no_of_channels = topo_channels;
  7022. pr_debug("%s: Topology Rx no of channels: %d",
  7023. __func__, v->dev_rx.no_of_channels);
  7024. memcpy(&v->dev_rx.channel_mapping,
  7025. &((struct audio_cal_info_voc_top *)
  7026. cal_block->cal_info)->channel_mapping,
  7027. VSS_CHANNEL_MAPPING_SIZE);
  7028. } else {
  7029. pr_debug("%s: cal data is zero, default to Rx backend config\n",
  7030. __func__);
  7031. if (v->dev_rx.no_of_channels == NUM_CHANNELS_MONO) {
  7032. v->dev_rx.channel_mapping[0] = PCM_CHANNEL_FC;
  7033. } else if (v->dev_rx.no_of_channels ==
  7034. NUM_CHANNELS_STEREO) {
  7035. v->dev_rx.channel_mapping[0] = PCM_CHANNEL_FL;
  7036. v->dev_rx.channel_mapping[1] = PCM_CHANNEL_FR;
  7037. } else {
  7038. pr_warn("%s: Unsupported Rx num channels: %d\n",
  7039. __func__, v->dev_rx.no_of_channels);
  7040. }
  7041. }
  7042. } else if (topology_idx == CVP_VOC_TX_TOPOLOGY_CAL) {
  7043. topo_channels = ((struct audio_cal_info_voc_top *)
  7044. cal_block->cal_info)->num_channels;
  7045. if (topo_channels > 0) {
  7046. v->dev_tx.no_of_channels = topo_channels;
  7047. pr_debug("%s: Topology Tx no of channels: %d",
  7048. __func__, v->dev_tx.no_of_channels);
  7049. memcpy(&v->dev_tx.channel_mapping,
  7050. &((struct audio_cal_info_voc_top *)
  7051. cal_block->cal_info)->channel_mapping,
  7052. VSS_CHANNEL_MAPPING_SIZE);
  7053. } else {
  7054. pr_debug("%s: cal data is zero, default to Tx backend config\n",
  7055. __func__);
  7056. if (v->dev_tx.no_of_channels == NUM_CHANNELS_MONO) {
  7057. v->dev_tx.channel_mapping[0] = PCM_CHANNEL_FC;
  7058. } else if (v->dev_tx.no_of_channels ==
  7059. NUM_CHANNELS_STEREO) {
  7060. v->dev_tx.channel_mapping[0] = PCM_CHANNEL_FL;
  7061. v->dev_tx.channel_mapping[1] = PCM_CHANNEL_FR;
  7062. } else if (v->dev_tx.no_of_channels ==
  7063. NUM_CHANNELS_QUAD) {
  7064. v->dev_tx.channel_mapping[0] = PCM_CHANNEL_FL;
  7065. v->dev_tx.channel_mapping[1] = PCM_CHANNEL_FR;
  7066. v->dev_tx.channel_mapping[2] = PCM_CHANNEL_LS;
  7067. v->dev_tx.channel_mapping[3] = PCM_CHANNEL_RS;
  7068. } else {
  7069. pr_warn("%s: Unsupported Tx num channels: %d\n",
  7070. __func__, v->dev_tx.no_of_channels);
  7071. }
  7072. }
  7073. } else {
  7074. pr_err("%s: topology index %x is invalid\n",
  7075. __func__, topology_idx);
  7076. }
  7077. unlock:
  7078. mutex_unlock(&common.cal_data[topology_idx]->lock);
  7079. done:
  7080. return ret;
  7081. }
  7082. static int get_cal_type_index(int32_t cal_type)
  7083. {
  7084. int ret = -EINVAL;
  7085. switch (cal_type) {
  7086. case CVP_VOC_RX_TOPOLOGY_CAL_TYPE:
  7087. ret = CVP_VOC_RX_TOPOLOGY_CAL;
  7088. break;
  7089. case CVP_VOC_TX_TOPOLOGY_CAL_TYPE:
  7090. ret = CVP_VOC_TX_TOPOLOGY_CAL;
  7091. break;
  7092. case CVP_VOCPROC_STATIC_CAL_TYPE:
  7093. ret = CVP_VOCPROC_CAL;
  7094. break;
  7095. case CVP_VOCPROC_DYNAMIC_CAL_TYPE:
  7096. ret = CVP_VOCVOL_CAL;
  7097. break;
  7098. case CVS_VOCSTRM_STATIC_CAL_TYPE:
  7099. ret = CVS_VOCSTRM_CAL;
  7100. break;
  7101. case CVP_VOCDEV_CFG_CAL_TYPE:
  7102. ret = CVP_VOCDEV_CFG_CAL;
  7103. break;
  7104. case CVP_VOCPROC_STATIC_COL_CAL_TYPE:
  7105. ret = CVP_VOCPROC_COL_CAL;
  7106. break;
  7107. case CVP_VOCPROC_DYNAMIC_COL_CAL_TYPE:
  7108. ret = CVP_VOCVOL_COL_CAL;
  7109. break;
  7110. case CVS_VOCSTRM_STATIC_COL_CAL_TYPE:
  7111. ret = CVS_VOCSTRM_COL_CAL;
  7112. break;
  7113. case VOICE_RTAC_INFO_CAL_TYPE:
  7114. ret = VOICE_RTAC_INFO_CAL;
  7115. break;
  7116. case VOICE_RTAC_APR_CAL_TYPE:
  7117. ret = VOICE_RTAC_APR_CAL;
  7118. break;
  7119. default:
  7120. pr_err("%s: Invalid cal type %d!\n", __func__, cal_type);
  7121. }
  7122. return ret;
  7123. }
  7124. static int voice_prepare_volume_boost(int32_t cal_type,
  7125. size_t data_size, void *data)
  7126. {
  7127. return voc_deregister_vocproc_vol_table();
  7128. }
  7129. static int voice_enable_volume_boost(int32_t cal_type,
  7130. size_t data_size, void *data)
  7131. {
  7132. return voc_register_vocproc_vol_table();
  7133. }
  7134. static int voice_alloc_cal(int32_t cal_type,
  7135. size_t data_size, void *data)
  7136. {
  7137. int ret = 0;
  7138. int cal_index;
  7139. int cal_version;
  7140. pr_debug("%s\n", __func__);
  7141. cal_version = cal_utils_get_cal_type_version(data);
  7142. common.is_per_vocoder_cal_enabled =
  7143. !!(cal_version & PER_VOCODER_CAL_BIT_MASK);
  7144. cal_index = get_cal_type_index(cal_type);
  7145. if (cal_index < 0) {
  7146. pr_err("%s: Could not get cal index %d!\n",
  7147. __func__, cal_index);
  7148. ret = -EINVAL;
  7149. goto done;
  7150. }
  7151. ret = cal_utils_alloc_cal(data_size, data,
  7152. common.cal_data[cal_index], 0, NULL);
  7153. if (ret < 0) {
  7154. pr_err("%s: Cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
  7155. __func__, ret, cal_type);
  7156. ret = -EINVAL;
  7157. goto done;
  7158. }
  7159. done:
  7160. return ret;
  7161. }
  7162. static int voice_dealloc_cal(int32_t cal_type,
  7163. size_t data_size, void *data)
  7164. {
  7165. int ret = 0;
  7166. int cal_index;
  7167. pr_debug("%s\n", __func__);
  7168. cal_index = get_cal_type_index(cal_type);
  7169. if (cal_index < 0) {
  7170. pr_err("%s: Could not get cal index %d!\n",
  7171. __func__, cal_index);
  7172. ret = -EINVAL;
  7173. goto done;
  7174. }
  7175. ret = cal_utils_dealloc_cal(data_size, data,
  7176. common.cal_data[cal_index]);
  7177. if (ret < 0) {
  7178. pr_err("%s: Cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
  7179. __func__, ret, cal_type);
  7180. ret = -EINVAL;
  7181. goto done;
  7182. }
  7183. done:
  7184. return ret;
  7185. }
  7186. static int voice_set_cal(int32_t cal_type,
  7187. size_t data_size, void *data)
  7188. {
  7189. int ret = 0;
  7190. int cal_index;
  7191. pr_debug("%s\n", __func__);
  7192. cal_index = get_cal_type_index(cal_type);
  7193. if (cal_index < 0) {
  7194. pr_err("%s: Could not get cal index %d!\n",
  7195. __func__, cal_index);
  7196. ret = -EINVAL;
  7197. goto done;
  7198. }
  7199. ret = cal_utils_set_cal(data_size, data,
  7200. common.cal_data[cal_index], 0, NULL);
  7201. if (ret < 0) {
  7202. pr_err("%s: Cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
  7203. __func__, ret, cal_type);
  7204. ret = -EINVAL;
  7205. goto done;
  7206. }
  7207. done:
  7208. return ret;
  7209. }
  7210. static void voice_delete_cal_data(void)
  7211. {
  7212. pr_debug("%s\n", __func__);
  7213. cal_utils_destroy_cal_types(MAX_VOICE_CAL_TYPES, common.cal_data);
  7214. }
  7215. static int voice_init_cal_data(void)
  7216. {
  7217. int ret = 0;
  7218. struct cal_type_info cal_type_info[] = {
  7219. {{CVP_VOC_RX_TOPOLOGY_CAL_TYPE,
  7220. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  7221. {NULL, NULL, cal_utils_match_buf_num} },
  7222. {{CVP_VOC_TX_TOPOLOGY_CAL_TYPE,
  7223. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  7224. {NULL, NULL, cal_utils_match_buf_num} },
  7225. {{CVP_VOCPROC_STATIC_CAL_TYPE,
  7226. {voice_alloc_cal, voice_dealloc_cal, NULL,
  7227. voice_set_cal, NULL, NULL} },
  7228. {NULL, voice_unmap_cal_memory,
  7229. cal_utils_match_buf_num} },
  7230. {{CVP_VOCPROC_DYNAMIC_CAL_TYPE,
  7231. {voice_alloc_cal, voice_dealloc_cal,
  7232. voice_prepare_volume_boost,
  7233. voice_set_cal, NULL,
  7234. voice_enable_volume_boost} },
  7235. {NULL, voice_unmap_cal_memory,
  7236. cal_utils_match_buf_num} },
  7237. {{CVP_VOCDEV_CFG_CAL_TYPE,
  7238. {voice_alloc_cal, voice_dealloc_cal, NULL,
  7239. voice_set_cal, NULL, NULL} },
  7240. {NULL, voice_unmap_cal_memory,
  7241. cal_utils_match_buf_num} },
  7242. {{CVP_VOCPROC_STATIC_COL_CAL_TYPE,
  7243. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  7244. {NULL, NULL, cal_utils_match_buf_num} },
  7245. {{CVP_VOCPROC_DYNAMIC_COL_CAL_TYPE,
  7246. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  7247. {NULL, NULL, cal_utils_match_buf_num} },
  7248. {{CVS_VOCSTRM_STATIC_CAL_TYPE,
  7249. {voice_alloc_cal, voice_dealloc_cal, NULL,
  7250. voice_set_cal, NULL, NULL} },
  7251. {NULL, voice_unmap_cal_memory,
  7252. cal_utils_match_buf_num} },
  7253. {{CVS_VOCSTRM_STATIC_COL_CAL_TYPE,
  7254. {NULL, NULL, NULL, voice_set_cal, NULL, NULL} },
  7255. {NULL, NULL, cal_utils_match_buf_num} },
  7256. {{VOICE_RTAC_INFO_CAL_TYPE,
  7257. {NULL, NULL, NULL, NULL, NULL, NULL} },
  7258. {NULL, NULL, cal_utils_match_buf_num} },
  7259. {{VOICE_RTAC_APR_CAL_TYPE,
  7260. {NULL, NULL, NULL, NULL, NULL, NULL} },
  7261. {NULL, NULL, cal_utils_match_buf_num} },
  7262. };
  7263. ret = cal_utils_create_cal_types(MAX_VOICE_CAL_TYPES, common.cal_data,
  7264. cal_type_info);
  7265. if (ret < 0) {
  7266. pr_err("%s: Could not create cal type!\n",
  7267. __func__);
  7268. ret = -EINVAL;
  7269. goto err;
  7270. }
  7271. return ret;
  7272. err:
  7273. voice_delete_cal_data();
  7274. memset(&common, 0, sizeof(struct common_data));
  7275. return ret;
  7276. }
  7277. static int voice_send_set_sound_focus_cmd(struct voice_data *v,
  7278. struct sound_focus_param soundFocusData)
  7279. {
  7280. struct cvp_set_sound_focus_param_cmd_t cvp_set_sound_focus_param_cmd;
  7281. int ret = 0;
  7282. void *apr_cvp;
  7283. u16 cvp_handle;
  7284. int i;
  7285. pr_debug("%s: Enter\n", __func__);
  7286. if (v == NULL) {
  7287. pr_err("%s: v is NULL\n", __func__);
  7288. ret = -EINVAL;
  7289. goto done;
  7290. }
  7291. apr_cvp = common.apr_q6_cvp;
  7292. if (!apr_cvp) {
  7293. pr_err("%s: apr_cvp is NULL.\n", __func__);
  7294. ret = -EINVAL;
  7295. goto done;
  7296. }
  7297. cvp_handle = voice_get_cvp_handle(v);
  7298. /* send Sound Focus Params to cvp */
  7299. cvp_set_sound_focus_param_cmd.hdr.hdr_field =
  7300. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  7301. APR_HDR_LEN(APR_HDR_SIZE),
  7302. APR_PKT_VER);
  7303. cvp_set_sound_focus_param_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  7304. sizeof(cvp_set_sound_focus_param_cmd) - APR_HDR_SIZE);
  7305. cvp_set_sound_focus_param_cmd.hdr.src_port =
  7306. voice_get_idx_for_session(v->session_id);
  7307. cvp_set_sound_focus_param_cmd.hdr.dest_port = cvp_handle;
  7308. cvp_set_sound_focus_param_cmd.hdr.token = 0;
  7309. cvp_set_sound_focus_param_cmd.hdr.opcode =
  7310. VSS_ISOUNDFOCUS_CMD_SET_SECTORS;
  7311. memset(&(cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param), 0xFF,
  7312. sizeof(struct vss_isoundfocus_cmd_set_sectors_t));
  7313. for (i = 0; i < MAX_SECTORS; i++) {
  7314. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.
  7315. start_angles[i] = soundFocusData.start_angle[i];
  7316. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.
  7317. enables[i] = soundFocusData.enable[i];
  7318. pr_debug("%s: start_angle[%d] = %d\n",
  7319. __func__, i, soundFocusData.start_angle[i]);
  7320. pr_debug("%s: enable[%d] = %d\n",
  7321. __func__, i, soundFocusData.enable[i]);
  7322. }
  7323. cvp_set_sound_focus_param_cmd.cvp_set_sound_focus_param.gain_step =
  7324. soundFocusData.gain_step;
  7325. pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
  7326. v->cvp_state = CMD_STATUS_FAIL;
  7327. v->async_err = 0;
  7328. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_set_sound_focus_param_cmd);
  7329. if (ret < 0) {
  7330. pr_err("%s: Error in sending APR command\n", __func__);
  7331. ret = -EINVAL;
  7332. goto done;
  7333. }
  7334. ret = wait_event_timeout(v->cvp_wait,
  7335. (v->cvp_state == CMD_STATUS_SUCCESS),
  7336. msecs_to_jiffies(TIMEOUT_MS));
  7337. if (!ret) {
  7338. pr_err("%s: wait_event timeout\n", __func__);
  7339. ret = -EINVAL;
  7340. goto done;
  7341. }
  7342. if (v->async_err > 0) {
  7343. pr_err("%s: DSP returned error[%s]\n",
  7344. __func__, adsp_err_get_err_str(
  7345. v->async_err));
  7346. ret = adsp_err_get_lnx_err_code(
  7347. v->async_err);
  7348. goto done;
  7349. }
  7350. if (common.is_sound_focus_resp_success) {
  7351. ret = 0;
  7352. } else {
  7353. pr_err("%s: Error in setting sound focus params\n", __func__);
  7354. ret = -EINVAL;
  7355. }
  7356. done:
  7357. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7358. return ret;
  7359. }
  7360. int voc_set_sound_focus(struct sound_focus_param soundFocusData)
  7361. {
  7362. struct voice_data *v = NULL;
  7363. int ret = -EINVAL;
  7364. struct voice_session_itr itr;
  7365. pr_debug("%s: Enter\n", __func__);
  7366. mutex_lock(&common.common_lock);
  7367. voice_itr_init(&itr, ALL_SESSION_VSID);
  7368. while (voice_itr_get_next_session(&itr, &v)) {
  7369. if (v != NULL) {
  7370. mutex_lock(&v->lock);
  7371. if (is_voc_state_active(v->voc_state) &&
  7372. (v->lch_mode != VOICE_LCH_START) &&
  7373. !v->disable_topology)
  7374. ret = voice_send_set_sound_focus_cmd(v,
  7375. soundFocusData);
  7376. mutex_unlock(&v->lock);
  7377. } else {
  7378. pr_err("%s: invalid session\n", __func__);
  7379. ret = -EINVAL;
  7380. break;
  7381. }
  7382. }
  7383. mutex_unlock(&common.common_lock);
  7384. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7385. return ret;
  7386. }
  7387. static int voice_send_get_sound_focus_cmd(struct voice_data *v,
  7388. struct sound_focus_param *soundFocusData)
  7389. {
  7390. struct apr_hdr cvp_get_sound_focus_param_cmd;
  7391. int ret = 0;
  7392. void *apr_cvp;
  7393. u16 cvp_handle;
  7394. int i;
  7395. pr_debug("%s: Enter\n", __func__);
  7396. if (!v) {
  7397. pr_err("%s: v is NULL\n", __func__);
  7398. ret = -EINVAL;
  7399. goto done;
  7400. }
  7401. apr_cvp = common.apr_q6_cvp;
  7402. if (!apr_cvp) {
  7403. pr_err("%s: apr_cvp is NULL\n", __func__);
  7404. ret = -EINVAL;
  7405. goto done;
  7406. }
  7407. cvp_handle = voice_get_cvp_handle(v);
  7408. /* send APR command to retrieve Sound Focus Params */
  7409. cvp_get_sound_focus_param_cmd.hdr_field =
  7410. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  7411. APR_HDR_LEN(APR_HDR_SIZE),
  7412. APR_PKT_VER);
  7413. cvp_get_sound_focus_param_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  7414. sizeof(cvp_get_sound_focus_param_cmd) - APR_HDR_SIZE);
  7415. cvp_get_sound_focus_param_cmd.src_port =
  7416. voice_get_idx_for_session(v->session_id);
  7417. cvp_get_sound_focus_param_cmd.dest_port = cvp_handle;
  7418. cvp_get_sound_focus_param_cmd.token = 0;
  7419. cvp_get_sound_focus_param_cmd.opcode = VSS_ISOUNDFOCUS_CMD_GET_SECTORS;
  7420. v->cvp_state = CMD_STATUS_FAIL;
  7421. v->async_err = 0;
  7422. ret = apr_send_pkt(apr_cvp, (uint32_t *)&cvp_get_sound_focus_param_cmd);
  7423. if (ret < 0) {
  7424. pr_err("%s: Error in sending APR command\n", __func__);
  7425. ret = -EINVAL;
  7426. goto done;
  7427. }
  7428. ret = wait_event_timeout(v->cvp_wait,
  7429. (v->cvp_state == CMD_STATUS_SUCCESS),
  7430. msecs_to_jiffies(TIMEOUT_MS));
  7431. if (!ret) {
  7432. pr_err("%s: wait_event timeout\n", __func__);
  7433. ret = -EINVAL;
  7434. goto done;
  7435. }
  7436. if (v->async_err > 0) {
  7437. pr_err("%s: DSP returned error[%s]\n",
  7438. __func__, adsp_err_get_err_str(
  7439. v->async_err));
  7440. ret = adsp_err_get_lnx_err_code(
  7441. v->async_err);
  7442. goto done;
  7443. }
  7444. if (common.is_sound_focus_resp_success) {
  7445. for (i = 0; i < MAX_SECTORS; i++) {
  7446. soundFocusData->start_angle[i] =
  7447. common.soundFocusResponse.start_angles[i];
  7448. soundFocusData->enable[i] =
  7449. common.soundFocusResponse.enables[i];
  7450. pr_debug("%s: start_angle[%d] = %d\n",
  7451. __func__, i, soundFocusData->start_angle[i]);
  7452. pr_debug("%s: enable[%d] = %d\n",
  7453. __func__, i, soundFocusData->enable[i]);
  7454. }
  7455. soundFocusData->gain_step = common.soundFocusResponse.gain_step;
  7456. pr_debug("%s: gain_step = %d\n", __func__,
  7457. soundFocusData->gain_step);
  7458. common.is_sound_focus_resp_success = false;
  7459. ret = 0;
  7460. } else {
  7461. pr_err("%s: Invalid payload received from CVD\n", __func__);
  7462. ret = -EINVAL;
  7463. }
  7464. done:
  7465. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7466. return ret;
  7467. }
  7468. int voc_get_sound_focus(struct sound_focus_param *soundFocusData)
  7469. {
  7470. struct voice_data *v = NULL;
  7471. int ret = -EINVAL;
  7472. struct voice_session_itr itr;
  7473. pr_debug("%s: Enter\n", __func__);
  7474. mutex_lock(&common.common_lock);
  7475. voice_itr_init(&itr, ALL_SESSION_VSID);
  7476. while (voice_itr_get_next_session(&itr, &v)) {
  7477. if (v) {
  7478. mutex_lock(&v->lock);
  7479. if (is_voc_state_active(v->voc_state) &&
  7480. (v->lch_mode != VOICE_LCH_START) &&
  7481. !v->disable_topology)
  7482. ret = voice_send_get_sound_focus_cmd(v,
  7483. soundFocusData);
  7484. mutex_unlock(&v->lock);
  7485. } else {
  7486. pr_err("%s: invalid session\n", __func__);
  7487. ret = -EINVAL;
  7488. break;
  7489. }
  7490. }
  7491. mutex_unlock(&common.common_lock);
  7492. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7493. return ret;
  7494. }
  7495. static int is_source_tracking_shared_memomry_allocated(void)
  7496. {
  7497. bool ret;
  7498. pr_debug("%s: Enter\n", __func__);
  7499. if (common.source_tracking_sh_mem.sh_mem_block.client != NULL &&
  7500. common.source_tracking_sh_mem.sh_mem_block.handle != NULL)
  7501. ret = true;
  7502. else
  7503. ret = false;
  7504. pr_debug("%s: Exit\n", __func__);
  7505. return ret;
  7506. }
  7507. static int voice_alloc_source_tracking_shared_memory(void)
  7508. {
  7509. int ret = 0;
  7510. pr_debug("%s: Enter\n", __func__);
  7511. ret = msm_audio_ion_alloc("source_tracking_sh_mem_block",
  7512. &(common.source_tracking_sh_mem.sh_mem_block.client),
  7513. &(common.source_tracking_sh_mem.sh_mem_block.handle),
  7514. BUFFER_BLOCK_SIZE,
  7515. &(common.source_tracking_sh_mem.sh_mem_block.phys),
  7516. (size_t *)&(common.source_tracking_sh_mem.sh_mem_block.size),
  7517. &(common.source_tracking_sh_mem.sh_mem_block.data));
  7518. if (ret < 0) {
  7519. pr_err("%s: audio ION alloc failed for sh_mem block, ret = %d\n",
  7520. __func__, ret);
  7521. ret = -EINVAL;
  7522. goto done;
  7523. }
  7524. memset((void *)(common.source_tracking_sh_mem.sh_mem_block.data), 0,
  7525. common.source_tracking_sh_mem.sh_mem_block.size);
  7526. pr_debug("%s: sh_mem_block: phys:[%pK], data:[0x%pK], size:[%zd]\n",
  7527. __func__,
  7528. &(common.source_tracking_sh_mem.sh_mem_block.phys),
  7529. (void *)(common.source_tracking_sh_mem.sh_mem_block.data),
  7530. (size_t)(common.source_tracking_sh_mem.sh_mem_block.size));
  7531. ret = msm_audio_ion_alloc("source_tracking_sh_mem_table",
  7532. &(common.source_tracking_sh_mem.sh_mem_table.client),
  7533. &(common.source_tracking_sh_mem.sh_mem_table.handle),
  7534. sizeof(struct vss_imemory_table_t),
  7535. &(common.source_tracking_sh_mem.sh_mem_table.phys),
  7536. (size_t *)&(common.source_tracking_sh_mem.sh_mem_table.size),
  7537. &(common.source_tracking_sh_mem.sh_mem_table.data));
  7538. if (ret < 0) {
  7539. pr_err("%s: audio ION alloc failed for sh_mem table, ret = %d\n",
  7540. __func__, ret);
  7541. ret = msm_audio_ion_free(
  7542. common.source_tracking_sh_mem.sh_mem_block.client,
  7543. common.source_tracking_sh_mem.sh_mem_block.handle);
  7544. common.source_tracking_sh_mem.sh_mem_block.client = NULL;
  7545. common.source_tracking_sh_mem.sh_mem_block.handle = NULL;
  7546. if (ret < 0)
  7547. pr_err("%s: Error:%d freeing memory\n", __func__, ret);
  7548. ret = -EINVAL;
  7549. goto done;
  7550. }
  7551. memset((void *)(common.source_tracking_sh_mem.sh_mem_table.data), 0,
  7552. common.source_tracking_sh_mem.sh_mem_table.size);
  7553. pr_debug("%s sh_mem_table: phys:[%pK], data:[0x%pK], size:[%zd],\n",
  7554. __func__,
  7555. &(common.source_tracking_sh_mem.sh_mem_table.phys),
  7556. (void *)(common.source_tracking_sh_mem.sh_mem_table.data),
  7557. (size_t)(common.source_tracking_sh_mem.sh_mem_table.size));
  7558. done:
  7559. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7560. return ret;
  7561. }
  7562. static int voice_alloc_and_map_source_tracking_shared_memory(
  7563. struct voice_data *v)
  7564. {
  7565. int ret = 0;
  7566. pr_debug("%s: Enter\n", __func__);
  7567. ret = voice_alloc_source_tracking_shared_memory();
  7568. if (ret) {
  7569. pr_err("%s: Failed to allocate shared memory %d\n",
  7570. __func__, ret);
  7571. ret = -EINVAL;
  7572. goto done;
  7573. }
  7574. ret = voice_map_memory_physical_cmd(v,
  7575. &(common.source_tracking_sh_mem.sh_mem_table),
  7576. common.source_tracking_sh_mem.sh_mem_block.phys,
  7577. common.source_tracking_sh_mem.sh_mem_block.size,
  7578. VOC_SOURCE_TRACKING_MEM_MAP_TOKEN);
  7579. if (ret) {
  7580. pr_err("%s: memory mapping failed %d\n",
  7581. __func__, ret);
  7582. ret = -EINVAL;
  7583. goto done;
  7584. }
  7585. done:
  7586. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7587. return ret;
  7588. }
  7589. static int voice_unmap_and_free_source_tracking_shared_memory(
  7590. struct voice_data *v)
  7591. {
  7592. int ret = 0;
  7593. pr_debug("%s: Enter\n", __func__);
  7594. if (common.source_tracking_sh_mem.mem_handle != 0) {
  7595. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  7596. common.source_tracking_sh_mem.mem_handle);
  7597. if (ret < 0) {
  7598. pr_err("%s: Memory_unmap failed err %d\n",
  7599. __func__, ret);
  7600. ret = -EINVAL;
  7601. goto done;
  7602. }
  7603. }
  7604. if ((common.source_tracking_sh_mem.sh_mem_block.client == NULL) ||
  7605. (common.source_tracking_sh_mem.sh_mem_block.handle == NULL))
  7606. goto done;
  7607. ret = msm_audio_ion_free(
  7608. common.source_tracking_sh_mem.sh_mem_block.client,
  7609. common.source_tracking_sh_mem.sh_mem_block.handle);
  7610. if (ret < 0) {
  7611. pr_err("%s: Error:%d freeing memory\n", __func__, ret);
  7612. ret = -EINVAL;
  7613. goto done;
  7614. }
  7615. done:
  7616. common.source_tracking_sh_mem.mem_handle = 0;
  7617. common.source_tracking_sh_mem.sh_mem_block.client = NULL;
  7618. common.source_tracking_sh_mem.sh_mem_block.handle = NULL;
  7619. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7620. return ret;
  7621. }
  7622. static int voice_send_get_source_tracking_cmd(struct voice_data *v,
  7623. struct source_tracking_param *sourceTrackingData)
  7624. {
  7625. struct cvp_get_source_tracking_param_cmd_t st_cmd;
  7626. int ret = 0;
  7627. void *apr_cvp;
  7628. u16 cvp_handle;
  7629. int i;
  7630. pr_debug("%s: Enter\n", __func__);
  7631. if (!v) {
  7632. pr_err("%s: v is NULL\n", __func__);
  7633. return -EINVAL;
  7634. }
  7635. apr_cvp = common.apr_q6_cvp;
  7636. if (!apr_cvp) {
  7637. pr_err("%s: apr_cvp is NULL.\n", __func__);
  7638. return -EINVAL;
  7639. }
  7640. cvp_handle = voice_get_cvp_handle(v);
  7641. if (!is_source_tracking_shared_memomry_allocated()) {
  7642. ret = voice_alloc_and_map_source_tracking_shared_memory(v);
  7643. if (ret) {
  7644. pr_err("%s: Fail in allocating/mapping shared memory\n",
  7645. __func__);
  7646. ret = -EINVAL;
  7647. goto done;
  7648. }
  7649. }
  7650. st_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  7651. APR_HDR_LEN(APR_HDR_SIZE),
  7652. APR_PKT_VER);
  7653. st_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  7654. sizeof(st_cmd) - APR_HDR_SIZE);
  7655. st_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  7656. st_cmd.hdr.dest_port = cvp_handle;
  7657. st_cmd.hdr.token = 0;
  7658. st_cmd.hdr.opcode = VSS_ISOURCETRACK_CMD_GET_ACTIVITY;
  7659. st_cmd.cvp_get_source_tracking_param.mem_handle =
  7660. common.source_tracking_sh_mem.mem_handle;
  7661. st_cmd.cvp_get_source_tracking_param.mem_address_lsw =
  7662. lower_32_bits(common.source_tracking_sh_mem.sh_mem_block.phys);
  7663. st_cmd.cvp_get_source_tracking_param.mem_address_msw =
  7664. msm_audio_populate_upper_32_bits(common.source_tracking_sh_mem.
  7665. sh_mem_block.phys);
  7666. st_cmd.cvp_get_source_tracking_param.mem_size =
  7667. (uint32_t)common.source_tracking_sh_mem.sh_mem_block.size;
  7668. pr_debug("%s: mem_handle=0x%x, mem_address_lsw=0x%x, msw=0x%x, mem_size=%d\n",
  7669. __func__,
  7670. st_cmd.cvp_get_source_tracking_param.mem_handle,
  7671. st_cmd.cvp_get_source_tracking_param.mem_address_lsw,
  7672. st_cmd.cvp_get_source_tracking_param.mem_address_msw,
  7673. (uint32_t)st_cmd.cvp_get_source_tracking_param.mem_size);
  7674. v->cvp_state = CMD_STATUS_FAIL;
  7675. v->async_err = 0;
  7676. ret = apr_send_pkt(apr_cvp,
  7677. (uint32_t *) &st_cmd);
  7678. if (ret < 0) {
  7679. pr_err("%s: Error in sending APR command\n", __func__);
  7680. ret = -EINVAL;
  7681. goto done;
  7682. }
  7683. ret = wait_event_timeout(v->cvp_wait,
  7684. (v->cvp_state == CMD_STATUS_SUCCESS),
  7685. msecs_to_jiffies(TIMEOUT_MS));
  7686. if (!ret) {
  7687. pr_err("%s: wait_event timeout\n", __func__);
  7688. ret = -EINVAL;
  7689. goto done;
  7690. }
  7691. if (v->async_err > 0) {
  7692. pr_err("%s: DSP returned error[%s]\n",
  7693. __func__, adsp_err_get_err_str(
  7694. v->async_err));
  7695. ret = adsp_err_get_lnx_err_code(
  7696. v->async_err);
  7697. goto done;
  7698. }
  7699. if (common.is_source_tracking_resp_success) {
  7700. for (i = 0; i < MAX_SECTORS; i++) {
  7701. sourceTrackingData->vad[i] =
  7702. common.sourceTrackingResponse.voice_active[i];
  7703. pr_debug("%s: vad[%d] = %d\n",
  7704. __func__, i, sourceTrackingData->vad[i]);
  7705. }
  7706. sourceTrackingData->doa_speech =
  7707. common.sourceTrackingResponse.talker_doa;
  7708. pr_debug("%s: doa_speech = %d\n",
  7709. __func__, sourceTrackingData->doa_speech);
  7710. for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
  7711. sourceTrackingData->doa_noise[i] =
  7712. common.sourceTrackingResponse.interferer_doa[i];
  7713. pr_debug("%s: doa_noise[%d] = %d\n",
  7714. __func__, i, sourceTrackingData->doa_noise[i]);
  7715. }
  7716. for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
  7717. sourceTrackingData->polar_activity[i] =
  7718. common.sourceTrackingResponse.sound_strength[i];
  7719. pr_debug("%s: polar_activity[%d] = %d\n",
  7720. __func__, i, sourceTrackingData->polar_activity[i]);
  7721. }
  7722. common.is_source_tracking_resp_success = false;
  7723. ret = 0;
  7724. } else {
  7725. pr_err("%s: Error response received from CVD\n", __func__);
  7726. ret = -EINVAL;
  7727. }
  7728. done:
  7729. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7730. return ret;
  7731. }
  7732. int voc_get_source_tracking(struct source_tracking_param *sourceTrackingData)
  7733. {
  7734. struct voice_data *v = NULL;
  7735. int ret = -EINVAL;
  7736. struct voice_session_itr itr;
  7737. pr_debug("%s: Enter\n", __func__);
  7738. mutex_lock(&common.common_lock);
  7739. voice_itr_init(&itr, ALL_SESSION_VSID);
  7740. while (voice_itr_get_next_session(&itr, &v)) {
  7741. if (v != NULL) {
  7742. mutex_lock(&v->lock);
  7743. if (is_voc_state_active(v->voc_state) &&
  7744. (v->lch_mode != VOICE_LCH_START) &&
  7745. !v->disable_topology)
  7746. ret = voice_send_get_source_tracking_cmd(v,
  7747. sourceTrackingData);
  7748. mutex_unlock(&v->lock);
  7749. } else {
  7750. pr_err("%s: invalid session\n", __func__);
  7751. break;
  7752. }
  7753. }
  7754. mutex_unlock(&common.common_lock);
  7755. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  7756. return ret;
  7757. }
  7758. int is_voc_initialized(void)
  7759. {
  7760. return module_initialized;
  7761. }
  7762. static int __init voice_init(void)
  7763. {
  7764. int rc = 0, i = 0;
  7765. memset(&common, 0, sizeof(struct common_data));
  7766. /* set default value */
  7767. common.default_mute_val = 0; /* default is un-mute */
  7768. common.default_sample_val = 8000;
  7769. common.default_vol_step_val = 0;
  7770. common.default_vol_ramp_duration_ms = DEFAULT_VOLUME_RAMP_DURATION;
  7771. common.default_mute_ramp_duration_ms = DEFAULT_MUTE_RAMP_DURATION;
  7772. common.cvp_version = 0;
  7773. common.is_avcs_version_queried = false;
  7774. /* Initialize EC Ref media format info */
  7775. common.ec_ref_ext = false;
  7776. common.ec_media_fmt_info.port_id = AFE_PORT_INVALID;
  7777. common.ec_media_fmt_info.num_channels = 0;
  7778. common.ec_media_fmt_info.bits_per_sample = 16;
  7779. common.ec_media_fmt_info.sample_rate = 8000;
  7780. memset(&common.ec_media_fmt_info.channel_mapping, 0,
  7781. VSS_CHANNEL_MAPPING_SIZE);
  7782. /* Initialize AFE Sidetone Enable */
  7783. common.sidetone_enable = false;
  7784. /* Initialize MVS info. */
  7785. common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
  7786. /* Initialize is low memory flag */
  7787. common.is_destroy_cvd = false;
  7788. /* Initialize CVD version */
  7789. strlcpy(common.cvd_version, CVD_VERSION_DEFAULT,
  7790. sizeof(common.cvd_version));
  7791. /* Initialize Per-Vocoder Calibration flag */
  7792. common.is_per_vocoder_cal_enabled = false;
  7793. mutex_init(&common.common_lock);
  7794. /* Initialize session id with vsid */
  7795. init_session_id();
  7796. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  7797. /* initialize dev_rx and dev_tx */
  7798. common.voice[i].dev_rx.dev_mute = common.default_mute_val;
  7799. common.voice[i].dev_tx.dev_mute = common.default_mute_val;
  7800. common.voice[i].dev_rx.volume_step_value =
  7801. common.default_vol_step_val;
  7802. common.voice[i].dev_rx.volume_ramp_duration_ms =
  7803. common.default_vol_ramp_duration_ms;
  7804. common.voice[i].dev_rx.dev_mute_ramp_duration_ms =
  7805. common.default_mute_ramp_duration_ms;
  7806. common.voice[i].dev_tx.dev_mute_ramp_duration_ms =
  7807. common.default_mute_ramp_duration_ms;
  7808. common.voice[i].stream_rx.stream_mute = common.default_mute_val;
  7809. common.voice[i].stream_tx.stream_mute = common.default_mute_val;
  7810. common.voice[i].dev_tx.port_id = 0x100B;
  7811. common.voice[i].dev_rx.port_id = 0x100A;
  7812. common.voice[i].dev_tx.dev_id = 0;
  7813. common.voice[i].dev_rx.dev_id = 0;
  7814. common.voice[i].dev_tx.no_of_channels = 0;
  7815. common.voice[i].dev_rx.no_of_channels = 0;
  7816. common.voice[i].dev_tx.sample_rate = 8000;
  7817. common.voice[i].dev_rx.sample_rate = 8000;
  7818. common.voice[i].dev_tx.bits_per_sample = 16;
  7819. common.voice[i].dev_rx.bits_per_sample = 16;
  7820. memset(&common.voice[i].dev_tx.channel_mapping, 0,
  7821. VSS_CHANNEL_MAPPING_SIZE);
  7822. memset(&common.voice[i].dev_rx.channel_mapping, 0,
  7823. VSS_CHANNEL_MAPPING_SIZE);
  7824. common.voice[i].sidetone_gain = 0x512;
  7825. common.voice[i].dtmf_rx_detect_en = 0;
  7826. common.voice[i].lch_mode = 0;
  7827. common.voice[i].disable_topology = false;
  7828. common.voice[i].voc_state = VOC_INIT;
  7829. init_waitqueue_head(&common.voice[i].mvm_wait);
  7830. init_waitqueue_head(&common.voice[i].cvs_wait);
  7831. init_waitqueue_head(&common.voice[i].cvp_wait);
  7832. mutex_init(&common.voice[i].lock);
  7833. }
  7834. if (voice_init_cal_data())
  7835. pr_err("%s: Could not init cal data!\n", __func__);
  7836. if (rc == 0)
  7837. module_initialized = true;
  7838. pr_debug("%s: rc=%d\n", __func__, rc);
  7839. return rc;
  7840. }
  7841. device_initcall(voice_init);
  7842. static void __exit voice_exit(void)
  7843. {
  7844. voice_delete_cal_data();
  7845. free_cal_map_table();
  7846. }
  7847. __exitcall(voice_exit);