q6voice.c 229 KB

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