q6adm.c 149 KB

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