q6adm.c 166 KB

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