123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574 |
- // SPDX-License-Identifier: GPL-2.0-only
- /* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
- */
- #include <linux/init.h>
- #include <linux/err.h>
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/time.h>
- #include <linux/math64.h>
- #include <linux/wait.h>
- #include <linux/mutex.h>
- #include <linux/platform_device.h>
- #include <linux/slab.h>
- #include <sound/core.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/pcm.h>
- #include <sound/initval.h>
- #include <sound/control.h>
- #include <sound/pcm_params.h>
- #include <sound/audio_effects.h>
- #include <asm/dma.h>
- #include <linux/dma-mapping.h>
- #include <linux/msm_audio.h>
- #include <sound/timer.h>
- #include <sound/tlv.h>
- #include <sound/compress_params.h>
- #include <sound/compress_offload.h>
- #include <sound/compress_driver.h>
- #include <dsp/msm_audio_ion.h>
- #include <dsp/apr_audio-v2.h>
- #include <dsp/q6asm-v2.h>
- #include <dsp/q6core.h>
- #include <dsp/msm-audio-effects-q6-v2.h>
- #include "msm-pcm-routing-v2.h"
- #include "msm-qti-pp-config.h"
- #define DRV_NAME "msm-compress-q6-v2"
- #define TIMEOUT_MS 1000
- #define DSP_PP_BUFFERING_IN_MSEC 25
- #define PARTIAL_DRAIN_ACK_EARLY_BY_MSEC 150
- #define MP3_OUTPUT_FRAME_SZ 1152
- #define AAC_OUTPUT_FRAME_SZ 1024
- #define AC3_OUTPUT_FRAME_SZ 1536
- #define EAC3_OUTPUT_FRAME_SZ 1536
- #define DSP_NUM_OUTPUT_FRAME_BUFFERED 2
- #define FLAC_BLK_SIZE_LIMIT 65535
- /* Timestamp mode payload offsets */
- #define CAPTURE_META_DATA_TS_OFFSET_LSW 6
- #define CAPTURE_META_DATA_TS_OFFSET_MSW 7
- /* decoder parameter length */
- #define DDP_DEC_MAX_NUM_PARAM 18
- /* Default values used if user space does not set */
- #define COMPR_PLAYBACK_MIN_FRAGMENT_SIZE (8 * 1024)
- #define COMPR_PLAYBACK_MAX_FRAGMENT_SIZE (128 * 1024)
- #define COMPR_PLAYBACK_MIN_NUM_FRAGMENTS (4)
- #define COMPR_PLAYBACK_MAX_NUM_FRAGMENTS (16 * 4)
- #define COMPRESSED_LR_VOL_MAX_STEPS 0x2000
- const DECLARE_TLV_DB_LINEAR(msm_compr_vol_gain, 0,
- COMPRESSED_LR_VOL_MAX_STEPS);
- /* Stream id switches between 1 and 2 */
- #define NEXT_STREAM_ID(stream_id) ((stream_id & 1) + 1)
- #define STREAM_ARRAY_INDEX(stream_id) (stream_id - 1)
- #define MAX_NUMBER_OF_STREAMS 2
- #define SND_DEC_DDP_MAX_PARAMS 18
- #ifndef COMPRESSED_PERF_MODE_FLAG
- #define COMPRESSED_PERF_MODE_FLAG 0
- #endif
- struct msm_compr_gapless_state {
- bool set_next_stream_id;
- int32_t stream_opened[MAX_NUMBER_OF_STREAMS];
- uint32_t initial_samples_drop;
- uint32_t trailing_samples_drop;
- uint32_t gapless_transition;
- bool use_dsp_gapless_mode;
- union snd_codec_options codec_options;
- };
- static unsigned int supported_sample_rates[] = {
- 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000,
- 88200, 96000, 128000, 144000, 176400, 192000, 352800, 384000, 2822400,
- 5644800
- };
- struct msm_compr_pdata {
- struct snd_compr_stream *cstream[MSM_FRONTEND_DAI_MAX];
- uint32_t volume[MSM_FRONTEND_DAI_MAX][2]; /* For both L & R */
- struct msm_compr_audio_effects *audio_effects[MSM_FRONTEND_DAI_MAX];
- bool use_dsp_gapless_mode;
- bool use_legacy_api; /* indicates use older asm apis*/
- struct msm_compr_dec_params *dec_params[MSM_FRONTEND_DAI_MAX];
- struct msm_compr_ch_map *ch_map[MSM_FRONTEND_DAI_MAX];
- bool is_in_use[MSM_FRONTEND_DAI_MAX];
- struct msm_pcm_channel_mixer *chmixer_pspd[MSM_FRONTEND_DAI_MM_SIZE];
- struct mutex lock;
- };
- struct msm_compr_audio {
- struct snd_compr_stream *cstream;
- struct snd_compr_caps compr_cap;
- struct snd_compr_codec_caps codec_caps;
- struct snd_compr_params codec_param;
- struct audio_client *audio_client;
- uint32_t codec;
- uint32_t compr_passthr;
- void *buffer; /* virtual address */
- phys_addr_t buffer_paddr; /* physical address */
- uint32_t app_pointer;
- uint32_t buffer_size;
- uint32_t byte_offset;
- uint64_t copied_total; /* bytes consumed by DSP */
- uint64_t bytes_received; /* from userspace */
- uint64_t bytes_sent; /* to DSP */
- uint64_t received_total; /* bytes received from DSP */
- uint64_t bytes_copied; /* to userspace */
- uint64_t bytes_read; /* from DSP */
- uint32_t bytes_read_offset; /* bytes read offset */
- uint32_t ts_header_offset; /* holds the timestamp header offset */
- int32_t first_buffer;
- int32_t last_buffer;
- int32_t partial_drain_delay;
- uint16_t session_id;
- uint32_t sample_rate;
- uint32_t num_channels;
- /*
- * convention - commands coming from the same thread
- * can use the common cmd_ack var. Others (e.g drain/EOS)
- * must use separate vars to track command status.
- */
- uint32_t cmd_ack;
- uint32_t cmd_interrupt;
- uint32_t drain_ready;
- uint32_t eos_ack;
- uint32_t stream_available;
- uint32_t next_stream;
- uint32_t run_mode;
- uint32_t start_delay_lsw;
- uint32_t start_delay_msw;
- uint64_t marker_timestamp;
- struct msm_compr_gapless_state gapless_state;
- atomic_t start;
- atomic_t eos;
- atomic_t drain;
- atomic_t xrun;
- atomic_t close;
- atomic_t wait_on_close;
- atomic_t error;
- wait_queue_head_t eos_wait;
- wait_queue_head_t drain_wait;
- wait_queue_head_t close_wait;
- wait_queue_head_t wait_for_stream_avail;
- spinlock_t lock;
- };
- const u32 compr_codecs[] = {
- SND_AUDIOCODEC_AC3, SND_AUDIOCODEC_EAC3, SND_AUDIOCODEC_DTS,
- SND_AUDIOCODEC_DSD, SND_AUDIOCODEC_TRUEHD, SND_AUDIOCODEC_IEC61937};
- struct query_audio_effect {
- uint32_t mod_id;
- uint32_t parm_id;
- uint32_t size;
- uint32_t offset;
- uint32_t device;
- };
- struct msm_compr_audio_effects {
- struct bass_boost_params bass_boost;
- struct pbe_params pbe;
- struct virtualizer_params virtualizer;
- struct reverb_params reverb;
- struct eq_params equalizer;
- struct soft_volume_params volume;
- struct query_audio_effect query;
- };
- struct snd_dec_ddp {
- __u32 params_length;
- __u32 params_id[SND_DEC_DDP_MAX_PARAMS];
- __u32 params_value[SND_DEC_DDP_MAX_PARAMS];
- } __attribute__((packed, aligned(4)));
- struct msm_compr_dec_params {
- struct snd_dec_ddp ddp_params;
- };
- struct msm_compr_ch_map {
- bool set_ch_map;
- char channel_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8];
- };
- static int msm_compr_send_dec_params(struct snd_compr_stream *cstream,
- struct msm_compr_dec_params *dec_params,
- int stream_id);
- static int msm_compr_set_render_mode(struct msm_compr_audio *prtd,
- uint32_t render_mode) {
- int ret = -EINVAL;
- struct audio_client *ac = prtd->audio_client;
- pr_debug("%s, got render mode %u\n", __func__, render_mode);
- if (render_mode == SNDRV_COMPRESS_RENDER_MODE_AUDIO_MASTER) {
- render_mode = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_DEFAULT;
- } else if (render_mode == SNDRV_COMPRESS_RENDER_MODE_STC_MASTER) {
- render_mode = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_LOCAL_STC;
- prtd->run_mode = ASM_SESSION_CMD_RUN_STARTIME_RUN_WITH_DELAY;
- } else {
- pr_err("%s, Invalid render mode %u\n", __func__,
- render_mode);
- ret = -EINVAL;
- goto exit;
- }
- ret = q6asm_send_mtmx_strtr_render_mode(ac, render_mode);
- if (ret) {
- pr_err("%s, Render mode can't be set error %d\n", __func__,
- ret);
- }
- exit:
- return ret;
- }
- static int msm_compr_set_clk_rec_mode(struct audio_client *ac,
- uint32_t clk_rec_mode) {
- int ret = -EINVAL;
- pr_debug("%s, got clk rec mode %u\n", __func__, clk_rec_mode);
- if (clk_rec_mode == SNDRV_COMPRESS_CLK_REC_MODE_NONE) {
- clk_rec_mode = ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_NONE;
- } else if (clk_rec_mode == SNDRV_COMPRESS_CLK_REC_MODE_AUTO) {
- clk_rec_mode = ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_AUTO;
- } else {
- pr_err("%s, Invalid clk rec_mode mode %u\n", __func__,
- clk_rec_mode);
- ret = -EINVAL;
- goto exit;
- }
- ret = q6asm_send_mtmx_strtr_clk_rec_mode(ac, clk_rec_mode);
- if (ret) {
- pr_err("%s, clk rec mode can't be set, error %d\n", __func__,
- ret);
- }
- exit:
- return ret;
- }
- static int msm_compr_set_render_window(struct audio_client *ac,
- uint32_t ws_lsw, uint32_t ws_msw,
- uint32_t we_lsw, uint32_t we_msw)
- {
- int ret = -EINVAL;
- struct asm_session_mtmx_strtr_param_window_v2_t asm_mtmx_strtr_window;
- uint32_t param_id;
- pr_debug("%s, ws_lsw 0x%x ws_msw 0x%x we_lsw 0x%x we_ms 0x%x\n",
- __func__, ws_lsw, ws_msw, we_lsw, we_msw);
- memset(&asm_mtmx_strtr_window, 0,
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t));
- asm_mtmx_strtr_window.window_lsw = ws_lsw;
- asm_mtmx_strtr_window.window_msw = ws_msw;
- param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_START_V2;
- ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window,
- param_id);
- if (ret) {
- pr_err("%s, start window can't be set error %d\n", __func__,
- ret);
- goto exit;
- }
- asm_mtmx_strtr_window.window_lsw = we_lsw;
- asm_mtmx_strtr_window.window_msw = we_msw;
- param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_END_V2;
- ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window,
- param_id);
- if (ret) {
- pr_err("%s, end window can't be set error %d\n", __func__,
- ret);
- }
- exit:
- return ret;
- }
- static int msm_compr_enable_adjust_session_clock(struct audio_client *ac,
- bool enable)
- {
- int ret;
- pr_debug("%s, enable adjust_session %d\n", __func__, enable);
- ret = q6asm_send_mtmx_strtr_enable_adjust_session_clock(ac, enable);
- if (ret)
- pr_err("%s, adjust session clock can't be set error %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_compr_adjust_session_clock(struct audio_client *ac,
- uint32_t adjust_session_lsw, uint32_t adjust_session_msw)
- {
- int ret;
- pr_debug("%s, adjust_session_time_msw 0x%x adjust_session_time_lsw 0x%x\n",
- __func__, adjust_session_msw, adjust_session_lsw);
- ret = q6asm_adjust_session_clock(ac,
- adjust_session_lsw,
- adjust_session_msw);
- if (ret)
- pr_err("%s, adjust session clock can't be set error %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_compr_set_volume(struct snd_compr_stream *cstream,
- uint32_t volume_l, uint32_t volume_r)
- {
- struct msm_compr_audio *prtd;
- int rc = 0;
- uint32_t avg_vol, gain_list[VOLUME_CONTROL_MAX_CHANNELS];
- uint32_t num_channels;
- struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_component *component = NULL;
- struct msm_compr_pdata *pdata;
- bool use_default = true;
- u8 *chmap = NULL;
- pr_debug("%s: volume_l %d volume_r %d\n",
- __func__, volume_l, volume_r);
- if (!cstream || !cstream->runtime) {
- pr_err("%s: session not active\n", __func__);
- return -EPERM;
- }
- rtd = cstream->private_data;
- prtd = cstream->runtime->private_data;
- if (!rtd || !prtd || !prtd->audio_client) {
- pr_err("%s: invalid rtd, prtd or audio client", __func__);
- return rc;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: invalid component\n", __func__);
- return rc;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s: No volume config for passthrough %d\n",
- __func__, prtd->compr_passthr);
- return rc;
- }
- use_default = !(pdata->ch_map[rtd->dai_link->id]->set_ch_map);
- chmap = pdata->ch_map[rtd->dai_link->id]->channel_map;
- num_channels = prtd->num_channels;
- if (prtd->num_channels > 2) {
- /*
- * Currently the left and right gains are averaged an applied
- * to all channels. This might not be desirable. But currently,
- * there exists no API in userspace to send a list of gains for
- * each channel either. If such an API does become available,
- * the mixer control must be updated to accept more than 2
- * channel gains.
- *
- */
- avg_vol = (volume_l + volume_r) / 2;
- rc = q6asm_set_volume(prtd->audio_client, avg_vol);
- } else {
- gain_list[0] = volume_l;
- gain_list[1] = volume_r;
- gain_list[2] = volume_l;
- if (use_default)
- num_channels = 3;
- rc = q6asm_set_multich_gain(prtd->audio_client, num_channels,
- gain_list, chmap, use_default);
- }
- if (rc < 0)
- pr_err("%s: Send vol gain command failed rc=%d\n",
- __func__, rc);
- return rc;
- }
- static int msm_compr_send_ddp_cfg(struct audio_client *ac,
- struct snd_dec_ddp *ddp,
- int stream_id)
- {
- int i, rc;
- pr_debug("%s\n", __func__);
- for (i = 0; i < ddp->params_length; i++) {
- rc = q6asm_ds1_set_stream_endp_params(ac, ddp->params_id[i],
- ddp->params_value[i],
- stream_id);
- if (rc) {
- pr_err("sending params_id: %d failed\n",
- ddp->params_id[i]);
- return rc;
- }
- }
- return 0;
- }
- static int msm_compr_send_buffer(struct msm_compr_audio *prtd)
- {
- int buffer_length;
- uint64_t bytes_available;
- struct audio_aio_write_param param;
- struct snd_codec_metadata *buff_addr;
- if (!atomic_read(&prtd->start)) {
- pr_err("%s: stream is not in started state\n", __func__);
- return -EINVAL;
- }
- if (atomic_read(&prtd->xrun)) {
- WARN(1, "%s called while xrun is true", __func__);
- return -EPERM;
- }
- pr_debug("%s: bytes_received = %llu copied_total = %llu\n",
- __func__, prtd->bytes_received, prtd->copied_total);
- if (prtd->first_buffer && prtd->gapless_state.use_dsp_gapless_mode &&
- prtd->compr_passthr == LEGACY_PCM)
- q6asm_stream_send_meta_data(prtd->audio_client,
- prtd->audio_client->stream_id,
- prtd->gapless_state.initial_samples_drop,
- prtd->gapless_state.trailing_samples_drop);
- buffer_length = prtd->codec_param.buffer.fragment_size;
- bytes_available = prtd->bytes_received - prtd->copied_total;
- if (bytes_available < prtd->codec_param.buffer.fragment_size)
- buffer_length = bytes_available;
- if (prtd->byte_offset + buffer_length > prtd->buffer_size) {
- buffer_length = (prtd->buffer_size - prtd->byte_offset);
- pr_debug("%s: wrap around situation, send partial data %d now",
- __func__, buffer_length);
- }
- if (buffer_length) {
- param.paddr = prtd->buffer_paddr + prtd->byte_offset;
- WARN(prtd->byte_offset % 32 != 0, "offset %x not multiple of 32\n",
- prtd->byte_offset);
- } else {
- param.paddr = prtd->buffer_paddr;
- }
- param.len = buffer_length;
- if (prtd->ts_header_offset) {
- buff_addr = (struct snd_codec_metadata *)
- (prtd->buffer + prtd->byte_offset);
- param.len = buff_addr->length;
- param.msw_ts = (uint32_t)
- ((buff_addr->timestamp & 0xFFFFFFFF00000000LL) >> 32);
- param.lsw_ts = (uint32_t) (buff_addr->timestamp & 0xFFFFFFFFLL);
- param.paddr += prtd->ts_header_offset;
- param.flags = SET_TIMESTAMP;
- param.metadata_len = prtd->ts_header_offset;
- } else {
- param.msw_ts = 0;
- param.lsw_ts = 0;
- param.flags = NO_TIMESTAMP;
- param.metadata_len = 0;
- }
- param.uid = buffer_length;
- param.last_buffer = prtd->last_buffer;
- pr_debug("%s: sending %d bytes to DSP byte_offset = %d\n",
- __func__, param.len, prtd->byte_offset);
- if (q6asm_async_write(prtd->audio_client, ¶m) < 0) {
- pr_err("%s:q6asm_async_write failed\n", __func__);
- } else {
- prtd->bytes_sent += buffer_length;
- if (prtd->first_buffer)
- prtd->first_buffer = 0;
- }
- return 0;
- }
- static int msm_compr_read_buffer(struct msm_compr_audio *prtd)
- {
- int buffer_length;
- uint64_t bytes_available;
- uint64_t buffer_sent;
- struct audio_aio_read_param param;
- int ret;
- if (!atomic_read(&prtd->start)) {
- pr_err("%s: stream is not in started state\n", __func__);
- return -EINVAL;
- }
- buffer_length = prtd->codec_param.buffer.fragment_size -
- prtd->ts_header_offset;
- bytes_available = prtd->received_total - prtd->bytes_copied;
- buffer_sent = prtd->bytes_read - prtd->bytes_copied;
- if (buffer_sent + buffer_length + prtd->ts_header_offset
- > prtd->buffer_size) {
- pr_debug(" %s : Buffer is Full bytes_available: %llu\n",
- __func__, bytes_available);
- return 0;
- }
- memset(¶m, 0x0, sizeof(struct audio_aio_read_param));
- param.paddr = prtd->buffer_paddr + prtd->bytes_read_offset +
- prtd->ts_header_offset;
- param.len = buffer_length;
- param.uid = buffer_length;
- /* reserved[1] is for flags */
- param.flags = prtd->codec_param.codec.reserved[1];
- pr_debug("%s: reading %d bytes from DSP byte_offset = %llu\n",
- __func__, buffer_length, prtd->bytes_read);
- ret = q6asm_async_read(prtd->audio_client, ¶m);
- if (ret < 0) {
- pr_err("%s: q6asm_async_read failed - %d\n",
- __func__, ret);
- return ret;
- }
- prtd->bytes_read += buffer_length + prtd->ts_header_offset;
- prtd->bytes_read_offset += buffer_length + prtd->ts_header_offset;
- if (prtd->bytes_read_offset >= prtd->buffer_size)
- prtd->bytes_read_offset -= prtd->buffer_size;
- return 0;
- }
- static void compr_event_handler(uint32_t opcode,
- uint32_t token, uint32_t *payload, void *priv)
- {
- struct msm_compr_audio *prtd = priv;
- struct snd_compr_stream *cstream;
- struct audio_client *ac;
- uint32_t chan_mode = 0;
- uint32_t sample_rate = 0;
- uint64_t bytes_available;
- int stream_id;
- uint32_t stream_index;
- unsigned long flags;
- uint64_t read_size;
- uint32_t *buff_addr;
- struct snd_soc_pcm_runtime *rtd;
- int ret = 0;
- if (!prtd) {
- pr_err("%s: prtd is NULL\n", __func__);
- return;
- }
- cstream = prtd->cstream;
- if (!cstream) {
- pr_err("%s: cstream is NULL\n", __func__);
- return;
- }
- ac = prtd->audio_client;
- /*
- * Token for rest of the compressed commands use to set
- * session id, stream id, dir etc.
- */
- stream_id = q6asm_get_stream_id_from_token(token);
- pr_debug("%s opcode =%08x\n", __func__, opcode);
- switch (opcode) {
- case ASM_DATA_EVENT_WRITE_DONE_V2:
- spin_lock_irqsave(&prtd->lock, flags);
- if (payload[3]) {
- pr_err("%s: WRITE FAILED w/ err 0x%x !, paddr 0x%x, byte_offset=%d,copied_total=%llu,token=%d\n",
- __func__,
- payload[3],
- payload[0],
- prtd->byte_offset,
- prtd->copied_total, token);
- if (atomic_cmpxchg(&prtd->drain, 1, 0) &&
- prtd->last_buffer) {
- pr_debug("%s: wake up on drain\n", __func__);
- prtd->drain_ready = 1;
- wake_up(&prtd->drain_wait);
- prtd->last_buffer = 0;
- } else {
- atomic_set(&prtd->start, 0);
- }
- } else {
- pr_debug("ASM_DATA_EVENT_WRITE_DONE_V2 offset %d, length %d\n",
- prtd->byte_offset, token);
- }
- /*
- * Token for WRITE command represents the amount of data
- * written to ADSP in the last write, update offset and
- * total copied data accordingly.
- */
- if (prtd->ts_header_offset) {
- /* Always assume that the data will be sent to DSP on
- * frame boundary.
- * i.e, one frame of userspace write will result in
- * one kernel write to DSP. This is needed as
- * timestamp will be sent per frame.
- */
- prtd->byte_offset +=
- prtd->codec_param.buffer.fragment_size;
- prtd->copied_total +=
- prtd->codec_param.buffer.fragment_size;
- } else {
- prtd->byte_offset += token;
- prtd->copied_total += token;
- }
- if (prtd->byte_offset >= prtd->buffer_size)
- prtd->byte_offset -= prtd->buffer_size;
- snd_compr_fragment_elapsed(cstream);
- if (!atomic_read(&prtd->start)) {
- /* Writes must be restarted from _copy() */
- pr_debug("write_done received while not started, treat as xrun");
- atomic_set(&prtd->xrun, 1);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- bytes_available = prtd->bytes_received - prtd->copied_total;
- if (bytes_available < cstream->runtime->fragment_size) {
- pr_debug("WRITE_DONE Insufficient data to send. break out\n");
- atomic_set(&prtd->xrun, 1);
- if (prtd->last_buffer)
- prtd->last_buffer = 0;
- if (atomic_read(&prtd->drain)) {
- pr_debug("wake up on drain\n");
- prtd->drain_ready = 1;
- wake_up(&prtd->drain_wait);
- atomic_set(&prtd->drain, 0);
- }
- } else if ((bytes_available == cstream->runtime->fragment_size)
- && atomic_read(&prtd->drain)) {
- prtd->last_buffer = 1;
- msm_compr_send_buffer(prtd);
- prtd->last_buffer = 0;
- } else
- msm_compr_send_buffer(prtd);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- case ASM_DATA_EVENT_READ_DONE_V2:
- spin_lock_irqsave(&prtd->lock, flags);
- pr_debug("ASM_DATA_EVENT_READ_DONE_V2 offset %d, length %d\n",
- prtd->byte_offset, payload[4]);
- if (prtd->ts_header_offset) {
- /* Update the header for received buffer */
- buff_addr = prtd->buffer + prtd->byte_offset;
- /* Write the actual length of the received buffer */
- *buff_addr = payload[4];
- buff_addr++;
- /* Write the offset */
- *buff_addr = prtd->ts_header_offset;
- buff_addr++;
- /* Write the TS LSW */
- *buff_addr = payload[CAPTURE_META_DATA_TS_OFFSET_LSW];
- buff_addr++;
- /* Write the TS MSW */
- *buff_addr = payload[CAPTURE_META_DATA_TS_OFFSET_MSW];
- }
- /* Always assume read_size is same as fragment_size */
- read_size = prtd->codec_param.buffer.fragment_size;
- prtd->byte_offset += read_size;
- prtd->received_total += read_size;
- if (prtd->byte_offset >= prtd->buffer_size)
- prtd->byte_offset -= prtd->buffer_size;
- snd_compr_fragment_elapsed(cstream);
- if (!atomic_read(&prtd->start)) {
- pr_debug("read_done received while not started, treat as xrun");
- atomic_set(&prtd->xrun, 1);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- msm_compr_read_buffer(prtd);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- case ASM_DATA_EVENT_RENDERED_EOS:
- spin_lock_irqsave(&prtd->lock, flags);
- pr_debug("%s: ASM_DATA_CMDRSP_EOS token 0x%x,stream id %d\n",
- __func__, token, stream_id);
- if (atomic_read(&prtd->eos) &&
- !prtd->gapless_state.set_next_stream_id) {
- pr_debug("ASM_DATA_CMDRSP_EOS wake up\n");
- prtd->eos_ack = 1;
- wake_up(&prtd->eos_wait);
- }
- atomic_set(&prtd->eos, 0);
- stream_index = STREAM_ARRAY_INDEX(stream_id);
- if (stream_index >= MAX_NUMBER_OF_STREAMS ||
- stream_index < 0) {
- pr_err("%s: Invalid stream index %d", __func__,
- stream_index);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- if (prtd->gapless_state.set_next_stream_id &&
- prtd->gapless_state.stream_opened[stream_index]) {
- pr_debug("%s: CMD_CLOSE stream_id %d\n",
- __func__, stream_id);
- q6asm_stream_cmd_nowait(ac, CMD_CLOSE, stream_id);
- atomic_set(&prtd->close, 1);
- prtd->gapless_state.stream_opened[stream_index] = 0;
- prtd->gapless_state.set_next_stream_id = false;
- }
- if (prtd->gapless_state.gapless_transition)
- prtd->gapless_state.gapless_transition = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- case ASM_STREAM_PP_EVENT:
- case ASM_STREAM_CMD_ENCDEC_EVENTS:
- pr_debug("%s: ASM_STREAM_EVENT(0x%x)\n", __func__, opcode);
- rtd = cstream->private_data;
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- return;
- }
- ret = msm_adsp_inform_mixer_ctl(rtd, payload);
- if (ret) {
- pr_err("%s: failed to inform mixer ctrl. err = %d\n",
- __func__, ret);
- return;
- }
- break;
- case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
- case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY: {
- pr_debug("ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY\n");
- chan_mode = payload[1] >> 16;
- sample_rate = payload[2] >> 16;
- if (prtd && (chan_mode != prtd->num_channels ||
- sample_rate != prtd->sample_rate)) {
- prtd->num_channels = chan_mode;
- prtd->sample_rate = sample_rate;
- }
- }
- /* Fallthrough here */
- case APR_BASIC_RSP_RESULT: {
- switch (payload[0]) {
- case ASM_SESSION_CMD_RUN_V2:
- /* check if the first buffer need to be sent to DSP */
- pr_debug("ASM_SESSION_CMD_RUN_V2\n");
- /* FIXME: A state is a better way, dealing with this */
- spin_lock_irqsave(&prtd->lock, flags);
- if (cstream->direction == SND_COMPRESS_CAPTURE) {
- atomic_set(&prtd->start, 1);
- msm_compr_read_buffer(prtd);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- if (!prtd->bytes_sent) {
- bytes_available = prtd->bytes_received -
- prtd->copied_total;
- if (bytes_available <
- cstream->runtime->fragment_size) {
- pr_debug("CMD_RUN_V2 Insufficient data to send. break out\n");
- atomic_set(&prtd->xrun, 1);
- } else {
- msm_compr_send_buffer(prtd);
- }
- }
- /*
- * The condition below ensures playback finishes in the
- * follow cornercase
- * WRITE(last buffer)
- * WAIT_FOR_DRAIN
- * PAUSE
- * WRITE_DONE(X)
- * RESUME
- */
- if ((prtd->copied_total == prtd->bytes_sent) &&
- atomic_read(&prtd->drain)) {
- bytes_available = prtd->bytes_received - prtd->copied_total;
- if (bytes_available < cstream->runtime->fragment_size) {
- pr_debug("%s: RUN ack, wake up & continue pending drain\n",
- __func__);
- if (prtd->last_buffer)
- prtd->last_buffer = 0;
- prtd->drain_ready = 1;
- wake_up(&prtd->drain_wait);
- atomic_set(&prtd->drain, 0);
- } else if (atomic_read(&prtd->xrun)) {
- pr_debug("%s: RUN ack, continue write cycle\n", __func__);
- atomic_set(&prtd->xrun, 0);
- msm_compr_send_buffer(prtd);
- }
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- case ASM_STREAM_CMD_FLUSH:
- pr_debug("%s: ASM_STREAM_CMD_FLUSH:", __func__);
- pr_debug("token 0x%x, stream id %d\n", token,
- stream_id);
- prtd->cmd_ack = 1;
- break;
- case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
- pr_debug("%s: ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:",
- __func__);
- pr_debug("token 0x%x, stream id = %d\n", token,
- stream_id);
- break;
- case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
- pr_debug("%s: ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:",
- __func__);
- pr_debug("token = 0x%x, stream id = %d\n", token,
- stream_id);
- break;
- case ASM_STREAM_CMD_CLOSE:
- pr_debug("%s: ASM_DATA_CMD_CLOSE:", __func__);
- pr_debug("token 0x%x, stream id %d\n", token,
- stream_id);
- /*
- * wakeup wait for stream avail on stream 3
- * after stream 1 ends.
- */
- if (prtd->next_stream) {
- pr_debug("%s:CLOSE:wakeup wait for stream\n",
- __func__);
- prtd->stream_available = 1;
- wake_up(&prtd->wait_for_stream_avail);
- prtd->next_stream = 0;
- }
- if (atomic_read(&prtd->close) &&
- atomic_read(&prtd->wait_on_close)) {
- prtd->cmd_ack = 1;
- wake_up(&prtd->close_wait);
- }
- atomic_set(&prtd->close, 0);
- break;
- case ASM_STREAM_CMD_REGISTER_PP_EVENTS:
- pr_debug("%s: ASM_STREAM_CMD_REGISTER_PP_EVENTS:",
- __func__);
- break;
- default:
- break;
- }
- break;
- }
- case ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3:
- pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3\n",
- __func__);
- break;
- case RESET_EVENTS:
- pr_err("%s: Received reset events CB, move to error state",
- __func__);
- spin_lock_irqsave(&prtd->lock, flags);
- /*
- * Since ADSP is down, let this driver pretend that it copied
- * all the bytes received, so that next write will be triggered
- */
- prtd->copied_total = prtd->bytes_received;
- snd_compr_fragment_elapsed(cstream);
- atomic_set(&prtd->error, 1);
- wake_up(&prtd->drain_wait);
- if (atomic_cmpxchg(&prtd->eos, 1, 0)) {
- pr_debug("%s:unblock eos wait queues", __func__);
- wake_up(&prtd->eos_wait);
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- default:
- pr_debug("%s: Not Supported Event opcode[0x%x]\n",
- __func__, opcode);
- break;
- }
- }
- static int msm_compr_get_partial_drain_delay(int frame_sz, int sample_rate)
- {
- int delay_time_ms = 0;
- delay_time_ms = ((DSP_NUM_OUTPUT_FRAME_BUFFERED * frame_sz * 1000) /
- sample_rate) + DSP_PP_BUFFERING_IN_MSEC;
- delay_time_ms = delay_time_ms > PARTIAL_DRAIN_ACK_EARLY_BY_MSEC ?
- delay_time_ms - PARTIAL_DRAIN_ACK_EARLY_BY_MSEC : 0;
- pr_debug("%s: frame_sz %d, sample_rate %d, partial drain delay %d\n",
- __func__, frame_sz, sample_rate, delay_time_ms);
- return delay_time_ms;
- }
- static void populate_codec_list(struct msm_compr_audio *prtd)
- {
- pr_debug("%s\n", __func__);
- prtd->compr_cap.direction = SND_COMPRESS_PLAYBACK;
- prtd->compr_cap.min_fragment_size =
- COMPR_PLAYBACK_MIN_FRAGMENT_SIZE;
- prtd->compr_cap.max_fragment_size =
- COMPR_PLAYBACK_MAX_FRAGMENT_SIZE;
- prtd->compr_cap.min_fragments =
- COMPR_PLAYBACK_MIN_NUM_FRAGMENTS;
- prtd->compr_cap.max_fragments =
- COMPR_PLAYBACK_MAX_NUM_FRAGMENTS;
- prtd->compr_cap.num_codecs = 17;
- prtd->compr_cap.codecs[0] = SND_AUDIOCODEC_MP3;
- prtd->compr_cap.codecs[1] = SND_AUDIOCODEC_AAC;
- prtd->compr_cap.codecs[2] = SND_AUDIOCODEC_AC3;
- prtd->compr_cap.codecs[3] = SND_AUDIOCODEC_EAC3;
- prtd->compr_cap.codecs[4] = SND_AUDIOCODEC_MP2;
- prtd->compr_cap.codecs[5] = SND_AUDIOCODEC_PCM;
- prtd->compr_cap.codecs[6] = SND_AUDIOCODEC_WMA;
- prtd->compr_cap.codecs[7] = SND_AUDIOCODEC_WMA_PRO;
- prtd->compr_cap.codecs[8] = SND_AUDIOCODEC_FLAC;
- prtd->compr_cap.codecs[9] = SND_AUDIOCODEC_VORBIS;
- prtd->compr_cap.codecs[10] = SND_AUDIOCODEC_ALAC;
- prtd->compr_cap.codecs[11] = SND_AUDIOCODEC_APE;
- prtd->compr_cap.codecs[12] = SND_AUDIOCODEC_DTS;
- prtd->compr_cap.codecs[13] = SND_AUDIOCODEC_DSD;
- prtd->compr_cap.codecs[14] = SND_AUDIOCODEC_APTX;
- prtd->compr_cap.codecs[15] = SND_AUDIOCODEC_TRUEHD;
- prtd->compr_cap.codecs[16] = SND_AUDIOCODEC_IEC61937;
- }
- static int msm_compr_send_media_format_block(struct snd_compr_stream *cstream,
- int stream_id,
- bool use_gapless_codec_options)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component =NULL;
- struct msm_compr_pdata *pdata = NULL;
- struct asm_aac_cfg aac_cfg;
- struct asm_wma_cfg wma_cfg;
- struct asm_wmapro_cfg wma_pro_cfg;
- struct asm_flac_cfg flac_cfg;
- struct asm_vorbis_cfg vorbis_cfg;
- struct asm_alac_cfg alac_cfg;
- struct asm_ape_cfg ape_cfg;
- struct asm_dsd_cfg dsd_cfg;
- struct aptx_dec_bt_addr_cfg aptx_cfg;
- struct asm_amrwbplus_cfg amrwbplus_cfg;
- union snd_codec_options *codec_options;
- int ret = 0;
- uint16_t bit_width;
- bool use_default_chmap = true;
- char *chmap = NULL;
- uint16_t sample_word_size;
- pr_debug("%s: use_gapless_codec_options %d\n",
- __func__, use_gapless_codec_options);
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (use_gapless_codec_options)
- codec_options = &(prtd->gapless_state.codec_options);
- else
- codec_options = &(prtd->codec_param.codec.options);
- if (!codec_options) {
- pr_err("%s: codec_options is NULL\n", __func__);
- return -EINVAL;
- }
- switch (prtd->codec) {
- case FORMAT_LINEAR_PCM:
- pr_debug("SND_AUDIOCODEC_PCM\n");
- if (pdata->ch_map[rtd->dai_link->id]) {
- use_default_chmap =
- !(pdata->ch_map[rtd->dai_link->id]->set_ch_map);
- chmap =
- pdata->ch_map[rtd->dai_link->id]->channel_map;
- }
- switch (prtd->codec_param.codec.format) {
- case SNDRV_PCM_FORMAT_S32_LE:
- bit_width = 32;
- sample_word_size = 32;
- break;
- case SNDRV_PCM_FORMAT_S24_LE:
- bit_width = 24;
- sample_word_size = 32;
- break;
- case SNDRV_PCM_FORMAT_S24_3LE:
- bit_width = 24;
- sample_word_size = 24;
- break;
- case SNDRV_PCM_FORMAT_S16_LE:
- default:
- bit_width = 16;
- sample_word_size = 16;
- break;
- }
- if (q6core_get_avcs_api_version_per_service(
- APRV2_IDS_SERVICE_ID_ADSP_ASM_V) >=
- ADSP_ASM_API_VERSION_V2) {
- ret = q6asm_media_format_block_pcm_format_support_v5(
- prtd->audio_client,
- prtd->sample_rate,
- prtd->num_channels,
- bit_width, stream_id,
- use_default_chmap,
- chmap,
- sample_word_size,
- ASM_LITTLE_ENDIAN,
- DEFAULT_QF);
- } else {
- ret = q6asm_media_format_block_pcm_format_support_v4(
- prtd->audio_client,
- prtd->sample_rate,
- prtd->num_channels,
- bit_width, stream_id,
- use_default_chmap,
- chmap,
- sample_word_size,
- ASM_LITTLE_ENDIAN,
- DEFAULT_QF);
- }
- if (ret < 0)
- pr_err("%s: CMD Format block failed\n", __func__);
- break;
- case FORMAT_MP3:
- pr_debug("SND_AUDIOCODEC_MP3\n");
- /* no media format block needed */
- break;
- case FORMAT_MPEG4_AAC:
- pr_debug("SND_AUDIOCODEC_AAC\n");
- memset(&aac_cfg, 0x0, sizeof(struct asm_aac_cfg));
- aac_cfg.aot = AAC_ENC_MODE_EAAC_P;
- if (prtd->codec_param.codec.format ==
- SND_AUDIOSTREAMFORMAT_MP4ADTS)
- aac_cfg.format = 0x0;
- else if (prtd->codec_param.codec.format ==
- SND_AUDIOSTREAMFORMAT_MP4LATM)
- aac_cfg.format = 0x04;
- else
- aac_cfg.format = 0x03;
- aac_cfg.ch_cfg = prtd->num_channels;
- aac_cfg.sample_rate = prtd->sample_rate;
- ret = q6asm_stream_media_format_block_aac(prtd->audio_client,
- &aac_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed\n", __func__);
- break;
- case FORMAT_AC3:
- pr_debug("SND_AUDIOCODEC_AC3\n");
- break;
- case FORMAT_EAC3:
- pr_debug("SND_AUDIOCODEC_EAC3\n");
- break;
- case FORMAT_WMA_V9:
- pr_debug("SND_AUDIOCODEC_WMA\n");
- memset(&wma_cfg, 0x0, sizeof(struct asm_wma_cfg));
- wma_cfg.format_tag = prtd->codec_param.codec.format;
- wma_cfg.ch_cfg = prtd->codec_param.codec.ch_in;
- wma_cfg.sample_rate = prtd->sample_rate;
- wma_cfg.avg_bytes_per_sec = codec_options->wma_dec.avg_bit_rate/8;
- wma_cfg.block_align = codec_options->wma_dec.super_block_align;
- wma_cfg.valid_bits_per_sample =
- codec_options->wma_dec.bits_per_sample;
- wma_cfg.ch_mask = codec_options->wma_dec.channelmask;
- wma_cfg.encode_opt = codec_options->wma_dec.encodeopt;
- ret = q6asm_media_format_block_wma(prtd->audio_client,
- &wma_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed\n", __func__);
- break;
- case FORMAT_WMA_V10PRO:
- pr_debug("SND_AUDIOCODEC_WMA_PRO\n");
- memset(&wma_pro_cfg, 0x0, sizeof(struct asm_wmapro_cfg));
- wma_pro_cfg.format_tag = prtd->codec_param.codec.format;
- wma_pro_cfg.ch_cfg = prtd->codec_param.codec.ch_in;
- wma_pro_cfg.sample_rate = prtd->sample_rate;
- wma_cfg.avg_bytes_per_sec = codec_options->wma_dec.avg_bit_rate/8;
- wma_pro_cfg.block_align = codec_options->wma_dec.super_block_align;
- wma_pro_cfg.valid_bits_per_sample =
- codec_options->wma_dec.bits_per_sample;
- wma_pro_cfg.ch_mask = codec_options->wma_dec.channelmask;
- wma_pro_cfg.encode_opt = codec_options->wma_dec.encodeopt;
- wma_pro_cfg.adv_encode_opt = codec_options->wma_dec.encodeopt1;
- wma_pro_cfg.adv_encode_opt2 = codec_options->wma_dec.encodeopt2;
- ret = q6asm_media_format_block_wmapro(prtd->audio_client,
- &wma_pro_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed\n", __func__);
- break;
- case FORMAT_MP2:
- pr_debug("%s: SND_AUDIOCODEC_MP2\n", __func__);
- break;
- case FORMAT_FLAC:
- pr_debug("%s: SND_AUDIOCODEC_FLAC\n", __func__);
- memset(&flac_cfg, 0x0, sizeof(struct asm_flac_cfg));
- flac_cfg.ch_cfg = prtd->num_channels;
- flac_cfg.sample_rate = prtd->sample_rate;
- flac_cfg.stream_info_present = 1;
- flac_cfg.sample_size = codec_options->flac_dec.sample_size;
- flac_cfg.min_blk_size = codec_options->flac_dec.min_blk_size;
- flac_cfg.max_blk_size = codec_options->flac_dec.max_blk_size;
- flac_cfg.max_frame_size =
- codec_options->flac_dec.max_frame_size;
- flac_cfg.min_frame_size =
- codec_options->flac_dec.min_frame_size;
- ret = q6asm_stream_media_format_block_flac(prtd->audio_client,
- &flac_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_VORBIS:
- pr_debug("%s: SND_AUDIOCODEC_VORBIS\n", __func__);
- memset(&vorbis_cfg, 0x0, sizeof(struct asm_vorbis_cfg));
- vorbis_cfg.bit_stream_fmt =
- codec_options->vorbis_dec.bit_stream_fmt;
- ret = q6asm_stream_media_format_block_vorbis(
- prtd->audio_client, &vorbis_cfg,
- stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_ALAC:
- pr_debug("%s: SND_AUDIOCODEC_ALAC\n", __func__);
- memset(&alac_cfg, 0x0, sizeof(struct asm_alac_cfg));
- alac_cfg.num_channels = prtd->num_channels;
- alac_cfg.sample_rate = prtd->sample_rate;
- alac_cfg.frame_length = codec_options->alac.frame_length;
- alac_cfg.compatible_version =
- codec_options->alac.compatible_version;
- alac_cfg.bit_depth = codec_options->alac.bit_depth;
- alac_cfg.pb = codec_options->alac.pb;
- alac_cfg.mb = codec_options->alac.mb;
- alac_cfg.kb = codec_options->alac.kb;
- alac_cfg.max_run = codec_options->alac.max_run;
- alac_cfg.max_frame_bytes = codec_options->alac.max_frame_bytes;
- alac_cfg.avg_bit_rate = codec_options->alac.avg_bit_rate;
- alac_cfg.channel_layout_tag =
- codec_options->alac.channel_layout_tag;
- ret = q6asm_media_format_block_alac(prtd->audio_client,
- &alac_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_APE:
- pr_debug("%s: SND_AUDIOCODEC_APE\n", __func__);
- memset(&ape_cfg, 0x0, sizeof(struct asm_ape_cfg));
- ape_cfg.num_channels = prtd->num_channels;
- ape_cfg.sample_rate = prtd->sample_rate;
- ape_cfg.compatible_version =
- codec_options->ape.compatible_version;
- ape_cfg.compression_level =
- codec_options->ape.compression_level;
- ape_cfg.format_flags = codec_options->ape.format_flags;
- ape_cfg.blocks_per_frame = codec_options->ape.blocks_per_frame;
- ape_cfg.final_frame_blocks =
- codec_options->ape.final_frame_blocks;
- ape_cfg.total_frames = codec_options->ape.total_frames;
- ape_cfg.bits_per_sample = codec_options->ape.bits_per_sample;
- ape_cfg.seek_table_present =
- codec_options->ape.seek_table_present;
- ret = q6asm_media_format_block_ape(prtd->audio_client,
- &ape_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_DTS:
- pr_debug("SND_AUDIOCODEC_DTS\n");
- /* no media format block needed */
- break;
- case FORMAT_DSD:
- pr_debug("%s: SND_AUDIOCODEC_DSD\n", __func__);
- memset(&dsd_cfg, 0x0, sizeof(struct asm_dsd_cfg));
- dsd_cfg.num_channels = prtd->num_channels;
- dsd_cfg.dsd_data_rate = prtd->sample_rate;
- dsd_cfg.num_version = 0;
- dsd_cfg.is_bitwise_big_endian = 1;
- dsd_cfg.dsd_channel_block_size = 1;
- ret = q6asm_media_format_block_dsd(prtd->audio_client,
- &dsd_cfg, stream_id);
- if (ret < 0)
- pr_err("%s: CMD DSD Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_TRUEHD:
- pr_debug("SND_AUDIOCODEC_TRUEHD\n");
- /* no media format block needed */
- break;
- case FORMAT_IEC61937:
- pr_debug("SND_AUDIOCODEC_IEC61937\n");
- ret = q6asm_media_format_block_iec(prtd->audio_client,
- prtd->sample_rate,
- prtd->num_channels);
- if (ret < 0)
- pr_err("%s: CMD IEC61937 Format block failed ret %d\n",
- __func__, ret);
- break;
- case FORMAT_APTX:
- pr_debug("SND_AUDIOCODEC_APTX\n");
- memset(&aptx_cfg, 0x0, sizeof(struct aptx_dec_bt_addr_cfg));
- ret = q6asm_stream_media_format_block_aptx_dec(
- prtd->audio_client,
- prtd->sample_rate,
- stream_id);
- if (ret >= 0) {
- aptx_cfg.nap = codec_options->aptx_dec.nap;
- aptx_cfg.uap = codec_options->aptx_dec.uap;
- aptx_cfg.lap = codec_options->aptx_dec.lap;
- q6asm_set_aptx_dec_bt_addr(prtd->audio_client,
- &aptx_cfg);
- } else {
- pr_err("%s: CMD Format block failed ret %d\n",
- __func__, ret);
- }
- break;
- case FORMAT_AMRNB:
- pr_debug("SND_AUDIOCODEC_AMR\n");
- /* no media format block needed */
- break;
- case FORMAT_AMRWB:
- pr_debug("SND_AUDIOCODEC_AMRWB\n");
- /* no media format block needed */
- break;
- case FORMAT_AMR_WB_PLUS:
- pr_debug("SND_AUDIOCODEC_AMRWBPLUS\n");
- memset(&amrwbplus_cfg, 0x0, sizeof(struct asm_amrwbplus_cfg));
- amrwbplus_cfg.amr_frame_fmt =
- codec_options->amrwbplus.bit_stream_fmt;
- ret = q6asm_media_format_block_amrwbplus(
- prtd->audio_client,
- &amrwbplus_cfg);
- if (ret < 0)
- pr_err("%s: CMD AMRWBPLUS Format block failed ret %d\n",
- __func__, ret);
- break;
- default:
- pr_debug("%s, unsupported format, skip", __func__);
- break;
- }
- return ret;
- }
- static int msm_compr_init_pp_params(struct snd_compr_stream *cstream,
- struct audio_client *ac)
- {
- int ret = 0;
- struct asm_softvolume_params softvol = {
- .period = SOFT_VOLUME_PERIOD,
- .step = SOFT_VOLUME_STEP,
- .rampingcurve = SOFT_VOLUME_CURVE_LINEAR,
- };
- switch (ac->topology) {
- default:
- ret = q6asm_set_softvolume_v2(ac, &softvol,
- SOFT_VOLUME_INSTANCE_1);
- if (ret < 0)
- pr_err("%s: Send SoftVolume Param failed ret=%d\n",
- __func__, ret);
- break;
- }
- return ret;
- }
- static int msm_compr_configure_dsp_for_playback
- (struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- struct snd_soc_pcm_runtime *soc_prtd = cstream->private_data;
- uint16_t bits_per_sample = 16;
- int dir = IN, ret = 0;
- struct audio_client *ac = prtd->audio_client;
- uint32_t stream_index;
- struct asm_softpause_params softpause = {
- .enable = SOFT_PAUSE_ENABLE,
- .period = SOFT_PAUSE_PERIOD,
- .step = SOFT_PAUSE_STEP,
- .rampingcurve = SOFT_PAUSE_CURVE_LINEAR,
- };
- struct asm_softvolume_params softvol = {
- .period = SOFT_VOLUME_PERIOD,
- .step = SOFT_VOLUME_STEP,
- .rampingcurve = SOFT_VOLUME_CURVE_LINEAR,
- };
- struct snd_kcontrol *kctl;
- struct snd_ctl_elem_value kctl_elem_value;
- uint16_t target_asm_bit_width = 0;
- pr_debug("%s: stream_id %d\n", __func__, ac->stream_id);
- stream_index = STREAM_ARRAY_INDEX(ac->stream_id);
- if (stream_index >= MAX_NUMBER_OF_STREAMS || stream_index < 0) {
- pr_err("%s: Invalid stream index:%d", __func__, stream_index);
- return -EINVAL;
- }
- kctl = snd_soc_card_get_kcontrol(soc_prtd->card,
- DSP_BIT_WIDTH_MIXER_CTL);
- if (kctl) {
- kctl->get(kctl, &kctl_elem_value);
- target_asm_bit_width = kctl_elem_value.value.integer.value[0];
- if (target_asm_bit_width > 0) {
- pr_debug("%s enforce ASM bitwidth to %d from %d\n",
- __func__,
- target_asm_bit_width,
- bits_per_sample);
- bits_per_sample = target_asm_bit_width;
- }
- } else {
- pr_info("%s: failed to get mixer ctl for %s.\n",
- __func__, DSP_BIT_WIDTH_MIXER_CTL);
- }
- if ((prtd->codec_param.codec.format == SNDRV_PCM_FORMAT_S24_LE) ||
- (prtd->codec_param.codec.format == SNDRV_PCM_FORMAT_S24_3LE))
- bits_per_sample = 24;
- else if (prtd->codec_param.codec.format == SNDRV_PCM_FORMAT_S32_LE)
- bits_per_sample = 32;
- if (prtd->compr_passthr != LEGACY_PCM) {
- ret = q6asm_open_write_compressed(ac, prtd->codec,
- prtd->compr_passthr);
- if (ret < 0) {
- pr_err("%s:ASM open write err[%d] for compr_type[%d]\n",
- __func__, ret, prtd->compr_passthr);
- return ret;
- }
- prtd->gapless_state.stream_opened[stream_index] = 1;
- ret = msm_pcm_routing_reg_phy_compr_stream(
- soc_prtd->dai_link->id,
- ac->perf_mode,
- prtd->session_id,
- SNDRV_PCM_STREAM_PLAYBACK,
- prtd->compr_passthr);
- if (ret) {
- pr_err("%s: compr stream reg failed:%d\n", __func__,
- ret);
- return ret;
- }
- } else {
- pr_debug("%s: stream_id %d bits_per_sample %d\n",
- __func__, ac->stream_id, bits_per_sample);
- if (q6core_get_avcs_api_version_per_service(
- APRV2_IDS_SERVICE_ID_ADSP_ASM_V) >=
- ADSP_ASM_API_VERSION_V2)
- ret = q6asm_stream_open_write_v5(ac,
- prtd->codec, bits_per_sample,
- ac->stream_id,
- prtd->gapless_state.use_dsp_gapless_mode);
- else
- ret = q6asm_stream_open_write_v4(ac,
- prtd->codec, bits_per_sample,
- ac->stream_id,
- prtd->gapless_state.use_dsp_gapless_mode);
- if (ret < 0) {
- pr_err("%s:ASM open write err[%d] for compr type[%d]\n",
- __func__, ret, prtd->compr_passthr);
- return -ENOMEM;
- }
- prtd->gapless_state.stream_opened[stream_index] = 1;
- pr_debug("%s: BE id %d\n", __func__, soc_prtd->dai_link->id);
- ret = msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->id,
- ac->perf_mode,
- prtd->session_id,
- SNDRV_PCM_STREAM_PLAYBACK);
- if (ret) {
- pr_err("%s: stream reg failed:%d\n", __func__, ret);
- return ret;
- }
- }
- ret = msm_compr_set_volume(cstream, 0, 0);
- if (ret < 0)
- pr_err("%s : Set Volume failed : %d", __func__, ret);
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s : Don't send cal and PP params for compress path",
- __func__);
- } else {
- ret = q6asm_send_cal(ac);
- if (ret < 0)
- pr_debug("%s : Send cal failed : %d", __func__, ret);
- ret = q6asm_set_softpause(ac, &softpause);
- if (ret < 0)
- pr_err("%s: Send SoftPause Param failed ret=%d\n",
- __func__, ret);
- ret = q6asm_set_softvolume(ac, &softvol);
- if (ret < 0)
- pr_err("%s: Send SoftVolume Param failed ret=%d\n",
- __func__, ret);
- }
- ret = q6asm_set_io_mode(ac, (COMPRESSED_STREAM_IO | ASYNC_IO_MODE));
- if (ret < 0) {
- pr_err("%s: Set IO mode failed\n", __func__);
- return -EINVAL;
- }
- runtime->fragments = prtd->codec_param.buffer.fragments;
- runtime->fragment_size = prtd->codec_param.buffer.fragment_size;
- pr_debug("allocate %d buffers each of size %d\n",
- runtime->fragments,
- runtime->fragment_size);
- ret = q6asm_audio_client_buf_alloc_contiguous(dir, ac,
- runtime->fragment_size,
- runtime->fragments);
- if (ret < 0) {
- pr_err("Audio Start: Buffer Allocation failed rc = %d\n", ret);
- return -ENOMEM;
- }
- prtd->byte_offset = 0;
- prtd->copied_total = 0;
- prtd->app_pointer = 0;
- prtd->bytes_received = 0;
- prtd->bytes_sent = 0;
- prtd->buffer = ac->port[dir].buf[0].data;
- prtd->buffer_paddr = ac->port[dir].buf[0].phys;
- prtd->buffer_size = runtime->fragments * runtime->fragment_size;
- /* Bit-0 of flags represent timestamp mode */
- /* reserved[1] is for flags */
- if (prtd->codec_param.codec.reserved[1] & COMPRESSED_TIMESTAMP_FLAG)
- prtd->ts_header_offset = sizeof(struct snd_codec_metadata);
- else
- prtd->ts_header_offset = 0;
- ret = msm_compr_send_media_format_block(cstream, ac->stream_id, false);
- if (ret < 0)
- pr_err("%s, failed to send media format block\n", __func__);
- return ret;
- }
- static int msm_compr_configure_dsp_for_capture(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- struct snd_soc_pcm_runtime *soc_prtd = cstream->private_data;
- uint16_t bits_per_sample;
- uint16_t sample_word_size;
- int dir = OUT, ret = 0;
- struct audio_client *ac = prtd->audio_client;
- uint32_t stream_index;
- uint32_t enc_cfg_id = ENC_CFG_ID_NONE;
- bool compress_ts = false;
- switch (prtd->codec_param.codec.format) {
- case SNDRV_PCM_FORMAT_S24_LE:
- bits_per_sample = 24;
- sample_word_size = 32;
- break;
- case SNDRV_PCM_FORMAT_S24_3LE:
- bits_per_sample = 24;
- sample_word_size = 24;
- break;
- case SNDRV_PCM_FORMAT_S32_LE:
- bits_per_sample = 32;
- sample_word_size = 32;
- break;
- case SNDRV_PCM_FORMAT_S16_LE:
- default:
- bits_per_sample = 16;
- sample_word_size = 16;
- if (prtd->codec == FORMAT_BESPOKE)
- enc_cfg_id =
- prtd->codec_param.codec.options.generic.reserved[0];
- break;
- }
- pr_debug("%s: stream_id %d bits_per_sample %d compr_passthr %d\n",
- __func__, ac->stream_id, bits_per_sample,
- prtd->compr_passthr);
- if (prtd->compr_passthr != LEGACY_PCM) {
- ret = q6asm_open_read_compressed(prtd->audio_client,
- prtd->codec, prtd->compr_passthr);
- if (ret < 0) {
- pr_err("%s:ASM open read err[%d] for compr_type[%d]\n",
- __func__, ret, prtd->compr_passthr);
- return ret;
- }
- ret = msm_pcm_routing_reg_phy_compr_stream(
- soc_prtd->dai_link->id,
- ac->perf_mode,
- prtd->session_id,
- SNDRV_PCM_STREAM_CAPTURE,
- prtd->compr_passthr);
- if (ret) {
- pr_err("%s: compr stream reg failed:%d\n",
- __func__, ret);
- return ret;
- }
- } else {
- /* reserved[1] is for flags */
- if (prtd->codec_param.codec.reserved[1]
- & COMPRESSED_TIMESTAMP_FLAG)
- compress_ts = true;
- if (q6core_get_avcs_api_version_per_service(
- APRV2_IDS_SERVICE_ID_ADSP_ASM_V) >=
- ADSP_ASM_API_VERSION_V2)
- ret = q6asm_open_read_v5(prtd->audio_client,
- prtd->codec, bits_per_sample,
- compress_ts, enc_cfg_id);
- else
- ret = q6asm_open_read_v4(prtd->audio_client,
- prtd->codec, bits_per_sample,
- compress_ts, enc_cfg_id);
- if (ret < 0) {
- pr_err("%s: q6asm_open_read failed:%d\n",
- __func__, ret);
- return ret;
- }
- ret = msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->id,
- ac->perf_mode,
- prtd->session_id,
- SNDRV_PCM_STREAM_CAPTURE);
- if (ret) {
- pr_err("%s: stream reg failed:%d\n", __func__, ret);
- return ret;
- }
- }
- ret = q6asm_set_io_mode(ac, (COMPRESSED_STREAM_IO | ASYNC_IO_MODE));
- if (ret < 0) {
- pr_err("%s: Set IO mode failed\n", __func__);
- return -EINVAL;
- }
- stream_index = STREAM_ARRAY_INDEX(ac->stream_id);
- if (stream_index >= MAX_NUMBER_OF_STREAMS || stream_index < 0) {
- pr_err("%s: Invalid stream index:%d", __func__, stream_index);
- return -EINVAL;
- }
- runtime->fragments = prtd->codec_param.buffer.fragments;
- runtime->fragment_size = prtd->codec_param.buffer.fragment_size;
- pr_debug("%s: allocate %d buffers each of size %d\n",
- __func__, runtime->fragments,
- runtime->fragment_size);
- ret = q6asm_audio_client_buf_alloc_contiguous(dir, ac,
- runtime->fragment_size,
- runtime->fragments);
- if (ret < 0) {
- pr_err("Audio Start: Buffer Allocation failed rc = %d\n", ret);
- return -ENOMEM;
- }
- prtd->byte_offset = 0;
- prtd->received_total = 0;
- prtd->app_pointer = 0;
- prtd->bytes_copied = 0;
- prtd->bytes_read = 0;
- prtd->bytes_read_offset = 0;
- prtd->buffer = ac->port[dir].buf[0].data;
- prtd->buffer_paddr = ac->port[dir].buf[0].phys;
- prtd->buffer_size = runtime->fragments * runtime->fragment_size;
- /* Bit-0 of flags represent timestamp mode */
- /* reserved[1] is for flags */
- if (prtd->codec_param.codec.reserved[1] & COMPRESSED_TIMESTAMP_FLAG)
- prtd->ts_header_offset = sizeof(struct snd_codec_metadata);
- else
- prtd->ts_header_offset = 0;
- pr_debug("%s: sample_rate = %d channels = %d bps = %d sample_word_size = %d\n",
- __func__, prtd->sample_rate, prtd->num_channels,
- bits_per_sample, sample_word_size);
- if (prtd->codec == FORMAT_BESPOKE) {
- /*
- * For BESPOKE codec, encoder specific config params are
- * included as part of generic.
- */
- ret = q6asm_enc_cfg_blk_custom(prtd->audio_client, prtd->sample_rate,
- prtd->num_channels, prtd->codec,
- (void *)&prtd->codec_param.codec.options.generic);
- } else if (prtd->compr_passthr == LEGACY_PCM) {
- if (q6core_get_avcs_api_version_per_service(
- APRV2_IDS_SERVICE_ID_ADSP_ASM_V) >=
- ADSP_ASM_API_VERSION_V2)
- ret = q6asm_enc_cfg_blk_pcm_format_support_v5(
- prtd->audio_client,
- prtd->sample_rate, prtd->num_channels,
- bits_per_sample, sample_word_size,
- ASM_LITTLE_ENDIAN, DEFAULT_QF);
- else
- ret = q6asm_enc_cfg_blk_pcm_format_support_v4(
- prtd->audio_client,
- prtd->sample_rate, prtd->num_channels,
- bits_per_sample, sample_word_size,
- ASM_LITTLE_ENDIAN, DEFAULT_QF);
- }
- return ret;
- }
- static int msm_compr_playback_open(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component = NULL;
- struct msm_compr_audio *prtd = NULL;
- struct msm_compr_pdata *pdata = NULL;
- enum apr_subsys_state subsys_state;
- pr_debug("%s\n", __func__);
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (pdata->is_in_use[rtd->dai_link->id] == true) {
- pr_err("%s: %s is already in use, err: %d\n",
- __func__, rtd->dai_link->cpus->dai_name, -EBUSY);
- return -EBUSY;
- }
- subsys_state = apr_get_subsys_state();
- if (subsys_state == APR_SUBSYS_DOWN) {
- pr_debug("%s: adsp is down\n", __func__);
- return -ENETRESET;
- }
- prtd = kzalloc(sizeof(struct msm_compr_audio), GFP_KERNEL);
- if (prtd == NULL) {
- pr_err("Failed to allocate memory for msm_compr_audio\n");
- return -ENOMEM;
- }
- runtime->private_data = NULL;
- prtd->cstream = cstream;
- pdata->cstream[rtd->dai_link->id] = cstream;
- pdata->audio_effects[rtd->dai_link->id] =
- kzalloc(sizeof(struct msm_compr_audio_effects), GFP_KERNEL);
- if (pdata->audio_effects[rtd->dai_link->id] == NULL) {
- pr_err("%s: Could not allocate memory for effects\n", __func__);
- pdata->cstream[rtd->dai_link->id] = NULL;
- kfree(prtd);
- return -ENOMEM;
- }
- pdata->dec_params[rtd->dai_link->id] =
- kzalloc(sizeof(struct msm_compr_dec_params), GFP_KERNEL);
- if (pdata->dec_params[rtd->dai_link->id] == NULL) {
- pr_err("%s: Could not allocate memory for dec params\n",
- __func__);
- kfree(pdata->audio_effects[rtd->dai_link->id]);
- pdata->audio_effects[rtd->dai_link->id] = NULL;
- pdata->cstream[rtd->dai_link->id] = NULL;
- kfree(prtd);
- return -ENOMEM;
- }
- prtd->codec = FORMAT_MP3;
- prtd->bytes_received = 0;
- prtd->bytes_sent = 0;
- prtd->copied_total = 0;
- prtd->byte_offset = 0;
- prtd->sample_rate = 44100;
- prtd->num_channels = 2;
- prtd->drain_ready = 0;
- prtd->last_buffer = 0;
- prtd->first_buffer = 1;
- prtd->partial_drain_delay = 0;
- prtd->next_stream = 0;
- memset(&prtd->gapless_state, 0, sizeof(struct msm_compr_gapless_state));
- /*
- * Update the use_dsp_gapless_mode from gapless struture with the value
- * part of platform data.
- */
- prtd->gapless_state.use_dsp_gapless_mode = pdata->use_dsp_gapless_mode;
- pr_debug("%s: gapless mode %d", __func__, pdata->use_dsp_gapless_mode);
- spin_lock_init(&prtd->lock);
- atomic_set(&prtd->eos, 0);
- atomic_set(&prtd->start, 0);
- atomic_set(&prtd->drain, 0);
- atomic_set(&prtd->xrun, 0);
- atomic_set(&prtd->close, 0);
- atomic_set(&prtd->wait_on_close, 0);
- atomic_set(&prtd->error, 0);
- init_waitqueue_head(&prtd->eos_wait);
- init_waitqueue_head(&prtd->drain_wait);
- init_waitqueue_head(&prtd->close_wait);
- init_waitqueue_head(&prtd->wait_for_stream_avail);
- runtime->private_data = prtd;
- populate_codec_list(prtd);
- prtd->audio_client = q6asm_audio_client_alloc(
- (app_cb)compr_event_handler, prtd);
- if (prtd->audio_client == NULL) {
- pr_err("%s: Could not allocate memory for client\n", __func__);
- kfree(pdata->audio_effects[rtd->dai_link->id]);
- pdata->audio_effects[rtd->dai_link->id] = NULL;
- kfree(pdata->dec_params[rtd->dai_link->id]);
- pdata->dec_params[rtd->dai_link->id] = NULL;
- pdata->cstream[rtd->dai_link->id] = NULL;
- kfree(prtd);
- runtime->private_data = NULL;
- return -ENOMEM;
- }
- pr_debug("%s: session ID %d\n", __func__, prtd->audio_client->session);
- prtd->audio_client->perf_mode = false;
- prtd->session_id = prtd->audio_client->session;
- msm_adsp_init_mixer_ctl_pp_event_queue(rtd);
- pdata->is_in_use[rtd->dai_link->id] = true;
- return 0;
- }
- static int msm_compr_capture_open(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component = NULL;
- struct msm_compr_audio *prtd;
- struct msm_compr_pdata *pdata = NULL;
- enum apr_subsys_state subsys_state;
- pr_debug("%s\n", __func__);
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (!pdata) {
- pr_err("%s: pdata is NULL\n", __func__);
- return -EINVAL;
- }
- subsys_state = apr_get_subsys_state();
- if (subsys_state == APR_SUBSYS_DOWN) {
- pr_debug("%s: adsp is down\n", __func__);
- return -ENETRESET;
- }
- prtd = kzalloc(sizeof(struct msm_compr_audio), GFP_KERNEL);
- if (!prtd) {
- pr_err("Failed to allocate memory for msm_compr_audio\n");
- return -ENOMEM;
- }
- runtime->private_data = NULL;
- prtd->cstream = cstream;
- pdata->cstream[rtd->dai_link->id] = cstream;
- prtd->audio_client = q6asm_audio_client_alloc(
- (app_cb)compr_event_handler, prtd);
- if (!prtd->audio_client) {
- pr_err("%s: Could not allocate memory for client\n", __func__);
- pdata->cstream[rtd->dai_link->id] = NULL;
- kfree(prtd);
- return -ENOMEM;
- }
- pr_debug("%s: session ID %d\n", __func__, prtd->audio_client->session);
- prtd->audio_client->perf_mode = false;
- prtd->session_id = prtd->audio_client->session;
- prtd->codec = FORMAT_LINEAR_PCM;
- prtd->bytes_copied = 0;
- prtd->bytes_read = 0;
- prtd->bytes_read_offset = 0;
- prtd->received_total = 0;
- prtd->byte_offset = 0;
- prtd->sample_rate = 48000;
- prtd->num_channels = 2;
- prtd->first_buffer = 0;
- spin_lock_init(&prtd->lock);
- atomic_set(&prtd->eos, 0);
- atomic_set(&prtd->start, 0);
- atomic_set(&prtd->drain, 0);
- atomic_set(&prtd->xrun, 0);
- atomic_set(&prtd->close, 0);
- atomic_set(&prtd->wait_on_close, 0);
- atomic_set(&prtd->error, 0);
- init_waitqueue_head(&prtd->eos_wait);
- init_waitqueue_head(&prtd->drain_wait);
- init_waitqueue_head(&prtd->close_wait);
- init_waitqueue_head(&prtd->wait_for_stream_avail);
- runtime->private_data = prtd;
- return 0;
- }
- static int msm_compr_open(struct snd_compr_stream *cstream)
- {
- int ret = 0;
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- ret = msm_compr_playback_open(cstream);
- else if (cstream->direction == SND_COMPRESS_CAPTURE)
- ret = msm_compr_capture_open(cstream);
- return ret;
- }
- static int msm_compr_playback_free(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime;
- struct msm_compr_audio *prtd;
- struct snd_soc_pcm_runtime *soc_prtd;
- struct snd_soc_component *component = NULL;
- struct msm_compr_pdata *pdata;
- struct audio_client *ac;
- int dir = IN, ret = 0, stream_id;
- unsigned long flags;
- uint32_t stream_index;
- pr_debug("%s\n", __func__);
- if (!cstream) {
- pr_err("%s cstream is null\n", __func__);
- return 0;
- }
- runtime = cstream->runtime;
- soc_prtd = cstream->private_data;
- if (!runtime || !soc_prtd) {
- pr_err("%s runtime or soc_prtd is null\n",
- __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
- if (!component) {
- pr_err("%s component is null\n", __func__);
- return 0;
- }
- prtd = runtime->private_data;
- if (!prtd) {
- pr_err("%s prtd is null\n", __func__);
- return 0;
- }
- prtd->cmd_interrupt = 1;
- wake_up(&prtd->drain_wait);
- pdata = snd_soc_component_get_drvdata(component);
- ac = prtd->audio_client;
- if (!pdata || !ac) {
- pr_err("%s pdata or ac is null\n", __func__);
- return 0;
- }
- if (atomic_read(&prtd->eos)) {
- ret = wait_event_timeout(prtd->eos_wait,
- prtd->eos_ack,
- msecs_to_jiffies(TIMEOUT_MS));
- if (!ret)
- pr_err("%s: CMD_EOS failed\n", __func__);
- }
- if (atomic_read(&prtd->close)) {
- prtd->cmd_ack = 0;
- atomic_set(&prtd->wait_on_close, 1);
- ret = wait_event_timeout(prtd->close_wait,
- prtd->cmd_ack,
- msecs_to_jiffies(TIMEOUT_MS));
- if (!ret)
- pr_err("%s: CMD_CLOSE failed\n", __func__);
- }
- spin_lock_irqsave(&prtd->lock, flags);
- stream_id = ac->stream_id;
- stream_index = STREAM_ARRAY_INDEX(NEXT_STREAM_ID(stream_id));
- if ((stream_index < MAX_NUMBER_OF_STREAMS && stream_index >= 0) &&
- (prtd->gapless_state.stream_opened[stream_index])) {
- prtd->gapless_state.stream_opened[stream_index] = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- pr_debug(" close stream %d", NEXT_STREAM_ID(stream_id));
- q6asm_stream_cmd(ac, CMD_CLOSE, NEXT_STREAM_ID(stream_id));
- spin_lock_irqsave(&prtd->lock, flags);
- }
- stream_index = STREAM_ARRAY_INDEX(stream_id);
- if ((stream_index < MAX_NUMBER_OF_STREAMS && stream_index >= 0) &&
- (prtd->gapless_state.stream_opened[stream_index])) {
- prtd->gapless_state.stream_opened[stream_index] = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- pr_debug("close stream %d", stream_id);
- q6asm_stream_cmd(ac, CMD_CLOSE, stream_id);
- spin_lock_irqsave(&prtd->lock, flags);
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- mutex_lock(&pdata->lock);
- pdata->cstream[soc_prtd->dai_link->id] = NULL;
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- msm_pcm_routing_dereg_phy_stream(soc_prtd->dai_link->id,
- SNDRV_PCM_STREAM_PLAYBACK);
- }
- q6asm_audio_client_buf_free_contiguous(dir, ac);
- q6asm_audio_client_free(ac);
- msm_adsp_clean_mixer_ctl_pp_event_queue(soc_prtd);
- if (pdata->audio_effects[soc_prtd->dai_link->id] != NULL) {
- kfree(pdata->audio_effects[soc_prtd->dai_link->id]);
- pdata->audio_effects[soc_prtd->dai_link->id] = NULL;
- }
- if (pdata->dec_params[soc_prtd->dai_link->id] != NULL) {
- kfree(pdata->dec_params[soc_prtd->dai_link->id]);
- pdata->dec_params[soc_prtd->dai_link->id] = NULL;
- }
- pdata->is_in_use[soc_prtd->dai_link->id] = false;
- kfree(prtd);
- runtime->private_data = NULL;
- mutex_unlock(&pdata->lock);
- return 0;
- }
- static int msm_compr_capture_free(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime;
- struct msm_compr_audio *prtd;
- struct snd_soc_pcm_runtime *soc_prtd;
- struct snd_soc_component *component = NULL;
- struct msm_compr_pdata *pdata;
- struct audio_client *ac;
- int dir = OUT, stream_id;
- unsigned long flags;
- uint32_t stream_index;
- if (!cstream) {
- pr_err("%s cstream is null\n", __func__);
- return 0;
- }
- runtime = cstream->runtime;
- soc_prtd = cstream->private_data;
- if (!runtime || !soc_prtd) {
- pr_err("%s runtime or soc_prtd is null\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
- if (!component) {
- pr_err("%s component is null\n", __func__);
- return 0;
- }
- prtd = runtime->private_data;
- if (!prtd) {
- pr_err("%s prtd is null\n", __func__);
- return 0;
- }
- pdata = snd_soc_component_get_drvdata(component);
- ac = prtd->audio_client;
- if (!pdata || !ac) {
- pr_err("%s pdata or ac is null\n", __func__);
- return 0;
- }
- spin_lock_irqsave(&prtd->lock, flags);
- stream_id = ac->stream_id;
- stream_index = STREAM_ARRAY_INDEX(stream_id);
- if ((stream_index < MAX_NUMBER_OF_STREAMS && stream_index >= 0)) {
- spin_unlock_irqrestore(&prtd->lock, flags);
- pr_debug("close stream %d", stream_id);
- q6asm_stream_cmd(ac, CMD_CLOSE, stream_id);
- spin_lock_irqsave(&prtd->lock, flags);
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- mutex_lock(&pdata->lock);
- pdata->cstream[soc_prtd->dai_link->id] = NULL;
- msm_pcm_routing_dereg_phy_stream(soc_prtd->dai_link->id,
- SNDRV_PCM_STREAM_CAPTURE);
- q6asm_audio_client_buf_free_contiguous(dir, ac);
- q6asm_audio_client_free(ac);
- kfree(prtd);
- runtime->private_data = NULL;
- mutex_unlock(&pdata->lock);
- return 0;
- }
- static int msm_compr_free(struct snd_compr_stream *cstream)
- {
- int ret = 0;
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- ret = msm_compr_playback_free(cstream);
- else if (cstream->direction == SND_COMPRESS_CAPTURE)
- ret = msm_compr_capture_free(cstream);
- return ret;
- }
- static bool msm_compr_validate_codec_compr(__u32 codec_id)
- {
- int32_t i;
- for (i = 0; i < ARRAY_SIZE(compr_codecs); i++) {
- if (compr_codecs[i] == codec_id)
- return true;
- }
- return false;
- }
- /* compress stream operations */
- static int msm_compr_set_params(struct snd_compr_stream *cstream,
- struct snd_compr_params *params)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- int ret = 0, frame_sz = 0;
- int i, num_rates;
- bool is_format_gapless = false;
- pr_debug("%s\n", __func__);
- num_rates = sizeof(supported_sample_rates)/sizeof(unsigned int);
- for (i = 0; i < num_rates; i++)
- if (params->codec.sample_rate == supported_sample_rates[i])
- break;
- if (i == num_rates)
- return -EINVAL;
- memcpy(&prtd->codec_param, params, sizeof(struct snd_compr_params));
- /* ToDo: remove duplicates */
- prtd->num_channels = prtd->codec_param.codec.ch_in;
- prtd->sample_rate = prtd->codec_param.codec.sample_rate;
- pr_debug("%s: sample_rate %d\n", __func__, prtd->sample_rate);
- /* prtd->codec_param.codec.reserved[0] is for compr_passthr */
- if ((prtd->codec_param.codec.reserved[0] >= LEGACY_PCM &&
- prtd->codec_param.
- codec.reserved[0] <= COMPRESSED_PASSTHROUGH_DSD) ||
- (prtd->codec_param.
- codec.reserved[0] == COMPRESSED_PASSTHROUGH_IEC61937))
- prtd->compr_passthr = prtd->codec_param.codec.reserved[0];
- else
- prtd->compr_passthr = LEGACY_PCM;
- pr_debug("%s: compr_passthr = %d", __func__, prtd->compr_passthr);
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s: Reset gapless mode playback for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- prtd->gapless_state.use_dsp_gapless_mode = 0;
- if (!msm_compr_validate_codec_compr(params->codec.id)) {
- pr_err("%s codec not supported in passthrough,id =%d\n",
- __func__, params->codec.id);
- return -EINVAL;
- }
- }
- /* reserved[1] is for flags */
- if (params->codec.reserved[1] & COMPRESSED_PERF_MODE_FLAG) {
- pr_debug("%s: setting perf mode = %d", __func__, LOW_LATENCY_PCM_MODE);
- prtd->audio_client->perf_mode = LOW_LATENCY_PCM_MODE;
- }
- switch (params->codec.id) {
- case SND_AUDIOCODEC_PCM: {
- pr_debug("SND_AUDIOCODEC_PCM\n");
- prtd->codec = FORMAT_LINEAR_PCM;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_MP3: {
- pr_debug("SND_AUDIOCODEC_MP3\n");
- prtd->codec = FORMAT_MP3;
- frame_sz = MP3_OUTPUT_FRAME_SZ;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_AAC: {
- pr_debug("SND_AUDIOCODEC_AAC\n");
- prtd->codec = FORMAT_MPEG4_AAC;
- frame_sz = AAC_OUTPUT_FRAME_SZ;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_AC3: {
- pr_debug("SND_AUDIOCODEC_AC3\n");
- prtd->codec = FORMAT_AC3;
- frame_sz = AC3_OUTPUT_FRAME_SZ;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_EAC3: {
- pr_debug("SND_AUDIOCODEC_EAC3\n");
- prtd->codec = FORMAT_EAC3;
- frame_sz = EAC3_OUTPUT_FRAME_SZ;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_MP2: {
- pr_debug("SND_AUDIOCODEC_MP2\n");
- prtd->codec = FORMAT_MP2;
- break;
- }
- case SND_AUDIOCODEC_WMA: {
- pr_debug("SND_AUDIOCODEC_WMA\n");
- prtd->codec = FORMAT_WMA_V9;
- break;
- }
- case SND_AUDIOCODEC_WMA_PRO: {
- pr_debug("SND_AUDIOCODEC_WMA_PRO\n");
- prtd->codec = FORMAT_WMA_V10PRO;
- break;
- }
- case SND_AUDIOCODEC_FLAC: {
- pr_debug("%s: SND_AUDIOCODEC_FLAC\n", __func__);
- prtd->codec = FORMAT_FLAC;
- /*
- * DSP bufferring is based on blk size,
- * consider mininum buffering to rule out any false wait
- */
- frame_sz =
- prtd->codec_param.codec.options.flac_dec.min_blk_size;
- is_format_gapless = true;
- break;
- }
- case SND_AUDIOCODEC_VORBIS: {
- pr_debug("%s: SND_AUDIOCODEC_VORBIS\n", __func__);
- prtd->codec = FORMAT_VORBIS;
- break;
- }
- case SND_AUDIOCODEC_ALAC: {
- pr_debug("%s: SND_AUDIOCODEC_ALAC\n", __func__);
- prtd->codec = FORMAT_ALAC;
- break;
- }
- case SND_AUDIOCODEC_APE: {
- pr_debug("%s: SND_AUDIOCODEC_APE\n", __func__);
- prtd->codec = FORMAT_APE;
- break;
- }
- case SND_AUDIOCODEC_DTS: {
- pr_debug("%s: SND_AUDIOCODEC_DTS\n", __func__);
- prtd->codec = FORMAT_DTS;
- break;
- }
- case SND_AUDIOCODEC_DSD: {
- pr_debug("%s: SND_AUDIOCODEC_DSD\n", __func__);
- prtd->codec = FORMAT_DSD;
- break;
- }
- case SND_AUDIOCODEC_TRUEHD: {
- pr_debug("%s: SND_AUDIOCODEC_TRUEHD\n", __func__);
- prtd->codec = FORMAT_TRUEHD;
- break;
- }
- case SND_AUDIOCODEC_IEC61937: {
- pr_debug("%s: SND_AUDIOCODEC_IEC61937\n", __func__);
- prtd->codec = FORMAT_IEC61937;
- break;
- }
- case SND_AUDIOCODEC_APTX: {
- pr_debug("%s: SND_AUDIOCODEC_APTX\n", __func__);
- prtd->codec = FORMAT_APTX;
- break;
- }
- case SND_AUDIOCODEC_BESPOKE: {
- pr_debug("%s: SND_AUDIOCODEC_BESPOKE\n", __func__);
- prtd->codec = FORMAT_BESPOKE;
- break;
- }
- case SND_AUDIOCODEC_AMR: {
- pr_debug("%s:SND_AUDIOCODEC_AMR\n", __func__);
- prtd->codec = FORMAT_AMRNB;
- break;
- }
- case SND_AUDIOCODEC_AMRWB: {
- pr_debug("%s:SND_AUDIOCODEC_AMRWB\n", __func__);
- prtd->codec = FORMAT_AMRWB;
- break;
- }
- case SND_AUDIOCODEC_AMRWBPLUS: {
- pr_debug("%s:SND_AUDIOCODEC_AMRWBPLUS\n", __func__);
- prtd->codec = FORMAT_AMR_WB_PLUS;
- break;
- }
- default:
- pr_err("codec not supported, id =%d\n", params->codec.id);
- return -EINVAL;
- }
- if (!is_format_gapless)
- prtd->gapless_state.use_dsp_gapless_mode = false;
- prtd->partial_drain_delay =
- msm_compr_get_partial_drain_delay(frame_sz, prtd->sample_rate);
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- ret = msm_compr_configure_dsp_for_playback(cstream);
- else if (cstream->direction == SND_COMPRESS_CAPTURE)
- ret = msm_compr_configure_dsp_for_capture(cstream);
- return ret;
- }
- static int msm_compr_drain_buffer(struct msm_compr_audio *prtd,
- unsigned long *flags)
- {
- int rc = 0;
- atomic_set(&prtd->drain, 1);
- prtd->drain_ready = 0;
- spin_unlock_irqrestore(&prtd->lock, *flags);
- pr_debug("%s: wait for buffer to be drained\n", __func__);
- rc = wait_event_interruptible(prtd->drain_wait,
- prtd->drain_ready ||
- prtd->cmd_interrupt ||
- atomic_read(&prtd->xrun) ||
- atomic_read(&prtd->error));
- pr_debug("%s: out of buffer drain wait with ret %d\n", __func__, rc);
- spin_lock_irqsave(&prtd->lock, *flags);
- if (prtd->cmd_interrupt) {
- pr_debug("%s: buffer drain interrupted by flush)\n", __func__);
- rc = -EINTR;
- prtd->cmd_interrupt = 0;
- }
- if (atomic_read(&prtd->error)) {
- pr_err("%s: Got RESET EVENTS notification, return\n",
- __func__);
- rc = -ENETRESET;
- }
- return rc;
- }
- static int msm_compr_wait_for_stream_avail(struct msm_compr_audio *prtd,
- unsigned long *flags)
- {
- int rc = 0;
- pr_debug("next session is already in opened state\n");
- prtd->next_stream = 1;
- prtd->cmd_interrupt = 0;
- spin_unlock_irqrestore(&prtd->lock, *flags);
- /*
- * Wait for stream to be available, or the wait to be interrupted by
- * commands like flush or till a timeout of one second.
- */
- rc = wait_event_timeout(prtd->wait_for_stream_avail,
- prtd->stream_available || prtd->cmd_interrupt, 1 * HZ);
- pr_err("%s:prtd->stream_available %d, prtd->cmd_interrupt %d rc %d\n",
- __func__, prtd->stream_available, prtd->cmd_interrupt, rc);
- spin_lock_irqsave(&prtd->lock, *flags);
- if (rc == 0) {
- pr_err("%s: wait_for_stream_avail timed out\n",
- __func__);
- rc = -ETIMEDOUT;
- } else if (prtd->cmd_interrupt == 1) {
- /*
- * This scenario might not happen as we do not allow
- * flush in transition state.
- */
- pr_debug("%s: wait_for_stream_avail interrupted\n", __func__);
- prtd->cmd_interrupt = 0;
- prtd->stream_available = 0;
- rc = -EINTR;
- } else {
- prtd->stream_available = 0;
- rc = 0;
- }
- pr_debug("%s : rc = %d", __func__, rc);
- return rc;
- }
- static int msm_compr_trigger(struct snd_compr_stream *cstream, int cmd)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component = NULL;
- struct msm_compr_pdata *pdata = NULL;
- uint32_t *volume = NULL;
- struct audio_client *ac = prtd->audio_client;
- unsigned long fe_id = rtd->dai_link->id;
- int rc = 0;
- int bytes_to_write;
- unsigned long flags;
- int stream_id;
- uint32_t stream_index;
- uint16_t bits_per_sample = 16;
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (!pdata) {
- pr_err("%s: pdata is NULL\n", __func__);
- return -EINVAL;
- }
- volume = pdata->volume[rtd->dai_link->id];
- spin_lock_irqsave(&prtd->lock, flags);
- if (atomic_read(&prtd->error)) {
- pr_err("%s Got RESET EVENTS notification, return immediately",
- __func__);
- spin_unlock_irqrestore(&prtd->lock, flags);
- return 0;
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- pr_debug("%s: SNDRV_PCM_TRIGGER_START\n", __func__);
- atomic_set(&prtd->start, 1);
- /*
- * compr_set_volume and compr_init_pp_params
- * are used to configure ASM volume hence not
- * needed for compress passthrough playback.
- *
- * compress passthrough volume is controlled in
- * ADM by adm_send_compressed_device_mute()
- */
- if (prtd->compr_passthr == LEGACY_PCM &&
- cstream->direction == SND_COMPRESS_PLAYBACK) {
- /* set volume for the stream before RUN */
- rc = msm_compr_set_volume(cstream,
- volume[0], volume[1]);
- if (rc)
- pr_err("%s : Set Volume failed : %d\n",
- __func__, rc);
- rc = msm_compr_init_pp_params(cstream, ac);
- if (rc)
- pr_err("%s : init PP params failed : %d\n",
- __func__, rc);
- } else {
- msm_compr_read_buffer(prtd);
- }
- /* issue RUN command for the stream */
- q6asm_run_nowait(prtd->audio_client, prtd->run_mode,
- prtd->start_delay_msw, prtd->start_delay_lsw);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- spin_lock_irqsave(&prtd->lock, flags);
- pr_debug("%s: SNDRV_PCM_TRIGGER_STOP transition %d\n", __func__,
- prtd->gapless_state.gapless_transition);
- stream_id = ac->stream_id;
- atomic_set(&prtd->start, 0);
- if (cstream->direction == SND_COMPRESS_CAPTURE) {
- q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
- atomic_set(&prtd->xrun, 0);
- prtd->received_total = 0;
- prtd->bytes_copied = 0;
- prtd->bytes_read = 0;
- prtd->bytes_read_offset = 0;
- prtd->byte_offset = 0;
- prtd->app_pointer = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- if (prtd->next_stream) {
- pr_debug("%s: interrupt next track wait queues\n",
- __func__);
- prtd->cmd_interrupt = 1;
- wake_up(&prtd->wait_for_stream_avail);
- prtd->next_stream = 0;
- }
- if (atomic_read(&prtd->eos)) {
- pr_debug("%s: interrupt eos wait queues", __func__);
- /*
- * Gapless playback does not wait for eos, do not set
- * cmd_int and do not wake up eos_wait during gapless
- * transition
- */
- if (!prtd->gapless_state.gapless_transition) {
- prtd->cmd_interrupt = 1;
- wake_up(&prtd->eos_wait);
- }
- atomic_set(&prtd->eos, 0);
- }
- if (atomic_read(&prtd->drain)) {
- pr_debug("%s: interrupt drain wait queues", __func__);
- prtd->cmd_interrupt = 1;
- prtd->drain_ready = 1;
- wake_up(&prtd->drain_wait);
- atomic_set(&prtd->drain, 0);
- }
- prtd->last_buffer = 0;
- prtd->cmd_ack = 0;
- if (!prtd->gapless_state.gapless_transition) {
- pr_debug("issue CMD_FLUSH stream_id %d\n", stream_id);
- spin_unlock_irqrestore(&prtd->lock, flags);
- q6asm_stream_cmd(
- prtd->audio_client, CMD_FLUSH, stream_id);
- spin_lock_irqsave(&prtd->lock, flags);
- } else {
- prtd->first_buffer = 0;
- }
- /* FIXME. only reset if flush was successful */
- prtd->byte_offset = 0;
- prtd->copied_total = 0;
- prtd->app_pointer = 0;
- prtd->bytes_received = 0;
- prtd->bytes_sent = 0;
- prtd->marker_timestamp = 0;
- atomic_set(&prtd->xrun, 0);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- pr_debug("SNDRV_PCM_TRIGGER_PAUSE_PUSH transition %d\n",
- prtd->gapless_state.gapless_transition);
- if (!prtd->gapless_state.gapless_transition) {
- pr_debug("issue CMD_PAUSE stream_id %d\n",
- ac->stream_id);
- q6asm_stream_cmd_nowait(ac, CMD_PAUSE, ac->stream_id);
- atomic_set(&prtd->start, 0);
- }
- break;
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- pr_debug("SNDRV_PCM_TRIGGER_PAUSE_RELEASE transition %d\n",
- prtd->gapless_state.gapless_transition);
- if (!prtd->gapless_state.gapless_transition) {
- atomic_set(&prtd->start, 1);
- q6asm_run_nowait(prtd->audio_client, prtd->run_mode,
- 0, 0);
- }
- break;
- case SND_COMPR_TRIGGER_PARTIAL_DRAIN:
- pr_debug("%s: SND_COMPR_TRIGGER_PARTIAL_DRAIN\n", __func__);
- if (!prtd->gapless_state.use_dsp_gapless_mode) {
- pr_debug("%s: set partial drain as drain\n", __func__);
- cmd = SND_COMPR_TRIGGER_DRAIN;
- }
- case SND_COMPR_TRIGGER_DRAIN:
- pr_debug("%s: SNDRV_COMPRESS_DRAIN\n", __func__);
- /* Make sure all the data is sent to DSP before sending EOS */
- spin_lock_irqsave(&prtd->lock, flags);
- if (!atomic_read(&prtd->start)) {
- pr_err("%s: stream is not in started state\n",
- __func__);
- rc = -EPERM;
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- if (prtd->bytes_received > prtd->copied_total) {
- pr_debug("%s: wait till all the data is sent to dsp\n",
- __func__);
- rc = msm_compr_drain_buffer(prtd, &flags);
- if (rc || !atomic_read(&prtd->start)) {
- if (rc != -ENETRESET)
- rc = -EINTR;
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- /*
- * FIXME: Bug.
- * Write(32767)
- * Start
- * Drain <- Indefinite wait
- * sol1 : if (prtd->copied_total) then wait?
- * sol2 : (prtd->cmd_interrupt || prtd->drain_ready ||
- * atomic_read(xrun)
- */
- bytes_to_write = prtd->bytes_received
- - prtd->copied_total;
- WARN(bytes_to_write > runtime->fragment_size,
- "last write %d cannot be > than fragment_size",
- bytes_to_write);
- if (bytes_to_write > 0) {
- pr_debug("%s: send %d partial bytes at the end",
- __func__, bytes_to_write);
- atomic_set(&prtd->xrun, 0);
- prtd->last_buffer = 1;
- msm_compr_send_buffer(prtd);
- }
- }
- if ((cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN) &&
- (prtd->gapless_state.set_next_stream_id)) {
- /* wait for the last buffer to be returned */
- if (prtd->last_buffer) {
- pr_debug("%s: last buffer drain\n", __func__);
- rc = msm_compr_drain_buffer(prtd, &flags);
- if (rc || !atomic_read(&prtd->start)) {
- spin_unlock_irqrestore(&prtd->lock,
- flags);
- break;
- }
- }
- /* send EOS */
- prtd->eos_ack = 0;
- atomic_set(&prtd->eos, 1);
- pr_debug("issue CMD_EOS stream_id %d\n", ac->stream_id);
- q6asm_stream_cmd_nowait(ac, CMD_EOS, ac->stream_id);
- pr_info("PARTIAL DRAIN, do not wait for EOS ack\n");
- /* send a zero length buffer */
- atomic_set(&prtd->xrun, 0);
- msm_compr_send_buffer(prtd);
- /* wait for the zero length buffer to be returned */
- pr_debug("%s: zero length buffer drain\n", __func__);
- rc = msm_compr_drain_buffer(prtd, &flags);
- if (rc || !atomic_read(&prtd->start)) {
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- /* sleep for additional duration partial drain */
- atomic_set(&prtd->drain, 1);
- prtd->drain_ready = 0;
- pr_debug("%s, additional sleep: %d\n", __func__,
- prtd->partial_drain_delay);
- spin_unlock_irqrestore(&prtd->lock, flags);
- rc = wait_event_timeout(prtd->drain_wait,
- prtd->drain_ready || prtd->cmd_interrupt,
- msecs_to_jiffies(prtd->partial_drain_delay));
- pr_debug("%s: out of additional wait for low sample rate\n",
- __func__);
- spin_lock_irqsave(&prtd->lock, flags);
- if (prtd->cmd_interrupt) {
- pr_debug("%s: additional wait interrupted by flush)\n",
- __func__);
- rc = -EINTR;
- prtd->cmd_interrupt = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- /* move to next stream and reset vars */
- pr_debug("%s: Moving to next stream in gapless\n",
- __func__);
- ac->stream_id = NEXT_STREAM_ID(ac->stream_id);
- prtd->byte_offset = 0;
- prtd->app_pointer = 0;
- prtd->first_buffer = 1;
- prtd->last_buffer = 0;
- /*
- * Set gapless transition flag only if EOS hasn't been
- * acknowledged already.
- */
- if (atomic_read(&prtd->eos))
- prtd->gapless_state.gapless_transition = 1;
- prtd->marker_timestamp = 0;
- /*
- * Don't reset these as these vars map to
- * total_bytes_transferred and total_bytes_available
- * directly, only total_bytes_transferred will be
- * updated in the next avail() ioctl
- * prtd->copied_total = 0;
- * prtd->bytes_received = 0;
- */
- atomic_set(&prtd->drain, 0);
- atomic_set(&prtd->xrun, 1);
- pr_debug("%s: issue CMD_RUN", __func__);
- q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- /*
- * moving to next stream failed, so reset the gapless state
- * set next stream id for the same session so that the same
- * stream can be used for gapless playback
- */
- prtd->gapless_state.set_next_stream_id = false;
- prtd->gapless_state.gapless_transition = 0;
- pr_debug("%s:CMD_EOS stream_id %d\n", __func__, ac->stream_id);
- prtd->eos_ack = 0;
- atomic_set(&prtd->eos, 1);
- q6asm_stream_cmd_nowait(ac, CMD_EOS, ac->stream_id);
- spin_unlock_irqrestore(&prtd->lock, flags);
- /* Wait indefinitely for DRAIN. Flush can also signal this*/
- rc = wait_event_interruptible(prtd->eos_wait,
- (prtd->eos_ack ||
- prtd->cmd_interrupt ||
- atomic_read(&prtd->error)));
- if (rc < 0)
- pr_err("%s: EOS wait failed\n", __func__);
- pr_debug("%s: SNDRV_COMPRESS_DRAIN out of wait for EOS\n",
- __func__);
- if (prtd->cmd_interrupt)
- rc = -EINTR;
- if (atomic_read(&prtd->error)) {
- pr_err("%s: Got RESET EVENTS notification, return\n",
- __func__);
- rc = -ENETRESET;
- }
- /*FIXME : what if a flush comes while PC is here */
- if (rc == 0) {
- /*
- * Failed to open second stream in DSP for gapless
- * so prepare the current stream in session
- * for gapless playback
- */
- spin_lock_irqsave(&prtd->lock, flags);
- pr_debug("%s:issue CMD_PAUSE stream_id %d",
- __func__, ac->stream_id);
- q6asm_stream_cmd_nowait(ac, CMD_PAUSE, ac->stream_id);
- prtd->cmd_ack = 0;
- spin_unlock_irqrestore(&prtd->lock, flags);
- /*
- * Cache this time as last known time
- */
- if (pdata->use_legacy_api)
- q6asm_get_session_time_legacy(
- prtd->audio_client,
- &prtd->marker_timestamp);
- else
- q6asm_get_session_time(prtd->audio_client,
- &prtd->marker_timestamp);
- spin_lock_irqsave(&prtd->lock, flags);
- /*
- * Don't reset these as these vars map to
- * total_bytes_transferred and total_bytes_available.
- * Just total_bytes_transferred will be updated
- * in the next avail() ioctl.
- * prtd->copied_total = 0;
- * prtd->bytes_received = 0;
- * do not reset prtd->bytes_sent as well as the same
- * session is used for gapless playback
- */
- prtd->byte_offset = 0;
- prtd->app_pointer = 0;
- prtd->first_buffer = 1;
- prtd->last_buffer = 0;
- atomic_set(&prtd->drain, 0);
- atomic_set(&prtd->xrun, 1);
- spin_unlock_irqrestore(&prtd->lock, flags);
- pr_debug("%s:issue CMD_FLUSH ac->stream_id %d",
- __func__, ac->stream_id);
- q6asm_stream_cmd(ac, CMD_FLUSH, ac->stream_id);
- q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
- }
- prtd->cmd_interrupt = 0;
- break;
- case SND_COMPR_TRIGGER_NEXT_TRACK:
- if (!prtd->gapless_state.use_dsp_gapless_mode) {
- pr_debug("%s: ignore trigger next track\n", __func__);
- rc = 0;
- break;
- }
- pr_debug("%s: SND_COMPR_TRIGGER_NEXT_TRACK\n", __func__);
- spin_lock_irqsave(&prtd->lock, flags);
- rc = 0;
- /* next stream in gapless */
- stream_id = NEXT_STREAM_ID(ac->stream_id);
- /*
- * Wait if stream 1 has not completed before honoring next
- * track for stream 3. Scenario happens if second clip is
- * small and fills in one buffer so next track will be
- * called immediately.
- */
- stream_index = STREAM_ARRAY_INDEX(stream_id);
- if (stream_index >= MAX_NUMBER_OF_STREAMS ||
- stream_index < 0) {
- pr_err("%s: Invalid stream index: %d", __func__,
- stream_index);
- spin_unlock_irqrestore(&prtd->lock, flags);
- rc = -EINVAL;
- break;
- }
- if (prtd->gapless_state.stream_opened[stream_index]) {
- if (prtd->gapless_state.gapless_transition) {
- rc = msm_compr_wait_for_stream_avail(prtd,
- &flags);
- } else {
- /*
- * If session is already opened break out if
- * the state is not gapless transition. This
- * is when seek happens after the last buffer
- * is sent to the driver. Next track would be
- * called again after last buffer is sent.
- */
- pr_debug("next session is in opened state\n");
- spin_unlock_irqrestore(&prtd->lock, flags);
- break;
- }
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- if (rc < 0) {
- /*
- * if return type EINTR then reset to zero. Tiny
- * compress treats EINTR as error and prevents PARTIAL
- * DRAIN. EINTR is not an error. wait for stream avail
- * is interrupted by some other command like FLUSH.
- */
- if (rc == -EINTR) {
- pr_debug("%s: EINTR reset rc to 0\n", __func__);
- rc = 0;
- }
- break;
- }
- if (prtd->codec_param.codec.format == SNDRV_PCM_FORMAT_S24_LE)
- bits_per_sample = 24;
- else if (prtd->codec_param.codec.format ==
- SNDRV_PCM_FORMAT_S32_LE)
- bits_per_sample = 32;
- pr_debug("%s: open_write stream_id %d bits_per_sample %d",
- __func__, stream_id, bits_per_sample);
- if (q6core_get_avcs_api_version_per_service(
- APRV2_IDS_SERVICE_ID_ADSP_ASM_V) >=
- ADSP_ASM_API_VERSION_V2)
- rc = q6asm_stream_open_write_v5(prtd->audio_client,
- prtd->codec, bits_per_sample,
- stream_id,
- prtd->gapless_state.use_dsp_gapless_mode);
- else
- rc = q6asm_stream_open_write_v4(prtd->audio_client,
- prtd->codec, bits_per_sample,
- stream_id,
- prtd->gapless_state.use_dsp_gapless_mode);
- if (rc < 0) {
- pr_err("%s: Session out open failed for gapless [%d]\n",
- __func__, rc);
- break;
- }
- spin_lock_irqsave(&prtd->lock, flags);
- prtd->gapless_state.stream_opened[stream_index] = 1;
- prtd->gapless_state.set_next_stream_id = true;
- spin_unlock_irqrestore(&prtd->lock, flags);
- rc = msm_compr_send_media_format_block(cstream,
- stream_id, false);
- if (rc < 0) {
- pr_err("%s, failed to send media format block\n",
- __func__);
- break;
- }
- msm_compr_send_dec_params(cstream, pdata->dec_params[fe_id],
- stream_id);
- break;
- }
- return rc;
- }
- static int msm_compr_pointer(struct snd_compr_stream *cstream,
- struct snd_compr_tstamp *arg)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct msm_compr_audio *prtd = runtime->private_data;
- struct snd_soc_component *component = NULL;
- struct msm_compr_pdata *pdata = NULL;
- struct snd_compr_tstamp tstamp;
- uint64_t timestamp = 0;
- int rc = 0, first_buffer;
- unsigned long flags;
- uint32_t gapless_transition;
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (!pdata) {
- pr_err("%s: pdata is NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s\n", __func__);
- memset(&tstamp, 0x0, sizeof(struct snd_compr_tstamp));
- spin_lock_irqsave(&prtd->lock, flags);
- tstamp.sampling_rate = prtd->sample_rate;
- tstamp.byte_offset = prtd->byte_offset;
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- tstamp.copied_total = prtd->copied_total;
- else if (cstream->direction == SND_COMPRESS_CAPTURE)
- tstamp.copied_total = prtd->received_total;
- first_buffer = prtd->first_buffer;
- if (atomic_read(&prtd->error)) {
- pr_err_ratelimited("%s Got RESET EVENTS notification, return error\n",
- __func__);
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- runtime->total_bytes_transferred = tstamp.copied_total;
- else
- runtime->total_bytes_available = tstamp.copied_total;
- tstamp.pcm_io_frames = 0;
- memcpy(arg, &tstamp, sizeof(struct snd_compr_tstamp));
- spin_unlock_irqrestore(&prtd->lock, flags);
- return -ENETRESET;
- }
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- gapless_transition = prtd->gapless_state.gapless_transition;
- spin_unlock_irqrestore(&prtd->lock, flags);
- if (gapless_transition)
- pr_debug("%s session time in gapless transition",
- __func__);
- /*
- *- Do not query if no buffer has been given.
- *- Do not query on a gapless transition.
- * Playback for the 2nd stream can start (thus returning time
- * starting from 0) before the driver knows about EOS of first
- * stream.
- */
- if (!first_buffer || gapless_transition) {
- if (pdata->use_legacy_api)
- rc = q6asm_get_session_time_legacy(
- prtd->audio_client, &prtd->marker_timestamp);
- else
- rc = q6asm_get_session_time(
- prtd->audio_client, &prtd->marker_timestamp);
- if (rc < 0) {
- if (atomic_read(&prtd->error))
- return -ENETRESET;
- else
- return rc;
- }
- }
- } else {
- spin_unlock_irqrestore(&prtd->lock, flags);
- }
- timestamp = prtd->marker_timestamp;
- /* DSP returns timestamp in usec */
- pr_debug("%s: timestamp = %lld usec\n", __func__, timestamp);
- timestamp *= prtd->sample_rate;
- tstamp.pcm_io_frames = (snd_pcm_uframes_t)div64_u64(timestamp, 1000000);
- memcpy(arg, &tstamp, sizeof(struct snd_compr_tstamp));
- return 0;
- }
- static int msm_compr_ack(struct snd_compr_stream *cstream,
- size_t count)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- void *src, *dstn;
- size_t copy;
- unsigned long flags;
- WARN(1, "This path is untested");
- return -EINVAL;
- pr_debug("%s: count = %zd\n", __func__, count);
- if (!prtd->buffer) {
- pr_err("%s: Buffer is not allocated yet ??\n", __func__);
- return -EINVAL;
- }
- src = runtime->buffer + prtd->app_pointer;
- dstn = prtd->buffer + prtd->app_pointer;
- if (count < prtd->buffer_size - prtd->app_pointer) {
- memcpy(dstn, src, count);
- prtd->app_pointer += count;
- } else {
- copy = prtd->buffer_size - prtd->app_pointer;
- memcpy(dstn, src, copy);
- memcpy(prtd->buffer, runtime->buffer, count - copy);
- prtd->app_pointer = count - copy;
- }
- /*
- * If the stream is started and all the bytes received were
- * copied to DSP, the newly received bytes should be
- * sent right away
- */
- spin_lock_irqsave(&prtd->lock, flags);
- if (atomic_read(&prtd->start) &&
- prtd->bytes_received == prtd->copied_total) {
- prtd->bytes_received += count;
- msm_compr_send_buffer(prtd);
- } else
- prtd->bytes_received += count;
- spin_unlock_irqrestore(&prtd->lock, flags);
- return 0;
- }
- static int msm_compr_playback_copy(struct snd_compr_stream *cstream,
- char __user *buf, size_t count)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- void *dstn;
- size_t copy;
- uint64_t bytes_available = 0;
- unsigned long flags;
- pr_debug("%s: count = %zd\n", __func__, count);
- if (!prtd->buffer) {
- pr_err("%s: Buffer is not allocated yet ??", __func__);
- return 0;
- }
- spin_lock_irqsave(&prtd->lock, flags);
- if (atomic_read(&prtd->error)) {
- pr_err("%s Got RESET EVENTS notification", __func__);
- spin_unlock_irqrestore(&prtd->lock, flags);
- return -ENETRESET;
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- dstn = prtd->buffer + prtd->app_pointer;
- if (count < prtd->buffer_size - prtd->app_pointer) {
- if (copy_from_user(dstn, buf, count))
- return -EFAULT;
- prtd->app_pointer += count;
- } else {
- copy = prtd->buffer_size - prtd->app_pointer;
- if (copy_from_user(dstn, buf, copy))
- return -EFAULT;
- if (copy_from_user(prtd->buffer, buf + copy, count - copy))
- return -EFAULT;
- prtd->app_pointer = count - copy;
- }
- /*
- * If stream is started and there has been an xrun,
- * since the available bytes fits fragment_size, copy the data
- * right away.
- */
- spin_lock_irqsave(&prtd->lock, flags);
- prtd->bytes_received += count;
- if (atomic_read(&prtd->start)) {
- if (atomic_read(&prtd->xrun)) {
- pr_debug("%s: in xrun, count = %zd\n", __func__, count);
- bytes_available = prtd->bytes_received -
- prtd->copied_total;
- if (bytes_available >= runtime->fragment_size) {
- pr_debug("%s: handle xrun, bytes_to_write = %llu\n",
- __func__, bytes_available);
- atomic_set(&prtd->xrun, 0);
- msm_compr_send_buffer(prtd);
- } /* else not sufficient data */
- } /* writes will continue on the next write_done */
- }
- spin_unlock_irqrestore(&prtd->lock, flags);
- return count;
- }
- static int msm_compr_capture_copy(struct snd_compr_stream *cstream,
- char __user *buf, size_t count)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- void *source;
- unsigned long flags;
- pr_debug("%s: count = %zd\n", __func__, count);
- if (!prtd->buffer) {
- pr_err("%s: Buffer is not allocated yet ??", __func__);
- return 0;
- }
- spin_lock_irqsave(&prtd->lock, flags);
- if (atomic_read(&prtd->error)) {
- pr_err("%s Got RESET EVENTS notification", __func__);
- spin_unlock_irqrestore(&prtd->lock, flags);
- return -ENETRESET;
- }
- source = prtd->buffer + prtd->app_pointer;
- /* check if we have requested amount of data to copy to user*/
- if (count <= prtd->received_total - prtd->bytes_copied) {
- spin_unlock_irqrestore(&prtd->lock, flags);
- if (copy_to_user(buf, source, count)) {
- pr_err("copy_to_user failed");
- return -EFAULT;
- }
- spin_lock_irqsave(&prtd->lock, flags);
- prtd->app_pointer += count;
- if (prtd->app_pointer >= prtd->buffer_size)
- prtd->app_pointer -= prtd->buffer_size;
- prtd->bytes_copied += count;
- }
- msm_compr_read_buffer(prtd);
- spin_unlock_irqrestore(&prtd->lock, flags);
- return count;
- }
- static int msm_compr_copy(struct snd_compr_stream *cstream,
- char __user *buf, size_t count)
- {
- int ret = 0;
- pr_debug(" In %s\n", __func__);
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- ret = msm_compr_playback_copy(cstream, buf, count);
- else if (cstream->direction == SND_COMPRESS_CAPTURE)
- ret = msm_compr_capture_copy(cstream, buf, count);
- return ret;
- }
- static int msm_compr_get_caps(struct snd_compr_stream *cstream,
- struct snd_compr_caps *arg)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_compr_audio *prtd = runtime->private_data;
- int ret = 0;
- pr_debug("%s\n", __func__);
- if ((arg != NULL) && (prtd != NULL)) {
- memcpy(arg, &prtd->compr_cap, sizeof(struct snd_compr_caps));
- } else {
- ret = -EINVAL;
- pr_err("%s: arg (0x%pK), prtd (0x%pK)\n", __func__, arg, prtd);
- }
- return ret;
- }
- static int msm_compr_get_codec_caps(struct snd_compr_stream *cstream,
- struct snd_compr_codec_caps *codec)
- {
- pr_debug("%s\n", __func__);
- switch (codec->codec) {
- case SND_AUDIOCODEC_MP3:
- codec->num_descriptors = 2;
- codec->descriptor[0].max_ch = 2;
- memcpy(codec->descriptor[0].sample_rates,
- supported_sample_rates,
- sizeof(supported_sample_rates));
- codec->descriptor[0].num_sample_rates =
- sizeof(supported_sample_rates)/sizeof(unsigned int);
- codec->descriptor[0].bit_rate[0] = 320; /* 320kbps */
- codec->descriptor[0].bit_rate[1] = 128;
- codec->descriptor[0].num_bitrates = 2;
- codec->descriptor[0].profiles = 0;
- codec->descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO;
- codec->descriptor[0].formats = 0;
- break;
- case SND_AUDIOCODEC_AAC:
- codec->num_descriptors = 2;
- codec->descriptor[1].max_ch = 2;
- memcpy(codec->descriptor[1].sample_rates,
- supported_sample_rates,
- sizeof(supported_sample_rates));
- codec->descriptor[1].num_sample_rates =
- sizeof(supported_sample_rates)/sizeof(unsigned int);
- codec->descriptor[1].bit_rate[0] = 320; /* 320kbps */
- codec->descriptor[1].bit_rate[1] = 128;
- codec->descriptor[1].num_bitrates = 2;
- codec->descriptor[1].profiles = 0;
- codec->descriptor[1].modes = 0;
- codec->descriptor[1].formats =
- (SND_AUDIOSTREAMFORMAT_MP4ADTS |
- SND_AUDIOSTREAMFORMAT_RAW);
- break;
- case SND_AUDIOCODEC_AC3:
- case SND_AUDIOCODEC_EAC3:
- case SND_AUDIOCODEC_FLAC:
- case SND_AUDIOCODEC_VORBIS:
- case SND_AUDIOCODEC_ALAC:
- case SND_AUDIOCODEC_APE:
- case SND_AUDIOCODEC_DTS:
- case SND_AUDIOCODEC_DSD:
- case SND_AUDIOCODEC_TRUEHD:
- case SND_AUDIOCODEC_IEC61937:
- case SND_AUDIOCODEC_APTX:
- break;
- default:
- pr_err("%s: Unsupported audio codec %d\n",
- __func__, codec->codec);
- return -EINVAL;
- }
- return 0;
- }
- static int msm_compr_set_metadata(struct snd_compr_stream *cstream,
- struct snd_compr_metadata *metadata)
- {
- struct msm_compr_audio *prtd;
- struct audio_client *ac;
- pr_debug("%s\n", __func__);
- if (!metadata || !cstream)
- return -EINVAL;
- prtd = cstream->runtime->private_data;
- if (!prtd || !prtd->audio_client) {
- pr_err("%s: prtd or audio client is NULL\n", __func__);
- return -EINVAL;
- }
- if (((metadata->key == SNDRV_COMPRESS_ENCODER_PADDING) ||
- (metadata->key == SNDRV_COMPRESS_ENCODER_DELAY)) &&
- (prtd->compr_passthr != LEGACY_PCM)) {
- pr_debug("%s: No trailing silence for compress_type[%d]\n",
- __func__, prtd->compr_passthr);
- return 0;
- }
- ac = prtd->audio_client;
- if (metadata->key == SNDRV_COMPRESS_ENCODER_PADDING) {
- pr_debug("%s, got encoder padding %u",
- __func__, metadata->value[0]);
- prtd->gapless_state.trailing_samples_drop = metadata->value[0];
- } else if (metadata->key == SNDRV_COMPRESS_ENCODER_DELAY) {
- pr_debug("%s, got encoder delay %u",
- __func__, metadata->value[0]);
- prtd->gapless_state.initial_samples_drop = metadata->value[0];
- } else if (metadata->key == SNDRV_COMPRESS_RENDER_MODE) {
- return msm_compr_set_render_mode(prtd, metadata->value[0]);
- } else if (metadata->key == SNDRV_COMPRESS_CLK_REC_MODE) {
- return msm_compr_set_clk_rec_mode(ac, metadata->value[0]);
- } else if (metadata->key == SNDRV_COMPRESS_RENDER_WINDOW) {
- return msm_compr_set_render_window(
- ac,
- metadata->value[0],
- metadata->value[1],
- metadata->value[2],
- metadata->value[3]);
- } else if (metadata->key == SNDRV_COMPRESS_START_DELAY) {
- prtd->start_delay_lsw = metadata->value[0];
- prtd->start_delay_msw = metadata->value[1];
- } else if (metadata->key ==
- SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK) {
- return msm_compr_enable_adjust_session_clock(ac,
- metadata->value[0]);
- } else if (metadata->key == SNDRV_COMPRESS_ADJUST_SESSION_CLOCK) {
- return msm_compr_adjust_session_clock(ac,
- metadata->value[0],
- metadata->value[1]);
- }
- return 0;
- }
- static int msm_compr_get_metadata(struct snd_compr_stream *cstream,
- struct snd_compr_metadata *metadata)
- {
- struct msm_compr_audio *prtd;
- struct audio_client *ac;
- int ret = -EINVAL;
- uint64_t ses_time = 0, frames = 0, abs_time = 0;
- uint64_t *val = NULL;
- int64_t av_offset = 0;
- int32_t clock_id = -EINVAL;
- pr_debug("%s\n", __func__);
- if (!metadata || !cstream || !cstream->runtime)
- return ret;
- if (metadata->key != SNDRV_COMPRESS_PATH_DELAY &&
- metadata->key != SNDRV_COMPRESS_DSP_POSITION) {
- pr_err("%s, unsupported key %d\n", __func__, metadata->key);
- return ret;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd || !prtd->audio_client) {
- pr_err("%s: prtd or audio client is NULL\n", __func__);
- return ret;
- }
- switch (metadata->key) {
- case SNDRV_COMPRESS_PATH_DELAY:
- ac = prtd->audio_client;
- ret = q6asm_get_path_delay(prtd->audio_client);
- if (ret) {
- pr_err("%s: get_path_delay failed, ret=%d\n",
- __func__, ret);
- return ret;
- }
- pr_debug("%s, path delay(in us) %u\n", __func__,
- ac->path_delay);
- metadata->value[0] = ac->path_delay;
- break;
- case SNDRV_COMPRESS_DSP_POSITION:
- clock_id = metadata->value[0];
- pr_debug("%s, clock_id %d\n", __func__, clock_id);
- ret = q6asm_get_session_time_v2(prtd->audio_client,
- &ses_time, &abs_time);
- if (ret) {
- pr_err("%s: q6asm_get_session_time_v2 failed, ret=%d\n",
- __func__, ret);
- return ret;
- }
- frames = div64_u64((ses_time * prtd->sample_rate), 1000000);
- ret = avcs_core_query_timer_offset(&av_offset, clock_id);
- if (ret) {
- pr_err("%s: avcs query failed, ret=%d\n",
- __func__, ret);
- return ret;
- }
- val = (uint64_t *) &metadata->value[1];
- val[0] = frames;
- val[1] = abs_time + av_offset;
- pr_debug("%s, vals frames %lld, time %lld, avoff %lld, abst %lld, sess_time %llu sr %d\n",
- __func__, val[0], val[1], av_offset, abs_time,
- ses_time, prtd->sample_rate);
- break;
- default:
- pr_err("%s, unsupported key %d\n", __func__, metadata->key);
- break;
- }
- return ret;
- }
- #if IS_ENABLED(CONFIG_AUDIO_QGKI)
- static int msm_compr_set_next_track_param(struct snd_compr_stream *cstream,
- union snd_codec_options *codec_options)
- {
- struct msm_compr_audio *prtd;
- struct audio_client *ac;
- int ret = 0;
- if (!codec_options || !cstream)
- return -EINVAL;
- prtd = cstream->runtime->private_data;
- if (!prtd || !prtd->audio_client) {
- pr_err("%s: prtd or audio client is NULL\n", __func__);
- return -EINVAL;
- }
- ac = prtd->audio_client;
- pr_debug("%s: got codec options for codec type %u",
- __func__, prtd->codec);
- switch (prtd->codec) {
- case FORMAT_WMA_V9:
- case FORMAT_WMA_V10PRO:
- case FORMAT_FLAC:
- case FORMAT_VORBIS:
- case FORMAT_ALAC:
- case FORMAT_APE:
- case FORMAT_AMRNB:
- case FORMAT_AMRWB:
- case FORMAT_AMR_WB_PLUS:
- memcpy(&(prtd->gapless_state.codec_options),
- codec_options,
- sizeof(union snd_codec_options));
- ret = msm_compr_send_media_format_block(cstream,
- ac->stream_id, true);
- if (ret < 0) {
- pr_err("%s: failed to send media format block\n",
- __func__);
- }
- break;
- default:
- pr_debug("%s: Ignore sending CMD Format block\n",
- __func__);
- break;
- }
- return ret;
- }
- #endif /* CONFIG_AUDIO_QGKI */
- static int msm_compr_volume_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- uint32_t *volume = NULL;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- volume = pdata->volume[fe_id];
- volume[0] = ucontrol->value.integer.value[0];
- volume[1] = ucontrol->value.integer.value[1];
- pr_debug("%s: fe_id %lu left_vol %d right_vol %d\n",
- __func__, fe_id, volume[0], volume[1]);
- if (cstream)
- msm_compr_set_volume(cstream, volume[0], volume[1]);
- return 0;
- }
- static int msm_compr_volume_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata =
- snd_soc_component_get_drvdata(comp);
- uint32_t *volume = NULL;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
- return -EINVAL;
- }
- volume = pdata->volume[fe_id];
- pr_debug("%s: fe_id %lu\n", __func__, fe_id);
- ucontrol->value.integer.value[0] = volume[0];
- ucontrol->value.integer.value[1] = volume[1];
- return 0;
- }
- static int msm_compr_audio_effects_config_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_compr_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd = NULL;
- long *values = &(ucontrol->value.integer.value[0]);
- int ret = 0;
- int effects_module;
- pr_debug("%s\n", __func__);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_err("%s: stream or effects inactive\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set audio effects\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s: No effects for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- goto done;
- }
- pr_debug("%s: Effects supported for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- effects_module = *values++;
- switch (effects_module) {
- case VIRTUALIZER_MODULE:
- pr_debug("%s: VIRTUALIZER_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_virtualizer_handler(
- prtd->audio_client,
- &(audio_effects->virtualizer),
- values);
- break;
- case REVERB_MODULE:
- pr_debug("%s: REVERB_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_reverb_handler(prtd->audio_client,
- &(audio_effects->reverb),
- values);
- break;
- case BASS_BOOST_MODULE:
- pr_debug("%s: BASS_BOOST_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_bass_boost_handler(prtd->audio_client,
- &(audio_effects->bass_boost),
- values);
- break;
- case PBE_MODULE:
- pr_debug("%s: PBE_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_pbe_handler(prtd->audio_client,
- &(audio_effects->pbe),
- values);
- break;
- case EQ_MODULE:
- pr_debug("%s: EQ_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_popless_eq_handler(prtd->audio_client,
- &(audio_effects->equalizer),
- values);
- break;
- case SOFT_VOLUME_MODULE:
- pr_debug("%s: SOFT_VOLUME_MODULE\n", __func__);
- break;
- case SOFT_VOLUME2_MODULE:
- pr_debug("%s: SOFT_VOLUME2_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- msm_audio_effects_volume_handler_v2(prtd->audio_client,
- &(audio_effects->volume),
- values, SOFT_VOLUME_INSTANCE_2);
- break;
- default:
- pr_err("%s Invalid effects config module\n", __func__);
- ret = -EINVAL;
- }
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_audio_effects_config_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_compr_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- int ret = 0;
- struct msm_compr_audio *prtd = NULL;
- pr_debug("%s\n", __func__);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_debug("%s: stream or effects inactive\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set audio effects\n", __func__);
- ret = -EINVAL;
- }
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_query_audio_effect_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_compr_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd = NULL;
- int ret = 0;
- long *values = &(ucontrol->value.integer.value[0]);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_err("%s: stream or effects inactive\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set audio effects\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_err("%s: No effects for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- ret = -EPERM;
- goto done;
- }
- audio_effects->query.mod_id = (u32)*values++;
- audio_effects->query.parm_id = (u32)*values++;
- audio_effects->query.size = (u32)*values++;
- audio_effects->query.offset = (u32)*values++;
- audio_effects->query.device = (u32)*values++;
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_query_audio_effect_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_compr_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd = NULL;
- int ret = 0;
- long *values = &(ucontrol->value.integer.value[0]);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_debug("%s: stream or effects inactive\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set audio effects\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- values[0] = (long)audio_effects->query.mod_id;
- values[1] = (long)audio_effects->query.parm_id;
- values[2] = (long)audio_effects->query.size;
- values[3] = (long)audio_effects->query.offset;
- values[4] = (long)audio_effects->query.device;
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_send_dec_params(struct snd_compr_stream *cstream,
- struct msm_compr_dec_params *dec_params,
- int stream_id)
- {
- int rc = 0;
- struct msm_compr_audio *prtd = NULL;
- struct snd_dec_ddp *ddp = &dec_params->ddp_params;
- if (!cstream || !dec_params) {
- pr_err("%s: stream or dec_params inactive\n", __func__);
- rc = -EINVAL;
- goto end;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set dec_params\n", __func__);
- rc = -EINVAL;
- goto end;
- }
- switch (prtd->codec) {
- case FORMAT_MP3:
- case FORMAT_MPEG4_AAC:
- case FORMAT_TRUEHD:
- case FORMAT_IEC61937:
- case FORMAT_APTX:
- pr_debug("%s: no runtime parameters for codec: %d\n", __func__,
- prtd->codec);
- break;
- case FORMAT_AC3:
- case FORMAT_EAC3:
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s: No DDP param for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- break;
- }
- rc = msm_compr_send_ddp_cfg(prtd->audio_client, ddp, stream_id);
- if (rc < 0)
- pr_err("%s: DDP CMD CFG failed %d\n", __func__, rc);
- break;
- default:
- break;
- }
- end:
- return rc;
- }
- static int msm_compr_dec_params_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_compr_dec_params *dec_params = NULL;
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd = NULL;
- long *values = &(ucontrol->value.integer.value[0]);
- int rc = 0;
- pr_debug("%s\n", __func__);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- dec_params = pdata->dec_params[fe_id];
- if (!cstream || !dec_params) {
- pr_err("%s: stream or dec_params inactive\n", __func__);
- return -EINVAL;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set dec_params\n", __func__);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- switch (prtd->codec) {
- case FORMAT_MP3:
- case FORMAT_MPEG4_AAC:
- case FORMAT_FLAC:
- case FORMAT_VORBIS:
- case FORMAT_ALAC:
- case FORMAT_APE:
- case FORMAT_DTS:
- case FORMAT_DSD:
- case FORMAT_TRUEHD:
- case FORMAT_IEC61937:
- case FORMAT_APTX:
- case FORMAT_AMRNB:
- case FORMAT_AMRWB:
- case FORMAT_AMR_WB_PLUS:
- pr_debug("%s: no runtime parameters for codec: %d\n", __func__,
- prtd->codec);
- break;
- case FORMAT_AC3:
- case FORMAT_EAC3: {
- struct snd_dec_ddp *ddp = &dec_params->ddp_params;
- int cnt;
- if (prtd->compr_passthr != LEGACY_PCM) {
- pr_debug("%s: No DDP param for compr_type[%d]\n",
- __func__, prtd->compr_passthr);
- break;
- }
- ddp->params_length = (*values++);
- if (ddp->params_length > DDP_DEC_MAX_NUM_PARAM) {
- pr_err("%s: invalid num of params:: %d\n", __func__,
- ddp->params_length);
- rc = -EINVAL;
- goto end;
- }
- for (cnt = 0; cnt < ddp->params_length; cnt++) {
- ddp->params_id[cnt] = *values++;
- ddp->params_value[cnt] = *values++;
- }
- prtd = cstream->runtime->private_data;
- if (prtd && prtd->audio_client)
- rc = msm_compr_send_dec_params(cstream, dec_params,
- prtd->audio_client->stream_id);
- break;
- }
- default:
- break;
- }
- end:
- pr_debug("%s: ret %d\n", __func__, rc);
- mutex_unlock(&pdata->lock);
- return rc;
- }
- static int msm_compr_dec_params_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- /* dummy function */
- return 0;
- }
- static int msm_compr_playback_app_type_cfg_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_RX;
- int be_id = ucontrol->value.integer.value[3];
- struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
- int ret = 0;
- cfg_data.app_type = ucontrol->value.integer.value[0];
- cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
- if (ucontrol->value.integer.value[2] != 0)
- cfg_data.sample_rate = ucontrol->value.integer.value[2];
- pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
- be_id, &cfg_data);
- if (ret < 0)
- pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_compr_playback_app_type_cfg_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_RX;
- int be_id = 0;
- struct msm_pcm_stream_app_type_cfg cfg_data = {0};
- int ret = 0;
- ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
- &be_id, &cfg_data);
- if (ret < 0) {
- pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
- __func__, ret);
- goto done;
- }
- ucontrol->value.integer.value[0] = cfg_data.app_type;
- ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
- ucontrol->value.integer.value[2] = cfg_data.sample_rate;
- ucontrol->value.integer.value[3] = be_id;
- pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- done:
- return ret;
- }
- static int msm_compr_capture_app_type_cfg_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_TX;
- int be_id = ucontrol->value.integer.value[3];
- struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
- int ret = 0;
- cfg_data.app_type = ucontrol->value.integer.value[0];
- cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
- if (ucontrol->value.integer.value[2] != 0)
- cfg_data.sample_rate = ucontrol->value.integer.value[2];
- pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
- be_id, &cfg_data);
- if (ret < 0)
- pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_compr_capture_app_type_cfg_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_TX;
- int be_id = 0;
- struct msm_pcm_stream_app_type_cfg cfg_data = {0};
- int ret = 0;
- ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
- &be_id, &cfg_data);
- if (ret < 0) {
- pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
- __func__, ret);
- goto done;
- }
- ucontrol->value.integer.value[0] = cfg_data.app_type;
- ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
- ucontrol->value.integer.value[2] = cfg_data.sample_rate;
- ucontrol->value.integer.value[3] = be_id;
- pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- done:
- return ret;
- }
- static int msm_compr_channel_map_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- u64 fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- int rc = 0, i;
- struct msm_pcm_channel_mixer *chmixer_pspd = NULL;
- pr_debug("%s: fe_id- %llu\n", __func__, fe_id);
- if (fe_id >= MSM_FRONTEND_DAI_MM_SIZE) {
- pr_err("%s Received out of bounds fe_id %llu\n",
- __func__, fe_id);
- rc = -EINVAL;
- goto end;
- }
- if (pdata->ch_map[fe_id]) {
- pdata->ch_map[fe_id]->set_ch_map = true;
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- pdata->ch_map[fe_id]->channel_map[i] =
- (char)(ucontrol->value.integer.value[i]);
- /* update chmixer_pspd chmap cached with routing driver as well */
- chmixer_pspd = pdata->chmixer_pspd[fe_id];
- if (chmixer_pspd && chmixer_pspd->enable) {
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->in_ch_map[i] =
- pdata->ch_map[fe_id]->channel_map[i];
- chmixer_pspd->override_in_ch_map = true;
- msm_pcm_routing_set_channel_mixer_cfg(fe_id,
- SESSION_TYPE_RX, chmixer_pspd);
- }
- } else {
- pr_debug("%s: no memory for ch_map, default will be set\n",
- __func__);
- }
- end:
- pr_debug("%s: ret %d\n", __func__, rc);
- return rc;
- }
- static int msm_compr_channel_map_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- u64 fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- int rc = 0, i;
- pr_debug("%s: fe_id- %llu\n", __func__, fe_id);
- if (fe_id >= MSM_FRONTEND_DAI_MM_SIZE) {
- pr_err("%s: Received out of bounds fe_id %llu\n",
- __func__, fe_id);
- rc = -EINVAL;
- goto end;
- }
- if (pdata->ch_map[fe_id]) {
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- ucontrol->value.integer.value[i] =
- pdata->ch_map[fe_id]->channel_map[i];
- }
- end:
- pr_debug("%s: ret %d\n", __func__, rc);
- return rc;
- }
- static int msm_compr_adsp_stream_cmd_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd;
- int ret = 0;
- struct msm_adsp_event_data *event_data = NULL;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received invalid fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null\n", __func__);
- return -EINVAL;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null\n", __func__);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- event_data = (struct msm_adsp_event_data *)ucontrol->value.bytes.data;
- if ((event_data->event_type < ADSP_STREAM_PP_EVENT) ||
- (event_data->event_type >= ADSP_STREAM_EVENT_MAX)) {
- pr_err("%s: invalid event_type=%d",
- __func__, event_data->event_type);
- ret = -EINVAL;
- goto done;
- }
- if (event_data->payload_len > sizeof(ucontrol->value.bytes.data)
- - sizeof(struct msm_adsp_event_data)) {
- pr_err("%s param length=%d exceeds limit",
- __func__, event_data->payload_len);
- ret = -EINVAL;
- goto done;
- }
- ret = q6asm_send_stream_cmd(prtd->audio_client, event_data);
- if (ret < 0)
- pr_err("%s: failed to send stream event cmd, err = %d\n",
- __func__, ret);
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_ion_fd_map_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd;
- int fd;
- int ret = 0;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds invalid fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null\n", __func__);
- return -EINVAL;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null\n", __func__);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- memcpy(&fd, ucontrol->value.bytes.data, sizeof(fd));
- ret = q6asm_send_ion_fd(prtd->audio_client, fd);
- if (ret < 0)
- pr_err("%s: failed to register ion fd\n", __func__);
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_rtic_event_ack_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd;
- int ret = 0;
- int param_length = 0;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received invalid fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- mutex_lock(&pdata->lock);
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- memcpy(¶m_length, ucontrol->value.bytes.data,
- sizeof(param_length));
- if ((param_length + sizeof(param_length))
- >= sizeof(ucontrol->value.bytes.data)) {
- pr_err("%s param length=%d exceeds limit",
- __func__, param_length);
- ret = -EINVAL;
- goto done;
- }
- ret = q6asm_send_rtic_event_ack(prtd->audio_client,
- ucontrol->value.bytes.data + sizeof(param_length),
- param_length);
- if (ret < 0)
- pr_err("%s: failed to send rtic event ack, err = %d\n",
- __func__, ret);
- done:
- mutex_unlock(&pdata->lock);
- return ret;
- }
- static int msm_compr_gapless_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- pdata->use_dsp_gapless_mode = ucontrol->value.integer.value[0];
- pr_debug("%s: value: %ld\n", __func__,
- ucontrol->value.integer.value[0]);
- return 0;
- }
- static int msm_compr_gapless_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata =
- snd_soc_component_get_drvdata(comp);
- pr_debug("%s:gapless mode %d\n", __func__, pdata->use_dsp_gapless_mode);
- ucontrol->value.integer.value[0] = pdata->use_dsp_gapless_mode;
- return 0;
- }
- static const struct snd_kcontrol_new msm_compr_gapless_controls[] = {
- SOC_SINGLE_EXT("Compress Gapless Playback",
- 0, 0, 1, 0,
- msm_compr_gapless_get,
- msm_compr_gapless_put),
- };
- static int msm_compr_probe(struct snd_soc_component *component)
- {
- struct msm_compr_pdata *pdata;
- int i;
- int rc;
- const char *qdsp_version;
- pr_debug("%s\n", __func__);
- pdata = (struct msm_compr_pdata *) dev_get_drvdata(component->dev);
- if (!pdata) {
- pr_err("%s platform data not set\n", __func__);
- return -EINVAL;
- }
- snd_soc_component_set_drvdata(component, pdata);
- for (i = 0; i < MSM_FRONTEND_DAI_MAX; i++) {
- pdata->volume[i][0] = COMPRESSED_LR_VOL_MAX_STEPS;
- pdata->volume[i][1] = COMPRESSED_LR_VOL_MAX_STEPS;
- pdata->audio_effects[i] = NULL;
- pdata->dec_params[i] = NULL;
- pdata->cstream[i] = NULL;
- pdata->ch_map[i] = NULL;
- pdata->is_in_use[i] = false;
- }
- snd_soc_add_component_controls(component, msm_compr_gapless_controls,
- ARRAY_SIZE(msm_compr_gapless_controls));
- rc = of_property_read_string(component->dev->of_node,
- "qcom,adsp-version", &qdsp_version);
- if (!rc) {
- if (!strcmp(qdsp_version, "MDSP 1.2"))
- pdata->use_legacy_api = true;
- else
- pdata->use_legacy_api = false;
- } else
- pdata->use_legacy_api = false;
- pr_debug("%s: use legacy api %d\n", __func__, pdata->use_legacy_api);
- /*
- * use_dsp_gapless_mode part of platform data(pdata) is updated from HAL
- * through a mixer control before compress driver is opened. The mixer
- * control is used to decide if dsp gapless mode needs to be enabled.
- * Gapless is disabled by default.
- */
- pdata->use_dsp_gapless_mode = false;
- return 0;
- }
- static int msm_compr_volume_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 2;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = COMPRESSED_LR_VOL_MAX_STEPS;
- return 0;
- }
- static int msm_compr_audio_effects_config_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = MAX_PP_PARAMS_SZ;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_compr_query_audio_effect_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 128;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_compr_dec_params_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 128;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_compr_app_type_cfg_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 5;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_compr_channel_map_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = PCM_FORMAT_MAX_NUM_CHANNEL_V8;
- uinfo->value.integer.min = 0;
- /* See PCM_MAX_CHANNEL_MAP in apr_audio-v2.h */
- uinfo->value.integer.max = PCM_MAX_CHANNEL_MAP;
- return 0;
- }
- static int msm_compr_add_volume_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Compress Playback";
- const char *deviceNo = "NN";
- const char *suffix = "Volume";
- char *mixer_str = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_volume_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
- SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_volume_info,
- .tlv.p = msm_compr_vol_gain,
- .get = msm_compr_volume_get,
- .put = msm_compr_volume_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return 0;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1 +
- strlen(suffix) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- pr_err("failed to allocate mixer ctrl str of len %d", ctl_len);
- return 0;
- }
- snprintf(mixer_str, ctl_len, "%s %d %s", mixer_ctl_name,
- rtd->pcm->device, suffix);
- fe_volume_control[0].name = mixer_str;
- fe_volume_control[0].private_value = rtd->dai_link->id;
- pr_debug("Registering new mixer ctl %s", mixer_str);
- snd_soc_add_component_controls(component, fe_volume_control,
- ARRAY_SIZE(fe_volume_control));
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_audio_effects_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Audio Effects Config";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_audio_effects_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_audio_effects_config_info,
- .get = msm_compr_audio_effects_config_get,
- .put = msm_compr_audio_effects_config_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return 0;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return 0;
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_audio_effects_config_control[0].name = mixer_str;
- fe_audio_effects_config_control[0].private_value = rtd->dai_link->id;
- pr_debug("Registering new mixer ctl %s\n", mixer_str);
- snd_soc_add_component_controls(component,
- fe_audio_effects_config_control,
- ARRAY_SIZE(fe_audio_effects_config_control));
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_query_audio_effect_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Query Audio Effect Param";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_query_audio_effect_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_query_audio_effect_info,
- .get = msm_compr_query_audio_effect_get,
- .put = msm_compr_query_audio_effect_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return 0;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- pr_err("failed to allocate mixer ctrl str of len %d", ctl_len);
- return 0;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_query_audio_effect_control[0].name = mixer_str;
- fe_query_audio_effect_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: registering new mixer ctl %s\n", __func__, mixer_str);
- snd_soc_add_component_controls(component,
- fe_query_audio_effect_control,
- ARRAY_SIZE(fe_query_audio_effect_control));
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_audio_adsp_stream_cmd_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = DSP_STREAM_CMD;
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_audio_adsp_stream_cmd_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_compr_adsp_stream_cmd_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return -ENOMEM;
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_audio_adsp_stream_cmd_config_control[0].name = mixer_str;
- fe_audio_adsp_stream_cmd_config_control[0].private_value =
- rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_audio_adsp_stream_cmd_config_control,
- ARRAY_SIZE(fe_audio_adsp_stream_cmd_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s. err = %d\n",
- __func__, mixer_str, ret);
- kfree(mixer_str);
- return ret;
- }
- static int msm_compr_add_audio_adsp_stream_callback_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol *kctl;
- struct snd_kcontrol_new fe_audio_adsp_callback_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_callback_info,
- .get = msm_adsp_stream_callback_get,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_audio_adsp_callback_config_control[0].name = mixer_str;
- fe_audio_adsp_callback_config_control[0].private_value =
- rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_audio_adsp_callback_config_control,
- ARRAY_SIZE(fe_audio_adsp_callback_config_control));
- if (ret < 0) {
- pr_err("%s: failed to add ctl %s. err = %d\n",
- __func__, mixer_str, ret);
- ret = -EINVAL;
- goto free_mixer_str;
- }
- kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
- if (!kctl) {
- pr_err("%s: failed to get kctl %s.\n", __func__, mixer_str);
- ret = -EINVAL;
- goto free_mixer_str;
- }
- kctl->private_data = NULL;
- free_mixer_str:
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_compr_add_dec_runtime_params_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Audio Stream";
- const char *deviceNo = "NN";
- const char *suffix = "Dec Params";
- char *mixer_str = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_dec_params_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_dec_params_info,
- .get = msm_compr_dec_params_get,
- .put = msm_compr_dec_params_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return 0;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1 +
- strlen(suffix) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return 0;
- snprintf(mixer_str, ctl_len, "%s %d %s", mixer_ctl_name,
- rtd->pcm->device, suffix);
- fe_dec_params_control[0].name = mixer_str;
- fe_dec_params_control[0].private_value = rtd->dai_link->id;
- pr_debug("Registering new mixer ctl %s", mixer_str);
- snd_soc_add_component_controls(component,
- fe_dec_params_control,
- ARRAY_SIZE(fe_dec_params_control));
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_app_type_cfg_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *playback_mixer_ctl_name = "Audio Stream";
- const char *capture_mixer_ctl_name = "Audio Stream Capture";
- const char *deviceNo = "NN";
- const char *suffix = "App Type Cfg";
- char *mixer_str = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_app_type_cfg_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_app_type_cfg_info,
- .put = msm_compr_playback_app_type_cfg_put,
- .get = msm_compr_playback_app_type_cfg_get,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return 0;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return 0;
- }
- pr_debug("%s: added new compr FE ctl with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK)
- ctl_len = strlen(playback_mixer_ctl_name) + 1 + strlen(deviceNo)
- + 1 + strlen(suffix) + 1;
- else
- ctl_len = strlen(capture_mixer_ctl_name) + 1 + strlen(deviceNo)
- + 1 + strlen(suffix) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return 0;
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK)
- snprintf(mixer_str, ctl_len, "%s %d %s",
- playback_mixer_ctl_name, rtd->pcm->device, suffix);
- else
- snprintf(mixer_str, ctl_len, "%s %d %s",
- capture_mixer_ctl_name, rtd->pcm->device, suffix);
- fe_app_type_cfg_control[0].name = mixer_str;
- fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
- fe_app_type_cfg_control[0].put =
- msm_compr_playback_app_type_cfg_put;
- fe_app_type_cfg_control[0].get =
- msm_compr_playback_app_type_cfg_get;
- } else {
- fe_app_type_cfg_control[0].put =
- msm_compr_capture_app_type_cfg_put;
- fe_app_type_cfg_control[0].get =
- msm_compr_capture_app_type_cfg_get;
- }
- pr_debug("Registering new mixer ctl %s", mixer_str);
- snd_soc_add_component_controls(component,
- fe_app_type_cfg_control,
- ARRAY_SIZE(fe_app_type_cfg_control));
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_channel_map_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Playback Channel Map";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- struct msm_compr_pdata *pdata = NULL;
- int ctl_len;
- struct snd_kcontrol_new fe_channel_map_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_channel_map_info,
- .get = msm_compr_channel_map_get,
- .put = msm_compr_channel_map_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s: NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
- __func__, rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return -ENOMEM;
- snprintf(mixer_str, ctl_len, "%s%d", mixer_ctl_name, rtd->pcm->device);
- fe_channel_map_control[0].name = mixer_str;
- fe_channel_map_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- snd_soc_add_component_controls(component,
- fe_channel_map_control,
- ARRAY_SIZE(fe_channel_map_control));
- pdata = snd_soc_component_get_drvdata(component);
- pdata->ch_map[rtd->dai_link->id] =
- kzalloc(sizeof(struct msm_compr_ch_map), GFP_KERNEL);
- if (!pdata->ch_map[rtd->dai_link->id]) {
- pr_err("%s: Could not allocate memory for channel map\n",
- __func__);
- kfree(mixer_str);
- return -ENOMEM;
- }
- kfree(mixer_str);
- return 0;
- }
- static int msm_compr_add_io_fd_cmd_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Playback ION FD";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_ion_fd_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_compr_ion_fd_map_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return -ENOMEM;
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_ion_fd_config_control[0].name = mixer_str;
- fe_ion_fd_config_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_ion_fd_config_control,
- ARRAY_SIZE(fe_ion_fd_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
- kfree(mixer_str);
- return ret;
- }
- static int msm_compr_add_event_ack_cmd_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Playback Event Ack";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_event_ack_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_compr_rtic_event_ack_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str)
- return -ENOMEM;
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_event_ack_config_control[0].name = mixer_str;
- fe_event_ack_config_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_event_ack_config_control,
- ARRAY_SIZE(fe_event_ack_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
- kfree(mixer_str);
- return ret;
- }
- static struct msm_pcm_channel_mixer *msm_compr_get_chmixer(
- struct msm_compr_pdata *pdata, u64 fe_id)
- {
- if (!pdata) {
- pr_err("%s: missing pdata\n", __func__);
- return NULL;
- }
- if (fe_id >= MSM_FRONTEND_DAI_MM_SIZE) {
- pr_err("%s: invalid FE %llu\n", __func__, fe_id);
- return NULL;
- }
- return pdata->chmixer_pspd[fe_id];
- }
- static int msm_compr_channel_mixer_cfg_ctl_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int session_type = (kcontrol->private_value >> 8) & 0xFF;
- int ret = 0, i = 0, stream_id = 0, be_id = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_compr_audio *prtd = NULL;
- struct msm_pcm_channel_mixer *chmixer_pspd = NULL;
- u8 asm_ch_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8] = {0};
- bool reset_override_out_ch_map = false;
- bool reset_override_in_ch_map = false;
- if ((session_type != SESSION_TYPE_TX) &&
- (session_type != SESSION_TYPE_RX)) {
- pr_err("%s: invalid session type %d\n", __func__, session_type);
- return -EINVAL;
- }
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- chmixer_pspd->enable = ucontrol->value.integer.value[0];
- chmixer_pspd->rule = ucontrol->value.integer.value[1];
- chmixer_pspd->input_channel = ucontrol->value.integer.value[2];
- chmixer_pspd->output_channel = ucontrol->value.integer.value[3];
- chmixer_pspd->port_idx = ucontrol->value.integer.value[4];
- if (chmixer_pspd->input_channel < 0 ||
- chmixer_pspd->input_channel > PCM_FORMAT_MAX_NUM_CHANNEL_V8 ||
- chmixer_pspd->output_channel < 0 ||
- chmixer_pspd->output_channel > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: Invalid channels, in %d, out %d\n",
- __func__, chmixer_pspd->input_channel,
- chmixer_pspd->output_channel);
- return -EINVAL;
- }
- if (chmixer_pspd->enable) {
- if (session_type == SESSION_TYPE_RX &&
- !chmixer_pspd->override_in_ch_map) {
- if (pdata->ch_map[fe_id]->set_ch_map) {
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->in_ch_map[i] =
- pdata->ch_map[fe_id]->channel_map[i];
- } else {
- q6asm_map_channels(asm_ch_map,
- chmixer_pspd->input_channel, false);
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->in_ch_map[i] = asm_ch_map[i];
- }
- chmixer_pspd->override_in_ch_map = true;
- reset_override_in_ch_map = true;
- } else if (session_type == SESSION_TYPE_TX &&
- !chmixer_pspd->override_out_ch_map) {
- if (pdata->ch_map[fe_id]->set_ch_map) {
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->out_ch_map[i] =
- pdata->ch_map[fe_id]->channel_map[i];
- } else {
- q6asm_map_channels(asm_ch_map,
- chmixer_pspd->output_channel, false);
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->out_ch_map[i] = asm_ch_map[i];
- }
- chmixer_pspd->override_out_ch_map = true;
- reset_override_out_ch_map = true;
- }
- } else {
- chmixer_pspd->override_out_ch_map = false;
- chmixer_pspd->override_in_ch_map = false;
- }
- /* cache value and take effect during adm_open stage */
- msm_pcm_routing_set_channel_mixer_cfg(fe_id,
- session_type,
- chmixer_pspd);
- cstream = pdata->cstream[fe_id];
- if (chmixer_pspd->enable && cstream && cstream->runtime) {
- prtd = cstream->runtime->private_data;
- if (prtd && prtd->audio_client) {
- stream_id = prtd->audio_client->session;
- be_id = chmixer_pspd->port_idx;
- msm_pcm_routing_set_channel_mixer_runtime(be_id,
- stream_id, session_type, chmixer_pspd);
- }
- }
- if (reset_override_out_ch_map)
- chmixer_pspd->override_out_ch_map = false;
- if (reset_override_in_ch_map)
- chmixer_pspd->override_in_ch_map = false;
- return ret;
- }
- static int msm_compr_channel_mixer_cfg_ctl_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- ucontrol->value.integer.value[0] = chmixer_pspd->enable;
- ucontrol->value.integer.value[1] = chmixer_pspd->rule;
- ucontrol->value.integer.value[2] = chmixer_pspd->input_channel;
- ucontrol->value.integer.value[3] = chmixer_pspd->output_channel;
- ucontrol->value.integer.value[4] = chmixer_pspd->port_idx;
- return 0;
- }
- static int msm_compr_channel_mixer_output_map_ctl_put(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int i = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- chmixer_pspd->override_out_ch_map = true;
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->out_ch_map[i] =
- ucontrol->value.integer.value[i];
- return 0;
- }
- static int msm_compr_channel_mixer_output_map_ctl_get(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int i = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- ucontrol->value.integer.value[i] =
- chmixer_pspd->out_ch_map[i];
- return 0;
- }
- static int msm_compr_channel_mixer_input_map_ctl_put(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int i = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- chmixer_pspd->override_in_ch_map = true;
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->in_ch_map[i] = ucontrol->value.integer.value[i];
- return 0;
- }
- static int msm_compr_channel_mixer_input_map_ctl_get(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int i = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- ucontrol->value.integer.value[i] =
- chmixer_pspd->in_ch_map[i];
- return 0;
- }
- static int msm_compr_channel_mixer_weight_ctl_put(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int channel = (kcontrol->private_value >> 16) & 0xFF;
- int i = 0;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_pcm_channel_mixer *chmixer_pspd;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- if (channel <= 0 || channel > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: invalid channel number %d\n", __func__, channel);
- return -EINVAL;
- }
- channel--;
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- chmixer_pspd->channel_weight[channel][i] =
- ucontrol->value.integer.value[i];
- return 0;
- }
- static int msm_compr_channel_mixer_weight_ctl_get(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value & 0xFF;
- int channel = (kcontrol->private_value >> 16) & 0xFF;
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(comp);
- int i = 0;
- struct msm_pcm_channel_mixer *chmixer_pspd;
- if (channel <= 0 || channel > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: invalid channel number %d\n", __func__, channel);
- return -EINVAL;
- }
- channel--;
- chmixer_pspd = msm_compr_get_chmixer(pdata, fe_id);
- if (!chmixer_pspd) {
- pr_err("%s: invalid chmixer_pspd in pdata", __func__);
- return -EINVAL;
- }
- for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
- ucontrol->value.integer.value[i] =
- chmixer_pspd->channel_weight[channel][i];
- return 0;
- }
- static int msm_compr_add_platform_controls(struct snd_kcontrol_new *kctl,
- struct snd_soc_pcm_runtime *rtd, const char *name_prefix,
- const char *name_suffix, int session_type, int channels)
- {
- int ret = -EINVAL;
- char *mixer_name = NULL;
- const char *deviceNo = "NN";
- const char *channelNo = "NN";
- int ctl_len = 0;
- struct snd_soc_component *component = NULL;
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(name_prefix) + 1 + strlen(deviceNo) + 1 +
- strlen(channelNo) + 1 + strlen(name_suffix) + 1;
- mixer_name = kzalloc(ctl_len, GFP_KERNEL);
- if (mixer_name == NULL)
- return -ENOMEM;
- if (channels >= 0) {
- snprintf(mixer_name, ctl_len, "%s %d %s %d",
- name_prefix, rtd->pcm->device, name_suffix, channels);
- kctl->private_value = (rtd->dai_link->id) | (channels << 16);
- } else {
- snprintf(mixer_name, ctl_len, "%s %d %s",
- name_prefix, rtd->pcm->device, name_suffix);
- kctl->private_value = (rtd->dai_link->id);
- }
- if (session_type != INVALID_SESSION)
- kctl->private_value |= (session_type << 8);
- kctl->name = mixer_name;
- ret = snd_soc_add_component_controls(component, kctl, 1);
- kfree(mixer_name);
- return ret;
- }
- static int msm_compr_channel_mixer_output_map_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = PCM_FORMAT_MAX_NUM_CHANNEL_V8;
- /* Valid channel map value ranges from 1 to 64 */
- uinfo->value.integer.min = 1;
- uinfo->value.integer.max = 64;
- return 0;
- }
- static int msm_compr_add_channel_mixer_output_map_controls(
- struct snd_soc_pcm_runtime *rtd)
- {
- const char *playback_mixer_ctl_name = "AudStr";
- const char *capture_mixer_ctl_name = "AudStr Capture";
- const char *suffix = "ChMixer Output Map";
- const char *mixer_ctl_name = NULL;
- int ret = 0, session_type = INVALID_SESSION, channel = -1;
- struct snd_kcontrol_new channel_mixer_output_map_control = {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_channel_mixer_output_map_info,
- .put = msm_compr_channel_mixer_output_map_ctl_put,
- .get = msm_compr_channel_mixer_output_map_ctl_get,
- .private_value = 0,
- };
- mixer_ctl_name = rtd->compr->direction == SND_COMPRESS_PLAYBACK ?
- playback_mixer_ctl_name : capture_mixer_ctl_name ;
- ret = msm_compr_add_platform_controls(&channel_mixer_output_map_control,
- rtd, mixer_ctl_name, suffix, session_type, channel);
- if (ret < 0) {
- pr_err("%s: failed add platform ctl, err = %d\n",
- __func__, ret);
- }
- return ret;
- }
- static int msm_compr_channel_mixer_input_map_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = PCM_FORMAT_MAX_NUM_CHANNEL_V8;
- /* Valid channel map value ranges from 1 to 64 */
- uinfo->value.integer.min = 1;
- uinfo->value.integer.max = 64;
- return 0;
- }
- static int msm_compr_add_channel_mixer_input_map_controls(
- struct snd_soc_pcm_runtime *rtd)
- {
- const char *playback_mixer_ctl_name = "AudStr";
- const char *capture_mixer_ctl_name = "AudStr Capture";
- const char *suffix = "ChMixer Input Map";
- const char *mixer_ctl_name = NULL;
- int ret = 0, session_type = INVALID_SESSION, channel = -1;
- struct snd_kcontrol_new channel_mixer_input_map_control = {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_channel_mixer_input_map_info,
- .put = msm_compr_channel_mixer_input_map_ctl_put,
- .get = msm_compr_channel_mixer_input_map_ctl_get,
- .private_value = 0,
- };
- mixer_ctl_name = rtd->compr->direction == SND_COMPRESS_PLAYBACK ?
- playback_mixer_ctl_name : capture_mixer_ctl_name ;
- ret = msm_compr_add_platform_controls(&channel_mixer_input_map_control,
- rtd, mixer_ctl_name, suffix, session_type, channel);
- if (ret < 0) {
- pr_err("%s: failed add platform ctl, err = %d\n",
- __func__, ret);
- }
- return ret;
- }
- static int msm_compr_channel_mixer_cfg_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- /* five int values: enable, rule, in_channels, out_channels and port_id */
- uinfo->count = 5;
- /* Valid range is all positive values to support above controls */
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = INT_MAX;
- return 0;
- }
- static int msm_compr_add_channel_mixer_cfg_controls(
- struct snd_soc_pcm_runtime *rtd)
- {
- const char *playback_mixer_ctl_name = "AudStr";
- const char *capture_mixer_ctl_name = "AudStr Capture";
- const char *suffix = "ChMixer Cfg";
- const char *mixer_ctl_name = NULL;
- int ret = 0, session_type = INVALID_SESSION, channel = -1;
- struct snd_kcontrol_new channel_mixer_cfg_control = {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_channel_mixer_cfg_info,
- .put = msm_compr_channel_mixer_cfg_ctl_put,
- .get = msm_compr_channel_mixer_cfg_ctl_get,
- .private_value = 0,
- };
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
- session_type = SESSION_TYPE_RX;
- mixer_ctl_name = playback_mixer_ctl_name;
- } else {
- session_type = SESSION_TYPE_TX;
- mixer_ctl_name = capture_mixer_ctl_name;
- }
- ret = msm_compr_add_platform_controls(&channel_mixer_cfg_control,
- rtd, mixer_ctl_name, suffix, session_type, channel);
- if (ret < 0) {
- pr_err("%s: failed add platform ctl, err = %d\n",
- __func__, ret);
- }
- return ret;
- }
- static int msm_compr_channel_mixer_weight_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = PCM_FORMAT_MAX_NUM_CHANNEL_V8;
- /* Valid range: 0 to 0x4000(Unity) gain weightage */
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0x4000;
- return 0;
- }
- static int msm_compr_add_channel_mixer_weight_controls(
- struct snd_soc_pcm_runtime *rtd,
- int channel)
- {
- const char *playback_mixer_ctl_name = "AudStr";
- const char *capture_mixer_ctl_name = "AudStr Capture";
- const char *suffix = "ChMixer Weight Ch";
- const char *mixer_ctl_name = NULL;
- int ret = 0, session_type = INVALID_SESSION;
- struct snd_kcontrol_new channel_mixer_weight_control = {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_compr_channel_mixer_weight_info,
- .put = msm_compr_channel_mixer_weight_ctl_put,
- .get = msm_compr_channel_mixer_weight_ctl_get,
- .private_value = 0,
- };
- mixer_ctl_name = rtd->compr->direction == SND_COMPRESS_PLAYBACK ?
- playback_mixer_ctl_name : capture_mixer_ctl_name ;
- ret = msm_compr_add_platform_controls(&channel_mixer_weight_control,
- rtd, mixer_ctl_name, suffix, session_type, channel);
- if (ret < 0) {
- pr_err("%s: failed add platform ctl, err = %d\n",
- __func__, ret);
- }
- return ret;
- }
- static int msm_compr_add_channel_mixer_controls(struct snd_soc_pcm_runtime *rtd)
- {
- int i, ret = 0;
- struct msm_compr_pdata *pdata = NULL;
- struct snd_soc_component *component = NULL;
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = (struct msm_compr_pdata *)
- snd_soc_component_get_drvdata(component);
- if (!pdata) {
- pr_err("%s: platform data not populated\n", __func__);
- return -EINVAL;
- }
- if (!pdata->chmixer_pspd[rtd->dai_link->id]) {
- pdata->chmixer_pspd[rtd->dai_link->id] =
- kzalloc(sizeof(struct msm_pcm_channel_mixer), GFP_KERNEL);
- if (!pdata->chmixer_pspd[rtd->dai_link->id])
- return -ENOMEM;
- }
- ret = msm_compr_add_channel_mixer_cfg_controls(rtd);
- if (ret) {
- pr_err("%s: pcm add channel mixer cfg controls failed:%d\n",
- __func__, ret);
- goto fail;
- }
- ret = msm_compr_add_channel_mixer_input_map_controls(rtd);
- if (ret) {
- pr_err("%s: pcm add channel mixer input map controls failed:%d\n",
- __func__, ret);
- goto fail;
- }
- ret = msm_compr_add_channel_mixer_output_map_controls(rtd);
- if (ret) {
- pr_err("%s: pcm add channel mixer output map controls failed:%d\n",
- __func__, ret);
- goto fail;
- }
- for (i = 1; i <= PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++) {
- ret = msm_compr_add_channel_mixer_weight_controls(rtd, i);
- if (ret) {
- pr_err("%s: pcm add channel mixer weight controls failed:%d\n",
- __func__, ret);
- goto fail;
- }
- }
- return 0;
- fail:
- kfree(pdata->chmixer_pspd[rtd->dai_link->id]);
- pdata->chmixer_pspd[rtd->dai_link->id] = NULL;
- return ret;
- }
- static int msm_compr_new(struct snd_soc_pcm_runtime *rtd)
- {
- int rc;
- rc = msm_compr_add_volume_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Volume Control\n", __func__);
- rc = msm_compr_add_audio_effects_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Audio Effects Control\n",
- __func__);
- rc = msm_compr_add_audio_adsp_stream_cmd_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr ADSP Stream Cmd Control\n",
- __func__);
- rc = msm_compr_add_audio_adsp_stream_callback_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr ADSP Stream Callback Control\n",
- __func__);
- rc = msm_compr_add_io_fd_cmd_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr ion fd Control\n",
- __func__);
- rc = msm_compr_add_event_ack_cmd_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr event ack Control\n",
- __func__);
- rc = msm_compr_add_query_audio_effect_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Query Audio Effect Control\n",
- __func__);
- rc = msm_compr_add_dec_runtime_params_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Dec runtime params Control\n",
- __func__);
- rc = msm_compr_add_app_type_cfg_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr App Type Cfg Control\n",
- __func__);
- rc = msm_compr_add_channel_map_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Channel Map Control\n",
- __func__);
- rc = msm_compr_add_channel_mixer_controls(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Channel Mixer Controls\n",
- __func__);
- return 0;
- }
- static struct snd_compr_ops msm_compr_ops = {
- .open = msm_compr_open,
- .free = msm_compr_free,
- .trigger = msm_compr_trigger,
- .pointer = msm_compr_pointer,
- .set_params = msm_compr_set_params,
- .set_metadata = msm_compr_set_metadata,
- .get_metadata = msm_compr_get_metadata,
- #if IS_ENABLED(CONFIG_AUDIO_QGKI)
- .set_next_track_param = msm_compr_set_next_track_param,
- #endif /* CONFIG_AUDIO_QGKI */
- .ack = msm_compr_ack,
- .copy = msm_compr_copy,
- .get_caps = msm_compr_get_caps,
- .get_codec_caps = msm_compr_get_codec_caps,
- };
- static struct snd_soc_component_driver msm_soc_component = {
- .name = DRV_NAME,
- .probe = msm_compr_probe,
- .compr_ops = &msm_compr_ops,
- .pcm_new = msm_compr_new,
- };
- static int msm_compr_dev_probe(struct platform_device *pdev)
- {
- struct msm_compr_pdata *pdata = NULL;
- pr_debug("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
- pdata = (struct msm_compr_pdata *)
- kzalloc(sizeof(*pdata), GFP_KERNEL);
- if (!pdata)
- return -ENOMEM;
- mutex_init(&pdata->lock);
- dev_set_drvdata(&pdev->dev, pdata);
- return snd_soc_register_component(&pdev->dev,
- &msm_soc_component, NULL, 0);
- }
- static int msm_compr_remove(struct platform_device *pdev)
- {
- int i = 0;
- struct msm_compr_pdata *pdata = NULL;
- pdata = dev_get_drvdata(&pdev->dev);
- if (pdata) {
- for (i = 0; i < MSM_FRONTEND_DAI_MM_SIZE; i++)
- kfree(pdata->chmixer_pspd[i]);
- }
- mutex_destroy(&pdata->lock);
- kfree(pdata);
- snd_soc_unregister_component(&pdev->dev);
- return 0;
- }
- static const struct of_device_id msm_compr_dt_match[] = {
- {.compatible = "qcom,msm-compress-dsp"},
- {}
- };
- MODULE_DEVICE_TABLE(of, msm_compr_dt_match);
- static struct platform_driver msm_compr_driver = {
- .driver = {
- .name = "msm-compress-dsp",
- .owner = THIS_MODULE,
- .of_match_table = msm_compr_dt_match,
- .suppress_bind_attrs = true,
- },
- .probe = msm_compr_dev_probe,
- .remove = msm_compr_remove,
- };
- int __init msm_compress_dsp_init(void)
- {
- return platform_driver_register(&msm_compr_driver);
- }
- void msm_compress_dsp_exit(void)
- {
- platform_driver_unregister(&msm_compr_driver);
- }
- MODULE_DESCRIPTION("Compress Offload platform driver");
- MODULE_LICENSE("GPL v2");
|