q6voice.c 263 KB

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