q6adm.c 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/wait.h>
  8. #include <linux/sched.h>
  9. #include <linux/jiffies.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/atomic.h>
  12. #include <dsp/msm-dts-srs-tm-config.h>
  13. #include <dsp/apr_audio-v2.h>
  14. #include <dsp/q6adm-v2.h>
  15. #include <dsp/q6audio-v2.h>
  16. #include <dsp/q6afe-v2.h>
  17. #include <dsp/q6core.h>
  18. #include <dsp/audio_cal_utils.h>
  19. #include <dsp/q6common.h>
  20. #include <ipc/apr.h>
  21. #include "adsp_err.h"
  22. #include <soc/qcom/secure_buffer.h>
  23. #define TIMEOUT_MS 1000
  24. #define RESET_COPP_ID 99
  25. #define INVALID_COPP_ID 0xFF
  26. /* Used for inband payload copy, max size is 4k */
  27. /* 3 is to account for module, instance & param ID in payload */
  28. #define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 3 * sizeof(uint32_t))
  29. #define ULL_SUPPORTED_BITS_PER_SAMPLE 16
  30. #define ULL_SUPPORTED_SAMPLE_RATE 48000
  31. #ifndef CONFIG_DOLBY_DAP
  32. #undef DOLBY_ADM_COPP_TOPOLOGY_ID
  33. #define DOLBY_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFE
  34. #endif
  35. #ifndef CONFIG_DOLBY_DS2
  36. #undef DS2_ADM_COPP_TOPOLOGY_ID
  37. #define DS2_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFF
  38. #endif
  39. #define SESSION_TYPE_RX 0
  40. /* ENUM for adm_status */
  41. enum adm_cal_status {
  42. ADM_STATUS_CALIBRATION_REQUIRED = 0,
  43. ADM_STATUS_MAX,
  44. };
  45. struct adm_copp {
  46. atomic_t id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  47. atomic_t cnt[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  48. atomic_t topology[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  49. atomic_t mode[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  50. atomic_t stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  51. atomic_t rate[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  52. atomic_t bit_width[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  53. atomic_t channels[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  54. atomic_t app_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  55. atomic_t acdb_id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  56. atomic_t session_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  57. wait_queue_head_t wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  58. wait_queue_head_t adm_delay_wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  59. atomic_t adm_delay_stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  60. uint32_t adm_delay[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  61. unsigned long adm_status[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  62. atomic_t token[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
  63. };
  64. struct source_tracking_data {
  65. struct dma_buf *dma_buf;
  66. struct param_outband memmap;
  67. int apr_cmd_status;
  68. };
  69. struct adm_ctl {
  70. void *apr;
  71. struct adm_copp copp;
  72. atomic_t matrix_map_stat;
  73. wait_queue_head_t matrix_map_wait;
  74. atomic_t adm_stat;
  75. wait_queue_head_t adm_wait;
  76. struct cal_type_data *cal_data[ADM_MAX_CAL_TYPES];
  77. atomic_t mem_map_handles[ADM_MEM_MAP_INDEX_MAX];
  78. atomic_t mem_map_index;
  79. struct param_outband outband_memmap;
  80. struct source_tracking_data sourceTrackingData;
  81. int set_custom_topology;
  82. int ec_ref_rx;
  83. int num_ec_ref_rx_chans;
  84. int ec_ref_rx_bit_width;
  85. int ec_ref_rx_sampling_rate;
  86. int num_ec_ref_rx_chans_downmixed;
  87. uint16_t ec_ref_chmixer_weights[PCM_FORMAT_MAX_NUM_CHANNEL_V8]
  88. [PCM_FORMAT_MAX_NUM_CHANNEL_V8];
  89. int ffecns_port_id;
  90. int native_mode;
  91. uint32_t copp_token;
  92. int tx_port_id;
  93. bool hyp_assigned;
  94. };
  95. static struct adm_ctl this_adm;
  96. struct adm_multi_ch_map {
  97. bool set_channel_map;
  98. char channel_mapping[PCM_FORMAT_MAX_NUM_CHANNEL_V8];
  99. };
  100. #define ADM_MCH_MAP_IDX_PLAYBACK 0
  101. #define ADM_MCH_MAP_IDX_REC 1
  102. static struct adm_multi_ch_map multi_ch_maps[2] = {
  103. { false,
  104. {0, 0, 0, 0, 0, 0, 0, 0,
  105. 0, 0, 0, 0, 0, 0, 0, 0,
  106. 0, 0, 0, 0, 0, 0, 0, 0,
  107. 0, 0, 0, 0, 0, 0, 0, 0}
  108. },
  109. { false,
  110. {0, 0, 0, 0, 0, 0, 0, 0,
  111. 0, 0, 0, 0, 0, 0, 0, 0,
  112. 0, 0, 0, 0, 0, 0, 0, 0,
  113. 0, 0, 0, 0, 0, 0, 0, 0}
  114. }
  115. };
  116. static struct adm_multi_ch_map port_channel_map[AFE_MAX_PORTS];
  117. static int adm_get_parameters[MAX_COPPS_PER_PORT * ADM_GET_PARAMETER_LENGTH];
  118. static int adm_module_topo_list[MAX_COPPS_PER_PORT *
  119. ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH];
  120. static struct mutex dts_srs_lock;
  121. void msm_dts_srs_acquire_lock(void)
  122. {
  123. mutex_lock(&dts_srs_lock);
  124. }
  125. void msm_dts_srs_release_lock(void)
  126. {
  127. mutex_unlock(&dts_srs_lock);
  128. }
  129. static int adm_arrange_mch_map_v8(
  130. struct adm_device_endpoint_payload *ep_payload,
  131. int path,
  132. int channel_mode,
  133. int port_idx);
  134. /**
  135. * adm_validate_and_get_port_index -
  136. * validate given port id
  137. *
  138. * @port_id: Port ID number
  139. *
  140. * Returns valid index on success or error on failure
  141. */
  142. int adm_validate_and_get_port_index(int port_id)
  143. {
  144. int index;
  145. int ret;
  146. ret = q6audio_validate_port(port_id);
  147. if (ret < 0) {
  148. pr_err("%s: port validation failed id 0x%x ret %d\n",
  149. __func__, port_id, ret);
  150. return -EINVAL;
  151. }
  152. index = afe_get_port_index(port_id);
  153. if (index < 0 || index >= AFE_MAX_PORTS) {
  154. pr_err("%s: Invalid port idx %d port_id 0x%x\n",
  155. __func__, index,
  156. port_id);
  157. return -EINVAL;
  158. }
  159. pr_debug("%s: port_idx- %d\n", __func__, index);
  160. return index;
  161. }
  162. EXPORT_SYMBOL(adm_validate_and_get_port_index);
  163. /**
  164. * adm_get_default_copp_idx -
  165. * retrieve default copp_idx for given port
  166. *
  167. * @port_id: Port ID number
  168. *
  169. * Returns valid value on success or error on failure
  170. */
  171. int adm_get_default_copp_idx(int port_id)
  172. {
  173. int port_idx = adm_validate_and_get_port_index(port_id), idx;
  174. if (port_idx < 0) {
  175. pr_err("%s: Invalid port id: 0x%x", __func__, port_id);
  176. return -EINVAL;
  177. }
  178. pr_debug("%s: port_idx:%d\n", __func__, port_idx);
  179. for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) {
  180. if (atomic_read(&this_adm.copp.id[port_idx][idx]) !=
  181. RESET_COPP_ID)
  182. return idx;
  183. }
  184. return -EINVAL;
  185. }
  186. EXPORT_SYMBOL(adm_get_default_copp_idx);
  187. int adm_get_topology_for_port_from_copp_id(int port_id, int copp_id)
  188. {
  189. int port_idx = adm_validate_and_get_port_index(port_id), idx;
  190. if (port_idx < 0) {
  191. pr_err("%s: Invalid port id: 0x%x", __func__, port_id);
  192. return 0;
  193. }
  194. for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++)
  195. if (atomic_read(&this_adm.copp.id[port_idx][idx]) == copp_id)
  196. return atomic_read(&this_adm.copp.topology[port_idx]
  197. [idx]);
  198. pr_err("%s: Invalid copp_id %d port_id 0x%x\n",
  199. __func__, copp_id, port_id);
  200. return 0;
  201. }
  202. /**
  203. * adm_get_topology_for_port_copp_idx -
  204. * retrieve topology of given port/copp_idx
  205. *
  206. * @port_id: Port ID number
  207. * @copp_idx: copp index of ADM copp
  208. *
  209. * Returns valid value on success or 0 on failure
  210. */
  211. int adm_get_topology_for_port_copp_idx(int port_id, int copp_idx)
  212. {
  213. int port_idx = adm_validate_and_get_port_index(port_id);
  214. if (port_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  215. pr_err("%s: Invalid port: 0x%x copp id: 0x%x",
  216. __func__, port_id, copp_idx);
  217. return 0;
  218. }
  219. return atomic_read(&this_adm.copp.topology[port_idx][copp_idx]);
  220. }
  221. EXPORT_SYMBOL(adm_get_topology_for_port_copp_idx);
  222. int adm_get_indexes_from_copp_id(int copp_id, int *copp_idx, int *port_idx)
  223. {
  224. int p_idx, c_idx;
  225. for (p_idx = 0; p_idx < AFE_MAX_PORTS; p_idx++) {
  226. for (c_idx = 0; c_idx < MAX_COPPS_PER_PORT; c_idx++) {
  227. if (atomic_read(&this_adm.copp.id[p_idx][c_idx])
  228. == copp_id) {
  229. if (copp_idx != NULL)
  230. *copp_idx = c_idx;
  231. if (port_idx != NULL)
  232. *port_idx = p_idx;
  233. return 0;
  234. }
  235. }
  236. }
  237. return -EINVAL;
  238. }
  239. static int adm_get_copp_id(int port_idx, int copp_idx)
  240. {
  241. pr_debug("%s: port_idx:%d copp_idx:%d\n", __func__, port_idx, copp_idx);
  242. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  243. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  244. return -EINVAL;
  245. }
  246. return atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  247. }
  248. static int adm_get_idx_if_single_copp_exists(int port_idx,
  249. int topology, int mode,
  250. int rate, int bit_width,
  251. uint32_t copp_token)
  252. {
  253. int idx;
  254. pr_debug("%s: copp_token %d\n", __func__, copp_token);
  255. for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++)
  256. if ((topology ==
  257. atomic_read(&this_adm.copp.topology[port_idx][idx])) &&
  258. (mode ==
  259. atomic_read(&this_adm.copp.mode[port_idx][idx])) &&
  260. (rate ==
  261. atomic_read(&this_adm.copp.rate[port_idx][idx])) &&
  262. (bit_width ==
  263. atomic_read(&this_adm.copp.bit_width[port_idx][idx])) &&
  264. (copp_token ==
  265. atomic_read(&this_adm.copp.token[port_idx][idx])))
  266. return idx;
  267. return -EINVAL;
  268. }
  269. static int adm_get_idx_if_copp_exists(int port_idx, int topology, int mode,
  270. int rate, int bit_width, int app_type,
  271. int session_type, uint32_t copp_token)
  272. {
  273. int idx;
  274. pr_debug("%s: port_idx-%d, topology-0x%x, mode-%d, rate-%d, bit_width-%d\n",
  275. __func__, port_idx, topology, mode, rate, bit_width);
  276. if (copp_token)
  277. return adm_get_idx_if_single_copp_exists(port_idx,
  278. topology, mode,
  279. rate, bit_width,
  280. copp_token);
  281. for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++)
  282. if ((topology ==
  283. atomic_read(&this_adm.copp.topology[port_idx][idx])) &&
  284. (mode == atomic_read(&this_adm.copp.mode[port_idx][idx])) &&
  285. (rate == atomic_read(&this_adm.copp.rate[port_idx][idx])) &&
  286. (bit_width ==
  287. atomic_read(&this_adm.copp.bit_width[port_idx][idx])) &&
  288. (session_type ==
  289. atomic_read(
  290. &this_adm.copp.session_type[port_idx][idx])) &&
  291. (app_type ==
  292. atomic_read(&this_adm.copp.app_type[port_idx][idx])))
  293. return idx;
  294. return -EINVAL;
  295. }
  296. static int adm_get_next_available_copp(int port_idx)
  297. {
  298. int idx;
  299. pr_debug("%s:\n", __func__);
  300. for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) {
  301. pr_debug("%s: copp_id:0x%x port_idx:%d idx:%d\n", __func__,
  302. atomic_read(&this_adm.copp.id[port_idx][idx]),
  303. port_idx, idx);
  304. if (atomic_read(&this_adm.copp.id[port_idx][idx]) ==
  305. RESET_COPP_ID)
  306. break;
  307. }
  308. return idx;
  309. }
  310. /**
  311. * srs_trumedia_open -
  312. * command to set SRS trumedia open
  313. *
  314. * @port_id: Port ID number
  315. * @copp_idx: copp index of ADM copp
  316. * @srs_tech_id: SRS tech index
  317. * @srs_params: params pointer
  318. *
  319. * Returns 0 on success or error on failure
  320. */
  321. int srs_trumedia_open(int port_id, int copp_idx, __s32 srs_tech_id,
  322. void *srs_params)
  323. {
  324. struct param_hdr_v3 param_hdr;
  325. struct mem_mapping_hdr mem_hdr;
  326. u32 total_param_size = 0;
  327. bool outband = false;
  328. int port_idx;
  329. int ret = 0;
  330. pr_debug("SRS - %s", __func__);
  331. memset(&param_hdr, 0, sizeof(param_hdr));
  332. memset(&mem_hdr, 0, sizeof(mem_hdr));
  333. port_id = afe_convert_virtual_to_portid(port_id);
  334. port_idx = adm_validate_and_get_port_index(port_id);
  335. if (port_idx < 0) {
  336. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  337. return -EINVAL;
  338. }
  339. param_hdr.module_id = SRS_TRUMEDIA_MODULE_ID;
  340. param_hdr.instance_id = INSTANCE_ID_0;
  341. switch (srs_tech_id) {
  342. case SRS_ID_GLOBAL: {
  343. param_hdr.param_id = SRS_TRUMEDIA_PARAMS;
  344. param_hdr.param_size =
  345. sizeof(struct srs_trumedia_params_GLOBAL);
  346. break;
  347. }
  348. case SRS_ID_WOWHD: {
  349. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_WOWHD;
  350. param_hdr.param_size = sizeof(struct srs_trumedia_params_WOWHD);
  351. break;
  352. }
  353. case SRS_ID_CSHP: {
  354. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_CSHP;
  355. param_hdr.param_size = sizeof(struct srs_trumedia_params_CSHP);
  356. break;
  357. }
  358. case SRS_ID_HPF: {
  359. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HPF;
  360. param_hdr.param_size = sizeof(struct srs_trumedia_params_HPF);
  361. break;
  362. }
  363. case SRS_ID_AEQ: {
  364. u8 *update_params_ptr = (u8 *) this_adm.outband_memmap.kvaddr;
  365. outband = true;
  366. if (update_params_ptr == NULL) {
  367. pr_err("ADM_SRS_TRUMEDIA - %s: null memmap for AEQ params\n",
  368. __func__);
  369. ret = -EINVAL;
  370. goto fail_cmd;
  371. }
  372. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_AEQ;
  373. param_hdr.param_size = sizeof(struct srs_trumedia_params_AEQ);
  374. ret = q6common_pack_pp_params(update_params_ptr, &param_hdr,
  375. srs_params, &total_param_size);
  376. if (ret) {
  377. pr_err("%s: Failed to pack param header and data, error %d\n",
  378. __func__, ret);
  379. goto fail_cmd;
  380. }
  381. break;
  382. }
  383. case SRS_ID_HL: {
  384. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HL;
  385. param_hdr.param_size = sizeof(struct srs_trumedia_params_HL);
  386. break;
  387. }
  388. case SRS_ID_GEQ: {
  389. param_hdr.param_id = SRS_TRUMEDIA_PARAMS_GEQ;
  390. param_hdr.param_size = sizeof(struct srs_trumedia_params_GEQ);
  391. break;
  392. }
  393. default:
  394. goto fail_cmd;
  395. }
  396. if (outband && this_adm.outband_memmap.paddr) {
  397. mem_hdr.data_payload_addr_lsw =
  398. lower_32_bits(this_adm.outband_memmap.paddr);
  399. mem_hdr.data_payload_addr_msw =
  400. msm_audio_populate_upper_32_bits(
  401. this_adm.outband_memmap.paddr);
  402. mem_hdr.mem_map_handle = atomic_read(
  403. &this_adm.mem_map_handles[ADM_SRS_TRUMEDIA]);
  404. ret = adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL,
  405. total_param_size);
  406. } else {
  407. ret = adm_pack_and_set_one_pp_param(port_id, copp_idx,
  408. param_hdr,
  409. (u8 *) srs_params);
  410. }
  411. if (ret < 0)
  412. pr_err("SRS - %s: ADM enable for port %d failed\n", __func__,
  413. port_id);
  414. fail_cmd:
  415. return ret;
  416. }
  417. EXPORT_SYMBOL(srs_trumedia_open);
  418. static int adm_populate_channel_weight(u16 *ptr,
  419. struct msm_pcm_channel_mixer *ch_mixer,
  420. int channel_index)
  421. {
  422. u16 i, j, start_index = 0;
  423. if (channel_index > ch_mixer->output_channel) {
  424. pr_err("%s: channel index %d is larger than output_channel %d\n",
  425. __func__, channel_index, ch_mixer->output_channel);
  426. return -EINVAL;
  427. }
  428. for (i = 0; i < ch_mixer->output_channel; i++) {
  429. pr_debug("%s: weight for output %d:", __func__, i);
  430. for (j = 0; j < ADM_MAX_CHANNELS; j++)
  431. pr_debug(" %d",
  432. ch_mixer->channel_weight[i][j]);
  433. pr_debug("\n");
  434. }
  435. for (i = 0; i < channel_index; ++i)
  436. start_index += ch_mixer->input_channels[i];
  437. for (i = 0; i < ch_mixer->output_channel; ++i) {
  438. for (j = start_index;
  439. j < start_index +
  440. ch_mixer->input_channels[channel_index]; j++) {
  441. *ptr = ch_mixer->channel_weight[i][j];
  442. pr_debug("%s: ptr[%d][%d] = %d\n",
  443. __func__, i, j, *ptr);
  444. ptr++;
  445. }
  446. }
  447. return 0;
  448. }
  449. /*
  450. * adm_programable_channel_mixer
  451. *
  452. * Receives port_id, copp_idx, session_id, session_type, ch_mixer
  453. * and channel_index to send ADM command to mix COPP data.
  454. *
  455. * port_id - Passed value, port_id for which backend is wanted
  456. * copp_idx - Passed value, copp_idx for which COPP is wanted
  457. * session_id - Passed value, session_id for which session is needed
  458. * session_type - Passed value, session_type for RX or TX
  459. * ch_mixer - Passed value, ch_mixer for which channel mixer config is needed
  460. * channel_index - Passed value, channel_index for which channel is needed
  461. */
  462. int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id,
  463. int session_type,
  464. struct msm_pcm_channel_mixer *ch_mixer,
  465. int channel_index)
  466. {
  467. struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL;
  468. struct param_hdr_v1 data_v5;
  469. int ret = 0, port_idx, sz = 0, param_size = 0;
  470. struct adm_device_endpoint_payload ep_params = {0, 0, 0, {0}};
  471. u16 *adm_pspd_params;
  472. u16 *ptr;
  473. int index = 0, i = 0, path_type = ADM_PATH_PLAYBACK;
  474. pr_debug("%s: port_id = %d\n", __func__, port_id);
  475. port_id = afe_convert_virtual_to_portid(port_id);
  476. port_idx = adm_validate_and_get_port_index(port_id);
  477. if (port_idx < 0) {
  478. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  479. return -EINVAL;
  480. }
  481. /*
  482. * check if PSPD is already configured
  483. * if it is configured already, return 0 without applying PSPD.
  484. */
  485. if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) > 1) {
  486. pr_debug("%s: copp.cnt:%#x\n", __func__,
  487. atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]));
  488. return 0;
  489. }
  490. /*
  491. * First 8 bytes are 4 bytes as rule number, 2 bytes as output
  492. * channel and 2 bytes as input channel.
  493. * 2 * ch_mixer->output_channel means output channel mapping.
  494. * 2 * ch_mixer->input_channels[channel_index]) means input
  495. * channel mapping.
  496. * 2 * ch_mixer->input_channels[channel_index] *
  497. * ch_mixer->output_channel) means the channel mixer weighting
  498. * coefficients.
  499. * param_size needs to be a multiple of 4 bytes.
  500. */
  501. param_size = 2 * (4 + ch_mixer->output_channel +
  502. ch_mixer->input_channels[channel_index] +
  503. ch_mixer->input_channels[channel_index] *
  504. ch_mixer->output_channel);
  505. param_size = roundup(param_size, 4);
  506. sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) +
  507. sizeof(struct default_chmixer_param_id_coeff) +
  508. sizeof(struct param_hdr_v1) + param_size;
  509. pr_debug("%s: sz = %d\n", __func__, sz);
  510. adm_params = kzalloc(sz, GFP_KERNEL);
  511. if (!adm_params)
  512. return -ENOMEM;
  513. adm_params->payload_addr_lsw = 0;
  514. adm_params->payload_addr_msw = 0;
  515. adm_params->mem_map_handle = 0;
  516. adm_params->direction = session_type;
  517. adm_params->sessionid = session_id;
  518. pr_debug("%s: copp_id = %d, session id %d\n", __func__,
  519. atomic_read(&this_adm.copp.id[port_idx][copp_idx]),
  520. session_id);
  521. adm_params->deviceid = atomic_read(
  522. &this_adm.copp.id[port_idx][copp_idx]);
  523. adm_params->reserved = 0;
  524. /*
  525. * This module is internal to ADSP and cannot be configured with
  526. * an instance id
  527. */
  528. data_v5.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER;
  529. data_v5.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF;
  530. data_v5.reserved = 0;
  531. data_v5.param_size = param_size;
  532. adm_params->payload_size =
  533. sizeof(struct default_chmixer_param_id_coeff) +
  534. sizeof(struct param_hdr_v1) + data_v5.param_size;
  535. adm_pspd_params = (u16 *)((u8 *)adm_params +
  536. sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5));
  537. memcpy(adm_pspd_params, &data_v5, sizeof(data_v5));
  538. adm_pspd_params = (u16 *)((u8 *)adm_params +
  539. sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)
  540. + sizeof(data_v5));
  541. adm_pspd_params[0] = ch_mixer->rule;
  542. adm_pspd_params[2] = ch_mixer->output_channel;
  543. adm_pspd_params[3] = ch_mixer->input_channels[channel_index];
  544. index = 4;
  545. path_type = (session_type == SESSION_TYPE_RX) ?
  546. ADM_PATH_PLAYBACK : ADM_PATH_LIVE_REC;
  547. if (ch_mixer->override_out_ch_map) {
  548. memcpy(&adm_pspd_params[index], &ch_mixer->out_ch_map,
  549. ch_mixer->output_channel * sizeof(uint16_t));
  550. index += ch_mixer->output_channel;
  551. } else {
  552. ep_params.dev_num_channel = ch_mixer->output_channel;
  553. adm_arrange_mch_map_v8(&ep_params, path_type,
  554. ep_params.dev_num_channel, port_idx);
  555. for (i = 0; i < ch_mixer->output_channel; i++)
  556. adm_pspd_params[index++] = ep_params.dev_channel_mapping[i];
  557. }
  558. if (ch_mixer->override_in_ch_map) {
  559. memcpy(&adm_pspd_params[index], &ch_mixer->in_ch_map,
  560. ch_mixer->input_channel * sizeof(uint16_t));
  561. index += ch_mixer->input_channel;
  562. } else {
  563. ep_params.dev_num_channel = ch_mixer->input_channels[channel_index];
  564. adm_arrange_mch_map_v8(&ep_params, path_type,
  565. ep_params.dev_num_channel, port_idx);
  566. for (i = 0; i < ch_mixer->input_channels[channel_index]; i++)
  567. adm_pspd_params[index++] = ep_params.dev_channel_mapping[i];
  568. }
  569. ret = adm_populate_channel_weight(&adm_pspd_params[index],
  570. ch_mixer, channel_index);
  571. if (ret) {
  572. pr_err("%s: fail to get channel weight with error %d\n",
  573. __func__, ret);
  574. goto fail_cmd;
  575. }
  576. adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  577. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  578. adm_params->hdr.src_svc = APR_SVC_ADM;
  579. adm_params->hdr.src_domain = APR_DOMAIN_APPS;
  580. adm_params->hdr.src_port = port_id;
  581. adm_params->hdr.dest_svc = APR_SVC_ADM;
  582. adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
  583. adm_params->hdr.dest_port =
  584. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  585. adm_params->hdr.token = port_idx << 16 | copp_idx;
  586. adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5;
  587. adm_params->hdr.pkt_size = sz;
  588. adm_params->payload_addr_lsw = 0;
  589. adm_params->payload_addr_msw = 0;
  590. adm_params->mem_map_handle = 0;
  591. adm_params->reserved = 0;
  592. ptr = (u16 *)adm_params;
  593. for (index = 0; index < (sz / 2); index++)
  594. pr_debug("%s: adm_params[%d] = 0x%x\n",
  595. __func__, index, (unsigned int)ptr[index]);
  596. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], 0);
  597. ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
  598. if (ret < 0) {
  599. pr_err("%s: Set params failed port %d rc %d\n", __func__,
  600. port_id, ret);
  601. ret = -EINVAL;
  602. goto fail_cmd;
  603. }
  604. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  605. atomic_read(
  606. &this_adm.copp.stat[port_idx][copp_idx]) >= 0,
  607. msecs_to_jiffies(TIMEOUT_MS));
  608. if (!ret) {
  609. pr_err("%s: set params timed out port = %d\n",
  610. __func__, port_id);
  611. ret = -ETIMEDOUT;
  612. goto fail_cmd;
  613. }
  614. ret = 0;
  615. fail_cmd:
  616. kfree(adm_params);
  617. return ret;
  618. }
  619. EXPORT_SYMBOL(adm_programable_channel_mixer);
  620. /**
  621. * adm_set_stereo_to_custom_stereo -
  622. * command to update custom stereo
  623. *
  624. * @port_id: Port ID number
  625. * @copp_idx: copp index of ADM copp
  626. * @session_id: session id to be updated
  627. * @params: params pointer
  628. * @param_length: length of params
  629. *
  630. * Returns 0 on success or error on failure
  631. */
  632. int adm_set_stereo_to_custom_stereo(int port_id, int copp_idx,
  633. unsigned int session_id, char *params,
  634. uint32_t params_length)
  635. {
  636. struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL;
  637. int sz, rc = 0, port_idx;
  638. pr_debug("%s:\n", __func__);
  639. port_id = afe_convert_virtual_to_portid(port_id);
  640. port_idx = adm_validate_and_get_port_index(port_id);
  641. if (port_idx < 0) {
  642. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  643. return -EINVAL;
  644. }
  645. sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) +
  646. params_length;
  647. adm_params = kzalloc(sz, GFP_KERNEL);
  648. if (!adm_params) {
  649. pr_err("%s, adm params memory alloc failed\n", __func__);
  650. return -ENOMEM;
  651. }
  652. memcpy(((u8 *)adm_params +
  653. sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)),
  654. params, params_length);
  655. adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  656. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  657. adm_params->hdr.pkt_size = sz;
  658. adm_params->hdr.src_svc = APR_SVC_ADM;
  659. adm_params->hdr.src_domain = APR_DOMAIN_APPS;
  660. adm_params->hdr.src_port = port_id;
  661. adm_params->hdr.dest_svc = APR_SVC_ADM;
  662. adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
  663. adm_params->hdr.dest_port = 0; /* Ignored */;
  664. adm_params->hdr.token = port_idx << 16 | copp_idx;
  665. adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5;
  666. adm_params->payload_addr_lsw = 0;
  667. adm_params->payload_addr_msw = 0;
  668. adm_params->mem_map_handle = 0;
  669. adm_params->payload_size = params_length;
  670. /* direction RX as 0 */
  671. adm_params->direction = ADM_MATRIX_ID_AUDIO_RX;
  672. /* session id for this cmd to be applied on */
  673. adm_params->sessionid = session_id;
  674. adm_params->deviceid =
  675. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  676. adm_params->reserved = 0;
  677. pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n",
  678. __func__, adm_params->deviceid, adm_params->sessionid,
  679. adm_params->hdr.src_port, adm_params->hdr.dest_port);
  680. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  681. rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
  682. if (rc < 0) {
  683. pr_err("%s: Set params failed port = 0x%x rc %d\n",
  684. __func__, port_id, rc);
  685. rc = -EINVAL;
  686. goto set_stereo_to_custom_stereo_return;
  687. }
  688. /* Wait for the callback */
  689. rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  690. atomic_read(&this_adm.copp.stat
  691. [port_idx][copp_idx]) >= 0,
  692. msecs_to_jiffies(TIMEOUT_MS));
  693. if (!rc) {
  694. pr_err("%s: Set params timed out port = 0x%x\n", __func__,
  695. port_id);
  696. rc = -EINVAL;
  697. goto set_stereo_to_custom_stereo_return;
  698. } else if (atomic_read(&this_adm.copp.stat
  699. [port_idx][copp_idx]) > 0) {
  700. pr_err("%s: DSP returned error[%s]\n", __func__,
  701. adsp_err_get_err_str(atomic_read(
  702. &this_adm.copp.stat
  703. [port_idx][copp_idx])));
  704. rc = adsp_err_get_lnx_err_code(
  705. atomic_read(&this_adm.copp.stat
  706. [port_idx][copp_idx]));
  707. goto set_stereo_to_custom_stereo_return;
  708. }
  709. rc = 0;
  710. set_stereo_to_custom_stereo_return:
  711. kfree(adm_params);
  712. return rc;
  713. }
  714. EXPORT_SYMBOL(adm_set_stereo_to_custom_stereo);
  715. /*
  716. * adm_set_custom_chmix_cfg:
  717. * Set the custom channel mixer configuration for ADM
  718. *
  719. * @port_id: Backend port id
  720. * @copp_idx: ADM copp index
  721. * @session_id: ID of the requesting session
  722. * @params: Expected packaged params for channel mixer
  723. * @params_length: Length of the params to be set
  724. * @direction: RX or TX direction
  725. * @stream_type: Audio or Listen stream type
  726. */
  727. int adm_set_custom_chmix_cfg(int port_id, int copp_idx,
  728. unsigned int session_id, char *params,
  729. uint32_t params_length, int direction,
  730. int stream_type)
  731. {
  732. struct adm_cmd_set_pspd_mtmx_strtr_params_v6 *adm_params = NULL;
  733. int sz, rc = 0, port_idx;
  734. port_id = afe_convert_virtual_to_portid(port_id);
  735. port_idx = adm_validate_and_get_port_index(port_id);
  736. if (port_idx < 0) {
  737. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  738. return -EINVAL;
  739. }
  740. sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v6) +
  741. params_length;
  742. adm_params = kzalloc(sz, GFP_KERNEL);
  743. if (!adm_params) {
  744. pr_err("%s, adm params memory alloc failed\n", __func__);
  745. return -ENOMEM;
  746. }
  747. memcpy(((u8 *)adm_params +
  748. sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v6)),
  749. params, params_length);
  750. adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  751. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  752. adm_params->hdr.pkt_size = sz;
  753. adm_params->hdr.src_svc = APR_SVC_ADM;
  754. adm_params->hdr.src_domain = APR_DOMAIN_APPS;
  755. adm_params->hdr.src_port = port_id;
  756. adm_params->hdr.dest_svc = APR_SVC_ADM;
  757. adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
  758. adm_params->hdr.dest_port = 0; /* Ignored */;
  759. adm_params->hdr.token = port_idx << 16 | copp_idx;
  760. adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V6;
  761. adm_params->payload_addr_lsw = 0;
  762. adm_params->payload_addr_msw = 0;
  763. adm_params->mem_map_handle = 0;
  764. adm_params->payload_size = params_length;
  765. adm_params->direction = direction;
  766. /* session id for this cmd to be applied on */
  767. adm_params->sessionid = session_id;
  768. adm_params->deviceid =
  769. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  770. /* connecting stream type i.e. lsm or asm */
  771. adm_params->stream_type = stream_type;
  772. pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n",
  773. __func__, adm_params->deviceid, adm_params->sessionid,
  774. adm_params->hdr.src_port, adm_params->hdr.dest_port);
  775. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  776. rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
  777. if (rc < 0) {
  778. pr_err("%s: Set params failed port = 0x%x rc %d\n",
  779. __func__, port_id, rc);
  780. rc = -EINVAL;
  781. goto exit;
  782. }
  783. /* Wait for the callback */
  784. rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  785. atomic_read(&this_adm.copp.stat
  786. [port_idx][copp_idx]),
  787. msecs_to_jiffies(TIMEOUT_MS));
  788. if (!rc) {
  789. pr_err("%s: Set params timed out port = 0x%x\n", __func__,
  790. port_id);
  791. rc = -EINVAL;
  792. goto exit;
  793. } else if (atomic_read(&this_adm.copp.stat
  794. [port_idx][copp_idx]) > 0) {
  795. pr_err("%s: DSP returned error[%s]\n", __func__,
  796. adsp_err_get_err_str(atomic_read(
  797. &this_adm.copp.stat
  798. [port_idx][copp_idx])));
  799. rc = adsp_err_get_lnx_err_code(
  800. atomic_read(&this_adm.copp.stat
  801. [port_idx][copp_idx]));
  802. goto exit;
  803. }
  804. rc = 0;
  805. exit:
  806. kfree(adm_params);
  807. return rc;
  808. }
  809. EXPORT_SYMBOL(adm_set_custom_chmix_cfg);
  810. /*
  811. * With pre-packed data, only the opcode differes from V5 and V6.
  812. * Use q6common_pack_pp_params to pack the data correctly.
  813. */
  814. int adm_set_pp_params(int port_id, int copp_idx,
  815. struct mem_mapping_hdr *mem_hdr, u8 *param_data,
  816. u32 param_size)
  817. {
  818. struct adm_cmd_set_pp_params *adm_set_params = NULL;
  819. int size = 0;
  820. int port_idx = 0;
  821. atomic_t *copp_stat = NULL;
  822. int ret = 0;
  823. port_id = afe_convert_virtual_to_portid(port_id);
  824. port_idx = adm_validate_and_get_port_index(port_id);
  825. if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
  826. pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx);
  827. return -EINVAL;
  828. } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  829. pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
  830. return -EINVAL;
  831. }
  832. /* Only add params_size in inband case */
  833. size = sizeof(struct adm_cmd_set_pp_params);
  834. if (param_data != NULL)
  835. size += param_size;
  836. adm_set_params = kzalloc(size, GFP_KERNEL);
  837. if (!adm_set_params)
  838. return -ENOMEM;
  839. adm_set_params->apr_hdr.hdr_field =
  840. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  841. APR_PKT_VER);
  842. adm_set_params->apr_hdr.pkt_size = size;
  843. adm_set_params->apr_hdr.src_svc = APR_SVC_ADM;
  844. adm_set_params->apr_hdr.src_domain = APR_DOMAIN_APPS;
  845. adm_set_params->apr_hdr.src_port = port_id;
  846. adm_set_params->apr_hdr.dest_svc = APR_SVC_ADM;
  847. adm_set_params->apr_hdr.dest_domain = APR_DOMAIN_ADSP;
  848. adm_set_params->apr_hdr.dest_port =
  849. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  850. adm_set_params->apr_hdr.token = port_idx << 16 | copp_idx;
  851. if (q6common_is_instance_id_supported())
  852. adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V6;
  853. else
  854. adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
  855. adm_set_params->payload_size = param_size;
  856. if (mem_hdr != NULL) {
  857. /* Out of Band Case */
  858. adm_set_params->mem_hdr = *mem_hdr;
  859. } else if (param_data != NULL) {
  860. /*
  861. * In band case. Parameter data must be pre-packed with its
  862. * header before calling this function. Use
  863. * q6common_pack_pp_params to pack parameter data and header
  864. * correctly.
  865. */
  866. memcpy(&adm_set_params->param_data, param_data, param_size);
  867. } else {
  868. pr_err("%s: Received NULL pointers for both memory header and param data\n",
  869. __func__);
  870. ret = -EINVAL;
  871. goto done;
  872. }
  873. copp_stat = &this_adm.copp.stat[port_idx][copp_idx];
  874. atomic_set(copp_stat, -1);
  875. ret = apr_send_pkt(this_adm.apr, (uint32_t *) adm_set_params);
  876. if (ret < 0) {
  877. pr_err("%s: Set params APR send failed port = 0x%x ret %d\n",
  878. __func__, port_id, ret);
  879. goto done;
  880. }
  881. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  882. atomic_read(copp_stat) >= 0,
  883. msecs_to_jiffies(TIMEOUT_MS));
  884. if (!ret) {
  885. pr_err("%s: Set params timed out port = 0x%x\n", __func__,
  886. port_id);
  887. ret = -ETIMEDOUT;
  888. goto done;
  889. }
  890. if (atomic_read(copp_stat) > 0) {
  891. pr_err("%s: DSP returned error[%s]\n", __func__,
  892. adsp_err_get_err_str(atomic_read(copp_stat)));
  893. ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat));
  894. goto done;
  895. }
  896. ret = 0;
  897. done:
  898. kfree(adm_set_params);
  899. return ret;
  900. }
  901. EXPORT_SYMBOL(adm_set_pp_params);
  902. int adm_pack_and_set_one_pp_param(int port_id, int copp_idx,
  903. struct param_hdr_v3 param_hdr, u8 *param_data)
  904. {
  905. u8 *packed_data = NULL;
  906. u32 total_size = 0;
  907. int ret = 0;
  908. total_size = sizeof(union param_hdrs) + param_hdr.param_size;
  909. packed_data = kzalloc(total_size, GFP_KERNEL);
  910. if (!packed_data)
  911. return -ENOMEM;
  912. ret = q6common_pack_pp_params(packed_data, &param_hdr, param_data,
  913. &total_size);
  914. if (ret) {
  915. pr_err("%s: Failed to pack parameter data, error %d\n",
  916. __func__, ret);
  917. goto done;
  918. }
  919. ret = adm_set_pp_params(port_id, copp_idx, NULL, packed_data,
  920. total_size);
  921. if (ret)
  922. pr_err("%s: Failed to set parameter data, error %d\n", __func__,
  923. ret);
  924. done:
  925. kfree(packed_data);
  926. return ret;
  927. }
  928. EXPORT_SYMBOL(adm_pack_and_set_one_pp_param);
  929. /*
  930. * Only one parameter can be requested at a time. Therefore, packing and sending
  931. * the request can be handled locally.
  932. */
  933. int adm_get_pp_params(int port_id, int copp_idx, uint32_t client_id,
  934. struct mem_mapping_hdr *mem_hdr,
  935. struct param_hdr_v3 *param_hdr, u8 *returned_param_data)
  936. {
  937. struct adm_cmd_get_pp_params adm_get_params;
  938. int total_size = 0;
  939. int get_param_array_sz = ARRAY_SIZE(adm_get_parameters);
  940. int returned_param_size = 0;
  941. int returned_param_size_in_bytes = 0;
  942. int port_idx = 0;
  943. int idx = 0;
  944. atomic_t *copp_stat = NULL;
  945. int ret = 0;
  946. if (param_hdr == NULL) {
  947. pr_err("%s: Received NULL pointer for parameter header\n",
  948. __func__);
  949. return -EINVAL;
  950. }
  951. port_id = afe_convert_virtual_to_portid(port_id);
  952. port_idx = adm_validate_and_get_port_index(port_id);
  953. if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
  954. pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx);
  955. return -EINVAL;
  956. }
  957. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  958. pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
  959. return -EINVAL;
  960. }
  961. memset(&adm_get_params, 0, sizeof(adm_get_params));
  962. if (mem_hdr != NULL)
  963. adm_get_params.mem_hdr = *mem_hdr;
  964. q6common_pack_pp_params((u8 *) &adm_get_params.param_hdr, param_hdr,
  965. NULL, &total_size);
  966. /* Pack APR header after filling body so total_size has correct value */
  967. adm_get_params.apr_hdr.hdr_field =
  968. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
  969. APR_PKT_VER);
  970. adm_get_params.apr_hdr.pkt_size = sizeof(adm_get_params);
  971. adm_get_params.apr_hdr.src_svc = APR_SVC_ADM;
  972. adm_get_params.apr_hdr.src_domain = APR_DOMAIN_APPS;
  973. adm_get_params.apr_hdr.src_port = port_id;
  974. adm_get_params.apr_hdr.dest_svc = APR_SVC_ADM;
  975. adm_get_params.apr_hdr.dest_domain = APR_DOMAIN_ADSP;
  976. adm_get_params.apr_hdr.dest_port =
  977. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  978. adm_get_params.apr_hdr.token =
  979. port_idx << 16 | client_id << 8 | copp_idx;
  980. if (q6common_is_instance_id_supported())
  981. adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V6;
  982. else
  983. adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5;
  984. copp_stat = &this_adm.copp.stat[port_idx][copp_idx];
  985. atomic_set(copp_stat, -1);
  986. ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_params);
  987. if (ret < 0) {
  988. pr_err("%s: Get params APR send failed port = 0x%x ret %d\n",
  989. __func__, port_id, ret);
  990. ret = -EINVAL;
  991. goto done;
  992. }
  993. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  994. atomic_read(copp_stat) >= 0,
  995. msecs_to_jiffies(TIMEOUT_MS));
  996. if (!ret) {
  997. pr_err("%s: Get params timed out port = 0x%x\n", __func__,
  998. port_id);
  999. ret = -ETIMEDOUT;
  1000. goto done;
  1001. }
  1002. if (atomic_read(copp_stat) > 0) {
  1003. pr_err("%s: DSP returned error[%s]\n", __func__,
  1004. adsp_err_get_err_str(atomic_read(copp_stat)));
  1005. ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat));
  1006. goto done;
  1007. }
  1008. ret = 0;
  1009. /* Copy data to caller if sent in band */
  1010. if (!returned_param_data) {
  1011. pr_debug("%s: Received NULL pointer for param destination, not copying payload\n",
  1012. __func__);
  1013. return 0;
  1014. }
  1015. idx = ADM_GET_PARAMETER_LENGTH * copp_idx;
  1016. returned_param_size = adm_get_parameters[idx];
  1017. if (returned_param_size < 0 ||
  1018. returned_param_size + idx + 1 > get_param_array_sz) {
  1019. pr_err("%s: Invalid parameter size %d\n", __func__,
  1020. returned_param_size);
  1021. return -EINVAL;
  1022. }
  1023. returned_param_size_in_bytes = returned_param_size * sizeof(uint32_t);
  1024. if (param_hdr->param_size < returned_param_size_in_bytes) {
  1025. pr_err("%s: Provided buffer is not big enough, provided buffer size(%d) size needed(%d)\n",
  1026. __func__, param_hdr->param_size,
  1027. returned_param_size_in_bytes);
  1028. return -EINVAL;
  1029. }
  1030. memcpy(returned_param_data, &adm_get_parameters[idx + 1],
  1031. returned_param_size_in_bytes);
  1032. done:
  1033. return ret;
  1034. }
  1035. EXPORT_SYMBOL(adm_get_pp_params);
  1036. int adm_get_pp_topo_module_list_v2(int port_id, int copp_idx,
  1037. int32_t param_length,
  1038. int32_t *returned_params)
  1039. {
  1040. struct adm_cmd_get_pp_topo_module_list adm_get_module_list;
  1041. bool iid_supported = q6common_is_instance_id_supported();
  1042. int *topo_list;
  1043. int num_modules = 0;
  1044. int list_size = 0;
  1045. int port_idx, idx;
  1046. int i = 0;
  1047. atomic_t *copp_stat = NULL;
  1048. int ret = 0;
  1049. pr_debug("%s : port_id %x", __func__, port_id);
  1050. port_id = afe_convert_virtual_to_portid(port_id);
  1051. port_idx = adm_validate_and_get_port_index(port_id);
  1052. if (port_idx < 0) {
  1053. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  1054. return -EINVAL;
  1055. }
  1056. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  1057. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  1058. return -EINVAL;
  1059. }
  1060. memset(&adm_get_module_list, 0, sizeof(adm_get_module_list));
  1061. adm_get_module_list.apr_hdr.pkt_size = sizeof(adm_get_module_list);
  1062. adm_get_module_list.apr_hdr.src_svc = APR_SVC_ADM;
  1063. adm_get_module_list.apr_hdr.src_domain = APR_DOMAIN_APPS;
  1064. adm_get_module_list.apr_hdr.src_port = port_id;
  1065. adm_get_module_list.apr_hdr.dest_svc = APR_SVC_ADM;
  1066. adm_get_module_list.apr_hdr.dest_domain = APR_DOMAIN_ADSP;
  1067. adm_get_module_list.apr_hdr.dest_port =
  1068. atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
  1069. adm_get_module_list.apr_hdr.token = port_idx << 16 | copp_idx;
  1070. /*
  1071. * Out of band functionality is not currently utilized.
  1072. * Assume in band.
  1073. */
  1074. if (iid_supported) {
  1075. adm_get_module_list.apr_hdr.opcode =
  1076. ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2;
  1077. adm_get_module_list.param_max_size = param_length;
  1078. } else {
  1079. adm_get_module_list.apr_hdr.opcode =
  1080. ADM_CMD_GET_PP_TOPO_MODULE_LIST;
  1081. if (param_length > U16_MAX) {
  1082. pr_err("%s: Invalid param length for V1 %d\n", __func__,
  1083. param_length);
  1084. return -EINVAL;
  1085. }
  1086. adm_get_module_list.param_max_size = param_length << 16;
  1087. }
  1088. copp_stat = &this_adm.copp.stat[port_idx][copp_idx];
  1089. atomic_set(copp_stat, -1);
  1090. ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_module_list);
  1091. if (ret < 0) {
  1092. pr_err("%s: APR send pkt failed for port_id: 0x%x failed ret %d\n",
  1093. __func__, port_id, ret);
  1094. ret = -EINVAL;
  1095. goto done;
  1096. }
  1097. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  1098. atomic_read(copp_stat) >= 0,
  1099. msecs_to_jiffies(TIMEOUT_MS));
  1100. if (!ret) {
  1101. pr_err("%s: Timeout for port_id: 0x%x\n", __func__, port_id);
  1102. ret = -ETIMEDOUT;
  1103. goto done;
  1104. }
  1105. if (atomic_read(copp_stat) > 0) {
  1106. pr_err("%s: DSP returned error[%s]\n", __func__,
  1107. adsp_err_get_err_str(atomic_read(copp_stat)));
  1108. ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat));
  1109. goto done;
  1110. }
  1111. ret = 0;
  1112. if (returned_params) {
  1113. /*
  1114. * When processing ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST IID is
  1115. * added since it is not present. Therefore, there is no need to
  1116. * do anything different if IID is not supported here as it is
  1117. * already taken care of.
  1118. */
  1119. idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx;
  1120. num_modules = adm_module_topo_list[idx];
  1121. if (num_modules < 0 || num_modules > MAX_MODULES_IN_TOPO) {
  1122. pr_err("%s: Invalid number of modules returned %d\n",
  1123. __func__, num_modules);
  1124. return -EINVAL;
  1125. }
  1126. list_size = num_modules * sizeof(struct module_instance_info);
  1127. if (param_length < list_size) {
  1128. pr_err("%s: Provided buffer not big enough to hold module-instance list, provided size %d, needed size %d\n",
  1129. __func__, param_length, list_size);
  1130. return -EINVAL;
  1131. }
  1132. topo_list = (int32_t *) (&adm_module_topo_list[idx]);
  1133. memcpy(returned_params, topo_list, list_size);
  1134. for (i = 1; i <= num_modules; i += 2) {
  1135. pr_debug("module = 0x%x instance = 0x%x\n",
  1136. returned_params[i], returned_params[i + 1]);
  1137. }
  1138. }
  1139. done:
  1140. return ret;
  1141. }
  1142. EXPORT_SYMBOL(adm_get_pp_topo_module_list_v2);
  1143. static void adm_callback_debug_print(struct apr_client_data *data)
  1144. {
  1145. uint32_t *payload;
  1146. payload = data->payload;
  1147. if (data->payload_size >= 8)
  1148. pr_debug("%s: code = 0x%x PL#0[0x%x], PL#1[0x%x], size = %d\n",
  1149. __func__, data->opcode, payload[0], payload[1],
  1150. data->payload_size);
  1151. else if (data->payload_size >= 4)
  1152. pr_debug("%s: code = 0x%x PL#0[0x%x], size = %d\n",
  1153. __func__, data->opcode, payload[0],
  1154. data->payload_size);
  1155. else
  1156. pr_debug("%s: code = 0x%x, size = %d\n",
  1157. __func__, data->opcode, data->payload_size);
  1158. }
  1159. /**
  1160. * adm_set_multi_ch_map -
  1161. * Update multi channel map info
  1162. *
  1163. * @channel_map: pointer with channel map info
  1164. * @path: direction or ADM path type
  1165. *
  1166. * Returns 0 on success or error on failure
  1167. */
  1168. int adm_set_multi_ch_map(char *channel_map, int path)
  1169. {
  1170. int idx;
  1171. if (path == ADM_PATH_PLAYBACK) {
  1172. idx = ADM_MCH_MAP_IDX_PLAYBACK;
  1173. } else if (path == ADM_PATH_LIVE_REC) {
  1174. idx = ADM_MCH_MAP_IDX_REC;
  1175. } else {
  1176. pr_err("%s: invalid attempt to set path %d\n", __func__, path);
  1177. return -EINVAL;
  1178. }
  1179. memcpy(multi_ch_maps[idx].channel_mapping, channel_map,
  1180. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  1181. multi_ch_maps[idx].set_channel_map = true;
  1182. return 0;
  1183. }
  1184. EXPORT_SYMBOL(adm_set_multi_ch_map);
  1185. /**
  1186. * adm_get_multi_ch_map -
  1187. * Retrieves multi channel map info
  1188. *
  1189. * @channel_map: pointer to be updated with channel map
  1190. * @path: direction or ADM path type
  1191. *
  1192. * Returns 0 on success or error on failure
  1193. */
  1194. int adm_get_multi_ch_map(char *channel_map, int path)
  1195. {
  1196. int idx;
  1197. if (path == ADM_PATH_PLAYBACK) {
  1198. idx = ADM_MCH_MAP_IDX_PLAYBACK;
  1199. } else if (path == ADM_PATH_LIVE_REC) {
  1200. idx = ADM_MCH_MAP_IDX_REC;
  1201. } else {
  1202. pr_err("%s: invalid attempt to get path %d\n", __func__, path);
  1203. return -EINVAL;
  1204. }
  1205. if (multi_ch_maps[idx].set_channel_map) {
  1206. memcpy(channel_map, multi_ch_maps[idx].channel_mapping,
  1207. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  1208. }
  1209. return 0;
  1210. }
  1211. EXPORT_SYMBOL(adm_get_multi_ch_map);
  1212. /**
  1213. * adm_set_port_multi_ch_map -
  1214. * Update port specific channel map info
  1215. *
  1216. * @channel_map: pointer with channel map info
  1217. * @port_id: port for which chmap is set
  1218. */
  1219. void adm_set_port_multi_ch_map(char *channel_map, int port_id)
  1220. {
  1221. int port_idx;
  1222. port_id = q6audio_convert_virtual_to_portid(port_id);
  1223. port_idx = adm_validate_and_get_port_index(port_id);
  1224. if (port_idx < 0) {
  1225. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  1226. return;
  1227. }
  1228. memcpy(port_channel_map[port_idx].channel_mapping, channel_map,
  1229. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  1230. port_channel_map[port_idx].set_channel_map = true;
  1231. }
  1232. EXPORT_SYMBOL(adm_set_port_multi_ch_map);
  1233. static int adm_process_get_param_response(u32 opcode, u32 idx, u32 *payload,
  1234. u32 payload_size)
  1235. {
  1236. struct adm_cmd_rsp_get_pp_params_v5 *v5_rsp = NULL;
  1237. struct adm_cmd_rsp_get_pp_params_v6 *v6_rsp = NULL;
  1238. u32 *param_data = NULL;
  1239. int data_size = 0;
  1240. int struct_size = 0;
  1241. if (payload == NULL) {
  1242. pr_err("%s: Payload is NULL\n", __func__);
  1243. return -EINVAL;
  1244. }
  1245. switch (opcode) {
  1246. case ADM_CMDRSP_GET_PP_PARAMS_V5:
  1247. struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v5);
  1248. if (payload_size < struct_size) {
  1249. pr_err("%s: payload size %d < expected size %d\n",
  1250. __func__, payload_size, struct_size);
  1251. break;
  1252. }
  1253. v5_rsp = (struct adm_cmd_rsp_get_pp_params_v5 *) payload;
  1254. data_size = v5_rsp->param_hdr.param_size;
  1255. param_data = v5_rsp->param_data;
  1256. break;
  1257. case ADM_CMDRSP_GET_PP_PARAMS_V6:
  1258. struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v6);
  1259. if (payload_size < struct_size) {
  1260. pr_err("%s: payload size %d < expected size %d\n",
  1261. __func__, payload_size, struct_size);
  1262. break;
  1263. }
  1264. v6_rsp = (struct adm_cmd_rsp_get_pp_params_v6 *) payload;
  1265. data_size = v6_rsp->param_hdr.param_size;
  1266. param_data = v6_rsp->param_data;
  1267. break;
  1268. default:
  1269. pr_err("%s: Invalid opcode %d\n", __func__, opcode);
  1270. return -EINVAL;
  1271. }
  1272. /*
  1273. * Just store the returned parameter data, not the header. The calling
  1274. * function is expected to know what it asked for. Therefore, there is
  1275. * no difference between V5 and V6.
  1276. */
  1277. if ((payload_size >= struct_size + data_size) &&
  1278. (ARRAY_SIZE(adm_get_parameters) > idx) &&
  1279. (ARRAY_SIZE(adm_get_parameters) > idx + 1 + data_size)) {
  1280. pr_debug("%s: Received parameter data in band\n",
  1281. __func__);
  1282. /*
  1283. * data_size is expressed in number of bytes, store in number of
  1284. * ints
  1285. */
  1286. adm_get_parameters[idx] =
  1287. data_size / sizeof(*adm_get_parameters);
  1288. pr_debug("%s: GET_PP PARAM: received parameter length: 0x%x\n",
  1289. __func__, adm_get_parameters[idx]);
  1290. /* store params after param_size */
  1291. memcpy(&adm_get_parameters[idx + 1], param_data, data_size);
  1292. } else if (payload_size == sizeof(uint32_t)) {
  1293. adm_get_parameters[idx] = -1;
  1294. pr_debug("%s: Out of band case, setting size to %d\n",
  1295. __func__, adm_get_parameters[idx]);
  1296. } else {
  1297. pr_err("%s: Invalid parameter combination, payload_size %d, idx %d\n",
  1298. __func__, payload_size, idx);
  1299. return -EINVAL;
  1300. }
  1301. return 0;
  1302. }
  1303. static int adm_process_get_topo_list_response(u32 opcode, int copp_idx,
  1304. u32 num_modules, u32 *payload,
  1305. u32 payload_size)
  1306. {
  1307. u32 *fill_list = NULL;
  1308. int idx = 0;
  1309. int i = 0;
  1310. int j = 0;
  1311. if (payload == NULL) {
  1312. pr_err("%s: Payload is NULL\n", __func__);
  1313. return -EINVAL;
  1314. } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  1315. pr_err("%s: Invalid COPP index %d\n", __func__, copp_idx);
  1316. return -EINVAL;
  1317. }
  1318. idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx;
  1319. fill_list = adm_module_topo_list + idx;
  1320. *fill_list++ = num_modules;
  1321. for (i = 0; i < num_modules; i++) {
  1322. if (j > payload_size / sizeof(u32)) {
  1323. pr_err("%s: Invalid number of modules specified %d\n",
  1324. __func__, num_modules);
  1325. return -EINVAL;
  1326. }
  1327. /* store module ID */
  1328. *fill_list++ = payload[j];
  1329. j++;
  1330. switch (opcode) {
  1331. case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2:
  1332. /* store instance ID */
  1333. *fill_list++ = payload[j];
  1334. j++;
  1335. break;
  1336. case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST:
  1337. /* Insert IID 0 when repacking */
  1338. *fill_list++ = INSTANCE_ID_0;
  1339. break;
  1340. default:
  1341. pr_err("%s: Invalid opcode %d\n", __func__, opcode);
  1342. return -EINVAL;
  1343. }
  1344. }
  1345. return 0;
  1346. }
  1347. static void adm_reset_data(void)
  1348. {
  1349. int i, j;
  1350. apr_reset(this_adm.apr);
  1351. for (i = 0; i < AFE_MAX_PORTS; i++) {
  1352. for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
  1353. atomic_set(&this_adm.copp.id[i][j],
  1354. RESET_COPP_ID);
  1355. atomic_set(&this_adm.copp.cnt[i][j], 0);
  1356. atomic_set(
  1357. &this_adm.copp.topology[i][j], 0);
  1358. atomic_set(&this_adm.copp.mode[i][j],
  1359. 0);
  1360. atomic_set(&this_adm.copp.stat[i][j],
  1361. 0);
  1362. atomic_set(&this_adm.copp.rate[i][j],
  1363. 0);
  1364. atomic_set(
  1365. &this_adm.copp.channels[i][j],
  1366. 0);
  1367. atomic_set(
  1368. &this_adm.copp.bit_width[i][j], 0);
  1369. atomic_set(
  1370. &this_adm.copp.app_type[i][j], 0);
  1371. atomic_set(
  1372. &this_adm.copp.acdb_id[i][j], 0);
  1373. atomic_set(
  1374. &this_adm.copp.session_type[i][j], 0);
  1375. this_adm.copp.adm_status[i][j] =
  1376. ADM_STATUS_CALIBRATION_REQUIRED;
  1377. }
  1378. }
  1379. this_adm.apr = NULL;
  1380. cal_utils_clear_cal_block_q6maps(ADM_MAX_CAL_TYPES,
  1381. this_adm.cal_data);
  1382. mutex_lock(&this_adm.cal_data
  1383. [ADM_CUSTOM_TOP_CAL]->lock);
  1384. this_adm.set_custom_topology = 1;
  1385. mutex_unlock(&this_adm.cal_data[
  1386. ADM_CUSTOM_TOP_CAL]->lock);
  1387. rtac_clear_mapping(ADM_RTAC_CAL);
  1388. /*
  1389. * Free the ION memory and clear the map handles
  1390. * for Source Tracking
  1391. */
  1392. if (this_adm.sourceTrackingData.memmap.paddr != 0) {
  1393. msm_audio_ion_free(
  1394. this_adm.sourceTrackingData.dma_buf);
  1395. this_adm.sourceTrackingData.dma_buf = NULL;
  1396. this_adm.sourceTrackingData.memmap.size = 0;
  1397. this_adm.sourceTrackingData.memmap.kvaddr =
  1398. NULL;
  1399. this_adm.sourceTrackingData.memmap.paddr = 0;
  1400. this_adm.sourceTrackingData.apr_cmd_status = -1;
  1401. atomic_set(&this_adm.mem_map_handles[
  1402. ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
  1403. }
  1404. }
  1405. static int32_t adm_callback(struct apr_client_data *data, void *priv)
  1406. {
  1407. uint32_t *payload;
  1408. int port_idx, copp_idx, idx, client_id;
  1409. int num_modules;
  1410. int ret;
  1411. if (data == NULL) {
  1412. pr_err("%s: data parameter is null\n", __func__);
  1413. return -EINVAL;
  1414. }
  1415. payload = data->payload;
  1416. if (data->opcode == RESET_EVENTS) {
  1417. pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
  1418. __func__,
  1419. data->reset_event, data->reset_proc, this_adm.apr);
  1420. if (this_adm.apr)
  1421. adm_reset_data();
  1422. return 0;
  1423. }
  1424. adm_callback_debug_print(data);
  1425. if (data->payload_size >= sizeof(uint32_t)) {
  1426. copp_idx = (data->token) & 0XFF;
  1427. port_idx = ((data->token) >> 16) & 0xFF;
  1428. client_id = ((data->token) >> 8) & 0xFF;
  1429. if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
  1430. pr_err("%s: Invalid port idx %d token %d\n",
  1431. __func__, port_idx, data->token);
  1432. return 0;
  1433. }
  1434. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  1435. pr_err("%s: Invalid copp idx %d token %d\n",
  1436. __func__, copp_idx, data->token);
  1437. return 0;
  1438. }
  1439. if (client_id < 0 || client_id >= ADM_CLIENT_ID_MAX) {
  1440. pr_err("%s: Invalid client id %d\n", __func__,
  1441. client_id);
  1442. return 0;
  1443. }
  1444. if (data->opcode == APR_BASIC_RSP_RESULT) {
  1445. pr_debug("%s: APR_BASIC_RSP_RESULT id 0x%x\n",
  1446. __func__, payload[0]);
  1447. if (!((client_id != ADM_CLIENT_ID_SOURCE_TRACKING) &&
  1448. ((payload[0] == ADM_CMD_SET_PP_PARAMS_V5) ||
  1449. (payload[0] == ADM_CMD_SET_PP_PARAMS_V6)))) {
  1450. if (data->payload_size <
  1451. (2 * sizeof(uint32_t))) {
  1452. pr_err("%s: Invalid payload size %d\n",
  1453. __func__, data->payload_size);
  1454. return 0;
  1455. }
  1456. }
  1457. if (payload[1] != 0) {
  1458. pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
  1459. __func__, payload[0], payload[1]);
  1460. }
  1461. switch (payload[0]) {
  1462. case ADM_CMD_SET_PP_PARAMS_V5:
  1463. case ADM_CMD_SET_PP_PARAMS_V6:
  1464. pr_debug("%s: ADM_CMD_SET_PP_PARAMS\n",
  1465. __func__);
  1466. if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
  1467. this_adm.sourceTrackingData.
  1468. apr_cmd_status = payload[1];
  1469. else if (rtac_make_adm_callback(payload,
  1470. data->payload_size))
  1471. break;
  1472. /*
  1473. * if soft volume is called and already
  1474. * interrupted break out of the sequence here
  1475. */
  1476. case ADM_CMD_DEVICE_OPEN_V5:
  1477. case ADM_CMD_DEVICE_CLOSE_V5:
  1478. case ADM_CMD_DEVICE_OPEN_V6:
  1479. case ADM_CMD_DEVICE_OPEN_V8:
  1480. pr_debug("%s: Basic callback received, wake up.\n",
  1481. __func__);
  1482. atomic_set(&this_adm.copp.stat[port_idx]
  1483. [copp_idx], payload[1]);
  1484. wake_up(
  1485. &this_adm.copp.wait[port_idx][copp_idx]);
  1486. break;
  1487. case ADM_CMD_ADD_TOPOLOGIES:
  1488. pr_debug("%s: callback received, ADM_CMD_ADD_TOPOLOGIES.\n",
  1489. __func__);
  1490. atomic_set(&this_adm.adm_stat, payload[1]);
  1491. wake_up(&this_adm.adm_wait);
  1492. break;
  1493. case ADM_CMD_MATRIX_MAP_ROUTINGS_V5:
  1494. case ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5:
  1495. pr_debug("%s: Basic callback received, wake up.\n",
  1496. __func__);
  1497. atomic_set(&this_adm.matrix_map_stat,
  1498. payload[1]);
  1499. wake_up(&this_adm.matrix_map_wait);
  1500. break;
  1501. case ADM_CMD_SHARED_MEM_UNMAP_REGIONS:
  1502. pr_debug("%s: ADM_CMD_SHARED_MEM_UNMAP_REGIONS\n",
  1503. __func__);
  1504. atomic_set(&this_adm.adm_stat, payload[1]);
  1505. wake_up(&this_adm.adm_wait);
  1506. break;
  1507. case ADM_CMD_SHARED_MEM_MAP_REGIONS:
  1508. pr_debug("%s: ADM_CMD_SHARED_MEM_MAP_REGIONS\n",
  1509. __func__);
  1510. /* Should only come here if there is an APR */
  1511. /* error or malformed APR packet. Otherwise */
  1512. /* response will be returned as */
  1513. if (payload[1] != 0) {
  1514. pr_err("%s: ADM map error, resuming\n",
  1515. __func__);
  1516. atomic_set(&this_adm.adm_stat,
  1517. payload[1]);
  1518. wake_up(&this_adm.adm_wait);
  1519. }
  1520. break;
  1521. case ADM_CMD_GET_PP_PARAMS_V5:
  1522. case ADM_CMD_GET_PP_PARAMS_V6:
  1523. pr_debug("%s: ADM_CMD_GET_PP_PARAMS\n",
  1524. __func__);
  1525. /* Should only come here if there is an APR */
  1526. /* error or malformed APR packet. Otherwise */
  1527. /* response will be returned as */
  1528. /* ADM_CMDRSP_GET_PP_PARAMS_V5 */
  1529. if (client_id ==
  1530. ADM_CLIENT_ID_SOURCE_TRACKING) {
  1531. this_adm.sourceTrackingData.
  1532. apr_cmd_status = payload[1];
  1533. if (payload[1] != 0)
  1534. pr_err("%s: ADM get param error = %d\n",
  1535. __func__, payload[1]);
  1536. atomic_set(&this_adm.copp.stat
  1537. [port_idx][copp_idx],
  1538. payload[1]);
  1539. wake_up(&this_adm.copp.wait
  1540. [port_idx][copp_idx]);
  1541. } else {
  1542. if (payload[1] != 0) {
  1543. pr_err("%s: ADM get param error = %d, resuming\n",
  1544. __func__, payload[1]);
  1545. rtac_make_adm_callback(payload,
  1546. data->payload_size);
  1547. }
  1548. }
  1549. break;
  1550. case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5:
  1551. case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V6:
  1552. pr_debug("%s:callback received PSPD MTMX, wake up\n",
  1553. __func__);
  1554. atomic_set(&this_adm.copp.stat[port_idx]
  1555. [copp_idx], payload[1]);
  1556. wake_up(
  1557. &this_adm.copp.wait[port_idx][copp_idx]);
  1558. break;
  1559. case ADM_CMD_GET_PP_TOPO_MODULE_LIST:
  1560. case ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2:
  1561. pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n",
  1562. __func__);
  1563. if (payload[1] != 0)
  1564. pr_err("%s: ADM get topo list error = %d\n",
  1565. __func__, payload[1]);
  1566. break;
  1567. default:
  1568. pr_err("%s: Unknown Cmd: 0x%x\n", __func__,
  1569. payload[0]);
  1570. break;
  1571. }
  1572. return 0;
  1573. }
  1574. switch (data->opcode) {
  1575. case ADM_CMDRSP_DEVICE_OPEN_V5:
  1576. case ADM_CMDRSP_DEVICE_OPEN_V6:
  1577. case ADM_CMDRSP_DEVICE_OPEN_V8: {
  1578. struct adm_cmd_rsp_device_open_v5 *open = NULL;
  1579. if (data->payload_size <
  1580. sizeof(struct adm_cmd_rsp_device_open_v5)) {
  1581. pr_err("%s: Invalid payload size %d\n", __func__,
  1582. data->payload_size);
  1583. return 0;
  1584. }
  1585. open = (struct adm_cmd_rsp_device_open_v5 *)data->payload;
  1586. if (open->copp_id == INVALID_COPP_ID) {
  1587. pr_err("%s: invalid coppid rxed %d\n",
  1588. __func__, open->copp_id);
  1589. atomic_set(&this_adm.copp.stat[port_idx]
  1590. [copp_idx], ADSP_EBADPARAM);
  1591. wake_up(
  1592. &this_adm.copp.wait[port_idx][copp_idx]);
  1593. break;
  1594. }
  1595. atomic_set(&this_adm.copp.stat
  1596. [port_idx][copp_idx], payload[0]);
  1597. atomic_set(&this_adm.copp.id[port_idx][copp_idx],
  1598. open->copp_id);
  1599. pr_debug("%s: coppid rxed=%d\n", __func__,
  1600. open->copp_id);
  1601. wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
  1602. }
  1603. break;
  1604. case ADM_CMDRSP_GET_PP_PARAMS_V5:
  1605. case ADM_CMDRSP_GET_PP_PARAMS_V6:
  1606. pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS\n", __func__);
  1607. if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
  1608. this_adm.sourceTrackingData.apr_cmd_status =
  1609. payload[0];
  1610. else if (rtac_make_adm_callback(payload,
  1611. data->payload_size))
  1612. break;
  1613. idx = ADM_GET_PARAMETER_LENGTH * copp_idx;
  1614. if (payload[0] == 0 && data->payload_size > 0) {
  1615. ret = adm_process_get_param_response(
  1616. data->opcode, idx, payload,
  1617. data->payload_size);
  1618. if (ret)
  1619. pr_err("%s: Failed to process get param response, error %d\n",
  1620. __func__, ret);
  1621. } else {
  1622. adm_get_parameters[idx] = -1;
  1623. pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS returned error 0x%x\n",
  1624. __func__, payload[0]);
  1625. }
  1626. atomic_set(&this_adm.copp.stat[port_idx][copp_idx],
  1627. payload[0]);
  1628. wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
  1629. break;
  1630. case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST:
  1631. case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2:
  1632. pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n",
  1633. __func__);
  1634. if (data->payload_size >= (2 * sizeof(uint32_t))) {
  1635. num_modules = payload[1];
  1636. pr_debug("%s: Num modules %d\n", __func__,
  1637. num_modules);
  1638. if (payload[0]) {
  1639. pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST, error = %d\n",
  1640. __func__, payload[0]);
  1641. } else if (num_modules > MAX_MODULES_IN_TOPO) {
  1642. pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST invalid num modules received, num modules = %d\n",
  1643. __func__, num_modules);
  1644. } else {
  1645. ret = adm_process_get_topo_list_response(
  1646. data->opcode, copp_idx,
  1647. num_modules, payload,
  1648. data->payload_size);
  1649. if (ret)
  1650. pr_err("%s: Failed to process get topo modules list response, error %d\n",
  1651. __func__, ret);
  1652. }
  1653. } else {
  1654. pr_err("%s: Invalid payload size %d\n",
  1655. __func__, data->payload_size);
  1656. }
  1657. atomic_set(&this_adm.copp.stat[port_idx][copp_idx],
  1658. payload[0]);
  1659. wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
  1660. break;
  1661. case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS:
  1662. pr_debug("%s: ADM_CMDRSP_SHARED_MEM_MAP_REGIONS\n",
  1663. __func__);
  1664. atomic_set(&this_adm.mem_map_handles[
  1665. atomic_read(&this_adm.mem_map_index)],
  1666. *payload);
  1667. atomic_set(&this_adm.adm_stat, 0);
  1668. wake_up(&this_adm.adm_wait);
  1669. break;
  1670. default:
  1671. pr_err("%s: Unknown cmd:0x%x\n", __func__,
  1672. data->opcode);
  1673. break;
  1674. }
  1675. }
  1676. return 0;
  1677. }
  1678. static int adm_memory_map_regions(phys_addr_t *buf_add, uint32_t mempool_id,
  1679. uint32_t *bufsz, uint32_t bufcnt)
  1680. {
  1681. struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
  1682. struct avs_shared_map_region_payload *mregions = NULL;
  1683. void *mmap_region_cmd = NULL;
  1684. void *payload = NULL;
  1685. int ret = 0;
  1686. int i = 0;
  1687. int cmd_size = 0;
  1688. pr_debug("%s:\n", __func__);
  1689. if (this_adm.apr == NULL) {
  1690. this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
  1691. 0xFFFFFFFF, &this_adm);
  1692. if (this_adm.apr == NULL) {
  1693. pr_err("%s: Unable to register ADM\n", __func__);
  1694. ret = -ENODEV;
  1695. return ret;
  1696. }
  1697. rtac_set_adm_handle(this_adm.apr);
  1698. }
  1699. cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
  1700. + sizeof(struct avs_shared_map_region_payload)
  1701. * bufcnt;
  1702. mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
  1703. if (!mmap_region_cmd)
  1704. return -ENOMEM;
  1705. mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd;
  1706. mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1707. APR_HDR_LEN(APR_HDR_SIZE),
  1708. APR_PKT_VER);
  1709. mmap_regions->hdr.pkt_size = cmd_size;
  1710. mmap_regions->hdr.src_port = 0;
  1711. mmap_regions->hdr.dest_port = 0;
  1712. mmap_regions->hdr.token = 0;
  1713. mmap_regions->hdr.opcode = ADM_CMD_SHARED_MEM_MAP_REGIONS;
  1714. mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL & 0x00ff;
  1715. mmap_regions->num_regions = bufcnt & 0x00ff;
  1716. mmap_regions->property_flag = 0x00;
  1717. pr_debug("%s: map_regions->num_regions = %d\n", __func__,
  1718. mmap_regions->num_regions);
  1719. payload = ((u8 *) mmap_region_cmd +
  1720. sizeof(struct avs_cmd_shared_mem_map_regions));
  1721. mregions = (struct avs_shared_map_region_payload *)payload;
  1722. for (i = 0; i < bufcnt; i++) {
  1723. mregions->shm_addr_lsw = lower_32_bits(buf_add[i]);
  1724. mregions->shm_addr_msw =
  1725. msm_audio_populate_upper_32_bits(buf_add[i]);
  1726. mregions->mem_size_bytes = bufsz[i];
  1727. ++mregions;
  1728. }
  1729. atomic_set(&this_adm.adm_stat, -1);
  1730. ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd);
  1731. if (ret < 0) {
  1732. pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
  1733. mmap_regions->hdr.opcode, ret);
  1734. ret = -EINVAL;
  1735. goto fail_cmd;
  1736. }
  1737. ret = wait_event_timeout(this_adm.adm_wait,
  1738. atomic_read(&this_adm.adm_stat) >= 0,
  1739. msecs_to_jiffies(TIMEOUT_MS));
  1740. if (!ret) {
  1741. pr_err("%s: timeout. waited for memory_map\n", __func__);
  1742. ret = -EINVAL;
  1743. goto fail_cmd;
  1744. } else if (atomic_read(&this_adm.adm_stat) > 0) {
  1745. pr_err("%s: DSP returned error[%s]\n",
  1746. __func__, adsp_err_get_err_str(
  1747. atomic_read(&this_adm.adm_stat)));
  1748. ret = adsp_err_get_lnx_err_code(
  1749. atomic_read(&this_adm.adm_stat));
  1750. goto fail_cmd;
  1751. }
  1752. fail_cmd:
  1753. kfree(mmap_region_cmd);
  1754. return ret;
  1755. }
  1756. static int adm_memory_unmap_regions(void)
  1757. {
  1758. struct avs_cmd_shared_mem_unmap_regions unmap_regions;
  1759. int ret = 0;
  1760. pr_debug("%s:\n", __func__);
  1761. if (this_adm.apr == NULL) {
  1762. pr_err("%s: APR handle NULL\n", __func__);
  1763. return -EINVAL;
  1764. }
  1765. unmap_regions.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1766. APR_HDR_LEN(APR_HDR_SIZE),
  1767. APR_PKT_VER);
  1768. unmap_regions.hdr.pkt_size = sizeof(unmap_regions);
  1769. unmap_regions.hdr.src_port = 0;
  1770. unmap_regions.hdr.dest_port = 0;
  1771. unmap_regions.hdr.token = 0;
  1772. unmap_regions.hdr.opcode = ADM_CMD_SHARED_MEM_UNMAP_REGIONS;
  1773. unmap_regions.mem_map_handle = atomic_read(&this_adm.
  1774. mem_map_handles[atomic_read(&this_adm.mem_map_index)]);
  1775. atomic_set(&this_adm.adm_stat, -1);
  1776. ret = apr_send_pkt(this_adm.apr, (uint32_t *) &unmap_regions);
  1777. if (ret < 0) {
  1778. pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
  1779. unmap_regions.hdr.opcode, ret);
  1780. ret = -EINVAL;
  1781. goto fail_cmd;
  1782. }
  1783. ret = wait_event_timeout(this_adm.adm_wait,
  1784. atomic_read(&this_adm.adm_stat) >= 0,
  1785. msecs_to_jiffies(TIMEOUT_MS));
  1786. if (!ret) {
  1787. pr_err("%s: timeout. waited for memory_unmap\n",
  1788. __func__);
  1789. ret = -EINVAL;
  1790. goto fail_cmd;
  1791. } else if (atomic_read(&this_adm.adm_stat) > 0) {
  1792. pr_err("%s: DSP returned error[%s]\n",
  1793. __func__, adsp_err_get_err_str(
  1794. atomic_read(&this_adm.adm_stat)));
  1795. ret = adsp_err_get_lnx_err_code(
  1796. atomic_read(&this_adm.adm_stat));
  1797. goto fail_cmd;
  1798. } else {
  1799. pr_debug("%s: Unmap handle 0x%x succeeded\n", __func__,
  1800. unmap_regions.mem_map_handle);
  1801. }
  1802. fail_cmd:
  1803. return ret;
  1804. }
  1805. static int remap_cal_data(struct cal_block_data *cal_block, int cal_index)
  1806. {
  1807. int ret = 0;
  1808. if (cal_block->map_data.dma_buf == NULL) {
  1809. pr_err("%s: No ION allocation for cal index %d!\n",
  1810. __func__, cal_index);
  1811. ret = -EINVAL;
  1812. goto done;
  1813. }
  1814. if ((cal_block->map_data.map_size > 0) &&
  1815. (cal_block->map_data.q6map_handle == 0)) {
  1816. atomic_set(&this_adm.mem_map_index, cal_index);
  1817. ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
  1818. (uint32_t *)&cal_block->map_data.map_size, 1);
  1819. if (ret < 0) {
  1820. pr_err("%s: ADM mmap did not work! size = %zd ret %d\n",
  1821. __func__,
  1822. cal_block->map_data.map_size, ret);
  1823. pr_debug("%s: ADM mmap did not work! addr = 0x%pK, size = %zd ret %d\n",
  1824. __func__,
  1825. &cal_block->cal_data.paddr,
  1826. cal_block->map_data.map_size, ret);
  1827. goto done;
  1828. }
  1829. cal_block->map_data.q6map_handle = atomic_read(&this_adm.
  1830. mem_map_handles[cal_index]);
  1831. }
  1832. done:
  1833. return ret;
  1834. }
  1835. static void send_adm_custom_topology(void)
  1836. {
  1837. struct cal_block_data *cal_block = NULL;
  1838. struct cmd_set_topologies adm_top;
  1839. int cal_index = ADM_CUSTOM_TOP_CAL;
  1840. int result;
  1841. if (this_adm.cal_data[cal_index] == NULL)
  1842. goto done;
  1843. mutex_lock(&this_adm.cal_data[cal_index]->lock);
  1844. if (!this_adm.set_custom_topology)
  1845. goto unlock;
  1846. this_adm.set_custom_topology = 0;
  1847. cal_block = cal_utils_get_only_cal_block(this_adm.cal_data[cal_index]);
  1848. if (cal_block == NULL || cal_utils_is_cal_stale(cal_block))
  1849. goto unlock;
  1850. pr_debug("%s: Sending cal_index %d\n", __func__, cal_index);
  1851. result = remap_cal_data(cal_block, cal_index);
  1852. if (result) {
  1853. pr_err("%s: Remap_cal_data failed for cal %d!\n",
  1854. __func__, cal_index);
  1855. goto unlock;
  1856. }
  1857. atomic_set(&this_adm.mem_map_index, cal_index);
  1858. atomic_set(&this_adm.mem_map_handles[cal_index],
  1859. cal_block->map_data.q6map_handle);
  1860. if (cal_block->cal_data.size == 0) {
  1861. pr_debug("%s: No ADM cal to send\n", __func__);
  1862. goto unlock;
  1863. }
  1864. adm_top.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1865. APR_HDR_LEN(20), APR_PKT_VER);
  1866. adm_top.hdr.pkt_size = sizeof(adm_top);
  1867. adm_top.hdr.src_svc = APR_SVC_ADM;
  1868. adm_top.hdr.src_domain = APR_DOMAIN_APPS;
  1869. adm_top.hdr.src_port = 0;
  1870. adm_top.hdr.dest_svc = APR_SVC_ADM;
  1871. adm_top.hdr.dest_domain = APR_DOMAIN_ADSP;
  1872. adm_top.hdr.dest_port = 0;
  1873. adm_top.hdr.token = 0;
  1874. adm_top.hdr.opcode = ADM_CMD_ADD_TOPOLOGIES;
  1875. adm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
  1876. adm_top.payload_addr_msw = msm_audio_populate_upper_32_bits(
  1877. cal_block->cal_data.paddr);
  1878. adm_top.mem_map_handle = cal_block->map_data.q6map_handle;
  1879. adm_top.payload_size = cal_block->cal_data.size;
  1880. atomic_set(&this_adm.adm_stat, -1);
  1881. pr_debug("%s: Sending ADM_CMD_ADD_TOPOLOGIES payload = 0x%pK, size = %d\n",
  1882. __func__, &cal_block->cal_data.paddr,
  1883. adm_top.payload_size);
  1884. result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_top);
  1885. if (result < 0) {
  1886. pr_err("%s: Set topologies failed payload size = %zd result %d\n",
  1887. __func__, cal_block->cal_data.size, result);
  1888. goto unlock;
  1889. }
  1890. /* Wait for the callback */
  1891. result = wait_event_timeout(this_adm.adm_wait,
  1892. atomic_read(&this_adm.adm_stat) >= 0,
  1893. msecs_to_jiffies(TIMEOUT_MS));
  1894. if (!result) {
  1895. pr_err("%s: Set topologies timed out payload size = %zd\n",
  1896. __func__, cal_block->cal_data.size);
  1897. goto unlock;
  1898. } else if (atomic_read(&this_adm.adm_stat) > 0) {
  1899. pr_err("%s: DSP returned error[%s]\n",
  1900. __func__, adsp_err_get_err_str(
  1901. atomic_read(&this_adm.adm_stat)));
  1902. result = adsp_err_get_lnx_err_code(
  1903. atomic_read(&this_adm.adm_stat));
  1904. goto unlock;
  1905. }
  1906. unlock:
  1907. mutex_unlock(&this_adm.cal_data[cal_index]->lock);
  1908. done:
  1909. return;
  1910. }
  1911. static int send_adm_cal_block(int port_id, int copp_idx,
  1912. struct cal_block_data *cal_block, int perf_mode)
  1913. {
  1914. struct mem_mapping_hdr mem_hdr;
  1915. int payload_size = 0;
  1916. int port_idx = 0;
  1917. int topology = 0;
  1918. int result = 0;
  1919. pr_debug("%s: Port id 0x%x,\n", __func__, port_id);
  1920. if (!cal_block) {
  1921. pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n",
  1922. __func__, port_id);
  1923. result = -EINVAL;
  1924. goto done;
  1925. }
  1926. if (cal_block->cal_data.size <= 0) {
  1927. pr_debug("%s: No ADM cal sent for port_id = 0x%x!\n", __func__,
  1928. port_id);
  1929. result = -EINVAL;
  1930. goto done;
  1931. }
  1932. memset(&mem_hdr, 0, sizeof(mem_hdr));
  1933. port_id = afe_convert_virtual_to_portid(port_id);
  1934. port_idx = adm_validate_and_get_port_index(port_id);
  1935. if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
  1936. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  1937. return -EINVAL;
  1938. } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  1939. pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
  1940. return -EINVAL;
  1941. }
  1942. topology = atomic_read(&this_adm.copp.topology[port_idx][copp_idx]);
  1943. if (perf_mode == LEGACY_PCM_MODE &&
  1944. topology == DS2_ADM_COPP_TOPOLOGY_ID) {
  1945. pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode,
  1946. topology);
  1947. goto done;
  1948. }
  1949. mem_hdr.data_payload_addr_lsw =
  1950. lower_32_bits(cal_block->cal_data.paddr);
  1951. mem_hdr.data_payload_addr_msw =
  1952. msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
  1953. mem_hdr.mem_map_handle = cal_block->map_data.q6map_handle;
  1954. payload_size = cal_block->cal_data.size;
  1955. adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL, payload_size);
  1956. done:
  1957. return result;
  1958. }
  1959. static struct cal_block_data *adm_find_cal_by_path(int cal_index, int path)
  1960. {
  1961. struct list_head *ptr, *next;
  1962. struct cal_block_data *cal_block = NULL;
  1963. struct audio_cal_info_audproc *audproc_cal_info = NULL;
  1964. struct audio_cal_info_audvol *audvol_cal_info = NULL;
  1965. pr_debug("%s:\n", __func__);
  1966. list_for_each_safe(ptr, next,
  1967. &this_adm.cal_data[cal_index]->cal_blocks) {
  1968. cal_block = list_entry(ptr,
  1969. struct cal_block_data, list);
  1970. if (cal_utils_is_cal_stale(cal_block))
  1971. continue;
  1972. if (cal_index == ADM_AUDPROC_CAL ||
  1973. cal_index == ADM_LSM_AUDPROC_CAL ||
  1974. cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL ||
  1975. cal_index == ADM_AUDPROC_PERSISTENT_CAL) {
  1976. audproc_cal_info = cal_block->cal_info;
  1977. if ((audproc_cal_info->path == path) &&
  1978. (cal_block->cal_data.size > 0))
  1979. return cal_block;
  1980. } else if (cal_index == ADM_AUDVOL_CAL) {
  1981. audvol_cal_info = cal_block->cal_info;
  1982. if ((audvol_cal_info->path == path) &&
  1983. (cal_block->cal_data.size > 0))
  1984. return cal_block;
  1985. }
  1986. }
  1987. pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n",
  1988. __func__, cal_index, path);
  1989. return NULL;
  1990. }
  1991. static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path,
  1992. int app_type)
  1993. {
  1994. struct list_head *ptr, *next;
  1995. struct cal_block_data *cal_block = NULL;
  1996. struct audio_cal_info_audproc *audproc_cal_info = NULL;
  1997. struct audio_cal_info_audvol *audvol_cal_info = NULL;
  1998. pr_debug("%s\n", __func__);
  1999. list_for_each_safe(ptr, next,
  2000. &this_adm.cal_data[cal_index]->cal_blocks) {
  2001. cal_block = list_entry(ptr,
  2002. struct cal_block_data, list);
  2003. if (cal_utils_is_cal_stale(cal_block))
  2004. continue;
  2005. if (cal_index == ADM_AUDPROC_CAL ||
  2006. cal_index == ADM_LSM_AUDPROC_CAL ||
  2007. cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL ||
  2008. cal_index == ADM_AUDPROC_PERSISTENT_CAL) {
  2009. audproc_cal_info = cal_block->cal_info;
  2010. if ((audproc_cal_info->path == path) &&
  2011. (audproc_cal_info->app_type == app_type) &&
  2012. (cal_block->cal_data.size > 0))
  2013. return cal_block;
  2014. } else if (cal_index == ADM_AUDVOL_CAL) {
  2015. audvol_cal_info = cal_block->cal_info;
  2016. if ((audvol_cal_info->path == path) &&
  2017. (audvol_cal_info->app_type == app_type) &&
  2018. (cal_block->cal_data.size > 0))
  2019. return cal_block;
  2020. }
  2021. }
  2022. pr_debug("%s: Can't find ADM cali for cal_index %d, path %d, app %d, defaulting to search by path\n",
  2023. __func__, cal_index, path, app_type);
  2024. return adm_find_cal_by_path(cal_index, path);
  2025. }
  2026. static struct cal_block_data *adm_find_cal(int cal_index, int path,
  2027. int app_type, int acdb_id,
  2028. int sample_rate)
  2029. {
  2030. struct list_head *ptr, *next;
  2031. struct cal_block_data *cal_block = NULL;
  2032. struct audio_cal_info_audproc *audproc_cal_info = NULL;
  2033. struct audio_cal_info_audvol *audvol_cal_info = NULL;
  2034. pr_debug("%s:\n", __func__);
  2035. list_for_each_safe(ptr, next,
  2036. &this_adm.cal_data[cal_index]->cal_blocks) {
  2037. cal_block = list_entry(ptr,
  2038. struct cal_block_data, list);
  2039. if (cal_utils_is_cal_stale(cal_block))
  2040. continue;
  2041. if (cal_index == ADM_AUDPROC_CAL ||
  2042. cal_index == ADM_LSM_AUDPROC_CAL ||
  2043. cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL||
  2044. cal_index == ADM_AUDPROC_PERSISTENT_CAL) {
  2045. audproc_cal_info = cal_block->cal_info;
  2046. if ((audproc_cal_info->path == path) &&
  2047. (audproc_cal_info->app_type == app_type) &&
  2048. (audproc_cal_info->acdb_id == acdb_id) &&
  2049. (audproc_cal_info->sample_rate == sample_rate) &&
  2050. (cal_block->cal_data.size > 0))
  2051. return cal_block;
  2052. } else if (cal_index == ADM_AUDVOL_CAL) {
  2053. audvol_cal_info = cal_block->cal_info;
  2054. if ((audvol_cal_info->path == path) &&
  2055. (audvol_cal_info->app_type == app_type) &&
  2056. (audvol_cal_info->acdb_id == acdb_id) &&
  2057. (cal_block->cal_data.size > 0))
  2058. return cal_block;
  2059. }
  2060. }
  2061. pr_debug("%s: Can't find ADM cal for cal_index %d, path %d, app %d, acdb_id %d sample_rate %d defaulting to search by app type\n",
  2062. __func__, cal_index, path, app_type, acdb_id, sample_rate);
  2063. return adm_find_cal_by_app_type(cal_index, path, app_type);
  2064. }
  2065. static int adm_remap_and_send_cal_block(int cal_index, int port_id,
  2066. int copp_idx, struct cal_block_data *cal_block, int perf_mode,
  2067. int app_type, int acdb_id, int sample_rate)
  2068. {
  2069. int ret = 0;
  2070. pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index);
  2071. ret = remap_cal_data(cal_block, cal_index);
  2072. if (ret) {
  2073. pr_err("%s: Remap_cal_data failed for cal %d!\n",
  2074. __func__, cal_index);
  2075. goto done;
  2076. }
  2077. ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode);
  2078. if (ret < 0)
  2079. pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n",
  2080. __func__, cal_index, port_id, ret, sample_rate);
  2081. done:
  2082. return ret;
  2083. }
  2084. static void send_adm_cal_type(int cal_index, int path, int port_id,
  2085. int copp_idx, int perf_mode, int app_type,
  2086. int acdb_id, int sample_rate)
  2087. {
  2088. struct cal_block_data *cal_block = NULL;
  2089. int ret;
  2090. int dest_perms[2] = {PERM_READ | PERM_WRITE, PERM_READ | PERM_WRITE};
  2091. int source_vm[1] = {VMID_HLOS};
  2092. int dest_vm[2] = {VMID_LPASS, VMID_ADSP_HEAP};
  2093. pr_debug("%s: cal index %d\n", __func__, cal_index);
  2094. if (this_adm.cal_data[cal_index] == NULL) {
  2095. pr_debug("%s: cal_index %d not allocated!\n",
  2096. __func__, cal_index);
  2097. goto done;
  2098. }
  2099. mutex_lock(&this_adm.cal_data[cal_index]->lock);
  2100. cal_block = adm_find_cal(cal_index, path, app_type, acdb_id,
  2101. sample_rate);
  2102. if (cal_block == NULL)
  2103. goto unlock;
  2104. if (cal_block->cma_mem) {
  2105. if (cal_block->cal_data.paddr == 0 ||
  2106. cal_block->map_data.map_size <= 0) {
  2107. pr_err("%s: No address to map!\n", __func__);
  2108. ret = -EINVAL;
  2109. goto unlock;
  2110. }
  2111. ret = hyp_assign_phys(cal_block->cal_data.paddr,
  2112. cal_block->map_data.map_size,
  2113. source_vm, 1, dest_vm, dest_perms, 2);
  2114. if (ret < 0) {
  2115. pr_err("%s: hyp_assign_phys failed result = %d addr = 0x%pK size = %d\n",
  2116. __func__, ret, cal_block->cal_data.paddr,
  2117. cal_block->map_data.map_size);
  2118. ret = -EINVAL;
  2119. goto unlock;
  2120. }
  2121. this_adm.tx_port_id = port_id;
  2122. this_adm.hyp_assigned = true;
  2123. pr_debug("%s: hyp_assign_phys success in tx_port_id 0x%x\n",
  2124. __func__, this_adm.tx_port_id);
  2125. }
  2126. ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx,
  2127. cal_block, perf_mode, app_type, acdb_id, sample_rate);
  2128. cal_utils_mark_cal_used(cal_block);
  2129. unlock:
  2130. mutex_unlock(&this_adm.cal_data[cal_index]->lock);
  2131. done:
  2132. return;
  2133. }
  2134. static int get_cal_path(int path)
  2135. {
  2136. if (path == 0x1)
  2137. return RX_DEVICE;
  2138. else
  2139. return TX_DEVICE;
  2140. }
  2141. static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode,
  2142. int app_type, int acdb_id, int sample_rate,
  2143. int passthr_mode)
  2144. {
  2145. pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx);
  2146. if (passthr_mode != LISTEN) {
  2147. send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx,
  2148. perf_mode, app_type, acdb_id, sample_rate);
  2149. send_adm_cal_type(ADM_AUDPROC_PERSISTENT_CAL, path,
  2150. port_id, copp_idx, perf_mode, app_type,
  2151. acdb_id, sample_rate);
  2152. } else {
  2153. send_adm_cal_type(ADM_LSM_AUDPROC_CAL, path, port_id, copp_idx,
  2154. perf_mode, app_type, acdb_id, sample_rate);
  2155. send_adm_cal_type(ADM_LSM_AUDPROC_PERSISTENT_CAL, path,
  2156. port_id, copp_idx, perf_mode, app_type,
  2157. acdb_id, sample_rate);
  2158. }
  2159. send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode,
  2160. app_type, acdb_id, sample_rate);
  2161. }
  2162. /**
  2163. * adm_connect_afe_port -
  2164. * command to send ADM connect AFE port
  2165. *
  2166. * @mode: value of mode for ADM connect AFE
  2167. * @session_id: session active to connect
  2168. * @port_id: Port ID number
  2169. *
  2170. * Returns 0 on success or error on failure
  2171. */
  2172. int adm_connect_afe_port(int mode, int session_id, int port_id)
  2173. {
  2174. struct adm_cmd_connect_afe_port_v5 cmd;
  2175. int ret = 0;
  2176. int port_idx, copp_idx = 0;
  2177. pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__,
  2178. port_id, session_id, mode);
  2179. port_id = afe_convert_virtual_to_portid(port_id);
  2180. port_idx = adm_validate_and_get_port_index(port_id);
  2181. if (port_idx < 0) {
  2182. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  2183. return -EINVAL;
  2184. }
  2185. if (this_adm.apr == NULL) {
  2186. this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
  2187. 0xFFFFFFFF, &this_adm);
  2188. if (this_adm.apr == NULL) {
  2189. pr_err("%s: Unable to register ADM\n", __func__);
  2190. ret = -ENODEV;
  2191. return ret;
  2192. }
  2193. rtac_set_adm_handle(this_adm.apr);
  2194. }
  2195. pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx);
  2196. cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2197. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2198. cmd.hdr.pkt_size = sizeof(cmd);
  2199. cmd.hdr.src_svc = APR_SVC_ADM;
  2200. cmd.hdr.src_domain = APR_DOMAIN_APPS;
  2201. cmd.hdr.src_port = port_id;
  2202. cmd.hdr.dest_svc = APR_SVC_ADM;
  2203. cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
  2204. cmd.hdr.dest_port = 0; /* Ignored */
  2205. cmd.hdr.token = port_idx << 16 | copp_idx;
  2206. cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5;
  2207. cmd.mode = mode;
  2208. cmd.session_id = session_id;
  2209. cmd.afe_port_id = port_id;
  2210. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  2211. ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd);
  2212. if (ret < 0) {
  2213. pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n",
  2214. __func__, port_id, ret);
  2215. ret = -EINVAL;
  2216. goto fail_cmd;
  2217. }
  2218. /* Wait for the callback with copp id */
  2219. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  2220. atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
  2221. msecs_to_jiffies(TIMEOUT_MS));
  2222. if (!ret) {
  2223. pr_err("%s: ADM connect timedout for port_id: 0x%x\n",
  2224. __func__, port_id);
  2225. ret = -EINVAL;
  2226. goto fail_cmd;
  2227. } else if (atomic_read(&this_adm.copp.stat
  2228. [port_idx][copp_idx]) > 0) {
  2229. pr_err("%s: DSP returned error[%s]\n",
  2230. __func__, adsp_err_get_err_str(
  2231. atomic_read(&this_adm.copp.stat
  2232. [port_idx][copp_idx])));
  2233. ret = adsp_err_get_lnx_err_code(
  2234. atomic_read(&this_adm.copp.stat
  2235. [port_idx][copp_idx]));
  2236. goto fail_cmd;
  2237. }
  2238. atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
  2239. return 0;
  2240. fail_cmd:
  2241. return ret;
  2242. }
  2243. EXPORT_SYMBOL(adm_connect_afe_port);
  2244. int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path,
  2245. int channel_mode, int port_idx)
  2246. {
  2247. int rc = 0, idx;
  2248. pr_debug("%s: channel mode %d", __func__, channel_mode);
  2249. memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
  2250. switch (path) {
  2251. case ADM_PATH_PLAYBACK:
  2252. idx = ADM_MCH_MAP_IDX_PLAYBACK;
  2253. break;
  2254. case ADM_PATH_LIVE_REC:
  2255. case ADM_PATH_NONLIVE_REC:
  2256. idx = ADM_MCH_MAP_IDX_REC;
  2257. break;
  2258. default:
  2259. goto non_mch_path;
  2260. };
  2261. if ((open->dev_num_channel > 2) &&
  2262. (port_channel_map[port_idx].set_channel_map ||
  2263. multi_ch_maps[idx].set_channel_map)) {
  2264. if (port_channel_map[port_idx].set_channel_map)
  2265. memcpy(open->dev_channel_mapping,
  2266. port_channel_map[port_idx].channel_mapping,
  2267. PCM_FORMAT_MAX_NUM_CHANNEL);
  2268. else
  2269. memcpy(open->dev_channel_mapping,
  2270. multi_ch_maps[idx].channel_mapping,
  2271. PCM_FORMAT_MAX_NUM_CHANNEL);
  2272. } else {
  2273. if (channel_mode == 1) {
  2274. open->dev_channel_mapping[0] = PCM_CHANNEL_FC;
  2275. } else if (channel_mode == 2) {
  2276. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2277. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2278. } else if (channel_mode == 3) {
  2279. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2280. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2281. open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2282. } else if (channel_mode == 4) {
  2283. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2284. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2285. open->dev_channel_mapping[2] = PCM_CHANNEL_LS;
  2286. open->dev_channel_mapping[3] = PCM_CHANNEL_RS;
  2287. } else if (channel_mode == 5) {
  2288. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2289. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2290. open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2291. open->dev_channel_mapping[3] = PCM_CHANNEL_LS;
  2292. open->dev_channel_mapping[4] = PCM_CHANNEL_RS;
  2293. } else if (channel_mode == 6) {
  2294. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2295. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2296. open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2297. open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2298. open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2299. open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2300. } else if (channel_mode == 7) {
  2301. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2302. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2303. open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2304. open->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
  2305. open->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2306. open->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2307. open->dev_channel_mapping[6] = PCM_CHANNEL_CS;
  2308. } else if (channel_mode == 8) {
  2309. open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2310. open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2311. open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2312. open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2313. open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2314. open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2315. open->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2316. open->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2317. } else {
  2318. pr_err("%s: invalid num_chan %d\n", __func__,
  2319. channel_mode);
  2320. rc = -EINVAL;
  2321. goto inval_ch_mod;
  2322. }
  2323. }
  2324. non_mch_path:
  2325. inval_ch_mod:
  2326. return rc;
  2327. }
  2328. int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6,
  2329. int channel_mode)
  2330. {
  2331. int rc = 0;
  2332. memset(open_v6->dev_channel_mapping_eid2, 0,
  2333. PCM_FORMAT_MAX_NUM_CHANNEL);
  2334. if (channel_mode == 1) {
  2335. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC;
  2336. } else if (channel_mode == 2) {
  2337. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2338. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2339. } else if (channel_mode == 3) {
  2340. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2341. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2342. open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
  2343. } else if (channel_mode == 4) {
  2344. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2345. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2346. open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LS;
  2347. open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS;
  2348. } else if (channel_mode == 5) {
  2349. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2350. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2351. open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
  2352. open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS;
  2353. open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS;
  2354. } else if (channel_mode == 6) {
  2355. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2356. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2357. open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
  2358. open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
  2359. open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
  2360. open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
  2361. } else if (channel_mode == 8) {
  2362. open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
  2363. open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
  2364. open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
  2365. open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
  2366. open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
  2367. open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
  2368. open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB;
  2369. open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB;
  2370. } else {
  2371. pr_err("%s: invalid num_chan %d\n", __func__,
  2372. channel_mode);
  2373. rc = -EINVAL;
  2374. }
  2375. return rc;
  2376. }
  2377. static int adm_arrange_mch_map_v8(
  2378. struct adm_device_endpoint_payload *ep_payload,
  2379. int path, int channel_mode, int port_idx)
  2380. {
  2381. int rc = 0, idx;
  2382. memset(ep_payload->dev_channel_mapping,
  2383. 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  2384. switch (path) {
  2385. case ADM_PATH_PLAYBACK:
  2386. idx = ADM_MCH_MAP_IDX_PLAYBACK;
  2387. break;
  2388. case ADM_PATH_LIVE_REC:
  2389. case ADM_PATH_NONLIVE_REC:
  2390. idx = ADM_MCH_MAP_IDX_REC;
  2391. break;
  2392. default:
  2393. goto non_mch_path;
  2394. };
  2395. if ((ep_payload->dev_num_channel > 2) &&
  2396. (port_channel_map[port_idx].set_channel_map ||
  2397. multi_ch_maps[idx].set_channel_map)) {
  2398. if (port_channel_map[port_idx].set_channel_map)
  2399. memcpy(ep_payload->dev_channel_mapping,
  2400. port_channel_map[port_idx].channel_mapping,
  2401. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  2402. else
  2403. memcpy(ep_payload->dev_channel_mapping,
  2404. multi_ch_maps[idx].channel_mapping,
  2405. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  2406. } else {
  2407. if (channel_mode == 1) {
  2408. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC;
  2409. } else if (channel_mode == 2) {
  2410. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2411. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2412. } else if (channel_mode == 3) {
  2413. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2414. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2415. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2416. } else if (channel_mode == 4) {
  2417. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2418. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2419. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS;
  2420. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS;
  2421. } else if (channel_mode == 5) {
  2422. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2423. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2424. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2425. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS;
  2426. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS;
  2427. } else if (channel_mode == 6) {
  2428. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2429. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2430. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2431. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2432. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2433. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2434. } else if (channel_mode == 7) {
  2435. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2436. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2437. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2438. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
  2439. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2440. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2441. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_CS;
  2442. } else if (channel_mode == 8) {
  2443. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2444. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2445. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2446. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2447. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2448. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2449. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2450. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2451. } else if (channel_mode == 10) {
  2452. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2453. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2454. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2455. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2456. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2457. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2458. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
  2459. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
  2460. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
  2461. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
  2462. } else if (channel_mode == 12) {
  2463. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2464. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2465. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2466. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2467. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2468. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2469. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
  2470. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
  2471. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
  2472. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
  2473. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
  2474. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
  2475. } else if (channel_mode == 14) {
  2476. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2477. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2478. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2479. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2480. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2481. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2482. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
  2483. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
  2484. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
  2485. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
  2486. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
  2487. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
  2488. ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
  2489. ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
  2490. } else if (channel_mode == 16) {
  2491. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2492. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2493. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2494. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2495. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
  2496. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
  2497. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
  2498. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
  2499. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
  2500. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
  2501. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
  2502. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
  2503. ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
  2504. ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
  2505. ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
  2506. ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
  2507. } else if (channel_mode == 32) {
  2508. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2509. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2510. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2511. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2512. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2513. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2514. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2515. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2516. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
  2517. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TS;
  2518. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_CVH;
  2519. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_MS;
  2520. ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
  2521. ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
  2522. ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
  2523. ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
  2524. ep_payload->dev_channel_mapping[16] = PCM_CHANNEL_LFE2;
  2525. ep_payload->dev_channel_mapping[17] = PCM_CHANNEL_SL;
  2526. ep_payload->dev_channel_mapping[18] = PCM_CHANNEL_SR;
  2527. ep_payload->dev_channel_mapping[19] = PCM_CHANNEL_TFL;
  2528. ep_payload->dev_channel_mapping[20] = PCM_CHANNEL_TFR;
  2529. ep_payload->dev_channel_mapping[21] = PCM_CHANNEL_TC;
  2530. ep_payload->dev_channel_mapping[22] = PCM_CHANNEL_TBL;
  2531. ep_payload->dev_channel_mapping[23] = PCM_CHANNEL_TBR;
  2532. ep_payload->dev_channel_mapping[24] = PCM_CHANNEL_TSL;
  2533. ep_payload->dev_channel_mapping[25] = PCM_CHANNEL_TSR;
  2534. ep_payload->dev_channel_mapping[26] = PCM_CHANNEL_TBC;
  2535. ep_payload->dev_channel_mapping[27] = PCM_CHANNEL_BFC;
  2536. ep_payload->dev_channel_mapping[28] = PCM_CHANNEL_BFL;
  2537. ep_payload->dev_channel_mapping[29] = PCM_CHANNEL_BFR;
  2538. ep_payload->dev_channel_mapping[30] = PCM_CHANNEL_LW;
  2539. ep_payload->dev_channel_mapping[31] = PCM_CHANNEL_RW;
  2540. } else {
  2541. pr_err("%s: invalid num_chan %d\n", __func__,
  2542. channel_mode);
  2543. rc = -EINVAL;
  2544. goto inval_ch_mod;
  2545. }
  2546. }
  2547. non_mch_path:
  2548. inval_ch_mod:
  2549. return rc;
  2550. }
  2551. static int adm_arrange_mch_ep2_map_v8(
  2552. struct adm_device_endpoint_payload *ep_payload,
  2553. int channel_mode)
  2554. {
  2555. int rc = 0;
  2556. memset(ep_payload->dev_channel_mapping, 0,
  2557. PCM_FORMAT_MAX_NUM_CHANNEL_V8);
  2558. if (channel_mode == 1) {
  2559. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC;
  2560. } else if (channel_mode == 2) {
  2561. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2562. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2563. } else if (channel_mode == 3) {
  2564. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2565. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2566. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2567. } else if (channel_mode == 4) {
  2568. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2569. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2570. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS;
  2571. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS;
  2572. } else if (channel_mode == 5) {
  2573. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2574. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2575. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
  2576. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS;
  2577. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS;
  2578. } else if (channel_mode == 6) {
  2579. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2580. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2581. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2582. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2583. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2584. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2585. } else if (channel_mode == 8) {
  2586. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2587. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2588. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2589. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2590. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2591. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2592. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2593. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2594. } else if (channel_mode == 10) {
  2595. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2596. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2597. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2598. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2599. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2600. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2601. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2602. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2603. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
  2604. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TS;
  2605. } else if (channel_mode == 12) {
  2606. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2607. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2608. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2609. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2610. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2611. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2612. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2613. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2614. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
  2615. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
  2616. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
  2617. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
  2618. } else if (channel_mode == 16) {
  2619. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2620. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2621. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2622. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2623. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2624. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2625. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2626. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2627. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
  2628. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TS;
  2629. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_CVH;
  2630. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_MS;
  2631. ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
  2632. ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
  2633. ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
  2634. ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
  2635. } else if (channel_mode == 32) {
  2636. ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
  2637. ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
  2638. ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
  2639. ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
  2640. ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
  2641. ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
  2642. ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
  2643. ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
  2644. ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
  2645. ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TS;
  2646. ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_CVH;
  2647. ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_MS;
  2648. ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
  2649. ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
  2650. ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
  2651. ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
  2652. ep_payload->dev_channel_mapping[16] = PCM_CHANNEL_LFE2;
  2653. ep_payload->dev_channel_mapping[17] = PCM_CHANNEL_SL;
  2654. ep_payload->dev_channel_mapping[18] = PCM_CHANNEL_SR;
  2655. ep_payload->dev_channel_mapping[19] = PCM_CHANNEL_TFL;
  2656. ep_payload->dev_channel_mapping[20] = PCM_CHANNEL_TFR;
  2657. ep_payload->dev_channel_mapping[21] = PCM_CHANNEL_TC;
  2658. ep_payload->dev_channel_mapping[22] = PCM_CHANNEL_TBL;
  2659. ep_payload->dev_channel_mapping[23] = PCM_CHANNEL_TBR;
  2660. ep_payload->dev_channel_mapping[24] = PCM_CHANNEL_TSL;
  2661. ep_payload->dev_channel_mapping[25] = PCM_CHANNEL_TSR;
  2662. ep_payload->dev_channel_mapping[26] = PCM_CHANNEL_TBC;
  2663. ep_payload->dev_channel_mapping[27] = PCM_CHANNEL_BFC;
  2664. ep_payload->dev_channel_mapping[28] = PCM_CHANNEL_BFL;
  2665. ep_payload->dev_channel_mapping[29] = PCM_CHANNEL_BFR;
  2666. ep_payload->dev_channel_mapping[30] = PCM_CHANNEL_LW;
  2667. ep_payload->dev_channel_mapping[31] = PCM_CHANNEL_RW;
  2668. } else {
  2669. pr_err("%s: invalid num_chan %d\n", __func__,
  2670. channel_mode);
  2671. rc = -EINVAL;
  2672. }
  2673. return rc;
  2674. }
  2675. static int adm_copp_set_ec_ref_mfc_cfg(int port_id, int copp_idx,
  2676. int sample_rate, int bps,
  2677. int in_channels, int out_channels)
  2678. {
  2679. struct audproc_mfc_param_media_fmt mfc_cfg;
  2680. struct param_hdr_v3 param_hdr;
  2681. u16 *chmixer_params = NULL;
  2682. int rc = 0, i = 0, j = 0, param_index = 0, param_size = 0;
  2683. struct adm_device_endpoint_payload ep_payload = {0, 0, 0, {0}};
  2684. memset(&mfc_cfg, 0, sizeof(mfc_cfg));
  2685. memset(&ep_payload, 0, sizeof(ep_payload));
  2686. memset(&param_hdr, 0, sizeof(param_hdr));
  2687. param_hdr.module_id = AUDPROC_MODULE_ID_MFC_EC_REF;
  2688. param_hdr.instance_id = INSTANCE_ID_0;
  2689. pr_debug("%s: port_id %d copp_idx %d SR %d, BW %d in_ch %d out_ch %d\n",
  2690. __func__, port_id, copp_idx, sample_rate,
  2691. bps, in_channels, out_channels);
  2692. if (out_channels <= 0 || out_channels > AUDPROC_MFC_OUT_CHANNELS_MAX) {
  2693. pr_err("%s: unsupported out channels=%d\n", __func__, out_channels);
  2694. return -EINVAL;
  2695. }
  2696. /* 1. Update Media Format */
  2697. param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
  2698. param_hdr.param_size = sizeof(mfc_cfg);
  2699. mfc_cfg.sampling_rate = sample_rate;
  2700. mfc_cfg.bits_per_sample = bps;
  2701. mfc_cfg.num_channels = out_channels;
  2702. ep_payload.dev_num_channel = out_channels;
  2703. rc = adm_arrange_mch_ep2_map_v8(&ep_payload, out_channels);
  2704. if (rc < 0) {
  2705. pr_err("%s: unable to get map for out channels=%d\n",
  2706. __func__, out_channels);
  2707. return -EINVAL;
  2708. }
  2709. for (i = 0; i < out_channels; i++)
  2710. mfc_cfg.channel_type[i] = (uint16_t) ep_payload.dev_channel_mapping[i];
  2711. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx,
  2712. param_hdr, (uint8_t *) &mfc_cfg);
  2713. if (rc) {
  2714. pr_err("%s: Failed to set media format, err %d\n", __func__, rc);
  2715. return rc;
  2716. }
  2717. /* 2. Send Channel Mixer params */
  2718. param_size = 2 * (4 + out_channels + in_channels + (out_channels * in_channels));
  2719. param_size = round_up(param_size, 4);
  2720. param_hdr.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF;
  2721. param_hdr.param_size = param_size;
  2722. pr_debug("%s: chmixer param sz = %d\n", __func__, param_size);
  2723. chmixer_params = kzalloc(param_size, GFP_KERNEL);
  2724. if (!chmixer_params) {
  2725. return -ENOMEM;
  2726. }
  2727. param_index = 2; /* param[0] and [1] represents chmixer rule(always 0) */
  2728. chmixer_params[param_index++] = out_channels;
  2729. chmixer_params[param_index++] = in_channels;
  2730. /* output channel map is same as one set in media format */
  2731. for (i = 0; i < out_channels; i++)
  2732. chmixer_params[param_index++] = ep_payload.dev_channel_mapping[i];
  2733. /* input channel map should be same as one set for ep2 during copp open */
  2734. ep_payload.dev_num_channel = in_channels;
  2735. rc = adm_arrange_mch_ep2_map_v8(&ep_payload, in_channels);
  2736. if (rc < 0) {
  2737. pr_err("%s: unable to get in channal map\n", __func__);
  2738. goto exit;
  2739. }
  2740. for (i = 0; i < in_channels; i++)
  2741. chmixer_params[param_index++] = ep_payload.dev_channel_mapping[i];
  2742. for (i = 0; i < out_channels; i++)
  2743. for (j = 0; j < in_channels; j++)
  2744. chmixer_params[param_index++] = this_adm.ec_ref_chmixer_weights[i][j];
  2745. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx,
  2746. param_hdr, (uint8_t *) chmixer_params);
  2747. if (rc)
  2748. pr_err("%s: Failed to set chmixer params, err %d\n", __func__, rc);
  2749. exit:
  2750. kfree(chmixer_params);
  2751. return rc;
  2752. }
  2753. /**
  2754. * adm_open -
  2755. * command to send ADM open
  2756. *
  2757. * @port_id: port id number
  2758. * @path: direction or ADM path type
  2759. * @rate: sample rate of session
  2760. * @channel_mode: number of channels set
  2761. * @topology: topology active for this session
  2762. * @perf_mode: performance mode like LL/ULL/..
  2763. * @bit_width: bit width to set for copp
  2764. * @app_type: App type used for this session
  2765. * @acdb_id: ACDB ID of this device
  2766. * @session_type: type of session
  2767. *
  2768. * Returns 0 on success or error on failure
  2769. */
  2770. int adm_open(int port_id, int path, int rate, int channel_mode, int topology,
  2771. int perf_mode, uint16_t bit_width, int app_type, int acdb_id,
  2772. int session_type, uint32_t passthr_mode, uint32_t copp_token)
  2773. {
  2774. struct adm_cmd_device_open_v5 open;
  2775. struct adm_cmd_device_open_v6 open_v6;
  2776. struct adm_cmd_device_open_v8 open_v8;
  2777. struct adm_device_endpoint_payload ep1_payload;
  2778. struct adm_device_endpoint_payload ep2_payload;
  2779. int ep1_payload_size = 0;
  2780. int ep2_payload_size = 0;
  2781. int ret = 0;
  2782. int port_idx, flags;
  2783. int copp_idx = -1;
  2784. int tmp_port = q6audio_get_port_id(port_id);
  2785. void *adm_params = NULL;
  2786. int param_size;
  2787. int num_ec_ref_rx_chans = this_adm.num_ec_ref_rx_chans;
  2788. pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n",
  2789. __func__, port_id, path, rate, channel_mode, perf_mode,
  2790. topology);
  2791. port_id = q6audio_convert_virtual_to_portid(port_id);
  2792. port_idx = adm_validate_and_get_port_index(port_id);
  2793. if (port_idx < 0) {
  2794. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  2795. return -EINVAL;
  2796. }
  2797. if (channel_mode < 0 || channel_mode > 32) {
  2798. pr_err("%s: Invalid channel number 0x%x\n",
  2799. __func__, channel_mode);
  2800. return -EINVAL;
  2801. }
  2802. if (this_adm.apr == NULL) {
  2803. this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
  2804. 0xFFFFFFFF, &this_adm);
  2805. if (this_adm.apr == NULL) {
  2806. pr_err("%s: Unable to register ADM\n", __func__);
  2807. return -ENODEV;
  2808. }
  2809. rtac_set_adm_handle(this_adm.apr);
  2810. }
  2811. if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) {
  2812. flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION;
  2813. if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
  2814. (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
  2815. (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
  2816. topology = DEFAULT_COPP_TOPOLOGY;
  2817. } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
  2818. flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION;
  2819. topology = NULL_COPP_TOPOLOGY;
  2820. rate = ULL_SUPPORTED_SAMPLE_RATE;
  2821. bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE;
  2822. } else if (perf_mode == LOW_LATENCY_PCM_MODE) {
  2823. flags = ADM_LOW_LATENCY_DEVICE_SESSION;
  2824. if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
  2825. (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
  2826. (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
  2827. topology = DEFAULT_COPP_TOPOLOGY;
  2828. } else {
  2829. if ((path == ADM_PATH_COMPRESSED_RX) ||
  2830. (path == ADM_PATH_COMPRESSED_TX))
  2831. flags = 0;
  2832. else
  2833. flags = ADM_LEGACY_DEVICE_SESSION;
  2834. }
  2835. if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) ||
  2836. (topology == VPM_TX_DM_FLUENCE_EF_COPP_TOPOLOGY)) {
  2837. if ((rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_8K) &&
  2838. (rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_16K) &&
  2839. (rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_32K) &&
  2840. (rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_48K))
  2841. rate = 16000;
  2842. }
  2843. if ((topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) ||
  2844. (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY)) {
  2845. if ((rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_8K) &&
  2846. (rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_16K) &&
  2847. (rate != ADM_CMD_COPP_OPEN_SAMPLE_RATE_32K))
  2848. rate = 16000;
  2849. }
  2850. if (topology == FFECNS_TOPOLOGY) {
  2851. this_adm.ffecns_port_id = port_id;
  2852. pr_debug("%s: ffecns port id =%x\n", __func__,
  2853. this_adm.ffecns_port_id);
  2854. }
  2855. if (topology == VPM_TX_VOICE_SMECNS_V2_COPP_TOPOLOGY ||
  2856. topology == VPM_TX_VOICE_FLUENCE_SM_COPP_TOPOLOGY)
  2857. channel_mode = 1;
  2858. /*
  2859. * Routing driver reuses the same adm for streams with the same
  2860. * app_type, sample_rate etc.
  2861. * This isn't allowed for ULL streams as per the DSP interface
  2862. */
  2863. if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE)
  2864. copp_idx = adm_get_idx_if_copp_exists(port_idx, topology,
  2865. perf_mode,
  2866. rate, bit_width,
  2867. app_type, session_type, copp_token);
  2868. if (copp_idx < 0) {
  2869. copp_idx = adm_get_next_available_copp(port_idx);
  2870. if (copp_idx >= MAX_COPPS_PER_PORT) {
  2871. pr_err("%s: exceeded copp id %d\n",
  2872. __func__, copp_idx);
  2873. return -EINVAL;
  2874. }
  2875. atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
  2876. atomic_set(&this_adm.copp.topology[port_idx][copp_idx],
  2877. topology);
  2878. atomic_set(&this_adm.copp.mode[port_idx][copp_idx],
  2879. perf_mode);
  2880. atomic_set(&this_adm.copp.rate[port_idx][copp_idx],
  2881. rate);
  2882. atomic_set(&this_adm.copp.channels[port_idx][copp_idx],
  2883. channel_mode);
  2884. atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx],
  2885. bit_width);
  2886. atomic_set(&this_adm.copp.app_type[port_idx][copp_idx],
  2887. app_type);
  2888. atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx],
  2889. acdb_id);
  2890. atomic_set(&this_adm.copp.session_type[port_idx][copp_idx],
  2891. session_type);
  2892. atomic_set(&this_adm.copp.token[port_idx][copp_idx],
  2893. copp_token);
  2894. set_bit(ADM_STATUS_CALIBRATION_REQUIRED,
  2895. (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
  2896. if ((path != ADM_PATH_COMPRESSED_RX) &&
  2897. (path != ADM_PATH_COMPRESSED_TX))
  2898. send_adm_custom_topology();
  2899. }
  2900. if (this_adm.copp.adm_delay[port_idx][copp_idx] &&
  2901. perf_mode == LEGACY_PCM_MODE) {
  2902. atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
  2903. 1);
  2904. this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
  2905. wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
  2906. }
  2907. /* Create a COPP if port id are not enabled */
  2908. if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) {
  2909. pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__,
  2910. port_idx, copp_idx);
  2911. if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) &&
  2912. perf_mode == LEGACY_PCM_MODE) {
  2913. int res;
  2914. atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA);
  2915. msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap);
  2916. res = adm_memory_map_regions(
  2917. &this_adm.outband_memmap.paddr, 0,
  2918. (uint32_t *)&this_adm.outband_memmap.size, 1);
  2919. if (res < 0) {
  2920. pr_err("%s: SRS adm_memory_map_regions failed! addr = 0x%pK, size = %d\n",
  2921. __func__,
  2922. (void *)this_adm.outband_memmap.paddr,
  2923. (uint32_t)this_adm.outband_memmap.size);
  2924. }
  2925. }
  2926. if ((q6core_get_avcs_api_version_per_service(
  2927. APRV2_IDS_SERVICE_ID_ADSP_ADM_V) >=
  2928. ADSP_ADM_API_VERSION_V3)) {
  2929. memset(&open_v8, 0, sizeof(open_v8));
  2930. memset(&ep1_payload, 0, sizeof(ep1_payload));
  2931. memset(&ep2_payload, 0, sizeof(ep2_payload));
  2932. open_v8.hdr.hdr_field = APR_HDR_FIELD(
  2933. APR_MSG_TYPE_SEQ_CMD,
  2934. APR_HDR_LEN(APR_HDR_SIZE),
  2935. APR_PKT_VER);
  2936. open_v8.hdr.src_svc = APR_SVC_ADM;
  2937. open_v8.hdr.src_domain = APR_DOMAIN_APPS;
  2938. open_v8.hdr.src_port = tmp_port;
  2939. open_v8.hdr.dest_svc = APR_SVC_ADM;
  2940. open_v8.hdr.dest_domain = APR_DOMAIN_ADSP;
  2941. open_v8.hdr.dest_port = tmp_port;
  2942. open_v8.hdr.token = port_idx << 16 | copp_idx;
  2943. open_v8.hdr.opcode = ADM_CMD_DEVICE_OPEN_V8;
  2944. if (this_adm.native_mode != 0) {
  2945. open_v8.flags = flags |
  2946. (this_adm.native_mode << 11);
  2947. this_adm.native_mode = 0;
  2948. } else {
  2949. open_v8.flags = flags;
  2950. }
  2951. open_v8.mode_of_operation = path;
  2952. open_v8.endpoint_id_1 = tmp_port;
  2953. open_v8.endpoint_id_2 = 0xFFFF;
  2954. open_v8.endpoint_id_3 = 0xFFFF;
  2955. if (((this_adm.ec_ref_rx & AFE_PORT_INVALID) !=
  2956. AFE_PORT_INVALID) &&
  2957. (path != ADM_PATH_PLAYBACK)) {
  2958. if (this_adm.num_ec_ref_rx_chans != 0) {
  2959. open_v8.endpoint_id_2 =
  2960. this_adm.ec_ref_rx;
  2961. this_adm.ec_ref_rx = AFE_PORT_INVALID;
  2962. } else {
  2963. pr_err("%s: EC channels not set %d\n",
  2964. __func__,
  2965. this_adm.num_ec_ref_rx_chans);
  2966. return -EINVAL;
  2967. }
  2968. }
  2969. open_v8.topology_id = topology;
  2970. open_v8.compressed_data_type = 0;
  2971. if (passthr_mode == COMPRESSED_PASSTHROUGH_DSD)
  2972. open_v8.compressed_data_type = 1;
  2973. /* variable endpoint payload */
  2974. ep1_payload.dev_num_channel = channel_mode & 0x00FF;
  2975. ep1_payload.bit_width = bit_width;
  2976. ep1_payload.sample_rate = rate;
  2977. ret = adm_arrange_mch_map_v8(&ep1_payload, path,
  2978. channel_mode, port_idx);
  2979. if (ret)
  2980. return ret;
  2981. pr_debug("%s: port_id=0x%x %x %x topology_id=0x%X flags %x ref_ch %x\n",
  2982. __func__, open_v8.endpoint_id_1,
  2983. open_v8.endpoint_id_2,
  2984. open_v8.endpoint_id_3,
  2985. open_v8.topology_id,
  2986. open_v8.flags,
  2987. this_adm.num_ec_ref_rx_chans);
  2988. ep1_payload_size = 8 +
  2989. roundup(ep1_payload.dev_num_channel, 4);
  2990. param_size = sizeof(struct adm_cmd_device_open_v8)
  2991. + ep1_payload_size;
  2992. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  2993. if ((this_adm.num_ec_ref_rx_chans != 0)
  2994. && (path != ADM_PATH_PLAYBACK)
  2995. && (open_v8.endpoint_id_2 != 0xFFFF)) {
  2996. ep2_payload.dev_num_channel =
  2997. this_adm.num_ec_ref_rx_chans;
  2998. if (this_adm.ec_ref_rx_bit_width != 0) {
  2999. ep2_payload.bit_width =
  3000. this_adm.ec_ref_rx_bit_width;
  3001. } else {
  3002. ep2_payload.bit_width = bit_width;
  3003. }
  3004. if (this_adm.ec_ref_rx_sampling_rate != 0) {
  3005. ep2_payload.sample_rate =
  3006. this_adm.ec_ref_rx_sampling_rate;
  3007. } else {
  3008. ep2_payload.sample_rate = rate;
  3009. }
  3010. pr_debug("%s: adm open_v8 eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
  3011. __func__,
  3012. ep2_payload.dev_num_channel,
  3013. ep2_payload.bit_width,
  3014. ep2_payload.sample_rate);
  3015. ret = adm_arrange_mch_ep2_map_v8(&ep2_payload,
  3016. ep2_payload.dev_num_channel);
  3017. if (ret)
  3018. return ret;
  3019. ep2_payload_size = 8 +
  3020. roundup(ep2_payload.dev_num_channel, 4);
  3021. param_size += ep2_payload_size;
  3022. }
  3023. open_v8.hdr.pkt_size = param_size;
  3024. adm_params = kzalloc(param_size, GFP_KERNEL);
  3025. if (!adm_params)
  3026. return -ENOMEM;
  3027. memcpy(adm_params, &open_v8, sizeof(open_v8));
  3028. memcpy(adm_params + sizeof(open_v8),
  3029. (void *)&ep1_payload,
  3030. ep1_payload_size);
  3031. if ((this_adm.num_ec_ref_rx_chans != 0)
  3032. && (path != ADM_PATH_PLAYBACK)
  3033. && (open_v8.endpoint_id_2 != 0xFFFF)) {
  3034. memcpy(adm_params + sizeof(open_v8)
  3035. + ep1_payload_size,
  3036. (void *)&ep2_payload,
  3037. ep2_payload_size);
  3038. }
  3039. ret = apr_send_pkt(this_adm.apr,
  3040. (uint32_t *)adm_params);
  3041. if (ret < 0) {
  3042. pr_err("%s: port_id: 0x%x for[0x%x] failed %d for open_v8\n",
  3043. __func__, tmp_port, port_id, ret);
  3044. return -EINVAL;
  3045. }
  3046. kfree(adm_params);
  3047. } else {
  3048. open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3049. APR_HDR_LEN(APR_HDR_SIZE),
  3050. APR_PKT_VER);
  3051. open.hdr.pkt_size = sizeof(open);
  3052. open.hdr.src_svc = APR_SVC_ADM;
  3053. open.hdr.src_domain = APR_DOMAIN_APPS;
  3054. open.hdr.src_port = tmp_port;
  3055. open.hdr.dest_svc = APR_SVC_ADM;
  3056. open.hdr.dest_domain = APR_DOMAIN_ADSP;
  3057. open.hdr.dest_port = tmp_port;
  3058. open.hdr.token = port_idx << 16 | copp_idx;
  3059. open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5;
  3060. open.flags = flags;
  3061. open.mode_of_operation = path;
  3062. open.endpoint_id_1 = tmp_port;
  3063. open.endpoint_id_2 = 0xFFFF;
  3064. if (this_adm.ec_ref_rx && (path != 1) &&
  3065. (afe_get_port_type(tmp_port) == MSM_AFE_PORT_TYPE_TX)) {
  3066. open.endpoint_id_2 = this_adm.ec_ref_rx;
  3067. }
  3068. open.topology_id = topology;
  3069. open.dev_num_channel = channel_mode & 0x00FF;
  3070. open.bit_width = bit_width;
  3071. WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) &&
  3072. (rate != ULL_SUPPORTED_SAMPLE_RATE));
  3073. open.sample_rate = rate;
  3074. ret = adm_arrange_mch_map(&open, path, channel_mode,
  3075. port_idx);
  3076. if (ret)
  3077. return ret;
  3078. pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n",
  3079. __func__, open.endpoint_id_1, open.sample_rate,
  3080. open.topology_id);
  3081. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  3082. if ((this_adm.num_ec_ref_rx_chans != 0) &&
  3083. (path != 1) && (open.endpoint_id_2 != 0xFFFF)) {
  3084. memset(&open_v6, 0,
  3085. sizeof(struct adm_cmd_device_open_v6));
  3086. memcpy(&open_v6, &open,
  3087. sizeof(struct adm_cmd_device_open_v5));
  3088. open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6;
  3089. open_v6.hdr.pkt_size = sizeof(open_v6);
  3090. open_v6.dev_num_channel_eid2 =
  3091. this_adm.num_ec_ref_rx_chans;
  3092. if (this_adm.ec_ref_rx_bit_width != 0) {
  3093. open_v6.bit_width_eid2 =
  3094. this_adm.ec_ref_rx_bit_width;
  3095. } else {
  3096. open_v6.bit_width_eid2 = bit_width;
  3097. }
  3098. if (this_adm.ec_ref_rx_sampling_rate != 0) {
  3099. open_v6.sample_rate_eid2 =
  3100. this_adm.ec_ref_rx_sampling_rate;
  3101. } else {
  3102. open_v6.sample_rate_eid2 = rate;
  3103. }
  3104. pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
  3105. __func__, open_v6.dev_num_channel_eid2,
  3106. open_v6.bit_width_eid2,
  3107. open_v6.sample_rate_eid2);
  3108. ret = adm_arrange_mch_ep2_map(&open_v6,
  3109. open_v6.dev_num_channel_eid2);
  3110. if (ret)
  3111. return ret;
  3112. ret = apr_send_pkt(this_adm.apr,
  3113. (uint32_t *)&open_v6);
  3114. } else {
  3115. ret = apr_send_pkt(this_adm.apr,
  3116. (uint32_t *)&open);
  3117. }
  3118. if (ret < 0) {
  3119. pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n",
  3120. __func__, tmp_port, port_id, ret);
  3121. return -EINVAL;
  3122. }
  3123. }
  3124. /* Wait for the callback with copp id */
  3125. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  3126. atomic_read(&this_adm.copp.stat
  3127. [port_idx][copp_idx]) >= 0,
  3128. msecs_to_jiffies(2 * TIMEOUT_MS));
  3129. if (!ret) {
  3130. pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n",
  3131. __func__, tmp_port, port_id);
  3132. return -EINVAL;
  3133. } else if (atomic_read(&this_adm.copp.stat
  3134. [port_idx][copp_idx]) > 0) {
  3135. pr_err("%s: DSP returned error[%s]\n",
  3136. __func__, adsp_err_get_err_str(
  3137. atomic_read(&this_adm.copp.stat
  3138. [port_idx][copp_idx])));
  3139. return adsp_err_get_lnx_err_code(
  3140. atomic_read(&this_adm.copp.stat
  3141. [port_idx][copp_idx]));
  3142. }
  3143. }
  3144. atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
  3145. /*
  3146. * Configure MFC(in ec_ref path) if chmixing param is applicable and set.
  3147. * Except channels and channel maps the media format config for this module
  3148. * should match with the COPP(EP1) config values.
  3149. */
  3150. if (path != ADM_PATH_PLAYBACK &&
  3151. this_adm.num_ec_ref_rx_chans_downmixed != 0 &&
  3152. num_ec_ref_rx_chans != this_adm.num_ec_ref_rx_chans_downmixed) {
  3153. ret = adm_copp_set_ec_ref_mfc_cfg(port_id, copp_idx,
  3154. rate, bit_width, num_ec_ref_rx_chans,
  3155. this_adm.num_ec_ref_rx_chans_downmixed);
  3156. this_adm.num_ec_ref_rx_chans_downmixed = 0;
  3157. if (ret)
  3158. pr_err("%s: set EC REF MFC cfg failed, err %d\n", __func__, ret);
  3159. }
  3160. return copp_idx;
  3161. }
  3162. EXPORT_SYMBOL(adm_open);
  3163. /**
  3164. * adm_copp_mfc_cfg -
  3165. * command to send ADM MFC config
  3166. *
  3167. * @port_id: Port ID number
  3168. * @copp_idx: copp index assigned
  3169. * @dst_sample_rate: sink sample rate
  3170. *
  3171. */
  3172. void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate)
  3173. {
  3174. struct audproc_mfc_param_media_fmt mfc_cfg;
  3175. struct adm_cmd_device_open_v5 open;
  3176. struct param_hdr_v3 param_hdr;
  3177. int port_idx;
  3178. int rc = 0;
  3179. int i = 0;
  3180. port_id = q6audio_convert_virtual_to_portid(port_id);
  3181. port_idx = adm_validate_and_get_port_index(port_id);
  3182. if (port_idx < 0) {
  3183. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  3184. goto fail_cmd;
  3185. }
  3186. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  3187. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  3188. goto fail_cmd;
  3189. }
  3190. memset(&mfc_cfg, 0, sizeof(mfc_cfg));
  3191. memset(&open, 0, sizeof(open));
  3192. memset(&param_hdr, 0, sizeof(param_hdr));
  3193. param_hdr.module_id = AUDPROC_MODULE_ID_MFC;
  3194. param_hdr.instance_id = INSTANCE_ID_0;
  3195. param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
  3196. param_hdr.param_size = sizeof(mfc_cfg);
  3197. mfc_cfg.sampling_rate = dst_sample_rate;
  3198. mfc_cfg.bits_per_sample =
  3199. atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
  3200. open.dev_num_channel = mfc_cfg.num_channels =
  3201. atomic_read(&this_adm.copp.channels[port_idx][copp_idx]);
  3202. rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK,
  3203. mfc_cfg.num_channels, port_idx);
  3204. if (rc < 0) {
  3205. pr_err("%s: unable to get channal map\n", __func__);
  3206. goto fail_cmd;
  3207. }
  3208. for (i = 0; i < mfc_cfg.num_channels; i++)
  3209. mfc_cfg.channel_type[i] =
  3210. (uint16_t) open.dev_channel_mapping[i];
  3211. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  3212. pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d o/p SR %d\n",
  3213. __func__, port_idx, copp_idx,
  3214. atomic_read(&this_adm.copp.rate[port_idx][copp_idx]),
  3215. mfc_cfg.bits_per_sample, mfc_cfg.num_channels,
  3216. mfc_cfg.sampling_rate);
  3217. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  3218. (uint8_t *) &mfc_cfg);
  3219. if (rc)
  3220. pr_err("%s: Failed to set media format configuration data, err %d\n",
  3221. __func__, rc);
  3222. fail_cmd:
  3223. return;
  3224. }
  3225. EXPORT_SYMBOL(adm_copp_mfc_cfg);
  3226. static void route_set_opcode_matrix_id(
  3227. struct adm_cmd_matrix_map_routings_v5 **route_addr,
  3228. int path, uint32_t passthr_mode)
  3229. {
  3230. struct adm_cmd_matrix_map_routings_v5 *route = *route_addr;
  3231. switch (path) {
  3232. case ADM_PATH_PLAYBACK:
  3233. route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
  3234. route->matrix_id = ADM_MATRIX_ID_AUDIO_RX;
  3235. break;
  3236. case ADM_PATH_LIVE_REC:
  3237. if (passthr_mode == LISTEN) {
  3238. route->hdr.opcode =
  3239. ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
  3240. route->matrix_id = ADM_MATRIX_ID_LISTEN_TX;
  3241. break;
  3242. }
  3243. /* fall through to set matrix id for non-listen case */
  3244. case ADM_PATH_NONLIVE_REC:
  3245. route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
  3246. route->matrix_id = ADM_MATRIX_ID_AUDIO_TX;
  3247. break;
  3248. case ADM_PATH_COMPRESSED_RX:
  3249. route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
  3250. route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX;
  3251. break;
  3252. case ADM_PATH_COMPRESSED_TX:
  3253. route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
  3254. route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX;
  3255. break;
  3256. default:
  3257. pr_err("%s: Wrong path set[%d]\n", __func__, path);
  3258. break;
  3259. }
  3260. pr_debug("%s: opcode 0x%x, matrix id %d\n",
  3261. __func__, route->hdr.opcode, route->matrix_id);
  3262. }
  3263. /**
  3264. * adm_matrix_map -
  3265. * command to send ADM matrix map for ADM copp list
  3266. *
  3267. * @path: direction or ADM path type
  3268. * @payload_map: have info of session id and associated copp_idx/num_copps
  3269. * @perf_mode: performance mode like LL/ULL/..
  3270. * @passthr_mode: flag to indicate passthrough mode
  3271. *
  3272. * Returns 0 on success or error on failure
  3273. */
  3274. int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode,
  3275. uint32_t passthr_mode)
  3276. {
  3277. struct adm_cmd_matrix_map_routings_v5 *route;
  3278. struct adm_session_map_node_v5 *node;
  3279. uint16_t *copps_list;
  3280. int cmd_size = 0;
  3281. int ret = 0, i = 0;
  3282. void *payload = NULL;
  3283. void *matrix_map = NULL;
  3284. int port_idx, copp_idx;
  3285. /* Assumes port_ids have already been validated during adm_open */
  3286. cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) +
  3287. sizeof(struct adm_session_map_node_v5) +
  3288. (sizeof(uint32_t) * payload_map.num_copps));
  3289. matrix_map = kzalloc(cmd_size, GFP_KERNEL);
  3290. if (matrix_map == NULL) {
  3291. pr_err("%s: Mem alloc failed\n", __func__);
  3292. ret = -EINVAL;
  3293. return ret;
  3294. }
  3295. route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map;
  3296. route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3297. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3298. route->hdr.pkt_size = cmd_size;
  3299. route->hdr.src_svc = 0;
  3300. route->hdr.src_domain = APR_DOMAIN_APPS;
  3301. route->hdr.src_port = 0; /* Ignored */;
  3302. route->hdr.dest_svc = APR_SVC_ADM;
  3303. route->hdr.dest_domain = APR_DOMAIN_ADSP;
  3304. route->hdr.dest_port = 0; /* Ignored */;
  3305. route->hdr.token = 0;
  3306. route->num_sessions = 1;
  3307. route_set_opcode_matrix_id(&route, path, passthr_mode);
  3308. payload = ((u8 *)matrix_map +
  3309. sizeof(struct adm_cmd_matrix_map_routings_v5));
  3310. node = (struct adm_session_map_node_v5 *)payload;
  3311. node->session_id = payload_map.session_id;
  3312. node->num_copps = payload_map.num_copps;
  3313. payload = (u8 *)node + sizeof(struct adm_session_map_node_v5);
  3314. copps_list = (uint16_t *)payload;
  3315. for (i = 0; i < payload_map.num_copps; i++) {
  3316. port_idx =
  3317. adm_validate_and_get_port_index(payload_map.port_id[i]);
  3318. if (port_idx < 0) {
  3319. pr_err("%s: Invalid port_id 0x%x\n", __func__,
  3320. payload_map.port_id[i]);
  3321. ret = -EINVAL;
  3322. goto fail_cmd;
  3323. }
  3324. copp_idx = payload_map.copp_idx[i];
  3325. copps_list[i] = atomic_read(&this_adm.copp.id[port_idx]
  3326. [copp_idx]);
  3327. }
  3328. atomic_set(&this_adm.matrix_map_stat, -1);
  3329. ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map);
  3330. if (ret < 0) {
  3331. pr_err("%s: routing for syream %d failed ret %d\n",
  3332. __func__, payload_map.session_id, ret);
  3333. ret = -EINVAL;
  3334. goto fail_cmd;
  3335. }
  3336. ret = wait_event_timeout(this_adm.matrix_map_wait,
  3337. atomic_read(&this_adm.matrix_map_stat) >= 0,
  3338. msecs_to_jiffies(TIMEOUT_MS));
  3339. if (!ret) {
  3340. pr_err("%s: routing for syream %d failed\n", __func__,
  3341. payload_map.session_id);
  3342. ret = -EINVAL;
  3343. goto fail_cmd;
  3344. } else if (atomic_read(&this_adm.matrix_map_stat) > 0) {
  3345. pr_err("%s: DSP returned error[%s]\n", __func__,
  3346. adsp_err_get_err_str(atomic_read(
  3347. &this_adm.matrix_map_stat)));
  3348. ret = adsp_err_get_lnx_err_code(
  3349. atomic_read(&this_adm.matrix_map_stat));
  3350. goto fail_cmd;
  3351. }
  3352. if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) &&
  3353. (path != ADM_PATH_COMPRESSED_RX)) {
  3354. for (i = 0; i < payload_map.num_copps; i++) {
  3355. port_idx = afe_get_port_index(payload_map.port_id[i]);
  3356. copp_idx = payload_map.copp_idx[i];
  3357. if (port_idx < 0 || copp_idx < 0 ||
  3358. (copp_idx > MAX_COPPS_PER_PORT - 1)) {
  3359. pr_err("%s: Invalid idx port_idx %d copp_idx %d\n",
  3360. __func__, port_idx, copp_idx);
  3361. continue;
  3362. }
  3363. rtac_add_adm_device(payload_map.port_id[i],
  3364. atomic_read(&this_adm.copp.id
  3365. [port_idx][copp_idx]),
  3366. get_cal_path(path),
  3367. payload_map.session_id,
  3368. payload_map.app_type[i],
  3369. payload_map.acdb_dev_id[i]);
  3370. if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED,
  3371. (void *)&this_adm.copp.adm_status[port_idx]
  3372. [copp_idx])) {
  3373. pr_debug("%s: adm copp[0x%x][%d] already sent",
  3374. __func__, port_idx, copp_idx);
  3375. continue;
  3376. }
  3377. send_adm_cal(payload_map.port_id[i], copp_idx,
  3378. get_cal_path(path), perf_mode,
  3379. payload_map.app_type[i],
  3380. payload_map.acdb_dev_id[i],
  3381. payload_map.sample_rate[i],
  3382. passthr_mode);
  3383. /* ADM COPP calibration is already sent */
  3384. clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
  3385. (void *)&this_adm.copp.
  3386. adm_status[port_idx][copp_idx]);
  3387. pr_debug("%s: copp_id: %d\n", __func__,
  3388. atomic_read(&this_adm.copp.id[port_idx]
  3389. [copp_idx]));
  3390. }
  3391. }
  3392. fail_cmd:
  3393. kfree(matrix_map);
  3394. return ret;
  3395. }
  3396. EXPORT_SYMBOL(adm_matrix_map);
  3397. /**
  3398. * adm_ec_ref_rx_id -
  3399. * Update EC ref port ID
  3400. *
  3401. */
  3402. void adm_ec_ref_rx_id(int port_id)
  3403. {
  3404. this_adm.ec_ref_rx = port_id;
  3405. pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx);
  3406. }
  3407. EXPORT_SYMBOL(adm_ec_ref_rx_id);
  3408. /**
  3409. * adm_num_ec_ref_rx_chans -
  3410. * Update EC ref number of channels
  3411. *
  3412. */
  3413. void adm_num_ec_ref_rx_chans(int num_chans)
  3414. {
  3415. this_adm.num_ec_ref_rx_chans = num_chans;
  3416. pr_debug("%s: num_ec_ref_rx_chans:%d\n",
  3417. __func__, this_adm.num_ec_ref_rx_chans);
  3418. }
  3419. EXPORT_SYMBOL(adm_num_ec_ref_rx_chans);
  3420. /**
  3421. * adm_num_ec_rx_ref_chans_downmixed -
  3422. * Update EC ref num of channels(downmixed) to be fed to EC algo
  3423. *
  3424. */
  3425. void adm_num_ec_ref_rx_chans_downmixed(int num_chans)
  3426. {
  3427. this_adm.num_ec_ref_rx_chans_downmixed = num_chans;
  3428. pr_debug("%s: num_ec_ref_rx_chans_downmixed:%d\n",
  3429. __func__, this_adm.num_ec_ref_rx_chans_downmixed);
  3430. }
  3431. EXPORT_SYMBOL(adm_num_ec_ref_rx_chans_downmixed);
  3432. /**
  3433. * adm_ec_ref_chmixer_weights -
  3434. * Update MFC(in ec ref) Channel Mixer Weights to be used
  3435. * for downmixing rx channels before feeding them to EC algo
  3436. * @out_channel_idx: index of output channel to which weightages are applicable
  3437. * @weights: pointer to array having input weightages
  3438. * @count: array sizeof pointer weights, max supported value is
  3439. * PCM_FORMAT_MAX_NUM_CHANNEL_V8
  3440. * Returns 0 on success or error on failure
  3441. */
  3442. int adm_ec_ref_chmixer_weights(int out_channel_idx,
  3443. uint16_t *weights, int count)
  3444. {
  3445. int i = 0;
  3446. if (weights == NULL || count <= 0 || out_channel_idx < 0 ||
  3447. count > PCM_FORMAT_MAX_NUM_CHANNEL_V8 ||
  3448. out_channel_idx >= PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
  3449. pr_err("%s: invalid weightages count(%d) ch_idx(%d)",
  3450. __func__, count, out_channel_idx);
  3451. return -EINVAL;
  3452. }
  3453. for (i = 0; i < count; i++) {
  3454. this_adm.ec_ref_chmixer_weights[out_channel_idx][i] = weights[i];
  3455. pr_debug("%s: out ch idx :%d, weight[%d] = %d\n",
  3456. __func__, out_channel_idx, i, weights[i]);
  3457. }
  3458. return 0;
  3459. }
  3460. EXPORT_SYMBOL(adm_ec_ref_chmixer_weights);
  3461. /**
  3462. * adm_ec_ref_rx_bit_width -
  3463. * Update EC ref bit_width
  3464. *
  3465. */
  3466. void adm_ec_ref_rx_bit_width(int bit_width)
  3467. {
  3468. this_adm.ec_ref_rx_bit_width = bit_width;
  3469. pr_debug("%s: ec_ref_rx_bit_width:%d\n",
  3470. __func__, this_adm.ec_ref_rx_bit_width);
  3471. }
  3472. EXPORT_SYMBOL(adm_ec_ref_rx_bit_width);
  3473. /**
  3474. * adm_ec_ref_rx_sampling_rate -
  3475. * Update EC ref sample rate
  3476. *
  3477. */
  3478. void adm_ec_ref_rx_sampling_rate(int sampling_rate)
  3479. {
  3480. this_adm.ec_ref_rx_sampling_rate = sampling_rate;
  3481. pr_debug("%s: ec_ref_rx_sampling_rate:%d\n",
  3482. __func__, this_adm.ec_ref_rx_sampling_rate);
  3483. }
  3484. EXPORT_SYMBOL(adm_ec_ref_rx_sampling_rate);
  3485. /**
  3486. * adm_set_native_mode -
  3487. * Set adm channel native mode.
  3488. * If enabled matrix mixer will be
  3489. * running in native mode for channel
  3490. * configuration for this device session.
  3491. *
  3492. */
  3493. void adm_set_native_mode(int mode)
  3494. {
  3495. this_adm.native_mode = mode;
  3496. pr_debug("%s: enable native_mode :%d\n",
  3497. __func__, this_adm.native_mode);
  3498. }
  3499. EXPORT_SYMBOL(adm_set_native_mode);
  3500. /**
  3501. * adm_close -
  3502. * command to close ADM copp
  3503. *
  3504. * @port_id: Port ID number
  3505. * @perf_mode: performance mode like LL/ULL/..
  3506. * @copp_idx: copp index assigned
  3507. *
  3508. * Returns 0 on success or error on failure
  3509. */
  3510. int adm_close(int port_id, int perf_mode, int copp_idx)
  3511. {
  3512. struct apr_hdr close;
  3513. int ret = 0, port_idx;
  3514. int copp_id = RESET_COPP_ID;
  3515. bool result = false;
  3516. int dest_perms[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};
  3517. int source_vm[2] = {VMID_LPASS, VMID_ADSP_HEAP};
  3518. int dest_vm[1] = {VMID_HLOS};
  3519. struct cal_block_data *cal_block = NULL;
  3520. int cal_index = ADM_AUDPROC_PERSISTENT_CAL;
  3521. pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__,
  3522. port_id, perf_mode, copp_idx);
  3523. port_id = q6audio_convert_virtual_to_portid(port_id);
  3524. port_idx = adm_validate_and_get_port_index(port_id);
  3525. if (port_idx < 0) {
  3526. pr_err("%s: Invalid port_id 0x%x\n",
  3527. __func__, port_id);
  3528. return -EINVAL;
  3529. }
  3530. if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
  3531. pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx);
  3532. return -EINVAL;
  3533. }
  3534. port_channel_map[port_idx].set_channel_map = false;
  3535. if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode
  3536. == LEGACY_PCM_MODE) {
  3537. atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
  3538. 1);
  3539. this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
  3540. wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
  3541. }
  3542. atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]);
  3543. if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) {
  3544. copp_id = adm_get_copp_id(port_idx, copp_idx);
  3545. pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n",
  3546. __func__, port_idx, copp_idx, copp_id);
  3547. if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) &&
  3548. (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) ==
  3549. SRS_TRUMEDIA_TOPOLOGY_ID)) {
  3550. atomic_set(&this_adm.mem_map_index,
  3551. ADM_SRS_TRUMEDIA);
  3552. ret = adm_memory_unmap_regions();
  3553. if (ret < 0) {
  3554. pr_err("%s: adm mem unmmap err %d",
  3555. __func__, ret);
  3556. } else {
  3557. atomic_set(&this_adm.mem_map_handles
  3558. [ADM_SRS_TRUMEDIA], 0);
  3559. }
  3560. }
  3561. if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) &&
  3562. this_adm.sourceTrackingData.memmap.paddr) {
  3563. atomic_set(&this_adm.mem_map_index,
  3564. ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
  3565. ret = adm_memory_unmap_regions();
  3566. if (ret < 0) {
  3567. pr_err("%s: adm mem unmmap err %d",
  3568. __func__, ret);
  3569. }
  3570. msm_audio_ion_free(
  3571. this_adm.sourceTrackingData.dma_buf);
  3572. this_adm.sourceTrackingData.dma_buf = NULL;
  3573. this_adm.sourceTrackingData.memmap.size = 0;
  3574. this_adm.sourceTrackingData.memmap.kvaddr = NULL;
  3575. this_adm.sourceTrackingData.memmap.paddr = 0;
  3576. this_adm.sourceTrackingData.apr_cmd_status = -1;
  3577. atomic_set(&this_adm.mem_map_handles[
  3578. ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
  3579. }
  3580. close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3581. APR_HDR_LEN(APR_HDR_SIZE),
  3582. APR_PKT_VER);
  3583. close.pkt_size = sizeof(close);
  3584. close.src_svc = APR_SVC_ADM;
  3585. close.src_domain = APR_DOMAIN_APPS;
  3586. close.src_port = port_id;
  3587. close.dest_svc = APR_SVC_ADM;
  3588. close.dest_domain = APR_DOMAIN_ADSP;
  3589. close.dest_port = copp_id;
  3590. close.token = port_idx << 16 | copp_idx;
  3591. close.opcode = ADM_CMD_DEVICE_CLOSE_V5;
  3592. atomic_set(&this_adm.copp.id[port_idx][copp_idx],
  3593. RESET_COPP_ID);
  3594. atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
  3595. atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0);
  3596. atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0);
  3597. atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
  3598. atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0);
  3599. atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0);
  3600. atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0);
  3601. atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0);
  3602. atomic_set(&this_adm.copp.session_type[port_idx][copp_idx], 0);
  3603. atomic_set(&this_adm.copp.token[port_idx][copp_idx], 0);
  3604. clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
  3605. (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
  3606. ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close);
  3607. if (ret < 0) {
  3608. pr_err("%s: ADM close failed %d\n", __func__, ret);
  3609. if (this_adm.tx_port_id == port_id) {
  3610. mutex_lock(&this_adm.cal_data[cal_index]->lock);
  3611. cal_block = cal_utils_get_only_cal_block(
  3612. this_adm.cal_data[cal_index]);
  3613. if (cal_block != NULL) {
  3614. result = true;
  3615. pr_debug("%s: cma_alloc %d\n",
  3616. __func__, cal_block->cma_mem);
  3617. }
  3618. if (result) {
  3619. pr_debug("%s: use hyp assigned %d, use buffer %d\n",
  3620. __func__, this_adm.hyp_assigned,
  3621. cal_block->buffer_number);
  3622. if(cal_block->cma_mem &&
  3623. this_adm.hyp_assigned) {
  3624. if (cal_block->cal_data.paddr == 0 ||
  3625. cal_block->map_data.map_size <= 0) {
  3626. pr_err("%s: No address to map!\n",
  3627. __func__);
  3628. ret = -EINVAL;
  3629. goto fail;
  3630. }
  3631. ret = hyp_assign_phys(
  3632. cal_block->cal_data.paddr,
  3633. cal_block->map_data.map_size,
  3634. source_vm, 2, dest_vm,
  3635. dest_perms, 1);
  3636. if (ret < 0) {
  3637. pr_err("%s: hyp_assign_phys failed result = %d addr = 0x%pK size = %d\n",
  3638. __func__, ret,
  3639. cal_block->cal_data.paddr,
  3640. cal_block->map_data.map_size);
  3641. goto fail;
  3642. } else {
  3643. pr_debug("%s: hyp_assign_phys success\n",
  3644. __func__);
  3645. this_adm.hyp_assigned = false;
  3646. }
  3647. }
  3648. ret = -EINVAL;
  3649. }
  3650. goto fail;
  3651. }
  3652. return -EINVAL;
  3653. }
  3654. ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
  3655. atomic_read(&this_adm.copp.stat
  3656. [port_idx][copp_idx]) >= 0,
  3657. msecs_to_jiffies(TIMEOUT_MS));
  3658. if (!ret) {
  3659. pr_err("%s: ADM cmd Route timedout for port 0x%x\n",
  3660. __func__, port_id);
  3661. return -EINVAL;
  3662. } else if (atomic_read(&this_adm.copp.stat
  3663. [port_idx][copp_idx]) > 0) {
  3664. pr_err("%s: DSP returned error[%s]\n",
  3665. __func__, adsp_err_get_err_str(
  3666. atomic_read(&this_adm.copp.stat
  3667. [port_idx][copp_idx])));
  3668. return adsp_err_get_lnx_err_code(
  3669. atomic_read(&this_adm.copp.stat
  3670. [port_idx][copp_idx]));
  3671. }
  3672. }
  3673. if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) {
  3674. pr_debug("%s: remove adm device from rtac\n", __func__);
  3675. rtac_remove_adm_device(port_id, copp_id);
  3676. }
  3677. if (this_adm.tx_port_id == port_id) {
  3678. mutex_lock(&this_adm.cal_data[cal_index]->lock);
  3679. cal_block = cal_utils_get_only_cal_block(
  3680. this_adm.cal_data[cal_index]);
  3681. if (cal_block != NULL) {
  3682. result = true;
  3683. pr_debug("%s: cma_alloc %d\n",
  3684. __func__, cal_block->cma_mem);
  3685. }
  3686. if (result) {
  3687. pr_debug("%s: use hyp assigned %d, use buffer %d\n",
  3688. __func__, this_adm.hyp_assigned,
  3689. cal_block->buffer_number);
  3690. if(cal_block->cma_mem && this_adm.hyp_assigned) {
  3691. if (cal_block->cal_data.paddr == 0 ||
  3692. cal_block->map_data.map_size <= 0) {
  3693. pr_err("%s: No address to map!\n",
  3694. __func__);
  3695. ret = -EINVAL;
  3696. goto fail;
  3697. }
  3698. ret = hyp_assign_phys(cal_block->cal_data.paddr,
  3699. cal_block->map_data.map_size,
  3700. source_vm, 2, dest_vm,
  3701. dest_perms, 1);
  3702. if (ret < 0) {
  3703. pr_err("%s: hyp_assign_phys failed result = %d addr = 0x%pK size = %d\n",
  3704. __func__, ret, cal_block->cal_data.paddr,
  3705. cal_block->map_data.map_size);
  3706. ret = -EINVAL;
  3707. goto fail;
  3708. } else {
  3709. pr_debug("%s: hyp_assign_phys success\n",
  3710. __func__);
  3711. this_adm.hyp_assigned = false;
  3712. }
  3713. }
  3714. }
  3715. goto fail;
  3716. }
  3717. if (port_id == this_adm.ffecns_port_id)
  3718. this_adm.ffecns_port_id = -1;
  3719. return 0;
  3720. fail:
  3721. mutex_unlock(&this_adm.cal_data[cal_index]->lock);
  3722. return ret;
  3723. }
  3724. EXPORT_SYMBOL(adm_close);
  3725. int send_rtac_audvol_cal(void)
  3726. {
  3727. int ret = 0;
  3728. int ret2 = 0;
  3729. int i = 0;
  3730. int copp_idx, port_idx, acdb_id, app_id, path;
  3731. struct cal_block_data *cal_block = NULL;
  3732. struct audio_cal_info_audvol *audvol_cal_info = NULL;
  3733. struct rtac_adm rtac_adm_data;
  3734. mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
  3735. cal_block = cal_utils_get_only_cal_block(
  3736. this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]);
  3737. if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) {
  3738. pr_err("%s: can't find cal block!\n", __func__);
  3739. goto unlock;
  3740. }
  3741. audvol_cal_info = cal_block->cal_info;
  3742. if (audvol_cal_info == NULL) {
  3743. pr_err("%s: audvol_cal_info is NULL!\n", __func__);
  3744. goto unlock;
  3745. }
  3746. get_rtac_adm_data(&rtac_adm_data);
  3747. for (; i < rtac_adm_data.num_of_dev; i++) {
  3748. acdb_id = rtac_adm_data.device[i].acdb_dev_id;
  3749. if (acdb_id == 0)
  3750. acdb_id = audvol_cal_info->acdb_id;
  3751. app_id = rtac_adm_data.device[i].app_type;
  3752. if (app_id == 0)
  3753. app_id = audvol_cal_info->app_type;
  3754. path = afe_get_port_type(rtac_adm_data.device[i].afe_port);
  3755. if ((acdb_id == audvol_cal_info->acdb_id) &&
  3756. (app_id == audvol_cal_info->app_type) &&
  3757. (path == audvol_cal_info->path)) {
  3758. if (adm_get_indexes_from_copp_id(rtac_adm_data.
  3759. device[i].copp, &copp_idx, &port_idx) != 0) {
  3760. pr_debug("%s: Copp Id %d is not active\n",
  3761. __func__,
  3762. rtac_adm_data.device[i].copp);
  3763. continue;
  3764. }
  3765. ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL,
  3766. rtac_adm_data.device[i].afe_port,
  3767. copp_idx, cal_block,
  3768. atomic_read(&this_adm.copp.
  3769. mode[port_idx][copp_idx]),
  3770. audvol_cal_info->app_type,
  3771. audvol_cal_info->acdb_id,
  3772. atomic_read(&this_adm.copp.
  3773. rate[port_idx][copp_idx]));
  3774. if (ret2 < 0) {
  3775. pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n",
  3776. __func__, rtac_adm_data.device[i].copp,
  3777. audvol_cal_info->acdb_id,
  3778. audvol_cal_info->app_type,
  3779. audvol_cal_info->path);
  3780. ret = ret2;
  3781. }
  3782. }
  3783. }
  3784. unlock:
  3785. mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
  3786. return ret;
  3787. }
  3788. int adm_map_rtac_block(struct rtac_cal_block_data *cal_block)
  3789. {
  3790. int result = 0;
  3791. pr_debug("%s:\n", __func__);
  3792. if (cal_block == NULL) {
  3793. pr_err("%s: cal_block is NULL!\n",
  3794. __func__);
  3795. result = -EINVAL;
  3796. goto done;
  3797. }
  3798. if (cal_block->cal_data.paddr == 0) {
  3799. pr_debug("%s: No address to map!\n",
  3800. __func__);
  3801. result = -EINVAL;
  3802. goto done;
  3803. }
  3804. if (cal_block->map_data.map_size == 0) {
  3805. pr_debug("%s: map size is 0!\n",
  3806. __func__);
  3807. result = -EINVAL;
  3808. goto done;
  3809. }
  3810. /* valid port ID needed for callback use primary I2S */
  3811. atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
  3812. result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
  3813. &cal_block->map_data.map_size, 1);
  3814. if (result < 0) {
  3815. pr_err("%s: RTAC mmap did not work! size = %d result %d\n",
  3816. __func__,
  3817. cal_block->map_data.map_size, result);
  3818. pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
  3819. __func__,
  3820. &cal_block->cal_data.paddr,
  3821. cal_block->map_data.map_size);
  3822. goto done;
  3823. }
  3824. cal_block->map_data.map_handle = atomic_read(
  3825. &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]);
  3826. done:
  3827. return result;
  3828. }
  3829. int adm_unmap_rtac_block(uint32_t *mem_map_handle)
  3830. {
  3831. int result = 0;
  3832. pr_debug("%s:\n", __func__);
  3833. if (mem_map_handle == NULL) {
  3834. pr_debug("%s: Map handle is NULL, nothing to unmap\n",
  3835. __func__);
  3836. goto done;
  3837. }
  3838. if (*mem_map_handle == 0) {
  3839. pr_debug("%s: Map handle is 0, nothing to unmap\n",
  3840. __func__);
  3841. goto done;
  3842. }
  3843. if (*mem_map_handle != atomic_read(
  3844. &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) {
  3845. pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n",
  3846. __func__, *mem_map_handle, atomic_read(
  3847. &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]));
  3848. /* if mismatch use handle passed in to unmap */
  3849. atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL],
  3850. *mem_map_handle);
  3851. }
  3852. /* valid port ID needed for callback use primary I2S */
  3853. atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
  3854. result = adm_memory_unmap_regions();
  3855. if (result < 0) {
  3856. pr_debug("%s: adm_memory_unmap_regions failed, error %d\n",
  3857. __func__, result);
  3858. } else {
  3859. atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0);
  3860. *mem_map_handle = 0;
  3861. }
  3862. done:
  3863. return result;
  3864. }
  3865. static int get_cal_type_index(int32_t cal_type)
  3866. {
  3867. int ret = -EINVAL;
  3868. switch (cal_type) {
  3869. case ADM_AUDPROC_CAL_TYPE:
  3870. ret = ADM_AUDPROC_CAL;
  3871. break;
  3872. case ADM_LSM_AUDPROC_CAL_TYPE:
  3873. ret = ADM_LSM_AUDPROC_CAL;
  3874. break;
  3875. case ADM_AUDVOL_CAL_TYPE:
  3876. ret = ADM_AUDVOL_CAL;
  3877. break;
  3878. case ADM_CUST_TOPOLOGY_CAL_TYPE:
  3879. ret = ADM_CUSTOM_TOP_CAL;
  3880. break;
  3881. case ADM_RTAC_INFO_CAL_TYPE:
  3882. ret = ADM_RTAC_INFO_CAL;
  3883. break;
  3884. case ADM_RTAC_APR_CAL_TYPE:
  3885. ret = ADM_RTAC_APR_CAL;
  3886. break;
  3887. case ADM_RTAC_AUDVOL_CAL_TYPE:
  3888. ret = ADM_RTAC_AUDVOL_CAL;
  3889. break;
  3890. case ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE:
  3891. ret = ADM_LSM_AUDPROC_PERSISTENT_CAL;
  3892. break;
  3893. case ADM_AUDPROC_PERSISTENT_CAL_TYPE:
  3894. ret = ADM_AUDPROC_PERSISTENT_CAL;
  3895. break;
  3896. default:
  3897. pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
  3898. }
  3899. return ret;
  3900. }
  3901. static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data)
  3902. {
  3903. int ret = 0;
  3904. int cal_index;
  3905. pr_debug("%s:\n", __func__);
  3906. cal_index = get_cal_type_index(cal_type);
  3907. if (cal_index < 0) {
  3908. pr_err("%s: could not get cal index %d!\n",
  3909. __func__, cal_index);
  3910. ret = -EINVAL;
  3911. goto done;
  3912. }
  3913. ret = cal_utils_alloc_cal(data_size, data,
  3914. this_adm.cal_data[cal_index], 0, NULL);
  3915. if (ret < 0) {
  3916. pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
  3917. __func__, ret, cal_type);
  3918. ret = -EINVAL;
  3919. goto done;
  3920. }
  3921. done:
  3922. return ret;
  3923. }
  3924. static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data)
  3925. {
  3926. int ret = 0;
  3927. int cal_index;
  3928. pr_debug("%s:\n", __func__);
  3929. cal_index = get_cal_type_index(cal_type);
  3930. if (cal_index < 0) {
  3931. pr_err("%s: could not get cal index %d!\n",
  3932. __func__, cal_index);
  3933. ret = -EINVAL;
  3934. goto done;
  3935. }
  3936. ret = cal_utils_dealloc_cal(data_size, data,
  3937. this_adm.cal_data[cal_index]);
  3938. if (ret < 0) {
  3939. pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
  3940. __func__, ret, cal_type);
  3941. ret = -EINVAL;
  3942. goto done;
  3943. }
  3944. done:
  3945. return ret;
  3946. }
  3947. static int adm_set_cal(int32_t cal_type, size_t data_size, void *data)
  3948. {
  3949. int ret = 0;
  3950. int cal_index;
  3951. pr_debug("%s:\n", __func__);
  3952. cal_index = get_cal_type_index(cal_type);
  3953. if (cal_index < 0) {
  3954. pr_err("%s: could not get cal index %d!\n",
  3955. __func__, cal_index);
  3956. ret = -EINVAL;
  3957. goto done;
  3958. }
  3959. ret = cal_utils_set_cal(data_size, data,
  3960. this_adm.cal_data[cal_index], 0, NULL);
  3961. if (ret < 0) {
  3962. pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
  3963. __func__, ret, cal_type);
  3964. ret = -EINVAL;
  3965. goto done;
  3966. }
  3967. if (cal_index == ADM_CUSTOM_TOP_CAL) {
  3968. mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
  3969. this_adm.set_custom_topology = 1;
  3970. mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
  3971. } else if (cal_index == ADM_RTAC_AUDVOL_CAL) {
  3972. send_rtac_audvol_cal();
  3973. }
  3974. done:
  3975. return ret;
  3976. }
  3977. static int adm_map_cal_data(int32_t cal_type,
  3978. struct cal_block_data *cal_block)
  3979. {
  3980. int ret = 0;
  3981. int cal_index;
  3982. pr_debug("%s:\n", __func__);
  3983. cal_index = get_cal_type_index(cal_type);
  3984. if (cal_index < 0) {
  3985. pr_err("%s: could not get cal index %d!\n",
  3986. __func__, cal_index);
  3987. ret = -EINVAL;
  3988. goto done;
  3989. }
  3990. atomic_set(&this_adm.mem_map_index, cal_index);
  3991. ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
  3992. (uint32_t *)&cal_block->map_data.map_size, 1);
  3993. if (ret < 0) {
  3994. pr_err("%s: map did not work! cal_type %i ret %d\n",
  3995. __func__, cal_index, ret);
  3996. ret = -ENODEV;
  3997. goto done;
  3998. }
  3999. cal_block->map_data.q6map_handle = atomic_read(&this_adm.
  4000. mem_map_handles[cal_index]);
  4001. done:
  4002. return ret;
  4003. }
  4004. static int adm_unmap_cal_data(int32_t cal_type,
  4005. struct cal_block_data *cal_block)
  4006. {
  4007. int ret = 0;
  4008. int cal_index;
  4009. pr_debug("%s:\n", __func__);
  4010. cal_index = get_cal_type_index(cal_type);
  4011. if (cal_index < 0) {
  4012. pr_err("%s: could not get cal index %d!\n",
  4013. __func__, cal_index);
  4014. ret = -EINVAL;
  4015. goto done;
  4016. }
  4017. if (cal_block == NULL) {
  4018. pr_err("%s: Cal block is NULL!\n",
  4019. __func__);
  4020. goto done;
  4021. }
  4022. if (cal_block->map_data.q6map_handle == 0) {
  4023. pr_err("%s: Map handle is NULL, nothing to unmap\n",
  4024. __func__);
  4025. goto done;
  4026. }
  4027. atomic_set(&this_adm.mem_map_handles[cal_index],
  4028. cal_block->map_data.q6map_handle);
  4029. atomic_set(&this_adm.mem_map_index, cal_index);
  4030. ret = adm_memory_unmap_regions();
  4031. if (ret < 0) {
  4032. pr_err("%s: unmap did not work! cal_type %i ret %d\n",
  4033. __func__, cal_index, ret);
  4034. ret = -ENODEV;
  4035. goto done;
  4036. }
  4037. cal_block->map_data.q6map_handle = 0;
  4038. done:
  4039. return ret;
  4040. }
  4041. static void adm_delete_cal_data(void)
  4042. {
  4043. pr_debug("%s:\n", __func__);
  4044. cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data);
  4045. }
  4046. static int adm_init_cal_data(void)
  4047. {
  4048. int ret = 0;
  4049. struct cal_type_info cal_type_info[] = {
  4050. {{ADM_CUST_TOPOLOGY_CAL_TYPE,
  4051. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4052. adm_set_cal, NULL, NULL} },
  4053. {adm_map_cal_data, adm_unmap_cal_data,
  4054. cal_utils_match_buf_num} },
  4055. {{ADM_AUDPROC_CAL_TYPE,
  4056. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4057. adm_set_cal, NULL, NULL} },
  4058. {adm_map_cal_data, adm_unmap_cal_data,
  4059. cal_utils_match_buf_num} },
  4060. {{ADM_LSM_AUDPROC_CAL_TYPE,
  4061. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4062. adm_set_cal, NULL, NULL} },
  4063. {adm_map_cal_data, adm_unmap_cal_data,
  4064. cal_utils_match_buf_num} },
  4065. {{ADM_AUDVOL_CAL_TYPE,
  4066. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4067. adm_set_cal, NULL, NULL} },
  4068. {adm_map_cal_data, adm_unmap_cal_data,
  4069. cal_utils_match_buf_num} },
  4070. {{ADM_RTAC_INFO_CAL_TYPE,
  4071. {NULL, NULL, NULL, NULL, NULL, NULL} },
  4072. {NULL, NULL, cal_utils_match_buf_num} },
  4073. {{ADM_RTAC_APR_CAL_TYPE,
  4074. {NULL, NULL, NULL, NULL, NULL, NULL} },
  4075. {NULL, NULL, cal_utils_match_buf_num} },
  4076. {{SRS_TRUMEDIA_CAL_TYPE,
  4077. {NULL, NULL, NULL, NULL, NULL, NULL} },
  4078. {NULL, NULL, cal_utils_match_buf_num} },
  4079. {{ADM_RTAC_AUDVOL_CAL_TYPE,
  4080. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4081. adm_set_cal, NULL, NULL} },
  4082. {adm_map_cal_data, adm_unmap_cal_data,
  4083. cal_utils_match_buf_num} },
  4084. {{ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE,
  4085. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4086. adm_set_cal, NULL, NULL} },
  4087. {adm_map_cal_data, adm_unmap_cal_data,
  4088. cal_utils_match_buf_num} },
  4089. {{ADM_AUDPROC_PERSISTENT_CAL_TYPE,
  4090. {adm_alloc_cal, adm_dealloc_cal, NULL,
  4091. adm_set_cal, NULL, NULL} },
  4092. {adm_map_cal_data, adm_unmap_cal_data,
  4093. cal_utils_match_buf_num} },
  4094. };
  4095. pr_debug("%s:\n", __func__);
  4096. ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data,
  4097. cal_type_info);
  4098. if (ret < 0) {
  4099. pr_err("%s: could not create cal type! ret %d\n",
  4100. __func__, ret);
  4101. ret = -EINVAL;
  4102. goto err;
  4103. }
  4104. return ret;
  4105. err:
  4106. adm_delete_cal_data();
  4107. return ret;
  4108. }
  4109. /**
  4110. * adm_set_volume -
  4111. * command to set volume on ADM copp
  4112. *
  4113. * @port_id: Port ID number
  4114. * @copp_idx: copp index assigned
  4115. * @volume: gain value to set
  4116. *
  4117. * Returns 0 on success or error on failure
  4118. */
  4119. int adm_set_volume(int port_id, int copp_idx, int volume)
  4120. {
  4121. struct audproc_volume_ctrl_master_gain audproc_vol;
  4122. struct param_hdr_v3 param_hdr;
  4123. int rc = 0;
  4124. pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume);
  4125. memset(&audproc_vol, 0, sizeof(audproc_vol));
  4126. memset(&param_hdr, 0, sizeof(param_hdr));
  4127. param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
  4128. param_hdr.instance_id = INSTANCE_ID_0;
  4129. param_hdr.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN;
  4130. param_hdr.param_size = sizeof(audproc_vol);
  4131. audproc_vol.master_gain = volume;
  4132. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4133. (uint8_t *) &audproc_vol);
  4134. if (rc)
  4135. pr_err("%s: Failed to set volume, err %d\n", __func__, rc);
  4136. return rc;
  4137. }
  4138. EXPORT_SYMBOL(adm_set_volume);
  4139. /**
  4140. * adm_set_softvolume -
  4141. * command to set softvolume
  4142. *
  4143. * @port_id: Port ID number
  4144. * @copp_idx: copp index assigned
  4145. * @softvol_param: Params to set for softvolume
  4146. *
  4147. * Returns 0 on success or error on failure
  4148. */
  4149. int adm_set_softvolume(int port_id, int copp_idx,
  4150. struct audproc_softvolume_params *softvol_param)
  4151. {
  4152. struct audproc_soft_step_volume_params audproc_softvol;
  4153. struct param_hdr_v3 param_hdr;
  4154. int rc = 0;
  4155. pr_debug("%s: period %d step %d curve %d\n", __func__,
  4156. softvol_param->period, softvol_param->step,
  4157. softvol_param->rampingcurve);
  4158. memset(&audproc_softvol, 0, sizeof(audproc_softvol));
  4159. memset(&param_hdr, 0, sizeof(param_hdr));
  4160. param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
  4161. param_hdr.instance_id = INSTANCE_ID_0;
  4162. param_hdr.param_id = AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
  4163. param_hdr.param_size = sizeof(audproc_softvol);
  4164. audproc_softvol.period = softvol_param->period;
  4165. audproc_softvol.step = softvol_param->step;
  4166. audproc_softvol.ramping_curve = softvol_param->rampingcurve;
  4167. pr_debug("%s: period %d, step %d, curve %d\n", __func__,
  4168. audproc_softvol.period, audproc_softvol.step,
  4169. audproc_softvol.ramping_curve);
  4170. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4171. (uint8_t *) &audproc_softvol);
  4172. if (rc)
  4173. pr_err("%s: Failed to set soft volume, err %d\n", __func__, rc);
  4174. return rc;
  4175. }
  4176. EXPORT_SYMBOL(adm_set_softvolume);
  4177. /**
  4178. * adm_set_mic_gain -
  4179. * command to set MIC gain
  4180. *
  4181. * @port_id: Port ID number
  4182. * @copp_idx: copp index assigned
  4183. * @volume: gain value to set
  4184. *
  4185. * Returns 0 on success or error on failure
  4186. */
  4187. int adm_set_mic_gain(int port_id, int copp_idx, int volume)
  4188. {
  4189. struct admx_mic_gain mic_gain_params;
  4190. struct param_hdr_v3 param_hdr;
  4191. int rc = 0;
  4192. pr_debug("%s: Setting mic gain to %d at port_id 0x%x\n", __func__,
  4193. volume, port_id);
  4194. memset(&mic_gain_params, 0, sizeof(mic_gain_params));
  4195. memset(&param_hdr, 0, sizeof(param_hdr));
  4196. param_hdr.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL;
  4197. param_hdr.instance_id = INSTANCE_ID_0;
  4198. param_hdr.param_id = ADM_PARAM_IDX_MIC_GAIN;
  4199. param_hdr.param_size = sizeof(mic_gain_params);
  4200. mic_gain_params.tx_mic_gain = volume;
  4201. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4202. (uint8_t *) &mic_gain_params);
  4203. if (rc)
  4204. pr_err("%s: Failed to set mic gain, err %d\n", __func__, rc);
  4205. return rc;
  4206. }
  4207. EXPORT_SYMBOL(adm_set_mic_gain);
  4208. /**
  4209. * adm_send_set_multichannel_ec_primary_mic_ch -
  4210. * command to set multi-ch EC primary mic
  4211. *
  4212. * @port_id: Port ID number
  4213. * @copp_idx: copp index assigned
  4214. * @primary_mic_ch: channel number of primary mic
  4215. *
  4216. * Returns 0 on success or error on failure
  4217. */
  4218. int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx,
  4219. int primary_mic_ch)
  4220. {
  4221. struct admx_sec_primary_mic_ch sec_primary_ch_params;
  4222. struct param_hdr_v3 param_hdr;
  4223. int rc = 0;
  4224. pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n",
  4225. __func__, port_id, copp_idx, primary_mic_ch);
  4226. memset(&sec_primary_ch_params, 0, sizeof(sec_primary_ch_params));
  4227. memset(&param_hdr, 0, sizeof(param_hdr));
  4228. param_hdr.module_id = AUDPROC_MODULE_ID_VOICE_TX_SECNS;
  4229. param_hdr.instance_id = INSTANCE_ID_0;
  4230. param_hdr.param_id = AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH;
  4231. param_hdr.param_size = sizeof(sec_primary_ch_params);
  4232. sec_primary_ch_params.version = 0;
  4233. sec_primary_ch_params.sec_primary_mic_ch = primary_mic_ch;
  4234. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4235. (uint8_t *) &sec_primary_ch_params);
  4236. if (rc)
  4237. pr_err("%s: Failed to set primary mic chanel, err %d\n",
  4238. __func__, rc);
  4239. return rc;
  4240. }
  4241. EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch);
  4242. /**
  4243. * adm_set_ffecns_effect -
  4244. * command to set effect for ffecns module
  4245. *
  4246. * @effect: effect payload
  4247. *
  4248. * Returns 0 on success or error on failure
  4249. */
  4250. int adm_set_ffecns_effect(int effect)
  4251. {
  4252. struct ffecns_effect ffecns_params;
  4253. struct param_hdr_v3 param_hdr;
  4254. int rc = 0;
  4255. int copp_idx = 0;
  4256. copp_idx = adm_get_default_copp_idx(this_adm.ffecns_port_id);
  4257. if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
  4258. pr_err("%s, no active copp to query rms copp_idx:%d\n",
  4259. __func__, copp_idx);
  4260. return -EINVAL;
  4261. }
  4262. memset(&ffecns_params, 0, sizeof(ffecns_params));
  4263. memset(&param_hdr, 0, sizeof(param_hdr));
  4264. param_hdr.module_id = FFECNS_MODULE_ID;
  4265. param_hdr.instance_id = INSTANCE_ID_0;
  4266. param_hdr.param_id = FLUENCE_CMN_GLOBAL_EFFECT_PARAM_ID;
  4267. param_hdr.param_size = sizeof(ffecns_params);
  4268. ffecns_params.payload = effect;
  4269. rc = adm_pack_and_set_one_pp_param(this_adm.ffecns_port_id, copp_idx,
  4270. param_hdr, (uint8_t *) &ffecns_params);
  4271. if (rc)
  4272. pr_err("%s: Failed to set ffecns effect, err %d\n",
  4273. __func__, rc);
  4274. return rc;
  4275. }
  4276. EXPORT_SYMBOL(adm_set_ffecns_effect);
  4277. /**
  4278. * adm_set_ffecns_freeze_event -
  4279. * command to set event for ffecns module
  4280. *
  4281. * @event: send ffecns freeze event true or false
  4282. *
  4283. * Returns 0 on success or error on failure
  4284. */
  4285. int adm_set_ffecns_freeze_event(bool ffecns_freeze_event)
  4286. {
  4287. struct ffv_spf_freeze_param_t ffv_param;
  4288. struct param_hdr_v3 param_hdr;
  4289. int rc = 0;
  4290. int copp_idx = 0;
  4291. memset(&param_hdr, 0, sizeof(param_hdr));
  4292. memset(&ffv_param, 0, sizeof(ffv_param));
  4293. ffv_param.freeze = ffecns_freeze_event ? 1 : 0;
  4294. ffv_param.source_id = 0; /*default value*/
  4295. copp_idx = adm_get_default_copp_idx(this_adm.ffecns_port_id);
  4296. if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
  4297. pr_err("%s, no active copp to query rms copp_idx:%d\n",
  4298. __func__, copp_idx);
  4299. return -EINVAL;
  4300. }
  4301. param_hdr.module_id = FFECNS_MODULE_ID;
  4302. param_hdr.instance_id = INSTANCE_ID_0;
  4303. param_hdr.param_id = PARAM_ID_FFV_SPF_FREEZE;
  4304. param_hdr.param_size = sizeof(ffv_param);
  4305. rc = adm_pack_and_set_one_pp_param(this_adm.ffecns_port_id, copp_idx,
  4306. param_hdr, (uint8_t *) &ffv_param);
  4307. if (rc)
  4308. pr_err("%s: Failed to set ffecns imc event, err %d\n",
  4309. __func__, rc);
  4310. return rc;
  4311. }
  4312. EXPORT_SYMBOL(adm_set_ffecns_freeze_event);
  4313. /**
  4314. * adm_param_enable -
  4315. * command to send params to ADM for given module
  4316. *
  4317. * @port_id: Port ID number
  4318. * @copp_idx: copp index assigned
  4319. * @module_id: ADM module
  4320. * @enable: flag to enable or disable module
  4321. *
  4322. * Returns 0 on success or error on failure
  4323. */
  4324. int adm_param_enable(int port_id, int copp_idx, int module_id, int enable)
  4325. {
  4326. struct module_instance_info mod_inst_info;
  4327. memset(&mod_inst_info, 0, sizeof(mod_inst_info));
  4328. mod_inst_info.module_id = module_id;
  4329. mod_inst_info.instance_id = INSTANCE_ID_0;
  4330. return adm_param_enable_v2(port_id, copp_idx, mod_inst_info, enable);
  4331. }
  4332. EXPORT_SYMBOL(adm_param_enable);
  4333. /**
  4334. * adm_param_enable_v2 -
  4335. * command to send params to ADM for given module
  4336. *
  4337. * @port_id: Port ID number
  4338. * @copp_idx: copp index assigned
  4339. * @mod_inst_info: module and instance ID info
  4340. * @enable: flag to enable or disable module
  4341. *
  4342. * Returns 0 on success or error on failure
  4343. */
  4344. int adm_param_enable_v2(int port_id, int copp_idx,
  4345. struct module_instance_info mod_inst_info, int enable)
  4346. {
  4347. uint32_t enable_param;
  4348. struct param_hdr_v3 param_hdr;
  4349. int rc = 0;
  4350. if (enable < 0 || enable > 1) {
  4351. pr_err("%s: Invalid value for enable %d\n", __func__, enable);
  4352. return -EINVAL;
  4353. }
  4354. pr_debug("%s port_id %d, module_id 0x%x, instance_id 0x%x, enable %d\n",
  4355. __func__, port_id, mod_inst_info.module_id,
  4356. mod_inst_info.instance_id, enable);
  4357. memset(&param_hdr, 0, sizeof(param_hdr));
  4358. param_hdr.module_id = mod_inst_info.module_id;
  4359. param_hdr.instance_id = mod_inst_info.instance_id;
  4360. param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
  4361. param_hdr.param_size = sizeof(enable_param);
  4362. enable_param = enable;
  4363. rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4364. (uint8_t *) &enable_param);
  4365. if (rc)
  4366. pr_err("%s: Failed to set enable of module(%d) instance(%d) to %d, err %d\n",
  4367. __func__, mod_inst_info.module_id,
  4368. mod_inst_info.instance_id, enable, rc);
  4369. return rc;
  4370. }
  4371. EXPORT_SYMBOL(adm_param_enable_v2);
  4372. /**
  4373. * adm_send_calibration -
  4374. * send ADM calibration to DSP
  4375. *
  4376. * @port_id: Port ID number
  4377. * @copp_idx: copp index assigned
  4378. * @path: direction or ADM path type
  4379. * @perf_mode: performance mode like LL/ULL/..
  4380. * @cal_type: calibration type to use
  4381. * @params: pointer with cal data
  4382. * @size: cal size
  4383. *
  4384. * Returns 0 on success or error on failure
  4385. */
  4386. int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode,
  4387. int cal_type, char *params, int size)
  4388. {
  4389. int rc = 0;
  4390. pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n",
  4391. __func__, port_id, path, perf_mode, cal_type, size);
  4392. /* Maps audio_dev_ctrl path definition to ACDB definition */
  4393. if (get_cal_path(path) != RX_DEVICE) {
  4394. pr_err("%s: acdb_path %d\n", __func__, path);
  4395. rc = -EINVAL;
  4396. goto end;
  4397. }
  4398. rc = adm_set_pp_params(port_id, copp_idx, NULL, (u8 *) params, size);
  4399. end:
  4400. return rc;
  4401. }
  4402. EXPORT_SYMBOL(adm_send_calibration);
  4403. /*
  4404. * adm_update_wait_parameters must be called with routing driver locks.
  4405. * adm_reset_wait_parameters must be called with routing driver locks.
  4406. * set and reset parmeters are separated to make sure it is always called
  4407. * under routing driver lock.
  4408. * adm_wait_timeout is to block until timeout or interrupted. Timeout is
  4409. * not a an error.
  4410. */
  4411. int adm_set_wait_parameters(int port_id, int copp_idx)
  4412. {
  4413. int ret = 0, port_idx;
  4414. pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id,
  4415. copp_idx);
  4416. port_id = afe_convert_virtual_to_portid(port_id);
  4417. port_idx = adm_validate_and_get_port_index(port_id);
  4418. if (port_idx < 0) {
  4419. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  4420. ret = -EINVAL;
  4421. goto end;
  4422. }
  4423. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  4424. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  4425. return -EINVAL;
  4426. }
  4427. this_adm.copp.adm_delay[port_idx][copp_idx] = 1;
  4428. atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0);
  4429. end:
  4430. return ret;
  4431. }
  4432. EXPORT_SYMBOL(adm_set_wait_parameters);
  4433. /**
  4434. * adm_reset_wait_parameters -
  4435. * reset wait parameters or ADM delay value
  4436. *
  4437. * @port_id: Port ID number
  4438. * @copp_idx: copp index assigned
  4439. *
  4440. * Returns 0 on success or error on failure
  4441. */
  4442. int adm_reset_wait_parameters(int port_id, int copp_idx)
  4443. {
  4444. int ret = 0, port_idx;
  4445. pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id,
  4446. copp_idx);
  4447. port_id = afe_convert_virtual_to_portid(port_id);
  4448. port_idx = adm_validate_and_get_port_index(port_id);
  4449. if (port_idx < 0) {
  4450. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  4451. ret = -EINVAL;
  4452. goto end;
  4453. }
  4454. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  4455. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  4456. return -EINVAL;
  4457. }
  4458. atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1);
  4459. this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
  4460. end:
  4461. return ret;
  4462. }
  4463. EXPORT_SYMBOL(adm_reset_wait_parameters);
  4464. /**
  4465. * adm_wait_timeout -
  4466. * ADM wait command after command send to DSP
  4467. *
  4468. * @port_id: Port ID number
  4469. * @copp_idx: copp index assigned
  4470. * @wait_time: value in ms for command timeout
  4471. *
  4472. * Returns 0 on success or error on failure
  4473. */
  4474. int adm_wait_timeout(int port_id, int copp_idx, int wait_time)
  4475. {
  4476. int ret = 0, port_idx;
  4477. pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__,
  4478. port_id, copp_idx, wait_time);
  4479. port_id = afe_convert_virtual_to_portid(port_id);
  4480. port_idx = adm_validate_and_get_port_index(port_id);
  4481. if (port_idx < 0) {
  4482. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  4483. ret = -EINVAL;
  4484. goto end;
  4485. }
  4486. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  4487. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  4488. return -EINVAL;
  4489. }
  4490. ret = wait_event_timeout(
  4491. this_adm.copp.adm_delay_wait[port_idx][copp_idx],
  4492. atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]),
  4493. msecs_to_jiffies(wait_time));
  4494. pr_debug("%s: return %d\n", __func__, ret);
  4495. if (ret != 0)
  4496. ret = -EINTR;
  4497. end:
  4498. pr_debug("%s: return %d--\n", __func__, ret);
  4499. return ret;
  4500. }
  4501. EXPORT_SYMBOL(adm_wait_timeout);
  4502. /**
  4503. * adm_store_cal_data -
  4504. * Retrieve calibration data for ADM copp device
  4505. *
  4506. * @port_id: Port ID number
  4507. * @copp_idx: copp index assigned
  4508. * @path: direction or copp type
  4509. * @perf_mode: performance mode like LL/ULL/..
  4510. * @cal_index: calibration index to use
  4511. * @params: pointer to store cal data
  4512. * @size: pointer to fill with cal size
  4513. *
  4514. * Returns 0 on success or error on failure
  4515. */
  4516. int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode,
  4517. int cal_index, char *params, int *size)
  4518. {
  4519. int rc = 0;
  4520. struct cal_block_data *cal_block = NULL;
  4521. int app_type, acdb_id, port_idx, sample_rate;
  4522. if (this_adm.cal_data[cal_index] == NULL) {
  4523. pr_debug("%s: cal_index %d not allocated!\n",
  4524. __func__, cal_index);
  4525. goto end;
  4526. }
  4527. if (get_cal_path(path) != RX_DEVICE) {
  4528. pr_debug("%s: Invalid path to store calibration %d\n",
  4529. __func__, path);
  4530. rc = -EINVAL;
  4531. goto end;
  4532. }
  4533. port_id = afe_convert_virtual_to_portid(port_id);
  4534. port_idx = adm_validate_and_get_port_index(port_id);
  4535. if (port_idx < 0) {
  4536. pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
  4537. rc = -EINVAL;
  4538. goto end;
  4539. }
  4540. if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  4541. pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
  4542. return -EINVAL;
  4543. }
  4544. acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]);
  4545. app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]);
  4546. sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]);
  4547. mutex_lock(&this_adm.cal_data[cal_index]->lock);
  4548. cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type,
  4549. acdb_id, sample_rate);
  4550. if (cal_block == NULL)
  4551. goto unlock;
  4552. if (cal_block->cal_data.size <= 0) {
  4553. pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
  4554. __func__, port_id);
  4555. rc = -EINVAL;
  4556. goto unlock;
  4557. }
  4558. if (cal_index == ADM_AUDPROC_CAL || cal_index == ADM_LSM_AUDPROC_CAL) {
  4559. if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) {
  4560. pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n",
  4561. __func__, cal_block->cal_data.size, *size);
  4562. rc = -ENOMEM;
  4563. goto unlock;
  4564. }
  4565. } else if (cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) {
  4566. if (cal_block->cal_data.size > AUD_PROC_PERSIST_BLOCK_SIZE) {
  4567. pr_err("%s:persist invalid size exp/actual[%zd, %d]\n",
  4568. __func__, cal_block->cal_data.size, *size);
  4569. rc = -ENOMEM;
  4570. goto unlock;
  4571. }
  4572. } else if (cal_index == ADM_AUDPROC_PERSISTENT_CAL) {
  4573. if (cal_block->cal_data.size > AUD_PROC_PERSIST_BLOCK_SIZE) {
  4574. pr_err("%s:persist invalid size exp/actual[%zd, %d]\n",
  4575. __func__, cal_block->cal_data.size, *size);
  4576. rc = -ENOMEM;
  4577. goto unlock;
  4578. }
  4579. }
  4580. else if (cal_index == ADM_AUDVOL_CAL) {
  4581. if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) {
  4582. pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n",
  4583. __func__, cal_block->cal_data.size, *size);
  4584. rc = -ENOMEM;
  4585. goto unlock;
  4586. }
  4587. } else {
  4588. pr_debug("%s: Not valid calibration for dolby topolgy\n",
  4589. __func__);
  4590. rc = -EINVAL;
  4591. goto unlock;
  4592. }
  4593. memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size);
  4594. *size = cal_block->cal_data.size;
  4595. pr_debug("%s:port_id %d, copp_idx %d, path %d",
  4596. __func__, port_id, copp_idx, path);
  4597. pr_debug("perf_mode %d, cal_type %d, size %d\n",
  4598. perf_mode, cal_index, *size);
  4599. unlock:
  4600. mutex_unlock(&this_adm.cal_data[cal_index]->lock);
  4601. end:
  4602. return rc;
  4603. }
  4604. EXPORT_SYMBOL(adm_store_cal_data);
  4605. /**
  4606. * adm_send_compressed_device_mute -
  4607. * command to send mute for compressed device
  4608. *
  4609. * @port_id: Port ID number
  4610. * @copp_idx: copp index assigned
  4611. * @mute_on: flag to indicate mute or unmute
  4612. *
  4613. * Returns 0 on success or error on failure
  4614. */
  4615. int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on)
  4616. {
  4617. u32 mute_param = mute_on ? 1 : 0;
  4618. struct param_hdr_v3 param_hdr;
  4619. int ret = 0;
  4620. pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n",
  4621. __func__, port_id, copp_idx, mute_on);
  4622. memset(&param_hdr, 0, sizeof(param_hdr));
  4623. param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE;
  4624. param_hdr.instance_id = INSTANCE_ID_0;
  4625. param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE;
  4626. param_hdr.param_size = sizeof(mute_param);
  4627. ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4628. (uint8_t *) &mute_param);
  4629. if (ret)
  4630. pr_err("%s: Failed to set mute, err %d\n", __func__, ret);
  4631. return ret;
  4632. }
  4633. EXPORT_SYMBOL(adm_send_compressed_device_mute);
  4634. /**
  4635. * adm_send_compressed_device_latency -
  4636. * command to send latency for compressed device
  4637. *
  4638. * @port_id: Port ID number
  4639. * @copp_idx: copp index assigned
  4640. * @latency: latency value to pass
  4641. *
  4642. * Returns 0 on success or error on failure
  4643. */
  4644. int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency)
  4645. {
  4646. u32 latency_param;
  4647. struct param_hdr_v3 param_hdr;
  4648. int ret = 0;
  4649. pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__,
  4650. port_id, copp_idx, latency);
  4651. if (latency < 0) {
  4652. pr_err("%s: Invalid value for latency %d", __func__, latency);
  4653. return -EINVAL;
  4654. }
  4655. memset(&param_hdr, 0, sizeof(param_hdr));
  4656. param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY;
  4657. param_hdr.instance_id = INSTANCE_ID_0;
  4658. param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY;
  4659. param_hdr.param_size = sizeof(latency_param);
  4660. latency_param = latency;
  4661. ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4662. (uint8_t *) &latency_param);
  4663. if (ret)
  4664. pr_err("%s: Failed to set latency, err %d\n", __func__, ret);
  4665. return ret;
  4666. }
  4667. EXPORT_SYMBOL(adm_send_compressed_device_latency);
  4668. /**
  4669. * adm_swap_speaker_channels
  4670. *
  4671. * Receives port_id, copp_idx, sample rate, spk_swap and
  4672. * send MFC command to swap speaker channel.
  4673. * Return zero on success. On failure returns nonzero.
  4674. *
  4675. * port_id - Passed value, port_id for which channels swap is wanted
  4676. * copp_idx - Passed value, copp_idx for which channels swap is wanted
  4677. * sample_rate - Passed value, sample rate used by app type config
  4678. * spk_swap - Passed value, spk_swap for check if swap flag is set
  4679. */
  4680. int adm_swap_speaker_channels(int port_id, int copp_idx,
  4681. int sample_rate, bool spk_swap)
  4682. {
  4683. struct audproc_mfc_param_media_fmt mfc_cfg;
  4684. struct param_hdr_v3 param_hdr;
  4685. uint16_t num_channels;
  4686. int port_idx = 0;
  4687. int ret = 0;
  4688. pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
  4689. __func__, port_id, copp_idx);
  4690. port_id = q6audio_convert_virtual_to_portid(port_id);
  4691. port_idx = adm_validate_and_get_port_index(port_id);
  4692. if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
  4693. pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
  4694. return -EINVAL;
  4695. } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
  4696. pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
  4697. return -EINVAL;
  4698. }
  4699. num_channels = atomic_read(&this_adm.copp.channels[port_idx][copp_idx]);
  4700. if (num_channels != 2) {
  4701. pr_debug("%s: Invalid number of channels: %d\n",
  4702. __func__, num_channels);
  4703. return -EINVAL;
  4704. }
  4705. memset(&mfc_cfg, 0, sizeof(mfc_cfg));
  4706. memset(&param_hdr, 0, sizeof(param_hdr));
  4707. param_hdr.module_id = AUDPROC_MODULE_ID_MFC;
  4708. param_hdr.instance_id = INSTANCE_ID_0;
  4709. param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
  4710. param_hdr.param_size = sizeof(mfc_cfg);
  4711. mfc_cfg.sampling_rate = sample_rate;
  4712. mfc_cfg.bits_per_sample =
  4713. atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
  4714. mfc_cfg.num_channels = num_channels;
  4715. /* Currently applying speaker swap for only 2 channel use case */
  4716. if (spk_swap) {
  4717. mfc_cfg.channel_type[0] =
  4718. (uint16_t) PCM_CHANNEL_FR;
  4719. mfc_cfg.channel_type[1] =
  4720. (uint16_t) PCM_CHANNEL_FL;
  4721. } else {
  4722. mfc_cfg.channel_type[0] =
  4723. (uint16_t) PCM_CHANNEL_FL;
  4724. mfc_cfg.channel_type[1] =
  4725. (uint16_t) PCM_CHANNEL_FR;
  4726. }
  4727. ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4728. (u8 *) &mfc_cfg);
  4729. if (ret < 0) {
  4730. pr_err("%s: Failed to set swap speaker channels on port[0x%x] failed %d\n",
  4731. __func__, port_id, ret);
  4732. return ret;
  4733. }
  4734. pr_debug("%s: mfc_cfg Set params returned success", __func__);
  4735. return 0;
  4736. }
  4737. EXPORT_SYMBOL(adm_swap_speaker_channels);
  4738. /**
  4739. * adm_set_sound_focus -
  4740. * Update sound focus info
  4741. *
  4742. * @port_id: Port ID number
  4743. * @copp_idx: copp index assigned
  4744. * @soundFocusData: sound focus data to pass
  4745. *
  4746. * Returns 0 on success or error on failure
  4747. */
  4748. int adm_set_sound_focus(int port_id, int copp_idx,
  4749. struct sound_focus_param soundFocusData)
  4750. {
  4751. struct adm_param_fluence_soundfocus_t soundfocus_params;
  4752. struct param_hdr_v3 param_hdr;
  4753. int ret = 0;
  4754. int i;
  4755. pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
  4756. __func__, port_id, copp_idx);
  4757. memset(&param_hdr, 0, sizeof(param_hdr));
  4758. param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX;
  4759. param_hdr.instance_id = INSTANCE_ID_0;
  4760. param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS;
  4761. param_hdr.param_size = sizeof(soundfocus_params);
  4762. memset(&(soundfocus_params), 0xFF, sizeof(soundfocus_params));
  4763. for (i = 0; i < MAX_SECTORS; i++) {
  4764. soundfocus_params.start_angles[i] =
  4765. soundFocusData.start_angle[i];
  4766. soundfocus_params.enables[i] = soundFocusData.enable[i];
  4767. pr_debug("%s: start_angle[%d] = %d\n",
  4768. __func__, i, soundFocusData.start_angle[i]);
  4769. pr_debug("%s: enable[%d] = %d\n",
  4770. __func__, i, soundFocusData.enable[i]);
  4771. }
  4772. soundfocus_params.gain_step = soundFocusData.gain_step;
  4773. pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
  4774. soundfocus_params.reserved = 0;
  4775. ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr,
  4776. (uint8_t *) &soundfocus_params);
  4777. if (ret)
  4778. pr_err("%s: Failed to set sound focus params, err %d\n",
  4779. __func__, ret);
  4780. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  4781. return ret;
  4782. }
  4783. EXPORT_SYMBOL(adm_set_sound_focus);
  4784. /**
  4785. * adm_get_sound_focus -
  4786. * Retrieve sound focus info
  4787. *
  4788. * @port_id: Port ID number
  4789. * @copp_idx: copp index assigned
  4790. * @soundFocusData: pointer for sound focus data to be updated with
  4791. *
  4792. * Returns 0 on success or error on failure
  4793. */
  4794. int adm_get_sound_focus(int port_id, int copp_idx,
  4795. struct sound_focus_param *soundFocusData)
  4796. {
  4797. int ret = 0, i;
  4798. char *params_value;
  4799. uint32_t max_param_size = 0;
  4800. struct adm_param_fluence_soundfocus_t *soundfocus_params = NULL;
  4801. struct param_hdr_v3 param_hdr;
  4802. pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
  4803. __func__, port_id, copp_idx);
  4804. max_param_size = sizeof(struct adm_param_fluence_soundfocus_t) +
  4805. sizeof(union param_hdrs);
  4806. params_value = kzalloc(max_param_size, GFP_KERNEL);
  4807. if (!params_value)
  4808. return -ENOMEM;
  4809. memset(&param_hdr, 0, sizeof(param_hdr));
  4810. param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX;
  4811. param_hdr.instance_id = INSTANCE_ID_0;
  4812. param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS;
  4813. param_hdr.param_size = max_param_size;
  4814. ret = adm_get_pp_params(port_id, copp_idx,
  4815. ADM_CLIENT_ID_SOURCE_TRACKING, NULL, &param_hdr,
  4816. params_value);
  4817. if (ret) {
  4818. pr_err("%s: get parameters failed ret:%d\n", __func__, ret);
  4819. ret = -EINVAL;
  4820. goto done;
  4821. }
  4822. if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
  4823. pr_err("%s - get params returned error [%s]\n",
  4824. __func__, adsp_err_get_err_str(
  4825. this_adm.sourceTrackingData.apr_cmd_status));
  4826. ret = adsp_err_get_lnx_err_code(
  4827. this_adm.sourceTrackingData.apr_cmd_status);
  4828. goto done;
  4829. }
  4830. soundfocus_params = (struct adm_param_fluence_soundfocus_t *)
  4831. params_value;
  4832. for (i = 0; i < MAX_SECTORS; i++) {
  4833. soundFocusData->start_angle[i] =
  4834. soundfocus_params->start_angles[i];
  4835. soundFocusData->enable[i] = soundfocus_params->enables[i];
  4836. pr_debug("%s: start_angle[%d] = %d\n",
  4837. __func__, i, soundFocusData->start_angle[i]);
  4838. pr_debug("%s: enable[%d] = %d\n",
  4839. __func__, i, soundFocusData->enable[i]);
  4840. }
  4841. soundFocusData->gain_step = soundfocus_params->gain_step;
  4842. pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step);
  4843. done:
  4844. pr_debug("%s: Exit, ret = %d\n", __func__, ret);
  4845. kfree(params_value);
  4846. return ret;
  4847. }
  4848. EXPORT_SYMBOL(adm_get_sound_focus);
  4849. static int adm_source_tracking_alloc_map_memory(void)
  4850. {
  4851. int ret;
  4852. pr_debug("%s: Enter\n", __func__);
  4853. ret = msm_audio_ion_alloc(&this_adm.sourceTrackingData.dma_buf,
  4854. AUD_PROC_BLOCK_SIZE,
  4855. &this_adm.sourceTrackingData.memmap.paddr,
  4856. &this_adm.sourceTrackingData.memmap.size,
  4857. &this_adm.sourceTrackingData.memmap.kvaddr);
  4858. if (ret) {
  4859. pr_err("%s: failed to allocate memory\n", __func__);
  4860. ret = -EINVAL;
  4861. goto done;
  4862. }
  4863. atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
  4864. ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr,
  4865. 0,
  4866. (uint32_t *)&this_adm.sourceTrackingData.memmap.size,
  4867. 1);
  4868. if (ret < 0) {
  4869. pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n",
  4870. __func__,
  4871. (void *)this_adm.sourceTrackingData.memmap.paddr,
  4872. (uint32_t)this_adm.sourceTrackingData.memmap.size);
  4873. msm_audio_ion_free(this_adm.sourceTrackingData.dma_buf);
  4874. this_adm.sourceTrackingData.dma_buf = NULL;
  4875. this_adm.sourceTrackingData.memmap.size = 0;
  4876. this_adm.sourceTrackingData.memmap.kvaddr = NULL;
  4877. this_adm.sourceTrackingData.memmap.paddr = 0;
  4878. this_adm.sourceTrackingData.apr_cmd_status = -1;
  4879. atomic_set(&this_adm.mem_map_handles
  4880. [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
  4881. ret = -EINVAL;
  4882. goto done;
  4883. }
  4884. ret = 0;
  4885. pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n",
  4886. __func__, (void *)this_adm.sourceTrackingData.memmap.paddr,
  4887. (uint32_t)this_adm.sourceTrackingData.memmap.size,
  4888. atomic_read(&this_adm.mem_map_handles
  4889. [ADM_MEM_MAP_INDEX_SOURCE_TRACKING]));
  4890. done:
  4891. pr_debug("%s: Exit, ret = %d\n", __func__, ret);
  4892. return ret;
  4893. }
  4894. /**
  4895. * adm_get_source_tracking -
  4896. * Retrieve source tracking info
  4897. *
  4898. * @port_id: Port ID number
  4899. * @copp_idx: copp index assigned
  4900. * @sourceTrackingData: pointer for source track data to be updated with
  4901. *
  4902. * Returns 0 on success or error on failure
  4903. */
  4904. int adm_get_source_tracking(int port_id, int copp_idx,
  4905. struct source_tracking_param *sourceTrackingData)
  4906. {
  4907. struct adm_param_fluence_sourcetracking_t *source_tracking_params =
  4908. NULL;
  4909. struct mem_mapping_hdr mem_hdr;
  4910. struct param_hdr_v3 param_hdr;
  4911. int i = 0;
  4912. int ret = 0;
  4913. pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
  4914. __func__, port_id, copp_idx);
  4915. if (!this_adm.sourceTrackingData.memmap.paddr) {
  4916. /* Allocate and map shared memory for out of band usage */
  4917. ret = adm_source_tracking_alloc_map_memory();
  4918. if (ret != 0) {
  4919. ret = -EINVAL;
  4920. goto done;
  4921. }
  4922. }
  4923. memset(&mem_hdr, 0, sizeof(mem_hdr));
  4924. memset(&param_hdr, 0, sizeof(param_hdr));
  4925. mem_hdr.data_payload_addr_lsw =
  4926. lower_32_bits(this_adm.sourceTrackingData.memmap.paddr);
  4927. mem_hdr.data_payload_addr_msw = msm_audio_populate_upper_32_bits(
  4928. this_adm.sourceTrackingData.memmap.paddr);
  4929. mem_hdr.mem_map_handle = atomic_read(
  4930. &this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING]);
  4931. param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX;
  4932. param_hdr.instance_id = INSTANCE_ID_0;
  4933. param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING;
  4934. /*
  4935. * This size should be the max size of the calibration data + header.
  4936. * Use the union size to ensure max size is used.
  4937. */
  4938. param_hdr.param_size =
  4939. sizeof(struct adm_param_fluence_sourcetracking_t) +
  4940. sizeof(struct param_hdr_v3);
  4941. /*
  4942. * Retrieving parameters out of band, so no need to provide a buffer for
  4943. * the returned parameter data as it will be at the memory location
  4944. * provided.
  4945. */
  4946. ret = adm_get_pp_params(port_id, copp_idx,
  4947. ADM_CLIENT_ID_SOURCE_TRACKING, &mem_hdr,
  4948. &param_hdr, NULL);
  4949. if (ret) {
  4950. pr_err("%s: Failed to get params, error %d\n", __func__, ret);
  4951. goto done;
  4952. }
  4953. if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
  4954. pr_err("%s - get params returned error [%s]\n",
  4955. __func__, adsp_err_get_err_str(
  4956. this_adm.sourceTrackingData.apr_cmd_status));
  4957. ret = adsp_err_get_lnx_err_code(
  4958. this_adm.sourceTrackingData.apr_cmd_status);
  4959. goto done;
  4960. }
  4961. /* How do we know what the param data was retrieved with for hdr size */
  4962. source_tracking_params =
  4963. (struct adm_param_fluence_sourcetracking_t
  4964. *) (this_adm.sourceTrackingData.memmap.kvaddr +
  4965. sizeof(struct param_hdr_v3));
  4966. for (i = 0; i < MAX_SECTORS; i++) {
  4967. sourceTrackingData->vad[i] = source_tracking_params->vad[i];
  4968. pr_debug("%s: vad[%d] = %d\n",
  4969. __func__, i, sourceTrackingData->vad[i]);
  4970. }
  4971. sourceTrackingData->doa_speech = source_tracking_params->doa_speech;
  4972. pr_debug("%s: doa_speech = %d\n",
  4973. __func__, sourceTrackingData->doa_speech);
  4974. for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
  4975. sourceTrackingData->doa_noise[i] =
  4976. source_tracking_params->doa_noise[i];
  4977. pr_debug("%s: doa_noise[%d] = %d\n",
  4978. __func__, i, sourceTrackingData->doa_noise[i]);
  4979. }
  4980. for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
  4981. sourceTrackingData->polar_activity[i] =
  4982. source_tracking_params->polar_activity[i];
  4983. pr_debug("%s: polar_activity[%d] = %d\n",
  4984. __func__, i, sourceTrackingData->polar_activity[i]);
  4985. }
  4986. ret = 0;
  4987. done:
  4988. pr_debug("%s: Exit, ret=%d\n", __func__, ret);
  4989. return ret;
  4990. }
  4991. EXPORT_SYMBOL(adm_get_source_tracking);
  4992. /**
  4993. * adm_get_doa_tracking_mon -
  4994. * Retrieve doa tracking monitor info
  4995. *
  4996. * @port_id: Port ID number
  4997. * @copp_idx: copp index assigned
  4998. * @doa_tracking_data: pointer for doa data to be updated with
  4999. *
  5000. * Returns 0 on success or error on failure
  5001. */
  5002. int adm_get_doa_tracking_mon(int port_id, int copp_idx,
  5003. struct doa_tracking_mon_param *doa_tracking_data)
  5004. {
  5005. int ret = 0, i;
  5006. char *params_value;
  5007. uint32_t max_param_size = 0;
  5008. struct adm_param_doa_tracking_mon_t *doa_tracking_params = NULL;
  5009. struct param_hdr_v3 param_hdr;
  5010. pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
  5011. __func__, port_id, copp_idx);
  5012. if (doa_tracking_data == NULL) {
  5013. pr_err("%s: Received NULL pointer for doa tracking data\n",
  5014. __func__);
  5015. return -EINVAL;
  5016. }
  5017. max_param_size = sizeof(struct adm_param_doa_tracking_mon_t) +
  5018. sizeof(union param_hdrs);
  5019. params_value = kzalloc(max_param_size, GFP_KERNEL);
  5020. if (!params_value)
  5021. return -ENOMEM;
  5022. memset(&param_hdr, 0, sizeof(param_hdr));
  5023. param_hdr.module_id = AUDPROC_MODULE_ID_FFECNS;
  5024. param_hdr.instance_id = INSTANCE_ID_0;
  5025. param_hdr.param_id = AUDPROC_PARAM_ID_FFV_DOA_TRACKING_MONITOR;
  5026. param_hdr.param_size = max_param_size;
  5027. ret = adm_get_pp_params(port_id, copp_idx,
  5028. ADM_CLIENT_ID_DEFAULT, NULL, &param_hdr,
  5029. params_value);
  5030. if (ret) {
  5031. pr_err("%s: get parameters failed ret:%d\n", __func__, ret);
  5032. goto done;
  5033. }
  5034. doa_tracking_params =
  5035. (struct adm_param_doa_tracking_mon_t *)params_value;
  5036. for (i = 0; i < MAX_DOA_TRACKING_ANGLES; i++) {
  5037. doa_tracking_data->target_angle_L16[i] =
  5038. doa_tracking_params->target_angle_L16[i];
  5039. pr_debug("%s: target angle[%d] = %d\n",
  5040. __func__, i, doa_tracking_data->target_angle_L16[i]);
  5041. }
  5042. for (i = 0; i < MAX_DOA_TRACKING_ANGLES; i++) {
  5043. doa_tracking_data->interf_angle_L16[i] =
  5044. doa_tracking_params->interf_angle_L16[i];
  5045. pr_debug("%s: interference angle[%d] = %d\n",
  5046. __func__, i, doa_tracking_data->interf_angle_L16[i]);
  5047. }
  5048. for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
  5049. doa_tracking_data->polar_activity[i] =
  5050. doa_tracking_params->polar_activity[i];
  5051. }
  5052. done:
  5053. pr_debug("%s: Exit, ret = %d\n", __func__, ret);
  5054. kfree(params_value);
  5055. return ret;
  5056. }
  5057. EXPORT_SYMBOL(adm_get_doa_tracking_mon);
  5058. int __init adm_init(void)
  5059. {
  5060. int i = 0, j;
  5061. this_adm.ec_ref_rx = -1;
  5062. this_adm.ffecns_port_id = -1;
  5063. this_adm.tx_port_id = -1;
  5064. this_adm.hyp_assigned = false;
  5065. init_waitqueue_head(&this_adm.matrix_map_wait);
  5066. init_waitqueue_head(&this_adm.adm_wait);
  5067. for (i = 0; i < AFE_MAX_PORTS; i++) {
  5068. for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
  5069. atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID);
  5070. init_waitqueue_head(&this_adm.copp.wait[i][j]);
  5071. init_waitqueue_head(
  5072. &this_adm.copp.adm_delay_wait[i][j]);
  5073. }
  5074. }
  5075. if (adm_init_cal_data())
  5076. pr_err("%s: could not init cal data!\n", __func__);
  5077. this_adm.sourceTrackingData.dma_buf = NULL;
  5078. this_adm.sourceTrackingData.memmap.size = 0;
  5079. this_adm.sourceTrackingData.memmap.kvaddr = NULL;
  5080. this_adm.sourceTrackingData.memmap.paddr = 0;
  5081. this_adm.sourceTrackingData.apr_cmd_status = -1;
  5082. return 0;
  5083. }
  5084. void adm_exit(void)
  5085. {
  5086. if (this_adm.apr)
  5087. adm_reset_data();
  5088. adm_delete_cal_data();
  5089. }