q6adm.c 159 KB

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