q6adm.c 158 KB

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