123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061 |
- /*
- * Copyright (c) 2012-2016, 2019 The Linux Foundation. All rights reserved.
- * Author: Brian Swetland <swetland@google.com>
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
- #include <linux/fs.h>
- #include <linux/mutex.h>
- #include <linux/wait.h>
- #include <linux/miscdevice.h>
- #include <linux/uaccess.h>
- #include <linux/sched.h>
- #include <linux/dma-mapping.h>
- #include <linux/miscdevice.h>
- #include <linux/delay.h>
- #include <linux/spinlock.h>
- #include <linux/slab.h>
- #include <linux/msm_audio.h>
- #include <linux/memory_alloc.h>
- #include <linux/debugfs.h>
- #include <linux/time.h>
- #include <linux/atomic.h>
- #include <linux/msm_audio_ion.h>
- #include <linux/mm.h>
- #include <asm/ioctls.h>
- #include <mach/memory.h>
- #include <mach/debug_mm.h>
- #include <sound/apr_audio-v2.h>
- #include <sound/q6asm-v2.h>
- #include <sound/q6audio-v2.h>
- #include "audio_acdb.h"
- #define TRUE 0x01
- #define FALSE 0x00
- #define FRAME_NUM (8)
- /* TODO, combine them together */
- static DEFINE_MUTEX(session_lock);
- struct asm_mmap {
- atomic_t ref_cnt;
- void *apr;
- };
- static struct asm_mmap this_mmap;
- /* session id: 0 reserved */
- static struct audio_client *session[SESSION_MAX+1];
- struct asm_buffer_node {
- struct list_head list;
- uint32_t buf_addr_lsw;
- uint32_t mmap_hdl;
- };
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv);
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous);
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir);
- static void q6asm_reset_buf_state(struct audio_client *ac);
- static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels);
- void *q6asm_mmap_apr_reg(void);
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv);
- /* for ASM custom topology */
- static struct audio_buffer common_buf[2];
- static struct audio_client common_client;
- static int set_custom_topology;
- static int topology_map_handle;
- #ifdef CONFIG_DEBUG_FS
- #define OUT_BUFFER_SIZE 56
- #define IN_BUFFER_SIZE 24
- static struct timeval out_cold_tv;
- static struct timeval out_warm_tv;
- static struct timeval out_cont_tv;
- static struct timeval in_cont_tv;
- static long out_enable_flag;
- static long in_enable_flag;
- static struct dentry *out_dentry;
- static struct dentry *in_dentry;
- static int in_cont_index;
- /*This var is used to keep track of first write done for cold output latency */
- static int out_cold_index;
- static char *out_buffer;
- static char *in_buffer;
- u32 score;
- int q6asm_mmap_apr_dereg(void)
- {
- int c;
- c = atomic_sub_return(1, &this_mmap.ref_cnt);
- if (c == 0) {
- apr_deregister(this_mmap.apr);
- pr_debug("%s: APR De-Register common port\n", __func__);
- } else if (c < 0) {
- pr_err("%s: APR Common Port Already Closed\n", __func__);
- atomic_set(&this_mmap.ref_cnt, 0);
- }
- return 0;
- }
- static int audio_output_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_output_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (out_buffer == NULL) {
- pr_err("%s: out_buffer is null\n", __func__);
- return 0;
- }
- if (count < OUT_BUFFER_SIZE) {
- pr_err("%s: read size %d exceeds buf size %zd\n", __func__,
- OUT_BUFFER_SIZE, count);
- return 0;
- }
- snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
- out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
- out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
- out_buffer, OUT_BUFFER_SIZE);
- }
- static ssize_t audio_output_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char))
- return -EINVAL;
- else
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- out_cold_index = 0;
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &out_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_output_latency_debug_fops = {
- .open = audio_output_latency_dbgfs_open,
- .read = audio_output_latency_dbgfs_read,
- .write = audio_output_latency_dbgfs_write
- };
- static int audio_input_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_input_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (in_buffer == NULL) {
- pr_err("%s: in_buffer is null\n", __func__);
- return 0;
- }
- if (count < IN_BUFFER_SIZE) {
- pr_err("%s: read size %d exceeds buf size %zd\n", __func__,
- IN_BUFFER_SIZE, count);
- return 0;
- }
- snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
- in_buffer, IN_BUFFER_SIZE);
- }
- static ssize_t audio_input_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char))
- return -EINVAL;
- else
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &in_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_input_latency_debug_fops = {
- .open = audio_input_latency_dbgfs_open,
- .read = audio_input_latency_dbgfs_read,
- .write = audio_input_latency_dbgfs_write
- };
- static void config_debug_fs_write_cb(void)
- {
- if (out_enable_flag) {
- /* For first Write done log the time and reset
- out_cold_index*/
- if (out_cold_index != 1) {
- do_gettimeofday(&out_cold_tv);
- pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
- out_cold_tv.tv_sec,\
- out_cold_tv.tv_usec);
- out_cold_index = 1;
- }
- pr_debug("out_enable_flag %ld",\
- out_enable_flag);
- }
- }
- static void config_debug_fs_read_cb(void)
- {
- if (in_enable_flag) {
- /* when in_cont_index == 7, DSP would be
- * writing into the 8th 512 byte buffer and this
- * timestamp is tapped here.Once done it then writes
- * to 9th 512 byte buffer.These two buffers(8th, 9th)
- * reach the test application in 5th iteration and that
- * timestamp is tapped at user level. The difference
- * of these two timestamps gives us the time between
- * the time at which dsp started filling the sample
- * required and when it reached the test application.
- * Hence continuous input latency
- */
- if (in_cont_index == 7) {
- do_gettimeofday(&in_cont_tv);
- pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- }
- in_cont_index++;
- }
- }
- static void config_debug_fs_reset_index(void)
- {
- in_cont_index = 0;
- }
- static void config_debug_fs_run(void)
- {
- if (out_enable_flag) {
- do_gettimeofday(&out_cold_tv);
- pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
- out_cold_tv.tv_sec, out_cold_tv.tv_usec);
- }
- }
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- if (out_enable_flag) {
- char zero_pattern[2] = {0x00, 0x00};
- /* If First two byte is non zero and last two byte
- is zero then it is warm output pattern */
- if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
- (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
- do_gettimeofday(&out_warm_tv);
- pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
- out_warm_tv.tv_sec,\
- out_warm_tv.tv_usec);
- pr_debug("Warm Pattern Matched");
- }
- /* If First two byte is zero and last two byte is
- non zero then it is cont ouput pattern */
- else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
- && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
- do_gettimeofday(&out_cont_tv);
- pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
- out_cont_tv.tv_sec,\
- out_cont_tv.tv_usec);
- pr_debug("Cont Pattern Matched");
- }
- }
- }
- static void config_debug_fs_init(void)
- {
- out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
- if (out_buffer == NULL) {
- pr_err("%s: kmalloc() for out_buffer failed\n", __func__);
- goto outbuf_fail;
- }
- in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
- if (in_buffer == NULL) {
- pr_err("%s: kmalloc() for in_buffer failed\n", __func__);
- goto inbuf_fail;
- }
- out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
- S_IRUGO | S_IWUSR | S_IWGRP,\
- NULL, NULL, &audio_output_latency_debug_fops);
- if (IS_ERR(out_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
- S_IRUGO | S_IWUSR | S_IWGRP,\
- NULL, NULL, &audio_input_latency_debug_fops);
- if (IS_ERR(in_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- return;
- file_fail:
- kfree(in_buffer);
- inbuf_fail:
- kfree(out_buffer);
- outbuf_fail:
- in_buffer = NULL;
- out_buffer = NULL;
- return;
- }
- #else
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- return;
- }
- static void config_debug_fs_run(void)
- {
- return;
- }
- static void config_debug_fs_reset_index(void)
- {
- return;
- }
- static void config_debug_fs_read_cb(void)
- {
- return;
- }
- static void config_debug_fs_write_cb(void)
- {
- return;
- }
- static void config_debug_fs_init(void)
- {
- return;
- }
- #endif
- static int q6asm_session_alloc(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= SESSION_MAX; n++) {
- if (!session[n]) {
- session[n] = ac;
- return n;
- }
- }
- return -ENOMEM;
- }
- static bool q6asm_is_valid_audio_client(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= SESSION_MAX; n++) {
- if (session[n] == ac)
- return 1;
- }
- return 0;
- }
- static void q6asm_session_free(struct audio_client *ac)
- {
- pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
- rtac_remove_popp_from_adm_devices(ac->session);
- session[ac->session] = 0;
- ac->session = 0;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- return;
- }
- void send_asm_custom_topology(struct audio_client *ac)
- {
- struct acdb_cal_block cal_block;
- struct cmd_set_topologies asm_top;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- int result;
- int size = 4096;
- if (!set_custom_topology)
- return;
- get_asm_custom_topology(&cal_block);
- if (cal_block.cal_size == 0) {
- pr_debug("%s: no cal to send addr= 0x%pa\n",
- __func__, &cal_block.cal_paddr);
- return;
- }
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- common_client.apr = common_client.mmap_apr;
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto mmap_fail;
- }
- /* Only call this once */
- set_custom_topology = 0;
- /* Use first asm buf to map memory */
- if (common_client.port[IN].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- goto err_map;
- }
- common_client.port[IN].buf->phys = cal_block.cal_paddr;
- result = q6asm_memory_map_regions(&common_client,
- IN, size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! addr = 0x%pa, size = %zd\n",
- __func__, &cal_block.cal_paddr,
- cal_block.cal_size);
- goto err_map;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == cal_block.cal_paddr) {
- topology_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- q6asm_add_hdr_custom_topology(ac, &asm_top.hdr,
- APR_PKT_SIZE(APR_HDR_SIZE,
- sizeof(asm_top)), TRUE);
- atomic_set(&ac->mem_state, 1);
- asm_top.hdr.opcode = ASM_CMD_ADD_TOPOLOGIES;
- asm_top.payload_addr_lsw = cal_block.cal_paddr;
- asm_top.payload_addr_msw = 0;
- asm_top.mem_map_handle = topology_map_handle;
- asm_top.payload_size = cal_block.cal_size;
- pr_debug("%s: Sending ASM_CMD_ADD_TOPOLOGIES payload = 0x%x, size = %d, map handle = 0x%x\n",
- __func__, asm_top.payload_addr_lsw,
- asm_top.payload_size, asm_top.mem_map_handle);
- result = apr_send_pkt(ac->apr, (uint32_t *) &asm_top);
- if (result < 0) {
- pr_err("%s: Set topologies failed payload = 0x%x\n",
- __func__, cal_block.cal_paddr);
- goto err_unmap;
- }
- result = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) == 0), 5*HZ);
- if (!result) {
- pr_err("%s: Set topologies failed after timedout payload = 0x%x\n",
- __func__, cal_block.cal_paddr);
- goto err_unmap;
- }
- return;
- err_unmap:
- q6asm_memory_unmap_regions(ac, IN);
- err_map:
- q6asm_mmap_apr_dereg();
- set_custom_topology = 1;
- mmap_fail:
- return;
- }
- int q6asm_map_rtac_block(struct rtac_cal_block_data *cal_block)
- {
- int result = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- pr_debug("%s\n", __func__);
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (cal_block->cal_data.paddr == 0) {
- pr_debug("%s: No address to map!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- if (cal_block->map_data.map_size == 0) {
- pr_debug("%s: map size is 0!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- /* Use second asm buf to map memory */
- if (common_client.port[OUT].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- common_client.port[OUT].buf->phys = cal_block->cal_data.paddr;
- result = q6asm_memory_map_regions(&common_client,
- OUT, cal_block->map_data.map_size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! addr = 0x%x, size = %d\n",
- __func__, cal_block->cal_data.paddr,
- cal_block->map_data.map_size);
- goto done;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == cal_block->cal_data.paddr) {
- cal_block->map_data.map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- result = q6asm_mmap_apr_dereg();
- if (result < 0) {
- pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
- __func__, result);
- } else {
- common_client.mmap_apr = NULL;
- }
- done:
- return result;
- }
- int q6asm_unmap_rtac_block(uint32_t *mem_map_handle)
- {
- int result = 0;
- int result2 = 0;
- pr_debug("%s\n", __func__);
- if (mem_map_handle == NULL) {
- pr_debug("%s: Map handle is NULL, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (*mem_map_handle == 0) {
- pr_debug("%s: Map handle is 0, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, OUT);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- mem_map_handle = 0;
- }
- result2 = q6asm_mmap_apr_dereg();
- if (result2 < 0) {
- pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- common_client.mmap_apr = NULL;
- }
- done:
- return result;
- }
- int q6asm_unmap_cal_blocks(void)
- {
- int result = 0;
- int result2 = 0;
- pr_debug("%s\n", __func__);
- if (topology_map_handle == 0)
- goto done;
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, IN);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- topology_map_handle = 0;
- }
- result2 = q6asm_mmap_apr_dereg();
- if (result2 < 0) {
- pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- common_client.mmap_apr = NULL;
- }
- set_custom_topology = 0;
- done:
- return result;
- }
- int q6asm_audio_client_buf_free(unsigned int dir,
- struct audio_client *ac)
- {
- struct audio_port_data *port;
- int cnt = 0;
- int rc = 0;
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- mutex_lock(&ac->cmd_lock);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- if (!port->buf) {
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- cnt = port->max_buf_cnt - 1;
- if (cnt >= 0) {
- rc = q6asm_memory_unmap_regions(ac, dir);
- if (rc < 0)
- pr_err("%s CMD Memory_unmap_regions failed\n",
- __func__);
- }
- while (cnt >= 0) {
- if (port->buf[cnt].data) {
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(
- port->buf[cnt].client,
- port->buf[cnt].handle);
- port->buf[cnt].client = NULL;
- port->buf[cnt].handle = NULL;
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- --(port->max_buf_cnt);
- }
- --cnt;
- }
- kfree(port->buf);
- port->buf = NULL;
- }
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
- struct audio_client *ac)
- {
- struct audio_port_data *port;
- int cnt = 0;
- int rc = 0;
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- mutex_lock(&ac->cmd_lock);
- port = &ac->port[dir];
- if (!port->buf) {
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- cnt = port->max_buf_cnt - 1;
- if (cnt >= 0) {
- rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
- if (rc < 0)
- pr_err("%s CMD Memory_unmap_regions failed\n",
- __func__);
- }
- if (port->buf[0].data) {
- pr_debug("%s:data[%p]phys[%p][%p] , client[%p] handle[%p]\n",
- __func__,
- (void *)port->buf[0].data,
- (void *)port->buf[0].phys,
- (void *)&port->buf[0].phys,
- (void *)port->buf[0].client,
- (void *)port->buf[0].handle);
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(port->buf[0].client,
- port->buf[0].handle);
- port->buf[0].client = NULL;
- port->buf[0].handle = NULL;
- }
- while (cnt >= 0) {
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- cnt--;
- }
- port->max_buf_cnt = 0;
- kfree(port->buf);
- port->buf = NULL;
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- void q6asm_audio_client_free(struct audio_client *ac)
- {
- int loopcnt;
- struct audio_port_data *port;
- if (!ac || !ac->session)
- return;
- mutex_lock(&session_lock);
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- if (ac->io_mode & SYNC_IO_MODE) {
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- if (!port->buf)
- continue;
- pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
- q6asm_audio_client_buf_free(loopcnt, ac);
- }
- }
- apr_deregister(ac->apr2);
- ac->apr2 = NULL;
- apr_deregister(ac->apr);
- ac->apr = NULL;
- ac->mmap_apr = NULL;
- rtac_set_asm_handle(ac->session, ac->apr);
- q6asm_session_free(ac);
- q6asm_mmap_apr_dereg();
- pr_debug("%s: APR De-Register\n", __func__);
- /*done:*/
- kfree(ac);
- ac = NULL;
- mutex_unlock(&session_lock);
- return;
- }
- int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode1)
- {
- uint32_t mode;
- if (ac == NULL) {
- pr_err("%s APR handle NULL\n", __func__);
- return -EINVAL;
- }
- ac->io_mode &= 0xFF00;
- mode = (mode1 & 0xF);
- pr_debug("%s ac->mode after anding with FF00:0x[%x],\n",
- __func__, ac->io_mode);
- if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
- ac->io_mode |= mode1;
- pr_debug("%s:Set Mode to 0x[%x]\n", __func__, ac->io_mode);
- return 0;
- } else {
- pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
- return -EINVAL;
- }
- }
- void *q6asm_mmap_apr_reg(void)
- {
- if ((atomic_read(&this_mmap.ref_cnt) == 0) ||
- (this_mmap.apr == NULL)) {
- this_mmap.apr = apr_register("ADSP", "ASM", \
- (apr_fn)q6asm_srvc_callback,\
- 0x0FFFFFFFF, &this_mmap);
- if (this_mmap.apr == NULL) {
- pr_debug("%s Unable to register APR ASM common port\n",
- __func__);
- goto fail;
- }
- }
- atomic_inc(&this_mmap.ref_cnt);
- return this_mmap.apr;
- fail:
- return NULL;
- }
- struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
- {
- struct audio_client *ac;
- int n;
- int lcnt = 0;
- ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
- if (!ac)
- return NULL;
- mutex_lock(&session_lock);
- n = q6asm_session_alloc(ac);
- if (n <= 0) {
- mutex_unlock(&session_lock);
- goto fail_session;
- }
- ac->session = n;
- ac->cb = cb;
- ac->priv = priv;
- ac->io_mode = SYNC_IO_MODE;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- /* DSP expects stream id from 1 */
- ac->stream_id = 1;
- ac->apr = apr_register("ADSP", "ASM", \
- (apr_fn)q6asm_callback,\
- ((ac->session) << 8 | 0x0001),\
- ac);
- if (ac->apr == NULL) {
- pr_err("%s Registration with APR failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr1;
- }
- ac->apr2 = apr_register("ADSP", "ASM", \
- (apr_fn)q6asm_callback,\
- ((ac->session) << 8 | 0x0002),\
- ac);
- if (ac->apr2 == NULL) {
- pr_err("%s Registration with APR-2 failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr2;
- }
- rtac_set_asm_handle(n, ac->apr);
- pr_debug("%s Registering the common port with APR\n", __func__);
- ac->mmap_apr = q6asm_mmap_apr_reg();
- if (ac->mmap_apr == NULL) {
- mutex_unlock(&session_lock);
- goto fail_mmap;
- }
- init_waitqueue_head(&ac->cmd_wait);
- init_waitqueue_head(&ac->time_wait);
- init_waitqueue_head(&ac->mem_wait);
- atomic_set(&ac->time_flag, 1);
- atomic_set(&ac->reset, 0);
- INIT_LIST_HEAD(&ac->port[0].mem_map_handle);
- INIT_LIST_HEAD(&ac->port[1].mem_map_handle);
- pr_debug("%s: mem_map_handle list init'ed\n", __func__);
- mutex_init(&ac->cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&ac->port[lcnt].lock);
- spin_lock_init(&ac->port[lcnt].dsp_lock);
- }
- atomic_set(&ac->cmd_state, 0);
- atomic_set(&ac->nowait_cmd_cnt, 0);
- atomic_set(&ac->mem_state, 0);
- send_asm_custom_topology(ac);
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- mutex_unlock(&session_lock);
- return ac;
- fail_mmap:
- apr_deregister(ac->apr2);
- fail_apr2:
- apr_deregister(ac->apr);
- fail_apr1:
- q6asm_session_free(ac);
- fail_session:
- kfree(ac);
- return NULL;
- }
- struct audio_client *q6asm_get_audio_client(int session_id)
- {
- if (session_id == ASM_CONTROL_SESSION) {
- return &common_client;
- }
- if ((session_id <= 0) || (session_id > SESSION_MAX)) {
- pr_err("%s: invalid session: %d\n", __func__, session_id);
- goto err;
- }
- if (!session[session_id]) {
- pr_err("%s: session not active: %d\n", __func__, session_id);
- goto err;
- }
- return session[session_id];
- err:
- return NULL;
- }
- int q6asm_audio_client_buf_alloc(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- unsigned int bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- if (!(ac) || ((dir != IN) && (dir != OUT)))
- return -EINVAL;
- pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > 8)
- goto fail;
- if (ac->io_mode & SYNC_IO_MODE) {
- if (ac->port[dir].buf) {
- pr_debug("%s: buffer already allocated\n", __func__);
- return 0;
- }
- if (bufcnt != FRAME_NUM)
- goto fail;
- mutex_lock(&ac->cmd_lock);
- if (bufcnt > (LONG_MAX/sizeof(struct audio_buffer))) {
- pr_err("%s: Buffer size overflows", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- if (!buf[cnt].data) {
- rc = msm_audio_ion_alloc("audio_client",
- &buf[cnt].client, &buf[cnt].handle,
- bufsz,
- (ion_phys_addr_t *)&buf[cnt].phys,
- &len,
- &buf[cnt].data);
- if (rc) {
- pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s data[%p]phys[%p][%p]\n",
- __func__,
- (void *)buf[cnt].data,
- (void *)buf[cnt].phys,
- (void *)&buf[cnt].phys);
- cnt++;
- }
- }
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 0);
- if (rc < 0) {
- pr_err("%s:CMD Memory_map_regions failed\n", __func__);
- goto fail;
- }
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free(dir, ac);
- return -EINVAL;
- }
- int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- unsigned int bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- int bytes_to_alloc;
- if (!(ac) || ((dir != IN) && (dir != OUT)))
- return -EINVAL;
- pr_info("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
- __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > 8)
- goto fail;
- if (ac->port[dir].buf) {
- pr_info("%s: buffer already allocated\n", __func__);
- return 0;
- }
- if (bufcnt == 0) {
- pr_err("%s: invalid buffer count\n", __func__);
- return -EINVAL;
- }
- mutex_lock(&ac->cmd_lock);
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- /* check for integer overflow */
- if ((bufcnt > 0) && ((INT_MAX / bufcnt) < bufsz)) {
- pr_err("%s: integer overflow\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- bytes_to_alloc = bufsz * bufcnt;
- /* The size to allocate should be multiple of 4K bytes */
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc("audio_client", &buf[0].client, &buf[0].handle,
- bytes_to_alloc,
- (ion_phys_addr_t *)&buf[0].phys, &len,
- &buf[0].data);
- if (rc) {
- pr_err("%s: Audio ION alloc is failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].used = dir ^ 1;
- buf[0].size = bufsz;
- buf[0].actual_size = bufsz;
- cnt = 1;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- buf[cnt].data = buf[0].data + (cnt * bufsz);
- buf[cnt].phys = buf[0].phys + (cnt * bufsz);
- if (!buf[cnt].data) {
- pr_err("%s Buf alloc failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = dir ^ 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
- (void *)buf[cnt].data,
- (void *)buf[cnt].phys,
- (void *)&buf[cnt].phys);
- }
- cnt++;
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 1);
- if (rc < 0) {
- pr_err("%s:CMD Memory_map_regions failed\n", __func__);
- goto fail;
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free_contiguous(dir, ac);
- return -EINVAL;
- }
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv)
- {
- uint32_t sid = 0;
- uint32_t dir = 0;
- uint32_t i = IN;
- uint32_t *payload;
- unsigned long dsp_flags;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_client *ac = NULL;
- struct audio_port_data *port;
- if (!data) {
- pr_err("%s: Invalid CB\n", __func__);
- return 0;
- }
- payload = data->payload;
- if (data->opcode == RESET_EVENTS) {
- pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
- __func__,
- data->reset_event,
- data->reset_proc,
- this_mmap.apr);
- atomic_set(&this_mmap.ref_cnt, 0);
- apr_reset(this_mmap.apr);
- this_mmap.apr = NULL;
- for (; i <= OUT; i++) {
- list_for_each_safe(ptr, next,
- &common_client.port[i].mem_map_handle) {
- buf_node = list_entry(ptr,
- struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw ==
- common_client.port[i].buf->phys) {
- list_del(&buf_node->list);
- kfree(buf_node);
- }
- }
- pr_debug("%s:Clearing custom topology\n", __func__);
- }
- reset_custom_topology_flags();
- set_custom_topology = 1;
- topology_map_handle = 0;
- rtac_clear_mapping(ASM_RTAC_CAL);
- return 0;
- }
- sid = (data->token >> 8) & 0x0F;
- ac = q6asm_get_audio_client(sid);
- if (!ac) {
- pr_debug("%s: session[%d] already freed\n", __func__, sid);
- return 0;
- }
- pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
- __func__, payload[0], payload[1], data->opcode, data->token,
- data->payload_size, data->src_port, data->dest_port, sid, dir);
- pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- switch (payload[0]) {
- case ASM_CMD_SHARED_MEM_MAP_REGIONS:
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:
- case ASM_CMD_ADD_TOPOLOGIES:
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x sid:%d\n",
- __func__, payload[0], payload[1], sid);
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 0);
- } else {
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 1);
- }
- if (atomic_cmpxchg(&ac->mem_state, 1, 0))
- wake_up(&ac->mem_wait);
- pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- break;
- default:
- pr_debug("%s:command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- return 0;
- }
- dir = (data->token & 0x0F);
- if (dir != IN && dir != OUT) {
- pr_err("%s: Invalid audio port index: %d\n", __func__, dir);
- return 0;
- }
- port = &ac->port[dir];
- switch (data->opcode) {
- case ASM_CMDRSP_SHARED_MEM_MAP_REGIONS:{
- pr_debug("%s:PL#0[0x%x]PL#1 [0x%x] dir=%x s_id=%x\n",
- __func__, payload[0], payload[1], dir, sid);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, 1, 0)) {
- ac->port[dir].tmp_hdl = payload[0];
- wake_up(&ac->mem_wait);
- }
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:{
- pr_debug("%s:PL#0[0x%x]PL#1 [0x%x]\n",
- __func__, payload[0], payload[1]);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, 1, 0))
- wake_up(&ac->mem_wait);
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- default:
- pr_debug("%s:command[0x%x]success [0x%x]\n",
- __func__, payload[0], payload[1]);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- return 0;
- }
- static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
- {
- if (opcode == APR_BASIC_RSP_RESULT) {
- if (cmd_type != NULL) {
- switch (cmd_type[0]) {
- case ASM_SESSION_CMD_RUN_V2:
- case ASM_SESSION_CMD_PAUSE:
- case ASM_DATA_CMD_EOS:
- return 1;
- default:
- break;
- }
- } else
- pr_err("%s: null pointer!", __func__);
- } else if (opcode == ASM_DATA_EVENT_RENDERED_EOS)
- return 1;
- return 0;
- }
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
- {
- int i = 0;
- struct audio_client *ac = (struct audio_client *)priv;
- uint32_t token;
- unsigned long dsp_flags;
- uint32_t *payload;
- uint32_t wakeup_flag = 1;
- int32_t ret = 0;
- if ((ac == NULL) || (data == NULL)) {
- pr_err("ac or priv NULL\n");
- return -EINVAL;
- }
- if (!q6asm_is_valid_audio_client(ac)) {
- pr_err("%s: audio client pointer is invalid, ac = %p\n",
- __func__, ac);
- return -EINVAL;
- }
- if (ac->session <= 0 || ac->session > 8) {
- pr_err("%s:Session ID is invalid, session = %d\n", __func__,
- ac->session);
- return -EINVAL;
- }
- payload = data->payload;
- if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
- is_no_wait_cmd_rsp(data->opcode, payload)) {
- pr_debug("%s: nowait_cmd_cnt %d\n",
- __func__,
- atomic_read(&ac->nowait_cmd_cnt));
- atomic_dec(&ac->nowait_cmd_cnt);
- wakeup_flag = 0;
- }
- if (data->opcode == RESET_EVENTS) {
- atomic_set(&ac->reset, 1);
- if (ac->apr == NULL)
- ac->apr = ac->apr2;
- pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
- data->reset_event, data->reset_proc, ac->apr);
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- apr_reset(ac->apr);
- ac->apr = NULL;
- atomic_set(&ac->time_flag, 0);
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->time_wait);
- wake_up(&ac->cmd_wait);
- return 0;
- }
- pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
- __func__,
- ac->session, data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port);
- if ((data->opcode != ASM_DATA_EVENT_RENDERED_EOS) &&
- (data->opcode != ASM_DATA_EVENT_EOS) &&
- (data->opcode != ASM_SESSION_EVENT_RX_UNDERFLOW))
- pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- token = data->token;
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
- __func__, payload[0], payload[1]);
- }
- switch (payload[0]) {
- case ASM_STREAM_CMD_SET_PP_PARAMS_V2:
- if (rtac_make_asm_callback(ac->session, payload,
- data->payload_size))
- break;
- case ASM_SESSION_CMD_PAUSE:
- case ASM_SESSION_CMD_SUSPEND:
- case ASM_DATA_CMD_EOS:
- case ASM_STREAM_CMD_CLOSE:
- case ASM_STREAM_CMD_FLUSH:
- case ASM_SESSION_CMD_RUN_V2:
- case ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS:
- case ASM_STREAM_CMD_FLUSH_READBUFS:
- pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
- ret = q6asm_is_valid_session(data, priv);
- if (ret != 0)
- return ret;
- case ASM_STREAM_CMD_OPEN_READ_V3:
- case ASM_STREAM_CMD_OPEN_WRITE_V3:
- case ASM_STREAM_CMD_OPEN_READWRITE_V2:
- case ASM_STREAM_CMD_OPEN_LOOPBACK_V2:
- case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
- case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
- case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
- case ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS:
- pr_debug("%s:Payload = [0x%x]stat[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (atomic_read(&ac->cmd_state) && wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->cmd_wait);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_CMD_ADD_TOPOLOGIES:
- pr_debug("%s:Payload = [0x%x]stat[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (atomic_read(&ac->mem_state) && wakeup_flag) {
- atomic_set(&ac->mem_state, 0);
- wake_up(&ac->mem_wait);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_STREAM_CMD_GET_PP_PARAMS_V2:
- pr_debug("%s: ASM_STREAM_CMD_GET_PP_PARAMS_V2\n",
- __func__);
- /* Should only come here if there is an APR */
- /* error or malformed APR packet. Otherwise */
- /* response will be returned as */
- /* ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 */
- if (payload[1] != 0) {
- pr_err("%s: ASM get param error = %d, resuming\n",
- __func__, payload[1]);
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- }
- break;
- default:
- pr_debug("%s:command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- return 0;
- }
- switch (data->opcode) {
- case ASM_DATA_EVENT_WRITE_DONE_V2:{
- struct audio_port_data *port = &ac->port[IN];
- pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
- __func__, payload[0], payload[1],
- data->token);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Write Done\n",
- __func__);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (port->buf[data->token].phys !=
- payload[0]) {
- pr_err("Buf expected[%p]rxed[%p]\n",\
- (void *)port->buf[data->token].phys,\
- (void *)payload[0]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- return -EINVAL;
- }
- token = data->token;
- port->buf[token].used = 1;
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- config_debug_fs_write_cb();
- for (i = 0; i < port->max_buf_cnt; i++)
- pr_debug("%d ", port->buf[i].used);
- }
- break;
- }
- case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
- pr_debug("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2\n", __func__);
- if (payload[0] != 0)
- pr_err("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 returned error = 0x%x\n",
- __func__, payload[0]);
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- break;
- case ASM_DATA_EVENT_READ_DONE_V2:{
- struct audio_port_data *port = &ac->port[OUT];
- config_debug_fs_read_cb();
- pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
- __func__, payload[READDONE_IDX_STATUS],
- payload[READDONE_IDX_BUFADD_LSW],
- payload[READDONE_IDX_SIZE],
- payload[READDONE_IDX_OFFSET]);
- pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d memmap_hdl=%x flags=%d id=%d num=%d\n",
- __func__, payload[READDONE_IDX_MSW_TS],
- payload[READDONE_IDX_LSW_TS],
- payload[READDONE_IDX_MEMMAP_HDL],
- payload[READDONE_IDX_FLAGS],
- payload[READDONE_IDX_SEQ_ID],
- payload[READDONE_IDX_NUMFRAMES]);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Write Done\n", __func__);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- token = data->token;
- port->buf[token].used = 0;
- if (port->buf[token].phys !=
- payload[READDONE_IDX_BUFADD_LSW]) {
- pr_err("Buf expected[%p]rxed[%p]\n",\
- (void *)port->buf[token].phys,\
- (void *)payload[READDONE_IDX_BUFADD_LSW]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- break;
- }
- port->buf[token].actual_size =
- payload[READDONE_IDX_SIZE];
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- }
- break;
- }
- case ASM_DATA_EVENT_EOS:
- case ASM_DATA_EVENT_RENDERED_EOS:
- pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
- __func__, data->opcode);
- break;
- case ASM_SESSION_EVENTX_OVERFLOW:
- pr_debug("ASM_SESSION_EVENTX_OVERFLOW\n");
- break;
- case ASM_SESSION_EVENT_RX_UNDERFLOW:
- pr_debug("ASM_SESSION_EVENT_RX_UNDERFLOW\n");
- break;
- case ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3:
- pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
- __func__,
- payload[0], payload[1], payload[2]);
- ac->time_stamp = (uint64_t)(((uint64_t)payload[2] << 32) |
- payload[1]);
- if (atomic_cmpxchg(&ac->time_flag, 1, 0))
- wake_up(&ac->time_wait);
- break;
- case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
- case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
- pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
- __func__,
- payload[0], payload[1], payload[2],
- payload[3]);
- break;
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- return 0;
- }
- void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
- uint32_t *index)
- {
- void *data;
- unsigned char idx;
- struct audio_port_data *port;
- if (!ac || ((dir != IN) && (dir != OUT)))
- return NULL;
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->cpu_buf;
- if (port->buf == NULL) {
- pr_debug("%s:Buffer pointer null\n", __func__);
- mutex_unlock(&port->lock);
- return NULL;
- }
- /* dir 0: used = 0 means buf in use
- dir 1: used = 1 means buf in use */
- if (port->buf[idx].used == dir) {
- /* To make it more robust, we could loop and get the
- next avail buf, its risky though */
- pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- mutex_unlock(&port->lock);
- return NULL;
- }
- *size = port->buf[idx].actual_size;
- *index = port->cpu_buf;
- data = port->buf[idx].data;
- pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
- __func__,
- ac->session,
- port->cpu_buf,
- data, *size);
- /* By default increase the cpu_buf cnt
- user accesses this function,increase cpu
- buf(to avoid another api)*/
- port->buf[idx].used = dir;
- port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
- mutex_unlock(&port->lock);
- return data;
- }
- return NULL;
- }
- void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
- uint32_t *size, uint32_t *index)
- {
- void *data;
- unsigned char idx;
- struct audio_port_data *port;
- if (!ac || ((dir != IN) && (dir != OUT)))
- return NULL;
- port = &ac->port[dir];
- idx = port->cpu_buf;
- if (port->buf == NULL) {
- pr_debug("%s:Buffer pointer null\n", __func__);
- return NULL;
- }
- /*
- * dir 0: used = 0 means buf in use
- * dir 1: used = 1 means buf in use
- */
- if (port->buf[idx].used == dir) {
- /*
- * To make it more robust, we could loop and get the
- * next avail buf, its risky though
- */
- pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- return NULL;
- }
- *size = port->buf[idx].actual_size;
- *index = port->cpu_buf;
- data = port->buf[idx].data;
- pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
- __func__, ac->session, port->cpu_buf,
- data, *size);
- /*
- * By default increase the cpu_buf cnt
- * user accesses this function,increase cpu
- * buf(to avoid another api)
- */
- port->buf[idx].used = dir;
- port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
- return data;
- }
- int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
- {
- int ret = -1;
- struct audio_port_data *port;
- uint32_t idx;
- if (!ac || (dir != OUT))
- return ret;
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->dsp_buf;
- if (port->buf[idx].used == (dir ^ 1)) {
- /* To make it more robust, we could loop and get the
- next avail buf, its risky though */
- pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
- idx, dir);
- mutex_unlock(&port->lock);
- return ret;
- }
- pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
- ac->session, port->dsp_buf, port->cpu_buf);
- ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
- mutex_unlock(&port->lock);
- }
- return ret;
- }
- static void __q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, uint32_t stream_id)
- {
- pr_debug("%s:pkt_size=%d cmd_flg=%d session=%d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- return;
- }
- mutex_lock(&ac->cmd_lock);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
- APR_HDR_LEN(sizeof(struct apr_hdr)),\
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg) {
- hdr->token = ac->session;
- }
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- return;
- }
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, ac->stream_id);
- return;
- }
- static void q6asm_stream_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, stream_id);
- return;
- }
- static void __q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, uint32_t stream_id)
- {
- pr_debug("%s pkt_size = %d, cmd_flg = %d, session = %d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
- APR_HDR_LEN(sizeof(struct apr_hdr)),\
- APR_PKT_VER);
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- return;
- }
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg) {
- hdr->token = ac->session;
- }
- hdr->pkt_size = pkt_size;
- return;
- }
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg, ac->stream_id);
- return;
- }
- static void q6asm_stream_add_hdr_async(struct audio_client *ac,
- struct apr_hdr *hdr, uint32_t pkt_size,
- uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg, stream_id);
- return;
- }
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- pr_debug("%s:pkt_size=%d cmd_flg=%d session=%d\n", __func__, pkt_size,
- cmd_flg, ac->session);
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- return;
- }
- mutex_lock(&ac->cmd_lock);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
- APR_HDR_LEN(sizeof(struct apr_hdr)),\
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
- hdr->dest_port = 0;
- if (cmd_flg) {
- hdr->token = ((ac->session << 8) | 0x0001) ;
- }
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- return;
- }
- static void q6asm_add_mmaphdr(struct audio_client *ac, struct apr_hdr *hdr,
- u32 pkt_size, u32 cmd_flg, u32 token)
- {
- pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
- APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
- hdr->src_port = 0;
- hdr->dest_port = 0;
- if (cmd_flg) {
- hdr->token = token;
- }
- hdr->pkt_size = pkt_size;
- return;
- }
- static int __q6asm_open_read(struct audio_client *ac,
- uint32_t format, uint16_t bits_per_sample)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read_v3 open;
- config_debug_fs_reset_index();
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s:session[%d]", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, 1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V3;
- /* Stream prio : High, provide meta info with encoded frames */
- open.src_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- open.preprocopo_id = get_asm_topology();
- if (open.preprocopo_id == 0)
- open.preprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_NONE;
- open.bits_per_sample = bits_per_sample;
- open.mode_flags = 0x0;
- //if (ac->perf_mode)
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_TX_STREAM_SESSION << ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- else
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION << ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.mode_flags |= 0x00;
- open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_V13K:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.mode_flags |= BUFFER_META_ENABLE ;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.mode_flags |= BUFFER_META_ENABLE ;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- default:
- pr_err("Invalid format[%d]\n", format);
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("open failed op[0x%x]rc[%d]\n", \
- open.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open read rc[%d]\n", __func__,
- rc);
- goto fail_cmd;
- }
- ac->io_mode |= TUN_READ_IO_MODE;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_read(struct audio_client *ac,
- uint32_t format)
- {
- return __q6asm_open_read(ac, format, 16);
- }
- int q6asm_open_read_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_read(ac, format, bits_per_sample);
- }
- static int __q6asm_open_write(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, uint32_t stream_id,
- bool is_gapless_mode)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_write_v3 open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_info("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
- format);
- q6asm_stream_add_hdr(ac, &open.hdr, sizeof(open), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- open.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, open.hdr.token, stream_id, ac->session);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
- open.mode_flags = 0x00;
- if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_ULTRA_LOW_LATENCY_STREAM_SESSION;
- else if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else {
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- if (is_gapless_mode)
- open.mode_flags |= 1 << ASM_SHIFT_GAPLESS_MODE_FLAG;
- }
- /* source endpoint : matrix */
- open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- open.bits_per_sample = bits_per_sample;
- pr_info("%s: session[%d] open.mode_flags:%x", __func__, ac->session,
- open.mode_flags);
- open.postprocopo_id = get_asm_topology();
- if (open.postprocopo_id == 0)
- open.postprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_NONE;
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_DOLBY_AAC;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- case FORMAT_AC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_EAC3_DEC;
- break;
- case FORMAT_EAC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_EAC3_DEC;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, format);
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n", \
- __func__, open.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout. waited for open write rc[%d]\n", __func__,
- rc);
- goto fail_cmd;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_write(struct audio_client *ac, uint32_t format)
- {
- return __q6asm_open_write(ac, format, 16, ac->stream_id,
- false /*gapless*/);
- }
- int q6asm_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/);
- }
- int q6asm_stream_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode);
- }
- int q6asm_open_read_write(struct audio_client *ac,
- uint32_t rd_format,
- uint32_t wr_format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_readwrite_v2 open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]", __func__, ac->session);
- pr_debug("wr_format[0x%x]rd_format[0x%x]",
- wr_format, rd_format);
- ac->io_mode |= NT_MODE;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, 1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE_V2;
- open.mode_flags = BUFFER_META_ENABLE;
- open.bits_per_sample = 16;
- /* source endpoint : matrix */
- open.postprocopo_id = get_asm_topology();
- if (open.postprocopo_id == 0)
- open.postprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_NONE;
- switch (wr_format) {
- case FORMAT_LINEAR_PCM:
- open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_DOLBY_AAC;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_AMRNB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMR_WB_PLUS_V2;
- break;
- case FORMAT_V13K:
- open.dec_fmt_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_EVRCB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCB_FS;
- break;
- case FORMAT_EVRCWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCWB_FS;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- default:
- pr_err("Invalid format[%d]\n", wr_format);
- goto fail_cmd;
- }
- switch (rd_format) {
- case FORMAT_LINEAR_PCM:
- open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_V13K:
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- default:
- pr_err("Invalid format[%d]\n", rd_format);
- goto fail_cmd;
- }
- pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
- open.enc_cfg_id, open.dec_fmt_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("open failed op[0x%x]rc[%d]\n", \
- open.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for open read-write rc[%d]\n", rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_loopback_v2(struct audio_client *ac, uint16_t bits_per_sample)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_loopback_v2 open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, 1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK_V2;
- open.mode_flags = 0;
- open.src_endpointype = 0;
- open.sink_endpointype = 0;
- /* source endpoint : matrix */
- open.postprocopo_id = get_asm_topology();
- if (open.postprocopo_id == 0)
- open.postprocopo_id = DEFAULT_POPP_TOPOLOGY;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s open failed op[0x%x]rc[%d]\n", __func__,
- open.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s timeout. waited for open_loopback rc[%d]\n",
- __func__, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_run(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s session[%d]", __func__, ac->session);
- q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
- atomic_set(&ac->cmd_state, 1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- config_debug_fs_run();
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("Commmand run failed[%d]", rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for run success rc[%d]", rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- static int __q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s:APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("session[%d]", ac->session);
- q6asm_stream_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- /* have to increase first avoid race */
- atomic_inc(&ac->nowait_cmd_cnt);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- atomic_dec(&ac->nowait_cmd_cnt);
- pr_err("%s:Commmand run failed[%d]", __func__, rc);
- return -EINVAL;
- }
- return 0;
- }
- int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, ac->stream_id);
- }
- int q6asm_stream_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, stream_id);
- }
- int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
- uint32_t frames_per_buf,
- uint32_t sample_rate, uint32_t channels,
- uint32_t bit_rate, uint32_t mode, uint32_t format)
- {
- struct asm_aac_enc_cfg_v2 enc_cfg;
- int rc = 0;
- pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
- __func__, ac->session, frames_per_buf,
- sample_rate, channels, bit_rate, mode, format);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_aac_enc_cfg_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.bit_rate = bit_rate;
- enc_cfg.enc_mode = mode;
- enc_cfg.aac_fmt_flag = format;
- enc_cfg.channel_cfg = channels;
- enc_cfg.sample_rate = sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for FORMAT_UPDATE\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_set_encdec_chan_map(struct audio_client *ac,
- uint32_t num_channels)
- {
- struct asm_dec_out_chan_map_param chan_map;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: Session %d, num_channels = %d\n",
- __func__, ac->session, num_channels);
- if (num_channels > MAX_CHAN_MAP_CHANNELS) {
- pr_err("%s: Invalid channel count %d\n", __func__,
- num_channels);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
- atomic_set(&ac->cmd_state, 1);
- chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- chan_map.encdec.param_id = ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP;
- chan_map.encdec.param_size = sizeof(struct asm_dec_out_chan_map_param) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- chan_map.num_channels = num_channels;
- channel_mapping = chan_map.channel_mapping;
- memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
- if (q6asm_map_channels(channel_mapping, num_channels))
- return -EINVAL;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
- if (rc < 0) {
- pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout opcode[0x%x]\n", __func__,
- chan_map.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (q6asm_map_channels(channel_mapping, channels))
- return -EINVAL;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd open failed\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, 16);
- }
- int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, bits_per_sample);
- }
- int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = 0;/*channels;*/
- enc_cfg.bits_per_sample = 16;
- enc_cfg.sample_rate = 0;/*rate;*/
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (q6asm_map_channels(channel_mapping, channels))
- return -EINVAL;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd open failed\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels)
- {
- u8 *lchannel_mapping;
- lchannel_mapping = channel_mapping;
- pr_debug("%s channels passed: %d\n", __func__, channels);
- if (channels == 1) {
- lchannel_mapping[0] = PCM_CHANNEL_FC;
- } else if (channels == 2) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- } else if (channels == 3) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- } else if (channels == 4) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_RB;
- lchannel_mapping[3] = PCM_CHANNEL_LB;
- } else if (channels == 5) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LB;
- lchannel_mapping[4] = PCM_CHANNEL_RB;
- } else if (channels == 6) {
- lchannel_mapping[0] = PCM_CHANNEL_FC;
- lchannel_mapping[1] = PCM_CHANNEL_FL;
- lchannel_mapping[2] = PCM_CHANNEL_FR;
- lchannel_mapping[3] = PCM_CHANNEL_LB;
- lchannel_mapping[4] = PCM_CHANNEL_RB;
- lchannel_mapping[5] = PCM_CHANNEL_LFE;
- } else if (channels == 8) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_LFE;
- lchannel_mapping[3] = PCM_CHANNEL_FC;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_RLC;
- lchannel_mapping[7] = PCM_CHANNEL_RRC;
- } else {
- pr_err("%s: ERROR.unsupported num_ch = %u\n",
- __func__, channels);
- return -EINVAL;
- }
- return 0;
- }
- int q6asm_enable_sbrps(struct audio_client *ac,
- uint32_t sbr_ps_enable)
- {
- struct asm_aac_sbr_ps_flag_param sbrps;
- u32 frames_per_buf = 0;
- int rc = 0;
- pr_debug("%s: Session %d\n", __func__, ac->session);
- q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
- atomic_set(&ac->cmd_state, 1);
- sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- sbrps.encdec.param_id = ASM_PARAM_ID_AAC_SBR_PS_FLAG;
- sbrps.encdec.param_size = sizeof(struct asm_aac_sbr_ps_flag_param) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- sbrps.encblk.frames_per_buf = frames_per_buf;
- sbrps.encblk.enc_cfg_blk_size = sbrps.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- sbrps.sbr_ps_flag = sbr_ps_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
- if (rc < 0) {
- pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
- ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_SBR_PS_FLAG);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
- uint16_t sce_left, uint16_t sce_right)
- {
- struct asm_aac_dual_mono_mapping_param dual_mono;
- int rc = 0;
- pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
- __func__, ac->session, sce_left, sce_right);
- q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
- atomic_set(&ac->cmd_state, 1);
- dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- dual_mono.encdec.param_id = ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING;
- dual_mono.encdec.param_size = sizeof(dual_mono.left_channel_sce) +
- sizeof(dual_mono.right_channel_sce);
- dual_mono.left_channel_sce = sce_left;
- dual_mono.right_channel_sce = sce_right;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
- if (rc < 0) {
- pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout opcode[0x%x]\n", __func__,
- dual_mono.hdr.opcode);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- /* Support for selecting stereo mixing coefficients for B family not done */
- int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
- {
- struct asm_aac_stereo_mix_coeff_selection_param_v2 aac_mix_coeff;
- int rc = 0;
- q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
- atomic_set(&ac->cmd_state, 1);
- aac_mix_coeff.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- aac_mix_coeff.param_id =
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2;
- aac_mix_coeff.param_size =
- sizeof(struct asm_aac_stereo_mix_coeff_selection_param_v2);
- aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
- pr_debug("%s, mix_coeff = %u", __func__, mix_coeff);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
- if (rc < 0) {
- pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout opcode[0x%x]\n",
- __func__, aac_mix_coeff.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
- {
- struct asm_v13k_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]",
- __func__,
- ac->session, frames_per_buf, min_rate, max_rate,
- reduced_rate_level, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_v13k_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.reduced_rate_cmd = reduced_rate_level;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for setencdec v13k resp\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t rate_modulation_cmd)
- {
- struct asm_evrc_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
- __func__, ac->session,
- frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_evrc_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- enc_cfg.reserved = 0;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for encdec evrc\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrnb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrnb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for set encdec amrnb\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrwb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrwb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for FORMAT_UPDATE\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- static int __q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, 1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (q6asm_map_channels(channel_mapping, channels))
- return -EINVAL;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd open failed\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for format update\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, 16);
- }
- int q6asm_media_format_block_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, bits_per_sample);
- }
- static int __q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, 1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels)) {
- pr_err("%s: map channels failed", __func__);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd open failed\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for format update\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map, 16);
- }
- int q6asm_media_format_block_multi_ch_pcm_v2(
- struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map,
- bits_per_sample);
- }
- static int __q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- struct asm_aac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
- cfg->sample_rate, cfg->ch_cfg);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.aac_fmt_flag = cfg->format;
- fmt.audio_objype = cfg->aot;
- /* If zero, PCE is assumed to be available in bitstream*/
- fmt.total_size_of_PCE_bits = 0;
- fmt.channel_config = cfg->ch_cfg;
- fmt.sample_rate = cfg->sample_rate;
- pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
- __func__, fmt.aac_fmt_flag, fmt.fmt_blk.fmt_blk_size,
- fmt.aac_fmt_flag,
- fmt.audio_objype,
- fmt.channel_config,
- fmt.sample_rate);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd open failed\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- int q6asm_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- int q6asm_stream_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, stream_id);
- }
- int q6asm_media_format_block_wma(struct audio_client *ac,
- void *cfg)
- {
- struct asm_wmastdv9_fmt_blk_v2 fmt;
- struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
- int rc = 0;
- pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
- ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
- wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
- wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
- wma_cfg->ch_mask, wma_cfg->encode_opt);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, 1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wma_cfg->format_tag;
- fmt.num_channels = wma_cfg->ch_cfg;
- fmt.sample_rate = wma_cfg->sample_rate;
- fmt.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
- fmt.blk_align = wma_cfg->block_align;
- fmt.bits_per_sample =
- wma_cfg->valid_bits_per_sample;
- fmt.channel_mask = wma_cfg->ch_mask;
- fmt.enc_options = wma_cfg->encode_opt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd open failed\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_media_format_block_wmapro(struct audio_client *ac,
- void *cfg)
- {
- struct asm_wmaprov10_fmt_blk_v2 fmt;
- struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
- int rc = 0;
- pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x], adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
- ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
- wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
- wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
- wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
- wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, 1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wmapro_cfg->format_tag;
- fmt.num_channels = wmapro_cfg->ch_cfg;
- fmt.sample_rate = wmapro_cfg->sample_rate;
- fmt.avg_bytes_per_sec =
- wmapro_cfg->avg_bytes_per_sec;
- fmt.blk_align = wmapro_cfg->block_align;
- fmt.bits_per_sample = wmapro_cfg->valid_bits_per_sample;
- fmt.channel_mask = wmapro_cfg->ch_mask;
- fmt.enc_options = wmapro_cfg->encode_opt;
- fmt.usAdvancedEncodeOpt = wmapro_cfg->adv_encode_opt;
- fmt.advanced_enc_options2 = wmapro_cfg->adv_encode_opt2;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd open failed\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
- struct asm_amrwbplus_cfg *cfg)
- {
- struct asm_amrwbplus_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
- __func__,
- ac->session,
- cfg->amr_band_mode,
- cfg->amr_frame_fmt,
- cfg->num_channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, 1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.amr_frame_fmt = cfg->amr_frame_fmt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s:Comamnd media format update failed..\n", __func__);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_ds1_set_endp_params(struct audio_client *ac,
- int param_id, int param_value)
- {
- struct asm_dec_ddp_endp_param_v2 ddp_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]param_id[%d]param_value[%d]", __func__,
- ac->session, param_id, param_value);
- q6asm_add_hdr(ac, &ddp_cfg.hdr, sizeof(ddp_cfg), TRUE);
- atomic_set(&ac->cmd_state, 1);
- ddp_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- ddp_cfg.encdec.param_id = param_id;
- ddp_cfg.encdec.param_size = sizeof(struct asm_dec_ddp_endp_param_v2) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- ddp_cfg.endp_param_value = param_value;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &ddp_cfg);
- if (rc < 0) {
- pr_err("%s:Command opcode[0x%x] failed\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s:timeout opcode[0x%x]\n", __func__,
- ddp_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int cmd_size = 0;
- if (!ac || ac->mmap_apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- buffer_node = kmalloc(sizeof(struct asm_buffer_node), GFP_KERNEL);
- if (!buffer_node)
- return -ENOMEM;
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + sizeof(struct avs_shared_map_region_payload) * bufcnt;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- pr_err("%s: Mem alloc failed\n", __func__);
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size,
- TRUE, ((ac->session << 8) | dir));
- atomic_set(&ac->mem_state, 1);
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt & 0x00ff;
- mmap_regions->property_flag = 0x00;
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- pr_debug("%s, buf_add 0x%x, bufsz: %d\n", __func__, buf_add, bufsz);
- mregions->shm_addr_lsw = buf_add;
- /* Using only 32 bit address */
- mregions->shm_addr_msw = 0;
- mregions->mem_size_bytes = bufsz;
- ++mregions;
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("mmap op[0x%x]rc[%d]\n",
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) == 0 &&
- ac->port[dir].tmp_hdl), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for memory_map\n");
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- buffer_node->buf_addr_lsw = buf_add;
- buffer_node->mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node->list, &ac->port[dir].mem_map_handle);
- ac->port[dir].tmp_hdl = 0;
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- int rc = 0;
- if (!ac || this_mmap.apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr,
- sizeof(struct avs_cmd_shared_mem_unmap_regions),
- TRUE, ((ac->session << 8) | dir));
- atomic_set(&ac->mem_state, 1);
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("mem_unmap op[0x%x]rc[%d]\n",
- mem_unmap.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) == 0), 5 * HZ);
- if (!rc) {
- pr_err("%s timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- struct audio_buffer *ab = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int i = 0;
- uint32_t cmd_size = 0;
- uint32_t bufcnt_t;
- uint32_t bufsz_t;
- if (!ac || ac->mmap_apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- bufcnt_t = (is_contiguous) ? 1 : bufcnt;
- bufsz_t = (is_contiguous) ? (bufsz * bufcnt) : bufsz;
- if (is_contiguous) {
- /* The size to memory map should be multiple of 4K bytes */
- bufsz_t = PAGE_ALIGN(bufsz_t);
- }
- if (bufcnt_t > (UINT_MAX
- - sizeof(struct avs_cmd_shared_mem_map_regions))
- / sizeof(struct avs_shared_map_region_payload)) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt_t = %u\n",
- __func__, bufcnt_t);
- return -EINVAL;
- }
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + (sizeof(struct avs_shared_map_region_payload)
- * bufcnt_t);
- if (bufcnt > (UINT_MAX / sizeof(struct asm_buffer_node))) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt = %u\n",
- __func__, bufcnt);
- return -EINVAL;
- }
- buffer_node = kzalloc(sizeof(struct asm_buffer_node) * bufcnt,
- GFP_KERNEL);
- if (!buffer_node) {
- pr_err("%s: Mem alloc failed for asm_buffer_node\n",
- __func__);
- return -ENOMEM;
- }
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- pr_err("%s: Mem alloc failed\n", __func__);
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, TRUE,
- ((ac->session << 8) | dir));
- atomic_set(&ac->mem_state, 1);
- pr_debug("mmap_region=0x%p token=0x%x\n",
- mmap_regions, ((ac->session << 8) | dir));
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt_t; /*bufcnt & 0x00ff; */
- mmap_regions->property_flag = 0x00;
- pr_debug("map_regions->nregions = %d\n", mmap_regions->num_regions);
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- for (i = 0; i < bufcnt_t; i++) {
- ab = &port->buf[i];
- mregions->shm_addr_lsw = ab->phys;
- /* Using only 32 bit address */
- mregions->shm_addr_msw = 0;
- mregions->mem_size_bytes = bufsz_t;
- ++mregions;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("mmap_regions op[0x%x]rc[%d]\n",
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) == 0)
- , 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for memory_map\n");
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- mutex_lock(&ac->cmd_lock);
- for (i = 0; i < bufcnt; i++) {
- ab = &port->buf[i];
- buffer_node[i].buf_addr_lsw = ab->phys;
- buffer_node[i].mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node[i].list,
- &ac->port[dir].mem_map_handle);
- pr_debug("%s: i=%d, bufadd[i] = 0x%x, maphdl[i] = 0x%x\n",
- __func__, i, buffer_node[i].buf_addr_lsw,
- buffer_node[i].mmap_hdl);
- }
- ac->port[dir].tmp_hdl = 0;
- mutex_unlock(&ac->cmd_lock);
- rc = 0;
- pr_debug("%s: exit\n", __func__);
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct audio_port_data *port = NULL;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- uint32_t buf_add;
- int rc = 0;
- int cmd_size = 0;
- if (!ac || ac->mmap_apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- cmd_size = sizeof(struct avs_cmd_shared_mem_unmap_regions);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr, cmd_size,
- TRUE, ((ac->session << 8) | dir));
- atomic_set(&ac->mem_state, 1);
- port = &ac->port[dir];
- buf_add = (uint32_t)port->buf->phys;
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("mmap_regions op[0x%x]rc[%d]\n",
- mem_unmap.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
- {
- struct asm_volume_ctrl_lr_chan_gain lrgain;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_volume_ctrl_lr_chan_gain);
- q6asm_add_hdr_async(ac, &lrgain.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- lrgain.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- lrgain.param.data_payload_addr_lsw = 0;
- lrgain.param.data_payload_addr_msw = 0;
- lrgain.param.mem_map_handle = 0;
- lrgain.param.data_payload_size = sizeof(lrgain) -
- sizeof(lrgain.hdr) - sizeof(lrgain.param);
- lrgain.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- lrgain.data.param_id = ASM_PARAM_ID_VOL_CTRL_LR_CHANNEL_GAIN;
- lrgain.data.param_size = lrgain.param.data_payload_size -
- sizeof(lrgain.data);
- lrgain.data.reserved = 0;
- lrgain.l_chan_gain = left_gain;
- lrgain.r_chan_gain = right_gain;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &lrgain);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- lrgain.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- lrgain.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_mute(struct audio_client *ac, int muteflag)
- {
- struct asm_volume_ctrl_mute_config mute;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_volume_ctrl_mute_config);
- q6asm_add_hdr_async(ac, &mute.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- mute.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- mute.param.data_payload_addr_lsw = 0;
- mute.param.data_payload_addr_msw = 0;
- mute.param.mem_map_handle = 0;
- mute.param.data_payload_size = sizeof(mute) -
- sizeof(mute.hdr) - sizeof(mute.param);
- mute.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- mute.data.param_id = ASM_PARAM_ID_VOL_CTRL_MUTE_CONFIG;
- mute.data.param_size = mute.param.data_payload_size - sizeof(mute.data);
- mute.data.reserved = 0;
- mute.mute_flag = muteflag;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &mute);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- mute.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- mute.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_volume(struct audio_client *ac, int volume)
- {
- struct asm_volume_ctrl_master_gain vol;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_volume_ctrl_master_gain);
- q6asm_add_hdr_async(ac, &vol.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- vol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- vol.param.data_payload_addr_lsw = 0;
- vol.param.data_payload_addr_msw = 0;
- vol.param.mem_map_handle = 0;
- vol.param.data_payload_size = sizeof(vol) -
- sizeof(vol.hdr) - sizeof(vol.param);
- vol.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- vol.data.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
- vol.data.param_size = vol.param.data_payload_size - sizeof(vol.data);
- vol.data.reserved = 0;
- vol.master_gain = volume;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &vol);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- vol.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- vol.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_softpause(struct audio_client *ac,
- struct asm_softpause_params *pause_param)
- {
- struct asm_soft_pause_params softpause;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_soft_pause_params);
- q6asm_add_hdr_async(ac, &softpause.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- softpause.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- softpause.param.data_payload_addr_lsw = 0;
- softpause.param.data_payload_addr_msw = 0;
- softpause.param.mem_map_handle = 0;
- softpause.param.data_payload_size = sizeof(softpause) -
- sizeof(softpause.hdr) - sizeof(softpause.param);
- softpause.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- softpause.data.param_id = ASM_PARAM_ID_SOFT_PAUSE_PARAMETERS;
- softpause.data.param_size = softpause.param.data_payload_size -
- sizeof(softpause.data);
- softpause.data.reserved = 0;
- softpause.enable_flag = pause_param->enable;
- softpause.period = pause_param->period;
- softpause.step = pause_param->step;
- softpause.ramping_curve = pause_param->rampingcurve;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &softpause);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- softpause.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- softpause.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param)
- {
- struct asm_soft_step_volume_params softvol;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_soft_step_volume_params);
- q6asm_add_hdr_async(ac, &softvol.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- softvol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- softvol.param.data_payload_addr_lsw = 0;
- softvol.param.data_payload_addr_msw = 0;
- softvol.param.mem_map_handle = 0;
- softvol.param.data_payload_size = sizeof(softvol) -
- sizeof(softvol.hdr) - sizeof(softvol.param);
- softvol.data.module_id = ASM_MODULE_ID_VOL_CTRL;
- softvol.data.param_id = ASM_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
- softvol.data.param_size = softvol.param.data_payload_size -
- sizeof(softvol.data);
- softvol.data.reserved = 0;
- softvol.period = softvol_param->period;
- softvol.step = softvol_param->step;
- softvol.ramping_curve = softvol_param->rampingcurve;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &softvol);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- softvol.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- softvol.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_sa(struct audio_client *ac, int *param)
- {
- int sz = 0;
- int rc = 0;
- int i = 0;
- struct asm_stream_cmd_set_pp_params_sa cmd ;
-
- if(ac == NULL){
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_sa);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_SA;
- cmd.data.param_id = ASM_PARAM_ID_PP_SA_PARAMS;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
-
- /* SA paramerters */
- cmd.sa_param.OutDevice = param[0];
- cmd.sa_param.Preset = param[1];
- for( i=0; i<7; i++)
- cmd.sa_param.EqLev[i] = param[i+2];
- cmd.sa_param.m3Dlevel = param[9];
- cmd.sa_param.BElevel = param[10];
- cmd.sa_param.CHlevel = param[11];
- cmd.sa_param.CHRoomSize = param[12];
- cmd.sa_param.Clalevel = param[13];
- cmd.sa_param.volume = param[14];
- cmd.sa_param.Sqrow = param[15];
- cmd.sa_param.Sqcol = param[16];
- cmd.sa_param.TabInfo = param[17];
- cmd.sa_param.NewUI = param[18];
-
- printk("S ");
- for(i = 0 ; i < 19; i++)
- printk("%d ", param[i]);
- printk("\n");
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- pr_err("%s: send_pkt failed. paramid[0x%x]\n", __func__,
- cmd.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_set_vsp(struct audio_client *ac, int *param)
- {
- int sz = 0;
- int rc = 0;
- struct asm_stream_cmd_set_pp_params_vsp cmd;
- if(ac == NULL) {
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_vsp);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_SA_VSP;
- cmd.data.param_id = ASM_PARAM_ID_PP_SA_VSP_PARAMS;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
- /* VSP paramerters */
- cmd.speed_int = param[0];
- printk("%d ", param[0]);
- printk("\n");
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_set_dha(struct audio_client *ac,int *param)
- {
- int sz = 0;
- int rc = 0;
- int i = 0;
- struct asm_stream_cmd_set_pp_params_dha cmd;
- if(ac == NULL) {
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_dha);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_DHA;
- cmd.data.param_id = ASM_PARAM_ID_PP_DHA_PARAMS;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
- /* DHA paramerters */
- cmd.enable = param[0];
- for(i = 0; i < 12; i++)
- cmd.gain[i/6][i%6] = param[i+1];
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_set_lrsm(struct audio_client *ac,int *param)
- {
- int sz = 0;
- int rc = 0;
- struct asm_stream_cmd_set_pp_params_lrsm cmd;
- if(ac == NULL) {
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_lrsm);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_LRSM;
- cmd.data.param_id = ASM_PARAM_ID_PP_LRSM_PARAMS;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
- /* LRSM paramerters */
- cmd.sm = param[0];
- cmd.lr = param[1];
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_set_msp(struct audio_client *ac, long *param)
- {
- int sz = 0;
- int rc = 0;
- struct asm_stream_cmd_set_pp_params_msp cmd;
- if(ac == NULL) {
- pr_err("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_msp);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_SA_MSP;
- cmd.data.param_id = ASM_MODULE_ID_PP_SA_MSP_PARAM;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
- /* VSP paramerters */
- cmd.msp_int = param[0];
- pr_info("%s: %d\n", __func__, cmd.msp_int);
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_set_sa_ep(struct audio_client *ac,int *param)
- {
- int sz = 0;
- int rc = 0;
- struct asm_stream_cmd_set_pp_params_sa_ep cmd;
- if(ac == NULL) {
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_set_pp_params_sa_ep);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, TRUE);
- cmd.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.param.data_payload_size =
- sizeof(cmd) - sizeof(cmd.hdr) - sizeof(cmd.param);
- cmd.data.module_id = ASM_MODULE_ID_PP_SA_EP;
- cmd.data.param_id = ASM_PARAM_ID_PP_SA_EP_PARAMS;
- cmd.data.param_size = cmd.param.data_payload_size - sizeof(cmd.data);
- cmd.data.reserved = 0;
- /* SA EP paramerters */
- cmd.enable = param[0];
- cmd.score = param[1];
- printk("%s: %d %d\n", __func__, cmd.enable, cmd.score);
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- }
- int q6asm_get_sa_ep(struct audio_client *ac)
- {
- #if 0
- int sz = 0;
- int rc = 0;
- struct asm_stream_cmd_get_pp_params_v2 cmd;
- if(ac == NULL) {
- printk("%s: audio client is null\n", __func__);
- return -1;
- }
- sz = sizeof(struct asm_stream_cmd_get_pp_params_v2);
- q6asm_add_hdr_async(ac, &cmd.hdr, sz, true);
- cmd.hdr.opcode = ASM_STREAM_CMD_GET_PP_PARAMS_V2;
- cmd.param.data_payload_addr_lsw = 0;
- cmd.param.data_payload_addr_msw = 0;
- cmd.param.mem_map_handle = 0;
- cmd.data.module_id = ASM_MODULE_ID_PP_SA_EP;
- cmd.data.param_id = ASM_PARAM_ID_PP_SA_EP_GET_PARAMS;
- cmd.data.param_max_size = 20;
- cmd.data.reserved = 0;
- rc = apr_send_pkt(ac->apr, (uint32_t *)&cmd);
- if (rc < 0) {
- rc = -EINVAL;
- goto fail_cmd;
- }
- fail_cmd:
- return rc;
- #else
- return 0;
- #endif
- }
- int q6asm_equalizer(struct audio_client *ac, void *eq_p)
- {
- struct asm_eq_params eq;
- struct msm_audio_eq_stream_config *eq_params = NULL;
- int i = 0;
- int sz = 0;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (eq_p == NULL) {
- pr_err("%s[%d]: Invalid Eq param\n", __func__, ac->session);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_eq_params);
- eq_params = (struct msm_audio_eq_stream_config *) eq_p;
- q6asm_add_hdr(ac, &eq.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, 1);
- eq.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- eq.param.data_payload_addr_lsw = 0;
- eq.param.data_payload_addr_msw = 0;
- eq.param.mem_map_handle = 0;
- eq.param.data_payload_size = sizeof(eq) -
- sizeof(eq.hdr) - sizeof(eq.param);
- eq.data.module_id = ASM_MODULE_ID_EQUALIZER;
- eq.data.param_id = ASM_PARAM_ID_EQUALIZER_PARAMETERS;
- eq.data.param_size = eq.param.data_payload_size - sizeof(eq.data);
- eq.enable_flag = eq_params->enable;
- eq.num_bands = eq_params->num_bands;
- pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
- eq_params->num_bands);
- for (i = 0; i < eq_params->num_bands; i++) {
- eq.eq_bands[i].band_idx =
- eq_params->eq_bands[i].band_idx;
- eq.eq_bands[i].filterype =
- eq_params->eq_bands[i].filter_type;
- eq.eq_bands[i].center_freq_hz =
- eq_params->eq_bands[i].center_freq_hz;
- eq.eq_bands[i].filter_gain =
- eq_params->eq_bands[i].filter_gain;
- eq.eq_bands[i].q_factor =
- eq_params->eq_bands[i].q_factor;
- pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_type, i);
- pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].center_freq_hz, i);
- pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_gain, i);
- pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].q_factor, i);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *)&eq);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
- eq.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- eq.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_read(struct audio_client *ac)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
- mutex_lock(&port->lock);
- dsp_buf = port->dsp_buf;
- if (port->buf == NULL) {
- pr_err("%s buf is NULL\n", __func__);
- mutex_unlock(&port->lock);
- return -EINVAL;
- }
- ab = &port->buf[dsp_buf];
- pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
- __func__,
- ac->session,
- dsp_buf,
- (void *)port->buf[dsp_buf].data,
- port->cpu_buf,
- (void *)port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = ab->phys;
- read.buf_addr_msw = 0;
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == (uint32_t) ab->phys)
- read.mem_map_handle = buf_node->mmap_hdl;
- }
- pr_debug("memory_map handle in q6asm_read: [%0x]:",
- read.mem_map_handle);
- read.buf_size = ab->size;
- read.seq_id = port->dsp_buf;
- read.hdr.token = port->dsp_buf;
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
- mutex_unlock(&port->lock);
- pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
- read.buf_addr_lsw,
- read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_read_nolock(struct audio_client *ac)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
- __func__,
- ac->session,
- dsp_buf,
- (void *)port->buf[dsp_buf].data,
- port->cpu_buf,
- (void *)port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = ab->phys;
- read.buf_addr_msw = 0;
- read.buf_size = ab->size;
- read.seq_id = port->dsp_buf;
- read.hdr.token = port->dsp_buf;
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == (uint32_t)ab->phys) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
- pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
- read.buf_addr_lsw,
- read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_async_write(struct audio_client *ac,
- struct audio_aio_write_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- struct audio_port_data *port;
- u32 lbuf_addr_lsw;
- u32 liomode;
- u32 io_compressed;
- u32 io_compressed_stream;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(
- ac, &write.hdr, sizeof(write), FALSE, ac->stream_id);
- port = &ac->port[IN];
- ab = &port->buf[port->dsp_buf];
- /* Pass physical address as token for AIO scheme */
- write.hdr.token = param->uid;
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = param->paddr;
- write.buf_addr_msw = 0x00;
- write.buf_size = param->len;
- write.timestamp_msw = param->msw_ts;
- write.timestamp_lsw = param->lsw_ts;
- liomode = (ASYNC_IO_MODE | NT_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- io_compressed_stream = (ASYNC_IO_MODE | COMPRESSED_STREAM_IO);
- if (ac->io_mode == liomode)
- lbuf_addr_lsw = (write.buf_addr_lsw - 32);
- else if (ac->io_mode == io_compressed ||
- ac->io_mode == io_compressed_stream)
- lbuf_addr_lsw = (write.buf_addr_lsw - param->metadata_len);
- else
- lbuf_addr_lsw = write.buf_addr_lsw;
- pr_debug("%s: token[0x%x], buf_addr_lsw[0x%x], buf_size[0x%x], ts_msw[0x%x], ts_lsw[0x%x], lbuf_addr_lsw: 0x[%x]\n",
- __func__,
- write.hdr.token, write.buf_addr_lsw,
- write.buf_size, write.timestamp_msw,
- write.timestamp_lsw, lbuf_addr_lsw);
- /* Use 0xFF00 for disabling timestamps */
- if (param->flags == 0xFF00)
- write.flags = (0x00000000 | (param->flags & 0x800000FF));
- else
- write.flags = (0x80000000 | param->flags);
- write.flags |= param->last_buffer << ASM_SHIFT_LAST_BUFFER_FLAG;
- write.seq_id = param->uid;
- list_for_each_safe(ptr, next, &ac->port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == lbuf_addr_lsw) {
- write.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
- write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_async_read(struct audio_client *ac,
- struct audio_aio_read_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- u32 lbuf_addr_lsw;
- u32 liomode;
- u32 io_compressed;
- int dir = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- /* Pass physical address as token for AIO scheme */
- read.hdr.token = param->paddr;
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = param->paddr;
- read.buf_addr_msw = 0;
- read.buf_size = param->len;
- read.seq_id = param->uid;
- liomode = (NT_MODE | ASYNC_IO_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- if (ac->io_mode == liomode) {
- lbuf_addr_lsw = (read.buf_addr_lsw - 32);
- /*legacy wma driver case*/
- dir = IN;
- } else if (ac->io_mode == io_compressed) {
- lbuf_addr_lsw = (read.buf_addr_lsw - 64);
- dir = OUT;
- } else {
- lbuf_addr_lsw = read.buf_addr_lsw;
- dir = OUT;
- }
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_addr_lsw == lbuf_addr_lsw) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
- read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[IN];
- q6asm_add_hdr(ac, &write.hdr, sizeof(write),
- FALSE);
- mutex_lock(&port->lock);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- write.hdr.token = port->dsp_buf;
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = ab->phys;
- write.buf_addr_msw = 0;
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- pr_debug("%s:ab->phys[0x%x]bufadd[0x%x] token[0x%x]buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- mutex_unlock(&port->lock);
- config_debug_fs_write(ab);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
- goto fail_cmd;
- }
- pr_debug("%s: WRITE SUCCESS\n", __func__);
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[IN];
- q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
- FALSE);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- write.hdr.token = port->dsp_buf;
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = ab->phys;
- write.buf_addr_msw = 0;
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
- pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
- goto fail_cmd;
- }
- pr_debug("%s: WRITE SUCCESS\n", __func__);
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
- {
- struct apr_hdr hdr;
- int rc;
- if (!ac || ac->apr == NULL || tstamp == NULL) {
- pr_err("%s: APR handle NULL or tstamp NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- hdr.opcode = ASM_SESSION_CMD_GET_SESSIONTIME_V3;
- atomic_set(&ac->time_flag, 1);
- pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("Commmand 0x%x failed\n", hdr.opcode);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->time_wait,
- (atomic_read(&ac->time_flag) == 0), 5*HZ);
- if (!rc) {
- pr_err("%s: timeout in getting session time from DSP\n",
- __func__);
- goto fail_cmd;
- }
- *tstamp = ac->time_stamp;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_send_audio_effects_params(struct audio_client *ac, char *params,
- uint32_t params_length)
- {
- char *asm_params = NULL;
- struct apr_hdr hdr;
- struct asm_stream_cmd_set_pp_params_v2 payload_params;
- int sz, rc;
- pr_debug("%s\n", __func__);
- if (!ac || ac->apr == NULL || params == NULL) {
- pr_err("APR handle NULL or params NULL\n");
- return -EINVAL;
- }
- sz = sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2) +
- params_length;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- pr_err("%s, adm params memory alloc failed", __func__);
- return -ENOMEM;
- }
- q6asm_add_hdr_async(ac, &hdr, (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2) +
- params_length), TRUE);
- atomic_set(&ac->cmd_state, 1);
- hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- payload_params.data_payload_addr_lsw = 0;
- payload_params.data_payload_addr_msw = 0;
- payload_params.mem_map_handle = 0;
- payload_params.data_payload_size = params_length;
- memcpy(((u8 *)asm_params), &hdr, sizeof(struct apr_hdr));
- memcpy(((u8 *)asm_params + sizeof(struct apr_hdr)), &payload_params,
- sizeof(struct asm_stream_cmd_set_pp_params_v2));
- memcpy(((u8 *)asm_params + sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_pp_params_v2)),
- params, params_length);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: audio effects set-params send failed\n", __func__);
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 1*HZ);
- if (!rc) {
- pr_err("%s: timeout, audio effects set-params\n", __func__);
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- kfree(asm_params);
- return rc;
- }
- static int __q6asm_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- atomic_t *state;
- int cnt = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s:CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- state = &ac->cmd_state;
- break;
- case CMD_SUSPEND:
- pr_debug("%s:CMD_SUSPEND\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_SUSPEND;
- state = &ac->cmd_state;
- break;
- case CMD_FLUSH:
- pr_debug("%s:CMD_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH;
- state = &ac->cmd_state;
- break;
- case CMD_OUT_FLUSH:
- pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
- state = &ac->cmd_state;
- break;
- case CMD_EOS:
- pr_debug("%s:CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- atomic_set(&ac->cmd_state, 0);
- state = &ac->cmd_state;
- break;
- case CMD_CLOSE:
- pr_debug("%s:CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- state = &ac->cmd_state;
- break;
- default:
- pr_err("Invalid format[%d]\n", cmd);
- goto fail_cmd;
- }
- pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("Commmand 0x%x failed\n", hdr.opcode);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for response opcode[0x%x]\n",
- hdr.opcode);
- goto fail_cmd;
- }
- if (cmd == CMD_FLUSH)
- q6asm_reset_buf_state(ac);
- if (cmd == CMD_CLOSE) {
- /* check if DSP return all buffers */
- if (ac->port[IN].buf) {
- for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
- cnt++) {
- if (ac->port[IN].buf[cnt].used == IN) {
- pr_debug("Write Buf[%d] not returned\n",
- cnt);
- }
- }
- }
- if (ac->port[OUT].buf) {
- for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
- if (ac->port[OUT].buf[cnt].used == OUT) {
- pr_debug("Read Buf[%d] not returned\n",
- cnt);
- }
- }
- }
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_cmd(struct audio_client *ac, int cmd)
- {
- return __q6asm_cmd(ac, cmd, ac->stream_id);
- }
- int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- return __q6asm_cmd(ac, cmd, stream_id);
- }
- static int __q6asm_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s:APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s:CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- break;
- case CMD_EOS:
- pr_debug("%s:CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- break;
- case CMD_CLOSE:
- pr_debug("%s:CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- break;
- default:
- pr_err("%s:Invalid format[%d]\n", __func__, cmd);
- goto fail_cmd;
- }
- pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
- ac->session,
- hdr.opcode);
- /* have to increase first avoid race */
- atomic_inc(&ac->nowait_cmd_cnt);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- atomic_dec(&ac->nowait_cmd_cnt);
- pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
- {
- pr_debug("%s: stream_id: %d\n", __func__, ac->stream_id);
- return __q6asm_cmd_nowait(ac, cmd, ac->stream_id);
- }
- int q6asm_stream_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- pr_debug("%s: stream_id: %d\n", __func__, stream_id);
- return __q6asm_cmd_nowait(ac, cmd, stream_id);
- }
- int __q6asm_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- struct asm_data_cmd_remove_silence silence;
- int rc = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s session[%d]", __func__, ac->session);
- q6asm_stream_add_hdr_async(ac, &silence.hdr, sizeof(silence), FALSE,
- stream_id);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- silence.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, silence.hdr.token, stream_id, ac->session);
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_INITIAL_SILENCE;
- silence.num_samples_to_remove = initial_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("Commmand silence failed[%d]", rc);
- goto fail_cmd;
- }
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_TRAILING_SILENCE;
- silence.num_samples_to_remove = trailing_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("Commmand silence failed[%d]", rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_stream_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, stream_id, initial_samples,
- trailing_samples);
- }
- int q6asm_send_meta_data(struct audio_client *ac, uint32_t initial_samples,
- uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, ac->stream_id, initial_samples,
- trailing_samples);
- }
- static void q6asm_reset_buf_state(struct audio_client *ac)
- {
- int cnt = 0;
- int loopcnt = 0;
- int used;
- struct audio_port_data *port = NULL;
- if (ac->io_mode & SYNC_IO_MODE) {
- used = (ac->io_mode & TUN_WRITE_IO_MODE ? 1 : 0);
- mutex_lock(&ac->cmd_lock);
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- cnt = port->max_buf_cnt - 1;
- port->dsp_buf = 0;
- port->cpu_buf = 0;
- while (cnt >= 0) {
- if (!port->buf)
- continue;
- port->buf[cnt].used = used;
- cnt--;
- }
- }
- mutex_unlock(&ac->cmd_lock);
- }
- }
- int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_regx_overflow tx_overflow;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s:session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
- atomic_set(&ac->cmd_state, 1);
- tx_overflow.hdr.opcode = \
- ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS;
- /* tx overflow event: enable */
- tx_overflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
- if (rc < 0) {
- pr_err("tx overflow op[0x%x]rc[%d]\n", \
- tx_overflow.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for tx overflow\n");
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_reg_rx_underflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_rgstr_rx_underflow rx_underflow;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s:session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr_async(ac, &rx_underflow.hdr, sizeof(rx_underflow), FALSE);
- rx_underflow.hdr.opcode = \
- ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS;
- /* tx overflow event: enable */
- rx_underflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &rx_underflow);
- if (rc < 0) {
- pr_err("tx overflow op[0x%x]rc[%d]\n", \
- rx_underflow.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_get_apr_service_id(int session_id)
- {
- pr_debug("%s\n", __func__);
- if (session_id <= 0 || session_id > SESSION_MAX) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- return -EINVAL;
- }
- return ((struct apr_svc *)session[session_id]->apr)->id;
- }
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv)
- {
- struct audio_client *ac = (struct audio_client *)priv;
- uint32_t token = data->token;
- /*
- * Some commands for compressed playback has token as session and
- * other commands has session|stream. Check for both conditions
- * before deciding if the callback was for a invalud session.
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO) {
- if ((token & 0xFFFFFF00) != ((ac->session << 8) & 0xFFFFFF00)
- && (token != ac->session)) {
- pr_err("%s:Invalid compr session[%d] rxed expected[%d]",
- __func__, token, ac->session);
- return -EINVAL;
- }
- } else {
- if (token != ac->session) {
- pr_err("%s:Invalid session[%d] rxed expected[%d]",
- __func__, token, ac->session);
- return -EINVAL;
- }
- }
- return 0;
- }
- static int __init q6asm_init(void)
- {
- int lcnt;
- pr_debug("%s\n", __func__);
- memset(session, 0, sizeof(session));
- set_custom_topology = 1;
- /*setup common client used for cal mem map */
- common_client.session = ASM_CONTROL_SESSION;
- common_client.port[0].buf = &common_buf[0];
- common_client.port[1].buf = &common_buf[1];
- init_waitqueue_head(&common_client.cmd_wait);
- init_waitqueue_head(&common_client.time_wait);
- init_waitqueue_head(&common_client.mem_wait);
- atomic_set(&common_client.time_flag, 1);
- INIT_LIST_HEAD(&common_client.port[0].mem_map_handle);
- INIT_LIST_HEAD(&common_client.port[1].mem_map_handle);
- mutex_init(&common_client.cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&common_client.port[lcnt].lock);
- spin_lock_init(&common_client.port[lcnt].dsp_lock);
- }
- atomic_set(&common_client.cmd_state, 0);
- atomic_set(&common_client.nowait_cmd_cnt, 0);
- atomic_set(&common_client.mem_state, 0);
- config_debug_fs_init();
- return 0;
- }
- device_initcall(q6asm_init);
|