q6voice.c 254 KB

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