q6adm.c 166 KB

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