q6voice.c 259 KB

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