q6adm.c 150 KB

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