q6adm.c 150 KB

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