q6voice.c 245 KB

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