q6adm.c 163 KB

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