q6voice.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421
  1. /* Copyright (c) 2012-2014, 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 <linux/msm_audio_ion.h>
  20. #include <asm/mach-types.h>
  21. #include <mach/socinfo.h>
  22. #include <mach/qdsp6v2/apr_tal.h>
  23. #include "sound/apr_audio-v2.h"
  24. #include "sound/q6afe-v2.h"
  25. #include "audio_acdb.h"
  26. #include "q6voice.h"
  27. #define TIMEOUT_MS 500
  28. #define CMD_STATUS_SUCCESS 0
  29. #define CMD_STATUS_FAIL 1
  30. /* CVP CAL Size: 245760 = 240 * 1024 */
  31. #define CVP_CAL_SIZE 245760
  32. /* CVS CAL Size: 49152 = 48 * 1024 */
  33. #define CVS_CAL_SIZE 49152
  34. enum {
  35. VOC_TOKEN_NONE,
  36. VOIP_MEM_MAP_TOKEN,
  37. VOC_CAL_MEM_MAP_TOKEN,
  38. VOC_RTAC_MEM_MAP_TOKEN
  39. };
  40. static struct common_data common;
  41. static bool module_initialized;
  42. static int loopback_mode = 0;
  43. static int loopback_prev_mode = 0;
  44. static int dha_state = 0;
  45. static int In_roaming = 0;
  46. int voc_get_loopback_enable(void)
  47. {
  48. return loopback_mode;
  49. }
  50. void voc_set_loopback_enable(int mode)
  51. {
  52. loopback_prev_mode = loopback_mode;
  53. loopback_mode = mode;
  54. pr_info("%s : prev_mode = %d, mode = %d\n",
  55. __func__, loopback_prev_mode, mode);
  56. }
  57. int voc_get_roaming_enable(void)
  58. {
  59. return In_roaming;
  60. }
  61. void voc_set_roaming_enable(int mode)
  62. {
  63. In_roaming = mode;
  64. pr_info("%s : In_roaming = %d, mode = %d\n",
  65. __func__, In_roaming, mode);
  66. }
  67. static int voice_send_enable_vocproc_cmd(struct voice_data *v);
  68. static int voice_send_netid_timing_cmd(struct voice_data *v);
  69. static int voice_send_attach_vocproc_cmd(struct voice_data *v);
  70. static int voice_send_set_device_cmd(struct voice_data *v);
  71. static int voice_send_disable_vocproc_cmd(struct voice_data *v);
  72. static int voice_send_vol_step_cmd(struct voice_data *v);
  73. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  74. uint32_t mem_handle);
  75. static int voice_send_mvm_cal_network_cmd(struct voice_data *v);
  76. static int voice_send_mvm_media_type_cmd(struct voice_data *v);
  77. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v);
  78. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v);
  79. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  80. uint32_t mode);
  81. static int voice_send_cvs_register_cal_cmd(struct voice_data *v);
  82. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v);
  83. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v);
  84. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v);
  85. static int voice_send_cvp_register_cal_cmd(struct voice_data *v);
  86. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v);
  87. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v);
  88. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v);
  89. static int voice_cvs_stop_playback(struct voice_data *v);
  90. static int voice_cvs_start_playback(struct voice_data *v);
  91. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode);
  92. static int voice_cvs_stop_record(struct voice_data *v);
  93. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
  94. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
  95. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
  96. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  97. uint32_t module_id, int enable);
  98. static int send_packet_loopback_cmd(struct voice_data *v, bool mode);
  99. static int is_cal_memory_allocated(void);
  100. static int is_voip_memory_allocated(void);
  101. static int voice_alloc_cal_mem_map_table(void);
  102. static int voice_alloc_rtac_mem_map_table(void);
  103. static int voice_alloc_oob_shared_mem(void);
  104. static int voice_free_oob_shared_mem(void);
  105. static int voice_alloc_oob_mem_table(void);
  106. static int voice_alloc_and_map_cal_mem(struct voice_data *v);
  107. static int voice_alloc_and_map_oob_mem(struct voice_data *v);
  108. static int voc_disable_cvp(uint32_t session_id);
  109. static int voc_enable_cvp(uint32_t session_id);
  110. static struct voice_data *voice_get_session_by_idx(int idx);
  111. static void voice_itr_init(struct voice_session_itr *itr,
  112. u32 session_id)
  113. {
  114. if (itr == NULL)
  115. return;
  116. itr->session_idx = voice_get_idx_for_session(session_id);
  117. if (session_id == ALL_SESSION_VSID)
  118. itr->cur_idx = 0;
  119. else
  120. itr->cur_idx = itr->session_idx;
  121. }
  122. static bool voice_itr_get_next_session(struct voice_session_itr *itr,
  123. struct voice_data **voice)
  124. {
  125. bool ret = false;
  126. if (itr == NULL)
  127. return false;
  128. pr_debug("%s : cur idx = %d session idx = %d",
  129. __func__, itr->cur_idx, itr->session_idx);
  130. if (itr->cur_idx <= itr->session_idx) {
  131. ret = true;
  132. *voice = voice_get_session_by_idx(itr->cur_idx);
  133. itr->cur_idx++;
  134. } else {
  135. *voice = NULL;
  136. }
  137. return ret;
  138. }
  139. static bool voice_is_valid_session_id(uint32_t session_id)
  140. {
  141. bool ret = false;
  142. switch (session_id) {
  143. case VOICE_SESSION_VSID:
  144. case VOICE2_SESSION_VSID:
  145. case VOLTE_SESSION_VSID:
  146. case VOIP_SESSION_VSID:
  147. case QCHAT_SESSION_VSID:
  148. case VOWLAN_SESSION_VSID:
  149. case ALL_SESSION_VSID:
  150. ret = true;
  151. break;
  152. default:
  153. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  154. break;
  155. }
  156. return ret;
  157. }
  158. static u16 voice_get_mvm_handle(struct voice_data *v)
  159. {
  160. if (v == NULL) {
  161. pr_err("%s: v is NULL\n", __func__);
  162. return 0;
  163. }
  164. pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
  165. return v->mvm_handle;
  166. }
  167. static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
  168. {
  169. pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
  170. if (v == NULL) {
  171. pr_err("%s: v is NULL\n", __func__);
  172. return;
  173. }
  174. v->mvm_handle = mvm_handle;
  175. }
  176. static u16 voice_get_cvs_handle(struct voice_data *v)
  177. {
  178. if (v == NULL) {
  179. pr_err("%s: v is NULL\n", __func__);
  180. return 0;
  181. }
  182. pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
  183. return v->cvs_handle;
  184. }
  185. static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
  186. {
  187. pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
  188. if (v == NULL) {
  189. pr_err("%s: v is NULL\n", __func__);
  190. return;
  191. }
  192. v->cvs_handle = cvs_handle;
  193. }
  194. static u16 voice_get_cvp_handle(struct voice_data *v)
  195. {
  196. if (v == NULL) {
  197. pr_err("%s: v is NULL\n", __func__);
  198. return 0;
  199. }
  200. pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
  201. return v->cvp_handle;
  202. }
  203. static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
  204. {
  205. pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
  206. if (v == NULL) {
  207. pr_err("%s: v is NULL\n", __func__);
  208. return;
  209. }
  210. v->cvp_handle = cvp_handle;
  211. }
  212. char *voc_get_session_name(u32 session_id)
  213. {
  214. char *session_name = NULL;
  215. if (session_id == common.voice[VOC_PATH_PASSIVE].session_id) {
  216. session_name = VOICE_SESSION_NAME;
  217. } else if (session_id ==
  218. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id) {
  219. session_name = VOLTE_SESSION_NAME;
  220. } else if (session_id ==
  221. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id) {
  222. session_name = QCHAT_SESSION_NAME;
  223. } else if (session_id ==
  224. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id) {
  225. session_name = VOWLAN_SESSION_NAME;
  226. } else if (session_id == common.voice[VOC_PATH_FULL].session_id) {
  227. session_name = VOIP_SESSION_NAME;
  228. }
  229. return session_name;
  230. }
  231. uint32_t voc_get_session_id(char *name)
  232. {
  233. u32 session_id = 0;
  234. if (name != NULL) {
  235. if (!strncmp(name, "Voice session", 13))
  236. session_id = common.voice[VOC_PATH_PASSIVE].session_id;
  237. else if (!strncmp(name, "Voice2 session", 14))
  238. session_id =
  239. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id;
  240. else if (!strncmp(name, "VoLTE session", 13))
  241. session_id =
  242. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id;
  243. else if (!strncmp(name, "QCHAT session", 13))
  244. session_id =
  245. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id;
  246. else if (!strncmp(name, "VoWLAN session", 14))
  247. session_id =
  248. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id;
  249. else
  250. session_id = common.voice[VOC_PATH_FULL].session_id;
  251. pr_debug("%s: %s has session id 0x%x\n", __func__, name,
  252. session_id);
  253. }
  254. return session_id;
  255. }
  256. static struct voice_data *voice_get_session(u32 session_id)
  257. {
  258. struct voice_data *v = NULL;
  259. switch (session_id) {
  260. case VOICE_SESSION_VSID:
  261. v = &common.voice[VOC_PATH_PASSIVE];
  262. break;
  263. case VOICE2_SESSION_VSID:
  264. v = &common.voice[VOC_PATH_VOICE2_PASSIVE];
  265. break;
  266. case VOLTE_SESSION_VSID:
  267. v = &common.voice[VOC_PATH_VOLTE_PASSIVE];
  268. break;
  269. case VOIP_SESSION_VSID:
  270. v = &common.voice[VOC_PATH_FULL];
  271. break;
  272. case QCHAT_SESSION_VSID:
  273. v = &common.voice[VOC_PATH_QCHAT_PASSIVE];
  274. break;
  275. case VOWLAN_SESSION_VSID:
  276. v = &common.voice[VOC_PATH_VOWLAN_PASSIVE];
  277. break;
  278. case ALL_SESSION_VSID:
  279. break;
  280. default:
  281. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  282. break;
  283. }
  284. pr_debug("%s:session_id 0x%x session handle 0x%x\n",
  285. __func__, session_id, (unsigned int)v);
  286. return v;
  287. }
  288. int voice_get_idx_for_session(u32 session_id)
  289. {
  290. int idx = 0;
  291. switch (session_id) {
  292. case VOICE_SESSION_VSID:
  293. idx = VOC_PATH_PASSIVE;
  294. break;
  295. case VOICE2_SESSION_VSID:
  296. idx = VOC_PATH_VOICE2_PASSIVE;
  297. break;
  298. case VOLTE_SESSION_VSID:
  299. idx = VOC_PATH_VOLTE_PASSIVE;
  300. break;
  301. case VOIP_SESSION_VSID:
  302. idx = VOC_PATH_FULL;
  303. break;
  304. case QCHAT_SESSION_VSID:
  305. idx = VOC_PATH_QCHAT_PASSIVE;
  306. break;
  307. case VOWLAN_SESSION_VSID:
  308. idx = VOC_PATH_VOWLAN_PASSIVE;
  309. break;
  310. case ALL_SESSION_VSID:
  311. idx = MAX_VOC_SESSIONS - 1;
  312. break;
  313. default:
  314. pr_err("%s: Invalid session_id : %x\n", __func__, session_id);
  315. break;
  316. }
  317. return idx;
  318. }
  319. static struct voice_data *voice_get_session_by_idx(int idx)
  320. {
  321. return ((idx < 0 || idx >= MAX_VOC_SESSIONS) ?
  322. NULL : &common.voice[idx]);
  323. }
  324. static bool is_voice_session(u32 session_id)
  325. {
  326. return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
  327. }
  328. static bool is_voip_session(u32 session_id)
  329. {
  330. return (session_id == common.voice[VOC_PATH_FULL].session_id);
  331. }
  332. static bool is_volte_session(u32 session_id)
  333. {
  334. return (session_id == common.voice[VOC_PATH_VOLTE_PASSIVE].session_id);
  335. }
  336. static bool is_voice2_session(u32 session_id)
  337. {
  338. return (session_id == common.voice[VOC_PATH_VOICE2_PASSIVE].session_id);
  339. }
  340. static bool is_qchat_session(u32 session_id)
  341. {
  342. return (session_id == common.voice[VOC_PATH_QCHAT_PASSIVE].session_id);
  343. }
  344. static bool is_vowlan_session(u32 session_id)
  345. {
  346. return (session_id == common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id);
  347. }
  348. static bool is_voc_state_active(int voc_state)
  349. {
  350. if ((voc_state == VOC_RUN) ||
  351. (voc_state == VOC_CHANGE) ||
  352. (voc_state == VOC_STANDBY))
  353. return true;
  354. return false;
  355. }
  356. static void voc_set_error_state(uint16_t reset_proc)
  357. {
  358. struct voice_data *v = NULL;
  359. int i;
  360. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  361. if (reset_proc == APR_DEST_MODEM && i == VOC_PATH_FULL)
  362. continue;
  363. v = &common.voice[i];
  364. if (v != NULL)
  365. v->voc_state = VOC_ERROR;
  366. }
  367. }
  368. static bool is_other_session_active(u32 session_id)
  369. {
  370. int i;
  371. bool ret = false;
  372. /* Check if there is other active session except the input one */
  373. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  374. if (common.voice[i].session_id == session_id)
  375. continue;
  376. if (is_voc_state_active(common.voice[i].voc_state)) {
  377. ret = true;
  378. break;
  379. }
  380. }
  381. pr_debug("%s: ret %d\n", __func__, ret);
  382. return ret;
  383. }
  384. static bool is_voice_app_id(u32 session_id)
  385. {
  386. return (((session_id & APP_ID_MASK) >> APP_ID_SHIFT) ==
  387. VSID_APP_CS_VOICE);
  388. }
  389. static void init_session_id(void)
  390. {
  391. common.voice[VOC_PATH_PASSIVE].session_id = VOICE_SESSION_VSID;
  392. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id = VOLTE_SESSION_VSID;
  393. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id = VOICE2_SESSION_VSID;
  394. common.voice[VOC_PATH_FULL].session_id = VOIP_SESSION_VSID;
  395. common.voice[VOC_PATH_QCHAT_PASSIVE].session_id = QCHAT_SESSION_VSID;
  396. common.voice[VOC_PATH_VOWLAN_PASSIVE].session_id = VOWLAN_SESSION_VSID;
  397. }
  398. static int voice_apr_register(void)
  399. {
  400. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  401. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  402. void *modem_mvm, *modem_cvs, *modem_cvp;
  403. #endif
  404. pr_debug("%s\n", __func__);
  405. mutex_lock(&common.common_lock);
  406. /* register callback to APR */
  407. if (common.apr_q6_mvm == NULL) {
  408. pr_debug("%s: Start to register MVM callback\n", __func__);
  409. common.apr_q6_mvm = apr_register("ADSP", "MVM",
  410. qdsp_mvm_callback,
  411. 0xFFFFFFFF, &common);
  412. if (common.apr_q6_mvm == NULL) {
  413. pr_err("%s: Unable to register MVM\n", __func__);
  414. goto err;
  415. }
  416. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  417. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  418. /*
  419. * Register with modem for SSR callback. The APR handle
  420. * is not stored since it is used only to receive notifications
  421. * and not for communication
  422. */
  423. modem_mvm = apr_register("MODEM", "MVM",
  424. qdsp_mvm_callback,
  425. 0xFFFFFFFF, &common);
  426. if (modem_mvm == NULL)
  427. pr_err("%s: Unable to register MVM for MODEM\n",
  428. __func__);
  429. #endif
  430. }
  431. if (common.apr_q6_cvs == NULL) {
  432. pr_debug("%s: Start to register CVS callback\n", __func__);
  433. common.apr_q6_cvs = apr_register("ADSP", "CVS",
  434. qdsp_cvs_callback,
  435. 0xFFFFFFFF, &common);
  436. if (common.apr_q6_cvs == NULL) {
  437. pr_err("%s: Unable to register CVS\n", __func__);
  438. goto err;
  439. }
  440. rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
  441. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  442. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  443. /*
  444. * Register with modem for SSR callback. The APR handle
  445. * is not stored since it is used only to receive notifications
  446. * and not for communication
  447. */
  448. modem_cvs = apr_register("MODEM", "CVS",
  449. qdsp_cvs_callback,
  450. 0xFFFFFFFF, &common);
  451. if (modem_cvs == NULL)
  452. pr_err("%s: Unable to register CVS for MODEM\n",
  453. __func__);
  454. #endif
  455. }
  456. if (common.apr_q6_cvp == NULL) {
  457. pr_debug("%s: Start to register CVP callback\n", __func__);
  458. common.apr_q6_cvp = apr_register("ADSP", "CVP",
  459. qdsp_cvp_callback,
  460. 0xFFFFFFFF, &common);
  461. if (common.apr_q6_cvp == NULL) {
  462. pr_err("%s: Unable to register CVP\n", __func__);
  463. goto err;
  464. }
  465. rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
  466. #if !defined(CONFIG_MACH_MONDRIAN_WIFI) && !defined(CONFIG_SEC_MILLETWIFI_COMMON) && !defined(CONFIG_SEC_MATISSEWIFI_COMMON) \
  467. && !defined(CONFIG_SEC_RUBENSWIFI_COMMON)
  468. /*
  469. * Register with modem for SSR callback. The APR handle
  470. * is not stored since it is used only to receive notifications
  471. * and not for communication
  472. */
  473. modem_cvp = apr_register("MODEM", "CVP",
  474. qdsp_cvp_callback,
  475. 0xFFFFFFFF, &common);
  476. if (modem_cvp == NULL)
  477. pr_err("%s: Unable to register CVP for MODEM\n",
  478. __func__);
  479. #endif
  480. }
  481. mutex_unlock(&common.common_lock);
  482. return 0;
  483. err:
  484. if (common.apr_q6_cvs != NULL) {
  485. apr_deregister(common.apr_q6_cvs);
  486. common.apr_q6_cvs = NULL;
  487. rtac_set_voice_handle(RTAC_CVS, NULL);
  488. }
  489. if (common.apr_q6_mvm != NULL) {
  490. apr_deregister(common.apr_q6_mvm);
  491. common.apr_q6_mvm = NULL;
  492. }
  493. mutex_unlock(&common.common_lock);
  494. return -ENODEV;
  495. }
  496. static int voice_send_dual_control_cmd(struct voice_data *v)
  497. {
  498. int ret = 0;
  499. struct mvm_modem_dual_control_session_cmd mvm_voice_ctl_cmd;
  500. void *apr_mvm;
  501. u16 mvm_handle;
  502. if (v == NULL) {
  503. pr_err("%s: v is NULL\n", __func__);
  504. return -EINVAL;
  505. }
  506. apr_mvm = common.apr_q6_mvm;
  507. if (!apr_mvm) {
  508. pr_err("%s: apr_mvm is NULL.\n", __func__);
  509. return -EINVAL;
  510. }
  511. pr_debug("%s: Send Dual Control command to MVM\n", __func__);
  512. if (!is_voip_session(v->session_id)) {
  513. mvm_handle = voice_get_mvm_handle(v);
  514. mvm_voice_ctl_cmd.hdr.hdr_field = APR_HDR_FIELD(
  515. APR_MSG_TYPE_SEQ_CMD,
  516. APR_HDR_LEN(APR_HDR_SIZE),
  517. APR_PKT_VER);
  518. mvm_voice_ctl_cmd.hdr.pkt_size = APR_PKT_SIZE(
  519. APR_HDR_SIZE,
  520. sizeof(mvm_voice_ctl_cmd) -
  521. APR_HDR_SIZE);
  522. pr_debug("%s: send mvm Voice Ctl pkt size = %d\n",
  523. __func__, mvm_voice_ctl_cmd.hdr.pkt_size);
  524. mvm_voice_ctl_cmd.hdr.src_port =
  525. voice_get_idx_for_session(v->session_id);
  526. mvm_voice_ctl_cmd.hdr.dest_port = mvm_handle;
  527. mvm_voice_ctl_cmd.hdr.token = 0;
  528. mvm_voice_ctl_cmd.hdr.opcode =
  529. VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL;
  530. mvm_voice_ctl_cmd.voice_ctl.enable_flag = true;
  531. v->mvm_state = CMD_STATUS_FAIL;
  532. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_voice_ctl_cmd);
  533. if (ret < 0) {
  534. pr_err("%s: Error sending MVM Voice CTL CMD\n",
  535. __func__);
  536. ret = -EINVAL;
  537. goto fail;
  538. }
  539. ret = wait_event_timeout(v->mvm_wait,
  540. (v->mvm_state == CMD_STATUS_SUCCESS),
  541. msecs_to_jiffies(TIMEOUT_MS));
  542. if (!ret) {
  543. pr_err("%s: wait_event timeout\n", __func__);
  544. ret = -EINVAL;
  545. goto fail;
  546. }
  547. }
  548. ret = 0;
  549. fail:
  550. return ret;
  551. }
  552. static int voice_create_mvm_cvs_session(struct voice_data *v)
  553. {
  554. int ret = 0;
  555. struct mvm_create_ctl_session_cmd mvm_session_cmd;
  556. struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
  557. struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
  558. struct mvm_attach_stream_cmd attach_stream_cmd;
  559. void *apr_mvm, *apr_cvs, *apr_cvp;
  560. u16 mvm_handle, cvs_handle, cvp_handle;
  561. if (v == NULL) {
  562. pr_err("%s: v is NULL\n", __func__);
  563. return -EINVAL;
  564. }
  565. apr_mvm = common.apr_q6_mvm;
  566. apr_cvs = common.apr_q6_cvs;
  567. apr_cvp = common.apr_q6_cvp;
  568. if (!apr_mvm || !apr_cvs || !apr_cvp) {
  569. pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
  570. return -EINVAL;
  571. }
  572. mvm_handle = voice_get_mvm_handle(v);
  573. cvs_handle = voice_get_cvs_handle(v);
  574. cvp_handle = voice_get_cvp_handle(v);
  575. pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
  576. mvm_handle, cvs_handle);
  577. /* send cmd to create mvm session and wait for response */
  578. if (!mvm_handle) {
  579. memset(mvm_session_cmd.mvm_session.name, 0,
  580. sizeof(mvm_session_cmd.mvm_session.name));
  581. if (!is_voip_session(v->session_id)) {
  582. mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  583. APR_MSG_TYPE_SEQ_CMD,
  584. APR_HDR_LEN(APR_HDR_SIZE),
  585. APR_PKT_VER);
  586. mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
  587. APR_HDR_SIZE,
  588. sizeof(mvm_session_cmd) -
  589. APR_HDR_SIZE);
  590. pr_debug("%s: send mvm create session pkt size = %d\n",
  591. __func__, mvm_session_cmd.hdr.pkt_size);
  592. mvm_session_cmd.hdr.src_port =
  593. voice_get_idx_for_session(v->session_id);
  594. mvm_session_cmd.hdr.dest_port = 0;
  595. mvm_session_cmd.hdr.token = 0;
  596. mvm_session_cmd.hdr.opcode =
  597. VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  598. if (is_volte_session(v->session_id)) {
  599. strlcpy(mvm_session_cmd.mvm_session.name,
  600. "default volte voice",
  601. strlen("default volte voice")+1);
  602. } else if (is_voice2_session(v->session_id)) {
  603. if(In_roaming == true) { //MSM 2nd call
  604. strlcpy(mvm_session_cmd.mvm_session.name,
  605. VOICE2_SESSION_VSID_STR,
  606. sizeof(mvm_session_cmd.mvm_session.name));
  607. }
  608. else { //QSC call
  609. strlcpy(mvm_session_cmd.mvm_session.name,
  610. #ifdef CONFIG_DSDA_VIA_UART
  611. "default modem voice2",
  612. #else
  613. VOICE2_SESSION_VSID_STR,
  614. #endif /* CONFIG_DSDA_VIA_UART */
  615. strlen(VOICE2_SESSION_VSID_STR)+1);
  616. }
  617. } else if (is_qchat_session(v->session_id)) {
  618. strlcpy(mvm_session_cmd.mvm_session.name,
  619. QCHAT_SESSION_VSID_STR,
  620. strlen(QCHAT_SESSION_VSID_STR)+1);
  621. } else if (is_vowlan_session(v->session_id)) {
  622. strlcpy(mvm_session_cmd.mvm_session.name,
  623. VOWLAN_SESSION_VSID_STR,
  624. strlen(VOWLAN_SESSION_VSID_STR)+1);
  625. } else {
  626. strlcpy(mvm_session_cmd.mvm_session.name,
  627. "default modem voice",
  628. strlen("default modem voice")+1);
  629. }
  630. v->mvm_state = CMD_STATUS_FAIL;
  631. ret = apr_send_pkt(apr_mvm,
  632. (uint32_t *) &mvm_session_cmd);
  633. if (ret < 0) {
  634. pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
  635. __func__);
  636. goto fail;
  637. }
  638. ret = wait_event_timeout(v->mvm_wait,
  639. (v->mvm_state == CMD_STATUS_SUCCESS),
  640. msecs_to_jiffies(TIMEOUT_MS));
  641. if (!ret) {
  642. pr_err("%s: wait_event timeout\n", __func__);
  643. goto fail;
  644. }
  645. } else {
  646. pr_debug("%s: creating MVM full ctrl\n", __func__);
  647. mvm_session_cmd.hdr.hdr_field =
  648. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  649. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  650. mvm_session_cmd.hdr.pkt_size =
  651. APR_PKT_SIZE(APR_HDR_SIZE,
  652. sizeof(mvm_session_cmd) -
  653. APR_HDR_SIZE);
  654. mvm_session_cmd.hdr.src_port =
  655. voice_get_idx_for_session(v->session_id);
  656. mvm_session_cmd.hdr.dest_port = 0;
  657. mvm_session_cmd.hdr.token = 0;
  658. mvm_session_cmd.hdr.opcode =
  659. VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
  660. strlcpy(mvm_session_cmd.mvm_session.name,
  661. "default voip",
  662. strlen("default voip")+1);
  663. v->mvm_state = CMD_STATUS_FAIL;
  664. ret = apr_send_pkt(apr_mvm,
  665. (uint32_t *) &mvm_session_cmd);
  666. if (ret < 0) {
  667. pr_err("Fail in sending MVM_CONTROL_SESSION\n");
  668. goto fail;
  669. }
  670. ret = wait_event_timeout(v->mvm_wait,
  671. (v->mvm_state == CMD_STATUS_SUCCESS),
  672. msecs_to_jiffies(TIMEOUT_MS));
  673. if (!ret) {
  674. pr_err("%s: wait_event timeout\n", __func__);
  675. goto fail;
  676. }
  677. }
  678. /* Get the created MVM handle. */
  679. mvm_handle = voice_get_mvm_handle(v);
  680. }
  681. /* send cmd to create cvs session */
  682. if (!cvs_handle) {
  683. memset(cvs_session_cmd.cvs_session.name, 0,
  684. sizeof(cvs_session_cmd.cvs_session.name));
  685. if (!is_voip_session(v->session_id)) {
  686. pr_debug("%s: creating CVS passive session\n",
  687. __func__);
  688. cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  689. APR_MSG_TYPE_SEQ_CMD,
  690. APR_HDR_LEN(APR_HDR_SIZE),
  691. APR_PKT_VER);
  692. cvs_session_cmd.hdr.pkt_size =
  693. APR_PKT_SIZE(APR_HDR_SIZE,
  694. sizeof(cvs_session_cmd) -
  695. APR_HDR_SIZE);
  696. cvs_session_cmd.hdr.src_port =
  697. voice_get_idx_for_session(v->session_id);
  698. cvs_session_cmd.hdr.dest_port = 0;
  699. cvs_session_cmd.hdr.token = 0;
  700. cvs_session_cmd.hdr.opcode =
  701. VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  702. if (is_volte_session(v->session_id)) {
  703. strlcpy(cvs_session_cmd.cvs_session.name,
  704. "default volte voice",
  705. strlen("default volte voice")+1);
  706. } else if (is_voice2_session(v->session_id)) {
  707. if(In_roaming == true) { //MSM 2nd call
  708. strlcpy(cvs_session_cmd.cvs_session.name,
  709. VOICE2_SESSION_VSID_STR,
  710. sizeof(cvs_session_cmd.cvs_session.name));
  711. }
  712. else { //QSC call
  713. strlcpy(cvs_session_cmd.cvs_session.name,
  714. #ifdef CONFIG_DSDA_VIA_UART
  715. "default modem voice2",
  716. #else
  717. VOICE2_SESSION_VSID_STR,
  718. #endif /* CONFIG_DSDA_VIA_UART */
  719. strlen(VOICE2_SESSION_VSID_STR)+1);
  720. }
  721. } else if (is_qchat_session(v->session_id)) {
  722. strlcpy(cvs_session_cmd.cvs_session.name,
  723. QCHAT_SESSION_VSID_STR,
  724. strlen(QCHAT_SESSION_VSID_STR)+1);
  725. } else if (is_vowlan_session(v->session_id)) {
  726. strlcpy(cvs_session_cmd.cvs_session.name,
  727. VOWLAN_SESSION_VSID_STR,
  728. strlen(VOWLAN_SESSION_VSID_STR)+1);
  729. } else {
  730. strlcpy(cvs_session_cmd.cvs_session.name,
  731. "default modem voice",
  732. strlen("default modem voice")+1);
  733. }
  734. v->cvs_state = CMD_STATUS_FAIL;
  735. ret = apr_send_pkt(apr_cvs,
  736. (uint32_t *) &cvs_session_cmd);
  737. if (ret < 0) {
  738. pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
  739. goto fail;
  740. }
  741. ret = wait_event_timeout(v->cvs_wait,
  742. (v->cvs_state == CMD_STATUS_SUCCESS),
  743. msecs_to_jiffies(TIMEOUT_MS));
  744. if (!ret) {
  745. pr_err("%s: wait_event timeout\n", __func__);
  746. goto fail;
  747. }
  748. /* Get the created CVS handle. */
  749. cvs_handle = voice_get_cvs_handle(v);
  750. } else {
  751. pr_debug("%s: creating CVS full session\n", __func__);
  752. cvs_full_ctl_cmd.hdr.hdr_field =
  753. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  754. APR_HDR_LEN(APR_HDR_SIZE),
  755. APR_PKT_VER);
  756. cvs_full_ctl_cmd.hdr.pkt_size =
  757. APR_PKT_SIZE(APR_HDR_SIZE,
  758. sizeof(cvs_full_ctl_cmd) -
  759. APR_HDR_SIZE);
  760. cvs_full_ctl_cmd.hdr.src_port =
  761. voice_get_idx_for_session(v->session_id);
  762. cvs_full_ctl_cmd.hdr.dest_port = 0;
  763. cvs_full_ctl_cmd.hdr.token = 0;
  764. cvs_full_ctl_cmd.hdr.opcode =
  765. VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
  766. cvs_full_ctl_cmd.cvs_session.direction = 2;
  767. cvs_full_ctl_cmd.cvs_session.enc_media_type =
  768. common.mvs_info.media_type;
  769. cvs_full_ctl_cmd.cvs_session.dec_media_type =
  770. common.mvs_info.media_type;
  771. cvs_full_ctl_cmd.cvs_session.network_id =
  772. common.mvs_info.network_type;
  773. strlcpy(cvs_full_ctl_cmd.cvs_session.name,
  774. "default q6 voice",
  775. strlen("default q6 voice")+1);
  776. v->cvs_state = CMD_STATUS_FAIL;
  777. ret = apr_send_pkt(apr_cvs,
  778. (uint32_t *) &cvs_full_ctl_cmd);
  779. if (ret < 0) {
  780. pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
  781. __func__, ret);
  782. goto fail;
  783. }
  784. ret = wait_event_timeout(v->cvs_wait,
  785. (v->cvs_state == CMD_STATUS_SUCCESS),
  786. msecs_to_jiffies(TIMEOUT_MS));
  787. if (!ret) {
  788. pr_err("%s: wait_event timeout\n", __func__);
  789. goto fail;
  790. }
  791. /* Get the created CVS handle. */
  792. cvs_handle = voice_get_cvs_handle(v);
  793. /* Attach MVM to CVS. */
  794. pr_debug("%s: Attach MVM to stream\n", __func__);
  795. attach_stream_cmd.hdr.hdr_field =
  796. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  797. APR_HDR_LEN(APR_HDR_SIZE),
  798. APR_PKT_VER);
  799. attach_stream_cmd.hdr.pkt_size =
  800. APR_PKT_SIZE(APR_HDR_SIZE,
  801. sizeof(attach_stream_cmd) -
  802. APR_HDR_SIZE);
  803. attach_stream_cmd.hdr.src_port =
  804. voice_get_idx_for_session(v->session_id);
  805. attach_stream_cmd.hdr.dest_port = mvm_handle;
  806. attach_stream_cmd.hdr.token = 0;
  807. attach_stream_cmd.hdr.opcode =
  808. VSS_IMVM_CMD_ATTACH_STREAM;
  809. attach_stream_cmd.attach_stream.handle = cvs_handle;
  810. v->mvm_state = CMD_STATUS_FAIL;
  811. ret = apr_send_pkt(apr_mvm,
  812. (uint32_t *) &attach_stream_cmd);
  813. if (ret < 0) {
  814. pr_err("%s: Error %d sending ATTACH_STREAM\n",
  815. __func__, ret);
  816. goto fail;
  817. }
  818. ret = wait_event_timeout(v->mvm_wait,
  819. (v->mvm_state == CMD_STATUS_SUCCESS),
  820. msecs_to_jiffies(TIMEOUT_MS));
  821. if (!ret) {
  822. pr_err("%s: wait_event timeout\n", __func__);
  823. goto fail;
  824. }
  825. }
  826. }
  827. return 0;
  828. fail:
  829. return -EINVAL;
  830. }
  831. static int voice_destroy_mvm_cvs_session(struct voice_data *v)
  832. {
  833. int ret = 0;
  834. struct mvm_detach_stream_cmd detach_stream;
  835. struct apr_hdr mvm_destroy;
  836. struct apr_hdr cvs_destroy;
  837. void *apr_mvm, *apr_cvs;
  838. u16 mvm_handle, cvs_handle;
  839. if (v == NULL) {
  840. pr_err("%s: v is NULL\n", __func__);
  841. return -EINVAL;
  842. }
  843. apr_mvm = common.apr_q6_mvm;
  844. apr_cvs = common.apr_q6_cvs;
  845. if (!apr_mvm || !apr_cvs) {
  846. pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
  847. return -EINVAL;
  848. }
  849. mvm_handle = voice_get_mvm_handle(v);
  850. cvs_handle = voice_get_cvs_handle(v);
  851. /* MVM, CVS sessions are destroyed only for Full control sessions. */
  852. if (is_voip_session(v->session_id)) {
  853. pr_debug("%s: MVM detach stream, VOC_STATE: %d\n", __func__,
  854. v->voc_state);
  855. /* Detach voice stream. */
  856. detach_stream.hdr.hdr_field =
  857. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  858. APR_HDR_LEN(APR_HDR_SIZE),
  859. APR_PKT_VER);
  860. detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  861. sizeof(detach_stream) - APR_HDR_SIZE);
  862. detach_stream.hdr.src_port =
  863. voice_get_idx_for_session(v->session_id);
  864. detach_stream.hdr.dest_port = mvm_handle;
  865. detach_stream.hdr.token = 0;
  866. detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
  867. detach_stream.detach_stream.handle = cvs_handle;
  868. v->mvm_state = CMD_STATUS_FAIL;
  869. ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
  870. if (ret < 0) {
  871. pr_err("%s: Error %d sending DETACH_STREAM\n",
  872. __func__, ret);
  873. goto fail;
  874. }
  875. ret = wait_event_timeout(v->mvm_wait,
  876. (v->mvm_state == CMD_STATUS_SUCCESS),
  877. msecs_to_jiffies(TIMEOUT_MS));
  878. if (!ret) {
  879. pr_err("%s: wait event timeout\n", __func__);
  880. goto fail;
  881. }
  882. /* Unmap memory */
  883. if (v->shmem_info.mem_handle != 0) {
  884. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  885. v->shmem_info.mem_handle);
  886. if (ret < 0) {
  887. pr_err("%s Memory_unmap for voip failed %d\n",
  888. __func__, ret);
  889. goto fail;
  890. }
  891. v->shmem_info.mem_handle = 0;
  892. }
  893. }
  894. if (is_voip_session(v->session_id) ||
  895. is_qchat_session(v->session_id) ||
  896. is_volte_session(v->session_id) ||
  897. v->voc_state == VOC_ERROR) {
  898. /* Destroy CVS. */
  899. pr_debug("%s: CVS destroy session\n", __func__);
  900. cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  901. APR_HDR_LEN(APR_HDR_SIZE),
  902. APR_PKT_VER);
  903. cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  904. sizeof(cvs_destroy) - APR_HDR_SIZE);
  905. cvs_destroy.src_port =
  906. voice_get_idx_for_session(v->session_id);
  907. cvs_destroy.dest_port = cvs_handle;
  908. cvs_destroy.token = 0;
  909. cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  910. v->cvs_state = CMD_STATUS_FAIL;
  911. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
  912. if (ret < 0) {
  913. pr_err("%s: Error %d sending CVS DESTROY\n",
  914. __func__, ret);
  915. goto fail;
  916. }
  917. ret = wait_event_timeout(v->cvs_wait,
  918. (v->cvs_state == CMD_STATUS_SUCCESS),
  919. msecs_to_jiffies(TIMEOUT_MS));
  920. if (!ret) {
  921. pr_err("%s: wait event timeout\n", __func__);
  922. goto fail;
  923. }
  924. cvs_handle = 0;
  925. voice_set_cvs_handle(v, cvs_handle);
  926. /* Unmap physical memory for calibration */
  927. pr_debug("%s: cal_mem_handle %d\n", __func__,
  928. common.cal_mem_handle);
  929. if (!is_other_session_active(v->session_id) &&
  930. (common.cal_mem_handle != 0)) {
  931. ret = voice_send_mvm_unmap_memory_physical_cmd(v,
  932. common.cal_mem_handle);
  933. if (ret < 0) {
  934. pr_err("%s Fail at cal mem unmap %d\n",
  935. __func__, ret);
  936. goto fail;
  937. }
  938. common.cal_mem_handle = 0;
  939. }
  940. /* Destroy MVM. */
  941. pr_debug("MVM destroy session\n");
  942. mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  943. APR_HDR_LEN(APR_HDR_SIZE),
  944. APR_PKT_VER);
  945. mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  946. sizeof(mvm_destroy) - APR_HDR_SIZE);
  947. mvm_destroy.src_port =
  948. voice_get_idx_for_session(v->session_id);
  949. mvm_destroy.dest_port = mvm_handle;
  950. mvm_destroy.token = 0;
  951. mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  952. v->mvm_state = CMD_STATUS_FAIL;
  953. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
  954. if (ret < 0) {
  955. pr_err("%s: Error %d sending MVM DESTROY\n",
  956. __func__, ret);
  957. goto fail;
  958. }
  959. ret = wait_event_timeout(v->mvm_wait,
  960. (v->mvm_state == CMD_STATUS_SUCCESS),
  961. msecs_to_jiffies(TIMEOUT_MS));
  962. if (!ret) {
  963. pr_err("%s: wait event timeout\n", __func__);
  964. goto fail;
  965. }
  966. mvm_handle = 0;
  967. voice_set_mvm_handle(v, mvm_handle);
  968. }
  969. return 0;
  970. fail:
  971. return -EINVAL;
  972. }
  973. static int voice_send_tty_mode_cmd(struct voice_data *v)
  974. {
  975. int ret = 0;
  976. struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
  977. void *apr_mvm;
  978. u16 mvm_handle;
  979. if (v == NULL) {
  980. pr_err("%s: v is NULL\n", __func__);
  981. return -EINVAL;
  982. }
  983. apr_mvm = common.apr_q6_mvm;
  984. if (!apr_mvm) {
  985. pr_err("%s: apr_mvm is NULL.\n", __func__);
  986. return -EINVAL;
  987. }
  988. mvm_handle = voice_get_mvm_handle(v);
  989. /* send tty mode cmd to mvm */
  990. mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
  991. APR_MSG_TYPE_SEQ_CMD,
  992. APR_HDR_LEN(APR_HDR_SIZE),
  993. APR_PKT_VER);
  994. mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  995. sizeof(mvm_tty_mode_cmd) -
  996. APR_HDR_SIZE);
  997. pr_debug("%s: pkt size = %d\n",
  998. __func__, mvm_tty_mode_cmd.hdr.pkt_size);
  999. mvm_tty_mode_cmd.hdr.src_port =
  1000. voice_get_idx_for_session(v->session_id);
  1001. mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
  1002. mvm_tty_mode_cmd.hdr.token = 0;
  1003. mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
  1004. mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
  1005. pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
  1006. v->mvm_state = CMD_STATUS_FAIL;
  1007. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
  1008. if (ret < 0) {
  1009. pr_err("%s: Error %d sending SET_TTY_MODE\n",
  1010. __func__, ret);
  1011. goto fail;
  1012. }
  1013. ret = wait_event_timeout(v->mvm_wait,
  1014. (v->mvm_state == CMD_STATUS_SUCCESS),
  1015. msecs_to_jiffies(TIMEOUT_MS));
  1016. if (!ret) {
  1017. pr_err("%s: wait_event timeout\n", __func__);
  1018. goto fail;
  1019. }
  1020. return 0;
  1021. fail:
  1022. return -EINVAL;
  1023. }
  1024. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  1025. uint32_t module_id, int enable)
  1026. {
  1027. struct cvs_set_pp_enable_cmd cvs_set_pp_cmd;
  1028. int ret = 0;
  1029. void *apr_cvs;
  1030. u16 cvs_handle;
  1031. if (v == NULL) {
  1032. pr_err("%s: v is NULL\n", __func__);
  1033. return -EINVAL;
  1034. }
  1035. apr_cvs = common.apr_q6_cvs;
  1036. if (!apr_cvs) {
  1037. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1038. return -EINVAL;
  1039. }
  1040. cvs_handle = voice_get_cvs_handle(v);
  1041. cvs_set_pp_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1042. APR_HDR_LEN(APR_HDR_SIZE),
  1043. APR_PKT_VER);
  1044. cvs_set_pp_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1045. sizeof(cvs_set_pp_cmd) -
  1046. APR_HDR_SIZE);
  1047. cvs_set_pp_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  1048. cvs_set_pp_cmd.hdr.dest_port = cvs_handle;
  1049. cvs_set_pp_cmd.hdr.token = 0;
  1050. cvs_set_pp_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  1051. cvs_set_pp_cmd.vss_set_pp.module_id = module_id;
  1052. cvs_set_pp_cmd.vss_set_pp.param_id = VOICE_PARAM_MOD_ENABLE;
  1053. cvs_set_pp_cmd.vss_set_pp.param_size = MOD_ENABLE_PARAM_LEN;
  1054. cvs_set_pp_cmd.vss_set_pp.reserved = 0;
  1055. cvs_set_pp_cmd.vss_set_pp.enable = enable;
  1056. cvs_set_pp_cmd.vss_set_pp.reserved_field = 0;
  1057. pr_debug("voice_send_set_pp_enable_cmd, module_id=%d, enable=%d\n",
  1058. module_id, enable);
  1059. v->cvs_state = CMD_STATUS_FAIL;
  1060. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_pp_cmd);
  1061. if (ret < 0) {
  1062. pr_err("Fail: sending cvs set pp enable,\n");
  1063. goto fail;
  1064. }
  1065. ret = wait_event_timeout(v->cvs_wait,
  1066. (v->cvs_state == CMD_STATUS_SUCCESS),
  1067. msecs_to_jiffies(TIMEOUT_MS));
  1068. if (!ret) {
  1069. pr_err("%s: wait_event timeout\n", __func__);
  1070. goto fail;
  1071. }
  1072. return 0;
  1073. fail:
  1074. return -EINVAL;
  1075. }
  1076. static int voice_set_dtx(struct voice_data *v)
  1077. {
  1078. int ret = 0;
  1079. void *apr_cvs;
  1080. u16 cvs_handle;
  1081. struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
  1082. if (v == NULL) {
  1083. pr_err("%s: v is NULL\n", __func__);
  1084. return -EINVAL;
  1085. }
  1086. apr_cvs = common.apr_q6_cvs;
  1087. if (!apr_cvs) {
  1088. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1089. return -EINVAL;
  1090. }
  1091. cvs_handle = voice_get_cvs_handle(v);
  1092. /* Set DTX */
  1093. cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1094. APR_HDR_LEN(APR_HDR_SIZE),
  1095. APR_PKT_VER);
  1096. cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1097. sizeof(cvs_set_dtx) - APR_HDR_SIZE);
  1098. cvs_set_dtx.hdr.src_port =
  1099. voice_get_idx_for_session(v->session_id);
  1100. cvs_set_dtx.hdr.dest_port = cvs_handle;
  1101. cvs_set_dtx.hdr.token = 0;
  1102. cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
  1103. cvs_set_dtx.dtx_mode.enable = common.mvs_info.dtx_mode;
  1104. pr_debug("%s: Setting DTX %d\n", __func__, common.mvs_info.dtx_mode);
  1105. v->cvs_state = CMD_STATUS_FAIL;
  1106. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
  1107. if (ret < 0) {
  1108. pr_err("%s: Error %d sending SET_DTX\n", __func__, ret);
  1109. return -EINVAL;
  1110. }
  1111. ret = wait_event_timeout(v->cvs_wait,
  1112. (v->cvs_state == CMD_STATUS_SUCCESS),
  1113. msecs_to_jiffies(TIMEOUT_MS));
  1114. if (!ret) {
  1115. pr_err("%s: wait_event timeout\n", __func__);
  1116. return -EINVAL;
  1117. }
  1118. return 0;
  1119. }
  1120. static int voice_send_mvm_media_type_cmd(struct voice_data *v)
  1121. {
  1122. struct vss_imvm_cmd_set_cal_media_type_t mvm_set_cal_media_type;
  1123. int ret = 0;
  1124. void *apr_mvm;
  1125. u16 mvm_handle;
  1126. if (v == NULL) {
  1127. pr_err("%s: v is NULL\n", __func__);
  1128. return -EINVAL;
  1129. }
  1130. apr_mvm = common.apr_q6_mvm;
  1131. if (!apr_mvm) {
  1132. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1133. return -EINVAL;
  1134. }
  1135. mvm_handle = voice_get_mvm_handle(v);
  1136. mvm_set_cal_media_type.hdr.hdr_field =
  1137. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1138. APR_HDR_LEN(APR_HDR_SIZE),
  1139. APR_PKT_VER);
  1140. mvm_set_cal_media_type.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1141. sizeof(mvm_set_cal_media_type) -
  1142. APR_HDR_SIZE);
  1143. mvm_set_cal_media_type.hdr.src_port =
  1144. voice_get_idx_for_session(v->session_id);
  1145. mvm_set_cal_media_type.hdr.dest_port = mvm_handle;
  1146. mvm_set_cal_media_type.hdr.token = 0;
  1147. mvm_set_cal_media_type.hdr.opcode = VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE;
  1148. mvm_set_cal_media_type.media_id = common.mvs_info.media_type;
  1149. pr_debug("%s: setting media_id as %x\n",
  1150. __func__ , mvm_set_cal_media_type.media_id);
  1151. v->mvm_state = CMD_STATUS_FAIL;
  1152. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_media_type);
  1153. if (ret < 0) {
  1154. pr_err("%s: Error %d sending media type\n", __func__, ret);
  1155. goto fail;
  1156. }
  1157. ret = wait_event_timeout(v->mvm_wait,
  1158. (v->mvm_state == CMD_STATUS_SUCCESS),
  1159. msecs_to_jiffies(TIMEOUT_MS));
  1160. if (!ret) {
  1161. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  1162. goto fail;
  1163. }
  1164. return 0;
  1165. fail:
  1166. return -EINVAL;
  1167. }
  1168. static int voice_send_dtmf_rx_detection_cmd(struct voice_data *v,
  1169. uint32_t enable)
  1170. {
  1171. int ret = 0;
  1172. void *apr_cvs;
  1173. u16 cvs_handle;
  1174. struct cvs_set_rx_dtmf_detection_cmd cvs_dtmf_rx_detection;
  1175. if (v == NULL) {
  1176. pr_err("%s: v is NULL\n", __func__);
  1177. return -EINVAL;
  1178. }
  1179. apr_cvs = common.apr_q6_cvs;
  1180. if (!apr_cvs) {
  1181. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1182. return -EINVAL;
  1183. }
  1184. cvs_handle = voice_get_cvs_handle(v);
  1185. /* Set SET_DTMF_RX_DETECTION */
  1186. cvs_dtmf_rx_detection.hdr.hdr_field =
  1187. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1188. APR_HDR_LEN(APR_HDR_SIZE),
  1189. APR_PKT_VER);
  1190. cvs_dtmf_rx_detection.hdr.pkt_size =
  1191. APR_PKT_SIZE(APR_HDR_SIZE,
  1192. sizeof(cvs_dtmf_rx_detection) - APR_HDR_SIZE);
  1193. cvs_dtmf_rx_detection.hdr.src_port =
  1194. voice_get_idx_for_session(v->session_id);
  1195. cvs_dtmf_rx_detection.hdr.dest_port = cvs_handle;
  1196. cvs_dtmf_rx_detection.hdr.token = 0;
  1197. cvs_dtmf_rx_detection.hdr.opcode =
  1198. VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION;
  1199. cvs_dtmf_rx_detection.cvs_dtmf_det.enable = enable;
  1200. v->cvs_state = CMD_STATUS_FAIL;
  1201. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dtmf_rx_detection);
  1202. if (ret < 0) {
  1203. pr_err("%s: Error %d sending SET_DTMF_RX_DETECTION\n",
  1204. __func__,
  1205. ret);
  1206. return -EINVAL;
  1207. }
  1208. ret = wait_event_timeout(v->cvs_wait,
  1209. (v->cvs_state == CMD_STATUS_SUCCESS),
  1210. msecs_to_jiffies(TIMEOUT_MS));
  1211. if (!ret) {
  1212. pr_err("%s: wait_event timeout\n", __func__);
  1213. return -EINVAL;
  1214. }
  1215. return ret;
  1216. }
  1217. void voc_disable_dtmf_det_on_active_sessions(void)
  1218. {
  1219. struct voice_data *v = NULL;
  1220. int i;
  1221. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  1222. v = &common.voice[i];
  1223. if ((v->dtmf_rx_detect_en) &&
  1224. is_voc_state_active(v->voc_state)) {
  1225. pr_debug("disable dtmf det on ses_id=%d\n",
  1226. v->session_id);
  1227. voice_send_dtmf_rx_detection_cmd(v, 0);
  1228. }
  1229. }
  1230. }
  1231. int voc_enable_dtmf_rx_detection(uint32_t session_id, uint32_t enable)
  1232. {
  1233. struct voice_data *v = voice_get_session(session_id);
  1234. int ret = 0;
  1235. if (v == NULL) {
  1236. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  1237. return -EINVAL;
  1238. }
  1239. mutex_lock(&v->lock);
  1240. v->dtmf_rx_detect_en = enable;
  1241. if (is_voc_state_active(v->voc_state))
  1242. ret = voice_send_dtmf_rx_detection_cmd(v,
  1243. v->dtmf_rx_detect_en);
  1244. mutex_unlock(&v->lock);
  1245. return ret;
  1246. }
  1247. int voc_alloc_cal_shared_memory(void)
  1248. {
  1249. int rc = 0;
  1250. mutex_lock(&common.common_lock);
  1251. if (is_cal_memory_allocated()) {
  1252. pr_debug("%s: Calibration shared buffer already allocated",
  1253. __func__);
  1254. } else {
  1255. /* Allocate memory for calibration memory map table. */
  1256. rc = voice_alloc_cal_mem_map_table();
  1257. if (rc < 0) {
  1258. pr_err("%s: Failed to allocate cal memory, err=%d",
  1259. __func__, rc);
  1260. }
  1261. }
  1262. mutex_unlock(&common.common_lock);
  1263. return rc;
  1264. }
  1265. int voc_alloc_voip_shared_memory(void)
  1266. {
  1267. int rc = 0;
  1268. /* Allocate shared memory for OOB Voip */
  1269. rc = voice_alloc_oob_shared_mem();
  1270. if (rc < 0) {
  1271. pr_err("%s: Failed to alloc shared memory for OOB rc:%d\n",
  1272. __func__, rc);
  1273. } else {
  1274. /* Allocate mem map table for OOB */
  1275. rc = voice_alloc_oob_mem_table();
  1276. if (rc < 0) {
  1277. pr_err("%s: Failed to alloc mem map talbe rc:%d\n",
  1278. __func__, rc);
  1279. voice_free_oob_shared_mem();
  1280. }
  1281. }
  1282. return rc;
  1283. }
  1284. static int is_cal_memory_allocated(void)
  1285. {
  1286. bool ret;
  1287. if (common.cal_mem_map_table.client != NULL &&
  1288. common.cal_mem_map_table.handle != NULL)
  1289. ret = true;
  1290. else
  1291. ret = false;
  1292. return ret;
  1293. }
  1294. static int free_cal_map_table(void)
  1295. {
  1296. int ret = 0;
  1297. if ((common.cal_mem_map_table.client == NULL) ||
  1298. (common.cal_mem_map_table.handle == NULL))
  1299. goto done;
  1300. ret = msm_audio_ion_free(common.cal_mem_map_table.client,
  1301. common.cal_mem_map_table.handle);
  1302. if (ret < 0) {
  1303. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1304. ret = -EPERM;
  1305. }
  1306. done:
  1307. common.cal_mem_map_table.client = NULL;
  1308. common.cal_mem_map_table.handle = NULL;
  1309. return ret;
  1310. }
  1311. static int is_rtac_memory_allocated(void)
  1312. {
  1313. bool ret;
  1314. if (common.rtac_mem_map_table.client != NULL &&
  1315. common.rtac_mem_map_table.handle != NULL)
  1316. ret = true;
  1317. else
  1318. ret = false;
  1319. return ret;
  1320. }
  1321. static int free_rtac_map_table(void)
  1322. {
  1323. int ret = 0;
  1324. if ((common.rtac_mem_map_table.client == NULL) ||
  1325. (common.rtac_mem_map_table.handle == NULL))
  1326. goto done;
  1327. ret = msm_audio_ion_free(common.rtac_mem_map_table.client,
  1328. common.rtac_mem_map_table.handle);
  1329. if (ret < 0) {
  1330. pr_err("%s: msm_audio_ion_free failed:\n", __func__);
  1331. ret = -EPERM;
  1332. }
  1333. done:
  1334. common.rtac_mem_map_table.client = NULL;
  1335. common.rtac_mem_map_table.handle = NULL;
  1336. return ret;
  1337. }
  1338. static int is_voip_memory_allocated(void)
  1339. {
  1340. bool ret;
  1341. struct voice_data *v = voice_get_session(
  1342. common.voice[VOC_PATH_FULL].session_id);
  1343. if (v == NULL) {
  1344. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1345. common.voice[VOC_PATH_FULL].session_id);
  1346. ret = false;
  1347. goto done;
  1348. }
  1349. mutex_lock(&common.common_lock);
  1350. if (v->shmem_info.sh_buf.client != NULL &&
  1351. v->shmem_info.sh_buf.handle != NULL)
  1352. ret = true;
  1353. else
  1354. ret = false;
  1355. mutex_unlock(&common.common_lock);
  1356. done:
  1357. return ret;
  1358. }
  1359. static int voice_config_cvs_vocoder_amr_rate(struct voice_data *v)
  1360. {
  1361. int ret = 0;
  1362. void *apr_cvs;
  1363. u16 cvs_handle;
  1364. struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
  1365. if (v == NULL) {
  1366. pr_err("%s: v is NULL\n", __func__);
  1367. ret = -EINVAL;
  1368. goto done;
  1369. }
  1370. apr_cvs = common.apr_q6_cvs;
  1371. if (!apr_cvs) {
  1372. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1373. ret = -EINVAL;
  1374. goto done;
  1375. }
  1376. cvs_handle = voice_get_cvs_handle(v);
  1377. pr_debug("%s: Setting AMR rate. Media Type: %d\n", __func__,
  1378. common.mvs_info.media_type);
  1379. cvs_set_amr_rate.hdr.hdr_field =
  1380. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1381. APR_HDR_LEN(APR_HDR_SIZE),
  1382. APR_PKT_VER);
  1383. cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1384. sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
  1385. cvs_set_amr_rate.hdr.src_port =
  1386. voice_get_idx_for_session(v->session_id);
  1387. cvs_set_amr_rate.hdr.dest_port = cvs_handle;
  1388. cvs_set_amr_rate.hdr.token = 0;
  1389. if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_NB_MODEM)
  1390. cvs_set_amr_rate.hdr.opcode =
  1391. VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
  1392. else if (common.mvs_info.media_type == VSS_MEDIA_ID_AMR_WB_MODEM)
  1393. cvs_set_amr_rate.hdr.opcode =
  1394. VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
  1395. cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
  1396. v->cvs_state = CMD_STATUS_FAIL;
  1397. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
  1398. if (ret < 0) {
  1399. pr_err("%s: Error %d sending SET_AMR_RATE\n",
  1400. __func__, ret);
  1401. goto done;
  1402. }
  1403. ret = wait_event_timeout(v->cvs_wait,
  1404. (v->cvs_state == CMD_STATUS_SUCCESS),
  1405. msecs_to_jiffies(TIMEOUT_MS));
  1406. if (!ret) {
  1407. pr_err("%s: wait_event timeout\n", __func__);
  1408. ret = -EINVAL;
  1409. goto done;
  1410. }
  1411. return 0;
  1412. done:
  1413. return ret;
  1414. }
  1415. static int voice_config_cvs_vocoder(struct voice_data *v)
  1416. {
  1417. int ret = 0;
  1418. void *apr_cvs;
  1419. u16 cvs_handle;
  1420. /* Set media type. */
  1421. struct cvs_set_media_type_cmd cvs_set_media_cmd;
  1422. if (v == NULL) {
  1423. pr_err("%s: v is NULL\n", __func__);
  1424. return -EINVAL;
  1425. }
  1426. apr_cvs = common.apr_q6_cvs;
  1427. if (!apr_cvs) {
  1428. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1429. return -EINVAL;
  1430. }
  1431. cvs_handle = voice_get_cvs_handle(v);
  1432. cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1433. APR_HDR_LEN(APR_HDR_SIZE),
  1434. APR_PKT_VER);
  1435. cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1436. sizeof(cvs_set_media_cmd) -
  1437. APR_HDR_SIZE);
  1438. cvs_set_media_cmd.hdr.src_port =
  1439. voice_get_idx_for_session(v->session_id);
  1440. cvs_set_media_cmd.hdr.dest_port = cvs_handle;
  1441. cvs_set_media_cmd.hdr.token = 0;
  1442. cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
  1443. cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
  1444. cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
  1445. v->cvs_state = CMD_STATUS_FAIL;
  1446. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
  1447. if (ret < 0) {
  1448. pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
  1449. __func__, ret);
  1450. goto fail;
  1451. }
  1452. ret = wait_event_timeout(v->cvs_wait,
  1453. (v->cvs_state == CMD_STATUS_SUCCESS),
  1454. msecs_to_jiffies(TIMEOUT_MS));
  1455. if (!ret) {
  1456. pr_err("%s: wait_event timeout\n", __func__);
  1457. goto fail;
  1458. }
  1459. /* Set encoder properties. */
  1460. switch (common.mvs_info.media_type) {
  1461. case VSS_MEDIA_ID_EVRC_MODEM:
  1462. case VSS_MEDIA_ID_4GV_NB_MODEM:
  1463. case VSS_MEDIA_ID_4GV_WB_MODEM:
  1464. case VSS_MEDIA_ID_4GV_NW_MODEM: {
  1465. struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
  1466. pr_debug("Setting EVRC min-max rate\n");
  1467. cvs_set_cdma_rate.hdr.hdr_field =
  1468. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1469. APR_HDR_LEN(APR_HDR_SIZE),
  1470. APR_PKT_VER);
  1471. cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1472. sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
  1473. cvs_set_cdma_rate.hdr.src_port =
  1474. voice_get_idx_for_session(v->session_id);
  1475. cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
  1476. cvs_set_cdma_rate.hdr.token = 0;
  1477. cvs_set_cdma_rate.hdr.opcode =
  1478. VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
  1479. cvs_set_cdma_rate.cdma_rate.min_rate =
  1480. common.mvs_info.evrc_min_rate;
  1481. cvs_set_cdma_rate.cdma_rate.max_rate =
  1482. common.mvs_info.evrc_max_rate;
  1483. v->cvs_state = CMD_STATUS_FAIL;
  1484. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
  1485. if (ret < 0) {
  1486. pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
  1487. __func__, ret);
  1488. goto fail;
  1489. }
  1490. ret = wait_event_timeout(v->cvs_wait,
  1491. (v->cvs_state == CMD_STATUS_SUCCESS),
  1492. msecs_to_jiffies(TIMEOUT_MS));
  1493. if (!ret) {
  1494. pr_err("%s: wait_event timeout\n", __func__);
  1495. goto fail;
  1496. }
  1497. if (common.mvs_info.media_type != VSS_MEDIA_ID_EVRC_MODEM) {
  1498. ret = voice_set_dtx(v);
  1499. if (ret < 0)
  1500. goto fail;
  1501. }
  1502. break;
  1503. }
  1504. case VSS_MEDIA_ID_AMR_NB_MODEM:
  1505. case VSS_MEDIA_ID_AMR_WB_MODEM: {
  1506. ret = voice_config_cvs_vocoder_amr_rate(v);
  1507. if (ret) {
  1508. pr_err("%s: Failed to update vocoder rate. %d\n",
  1509. __func__, ret);
  1510. goto fail;
  1511. }
  1512. ret = voice_set_dtx(v);
  1513. if (ret < 0)
  1514. goto fail;
  1515. break;
  1516. }
  1517. case VSS_MEDIA_ID_G729:
  1518. case VSS_MEDIA_ID_G711_ALAW:
  1519. case VSS_MEDIA_ID_G711_MULAW: {
  1520. ret = voice_set_dtx(v);
  1521. break;
  1522. }
  1523. default:
  1524. /* Do nothing. */
  1525. break;
  1526. }
  1527. return 0;
  1528. fail:
  1529. return -EINVAL;
  1530. }
  1531. int voc_update_amr_vocoder_rate(uint32_t session_id)
  1532. {
  1533. int ret = 0;
  1534. struct voice_data *v;
  1535. pr_debug("%s: session_id:%d", __func__, session_id);
  1536. v = voice_get_session(session_id);
  1537. if (v == NULL) {
  1538. pr_err("%s: v is NULL, session_id:%d\n", __func__,
  1539. session_id);
  1540. ret = -EINVAL;
  1541. goto done;
  1542. }
  1543. mutex_lock(&v->lock);
  1544. ret = voice_config_cvs_vocoder_amr_rate(v);
  1545. mutex_unlock(&v->lock);
  1546. done:
  1547. return ret;
  1548. }
  1549. static int voice_send_start_voice_cmd(struct voice_data *v)
  1550. {
  1551. struct apr_hdr mvm_start_voice_cmd;
  1552. int ret = 0;
  1553. void *apr_mvm;
  1554. u16 mvm_handle;
  1555. if (v == NULL) {
  1556. pr_err("%s: v is NULL\n", __func__);
  1557. return -EINVAL;
  1558. }
  1559. apr_mvm = common.apr_q6_mvm;
  1560. if (!apr_mvm) {
  1561. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1562. return -EINVAL;
  1563. }
  1564. mvm_handle = voice_get_mvm_handle(v);
  1565. mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1566. APR_HDR_LEN(APR_HDR_SIZE),
  1567. APR_PKT_VER);
  1568. mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1569. sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
  1570. pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
  1571. mvm_start_voice_cmd.pkt_size);
  1572. mvm_start_voice_cmd.src_port =
  1573. voice_get_idx_for_session(v->session_id);
  1574. mvm_start_voice_cmd.dest_port = mvm_handle;
  1575. mvm_start_voice_cmd.token = 0;
  1576. mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
  1577. v->mvm_state = CMD_STATUS_FAIL;
  1578. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
  1579. if (ret < 0) {
  1580. pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
  1581. goto fail;
  1582. }
  1583. ret = wait_event_timeout(v->mvm_wait,
  1584. (v->mvm_state == CMD_STATUS_SUCCESS),
  1585. msecs_to_jiffies(TIMEOUT_MS));
  1586. if (!ret) {
  1587. pr_err("%s: wait_event timeout\n", __func__);
  1588. goto fail;
  1589. }
  1590. return 0;
  1591. fail:
  1592. return -EINVAL;
  1593. }
  1594. static int voice_send_disable_vocproc_cmd(struct voice_data *v)
  1595. {
  1596. struct apr_hdr cvp_disable_cmd;
  1597. int ret = 0;
  1598. void *apr_cvp;
  1599. u16 cvp_handle;
  1600. if (v == NULL) {
  1601. pr_err("%s: v is NULL\n", __func__);
  1602. return -EINVAL;
  1603. }
  1604. apr_cvp = common.apr_q6_cvp;
  1605. if (!apr_cvp) {
  1606. pr_err("%s: apr regist failed\n", __func__);
  1607. return -EINVAL;
  1608. }
  1609. cvp_handle = voice_get_cvp_handle(v);
  1610. /* disable vocproc and wait for respose */
  1611. cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1612. APR_HDR_LEN(APR_HDR_SIZE),
  1613. APR_PKT_VER);
  1614. cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1615. sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
  1616. pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
  1617. cvp_disable_cmd.pkt_size, cvp_handle);
  1618. cvp_disable_cmd.src_port =
  1619. voice_get_idx_for_session(v->session_id);
  1620. cvp_disable_cmd.dest_port = cvp_handle;
  1621. cvp_disable_cmd.token = 0;
  1622. cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
  1623. v->cvp_state = CMD_STATUS_FAIL;
  1624. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
  1625. if (ret < 0) {
  1626. pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
  1627. goto fail;
  1628. }
  1629. ret = wait_event_timeout(v->cvp_wait,
  1630. (v->cvp_state == CMD_STATUS_SUCCESS),
  1631. msecs_to_jiffies(TIMEOUT_MS));
  1632. if (!ret) {
  1633. pr_err("%s: wait_event timeout\n", __func__);
  1634. goto fail;
  1635. }
  1636. return 0;
  1637. fail:
  1638. return -EINVAL;
  1639. }
  1640. static void voc_get_tx_rx_topology(struct voice_data *v,
  1641. uint32_t *tx_topology_id,
  1642. uint32_t *rx_topology_id)
  1643. {
  1644. uint32_t tx_id = 0;
  1645. uint32_t rx_id = 0;
  1646. if (v->lch_mode == VOICE_LCH_START) {
  1647. pr_debug("%s: Setting TX and RX topology to NONE for LCH\n",
  1648. __func__);
  1649. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1650. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1651. } else {
  1652. /* Use default topology if invalid value in ACDB */
  1653. tx_id = get_voice_tx_topology();
  1654. if (tx_id == 0)
  1655. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
  1656. rx_id = get_voice_rx_topology();
  1657. if (rx_id == 0)
  1658. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  1659. }
  1660. *tx_topology_id = tx_id;
  1661. *rx_topology_id = rx_id;
  1662. }
  1663. static int voice_send_set_device_cmd(struct voice_data *v)
  1664. {
  1665. struct cvp_set_device_cmd cvp_setdev_cmd;
  1666. int ret = 0;
  1667. void *apr_cvp;
  1668. u16 cvp_handle;
  1669. if (v == NULL) {
  1670. pr_err("%s: v is NULL\n", __func__);
  1671. return -EINVAL;
  1672. }
  1673. apr_cvp = common.apr_q6_cvp;
  1674. if (!apr_cvp) {
  1675. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1676. return -EINVAL;
  1677. }
  1678. cvp_handle = voice_get_cvp_handle(v);
  1679. /* set device and wait for response */
  1680. cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1681. APR_HDR_LEN(APR_HDR_SIZE),
  1682. APR_PKT_VER);
  1683. cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1684. sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
  1685. pr_debug(" send create cvp setdev, pkt size = %d\n",
  1686. cvp_setdev_cmd.hdr.pkt_size);
  1687. cvp_setdev_cmd.hdr.src_port =
  1688. voice_get_idx_for_session(v->session_id);
  1689. cvp_setdev_cmd.hdr.dest_port = cvp_handle;
  1690. cvp_setdev_cmd.hdr.token = 0;
  1691. cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE_V2;
  1692. voc_get_tx_rx_topology(v,
  1693. &cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  1694. &cvp_setdev_cmd.cvp_set_device_v2.rx_topology_id);
  1695. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id = v->dev_tx.port_id;
  1696. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id = v->dev_rx.port_id;
  1697. if (common.ec_ref_ext) {
  1698. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  1699. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  1700. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  1701. common.ec_port_id;
  1702. } else {
  1703. cvp_setdev_cmd.cvp_set_device_v2.vocproc_mode =
  1704. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  1705. cvp_setdev_cmd.cvp_set_device_v2.ec_ref_port_id =
  1706. VSS_IVOCPROC_PORT_ID_NONE;
  1707. }
  1708. pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
  1709. cvp_setdev_cmd.cvp_set_device_v2.tx_topology_id,
  1710. cvp_setdev_cmd.cvp_set_device_v2.tx_port_id,
  1711. cvp_setdev_cmd.cvp_set_device_v2.rx_port_id);
  1712. v->cvp_state = CMD_STATUS_FAIL;
  1713. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
  1714. if (ret < 0) {
  1715. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  1716. goto fail;
  1717. }
  1718. pr_debug("wait for cvp create session event\n");
  1719. ret = wait_event_timeout(v->cvp_wait,
  1720. (v->cvp_state == CMD_STATUS_SUCCESS),
  1721. msecs_to_jiffies(TIMEOUT_MS));
  1722. if (!ret) {
  1723. pr_err("%s: wait_event timeout\n", __func__);
  1724. goto fail;
  1725. }
  1726. return 0;
  1727. fail:
  1728. return -EINVAL;
  1729. }
  1730. static int voice_send_stop_voice_cmd(struct voice_data *v)
  1731. {
  1732. struct apr_hdr mvm_stop_voice_cmd;
  1733. int ret = 0;
  1734. void *apr_mvm;
  1735. u16 mvm_handle;
  1736. if (v == NULL) {
  1737. pr_err("%s: v is NULL\n", __func__);
  1738. return -EINVAL;
  1739. }
  1740. apr_mvm = common.apr_q6_mvm;
  1741. if (!apr_mvm) {
  1742. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1743. return -EINVAL;
  1744. }
  1745. mvm_handle = voice_get_mvm_handle(v);
  1746. mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1747. APR_HDR_LEN(APR_HDR_SIZE),
  1748. APR_PKT_VER);
  1749. mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1750. sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
  1751. pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
  1752. mvm_stop_voice_cmd.pkt_size);
  1753. mvm_stop_voice_cmd.src_port =
  1754. voice_get_idx_for_session(v->session_id);
  1755. mvm_stop_voice_cmd.dest_port = mvm_handle;
  1756. mvm_stop_voice_cmd.token = 0;
  1757. mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
  1758. v->mvm_state = CMD_STATUS_FAIL;
  1759. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
  1760. if (ret < 0) {
  1761. pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
  1762. goto fail;
  1763. }
  1764. ret = wait_event_timeout(v->mvm_wait,
  1765. (v->mvm_state == CMD_STATUS_SUCCESS),
  1766. msecs_to_jiffies(TIMEOUT_MS));
  1767. if (!ret) {
  1768. pr_err("%s: wait_event timeout\n", __func__);
  1769. goto fail;
  1770. }
  1771. return 0;
  1772. fail:
  1773. return -EINVAL;
  1774. }
  1775. static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
  1776. {
  1777. struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
  1778. struct acdb_cal_block cal_block;
  1779. int ret = 0;
  1780. memset(&cvs_reg_cal_cmd, 0, sizeof(cvs_reg_cal_cmd));
  1781. if (v == NULL) {
  1782. pr_err("%s: v is NULL\n", __func__);
  1783. ret = -EINVAL;
  1784. goto done;
  1785. }
  1786. if (!common.apr_q6_cvs) {
  1787. pr_err("%s: apr_cvs is NULL\n", __func__);
  1788. ret = -EINVAL;
  1789. goto done;
  1790. }
  1791. if (!common.cal_mem_handle) {
  1792. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1793. ret = -EINVAL;
  1794. goto done;
  1795. }
  1796. get_vocstrm_cal(&cal_block);
  1797. if (cal_block.cal_size == 0) {
  1798. pr_err("%s: CVS cal size is 0\n", __func__);
  1799. ret = -EINVAL;
  1800. goto done;
  1801. }
  1802. cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1803. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1804. cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1805. sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
  1806. cvs_reg_cal_cmd.hdr.src_port =
  1807. voice_get_idx_for_session(v->session_id);
  1808. cvs_reg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  1809. cvs_reg_cal_cmd.hdr.token = 0;
  1810. cvs_reg_cal_cmd.hdr.opcode =
  1811. VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2;
  1812. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_handle = common.cal_mem_handle;
  1813. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_address = cal_block.cal_paddr;
  1814. cvs_reg_cal_cmd.cvs_cal_data.cal_mem_size = cal_block.cal_size;
  1815. /* Get the column info corresponding to CVS cal from ACDB. */
  1816. get_voice_col_data(VOCSTRM_CAL, &cal_block);
  1817. if (cal_block.cal_size == 0 ||
  1818. cal_block.cal_size >
  1819. sizeof(cvs_reg_cal_cmd.cvs_cal_data.column_info)) {
  1820. pr_err("%s: Invalid VOCSTRM_CAL size %d\n",
  1821. __func__, cal_block.cal_size);
  1822. ret = -EINVAL;
  1823. goto done;
  1824. }
  1825. memcpy(&cvs_reg_cal_cmd.cvs_cal_data.column_info[0],
  1826. (void *) cal_block.cal_kvaddr,
  1827. cal_block.cal_size);
  1828. v->cvs_state = CMD_STATUS_FAIL;
  1829. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_reg_cal_cmd);
  1830. if (ret < 0) {
  1831. pr_err("%s: Error %d registering CVS cal\n", __func__, ret);
  1832. ret = -EINVAL;
  1833. goto done;
  1834. }
  1835. ret = wait_event_timeout(v->cvs_wait,
  1836. (v->cvs_state == CMD_STATUS_SUCCESS),
  1837. msecs_to_jiffies(TIMEOUT_MS));
  1838. if (!ret) {
  1839. pr_err("%s: Command timeout\n", __func__);
  1840. ret = -EINVAL;
  1841. goto done;
  1842. }
  1843. done:
  1844. return ret;
  1845. }
  1846. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
  1847. {
  1848. struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
  1849. struct acdb_cal_block cal_block;
  1850. int ret = 0;
  1851. memset(&cvs_dereg_cal_cmd, 0, sizeof(cvs_dereg_cal_cmd));
  1852. if (v == NULL) {
  1853. pr_err("%s: v is NULL\n", __func__);
  1854. ret = -EINVAL;
  1855. goto done;
  1856. }
  1857. if (!common.apr_q6_cvs) {
  1858. pr_err("%s: apr_cvs is NULL\n", __func__);
  1859. ret = -EPERM;
  1860. goto done;
  1861. }
  1862. if (!common.cal_mem_handle) {
  1863. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1864. ret = -EPERM;
  1865. goto done;
  1866. }
  1867. get_vocstrm_cal(&cal_block);
  1868. if (cal_block.cal_size == 0) {
  1869. pr_err("%s: CVS cal size is 0\n", __func__);
  1870. ret = -EPERM;
  1871. goto done;
  1872. }
  1873. cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1874. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1875. cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1876. sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
  1877. cvs_dereg_cal_cmd.hdr.src_port =
  1878. voice_get_idx_for_session(v->session_id);
  1879. cvs_dereg_cal_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  1880. cvs_dereg_cal_cmd.hdr.token = 0;
  1881. cvs_dereg_cal_cmd.hdr.opcode =
  1882. VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
  1883. v->cvs_state = CMD_STATUS_FAIL;
  1884. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
  1885. if (ret < 0) {
  1886. pr_err("%s: Error %d de-registering CVS cal\n", __func__, ret);
  1887. ret = -EINVAL;
  1888. goto done;
  1889. }
  1890. ret = wait_event_timeout(v->cvs_wait,
  1891. (v->cvs_state == CMD_STATUS_SUCCESS),
  1892. msecs_to_jiffies(TIMEOUT_MS));
  1893. if (!ret) {
  1894. pr_err("%s: Command timeout\n", __func__);
  1895. ret = -EINVAL;
  1896. goto done;
  1897. }
  1898. done:
  1899. return ret;
  1900. }
  1901. static int voice_send_cvp_register_dev_cfg_cmd(struct voice_data *v)
  1902. {
  1903. struct cvp_register_dev_cfg_cmd cvp_reg_dev_cfg_cmd;
  1904. struct acdb_cal_block cal_block;
  1905. int ret = 0;
  1906. memset(&cvp_reg_dev_cfg_cmd, 0, sizeof(cvp_reg_dev_cfg_cmd));
  1907. if (v == NULL) {
  1908. pr_err("%s: v is NULL\n", __func__);
  1909. ret = -EINVAL;
  1910. goto done;
  1911. }
  1912. if (!common.apr_q6_cvp) {
  1913. pr_err("%s: apr_cvp is NULL\n", __func__);
  1914. ret = -EPERM;
  1915. goto done;
  1916. }
  1917. if (!common.cal_mem_handle) {
  1918. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1919. ret = -EPERM;
  1920. goto done;
  1921. }
  1922. get_vocproc_dev_cfg_cal(&cal_block);
  1923. if (cal_block.cal_size == 0) {
  1924. pr_err("%s: CVP cal size is 0\n", __func__);
  1925. ret = -EPERM;
  1926. goto done;
  1927. }
  1928. cvp_reg_dev_cfg_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1929. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1930. cvp_reg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1931. sizeof(cvp_reg_dev_cfg_cmd) - APR_HDR_SIZE);
  1932. cvp_reg_dev_cfg_cmd.hdr.src_port =
  1933. voice_get_idx_for_session(v->session_id);
  1934. cvp_reg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  1935. cvp_reg_dev_cfg_cmd.hdr.token = 0;
  1936. cvp_reg_dev_cfg_cmd.hdr.opcode =
  1937. VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG;
  1938. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_handle = common.cal_mem_handle;
  1939. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_address = cal_block.cal_paddr;
  1940. cvp_reg_dev_cfg_cmd.cvp_dev_cfg_data.mem_size = cal_block.cal_size;
  1941. v->cvp_state = CMD_STATUS_FAIL;
  1942. ret = apr_send_pkt(common.apr_q6_cvp,
  1943. (uint32_t *) &cvp_reg_dev_cfg_cmd);
  1944. if (ret < 0) {
  1945. pr_err("%s: Error %d registering CVP dev cfg cal\n",
  1946. __func__, ret);
  1947. ret = -EINVAL;
  1948. goto done;
  1949. }
  1950. ret = wait_event_timeout(v->cvp_wait,
  1951. (v->cvp_state == CMD_STATUS_SUCCESS),
  1952. msecs_to_jiffies(TIMEOUT_MS));
  1953. if (!ret) {
  1954. pr_err("%s: Command timeout\n", __func__);
  1955. ret = -EINVAL;
  1956. goto done;
  1957. }
  1958. done:
  1959. return ret;
  1960. }
  1961. static int voice_send_cvp_deregister_dev_cfg_cmd(struct voice_data *v)
  1962. {
  1963. struct cvp_deregister_dev_cfg_cmd cvp_dereg_dev_cfg_cmd;
  1964. struct acdb_cal_block cal_block;
  1965. int ret = 0;
  1966. memset(&cvp_dereg_dev_cfg_cmd, 0, sizeof(cvp_dereg_dev_cfg_cmd));
  1967. if (v == NULL) {
  1968. pr_err("%s: v is NULL\n", __func__);
  1969. ret = -EINVAL;
  1970. goto done;
  1971. }
  1972. if (!common.apr_q6_cvp) {
  1973. pr_err("%s: apr_cvp is NULL\n", __func__);
  1974. ret = -EPERM;
  1975. goto done;
  1976. }
  1977. if (!common.cal_mem_handle) {
  1978. pr_err("%s: Cal mem handle is NULL\n", __func__);
  1979. ret = -EPERM;
  1980. goto done;
  1981. }
  1982. get_vocproc_dev_cfg_cal(&cal_block);
  1983. if (cal_block.cal_size == 0) {
  1984. pr_err("%s: CVP cal size is 0\n", __func__);
  1985. ret = -EPERM;
  1986. goto done;
  1987. }
  1988. cvp_dereg_dev_cfg_cmd.hdr.hdr_field =
  1989. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1990. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1991. cvp_dereg_dev_cfg_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1992. sizeof(cvp_dereg_dev_cfg_cmd) - APR_HDR_SIZE);
  1993. cvp_dereg_dev_cfg_cmd.hdr.src_port =
  1994. voice_get_idx_for_session(v->session_id);
  1995. cvp_dereg_dev_cfg_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  1996. cvp_dereg_dev_cfg_cmd.hdr.token = 0;
  1997. cvp_dereg_dev_cfg_cmd.hdr.opcode =
  1998. VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG;
  1999. v->cvp_state = CMD_STATUS_FAIL;
  2000. ret = apr_send_pkt(common.apr_q6_cvp,
  2001. (uint32_t *) &cvp_dereg_dev_cfg_cmd);
  2002. if (ret < 0) {
  2003. pr_err("%s: Error %d de-registering CVP dev cfg cal\n",
  2004. __func__, ret);
  2005. ret = -EINVAL;
  2006. goto done;
  2007. }
  2008. ret = wait_event_timeout(v->cvp_wait,
  2009. (v->cvp_state == CMD_STATUS_SUCCESS),
  2010. msecs_to_jiffies(TIMEOUT_MS));
  2011. if (!ret) {
  2012. pr_err("%s: Command timeout\n", __func__);
  2013. ret = -EINVAL;
  2014. goto done;
  2015. }
  2016. done:
  2017. return ret;
  2018. }
  2019. static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
  2020. {
  2021. struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
  2022. struct acdb_cal_block cal_block;
  2023. int ret = 0;
  2024. memset(&cvp_reg_cal_cmd, 0, sizeof(cvp_reg_cal_cmd));
  2025. if (v == NULL) {
  2026. pr_err("%s: v is NULL\n", __func__);
  2027. ret = -EINVAL;
  2028. goto done;
  2029. }
  2030. if (!common.apr_q6_cvp) {
  2031. pr_err("%s: apr_cvp is NULL\n", __func__);
  2032. ret = -EINVAL;
  2033. goto done;
  2034. }
  2035. if (!common.cal_mem_handle) {
  2036. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2037. ret = -EINVAL;
  2038. goto done;
  2039. }
  2040. get_vocproc_cal(&cal_block);
  2041. if (cal_block.cal_size == 0) {
  2042. pr_err("%s: CVP cal size is 0\n", __func__);
  2043. ret = -EINVAL;
  2044. goto done;
  2045. }
  2046. cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2047. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2048. cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2049. sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
  2050. cvp_reg_cal_cmd.hdr.src_port =
  2051. voice_get_idx_for_session(v->session_id);
  2052. cvp_reg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2053. cvp_reg_cal_cmd.hdr.token = 0;
  2054. cvp_reg_cal_cmd.hdr.opcode =
  2055. VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2;
  2056. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_handle = common.cal_mem_handle;
  2057. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_address = cal_block.cal_paddr;
  2058. cvp_reg_cal_cmd.cvp_cal_data.cal_mem_size = cal_block.cal_size;
  2059. /* Get the column info corresponding to CVP cal from ACDB. */
  2060. get_voice_col_data(VOCPROC_CAL, &cal_block);
  2061. if (cal_block.cal_size == 0 ||
  2062. cal_block.cal_size >
  2063. sizeof(cvp_reg_cal_cmd.cvp_cal_data.column_info)) {
  2064. pr_err("%s: Invalid VOCPROC_CAL size %d\n",
  2065. __func__, cal_block.cal_size);
  2066. ret = -EINVAL;
  2067. goto done;
  2068. }
  2069. memcpy(&cvp_reg_cal_cmd.cvp_cal_data.column_info[0],
  2070. (void *) cal_block.cal_kvaddr,
  2071. cal_block.cal_size);
  2072. v->cvp_state = CMD_STATUS_FAIL;
  2073. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_reg_cal_cmd);
  2074. if (ret < 0) {
  2075. pr_err("%s: Error %d registering CVP cal\n", __func__, ret);
  2076. ret = -EINVAL;
  2077. goto done;
  2078. }
  2079. ret = wait_event_timeout(v->cvp_wait,
  2080. (v->cvp_state == CMD_STATUS_SUCCESS),
  2081. msecs_to_jiffies(TIMEOUT_MS));
  2082. if (!ret) {
  2083. pr_err("%s: Command timeout\n", __func__);
  2084. ret = -EINVAL;
  2085. goto done;
  2086. }
  2087. done:
  2088. return ret;
  2089. }
  2090. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
  2091. {
  2092. struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
  2093. struct acdb_cal_block cal_block;
  2094. int ret = 0;
  2095. memset(&cvp_dereg_cal_cmd, 0, sizeof(cvp_dereg_cal_cmd));
  2096. if (v == NULL) {
  2097. pr_err("%s: v is NULL\n", __func__);
  2098. ret = -EINVAL;
  2099. goto done;
  2100. }
  2101. if (!common.apr_q6_cvp) {
  2102. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2103. ret = -EPERM;
  2104. goto done;
  2105. }
  2106. if (!common.cal_mem_handle) {
  2107. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2108. ret = -EPERM;
  2109. goto done;
  2110. }
  2111. get_vocproc_cal(&cal_block);
  2112. if (cal_block.cal_size == 0) {
  2113. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2114. ret = -EPERM;
  2115. goto done;
  2116. }
  2117. cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2118. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2119. cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2120. sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
  2121. cvp_dereg_cal_cmd.hdr.src_port =
  2122. voice_get_idx_for_session(v->session_id);
  2123. cvp_dereg_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2124. cvp_dereg_cal_cmd.hdr.token = 0;
  2125. cvp_dereg_cal_cmd.hdr.opcode =
  2126. VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
  2127. v->cvp_state = CMD_STATUS_FAIL;
  2128. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
  2129. if (ret < 0) {
  2130. pr_err("%s: Error %d de-registering CVP cal\n", __func__, ret);
  2131. ret = -EINVAL;
  2132. goto done;
  2133. }
  2134. ret = wait_event_timeout(v->cvp_wait,
  2135. (v->cvp_state == CMD_STATUS_SUCCESS),
  2136. msecs_to_jiffies(TIMEOUT_MS));
  2137. if (!ret) {
  2138. pr_err("%s: Command timeout\n", __func__);
  2139. ret = -EINVAL;
  2140. goto done;
  2141. }
  2142. done:
  2143. return -EINVAL;
  2144. }
  2145. static int voice_send_cvp_register_vol_cal_cmd(struct voice_data *v)
  2146. {
  2147. struct cvp_register_vol_cal_data_cmd cvp_reg_vol_cal_cmd;
  2148. struct acdb_cal_block cal_block;
  2149. int ret = 0;
  2150. memset(&cvp_reg_vol_cal_cmd, 0, sizeof(cvp_reg_vol_cal_cmd));
  2151. if (v == NULL) {
  2152. pr_err("%s: v is NULL\n", __func__);
  2153. ret = -EINVAL;
  2154. goto done;
  2155. }
  2156. if (!common.apr_q6_cvp) {
  2157. pr_err("%s: apr_cvp is NULL\n", __func__);
  2158. ret = -EINVAL;
  2159. goto done;
  2160. }
  2161. if (!common.cal_mem_handle) {
  2162. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2163. ret = -EINVAL;
  2164. goto done;
  2165. }
  2166. get_vocvol_cal(&cal_block);
  2167. if (cal_block.cal_size == 0) {
  2168. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2169. ret = -EINVAL;
  2170. goto done;
  2171. }
  2172. cvp_reg_vol_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2173. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2174. cvp_reg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2175. sizeof(cvp_reg_vol_cal_cmd) - APR_HDR_SIZE);
  2176. cvp_reg_vol_cal_cmd.hdr.src_port =
  2177. voice_get_idx_for_session(v->session_id);
  2178. cvp_reg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2179. cvp_reg_vol_cal_cmd.hdr.token = 0;
  2180. cvp_reg_vol_cal_cmd.hdr.opcode =
  2181. VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA;
  2182. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_handle =
  2183. common.cal_mem_handle;
  2184. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_address =
  2185. cal_block.cal_paddr;
  2186. cvp_reg_vol_cal_cmd.cvp_vol_cal_data.cal_mem_size = cal_block.cal_size;
  2187. /* Get the column info corresponding to CVP volume cal from ACDB. */
  2188. get_voice_col_data(VOCVOL_CAL, &cal_block);
  2189. if (cal_block.cal_size == 0 ||
  2190. cal_block.cal_size >
  2191. sizeof(cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info)) {
  2192. pr_err("%s: Invalid VOCVOL_CAL size %d\n",
  2193. __func__, cal_block.cal_size);
  2194. ret = -EINVAL;
  2195. goto done;
  2196. }
  2197. memcpy(&cvp_reg_vol_cal_cmd.cvp_vol_cal_data.column_info[0],
  2198. (void *) cal_block.cal_kvaddr,
  2199. cal_block.cal_size);
  2200. v->cvp_state = CMD_STATUS_FAIL;
  2201. ret = apr_send_pkt(common.apr_q6_cvp,
  2202. (uint32_t *) &cvp_reg_vol_cal_cmd);
  2203. if (ret < 0) {
  2204. pr_err("%s: Error %d registering CVP vol cal\n", __func__, ret);
  2205. ret = -EINVAL;
  2206. goto done;
  2207. }
  2208. ret = wait_event_timeout(v->cvp_wait,
  2209. (v->cvp_state == CMD_STATUS_SUCCESS),
  2210. msecs_to_jiffies(TIMEOUT_MS));
  2211. if (!ret) {
  2212. pr_err("%s: Command timeout\n", __func__);
  2213. ret = -EINVAL;
  2214. goto done;
  2215. }
  2216. done:
  2217. return ret;
  2218. }
  2219. static int voice_send_cvp_deregister_vol_cal_cmd(struct voice_data *v)
  2220. {
  2221. struct cvp_deregister_vol_cal_data_cmd cvp_dereg_vol_cal_cmd;
  2222. struct acdb_cal_block cal_block;
  2223. int ret = 0;
  2224. memset(&cvp_dereg_vol_cal_cmd, 0, sizeof(cvp_dereg_vol_cal_cmd));
  2225. if (v == NULL) {
  2226. pr_err("%s: v is NULL\n", __func__);
  2227. ret = -EINVAL;
  2228. goto done;
  2229. }
  2230. if (!common.apr_q6_cvp) {
  2231. pr_err("%s: apr_cvp is NULL\n", __func__);
  2232. ret = -EPERM;
  2233. goto done;
  2234. }
  2235. if (!common.cal_mem_handle) {
  2236. pr_err("%s: Cal mem handle is NULL\n", __func__);
  2237. ret = -EPERM;
  2238. goto done;
  2239. }
  2240. get_vocvol_cal(&cal_block);
  2241. if (cal_block.cal_size == 0) {
  2242. pr_err("%s: CVP vol cal size is 0\n", __func__);
  2243. ret = -EPERM;
  2244. goto done;
  2245. }
  2246. cvp_dereg_vol_cal_cmd.hdr.hdr_field =
  2247. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2248. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2249. cvp_dereg_vol_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2250. sizeof(cvp_dereg_vol_cal_cmd) - APR_HDR_SIZE);
  2251. cvp_dereg_vol_cal_cmd.hdr.src_port =
  2252. voice_get_idx_for_session(v->session_id);
  2253. cvp_dereg_vol_cal_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  2254. cvp_dereg_vol_cal_cmd.hdr.token = 0;
  2255. cvp_dereg_vol_cal_cmd.hdr.opcode =
  2256. VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA;
  2257. v->cvp_state = CMD_STATUS_FAIL;
  2258. ret = apr_send_pkt(common.apr_q6_cvp,
  2259. (uint32_t *) &cvp_dereg_vol_cal_cmd);
  2260. if (ret < 0) {
  2261. pr_err("%s: Error %d de-registering CVP vol cal\n",
  2262. __func__, ret);
  2263. ret = -EINVAL;
  2264. goto done;
  2265. }
  2266. ret = wait_event_timeout(v->cvp_wait,
  2267. (v->cvp_state == CMD_STATUS_SUCCESS),
  2268. msecs_to_jiffies(TIMEOUT_MS));
  2269. if (!ret) {
  2270. pr_err("%s: Command timeout\n", __func__);
  2271. ret = -EINVAL;
  2272. goto done;
  2273. }
  2274. done:
  2275. return ret;
  2276. }
  2277. static int voice_map_memory_physical_cmd(struct voice_data *v,
  2278. struct mem_map_table *table_info,
  2279. dma_addr_t phys,
  2280. uint32_t size,
  2281. uint32_t token)
  2282. {
  2283. struct vss_imemory_cmd_map_physical_t mvm_map_phys_cmd;
  2284. uint32_t *memtable;
  2285. int ret = 0;
  2286. if (v == NULL) {
  2287. pr_err("%s: v is NULL\n", __func__);
  2288. goto fail;
  2289. }
  2290. if (!common.apr_q6_mvm) {
  2291. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2292. goto fail;
  2293. }
  2294. if (!table_info->data) {
  2295. pr_err("%s: memory table is NULL.\n", __func__);
  2296. goto fail;
  2297. }
  2298. memtable = (uint32_t *) table_info->data;
  2299. /*
  2300. * Store next table descriptor's address(64 bit) as NULL as there
  2301. * is only one memory block
  2302. */
  2303. memtable[0] = (uint32_t)NULL;
  2304. memtable[1] = (uint32_t)NULL;
  2305. /* Store next table descriptor's size */
  2306. memtable[2] = 0;
  2307. /* Store shared mem add */
  2308. memtable[3] = phys;
  2309. memtable[4] = 0;
  2310. /* Store shared memory size */
  2311. memtable[5] = size;
  2312. mvm_map_phys_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2313. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2314. mvm_map_phys_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2315. sizeof(mvm_map_phys_cmd) - APR_HDR_SIZE);
  2316. mvm_map_phys_cmd.hdr.src_port =
  2317. voice_get_idx_for_session(v->session_id);
  2318. mvm_map_phys_cmd.hdr.dest_port = voice_get_mvm_handle(v);
  2319. mvm_map_phys_cmd.hdr.token = token;
  2320. mvm_map_phys_cmd.hdr.opcode = VSS_IMEMORY_CMD_MAP_PHYSICAL;
  2321. mvm_map_phys_cmd.table_descriptor.mem_address = table_info->phys;
  2322. mvm_map_phys_cmd.table_descriptor.mem_size =
  2323. sizeof(struct vss_imemory_block_t) +
  2324. sizeof(struct vss_imemory_table_descriptor_t);
  2325. mvm_map_phys_cmd.is_cached = true;
  2326. mvm_map_phys_cmd.cache_line_size = 128;
  2327. mvm_map_phys_cmd.access_mask = 3;
  2328. mvm_map_phys_cmd.page_align = 4096;
  2329. mvm_map_phys_cmd.min_data_width = 8;
  2330. mvm_map_phys_cmd.max_data_width = 64;
  2331. pr_debug("%s: next table desc: add: %lld, size: %d\n",
  2332. __func__, *((uint64_t *) memtable),
  2333. *(((uint32_t *) memtable) + 2));
  2334. pr_debug("%s: phy add of of mem being mapped 0x%x, size: %d\n",
  2335. __func__, *(((uint32_t *) memtable) + 3),
  2336. *(((uint32_t *) memtable) + 5));
  2337. v->mvm_state = CMD_STATUS_FAIL;
  2338. ret = apr_send_pkt(common.apr_q6_mvm, (uint32_t *) &mvm_map_phys_cmd);
  2339. if (ret < 0) {
  2340. pr_err("%s: Error %d sending mvm map phy cmd\n", __func__, ret);
  2341. goto fail;
  2342. }
  2343. ret = wait_event_timeout(v->mvm_wait,
  2344. (v->mvm_state == CMD_STATUS_SUCCESS),
  2345. msecs_to_jiffies(TIMEOUT_MS));
  2346. if (!ret) {
  2347. pr_err("%s: Command timeout\n", __func__);
  2348. goto fail;
  2349. }
  2350. return 0;
  2351. fail:
  2352. return -EINVAL;
  2353. }
  2354. static int send_packet_loopback_cmd(struct voice_data *v, bool mode)
  2355. {
  2356. struct cvs_set_loopback_enable_cmd cvs_set_loopback_cmd;
  2357. int ret = 0;
  2358. void *apr_cvs;
  2359. u16 cvs_handle;
  2360. if (v == NULL) {
  2361. pr_err("%s: v is NULL\n", __func__);
  2362. return -EINVAL;
  2363. }
  2364. apr_cvs = common.apr_q6_cvs;
  2365. if (!apr_cvs) {
  2366. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2367. return -EINVAL;
  2368. }
  2369. cvs_handle = voice_get_cvs_handle(v);
  2370. /* fill in the header */
  2371. cvs_set_loopback_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2372. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2373. cvs_set_loopback_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2374. sizeof(cvs_set_loopback_cmd) - APR_HDR_SIZE);
  2375. cvs_set_loopback_cmd.hdr.src_port =
  2376. voice_get_idx_for_session(v->session_id);
  2377. cvs_set_loopback_cmd.hdr.dest_port = cvs_handle;
  2378. cvs_set_loopback_cmd.hdr.token = 0;
  2379. cvs_set_loopback_cmd.hdr.opcode = VOICE_CMD_SET_PARAM;
  2380. cvs_set_loopback_cmd.mem_handle = 0;
  2381. cvs_set_loopback_cmd.mem_address = 0;
  2382. cvs_set_loopback_cmd.mem_size = 0x10;
  2383. cvs_set_loopback_cmd.vss_set_loopback.module_id = VOICEPROC_MODULE_VENC;
  2384. cvs_set_loopback_cmd.vss_set_loopback.param_id = VOICE_PARAM_LOOPBACK_ENABLE;
  2385. cvs_set_loopback_cmd.vss_set_loopback.param_size = MOD_ENABLE_PARAM_LEN;
  2386. cvs_set_loopback_cmd.vss_set_loopback.reserved = 0;
  2387. cvs_set_loopback_cmd.vss_set_loopback.loopback_enable = (mode)? 1: 0;
  2388. cvs_set_loopback_cmd.vss_set_loopback.reserved_field = 0;
  2389. v->cvs_state = CMD_STATUS_FAIL;
  2390. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_loopback_cmd);
  2391. if (ret < 0) {
  2392. pr_err("Fail: sending cvs set loopback enable,\n");
  2393. goto fail;
  2394. }
  2395. ret = wait_event_timeout(v->cvs_wait,
  2396. (v->cvs_state == CMD_STATUS_SUCCESS),
  2397. msecs_to_jiffies(TIMEOUT_MS));
  2398. if (!ret) {
  2399. pr_err("%s: wait_event timeout\n", __func__);
  2400. goto fail;
  2401. }
  2402. return 0;
  2403. fail:
  2404. return -EINVAL;
  2405. }
  2406. static int voice_mem_map_cal_block(struct voice_data *v)
  2407. {
  2408. int ret = 0;
  2409. struct acdb_cal_block cal_block;
  2410. if (v == NULL) {
  2411. pr_err("%s: v is NULL\n", __func__);
  2412. return -EINVAL;
  2413. }
  2414. mutex_lock(&common.common_lock);
  2415. if (common.cal_mem_handle != 0) {
  2416. pr_debug("%s: Cal block already mem mapped\n", __func__);
  2417. goto done;
  2418. }
  2419. /* Get the physical address of calibration memory block from ACDB. */
  2420. get_voice_cal_allocation(&cal_block);
  2421. if (!cal_block.cal_paddr) {
  2422. pr_err("%s: Cal block not allocated\n", __func__);
  2423. ret = -EINVAL;
  2424. goto done;
  2425. }
  2426. ret = voice_map_memory_physical_cmd(v,
  2427. &common.cal_mem_map_table,
  2428. cal_block.cal_paddr,
  2429. cal_block.cal_size,
  2430. VOC_CAL_MEM_MAP_TOKEN);
  2431. done:
  2432. mutex_unlock(&common.common_lock);
  2433. return ret;
  2434. }
  2435. static int voice_pause_voice_call(struct voice_data *v)
  2436. {
  2437. struct apr_hdr mvm_pause_voice_cmd;
  2438. void *apr_mvm;
  2439. int ret = 0;
  2440. pr_debug("%s\n", __func__);
  2441. if (v == NULL) {
  2442. pr_err("%s: Voice data is NULL\n", __func__);
  2443. ret = -EINVAL;
  2444. goto done;
  2445. }
  2446. apr_mvm = common.apr_q6_mvm;
  2447. if (!apr_mvm) {
  2448. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2449. ret = -EINVAL;
  2450. goto done;
  2451. }
  2452. mvm_pause_voice_cmd.hdr_field =
  2453. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2454. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2455. mvm_pause_voice_cmd.pkt_size =
  2456. APR_PKT_SIZE(APR_HDR_SIZE,
  2457. sizeof(mvm_pause_voice_cmd) - APR_HDR_SIZE);
  2458. mvm_pause_voice_cmd.src_port =
  2459. voice_get_idx_for_session(v->session_id);
  2460. mvm_pause_voice_cmd.dest_port = voice_get_mvm_handle(v);
  2461. mvm_pause_voice_cmd.token = 0;
  2462. mvm_pause_voice_cmd.opcode = VSS_IMVM_CMD_PAUSE_VOICE;
  2463. v->mvm_state = CMD_STATUS_FAIL;
  2464. pr_debug("%s: send mvm_pause_voice_cmd pkt size = %d\n",
  2465. __func__, mvm_pause_voice_cmd.pkt_size);
  2466. ret = apr_send_pkt(apr_mvm,
  2467. (uint32_t *)&mvm_pause_voice_cmd);
  2468. if (ret < 0) {
  2469. pr_err("Fail in sending VSS_IMVM_CMD_PAUSE_VOICE\n");
  2470. ret = -EINVAL;
  2471. goto done;
  2472. }
  2473. ret = wait_event_timeout(v->mvm_wait,
  2474. (v->mvm_state == CMD_STATUS_SUCCESS),
  2475. msecs_to_jiffies(TIMEOUT_MS));
  2476. if (!ret) {
  2477. pr_err("%s: Command timeout\n", __func__);
  2478. ret = -EINVAL;
  2479. goto done;
  2480. }
  2481. done:
  2482. return ret;
  2483. }
  2484. int voc_register_vocproc_vol_table(void)
  2485. {
  2486. int result = 0;
  2487. int result2 = 0;
  2488. int i;
  2489. struct voice_data *v = NULL;
  2490. pr_debug("%s\n", __func__);
  2491. mutex_lock(&common.common_lock);
  2492. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2493. v = &common.voice[i];
  2494. mutex_lock(&v->lock);
  2495. if (is_voc_state_active(v->voc_state)) {
  2496. result2 = voice_send_cvp_register_vol_cal_cmd(v);
  2497. if (result2 < 0) {
  2498. pr_err("%s: Failed to register vocvol table for session 0x%x!\n",
  2499. __func__, v->session_id);
  2500. result = result2;
  2501. /* Still try to register other sessions */
  2502. }
  2503. }
  2504. mutex_unlock(&v->lock);
  2505. }
  2506. mutex_unlock(&common.common_lock);
  2507. return result;
  2508. }
  2509. int voc_deregister_vocproc_vol_table(void)
  2510. {
  2511. int result = 0;
  2512. int success = 0;
  2513. int i;
  2514. struct voice_data *v = NULL;
  2515. pr_debug("%s\n", __func__);
  2516. mutex_lock(&common.common_lock);
  2517. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2518. v = &common.voice[i];
  2519. mutex_lock(&v->lock);
  2520. if (is_voc_state_active(v->voc_state)) {
  2521. result = voice_send_cvp_deregister_vol_cal_cmd(v);
  2522. if (result < 0) {
  2523. pr_err("%s: Failed to deregister vocvol table for session 0x%x!\n",
  2524. __func__, v->session_id);
  2525. mutex_unlock(&v->lock);
  2526. mutex_unlock(&common.common_lock);
  2527. if (success) {
  2528. pr_err("%s: Try to re-register all deregistered sessions!\n",
  2529. __func__);
  2530. voc_register_vocproc_vol_table();
  2531. }
  2532. goto done;
  2533. } else {
  2534. success = 1;
  2535. }
  2536. }
  2537. mutex_unlock(&v->lock);
  2538. }
  2539. mutex_unlock(&common.common_lock);
  2540. done:
  2541. return result;
  2542. }
  2543. int voc_map_rtac_block(struct rtac_cal_block_data *cal_block)
  2544. {
  2545. int result = 0;
  2546. struct voice_data *v = NULL;
  2547. pr_debug("%s\n", __func__);
  2548. if (cal_block == NULL) {
  2549. pr_err("%s: cal_block is NULL!\n",
  2550. __func__);
  2551. result = -EINVAL;
  2552. goto done;
  2553. }
  2554. if (cal_block->cal_data.paddr == 0) {
  2555. pr_debug("%s: No address to map!\n",
  2556. __func__);
  2557. result = -EINVAL;
  2558. goto done;
  2559. }
  2560. if (cal_block->map_data.map_size == 0) {
  2561. pr_debug("%s: map size is 0!\n",
  2562. __func__);
  2563. result = -EINVAL;
  2564. goto done;
  2565. }
  2566. mutex_lock(&common.common_lock);
  2567. /* use first session */
  2568. v = &common.voice[0];
  2569. mutex_lock(&v->lock);
  2570. if (!is_rtac_memory_allocated()) {
  2571. result = voice_alloc_rtac_mem_map_table();
  2572. if (result < 0) {
  2573. pr_err("%s: RTAC alloc mem map table did not work! addr = 0x%x, size = %d\n",
  2574. __func__, cal_block->cal_data.paddr,
  2575. cal_block->map_data.map_size);
  2576. goto err;
  2577. }
  2578. }
  2579. result = voice_map_memory_physical_cmd(v,
  2580. &common.rtac_mem_map_table,
  2581. (dma_addr_t)cal_block->cal_data.paddr,
  2582. cal_block->map_data.map_size,
  2583. VOC_RTAC_MEM_MAP_TOKEN);
  2584. if (result < 0) {
  2585. pr_err("%s: RTAC mmap did not work! addr = 0x%x, size = %d\n",
  2586. __func__, cal_block->cal_data.paddr,
  2587. cal_block->map_data.map_size);
  2588. free_rtac_map_table();
  2589. goto err;
  2590. }
  2591. cal_block->map_data.map_handle = common.rtac_mem_handle;
  2592. err:
  2593. mutex_unlock(&v->lock);
  2594. mutex_unlock(&common.common_lock);
  2595. done:
  2596. return result;
  2597. }
  2598. int voc_unmap_rtac_block(uint32_t *mem_map_handle)
  2599. {
  2600. int result = 0;
  2601. struct voice_data *v = NULL;
  2602. pr_debug("%s\n", __func__);
  2603. if (mem_map_handle == NULL) {
  2604. pr_debug("%s: Map handle is NULL, nothing to unmap\n",
  2605. __func__);
  2606. goto done;
  2607. }
  2608. if (*mem_map_handle == 0) {
  2609. pr_debug("%s: Map handle is 0, nothing to unmap\n",
  2610. __func__);
  2611. goto done;
  2612. }
  2613. mutex_lock(&common.common_lock);
  2614. /* use first session */
  2615. v = &common.voice[0];
  2616. mutex_lock(&v->lock);
  2617. result = voice_send_mvm_unmap_memory_physical_cmd(
  2618. v, *mem_map_handle);
  2619. if (result) {
  2620. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd Failed for session 0x%x!\n",
  2621. __func__, v->session_id);
  2622. } else {
  2623. *mem_map_handle = 0;
  2624. common.rtac_mem_handle = 0;
  2625. free_rtac_map_table();
  2626. }
  2627. mutex_unlock(&v->lock);
  2628. mutex_unlock(&common.common_lock);
  2629. done:
  2630. return result;
  2631. }
  2632. int voc_unmap_cal_blocks(void)
  2633. {
  2634. int result = 0;
  2635. int result2 = 0;
  2636. int i;
  2637. struct voice_data *v = NULL;
  2638. pr_debug("%s\n", __func__);
  2639. mutex_lock(&common.common_lock);
  2640. if (common.cal_mem_handle == 0)
  2641. goto done;
  2642. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2643. v = &common.voice[i];
  2644. mutex_lock(&v->lock);
  2645. if (is_voc_state_active(v->voc_state)) {
  2646. result2 = voice_pause_voice_call(v);
  2647. if (result2 < 0) {
  2648. pr_err("%s: voice_pause_voice_call failed for session 0x%x, err %d!\n",
  2649. __func__, v->session_id, result2);
  2650. result = result2;
  2651. }
  2652. voice_send_cvp_deregister_vol_cal_cmd(v);
  2653. voice_send_cvp_deregister_cal_cmd(v);
  2654. voice_send_cvp_deregister_dev_cfg_cmd(v);
  2655. voice_send_cvs_deregister_cal_cmd(v);
  2656. result2 = voice_send_start_voice_cmd(v);
  2657. if (result2) {
  2658. pr_err("%s: voice_send_start_voice_cmd failed for session 0x%x, err %d!\n",
  2659. __func__, v->session_id, result2);
  2660. result = result2;
  2661. }
  2662. }
  2663. if ((common.cal_mem_handle != 0) &&
  2664. (!is_other_session_active(v->session_id))) {
  2665. result2 = voice_send_mvm_unmap_memory_physical_cmd(
  2666. v, common.cal_mem_handle);
  2667. if (result2) {
  2668. pr_err("%s: voice_send_mvm_unmap_memory_physical_cmd failed for session 0x%x, err %d!\n",
  2669. __func__, v->session_id, result2);
  2670. result = result2;
  2671. } else {
  2672. common.cal_mem_handle = 0;
  2673. free_cal_map_table();
  2674. }
  2675. }
  2676. mutex_unlock(&v->lock);
  2677. }
  2678. done:
  2679. mutex_unlock(&common.common_lock);
  2680. return result;
  2681. }
  2682. static int voice_setup_vocproc(struct voice_data *v)
  2683. {
  2684. struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
  2685. int ret = 0;
  2686. void *apr_cvp;
  2687. if (v == NULL) {
  2688. pr_err("%s: v is NULL\n", __func__);
  2689. return -EINVAL;
  2690. }
  2691. apr_cvp = common.apr_q6_cvp;
  2692. if (!apr_cvp) {
  2693. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2694. return -EINVAL;
  2695. }
  2696. /* create cvp session and wait for response */
  2697. cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2698. APR_HDR_LEN(APR_HDR_SIZE),
  2699. APR_PKT_VER);
  2700. cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2701. sizeof(cvp_session_cmd) - APR_HDR_SIZE);
  2702. pr_debug(" send create cvp session, pkt size = %d\n",
  2703. cvp_session_cmd.hdr.pkt_size);
  2704. cvp_session_cmd.hdr.src_port =
  2705. voice_get_idx_for_session(v->session_id);
  2706. cvp_session_cmd.hdr.dest_port = 0;
  2707. cvp_session_cmd.hdr.token = 0;
  2708. cvp_session_cmd.hdr.opcode =
  2709. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2;
  2710. voc_get_tx_rx_topology(v,
  2711. &cvp_session_cmd.cvp_session.tx_topology_id,
  2712. &cvp_session_cmd.cvp_session.rx_topology_id);
  2713. cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
  2714. cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
  2715. cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
  2716. cvp_session_cmd.cvp_session.profile_id =
  2717. VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2718. if (common.ec_ref_ext) {
  2719. cvp_session_cmd.cvp_session.vocproc_mode =
  2720. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  2721. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2722. common.ec_port_id;
  2723. } else {
  2724. cvp_session_cmd.cvp_session.vocproc_mode =
  2725. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  2726. cvp_session_cmd.cvp_session.ec_ref_port_id =
  2727. VSS_IVOCPROC_PORT_ID_NONE;
  2728. }
  2729. pr_debug("tx_topology: %d tx_port_id=%d, rx_port_id=%d, mode: 0x%x\n",
  2730. cvp_session_cmd.cvp_session.tx_topology_id,
  2731. cvp_session_cmd.cvp_session.tx_port_id,
  2732. cvp_session_cmd.cvp_session.rx_port_id,
  2733. cvp_session_cmd.cvp_session.vocproc_mode);
  2734. pr_debug("rx_topology: %d, profile_id: 0x%x, pkt_size: %d\n",
  2735. cvp_session_cmd.cvp_session.rx_topology_id,
  2736. cvp_session_cmd.cvp_session.profile_id,
  2737. cvp_session_cmd.hdr.pkt_size);
  2738. v->cvp_state = CMD_STATUS_FAIL;
  2739. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
  2740. if (ret < 0) {
  2741. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  2742. goto fail;
  2743. }
  2744. ret = wait_event_timeout(v->cvp_wait,
  2745. (v->cvp_state == CMD_STATUS_SUCCESS),
  2746. msecs_to_jiffies(TIMEOUT_MS));
  2747. if (!ret) {
  2748. pr_err("%s: wait_event timeout\n", __func__);
  2749. goto fail;
  2750. }
  2751. voice_send_cvs_register_cal_cmd(v);
  2752. voice_send_cvp_register_dev_cfg_cmd(v);
  2753. voice_send_cvp_register_cal_cmd(v);
  2754. voice_send_cvp_register_vol_cal_cmd(v);
  2755. /* enable vocproc */
  2756. ret = voice_send_enable_vocproc_cmd(v);
  2757. if (ret < 0)
  2758. goto fail;
  2759. /* attach vocproc */
  2760. ret = voice_send_attach_vocproc_cmd(v);
  2761. if (ret < 0)
  2762. goto fail;
  2763. /* send tty mode if tty device is used */
  2764. voice_send_tty_mode_cmd(v);
  2765. if (is_voip_session(v->session_id)) {
  2766. ret = voice_send_mvm_cal_network_cmd(v);
  2767. if (ret < 0)
  2768. pr_err("%s: voice_send_mvm_cal_network_cmd: %d\n",
  2769. __func__, ret);
  2770. ret = voice_send_mvm_media_type_cmd(v);
  2771. if (ret < 0)
  2772. pr_err("%s: voice_send_mvm_media_type_cmd: %d\n",
  2773. __func__, ret);
  2774. voice_send_netid_timing_cmd(v);
  2775. }
  2776. if (v->st_enable && !v->tty_mode)
  2777. voice_send_set_pp_enable_cmd(v,
  2778. MODULE_ID_VOICE_MODULE_ST,
  2779. v->st_enable);
  2780. /* Start in-call music delivery if this feature is enabled */
  2781. if (v->music_info.play_enable)
  2782. voice_cvs_start_playback(v);
  2783. /* Start in-call recording if this feature is enabled */
  2784. if (v->rec_info.rec_enable)
  2785. voice_cvs_start_record(v, v->rec_info.rec_mode);
  2786. if (v->dtmf_rx_detect_en)
  2787. voice_send_dtmf_rx_detection_cmd(v, v->dtmf_rx_detect_en);
  2788. rtac_add_voice(voice_get_cvs_handle(v),
  2789. voice_get_cvp_handle(v),
  2790. v->dev_rx.port_id, v->dev_tx.port_id,
  2791. v->session_id);
  2792. return 0;
  2793. fail:
  2794. return -EINVAL;
  2795. }
  2796. static int voice_send_enable_vocproc_cmd(struct voice_data *v)
  2797. {
  2798. int ret = 0;
  2799. struct apr_hdr cvp_enable_cmd;
  2800. void *apr_cvp;
  2801. u16 cvp_handle;
  2802. if (v == NULL) {
  2803. pr_err("%s: v is NULL\n", __func__);
  2804. return -EINVAL;
  2805. }
  2806. apr_cvp = common.apr_q6_cvp;
  2807. if (!apr_cvp) {
  2808. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2809. return -EINVAL;
  2810. }
  2811. cvp_handle = voice_get_cvp_handle(v);
  2812. /* enable vocproc and wait for respose */
  2813. cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2814. APR_HDR_LEN(APR_HDR_SIZE),
  2815. APR_PKT_VER);
  2816. cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2817. sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
  2818. pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
  2819. cvp_enable_cmd.pkt_size, cvp_handle);
  2820. cvp_enable_cmd.src_port =
  2821. voice_get_idx_for_session(v->session_id);
  2822. cvp_enable_cmd.dest_port = cvp_handle;
  2823. cvp_enable_cmd.token = 0;
  2824. cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
  2825. v->cvp_state = CMD_STATUS_FAIL;
  2826. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
  2827. if (ret < 0) {
  2828. pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
  2829. goto fail;
  2830. }
  2831. ret = wait_event_timeout(v->cvp_wait,
  2832. (v->cvp_state == CMD_STATUS_SUCCESS),
  2833. msecs_to_jiffies(TIMEOUT_MS));
  2834. if (!ret) {
  2835. pr_err("%s: wait_event timeout\n", __func__);
  2836. goto fail;
  2837. }
  2838. return 0;
  2839. fail:
  2840. return -EINVAL;
  2841. }
  2842. static int voice_send_mvm_cal_network_cmd(struct voice_data *v)
  2843. {
  2844. struct vss_imvm_cmd_set_cal_network_t mvm_set_cal_network;
  2845. int ret = 0;
  2846. void *apr_mvm;
  2847. u16 mvm_handle;
  2848. if (v == NULL) {
  2849. pr_err("%s: v is NULL\n", __func__);
  2850. return -EINVAL;
  2851. }
  2852. apr_mvm = common.apr_q6_mvm;
  2853. if (!apr_mvm) {
  2854. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2855. return -EINVAL;
  2856. }
  2857. mvm_handle = voice_get_mvm_handle(v);
  2858. mvm_set_cal_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2859. APR_HDR_LEN(APR_HDR_SIZE),
  2860. APR_PKT_VER);
  2861. mvm_set_cal_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2862. sizeof(mvm_set_cal_network) - APR_HDR_SIZE);
  2863. mvm_set_cal_network.hdr.src_port =
  2864. voice_get_idx_for_session(v->session_id);
  2865. mvm_set_cal_network.hdr.dest_port = mvm_handle;
  2866. mvm_set_cal_network.hdr.token = 0;
  2867. mvm_set_cal_network.hdr.opcode = VSS_IMVM_CMD_SET_CAL_NETWORK;
  2868. mvm_set_cal_network.network_id = VSS_ICOMMON_CAL_NETWORK_ID_NONE;
  2869. v->mvm_state = CMD_STATUS_FAIL;
  2870. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_cal_network);
  2871. if (ret < 0) {
  2872. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  2873. goto fail;
  2874. }
  2875. ret = wait_event_timeout(v->mvm_wait,
  2876. (v->mvm_state == CMD_STATUS_SUCCESS),
  2877. msecs_to_jiffies(TIMEOUT_MS));
  2878. if (!ret) {
  2879. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  2880. goto fail;
  2881. }
  2882. return 0;
  2883. fail:
  2884. return -EINVAL;
  2885. }
  2886. static int voice_send_netid_timing_cmd(struct voice_data *v)
  2887. {
  2888. int ret = 0;
  2889. void *apr_mvm;
  2890. u16 mvm_handle;
  2891. struct mvm_set_network_cmd mvm_set_network;
  2892. struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
  2893. if (v == NULL) {
  2894. pr_err("%s: v is NULL\n", __func__);
  2895. return -EINVAL;
  2896. }
  2897. apr_mvm = common.apr_q6_mvm;
  2898. if (!apr_mvm) {
  2899. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2900. return -EINVAL;
  2901. }
  2902. mvm_handle = voice_get_mvm_handle(v);
  2903. ret = voice_config_cvs_vocoder(v);
  2904. if (ret < 0) {
  2905. pr_err("%s: Error %d configuring CVS voc",
  2906. __func__, ret);
  2907. goto fail;
  2908. }
  2909. /* Set network ID. */
  2910. pr_debug("Setting network ID\n");
  2911. mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2912. APR_HDR_LEN(APR_HDR_SIZE),
  2913. APR_PKT_VER);
  2914. mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2915. sizeof(mvm_set_network) - APR_HDR_SIZE);
  2916. mvm_set_network.hdr.src_port =
  2917. voice_get_idx_for_session(v->session_id);
  2918. mvm_set_network.hdr.dest_port = mvm_handle;
  2919. mvm_set_network.hdr.token = 0;
  2920. mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
  2921. mvm_set_network.network.network_id = common.mvs_info.network_type;
  2922. v->mvm_state = CMD_STATUS_FAIL;
  2923. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
  2924. if (ret < 0) {
  2925. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  2926. goto fail;
  2927. }
  2928. ret = wait_event_timeout(v->mvm_wait,
  2929. (v->mvm_state == CMD_STATUS_SUCCESS),
  2930. msecs_to_jiffies(TIMEOUT_MS));
  2931. if (!ret) {
  2932. pr_err("%s: wait_event timeout\n", __func__);
  2933. goto fail;
  2934. }
  2935. /* Set voice timing. */
  2936. pr_debug("Setting voice timing\n");
  2937. mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2938. APR_HDR_LEN(APR_HDR_SIZE),
  2939. APR_PKT_VER);
  2940. mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2941. sizeof(mvm_set_voice_timing) -
  2942. APR_HDR_SIZE);
  2943. mvm_set_voice_timing.hdr.src_port =
  2944. voice_get_idx_for_session(v->session_id);
  2945. mvm_set_voice_timing.hdr.dest_port = mvm_handle;
  2946. mvm_set_voice_timing.hdr.token = 0;
  2947. mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
  2948. mvm_set_voice_timing.timing.mode = 0;
  2949. mvm_set_voice_timing.timing.enc_offset = 8000;
  2950. mvm_set_voice_timing.timing.dec_req_offset = 3300;
  2951. mvm_set_voice_timing.timing.dec_offset = 8300;
  2952. v->mvm_state = CMD_STATUS_FAIL;
  2953. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
  2954. if (ret < 0) {
  2955. pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
  2956. goto fail;
  2957. }
  2958. ret = wait_event_timeout(v->mvm_wait,
  2959. (v->mvm_state == CMD_STATUS_SUCCESS),
  2960. msecs_to_jiffies(TIMEOUT_MS));
  2961. if (!ret) {
  2962. pr_err("%s: wait_event timeout\n", __func__);
  2963. goto fail;
  2964. }
  2965. return 0;
  2966. fail:
  2967. return -EINVAL;
  2968. }
  2969. static int voice_send_attach_vocproc_cmd(struct voice_data *v)
  2970. {
  2971. int ret = 0;
  2972. struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
  2973. void *apr_mvm;
  2974. u16 mvm_handle, cvp_handle;
  2975. if (v == NULL) {
  2976. pr_err("%s: v is NULL\n", __func__);
  2977. return -EINVAL;
  2978. }
  2979. apr_mvm = common.apr_q6_mvm;
  2980. if (!apr_mvm) {
  2981. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2982. return -EINVAL;
  2983. }
  2984. mvm_handle = voice_get_mvm_handle(v);
  2985. cvp_handle = voice_get_cvp_handle(v);
  2986. /* attach vocproc and wait for response */
  2987. mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2988. APR_HDR_LEN(APR_HDR_SIZE),
  2989. APR_PKT_VER);
  2990. mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2991. sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
  2992. pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
  2993. mvm_a_vocproc_cmd.hdr.pkt_size);
  2994. mvm_a_vocproc_cmd.hdr.src_port =
  2995. voice_get_idx_for_session(v->session_id);
  2996. mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
  2997. mvm_a_vocproc_cmd.hdr.token = 0;
  2998. mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
  2999. mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
  3000. v->mvm_state = CMD_STATUS_FAIL;
  3001. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
  3002. if (ret < 0) {
  3003. pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
  3004. goto fail;
  3005. }
  3006. ret = wait_event_timeout(v->mvm_wait,
  3007. (v->mvm_state == CMD_STATUS_SUCCESS),
  3008. msecs_to_jiffies(TIMEOUT_MS));
  3009. if (!ret) {
  3010. pr_err("%s: wait_event timeout\n", __func__);
  3011. goto fail;
  3012. }
  3013. return 0;
  3014. fail:
  3015. return -EINVAL;
  3016. }
  3017. static int voice_destroy_vocproc(struct voice_data *v)
  3018. {
  3019. struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
  3020. struct apr_hdr cvp_destroy_session_cmd;
  3021. int ret = 0;
  3022. void *apr_mvm, *apr_cvp;
  3023. u16 mvm_handle, cvp_handle;
  3024. if (v == NULL) {
  3025. pr_err("%s: v is NULL\n", __func__);
  3026. return -EINVAL;
  3027. }
  3028. apr_mvm = common.apr_q6_mvm;
  3029. apr_cvp = common.apr_q6_cvp;
  3030. if (!apr_mvm || !apr_cvp) {
  3031. pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
  3032. return -EINVAL;
  3033. }
  3034. mvm_handle = voice_get_mvm_handle(v);
  3035. cvp_handle = voice_get_cvp_handle(v);
  3036. /* disable slowtalk if st_enable is set */
  3037. if (v->st_enable)
  3038. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_ST, 0);
  3039. /* stop playback or recording */
  3040. v->music_info.force = 1;
  3041. voice_cvs_stop_playback(v);
  3042. voice_cvs_stop_record(v);
  3043. /* If voice call is active during VoLTE, SRVCC happens.
  3044. Start recording on voice session if recording started during VoLTE.
  3045. */
  3046. if (is_volte_session(v->session_id) &&
  3047. ((common.voice[VOC_PATH_PASSIVE].voc_state == VOC_RUN) ||
  3048. (common.voice[VOC_PATH_PASSIVE].voc_state == VOC_CHANGE))) {
  3049. if (v->rec_info.rec_enable) {
  3050. voice_cvs_start_record(
  3051. &common.voice[VOC_PATH_PASSIVE],
  3052. v->rec_info.rec_mode);
  3053. common.srvcc_rec_flag = true;
  3054. pr_debug("%s: switch recording, srvcc_rec_flag %d\n",
  3055. __func__, common.srvcc_rec_flag);
  3056. }
  3057. }
  3058. /* send stop voice cmd */
  3059. voice_send_stop_voice_cmd(v);
  3060. /* send stop dtmf detecton cmd */
  3061. if (v->dtmf_rx_detect_en)
  3062. voice_send_dtmf_rx_detection_cmd(v, 0);
  3063. /* reset LCH mode */
  3064. v->lch_mode = 0;
  3065. /* clear mute setting */
  3066. v->dev_rx.dev_mute = common.default_mute_val;
  3067. v->dev_tx.dev_mute = common.default_mute_val;
  3068. v->stream_rx.stream_mute = common.default_mute_val;
  3069. v->stream_tx.stream_mute = common.default_mute_val;
  3070. /* detach VOCPROC and wait for response from mvm */
  3071. mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3072. APR_HDR_LEN(APR_HDR_SIZE),
  3073. APR_PKT_VER);
  3074. mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3075. sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
  3076. pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
  3077. mvm_d_vocproc_cmd.hdr.pkt_size);
  3078. mvm_d_vocproc_cmd.hdr.src_port =
  3079. voice_get_idx_for_session(v->session_id);
  3080. mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
  3081. mvm_d_vocproc_cmd.hdr.token = 0;
  3082. mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
  3083. mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
  3084. v->mvm_state = CMD_STATUS_FAIL;
  3085. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
  3086. if (ret < 0) {
  3087. pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
  3088. goto fail;
  3089. }
  3090. ret = wait_event_timeout(v->mvm_wait,
  3091. (v->mvm_state == CMD_STATUS_SUCCESS),
  3092. msecs_to_jiffies(TIMEOUT_MS));
  3093. if (!ret) {
  3094. pr_err("%s: wait_event timeout\n", __func__);
  3095. goto fail;
  3096. }
  3097. voice_send_cvp_deregister_vol_cal_cmd(v);
  3098. voice_send_cvp_deregister_cal_cmd(v);
  3099. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3100. voice_send_cvs_deregister_cal_cmd(v);
  3101. /* destrop cvp session */
  3102. cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3103. APR_HDR_LEN(APR_HDR_SIZE),
  3104. APR_PKT_VER);
  3105. cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3106. sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
  3107. pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
  3108. cvp_destroy_session_cmd.pkt_size);
  3109. cvp_destroy_session_cmd.src_port =
  3110. voice_get_idx_for_session(v->session_id);
  3111. cvp_destroy_session_cmd.dest_port = cvp_handle;
  3112. cvp_destroy_session_cmd.token = 0;
  3113. cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  3114. v->cvp_state = CMD_STATUS_FAIL;
  3115. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
  3116. if (ret < 0) {
  3117. pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
  3118. goto fail;
  3119. }
  3120. ret = wait_event_timeout(v->cvp_wait,
  3121. (v->cvp_state == CMD_STATUS_SUCCESS),
  3122. msecs_to_jiffies(TIMEOUT_MS));
  3123. if (!ret) {
  3124. pr_err("%s: wait_event timeout\n", __func__);
  3125. goto fail;
  3126. }
  3127. rtac_remove_voice(voice_get_cvs_handle(v));
  3128. cvp_handle = 0;
  3129. voice_set_cvp_handle(v, cvp_handle);
  3130. return 0;
  3131. fail:
  3132. return -EINVAL;
  3133. }
  3134. static int voice_send_mvm_unmap_memory_physical_cmd(struct voice_data *v,
  3135. uint32_t mem_handle)
  3136. {
  3137. struct vss_imemory_cmd_unmap_t mem_unmap;
  3138. int ret = 0;
  3139. void *apr_mvm;
  3140. u16 mvm_handle;
  3141. if (v == NULL) {
  3142. pr_err("%s: v is NULL\n", __func__);
  3143. return -EINVAL;
  3144. }
  3145. apr_mvm = common.apr_q6_mvm;
  3146. if (!apr_mvm) {
  3147. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3148. return -EINVAL;
  3149. }
  3150. mvm_handle = voice_get_mvm_handle(v);
  3151. mem_unmap.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3152. APR_HDR_LEN(APR_HDR_SIZE),
  3153. APR_PKT_VER);
  3154. mem_unmap.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3155. sizeof(mem_unmap) - APR_HDR_SIZE);
  3156. mem_unmap.hdr.src_port =
  3157. voice_get_idx_for_session(v->session_id);
  3158. mem_unmap.hdr.dest_port = mvm_handle;
  3159. mem_unmap.hdr.token = 0;
  3160. mem_unmap.hdr.opcode = VSS_IMEMORY_CMD_UNMAP;
  3161. mem_unmap.mem_handle = mem_handle;
  3162. pr_debug("%s: mem_handle: ox%x\n", __func__, mem_unmap.mem_handle);
  3163. v->mvm_state = CMD_STATUS_FAIL;
  3164. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mem_unmap);
  3165. if (ret < 0) {
  3166. pr_err("mem_unmap op[0x%x]ret[%d]\n",
  3167. mem_unmap.hdr.opcode, ret);
  3168. goto fail;
  3169. }
  3170. ret = wait_event_timeout(v->mvm_wait,
  3171. (v->mvm_state == CMD_STATUS_SUCCESS),
  3172. msecs_to_jiffies(TIMEOUT_MS));
  3173. if (!ret) {
  3174. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3175. goto fail;
  3176. }
  3177. return 0;
  3178. fail:
  3179. return ret;
  3180. }
  3181. static int voice_send_cvs_packet_exchange_config_cmd(struct voice_data *v)
  3182. {
  3183. struct vss_istream_cmd_set_oob_packet_exchange_config_t
  3184. packet_exchange_config_pkt;
  3185. int ret = 0;
  3186. uint64_t *dec_buf;
  3187. uint64_t *enc_buf;
  3188. void *apr_cvs;
  3189. u16 cvs_handle;
  3190. if (v == NULL) {
  3191. pr_err("%s: v is NULL\n", __func__);
  3192. return -EINVAL;
  3193. }
  3194. dec_buf = (uint64_t *)v->shmem_info.sh_buf.buf[0].phys;
  3195. enc_buf = (uint64_t *)v->shmem_info.sh_buf.buf[1].phys;
  3196. apr_cvs = common.apr_q6_cvs;
  3197. if (!apr_cvs) {
  3198. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3199. return -EINVAL;
  3200. }
  3201. cvs_handle = voice_get_cvs_handle(v);
  3202. packet_exchange_config_pkt.hdr.hdr_field = APR_HDR_FIELD(
  3203. APR_MSG_TYPE_SEQ_CMD,
  3204. APR_HDR_LEN(APR_HDR_SIZE),
  3205. APR_PKT_VER);
  3206. packet_exchange_config_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3207. sizeof(packet_exchange_config_pkt) -
  3208. APR_HDR_SIZE);
  3209. packet_exchange_config_pkt.hdr.src_port =
  3210. voice_get_idx_for_session(v->session_id);
  3211. packet_exchange_config_pkt.hdr.dest_port = cvs_handle;
  3212. packet_exchange_config_pkt.hdr.token = 0;
  3213. packet_exchange_config_pkt.hdr.opcode =
  3214. VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG;
  3215. packet_exchange_config_pkt.mem_handle = v->shmem_info.mem_handle;
  3216. packet_exchange_config_pkt.dec_buf_addr = (uint32_t)dec_buf;
  3217. packet_exchange_config_pkt.dec_buf_size = 4096;
  3218. packet_exchange_config_pkt.enc_buf_addr = (uint32_t)enc_buf;
  3219. packet_exchange_config_pkt.enc_buf_size = 4096;
  3220. pr_debug("%s: dec buf: add %p, size %d, enc buf: add %p, size %d\n",
  3221. __func__,
  3222. dec_buf,
  3223. packet_exchange_config_pkt.dec_buf_size,
  3224. enc_buf,
  3225. packet_exchange_config_pkt.enc_buf_size);
  3226. v->cvs_state = CMD_STATUS_FAIL;
  3227. ret = apr_send_pkt(apr_cvs, (uint32_t *) &packet_exchange_config_pkt);
  3228. if (ret < 0) {
  3229. pr_err("Failed to send packet exchange config cmd %d\n", ret);
  3230. goto fail;
  3231. }
  3232. ret = wait_event_timeout(v->cvs_wait,
  3233. (v->cvs_state == CMD_STATUS_SUCCESS),
  3234. msecs_to_jiffies(TIMEOUT_MS));
  3235. if (!ret)
  3236. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3237. return 0;
  3238. fail:
  3239. return -EINVAL;
  3240. }
  3241. static int voice_send_cvs_data_exchange_mode_cmd(struct voice_data *v)
  3242. {
  3243. struct vss_istream_cmd_set_packet_exchange_mode_t data_exchange_pkt;
  3244. int ret = 0;
  3245. void *apr_cvs;
  3246. u16 cvs_handle;
  3247. if (v == NULL) {
  3248. pr_err("%s: v is NULL\n", __func__);
  3249. return -EINVAL;
  3250. }
  3251. apr_cvs = common.apr_q6_cvs;
  3252. if (!apr_cvs) {
  3253. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3254. return -EINVAL;
  3255. }
  3256. cvs_handle = voice_get_cvs_handle(v);
  3257. data_exchange_pkt.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3258. APR_HDR_LEN(APR_HDR_SIZE),
  3259. APR_PKT_VER);
  3260. data_exchange_pkt.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3261. sizeof(data_exchange_pkt) - APR_HDR_SIZE);
  3262. data_exchange_pkt.hdr.src_port =
  3263. voice_get_idx_for_session(v->session_id);
  3264. data_exchange_pkt.hdr.dest_port = cvs_handle;
  3265. data_exchange_pkt.hdr.token = 0;
  3266. data_exchange_pkt.hdr.opcode = VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE;
  3267. data_exchange_pkt.mode = VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND;
  3268. v->cvs_state = CMD_STATUS_FAIL;
  3269. ret = apr_send_pkt(apr_cvs, (uint32_t *) &data_exchange_pkt);
  3270. if (ret < 0) {
  3271. pr_err("Failed to send data exchange mode %d\n", ret);
  3272. goto fail;
  3273. }
  3274. ret = wait_event_timeout(v->cvs_wait,
  3275. (v->cvs_state == CMD_STATUS_SUCCESS),
  3276. msecs_to_jiffies(TIMEOUT_MS));
  3277. if (!ret)
  3278. pr_err("%s: wait_event timeout %d\n", __func__, ret);
  3279. return 0;
  3280. fail:
  3281. return -EINVAL;
  3282. }
  3283. static int voice_send_stream_mute_cmd(struct voice_data *v, uint16_t direction,
  3284. uint16_t mute_flag, uint32_t ramp_duration)
  3285. {
  3286. struct cvs_set_mute_cmd cvs_mute_cmd;
  3287. int ret = 0;
  3288. if (v == NULL) {
  3289. pr_err("%s: v is NULL\n", __func__);
  3290. goto fail;
  3291. }
  3292. if (!common.apr_q6_cvs) {
  3293. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3294. goto fail;
  3295. }
  3296. /* send mute/unmute to cvs */
  3297. cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3298. APR_HDR_LEN(APR_HDR_SIZE),
  3299. APR_PKT_VER);
  3300. cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3301. sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
  3302. cvs_mute_cmd.hdr.src_port =
  3303. voice_get_idx_for_session(v->session_id);
  3304. cvs_mute_cmd.hdr.dest_port = voice_get_cvs_handle(v);
  3305. cvs_mute_cmd.hdr.token = 0;
  3306. cvs_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  3307. cvs_mute_cmd.cvs_set_mute.direction = direction;
  3308. cvs_mute_cmd.cvs_set_mute.mute_flag = mute_flag;
  3309. cvs_mute_cmd.cvs_set_mute.ramp_duration_ms = ramp_duration;
  3310. v->cvs_state = CMD_STATUS_FAIL;
  3311. ret = apr_send_pkt(common.apr_q6_cvs, (uint32_t *) &cvs_mute_cmd);
  3312. if (ret < 0) {
  3313. pr_err("%s: Error %d sending stream mute\n", __func__, ret);
  3314. goto fail;
  3315. }
  3316. ret = wait_event_timeout(v->cvs_wait,
  3317. (v->cvs_state == CMD_STATUS_SUCCESS),
  3318. msecs_to_jiffies(TIMEOUT_MS));
  3319. if (!ret) {
  3320. pr_err("%s: Command timeout\n", __func__);
  3321. goto fail;
  3322. }
  3323. return 0;
  3324. fail:
  3325. return -EINVAL;
  3326. }
  3327. static int voice_send_device_mute_cmd(struct voice_data *v, uint16_t direction,
  3328. uint16_t mute_flag, uint32_t ramp_duration)
  3329. {
  3330. struct cvp_set_mute_cmd cvp_mute_cmd;
  3331. int ret = 0;
  3332. if (v == NULL) {
  3333. pr_err("%s: v is NULL\n", __func__);
  3334. goto fail;
  3335. }
  3336. if (!common.apr_q6_cvp) {
  3337. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3338. goto fail;
  3339. }
  3340. cvp_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3341. APR_HDR_LEN(APR_HDR_SIZE),
  3342. APR_PKT_VER);
  3343. cvp_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3344. sizeof(cvp_mute_cmd) - APR_HDR_SIZE);
  3345. cvp_mute_cmd.hdr.src_port =
  3346. voice_get_idx_for_session(v->session_id);
  3347. cvp_mute_cmd.hdr.dest_port = voice_get_cvp_handle(v);
  3348. cvp_mute_cmd.hdr.token = 0;
  3349. cvp_mute_cmd.hdr.opcode = VSS_IVOLUME_CMD_MUTE_V2;
  3350. cvp_mute_cmd.cvp_set_mute.direction = direction;
  3351. cvp_mute_cmd.cvp_set_mute.mute_flag = mute_flag;
  3352. cvp_mute_cmd.cvp_set_mute.ramp_duration_ms = ramp_duration;
  3353. v->cvp_state = CMD_STATUS_FAIL;
  3354. ret = apr_send_pkt(common.apr_q6_cvp, (uint32_t *) &cvp_mute_cmd);
  3355. if (ret < 0) {
  3356. pr_err("%s: Error %d sending rx device cmd\n", __func__, ret);
  3357. goto fail;
  3358. }
  3359. ret = wait_event_timeout(v->cvp_wait,
  3360. (v->cvp_state == CMD_STATUS_SUCCESS),
  3361. msecs_to_jiffies(TIMEOUT_MS));
  3362. if (!ret) {
  3363. pr_err("%s: Command timeout\n", __func__);
  3364. goto fail;
  3365. }
  3366. return 0;
  3367. fail:
  3368. return -EINVAL;
  3369. }
  3370. static int voice_send_vol_step_cmd(struct voice_data *v)
  3371. {
  3372. struct cvp_set_rx_volume_step_cmd cvp_vol_step_cmd;
  3373. int ret = 0;
  3374. void *apr_cvp;
  3375. u16 cvp_handle;
  3376. if (v == NULL) {
  3377. pr_err("%s: v is NULL\n", __func__);
  3378. return -EINVAL;
  3379. }
  3380. apr_cvp = common.apr_q6_cvp;
  3381. if (!apr_cvp) {
  3382. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3383. return -EINVAL;
  3384. }
  3385. cvp_handle = voice_get_cvp_handle(v);
  3386. /* send volume index to cvp */
  3387. cvp_vol_step_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3388. APR_HDR_LEN(APR_HDR_SIZE),
  3389. APR_PKT_VER);
  3390. cvp_vol_step_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3391. sizeof(cvp_vol_step_cmd) - APR_HDR_SIZE);
  3392. cvp_vol_step_cmd.hdr.src_port =
  3393. voice_get_idx_for_session(v->session_id);
  3394. cvp_vol_step_cmd.hdr.dest_port = cvp_handle;
  3395. cvp_vol_step_cmd.hdr.token = 0;
  3396. cvp_vol_step_cmd.hdr.opcode = VSS_IVOLUME_CMD_SET_STEP;
  3397. cvp_vol_step_cmd.cvp_set_vol_step.direction = VSS_IVOLUME_DIRECTION_RX;
  3398. cvp_vol_step_cmd.cvp_set_vol_step.value = v->dev_rx.volume_step_value;
  3399. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms =
  3400. v->dev_rx.volume_ramp_duration_ms;
  3401. pr_debug("%s step_value:%d, ramp_duration_ms:%d",
  3402. __func__,
  3403. cvp_vol_step_cmd.cvp_set_vol_step.value,
  3404. cvp_vol_step_cmd.cvp_set_vol_step.ramp_duration_ms);
  3405. v->cvp_state = CMD_STATUS_FAIL;
  3406. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_step_cmd);
  3407. if (ret < 0) {
  3408. pr_err("Fail in sending RX VOL step\n");
  3409. return -EINVAL;
  3410. }
  3411. ret = wait_event_timeout(v->cvp_wait,
  3412. (v->cvp_state == CMD_STATUS_SUCCESS),
  3413. msecs_to_jiffies(TIMEOUT_MS));
  3414. if (!ret) {
  3415. pr_err("%s: wait_event timeout\n", __func__);
  3416. return -EINVAL;
  3417. }
  3418. return 0;
  3419. }
  3420. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode)
  3421. {
  3422. int ret = 0;
  3423. void *apr_cvs;
  3424. u16 cvs_handle;
  3425. struct cvs_start_record_cmd cvs_start_record;
  3426. if (v == NULL) {
  3427. pr_err("%s: v is NULL\n", __func__);
  3428. return -EINVAL;
  3429. }
  3430. apr_cvs = common.apr_q6_cvs;
  3431. if (!apr_cvs) {
  3432. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3433. return -EINVAL;
  3434. }
  3435. cvs_handle = voice_get_cvs_handle(v);
  3436. if (!v->rec_info.recording) {
  3437. cvs_start_record.hdr.hdr_field = APR_HDR_FIELD(
  3438. APR_MSG_TYPE_SEQ_CMD,
  3439. APR_HDR_LEN(APR_HDR_SIZE),
  3440. APR_PKT_VER);
  3441. cvs_start_record.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3442. sizeof(cvs_start_record) - APR_HDR_SIZE);
  3443. cvs_start_record.hdr.src_port =
  3444. voice_get_idx_for_session(v->session_id);
  3445. cvs_start_record.hdr.dest_port = cvs_handle;
  3446. cvs_start_record.hdr.token = 0;
  3447. cvs_start_record.hdr.opcode = VSS_IRECORD_CMD_START;
  3448. cvs_start_record.rec_mode.port_id =
  3449. VSS_IRECORD_PORT_ID_DEFAULT;
  3450. if (rec_mode == VOC_REC_UPLINK) {
  3451. cvs_start_record.rec_mode.rx_tap_point =
  3452. VSS_IRECORD_TAP_POINT_NONE;
  3453. cvs_start_record.rec_mode.tx_tap_point =
  3454. VSS_IRECORD_TAP_POINT_STREAM_END;
  3455. } else if (rec_mode == VOC_REC_DOWNLINK) {
  3456. cvs_start_record.rec_mode.rx_tap_point =
  3457. VSS_IRECORD_TAP_POINT_STREAM_END;
  3458. cvs_start_record.rec_mode.tx_tap_point =
  3459. VSS_IRECORD_TAP_POINT_NONE;
  3460. } else if (rec_mode == VOC_REC_BOTH) {
  3461. cvs_start_record.rec_mode.rx_tap_point =
  3462. VSS_IRECORD_TAP_POINT_STREAM_END;
  3463. cvs_start_record.rec_mode.tx_tap_point =
  3464. VSS_IRECORD_TAP_POINT_STREAM_END;
  3465. } else {
  3466. pr_err("%s: Invalid in-call rec_mode %d\n", __func__,
  3467. rec_mode);
  3468. ret = -EINVAL;
  3469. goto fail;
  3470. }
  3471. v->cvs_state = CMD_STATUS_FAIL;
  3472. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_record);
  3473. if (ret < 0) {
  3474. pr_err("%s: Error %d sending START_RECORD\n", __func__,
  3475. ret);
  3476. goto fail;
  3477. }
  3478. ret = wait_event_timeout(v->cvs_wait,
  3479. (v->cvs_state == CMD_STATUS_SUCCESS),
  3480. msecs_to_jiffies(TIMEOUT_MS));
  3481. if (!ret) {
  3482. pr_err("%s: wait_event timeout\n", __func__);
  3483. goto fail;
  3484. }
  3485. v->rec_info.recording = 1;
  3486. } else {
  3487. pr_debug("%s: Start record already sent\n", __func__);
  3488. }
  3489. return 0;
  3490. fail:
  3491. return ret;
  3492. }
  3493. static int voice_cvs_stop_record(struct voice_data *v)
  3494. {
  3495. int ret = 0;
  3496. void *apr_cvs;
  3497. u16 cvs_handle;
  3498. struct apr_hdr cvs_stop_record;
  3499. if (v == NULL) {
  3500. pr_err("%s: v is NULL\n", __func__);
  3501. return -EINVAL;
  3502. }
  3503. apr_cvs = common.apr_q6_cvs;
  3504. if (!apr_cvs) {
  3505. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3506. return -EINVAL;
  3507. }
  3508. cvs_handle = voice_get_cvs_handle(v);
  3509. if (v->rec_info.recording) {
  3510. cvs_stop_record.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3511. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3512. cvs_stop_record.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3513. sizeof(cvs_stop_record) - APR_HDR_SIZE);
  3514. cvs_stop_record.src_port =
  3515. voice_get_idx_for_session(v->session_id);
  3516. cvs_stop_record.dest_port = cvs_handle;
  3517. cvs_stop_record.token = 0;
  3518. cvs_stop_record.opcode = VSS_IRECORD_CMD_STOP;
  3519. v->cvs_state = CMD_STATUS_FAIL;
  3520. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_record);
  3521. if (ret < 0) {
  3522. pr_err("%s: Error %d sending STOP_RECORD\n",
  3523. __func__, ret);
  3524. goto fail;
  3525. }
  3526. ret = wait_event_timeout(v->cvs_wait,
  3527. (v->cvs_state == CMD_STATUS_SUCCESS),
  3528. msecs_to_jiffies(TIMEOUT_MS));
  3529. if (!ret) {
  3530. pr_err("%s: wait_event timeout\n", __func__);
  3531. goto fail;
  3532. }
  3533. v->rec_info.recording = 0;
  3534. } else {
  3535. pr_debug("%s: Stop record already sent\n", __func__);
  3536. }
  3537. return 0;
  3538. fail:
  3539. return ret;
  3540. }
  3541. int voc_start_record(uint32_t port_id, uint32_t set, uint32_t session_id)
  3542. {
  3543. int ret = 0;
  3544. int rec_mode = 0;
  3545. u16 cvs_handle;
  3546. int rec_set = 0;
  3547. struct voice_session_itr itr;
  3548. struct voice_data *v = NULL;
  3549. /* check if session_id is valid */
  3550. if (!voice_is_valid_session_id(session_id)) {
  3551. pr_err("%s: Invalid session id:%u\n", __func__,
  3552. session_id);
  3553. return -EINVAL;
  3554. }
  3555. voice_itr_init(&itr, session_id);
  3556. pr_debug("%s: session_id:%u\n", __func__, session_id);
  3557. while (voice_itr_get_next_session(&itr, &v)) {
  3558. if (v == NULL) {
  3559. pr_err("%s: v is NULL, sessionid:%u\n", __func__,
  3560. session_id);
  3561. break;
  3562. }
  3563. pr_debug("%s: port_id: %d, set: %d, v: %p\n",
  3564. __func__, port_id, set, v);
  3565. mutex_lock(&v->lock);
  3566. rec_mode = v->rec_info.rec_mode;
  3567. rec_set = set;
  3568. if (set) {
  3569. if ((v->rec_route_state.ul_flag != 0) &&
  3570. (v->rec_route_state.dl_flag != 0)) {
  3571. pr_debug("%s: rec mode already set.\n",
  3572. __func__);
  3573. mutex_unlock(&v->lock);
  3574. continue;
  3575. }
  3576. if (port_id == VOICE_RECORD_TX) {
  3577. if ((v->rec_route_state.ul_flag == 0)
  3578. && (v->rec_route_state.dl_flag == 0)) {
  3579. rec_mode = VOC_REC_UPLINK;
  3580. v->rec_route_state.ul_flag = 1;
  3581. } else if ((v->rec_route_state.ul_flag == 0)
  3582. && (v->rec_route_state.dl_flag != 0)) {
  3583. voice_cvs_stop_record(v);
  3584. rec_mode = VOC_REC_BOTH;
  3585. v->rec_route_state.ul_flag = 1;
  3586. }
  3587. } else if (port_id == VOICE_RECORD_RX) {
  3588. if ((v->rec_route_state.ul_flag == 0)
  3589. && (v->rec_route_state.dl_flag == 0)) {
  3590. rec_mode = VOC_REC_DOWNLINK;
  3591. v->rec_route_state.dl_flag = 1;
  3592. } else if ((v->rec_route_state.ul_flag != 0)
  3593. && (v->rec_route_state.dl_flag == 0)) {
  3594. voice_cvs_stop_record(v);
  3595. rec_mode = VOC_REC_BOTH;
  3596. v->rec_route_state.dl_flag = 1;
  3597. }
  3598. }
  3599. rec_set = 1;
  3600. } else {
  3601. if ((v->rec_route_state.ul_flag == 0) &&
  3602. (v->rec_route_state.dl_flag == 0)) {
  3603. pr_debug("%s: rec already stops.\n",
  3604. __func__);
  3605. mutex_unlock(&v->lock);
  3606. continue;
  3607. }
  3608. if (port_id == VOICE_RECORD_TX) {
  3609. if ((v->rec_route_state.ul_flag != 0)
  3610. && (v->rec_route_state.dl_flag == 0)) {
  3611. v->rec_route_state.ul_flag = 0;
  3612. rec_set = 0;
  3613. } else if ((v->rec_route_state.ul_flag != 0)
  3614. && (v->rec_route_state.dl_flag != 0)) {
  3615. voice_cvs_stop_record(v);
  3616. v->rec_route_state.ul_flag = 0;
  3617. rec_mode = VOC_REC_DOWNLINK;
  3618. rec_set = 1;
  3619. }
  3620. } else if (port_id == VOICE_RECORD_RX) {
  3621. if ((v->rec_route_state.ul_flag == 0)
  3622. && (v->rec_route_state.dl_flag != 0)) {
  3623. v->rec_route_state.dl_flag = 0;
  3624. rec_set = 0;
  3625. } else if ((v->rec_route_state.ul_flag != 0)
  3626. && (v->rec_route_state.dl_flag != 0)) {
  3627. voice_cvs_stop_record(v);
  3628. v->rec_route_state.dl_flag = 0;
  3629. rec_mode = VOC_REC_UPLINK;
  3630. rec_set = 1;
  3631. }
  3632. }
  3633. }
  3634. pr_debug("%s: mode =%d, set =%d\n", __func__,
  3635. rec_mode, rec_set);
  3636. cvs_handle = voice_get_cvs_handle(v);
  3637. if (cvs_handle != 0) {
  3638. if (rec_set)
  3639. ret = voice_cvs_start_record(v, rec_mode);
  3640. else
  3641. ret = voice_cvs_stop_record(v);
  3642. }
  3643. /* During SRVCC, recording will switch from VoLTE session to
  3644. voice session.
  3645. Then stop recording, need to stop recording on voice session.
  3646. */
  3647. if ((!rec_set) && common.srvcc_rec_flag) {
  3648. pr_debug("%s, srvcc_rec_flag:%d\n", __func__,
  3649. common.srvcc_rec_flag);
  3650. voice_cvs_stop_record(&common.voice[VOC_PATH_PASSIVE]);
  3651. common.srvcc_rec_flag = false;
  3652. }
  3653. /* Cache the value */
  3654. v->rec_info.rec_enable = rec_set;
  3655. v->rec_info.rec_mode = rec_mode;
  3656. mutex_unlock(&v->lock);
  3657. }
  3658. return ret;
  3659. }
  3660. static int voice_cvs_start_playback(struct voice_data *v)
  3661. {
  3662. int ret = 0;
  3663. struct cvs_start_playback_cmd cvs_start_playback;
  3664. void *apr_cvs;
  3665. u16 cvs_handle;
  3666. if (v == NULL) {
  3667. pr_err("%s: v is NULL\n", __func__);
  3668. return -EINVAL;
  3669. }
  3670. apr_cvs = common.apr_q6_cvs;
  3671. if (!apr_cvs) {
  3672. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3673. return -EINVAL;
  3674. }
  3675. cvs_handle = voice_get_cvs_handle(v);
  3676. if (!v->music_info.playing && v->music_info.count) {
  3677. cvs_start_playback.hdr.hdr_field = APR_HDR_FIELD(
  3678. APR_MSG_TYPE_SEQ_CMD,
  3679. APR_HDR_LEN(APR_HDR_SIZE),
  3680. APR_PKT_VER);
  3681. cvs_start_playback.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3682. sizeof(cvs_start_playback) - APR_HDR_SIZE);
  3683. cvs_start_playback.hdr.src_port =
  3684. voice_get_idx_for_session(v->session_id);
  3685. cvs_start_playback.hdr.dest_port = cvs_handle;
  3686. cvs_start_playback.hdr.token = 0;
  3687. cvs_start_playback.hdr.opcode = VSS_IPLAYBACK_CMD_START;
  3688. cvs_start_playback.playback_mode.port_id =
  3689. v->music_info.port_id;
  3690. v->cvs_state = CMD_STATUS_FAIL;
  3691. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
  3692. if (ret < 0) {
  3693. pr_err("%s: Error %d sending START_PLAYBACK\n",
  3694. __func__, ret);
  3695. goto fail;
  3696. }
  3697. ret = wait_event_timeout(v->cvs_wait,
  3698. (v->cvs_state == CMD_STATUS_SUCCESS),
  3699. msecs_to_jiffies(TIMEOUT_MS));
  3700. if (!ret) {
  3701. pr_err("%s: wait_event timeout\n", __func__);
  3702. goto fail;
  3703. }
  3704. v->music_info.playing = 1;
  3705. } else {
  3706. pr_debug("%s: Start playback already sent\n", __func__);
  3707. }
  3708. return 0;
  3709. fail:
  3710. return ret;
  3711. }
  3712. static int voice_cvs_stop_playback(struct voice_data *v)
  3713. {
  3714. int ret = 0;
  3715. struct apr_hdr cvs_stop_playback;
  3716. void *apr_cvs;
  3717. u16 cvs_handle;
  3718. if (v == NULL) {
  3719. pr_err("%s: v is NULL\n", __func__);
  3720. return -EINVAL;
  3721. }
  3722. apr_cvs = common.apr_q6_cvs;
  3723. if (!apr_cvs) {
  3724. pr_err("%s: apr_cvs is NULL.\n", __func__);
  3725. return -EINVAL;
  3726. }
  3727. cvs_handle = voice_get_cvs_handle(v);
  3728. if (v->music_info.playing && ((!v->music_info.count) ||
  3729. (v->music_info.force))) {
  3730. cvs_stop_playback.hdr_field =
  3731. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3732. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3733. cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3734. sizeof(cvs_stop_playback) - APR_HDR_SIZE);
  3735. cvs_stop_playback.src_port =
  3736. voice_get_idx_for_session(v->session_id);
  3737. cvs_stop_playback.dest_port = cvs_handle;
  3738. cvs_stop_playback.token = 0;
  3739. cvs_stop_playback.opcode = VSS_IPLAYBACK_CMD_STOP;
  3740. v->cvs_state = CMD_STATUS_FAIL;
  3741. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
  3742. if (ret < 0) {
  3743. pr_err("%s: Error %d sending STOP_PLAYBACK\n",
  3744. __func__, ret);
  3745. goto fail;
  3746. }
  3747. ret = wait_event_timeout(v->cvs_wait,
  3748. (v->cvs_state == CMD_STATUS_SUCCESS),
  3749. msecs_to_jiffies(TIMEOUT_MS));
  3750. if (!ret) {
  3751. pr_err("%s: wait_event timeout\n", __func__);
  3752. goto fail;
  3753. }
  3754. v->music_info.playing = 0;
  3755. v->music_info.force = 0;
  3756. } else {
  3757. pr_debug("%s: Stop playback already sent\n", __func__);
  3758. }
  3759. return 0;
  3760. fail:
  3761. return ret;
  3762. }
  3763. int voc_start_playback(uint32_t set, uint16_t port_id)
  3764. {
  3765. int ret = 0;
  3766. u16 cvs_handle;
  3767. struct voice_data *v = NULL;
  3768. if (port_id == VOICE_PLAYBACK_TX)
  3769. v = voice_get_session(voc_get_session_id(VOICE_SESSION_NAME));
  3770. else if (port_id == VOICE2_PLAYBACK_TX)
  3771. v = voice_get_session(voc_get_session_id(VOICE2_SESSION_NAME));
  3772. else
  3773. pr_err("%s: Invalid port_id 0x%x", __func__, port_id);
  3774. while (v != NULL) {
  3775. mutex_lock(&v->lock);
  3776. v->music_info.port_id = port_id;
  3777. v->music_info.play_enable = set;
  3778. if (set)
  3779. v->music_info.count++;
  3780. else
  3781. v->music_info.count--;
  3782. pr_debug("%s: music_info count =%d\n", __func__,
  3783. v->music_info.count);
  3784. cvs_handle = voice_get_cvs_handle(v);
  3785. if (cvs_handle != 0) {
  3786. if (set)
  3787. ret = voice_cvs_start_playback(v);
  3788. else
  3789. ret = voice_cvs_stop_playback(v);
  3790. }
  3791. mutex_unlock(&v->lock);
  3792. /* Voice and VoLTE call use the same pseudo port and hence
  3793. * use the same mixer control. So enable incall delivery
  3794. * for VoLTE as well with Voice.
  3795. */
  3796. if (is_voice_session(v->session_id)) {
  3797. v = voice_get_session(voc_get_session_id(
  3798. VOLTE_SESSION_NAME));
  3799. } else {
  3800. break;
  3801. }
  3802. }
  3803. return ret;
  3804. }
  3805. static int voc_disable_cvp(uint32_t session_id)
  3806. {
  3807. struct voice_data *v = voice_get_session(session_id);
  3808. int ret = 0;
  3809. if (v == NULL) {
  3810. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3811. return -EINVAL;
  3812. }
  3813. mutex_lock(&v->lock);
  3814. if (v->voc_state == VOC_RUN) {
  3815. rtac_remove_voice(voice_get_cvs_handle(v));
  3816. /* send cmd to dsp to disable vocproc */
  3817. ret = voice_send_disable_vocproc_cmd(v);
  3818. if (ret < 0) {
  3819. pr_err("%s: disable vocproc failed\n", __func__);
  3820. goto fail;
  3821. }
  3822. voice_send_cvp_deregister_vol_cal_cmd(v);
  3823. voice_send_cvp_deregister_cal_cmd(v);
  3824. voice_send_cvp_deregister_dev_cfg_cmd(v);
  3825. v->voc_state = VOC_CHANGE;
  3826. }
  3827. if (common.ec_ref_ext)
  3828. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  3829. fail: mutex_unlock(&v->lock);
  3830. return ret;
  3831. }
  3832. static int voc_enable_cvp(uint32_t session_id)
  3833. {
  3834. struct voice_data *v = voice_get_session(session_id);
  3835. int ret = 0;
  3836. if (v == NULL) {
  3837. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  3838. return -EINVAL;
  3839. }
  3840. mutex_lock(&v->lock);
  3841. if (v->voc_state == VOC_CHANGE) {
  3842. ret = voice_send_set_device_cmd(v);
  3843. if (ret < 0) {
  3844. pr_err("%s: Set device failed\n", __func__);
  3845. goto fail;
  3846. }
  3847. voice_send_cvp_register_dev_cfg_cmd(v);
  3848. voice_send_cvp_register_cal_cmd(v);
  3849. voice_send_cvp_register_vol_cal_cmd(v);
  3850. if (v->lch_mode == VOICE_LCH_START) {
  3851. pr_debug("%s: TX and RX mute ON\n", __func__);
  3852. voice_send_device_mute_cmd(v,
  3853. VSS_IVOLUME_DIRECTION_TX,
  3854. VSS_IVOLUME_MUTE_ON,
  3855. DEFAULT_MUTE_RAMP_DURATION);
  3856. voice_send_device_mute_cmd(v,
  3857. VSS_IVOLUME_DIRECTION_RX,
  3858. VSS_IVOLUME_MUTE_ON,
  3859. DEFAULT_MUTE_RAMP_DURATION);
  3860. /* Send unmute cmd as the TX stream
  3861. * might be muted previously
  3862. */
  3863. voice_send_stream_mute_cmd(v,
  3864. VSS_IVOLUME_DIRECTION_TX,
  3865. VSS_IVOLUME_MUTE_OFF,
  3866. DEFAULT_MUTE_RAMP_DURATION);
  3867. } else if (v->lch_mode == VOICE_LCH_STOP) {
  3868. pr_debug("%s: TX and RX mute OFF\n", __func__);
  3869. voice_send_device_mute_cmd(v,
  3870. VSS_IVOLUME_DIRECTION_TX,
  3871. VSS_IVOLUME_MUTE_OFF,
  3872. DEFAULT_MUTE_RAMP_DURATION);
  3873. voice_send_device_mute_cmd(v,
  3874. VSS_IVOLUME_DIRECTION_RX,
  3875. VSS_IVOLUME_MUTE_OFF,
  3876. DEFAULT_MUTE_RAMP_DURATION);
  3877. /* Reset lch mode when VOICE_LCH_STOP is recieved */
  3878. v->lch_mode = 0;
  3879. /* Apply cached mute setting */
  3880. voice_send_stream_mute_cmd(v,
  3881. VSS_IVOLUME_DIRECTION_TX,
  3882. v->stream_tx.stream_mute,
  3883. v->stream_tx.stream_mute_ramp_duration_ms);
  3884. } else {
  3885. pr_debug("%s: Mute commands not sent for lch_mode=%d\n",
  3886. __func__, v->lch_mode);
  3887. }
  3888. ret = voice_send_enable_vocproc_cmd(v);
  3889. if (ret < 0) {
  3890. pr_err("%s: Enable vocproc failed %d\n", __func__, ret);
  3891. goto fail;
  3892. }
  3893. voice_send_tty_mode_cmd(v);
  3894. if (v->st_enable && !v->tty_mode)
  3895. voice_send_set_pp_enable_cmd(v,
  3896. MODULE_ID_VOICE_MODULE_ST,
  3897. v->st_enable);
  3898. rtac_add_voice(voice_get_cvs_handle(v),
  3899. voice_get_cvp_handle(v),
  3900. v->dev_rx.port_id, v->dev_tx.port_id,
  3901. v->session_id);
  3902. v->voc_state = VOC_RUN;
  3903. }
  3904. fail:
  3905. mutex_unlock(&v->lock);
  3906. return ret;
  3907. }
  3908. static int voice_set_packet_exchange_mode_and_config(uint32_t session_id,
  3909. uint32_t mode)
  3910. {
  3911. struct voice_data *v = voice_get_session(session_id);
  3912. int ret = 0;
  3913. if (v == NULL) {
  3914. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3915. return -EINVAL;
  3916. }
  3917. if (v->voc_state != VOC_RUN)
  3918. ret = voice_send_cvs_data_exchange_mode_cmd(v);
  3919. if (ret) {
  3920. pr_err("%s: Error voice_send_data_exchange_mode_cmd %d\n",
  3921. __func__, ret);
  3922. goto fail;
  3923. }
  3924. ret = voice_send_cvs_packet_exchange_config_cmd(v);
  3925. if (ret) {
  3926. pr_err("%s: Error: voice_send_packet_exchange_config_cmd %d\n",
  3927. __func__, ret);
  3928. goto fail;
  3929. }
  3930. return ret;
  3931. fail:
  3932. return -EINVAL;
  3933. }
  3934. int voc_set_tx_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  3935. uint32_t ramp_duration)
  3936. {
  3937. struct voice_data *v = NULL;
  3938. int ret = 0;
  3939. struct voice_session_itr itr;
  3940. voice_itr_init(&itr, session_id);
  3941. while (voice_itr_get_next_session(&itr, &v)) {
  3942. if (v != NULL) {
  3943. mutex_lock(&v->lock);
  3944. v->stream_tx.stream_mute = mute;
  3945. v->stream_tx.stream_mute_ramp_duration_ms =
  3946. ramp_duration;
  3947. if (is_voc_state_active(v->voc_state) &&
  3948. (v->lch_mode == 0))
  3949. ret = voice_send_stream_mute_cmd(v,
  3950. VSS_IVOLUME_DIRECTION_TX,
  3951. v->stream_tx.stream_mute,
  3952. v->stream_tx.stream_mute_ramp_duration_ms);
  3953. mutex_unlock(&v->lock);
  3954. } else {
  3955. pr_err("%s: invalid session_id 0x%x\n", __func__,
  3956. session_id);
  3957. ret = -EINVAL;
  3958. break;
  3959. }
  3960. }
  3961. return ret;
  3962. }
  3963. int voc_set_device_mute(uint32_t session_id, uint32_t dir, uint32_t mute,
  3964. uint32_t ramp_duration)
  3965. {
  3966. struct voice_data *v = NULL;
  3967. int ret = 0;
  3968. struct voice_session_itr itr;
  3969. voice_itr_init(&itr, session_id);
  3970. while (voice_itr_get_next_session(&itr, &v)) {
  3971. if (v != NULL) {
  3972. mutex_lock(&v->lock);
  3973. if (dir == VSS_IVOLUME_DIRECTION_TX) {
  3974. v->dev_tx.dev_mute = mute;
  3975. v->dev_tx.dev_mute_ramp_duration_ms =
  3976. ramp_duration;
  3977. } else {
  3978. v->dev_rx.dev_mute = mute;
  3979. v->dev_rx.dev_mute_ramp_duration_ms =
  3980. ramp_duration;
  3981. }
  3982. if (((v->voc_state == VOC_RUN) ||
  3983. (v->voc_state == VOC_STANDBY)) &&
  3984. (v->lch_mode == 0))
  3985. ret = voice_send_device_mute_cmd(v,
  3986. dir,
  3987. mute,
  3988. ramp_duration);
  3989. mutex_unlock(&v->lock);
  3990. } else {
  3991. pr_err("%s: invalid session_id 0x%x\n", __func__,
  3992. session_id);
  3993. ret = -EINVAL;
  3994. break;
  3995. }
  3996. }
  3997. return ret;
  3998. }
  3999. int voc_get_rx_device_mute(uint32_t session_id)
  4000. {
  4001. struct voice_data *v = voice_get_session(session_id);
  4002. int ret = 0;
  4003. if (v == NULL) {
  4004. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4005. return -EINVAL;
  4006. }
  4007. mutex_lock(&v->lock);
  4008. ret = v->dev_rx.dev_mute;
  4009. mutex_unlock(&v->lock);
  4010. return ret;
  4011. }
  4012. int voc_set_tty_mode(uint32_t session_id, uint8_t tty_mode)
  4013. {
  4014. struct voice_data *v = voice_get_session(session_id);
  4015. int ret = 0;
  4016. if (v == NULL) {
  4017. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4018. return -EINVAL;
  4019. }
  4020. mutex_lock(&v->lock);
  4021. v->tty_mode = tty_mode;
  4022. mutex_unlock(&v->lock);
  4023. return ret;
  4024. }
  4025. uint8_t voc_get_tty_mode(uint32_t session_id)
  4026. {
  4027. struct voice_data *v = voice_get_session(session_id);
  4028. int ret = 0;
  4029. if (v == NULL) {
  4030. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4031. return -EINVAL;
  4032. }
  4033. mutex_lock(&v->lock);
  4034. ret = v->tty_mode;
  4035. mutex_unlock(&v->lock);
  4036. return ret;
  4037. }
  4038. int voc_set_pp_enable(uint32_t session_id, uint32_t module_id, uint32_t enable)
  4039. {
  4040. struct voice_data *v = NULL;
  4041. int ret = 0;
  4042. struct voice_session_itr itr;
  4043. voice_itr_init(&itr, session_id);
  4044. while (voice_itr_get_next_session(&itr, &v)) {
  4045. if (v != NULL) {
  4046. if (!(is_voice_app_id(v->session_id) ||
  4047. is_volte_session(v->session_id)))
  4048. continue;
  4049. mutex_lock(&v->lock);
  4050. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  4051. v->st_enable = enable;
  4052. if (v->voc_state == VOC_RUN) {
  4053. if ((module_id == MODULE_ID_VOICE_MODULE_ST) &&
  4054. (!v->tty_mode))
  4055. ret = voice_send_set_pp_enable_cmd(v,
  4056. MODULE_ID_VOICE_MODULE_ST,
  4057. enable);
  4058. }
  4059. mutex_unlock(&v->lock);
  4060. } else {
  4061. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4062. session_id);
  4063. ret = -EINVAL;
  4064. break;
  4065. }
  4066. }
  4067. return ret;
  4068. }
  4069. int voc_get_pp_enable(uint32_t session_id, uint32_t module_id)
  4070. {
  4071. struct voice_data *v = voice_get_session(session_id);
  4072. int ret = 0;
  4073. if (v == NULL) {
  4074. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4075. return -EINVAL;
  4076. }
  4077. mutex_lock(&v->lock);
  4078. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  4079. ret = v->st_enable;
  4080. mutex_unlock(&v->lock);
  4081. return ret;
  4082. }
  4083. int voc_set_rx_vol_step(uint32_t session_id, uint32_t dir, uint32_t vol_step,
  4084. uint32_t ramp_duration)
  4085. {
  4086. struct voice_data *v = NULL;
  4087. int ret = 0;
  4088. struct voice_session_itr itr;
  4089. pr_debug("%s session id = %#x vol = %u", __func__, session_id,
  4090. vol_step);
  4091. voice_itr_init(&itr, session_id);
  4092. while (voice_itr_get_next_session(&itr, &v)) {
  4093. if (v != NULL) {
  4094. mutex_lock(&v->lock);
  4095. v->dev_rx.volume_step_value = vol_step;
  4096. v->dev_rx.volume_ramp_duration_ms = ramp_duration;
  4097. if (is_voc_state_active(v->voc_state))
  4098. ret = voice_send_vol_step_cmd(v);
  4099. mutex_unlock(&v->lock);
  4100. } else {
  4101. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4102. session_id);
  4103. ret = -EINVAL;
  4104. break;
  4105. }
  4106. }
  4107. return ret;
  4108. }
  4109. int voc_set_rxtx_port(uint32_t session_id, uint32_t port_id, uint32_t dev_type)
  4110. {
  4111. struct voice_data *v = voice_get_session(session_id);
  4112. if (v == NULL) {
  4113. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4114. return -EINVAL;
  4115. }
  4116. pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
  4117. mutex_lock(&v->lock);
  4118. if (dev_type == DEV_RX)
  4119. v->dev_rx.port_id = q6audio_get_port_id(port_id);
  4120. else
  4121. v->dev_tx.port_id = q6audio_get_port_id(port_id);
  4122. mutex_unlock(&v->lock);
  4123. return 0;
  4124. }
  4125. int voc_set_route_flag(uint32_t session_id, uint8_t path_dir, uint8_t set)
  4126. {
  4127. struct voice_data *v = voice_get_session(session_id);
  4128. if (v == NULL) {
  4129. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4130. return -EINVAL;
  4131. }
  4132. pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
  4133. mutex_lock(&v->lock);
  4134. if (path_dir == RX_PATH)
  4135. v->voc_route_state.rx_route_flag = set;
  4136. else
  4137. v->voc_route_state.tx_route_flag = set;
  4138. mutex_unlock(&v->lock);
  4139. return 0;
  4140. }
  4141. uint8_t voc_get_route_flag(uint32_t session_id, uint8_t path_dir)
  4142. {
  4143. struct voice_data *v = voice_get_session(session_id);
  4144. int ret = 0;
  4145. if (v == NULL) {
  4146. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4147. return 0;
  4148. }
  4149. mutex_lock(&v->lock);
  4150. if (path_dir == RX_PATH)
  4151. ret = v->voc_route_state.rx_route_flag;
  4152. else
  4153. ret = v->voc_route_state.tx_route_flag;
  4154. mutex_unlock(&v->lock);
  4155. return ret;
  4156. }
  4157. int voc_end_voice_call(uint32_t session_id)
  4158. {
  4159. struct voice_data *v = voice_get_session(session_id);
  4160. int ret = 0;
  4161. if (v == NULL) {
  4162. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4163. return -EINVAL;
  4164. }
  4165. mutex_lock(&v->lock);
  4166. if (v->voc_state == VOC_RUN || v->voc_state == VOC_ERROR ||
  4167. v->voc_state == VOC_CHANGE || v->voc_state == VOC_STANDBY) {
  4168. if ((loopback_mode == 0) && (loopback_prev_mode == 1)) {
  4169. ret = send_packet_loopback_cmd(v, false);
  4170. if (ret < 0) {
  4171. pr_err("send packet loopback disable cmd failed\n");
  4172. } else {
  4173. pr_info("send packet loopback disable cmd success\n");
  4174. }
  4175. loopback_prev_mode = 0;
  4176. }
  4177. pr_debug("%s: VOC_STATE: %d\n", __func__, v->voc_state);
  4178. ret = voice_destroy_vocproc(v);
  4179. if (ret < 0)
  4180. pr_err("%s: destroy voice failed\n", __func__);
  4181. voice_destroy_mvm_cvs_session(v);
  4182. v->voc_state = VOC_RELEASE;
  4183. } else {
  4184. pr_err("%s: Error: End voice called in state %d\n",
  4185. __func__, v->voc_state);
  4186. ret = -EINVAL;
  4187. }
  4188. if (common.ec_ref_ext)
  4189. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  4190. mutex_unlock(&v->lock);
  4191. return ret;
  4192. }
  4193. int voc_standby_voice_call(uint32_t session_id)
  4194. {
  4195. struct voice_data *v = voice_get_session(session_id);
  4196. struct apr_hdr mvm_standby_voice_cmd;
  4197. void *apr_mvm;
  4198. u16 mvm_handle;
  4199. int ret = 0;
  4200. if (v == NULL) {
  4201. pr_err("%s: v is NULL\n", __func__);
  4202. return -EINVAL;
  4203. }
  4204. pr_debug("%s: voc state=%d", __func__, v->voc_state);
  4205. if (v->voc_state == VOC_RUN) {
  4206. apr_mvm = common.apr_q6_mvm;
  4207. if (!apr_mvm) {
  4208. pr_err("%s: apr_mvm is NULL.\n", __func__);
  4209. ret = -EINVAL;
  4210. goto fail;
  4211. }
  4212. mvm_handle = voice_get_mvm_handle(v);
  4213. mvm_standby_voice_cmd.hdr_field =
  4214. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4215. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4216. mvm_standby_voice_cmd.pkt_size =
  4217. APR_PKT_SIZE(APR_HDR_SIZE,
  4218. sizeof(mvm_standby_voice_cmd) - APR_HDR_SIZE);
  4219. pr_debug("send mvm_standby_voice_cmd pkt size = %d\n",
  4220. mvm_standby_voice_cmd.pkt_size);
  4221. mvm_standby_voice_cmd.src_port =
  4222. voice_get_idx_for_session(v->session_id);
  4223. mvm_standby_voice_cmd.dest_port = mvm_handle;
  4224. mvm_standby_voice_cmd.token = 0;
  4225. mvm_standby_voice_cmd.opcode = VSS_IMVM_CMD_STANDBY_VOICE;
  4226. v->mvm_state = CMD_STATUS_FAIL;
  4227. ret = apr_send_pkt(apr_mvm,
  4228. (uint32_t *)&mvm_standby_voice_cmd);
  4229. if (ret < 0) {
  4230. pr_err("Fail in sending VSS_IMVM_CMD_STANDBY_VOICE\n");
  4231. ret = -EINVAL;
  4232. goto fail;
  4233. }
  4234. v->voc_state = VOC_STANDBY;
  4235. }
  4236. fail:
  4237. return ret;
  4238. }
  4239. int voc_disable_device(uint32_t session_id)
  4240. {
  4241. struct voice_data *v = voice_get_session(session_id);
  4242. int ret = 0;
  4243. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  4244. if (v == NULL) {
  4245. pr_err("%s: v is NULL\n", __func__);
  4246. return -EINVAL;
  4247. }
  4248. mutex_lock(&v->lock);
  4249. if (v->voc_state == VOC_RUN) {
  4250. ret = voice_pause_voice_call(v);
  4251. if (ret < 0) {
  4252. pr_err("%s: Pause Voice Call failed for session 0x%x, err %d!\n",
  4253. __func__, v->session_id, ret);
  4254. goto done;
  4255. }
  4256. rtac_remove_voice(voice_get_cvs_handle(v));
  4257. voice_send_cvp_deregister_vol_cal_cmd(v);
  4258. voice_send_cvp_deregister_cal_cmd(v);
  4259. voice_send_cvp_deregister_dev_cfg_cmd(v);
  4260. v->voc_state = VOC_CHANGE;
  4261. } else {
  4262. pr_debug("%s: called in voc state=%d, No_OP\n",
  4263. __func__, v->voc_state);
  4264. }
  4265. if (common.ec_ref_ext)
  4266. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  4267. done:
  4268. mutex_unlock(&v->lock);
  4269. return ret;
  4270. }
  4271. int voc_enable_device(uint32_t session_id)
  4272. {
  4273. struct voice_data *v = voice_get_session(session_id);
  4274. int ret = 0;
  4275. pr_debug("%s: voc state=%d\n", __func__, v->voc_state);
  4276. if (v == NULL) {
  4277. pr_err("%s: v is NULL\n", __func__);
  4278. return -EINVAL;
  4279. }
  4280. mutex_lock(&v->lock);
  4281. if (v->voc_state == VOC_CHANGE) {
  4282. ret = voice_send_tty_mode_cmd(v);
  4283. if (ret < 0) {
  4284. pr_err("%s: Sending TTY mode failed, ret=%d\n",
  4285. __func__, ret);
  4286. /* Not a critical error, allow voice call to continue */
  4287. }
  4288. if (v->tty_mode) {
  4289. /* disable slowtalk */
  4290. voice_send_set_pp_enable_cmd(v,
  4291. MODULE_ID_VOICE_MODULE_ST,
  4292. 0);
  4293. } else {
  4294. /* restore slowtalk */
  4295. voice_send_set_pp_enable_cmd(v,
  4296. MODULE_ID_VOICE_MODULE_ST,
  4297. v->st_enable);
  4298. }
  4299. ret = voice_send_set_device_cmd(v);
  4300. if (ret < 0) {
  4301. pr_err("%s: Set device failed, ret=%d\n",
  4302. __func__, ret);
  4303. goto done;
  4304. }
  4305. voice_send_cvp_register_dev_cfg_cmd(v);
  4306. voice_send_cvp_register_cal_cmd(v);
  4307. voice_send_cvp_register_vol_cal_cmd(v);
  4308. rtac_add_voice(voice_get_cvs_handle(v),
  4309. voice_get_cvp_handle(v),
  4310. v->dev_rx.port_id, v->dev_tx.port_id,
  4311. v->session_id);
  4312. ret = voice_send_start_voice_cmd(v);
  4313. if (ret < 0) {
  4314. pr_err("%s: Fail in sending START_VOICE, ret=%d\n",
  4315. __func__, ret);
  4316. goto done;
  4317. }
  4318. v->voc_state = VOC_RUN;
  4319. } else {
  4320. pr_debug("%s: called in voc state=%d, No_OP\n",
  4321. __func__, v->voc_state);
  4322. }
  4323. done:
  4324. mutex_unlock(&v->lock);
  4325. return ret;
  4326. }
  4327. int voc_set_lch(uint32_t session_id, enum voice_lch_mode lch_mode)
  4328. {
  4329. struct voice_data *v = voice_get_session(session_id);
  4330. int ret = 0;
  4331. if (v == NULL) {
  4332. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  4333. ret = -EINVAL;
  4334. goto done;
  4335. }
  4336. mutex_lock(&v->lock);
  4337. if (v->lch_mode == lch_mode) {
  4338. pr_debug("%s: Session %d already in LCH mode %d\n",
  4339. __func__, session_id, lch_mode);
  4340. mutex_unlock(&v->lock);
  4341. goto done;
  4342. }
  4343. v->lch_mode = lch_mode;
  4344. mutex_unlock(&v->lock);
  4345. ret = voc_disable_cvp(session_id);
  4346. if (ret < 0) {
  4347. pr_err("%s: voc_disable_cvp failed ret=%d\n", __func__, ret);
  4348. goto done;
  4349. }
  4350. /* Mute and topology_none will be set as part of voc_enable_cvp() */
  4351. ret = voc_enable_cvp(session_id);
  4352. if (ret < 0) {
  4353. pr_err("%s: voc_enable_cvp failed ret=%d\n", __func__, ret);
  4354. goto done;
  4355. }
  4356. done:
  4357. return ret;
  4358. }
  4359. int voc_resume_voice_call(uint32_t session_id)
  4360. {
  4361. struct voice_data *v = voice_get_session(session_id);
  4362. int ret = 0;
  4363. ret = voice_send_start_voice_cmd(v);
  4364. if (ret < 0) {
  4365. pr_err("Fail in sending START_VOICE\n");
  4366. goto fail;
  4367. }
  4368. v->voc_state = VOC_RUN;
  4369. return 0;
  4370. fail:
  4371. return -EINVAL;
  4372. }
  4373. int voc_start_voice_call(uint32_t session_id)
  4374. {
  4375. struct voice_data *v = voice_get_session(session_id);
  4376. int ret = 0;
  4377. if (v == NULL) {
  4378. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4379. return -EINVAL;
  4380. }
  4381. mutex_lock(&v->lock);
  4382. if (v->voc_state == VOC_ERROR) {
  4383. pr_debug("%s: VOC in ERR state\n", __func__);
  4384. voice_destroy_mvm_cvs_session(v);
  4385. v->voc_state = VOC_INIT;
  4386. }
  4387. if ((v->voc_state == VOC_INIT) ||
  4388. (v->voc_state == VOC_RELEASE)) {
  4389. ret = voice_apr_register();
  4390. if (ret < 0) {
  4391. pr_err("%s: apr register failed\n", __func__);
  4392. goto fail;
  4393. }
  4394. ret = voice_create_mvm_cvs_session(v);
  4395. if (ret < 0) {
  4396. pr_err("create mvm and cvs failed\n");
  4397. goto fail;
  4398. }
  4399. /* Allocate cal mem if not already allocated and memory map
  4400. * the calibration memory block.
  4401. */
  4402. ret = voice_alloc_and_map_cal_mem(v);
  4403. if (ret < 0) {
  4404. pr_debug("%s: Continue without calibration %d\n",
  4405. __func__, ret);
  4406. }
  4407. if (is_voip_session(session_id)) {
  4408. /* Allocate oob mem if not already allocated and
  4409. * memory map the oob memory block.
  4410. */
  4411. ret = voice_alloc_and_map_oob_mem(v);
  4412. if (ret < 0) {
  4413. pr_err("%s: voice_alloc_and_map_oob_mem() failed, ret:%d\n",
  4414. __func__, ret);
  4415. goto fail;
  4416. }
  4417. ret = voice_set_packet_exchange_mode_and_config(
  4418. session_id,
  4419. VSS_ISTREAM_PACKET_EXCHANGE_MODE_OUT_OF_BAND);
  4420. if (ret) {
  4421. pr_err("%s: Err: exchange_mode_and_config %d\n",
  4422. __func__, ret);
  4423. goto fail;
  4424. }
  4425. }
  4426. ret = voice_send_dual_control_cmd(v);
  4427. if (ret < 0) {
  4428. pr_err("Err Dual command failed\n");
  4429. goto fail;
  4430. }
  4431. ret = voice_setup_vocproc(v);
  4432. if (ret < 0) {
  4433. pr_err("setup voice failed\n");
  4434. goto fail;
  4435. }
  4436. ret = voice_send_vol_step_cmd(v);
  4437. if (ret < 0)
  4438. pr_err("voice volume failed\n");
  4439. ret = voice_send_stream_mute_cmd(v,
  4440. VSS_IVOLUME_DIRECTION_TX,
  4441. v->stream_tx.stream_mute,
  4442. v->stream_tx.stream_mute_ramp_duration_ms);
  4443. if (ret < 0)
  4444. pr_err("voice mute failed\n");
  4445. ret = voice_send_start_voice_cmd(v);
  4446. if (ret < 0) {
  4447. pr_err("start voice failed\n");
  4448. goto fail;
  4449. }
  4450. if (loopback_mode == 1) {
  4451. ret = send_packet_loopback_cmd(v, true);
  4452. if (ret < 0) {
  4453. pr_err("send packet loopback cmd failed\n");
  4454. goto fail;
  4455. } else {
  4456. pr_info("%s : send packet loopback enable cmd success\n", __func__);
  4457. }
  4458. }
  4459. v->voc_state = VOC_RUN;
  4460. } else {
  4461. pr_err("%s: Error: Start voice called in state %d\n",
  4462. __func__, v->voc_state);
  4463. ret = -EINVAL;
  4464. goto fail;
  4465. }
  4466. fail:
  4467. mutex_unlock(&v->lock);
  4468. return ret;
  4469. }
  4470. int voc_set_ext_ec_ref(uint16_t port_id, bool state)
  4471. {
  4472. int ret = 0;
  4473. mutex_lock(&common.common_lock);
  4474. if (state == true) {
  4475. if (port_id == AFE_PORT_INVALID) {
  4476. pr_err("%s: Invalid port id", __func__);
  4477. ret = -EINVAL;
  4478. goto exit;
  4479. }
  4480. common.ec_port_id = port_id;
  4481. common.ec_ref_ext = true;
  4482. } else {
  4483. common.ec_ref_ext = false;
  4484. common.ec_port_id = port_id;
  4485. }
  4486. exit:
  4487. mutex_unlock(&common.common_lock);
  4488. return ret;
  4489. }
  4490. void voc_register_mvs_cb(ul_cb_fn ul_cb,
  4491. dl_cb_fn dl_cb,
  4492. voip_ssr_cb ssr_cb,
  4493. void *private_data)
  4494. {
  4495. common.mvs_info.ul_cb = ul_cb;
  4496. common.mvs_info.dl_cb = dl_cb;
  4497. common.mvs_info.ssr_cb = ssr_cb;
  4498. common.mvs_info.private_data = private_data;
  4499. }
  4500. void voc_register_dtmf_rx_detection_cb(dtmf_rx_det_cb_fn dtmf_rx_ul_cb,
  4501. void *private_data)
  4502. {
  4503. common.dtmf_info.dtmf_rx_ul_cb = dtmf_rx_ul_cb;
  4504. common.dtmf_info.private_data = private_data;
  4505. }
  4506. void voc_config_vocoder(uint32_t media_type,
  4507. uint32_t rate,
  4508. uint32_t network_type,
  4509. uint32_t dtx_mode,
  4510. uint32_t evrc_min_rate,
  4511. uint32_t evrc_max_rate)
  4512. {
  4513. common.mvs_info.media_type = media_type;
  4514. common.mvs_info.rate = rate;
  4515. common.mvs_info.network_type = network_type;
  4516. common.mvs_info.dtx_mode = dtx_mode;
  4517. common.mvs_info.evrc_min_rate = evrc_min_rate;
  4518. common.mvs_info.evrc_max_rate = evrc_max_rate;
  4519. }
  4520. #ifdef CONFIG_SEC_DHA_SOL_MAL
  4521. static int voice_send_dha_data(struct voice_data *v)
  4522. {
  4523. struct oem_dha_parm_send_cmd vpcm_dha_param_send_cmd;
  4524. int ret = 0, mode = 0;
  4525. void *apr_cvp;
  4526. u16 cvp_handle;
  4527. if (v == NULL) {
  4528. pr_err("%s: v is NULL\n", __func__);
  4529. return -EINVAL;
  4530. }
  4531. apr_cvp = common.apr_q6_cvp;
  4532. if (!apr_cvp) {
  4533. pr_err("%s: apr_cvp is NULL.\n", __func__);
  4534. return -EINVAL;
  4535. }
  4536. cvp_handle = voice_get_cvp_handle(v);
  4537. /* BEGIN: DHA */
  4538. /* Send start vpcm and wait for response. */
  4539. pr_debug("%s: Success DHA\n", __func__);
  4540. /* fill in the header */
  4541. vpcm_dha_param_send_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4542. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  4543. vpcm_dha_param_send_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4544. sizeof(vpcm_dha_param_send_cmd) - APR_HDR_SIZE);
  4545. vpcm_dha_param_send_cmd.hdr.src_port = voice_get_idx_for_session(v->session_id);
  4546. vpcm_dha_param_send_cmd.hdr.dest_port = cvp_handle;
  4547. vpcm_dha_param_send_cmd.hdr.token = 0;
  4548. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  4549. vpcm_dha_param_send_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  4550. #else
  4551. vpcm_dha_param_send_cmd.hdr.opcode = VOICE_CMD_SET_PARAM;
  4552. #endif
  4553. #if !defined(CONFIG_MACH_S3VE3G_EUR) && !defined(CONFIG_MACH_MS01_EUR_3G) && !defined(CONFIG_MACH_MS01_EUR_LTE) && !defined(CONFIG_MACH_MS01_KOR_LTE) && !defined(CONFIG_DSDA_VIA_UART)
  4554. vpcm_dha_param_send_cmd.mem_handle = 0;
  4555. vpcm_dha_param_send_cmd.mem_address = 0;
  4556. vpcm_dha_param_send_cmd.mem_size = 40;
  4557. #endif
  4558. vpcm_dha_param_send_cmd.dha_send.module_id = VOICE_MODULE_DHA;
  4559. vpcm_dha_param_send_cmd.dha_send.param_id = VOICE_PARAM_DHA_DYNAMIC;
  4560. vpcm_dha_param_send_cmd.dha_send.param_size = 28;
  4561. vpcm_dha_param_send_cmd.dha_send.reserved = 0;
  4562. mode = v->sec_dha_data.dha_mode;
  4563. vpcm_dha_param_send_cmd.dha_send.eq_mode = mode;
  4564. vpcm_dha_param_send_cmd.dha_send.select =
  4565. (uint16_t)v->sec_dha_data.dha_select;
  4566. memcpy(vpcm_dha_param_send_cmd.dha_send.param,
  4567. v->sec_dha_data.dha_params, 24);
  4568. pr_info(" send vpcm_dha_param_send_cmd, mode = %d, select=%d\n",
  4569. mode, vpcm_dha_param_send_cmd.dha_send.select);
  4570. v->cvp_state = CMD_STATUS_FAIL;
  4571. dha_state = 1;
  4572. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_dha_param_send_cmd);
  4573. if (ret < 0) {
  4574. pr_err("%s: Failed to send vpcm_dha_param_send_cmd\n",
  4575. __func__);
  4576. dha_state = 0;
  4577. goto fail;
  4578. }
  4579. pr_debug("wait for vpcm_dha_param_send_cmd\n");
  4580. ret = wait_event_timeout(v->cvp_wait,
  4581. (v->cvp_state == CMD_STATUS_SUCCESS),
  4582. msecs_to_jiffies(TIMEOUT_MS));
  4583. dha_state = 0;
  4584. if (!ret) {
  4585. pr_err("%s: wait_event timeout\n", __func__);
  4586. goto fail;
  4587. }
  4588. return 0;
  4589. fail:
  4590. return -EINVAL;
  4591. }
  4592. int voice_sec_set_dha_data(uint32_t session_id, short mode,
  4593. short select, short *parameters)
  4594. {
  4595. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  4596. struct voice_data *v = NULL;
  4597. int ret = 0;
  4598. int i = 0;
  4599. struct voice_session_itr itr;
  4600. voice_itr_init(&itr, session_id);
  4601. while (voice_itr_get_next_session(&itr, &v)) {
  4602. if (v != NULL) {
  4603. mutex_lock(&v->lock);
  4604. v->sec_dha_data.dha_mode = mode;
  4605. v->sec_dha_data.dha_select = select;
  4606. for (i = 0; i < 12; i++)
  4607. v->sec_dha_data.dha_params[i] = (short)parameters[i];
  4608. if (is_voc_state_active(v->voc_state) &&
  4609. (v->lch_mode == 0))
  4610. ret = voice_send_dha_data(v);
  4611. mutex_unlock(&v->lock);
  4612. } else {
  4613. pr_err("%s: invalid session_id 0x%x\n", __func__,
  4614. session_id);
  4615. ret = -EINVAL;
  4616. break;
  4617. }
  4618. }
  4619. #else
  4620. struct voice_data *v = voice_get_session(session_id);
  4621. int ret = 0;
  4622. int i;
  4623. if (v == NULL) {
  4624. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  4625. return -EINVAL;
  4626. }
  4627. mutex_lock(&v->lock);
  4628. v->sec_dha_data.dha_mode = mode;
  4629. v->sec_dha_data.dha_select = select;
  4630. for (i = 0; i < 12; i++)
  4631. v->sec_dha_data.dha_params[i] = (short)parameters[i];
  4632. if (v->voc_state == VOC_RUN)
  4633. ret = voice_send_dha_data(v);
  4634. mutex_unlock(&v->lock);
  4635. #endif
  4636. return ret;
  4637. }
  4638. EXPORT_SYMBOL(voice_sec_set_dha_data);
  4639. #endif /* CONFIG_SEC_DHA_SOL_MAL*/
  4640. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
  4641. {
  4642. uint32_t *ptr = NULL;
  4643. struct common_data *c = NULL;
  4644. struct voice_data *v = NULL;
  4645. int i = 0;
  4646. if ((data == NULL) || (priv == NULL)) {
  4647. pr_err("%s: data or priv is NULL\n", __func__);
  4648. return -EINVAL;
  4649. }
  4650. c = priv;
  4651. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  4652. data->payload_size, data->opcode);
  4653. if (data->opcode == RESET_EVENTS) {
  4654. if (data->reset_proc == APR_DEST_MODEM) {
  4655. pr_debug("%s: Received MODEM reset event\n", __func__);
  4656. } else {
  4657. pr_debug("%s: Reset event received in Voice service\n",
  4658. __func__);
  4659. if (common.mvs_info.ssr_cb) {
  4660. pr_debug("%s: Informing reset event to VoIP\n",
  4661. __func__);
  4662. common.mvs_info.ssr_cb(data->opcode,
  4663. common.mvs_info.private_data);
  4664. }
  4665. apr_reset(c->apr_q6_mvm);
  4666. c->apr_q6_mvm = NULL;
  4667. /* clean up memory handle */
  4668. c->cal_mem_handle = 0;
  4669. c->rtac_mem_handle = 0;
  4670. rtac_clear_mapping(VOICE_RTAC_CAL);
  4671. /* Sub-system restart is applicable to all sessions. */
  4672. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  4673. c->voice[i].mvm_handle = 0;
  4674. c->voice[i].shmem_info.mem_handle = 0;
  4675. }
  4676. }
  4677. /* clean up srvcc rec flag */
  4678. c->srvcc_rec_flag = false;
  4679. voc_set_error_state(data->reset_proc);
  4680. return 0;
  4681. }
  4682. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  4683. v = voice_get_session_by_idx(data->dest_port);
  4684. if (v == NULL) {
  4685. pr_err("%s: v is NULL\n", __func__);
  4686. return -EINVAL;
  4687. }
  4688. if (data->opcode == APR_BASIC_RSP_RESULT) {
  4689. if (data->payload_size) {
  4690. ptr = data->payload;
  4691. pr_debug("%x %x\n", ptr[0], ptr[1]);
  4692. /* ping mvm service ACK */
  4693. switch (ptr[0]) {
  4694. case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  4695. case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
  4696. /* Passive session is used for CS call
  4697. * Full session is used for VoIP call. */
  4698. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4699. if (!ptr[1]) {
  4700. pr_debug("%s: MVM handle is %d\n",
  4701. __func__, data->src_port);
  4702. voice_set_mvm_handle(v, data->src_port);
  4703. } else
  4704. pr_err("got NACK for sending MVM create session\n");
  4705. v->mvm_state = CMD_STATUS_SUCCESS;
  4706. wake_up(&v->mvm_wait);
  4707. break;
  4708. case VSS_IMVM_CMD_START_VOICE:
  4709. case VSS_IMVM_CMD_ATTACH_VOCPROC:
  4710. case VSS_IMVM_CMD_STOP_VOICE:
  4711. case VSS_IMVM_CMD_DETACH_VOCPROC:
  4712. case VSS_ISTREAM_CMD_SET_TTY_MODE:
  4713. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  4714. case VSS_IMVM_CMD_ATTACH_STREAM:
  4715. case VSS_IMVM_CMD_DETACH_STREAM:
  4716. case VSS_ICOMMON_CMD_SET_NETWORK:
  4717. case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
  4718. case VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL:
  4719. case VSS_IMVM_CMD_SET_CAL_NETWORK:
  4720. case VSS_IMVM_CMD_SET_CAL_MEDIA_TYPE:
  4721. case VSS_IMEMORY_CMD_MAP_PHYSICAL:
  4722. case VSS_IMEMORY_CMD_UNMAP:
  4723. case VSS_IMVM_CMD_PAUSE_VOICE:
  4724. case VSS_IMVM_CMD_STANDBY_VOICE:
  4725. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4726. v->mvm_state = CMD_STATUS_SUCCESS;
  4727. wake_up(&v->mvm_wait);
  4728. break;
  4729. default:
  4730. pr_debug("%s: not match cmd = 0x%x\n",
  4731. __func__, ptr[0]);
  4732. break;
  4733. }
  4734. }
  4735. } else if (data->opcode == VSS_IMEMORY_RSP_MAP) {
  4736. pr_debug("%s, Revd VSS_IMEMORY_RSP_MAP response\n", __func__);
  4737. if (data->payload_size && data->token == VOIP_MEM_MAP_TOKEN) {
  4738. ptr = data->payload;
  4739. if (ptr[0]) {
  4740. v->shmem_info.mem_handle = ptr[0];
  4741. pr_debug("%s: shared mem_handle: 0x[%x]\n",
  4742. __func__, v->shmem_info.mem_handle);
  4743. v->mvm_state = CMD_STATUS_SUCCESS;
  4744. wake_up(&v->mvm_wait);
  4745. }
  4746. } else if (data->payload_size &&
  4747. data->token == VOC_CAL_MEM_MAP_TOKEN) {
  4748. ptr = data->payload;
  4749. if (ptr[0]) {
  4750. c->cal_mem_handle = ptr[0];
  4751. pr_debug("%s: cal mem handle 0x%x\n",
  4752. __func__, c->cal_mem_handle);
  4753. v->mvm_state = CMD_STATUS_SUCCESS;
  4754. wake_up(&v->mvm_wait);
  4755. }
  4756. } else if (data->payload_size &&
  4757. data->token == VOC_RTAC_MEM_MAP_TOKEN) {
  4758. ptr = data->payload;
  4759. if (ptr[0]) {
  4760. c->rtac_mem_handle = ptr[0];
  4761. pr_debug("%s: cal mem handle 0x%x\n",
  4762. __func__, c->rtac_mem_handle);
  4763. v->mvm_state = CMD_STATUS_SUCCESS;
  4764. wake_up(&v->mvm_wait);
  4765. }
  4766. } else {
  4767. pr_err("%s: Unknown mem map token %d\n",
  4768. __func__, data->token);
  4769. }
  4770. }
  4771. return 0;
  4772. }
  4773. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
  4774. {
  4775. uint32_t *ptr = NULL;
  4776. struct common_data *c = NULL;
  4777. struct voice_data *v = NULL;
  4778. int i = 0;
  4779. if ((data == NULL) || (priv == NULL)) {
  4780. pr_err("%s: data or priv is NULL\n", __func__);
  4781. return -EINVAL;
  4782. }
  4783. c = priv;
  4784. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  4785. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  4786. data->payload_size, data->opcode);
  4787. if (data->opcode == RESET_EVENTS) {
  4788. if (data->reset_proc == APR_DEST_MODEM) {
  4789. pr_debug("%s: Received Modem reset event\n", __func__);
  4790. } else {
  4791. pr_debug("%s: Reset event received in Voice service\n",
  4792. __func__);
  4793. apr_reset(c->apr_q6_cvs);
  4794. c->apr_q6_cvs = NULL;
  4795. /* Sub-system restart is applicable to all sessions. */
  4796. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  4797. c->voice[i].cvs_handle = 0;
  4798. }
  4799. voc_set_error_state(data->reset_proc);
  4800. return 0;
  4801. }
  4802. v = voice_get_session_by_idx(data->dest_port);
  4803. if (v == NULL) {
  4804. pr_err("%s: v is NULL\n", __func__);
  4805. return -EINVAL;
  4806. }
  4807. if (data->opcode == APR_BASIC_RSP_RESULT) {
  4808. if (data->payload_size) {
  4809. ptr = data->payload;
  4810. pr_debug("%x %x\n", ptr[0], ptr[1]);
  4811. if (ptr[1] != 0) {
  4812. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  4813. __func__, ptr[0], ptr[1]);
  4814. }
  4815. /*response from CVS */
  4816. switch (ptr[0]) {
  4817. case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  4818. case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
  4819. if (!ptr[1]) {
  4820. pr_debug("%s: CVS handle is %d\n",
  4821. __func__, data->src_port);
  4822. voice_set_cvs_handle(v, data->src_port);
  4823. } else
  4824. pr_err("got NACK for sending CVS create session\n");
  4825. v->cvs_state = CMD_STATUS_SUCCESS;
  4826. wake_up(&v->cvs_wait);
  4827. break;
  4828. case VSS_IVOLUME_CMD_MUTE_V2:
  4829. case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
  4830. case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
  4831. case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
  4832. case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
  4833. case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
  4834. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  4835. case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA_V2:
  4836. case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
  4837. case VSS_ICOMMON_CMD_MAP_MEMORY:
  4838. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  4839. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  4840. case VSS_IPLAYBACK_CMD_START:
  4841. case VSS_IPLAYBACK_CMD_STOP:
  4842. case VSS_IRECORD_CMD_START:
  4843. case VSS_IRECORD_CMD_STOP:
  4844. case VSS_ISTREAM_CMD_SET_PACKET_EXCHANGE_MODE:
  4845. case VSS_ISTREAM_CMD_SET_OOB_PACKET_EXCHANGE_CONFIG:
  4846. case VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION:
  4847. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4848. v->cvs_state = CMD_STATUS_SUCCESS;
  4849. wake_up(&v->cvs_wait);
  4850. break;
  4851. case VOICE_CMD_SET_PARAM:
  4852. pr_debug("%s: VOICE_CMD_SET_PARAM\n", __func__);
  4853. rtac_make_voice_callback(RTAC_CVS, ptr,
  4854. data->payload_size);
  4855. if ((loopback_mode == 1) ||
  4856. ((loopback_mode == 0) && (loopback_prev_mode == 1))) {
  4857. v->cvs_state = CMD_STATUS_SUCCESS;
  4858. wake_up(&v->cvs_wait);
  4859. }
  4860. break;
  4861. case VOICE_CMD_GET_PARAM:
  4862. pr_debug("%s: VOICE_CMD_GET_PARAM\n",
  4863. __func__);
  4864. /* Should only come here if there is an APR */
  4865. /* error or malformed APR packet. Otherwise */
  4866. /* response will be returned as */
  4867. /* VOICE_EVT_GET_PARAM_ACK */
  4868. if (ptr[1] != 0) {
  4869. pr_err("%s: CVP get param error = %d, resuming\n",
  4870. __func__, ptr[1]);
  4871. rtac_make_voice_callback(RTAC_CVP,
  4872. data->payload,
  4873. data->payload_size);
  4874. }
  4875. break;
  4876. default:
  4877. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  4878. break;
  4879. }
  4880. }
  4881. } else if (data->opcode ==
  4882. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_READY) {
  4883. int ret = 0;
  4884. u16 cvs_handle;
  4885. uint32_t *cvs_voc_pkt;
  4886. struct cvs_enc_buffer_consumed_cmd send_enc_buf_consumed_cmd;
  4887. void *apr_cvs;
  4888. pr_debug("Encoder buffer is ready\n");
  4889. apr_cvs = common.apr_q6_cvs;
  4890. if (!apr_cvs) {
  4891. pr_err("%s: apr_cvs is NULL\n", __func__);
  4892. return -EINVAL;
  4893. }
  4894. cvs_handle = voice_get_cvs_handle(v);
  4895. send_enc_buf_consumed_cmd.hdr.hdr_field =
  4896. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4897. APR_HDR_LEN(APR_HDR_SIZE),
  4898. APR_PKT_VER);
  4899. send_enc_buf_consumed_cmd.hdr.pkt_size =
  4900. APR_PKT_SIZE(APR_HDR_SIZE,
  4901. sizeof(send_enc_buf_consumed_cmd) - APR_HDR_SIZE);
  4902. send_enc_buf_consumed_cmd.hdr.src_port =
  4903. voice_get_idx_for_session(v->session_id);
  4904. send_enc_buf_consumed_cmd.hdr.dest_port = cvs_handle;
  4905. send_enc_buf_consumed_cmd.hdr.token = 0;
  4906. send_enc_buf_consumed_cmd.hdr.opcode =
  4907. VSS_ISTREAM_EVT_OOB_NOTIFY_ENC_BUFFER_CONSUMED;
  4908. cvs_voc_pkt = v->shmem_info.sh_buf.buf[1].data;
  4909. if (cvs_voc_pkt != NULL && common.mvs_info.ul_cb != NULL) {
  4910. if (v->shmem_info.sh_buf.buf[1].size <
  4911. ((3 * sizeof(uint32_t)) + cvs_voc_pkt[2])) {
  4912. pr_err("%s: invalid voc pkt size\n", __func__);
  4913. return -EINVAL;
  4914. }
  4915. /* cvs_voc_pkt[0] contains tx timestamp */
  4916. common.mvs_info.ul_cb((uint8_t *)&cvs_voc_pkt[3],
  4917. cvs_voc_pkt[2],
  4918. cvs_voc_pkt[0],
  4919. common.mvs_info.private_data);
  4920. } else
  4921. pr_err("%s: cvs_voc_pkt or ul_cb is NULL\n", __func__);
  4922. ret = apr_send_pkt(apr_cvs,
  4923. (uint32_t *) &send_enc_buf_consumed_cmd);
  4924. if (ret < 0) {
  4925. pr_err("%s: Err send ENC_BUF_CONSUMED_NOTIFY %d\n",
  4926. __func__, ret);
  4927. goto fail;
  4928. }
  4929. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
  4930. pr_debug("Recd VSS_ISTREAM_EVT_SEND_ENC_BUFFER\n");
  4931. } else if (data->opcode ==
  4932. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_REQUEST) {
  4933. int ret = 0;
  4934. u16 cvs_handle;
  4935. uint32_t *cvs_voc_pkt;
  4936. struct cvs_dec_buffer_ready_cmd send_dec_buf;
  4937. void *apr_cvs;
  4938. apr_cvs = common.apr_q6_cvs;
  4939. if (!apr_cvs) {
  4940. pr_err("%s: apr_cvs is NULL\n", __func__);
  4941. return -EINVAL;
  4942. }
  4943. cvs_handle = voice_get_cvs_handle(v);
  4944. send_dec_buf.hdr.hdr_field =
  4945. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  4946. APR_HDR_LEN(APR_HDR_SIZE),
  4947. APR_PKT_VER);
  4948. send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  4949. sizeof(send_dec_buf) - APR_HDR_SIZE);
  4950. send_dec_buf.hdr.src_port =
  4951. voice_get_idx_for_session(v->session_id);
  4952. send_dec_buf.hdr.dest_port = cvs_handle;
  4953. send_dec_buf.hdr.token = 0;
  4954. send_dec_buf.hdr.opcode =
  4955. VSS_ISTREAM_EVT_OOB_NOTIFY_DEC_BUFFER_READY;
  4956. cvs_voc_pkt = (uint32_t *)(v->shmem_info.sh_buf.buf[0].data);
  4957. if (cvs_voc_pkt != NULL && common.mvs_info.dl_cb != NULL) {
  4958. /* Set timestamp to 0 and advance the pointer */
  4959. cvs_voc_pkt[0] = 0;
  4960. /* Set media_type and advance the pointer */
  4961. cvs_voc_pkt[1] = common.mvs_info.media_type;
  4962. common.mvs_info.dl_cb(
  4963. (uint8_t *)&cvs_voc_pkt[2],
  4964. common.mvs_info.private_data);
  4965. ret = apr_send_pkt(apr_cvs, (uint32_t *) &send_dec_buf);
  4966. if (ret < 0) {
  4967. pr_err("%s: Err send DEC_BUF_READY_NOTIFI %d\n",
  4968. __func__, ret);
  4969. goto fail;
  4970. }
  4971. } else {
  4972. pr_debug("%s: voc_pkt or dl_cb is NULL\n", __func__);
  4973. goto fail;
  4974. }
  4975. } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
  4976. pr_debug("Recd VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER\n");
  4977. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
  4978. pr_debug("Send dec buf resp\n");
  4979. } else if (data->opcode == APR_RSP_ACCEPTED) {
  4980. ptr = data->payload;
  4981. if (ptr[0])
  4982. pr_debug("%s: APR_RSP_ACCEPTED for 0x%x:\n",
  4983. __func__, ptr[0]);
  4984. } else if (data->opcode == VSS_ISTREAM_EVT_NOT_READY) {
  4985. pr_debug("Recd VSS_ISTREAM_EVT_NOT_READY\n");
  4986. } else if (data->opcode == VSS_ISTREAM_EVT_READY) {
  4987. pr_debug("Recd VSS_ISTREAM_EVT_READY\n");
  4988. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  4989. pr_debug("%s: VOICE_EVT_GET_PARAM_ACK\n", __func__);
  4990. ptr = data->payload;
  4991. if (ptr[0] != 0) {
  4992. pr_err("%s: VOICE_EVT_GET_PARAM_ACK returned error = 0x%x\n",
  4993. __func__, ptr[0]);
  4994. }
  4995. rtac_make_voice_callback(RTAC_CVS, data->payload,
  4996. data->payload_size);
  4997. } else if (data->opcode == VSS_ISTREAM_EVT_RX_DTMF_DETECTED) {
  4998. struct vss_istream_evt_rx_dtmf_detected *dtmf_rx_detected;
  4999. uint32_t *voc_pkt = data->payload;
  5000. uint32_t pkt_len = data->payload_size;
  5001. if ((voc_pkt != NULL) &&
  5002. (pkt_len ==
  5003. sizeof(struct vss_istream_evt_rx_dtmf_detected))) {
  5004. dtmf_rx_detected =
  5005. (struct vss_istream_evt_rx_dtmf_detected *) voc_pkt;
  5006. pr_debug("RX_DTMF_DETECTED low_freq=%d high_freq=%d\n",
  5007. dtmf_rx_detected->low_freq,
  5008. dtmf_rx_detected->high_freq);
  5009. if (c->dtmf_info.dtmf_rx_ul_cb)
  5010. c->dtmf_info.dtmf_rx_ul_cb((uint8_t *)voc_pkt,
  5011. voc_get_session_name(v->session_id),
  5012. c->dtmf_info.private_data);
  5013. } else {
  5014. pr_err("Invalid packet\n");
  5015. }
  5016. } else
  5017. pr_debug("Unknown opcode 0x%x\n", data->opcode);
  5018. fail:
  5019. return 0;
  5020. }
  5021. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
  5022. {
  5023. uint32_t *ptr = NULL;
  5024. struct common_data *c = NULL;
  5025. struct voice_data *v = NULL;
  5026. int i = 0;
  5027. if ((data == NULL) || (priv == NULL)) {
  5028. pr_err("%s: data or priv is NULL\n", __func__);
  5029. return -EINVAL;
  5030. }
  5031. c = priv;
  5032. if (data->opcode == RESET_EVENTS) {
  5033. if (data->reset_proc == APR_DEST_MODEM) {
  5034. pr_debug("%s: Received Modem reset event\n", __func__);
  5035. } else {
  5036. pr_debug("%s: Reset event received in Voice service\n",
  5037. __func__);
  5038. apr_reset(c->apr_q6_cvp);
  5039. c->apr_q6_cvp = NULL;
  5040. /* Sub-system restart is applicable to all sessions. */
  5041. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  5042. c->voice[i].cvp_handle = 0;
  5043. }
  5044. voc_set_error_state(data->reset_proc);
  5045. return 0;
  5046. }
  5047. v = voice_get_session_by_idx(data->dest_port);
  5048. if (v == NULL) {
  5049. pr_err("%s: v is NULL\n", __func__);
  5050. return -EINVAL;
  5051. }
  5052. if (data->opcode == APR_BASIC_RSP_RESULT) {
  5053. if (data->payload_size) {
  5054. ptr = data->payload;
  5055. pr_debug("%x %x\n", ptr[0], ptr[1]);
  5056. if (ptr[1] != 0) {
  5057. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  5058. __func__, ptr[0], ptr[1]);
  5059. }
  5060. switch (ptr[0]) {
  5061. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION_V2:
  5062. /*response from CVP */
  5063. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  5064. if (!ptr[1]) {
  5065. voice_set_cvp_handle(v, data->src_port);
  5066. pr_debug("status: %d, cvphdl=%d\n",
  5067. ptr[1], data->src_port);
  5068. } else
  5069. pr_err("got NACK from CVP create session response\n");
  5070. v->cvp_state = CMD_STATUS_SUCCESS;
  5071. wake_up(&v->cvp_wait);
  5072. break;
  5073. case VSS_IVOCPROC_CMD_SET_DEVICE_V2:
  5074. case VSS_IVOLUME_CMD_SET_STEP:
  5075. case VSS_IVOCPROC_CMD_ENABLE:
  5076. case VSS_IVOCPROC_CMD_DISABLE:
  5077. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  5078. case VSS_IVOCPROC_CMD_REGISTER_VOL_CALIBRATION_DATA:
  5079. case VSS_IVOCPROC_CMD_DEREGISTER_VOL_CALIBRATION_DATA:
  5080. case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA_V2:
  5081. case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
  5082. case VSS_IVOCPROC_CMD_REGISTER_DEVICE_CONFIG:
  5083. case VSS_IVOCPROC_CMD_DEREGISTER_DEVICE_CONFIG:
  5084. #if defined(CONFIG_MACH_S3VE3G_EUR) || defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_EUR_LTE) || defined(CONFIG_MACH_MS01_KOR_LTE) || defined(CONFIG_DSDA_VIA_UART)
  5085. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  5086. #endif
  5087. case VSS_ICOMMON_CMD_MAP_MEMORY:
  5088. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  5089. case VSS_IVOLUME_CMD_MUTE_V2:
  5090. v->cvp_state = CMD_STATUS_SUCCESS;
  5091. wake_up(&v->cvp_wait);
  5092. break;
  5093. case VOICE_CMD_SET_PARAM:
  5094. pr_debug("%s: VOICE_CMD_SET_PARAM\n", __func__);
  5095. rtac_make_voice_callback(RTAC_CVP, ptr,
  5096. data->payload_size);
  5097. if (dha_state) {
  5098. v->cvp_state = CMD_STATUS_SUCCESS;
  5099. wake_up(&v->cvp_wait);
  5100. }
  5101. break;
  5102. case VOICE_CMD_GET_PARAM:
  5103. pr_debug("%s: VOICE_CMD_GET_PARAM\n",
  5104. __func__);
  5105. /* Should only come here if there is an APR */
  5106. /* error or malformed APR packet. Otherwise */
  5107. /* response will be returned as */
  5108. /* VOICE_EVT_GET_PARAM_ACK */
  5109. if (ptr[1] != 0) {
  5110. pr_err("%s: CVP get param error = %d, resuming\n",
  5111. __func__, ptr[1]);
  5112. rtac_make_voice_callback(RTAC_CVP,
  5113. data->payload,
  5114. data->payload_size);
  5115. }
  5116. break;
  5117. #ifdef CONFIG_SEC_DHA_SOL_MAL
  5118. case VSS_ICOMMON_CMD_DHA_SET:
  5119. pr_err("Got ACK from CVP DHA set\n");
  5120. v->cvp_state = CMD_STATUS_SUCCESS;
  5121. wake_up(&v->cvp_wait);
  5122. break;
  5123. #endif /* CONFIG_SEC_DHA_SOL_MAL*/
  5124. default:
  5125. pr_debug("%s: not match cmd = 0x%x\n",
  5126. __func__, ptr[0]);
  5127. break;
  5128. }
  5129. }
  5130. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  5131. pr_debug("%s: VOICE_EVT_GET_PARAM_ACK\n", __func__);
  5132. ptr = data->payload;
  5133. if (ptr[0] != 0) {
  5134. pr_err("%s: VOICE_EVT_GET_PARAM_ACK returned error = 0x%x\n",
  5135. __func__, ptr[0]);
  5136. }
  5137. rtac_make_voice_callback(RTAC_CVP, data->payload,
  5138. data->payload_size);
  5139. }
  5140. return 0;
  5141. }
  5142. static int voice_free_oob_shared_mem(void)
  5143. {
  5144. int rc = 0;
  5145. int cnt = 0;
  5146. int bufcnt = NUM_OF_BUFFERS;
  5147. struct voice_data *v = voice_get_session(
  5148. common.voice[VOC_PATH_FULL].session_id);
  5149. mutex_lock(&common.common_lock);
  5150. if (v == NULL) {
  5151. pr_err("%s: v is NULL\n", __func__);
  5152. rc = -EINVAL;
  5153. goto done;
  5154. }
  5155. rc = msm_audio_ion_free(v->shmem_info.sh_buf.client,
  5156. v->shmem_info.sh_buf.handle);
  5157. v->shmem_info.sh_buf.client = NULL;
  5158. v->shmem_info.sh_buf.handle = NULL;
  5159. if (rc < 0) {
  5160. pr_err("%s: Error:%d freeing memory\n", __func__, rc);
  5161. goto done;
  5162. }
  5163. while (cnt < bufcnt) {
  5164. v->shmem_info.sh_buf.buf[cnt].data = NULL;
  5165. v->shmem_info.sh_buf.buf[cnt].phys = 0;
  5166. cnt++;
  5167. }
  5168. v->shmem_info.sh_buf.client = NULL;
  5169. v->shmem_info.sh_buf.handle = NULL;
  5170. done:
  5171. mutex_unlock(&common.common_lock);
  5172. return rc;
  5173. }
  5174. static int voice_alloc_oob_shared_mem(void)
  5175. {
  5176. int cnt = 0;
  5177. int rc = 0;
  5178. int len;
  5179. void *mem_addr;
  5180. dma_addr_t phys;
  5181. int bufsz = BUFFER_BLOCK_SIZE;
  5182. int bufcnt = NUM_OF_BUFFERS;
  5183. struct voice_data *v = voice_get_session(
  5184. common.voice[VOC_PATH_FULL].session_id);
  5185. mutex_lock(&common.common_lock);
  5186. if (v == NULL) {
  5187. pr_err("%s: v is NULL\n", __func__);
  5188. rc = -EINVAL;
  5189. goto done;
  5190. }
  5191. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.sh_buf.client),
  5192. &(v->shmem_info.sh_buf.handle),
  5193. bufsz*bufcnt,
  5194. (ion_phys_addr_t *)&phys, (size_t *)&len,
  5195. &mem_addr);
  5196. if (rc < 0) {
  5197. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5198. __func__, rc);
  5199. goto done;
  5200. }
  5201. while (cnt < bufcnt) {
  5202. v->shmem_info.sh_buf.buf[cnt].data = mem_addr + (cnt * bufsz);
  5203. v->shmem_info.sh_buf.buf[cnt].phys = phys + (cnt * bufsz);
  5204. v->shmem_info.sh_buf.buf[cnt].size = bufsz;
  5205. cnt++;
  5206. }
  5207. pr_debug("%s buf[0].data:[%p], buf[0].phys:[%p], &buf[0].phys:[%p],\n",
  5208. __func__,
  5209. (void *)v->shmem_info.sh_buf.buf[0].data,
  5210. (void *)v->shmem_info.sh_buf.buf[0].phys,
  5211. (void *)&v->shmem_info.sh_buf.buf[0].phys);
  5212. pr_debug("%s: buf[1].data:[%p], buf[1].phys[%p], &buf[1].phys[%p]\n",
  5213. __func__,
  5214. (void *)v->shmem_info.sh_buf.buf[1].data,
  5215. (void *)v->shmem_info.sh_buf.buf[1].phys,
  5216. (void *)&v->shmem_info.sh_buf.buf[1].phys);
  5217. memset((void *)v->shmem_info.sh_buf.buf[0].data, 0, (bufsz * bufcnt));
  5218. done:
  5219. mutex_unlock(&common.common_lock);
  5220. return rc;
  5221. }
  5222. static int voice_alloc_oob_mem_table(void)
  5223. {
  5224. int rc = 0;
  5225. int len;
  5226. struct voice_data *v = voice_get_session(
  5227. common.voice[VOC_PATH_FULL].session_id);
  5228. mutex_lock(&common.common_lock);
  5229. if (v == NULL) {
  5230. pr_err("%s: v is NULL\n", __func__);
  5231. rc = -EINVAL;
  5232. goto done;
  5233. }
  5234. rc = msm_audio_ion_alloc("voip_client", &(v->shmem_info.memtbl.client),
  5235. &(v->shmem_info.memtbl.handle),
  5236. sizeof(struct vss_imemory_table_t),
  5237. (ion_phys_addr_t *)&v->shmem_info.memtbl.phys,
  5238. (size_t *)&len,
  5239. &(v->shmem_info.memtbl.data));
  5240. if (rc < 0) {
  5241. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5242. __func__, rc);
  5243. goto done;
  5244. }
  5245. v->shmem_info.memtbl.size = sizeof(struct vss_imemory_table_t);
  5246. pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
  5247. (void *)v->shmem_info.memtbl.data,
  5248. (void *)v->shmem_info.memtbl.phys,
  5249. (void *)&v->shmem_info.memtbl.phys);
  5250. done:
  5251. mutex_unlock(&common.common_lock);
  5252. return rc;
  5253. }
  5254. static int voice_alloc_cal_mem_map_table(void)
  5255. {
  5256. int ret = 0;
  5257. int len;
  5258. ret = msm_audio_ion_alloc("voc_cal",
  5259. &(common.cal_mem_map_table.client),
  5260. &(common.cal_mem_map_table.handle),
  5261. sizeof(struct vss_imemory_table_t),
  5262. (ion_phys_addr_t *)&common.cal_mem_map_table.phys,
  5263. (size_t *) &len,
  5264. &(common.cal_mem_map_table.data));
  5265. if (ret < 0) {
  5266. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5267. __func__, ret);
  5268. goto done;
  5269. }
  5270. common.cal_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  5271. pr_debug("%s: data 0x%x phys 0x%x\n", __func__,
  5272. (unsigned int) common.cal_mem_map_table.data,
  5273. common.cal_mem_map_table.phys);
  5274. done:
  5275. return ret;
  5276. }
  5277. static int voice_alloc_rtac_mem_map_table(void)
  5278. {
  5279. int ret = 0;
  5280. int len;
  5281. ret = msm_audio_ion_alloc("voc_rtac_cal",
  5282. &(common.rtac_mem_map_table.client),
  5283. &(common.rtac_mem_map_table.handle),
  5284. sizeof(struct vss_imemory_table_t),
  5285. (ion_phys_addr_t *)&common.rtac_mem_map_table.phys,
  5286. (size_t *) &len,
  5287. &(common.rtac_mem_map_table.data));
  5288. if (ret < 0) {
  5289. pr_err("%s: audio ION alloc failed, rc = %d\n",
  5290. __func__, ret);
  5291. goto done;
  5292. }
  5293. common.rtac_mem_map_table.size = sizeof(struct vss_imemory_table_t);
  5294. pr_debug("%s: data 0x%x phys 0x%x\n", __func__,
  5295. (unsigned int) common.rtac_mem_map_table.data,
  5296. common.rtac_mem_map_table.phys);
  5297. done:
  5298. return ret;
  5299. }
  5300. static int voice_alloc_and_map_cal_mem(struct voice_data *v)
  5301. {
  5302. int ret = 0;
  5303. if (v == NULL) {
  5304. pr_err("%s: v is NULL\n", __func__);
  5305. return -EINVAL;
  5306. }
  5307. ret = voc_alloc_cal_shared_memory();
  5308. if (ret < 0) {
  5309. pr_err("%s: Memory allocation of cal block failed %d\n",
  5310. __func__, ret);
  5311. goto done;
  5312. }
  5313. /* Memory map the calibration memory block. */
  5314. ret = voice_mem_map_cal_block(v);
  5315. if (ret < 0) {
  5316. pr_err("%s: Memory map of cal block failed %d\n",
  5317. __func__, ret);
  5318. }
  5319. done:
  5320. return ret;
  5321. }
  5322. static int voice_alloc_and_map_oob_mem(struct voice_data *v)
  5323. {
  5324. int ret = 0;
  5325. if (v == NULL) {
  5326. pr_err("%s: v is NULL\n", __func__);
  5327. return -EINVAL;
  5328. }
  5329. if (!is_voip_memory_allocated()) {
  5330. ret = voc_alloc_voip_shared_memory();
  5331. if (ret < 0) {
  5332. pr_err("%s: Failed to create voip oob memory %d\n",
  5333. __func__, ret);
  5334. goto done;
  5335. }
  5336. }
  5337. ret = voice_map_memory_physical_cmd(v,
  5338. &v->shmem_info.memtbl,
  5339. v->shmem_info.sh_buf.buf[0].phys,
  5340. v->shmem_info.sh_buf.buf[0].size * NUM_OF_BUFFERS,
  5341. VOIP_MEM_MAP_TOKEN);
  5342. if (ret) {
  5343. pr_err("%s: mvm_map_memory_phy failed %d\n",
  5344. __func__, ret);
  5345. goto done;
  5346. }
  5347. done:
  5348. return ret;
  5349. }
  5350. int is_voc_initialized(void)
  5351. {
  5352. return module_initialized;
  5353. }
  5354. static int __init voice_init(void)
  5355. {
  5356. int rc = 0, i = 0;
  5357. memset(&common, 0, sizeof(struct common_data));
  5358. /* set default value */
  5359. common.default_mute_val = 0; /* default is un-mute */
  5360. common.default_sample_val = 8000;
  5361. common.default_vol_step_val = 0;
  5362. common.default_vol_ramp_duration_ms = DEFAULT_VOLUME_RAMP_DURATION;
  5363. common.default_mute_ramp_duration_ms = DEFAULT_MUTE_RAMP_DURATION;
  5364. common.ec_ref_ext = false;
  5365. /* Initialize MVS info. */
  5366. common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
  5367. mutex_init(&common.common_lock);
  5368. /* Initialize session id with vsid */
  5369. init_session_id();
  5370. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  5371. /* initialize dev_rx and dev_tx */
  5372. common.voice[i].dev_rx.dev_mute = common.default_mute_val;
  5373. common.voice[i].dev_tx.dev_mute = common.default_mute_val;
  5374. common.voice[i].dev_rx.volume_step_value =
  5375. common.default_vol_step_val;
  5376. common.voice[i].dev_rx.volume_ramp_duration_ms =
  5377. common.default_vol_ramp_duration_ms;
  5378. common.voice[i].dev_rx.dev_mute_ramp_duration_ms =
  5379. common.default_mute_ramp_duration_ms;
  5380. common.voice[i].dev_tx.dev_mute_ramp_duration_ms =
  5381. common.default_mute_ramp_duration_ms;
  5382. common.voice[i].stream_rx.stream_mute = common.default_mute_val;
  5383. common.voice[i].stream_tx.stream_mute = common.default_mute_val;
  5384. common.voice[i].dev_tx.port_id = 0x100B;
  5385. common.voice[i].dev_rx.port_id = 0x100A;
  5386. common.voice[i].sidetone_gain = 0x512;
  5387. common.voice[i].dtmf_rx_detect_en = 0;
  5388. common.voice[i].lch_mode = 0;
  5389. common.voice[i].voc_state = VOC_INIT;
  5390. init_waitqueue_head(&common.voice[i].mvm_wait);
  5391. init_waitqueue_head(&common.voice[i].cvs_wait);
  5392. init_waitqueue_head(&common.voice[i].cvp_wait);
  5393. mutex_init(&common.voice[i].lock);
  5394. }
  5395. if (rc == 0)
  5396. module_initialized = true;
  5397. pr_debug("%s: rc=%d\n", __func__, rc);
  5398. return rc;
  5399. }
  5400. device_initcall(voice_init);