q6adm.c 150 KB

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