q6voice.c 228 KB

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