q6adm.c 149 KB

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