q6adm.c 152 KB

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