q6adm.c 152 KB

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