q6voice.c 259 KB

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