q6voice.c 265 KB

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