q6voice.c 254 KB

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