q6adm.c 167 KB

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