q6voice.c 255 KB

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