q6adm.c 149 KB

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