q6voice.c 245 KB

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