q6adm.c 157 KB

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