q6adm.c 149 KB

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