q6adm.c 135 KB

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